diff --git a/app/src/main/java/org/schabi/newpipe/BaseFragment.java b/app/src/main/java/org/schabi/newpipe/BaseFragment.java index ce4318427..07e40cfad 100644 --- a/app/src/main/java/org/schabi/newpipe/BaseFragment.java +++ b/app/src/main/java/org/schabi/newpipe/BaseFragment.java @@ -4,6 +4,7 @@ import android.content.Context; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.view.View; @@ -92,4 +93,10 @@ public abstract class BaseFragment extends Fragment { activity.getSupportActionBar().setTitle(title); } } + + protected FragmentManager getFM() { + return getParentFragment() == null + ? getFragmentManager() + : getParentFragment().getFragmentManager(); + } } diff --git a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java index 3d76f09a0..db962dd6e 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java @@ -74,17 +74,6 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte } }; - - /*////////////////////////////////////////////////////////////////////////// - // Constants - //////////////////////////////////////////////////////////////////////////*/ - - private static final int FALLBACK_SERVICE_ID = ServiceList.YouTube.getServiceId(); - private static final String FALLBACK_CHANNEL_URL = "https://www.youtube.com/channel/UC-9-kyTW8ZkZNDHQJ6FgpwQ"; - private static final String FALLBACK_CHANNEL_NAME = "Music"; - private static final String FALLBACK_KIOSK_ID = "Trending"; - private static final int KIOSK_MENU_OFFSET = 2000; - /*////////////////////////////////////////////////////////////////////////// // Fragment's LifeCycle //////////////////////////////////////////////////////////////////////////*/ @@ -132,26 +121,22 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte } private void setFirstTitle() { - if((tabs.size()>0)&&activity != null) { - String tabNumber = tabs.get(0); - - if (tabNumber.startsWith(TAB_NUMBER_KIOSK + "\t")) { - String kiosk[] = tabNumber.split("\t"); + if((tabs.size() > 0) + && activity != null) { + String tabInformation = tabs.get(0); + if (tabInformation.startsWith(TAB_NUMBER_KIOSK + "\t")) { + String kiosk[] = tabInformation.split("\t"); if (kiosk.length == 2) { - try { - setTitle(kiosk[1]); - } catch (Exception e) { - //ignore this. It WILL be thrown while the service is changed. - } + setTitle(kiosk[1]); } - } else if (tabNumber.startsWith(TAB_NUMBER_CHANNEL + "\t")) { + } else if (tabInformation.startsWith(TAB_NUMBER_CHANNEL + "\t")) { - String channelInfo[] = tabNumber.split("\t"); + String channelInfo[] = tabInformation.split("\t"); if(channelInfo.length==4) { setTitle(channelInfo[2]); } } else { - switch (tabNumber) { + switch (tabInformation) { case TAB_NUMBER_BLANK: setTitle(getString(R.string.app_name)); break; @@ -176,26 +161,22 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte private void setIcons() { for (int i = 0; i < tabs.size(); i++) { - String tabNumber = tabs.get(i); + String tabInformation = tabs.get(i); TabLayout.Tab tabToSet = tabLayout.getTabAt(i); Context c = getContext(); if (tabToSet != null && c != null) { - if (tabNumber.startsWith(TAB_NUMBER_KIOSK + "\t")) { - String kiosk[] = tabNumber.split("\t"); + if (tabInformation.startsWith(TAB_NUMBER_KIOSK + "\t")) { + String kiosk[] = tabInformation.split("\t"); if (kiosk.length == 2) { - try { - tabToSet.setIcon(KioskTranslator.getKioskIcons(kiosk[1], getContext())); - } catch (Exception e) { - //ignore this. It WILL be thrown while the service is changed. - } + tabToSet.setIcon(KioskTranslator.getKioskIcons(kiosk[1], getContext())); } - } else if (tabNumber.startsWith(TAB_NUMBER_CHANNEL + "\t")) { + } else if (tabInformation.startsWith(TAB_NUMBER_CHANNEL + "\t")) { tabToSet.setIcon(ThemeHelper.resolveResourceIdFromAttr(getContext(), R.attr.ic_channel)); } else { - switch (tabNumber) { + switch (tabInformation) { case TAB_NUMBER_BLANK: tabToSet.setIcon(ThemeHelper.resolveResourceIdFromAttr(getContext(), R.attr.ic_hot)); break; @@ -238,15 +219,15 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte "none", "", R.string.app_ui_crash)); } - for(String tabNumber:tabsArray) { - if(tabNumber.equals(TAB_NUMBER_KIOSK)) { + for(String tabInformation:tabsArray) { + if(tabInformation.equals(TAB_NUMBER_KIOSK)) { if (kl != null) { for(String ks : kl.getAvailableKiosks()) { - tabs.add(tabNumber+"\t"+ks); + tabs.add(tabInformation+"\t"+ks); } } } else { - tabs.add(tabNumber); + tabs.add(tabInformation); } } } @@ -308,10 +289,10 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte @Override public Fragment getItem(int position) { - String tabNumber = tabs.get(position); + String tabInformation = tabs.get(position); - if(tabNumber.startsWith(TAB_NUMBER_KIOSK + "\t")) { - String kiosk[] = tabNumber.split("\t"); + if(tabInformation.startsWith(TAB_NUMBER_KIOSK + "\t")) { + String kiosk[] = tabInformation.split("\t"); if(kiosk.length==2) { KioskFragment fragment = null; try { @@ -326,8 +307,8 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte "none", "", R.string.app_ui_crash)); } } - } else if(tabNumber.startsWith(TAB_NUMBER_CHANNEL + "\t")) { - String channelInfo[] = tabNumber.split("\t"); + } else if(tabInformation.startsWith(TAB_NUMBER_CHANNEL + "\t")) { + String channelInfo[] = tabInformation.split("\t"); if(channelInfo.length==4) { ChannelFragment fragment = ChannelFragment.getInstance(Integer.parseInt(channelInfo[3]), channelInfo[1], channelInfo[2]); fragment.useAsFrontPage(true); @@ -336,7 +317,7 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte return new BlankFragment(); } } else { - switch (tabNumber) { + switch (tabInformation) { case TAB_NUMBER_BLANK: return new BlankFragment(); case TAB_NUMBER_SUBSCIRPTIONS: @@ -375,7 +356,10 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte @Override public void destroyItem(ViewGroup container, int position, Object object) { - getFragmentManager().beginTransaction().remove((Fragment)object).commitNowAllowingStateLoss(); + getFragmentManager() + .beginTransaction() + .remove((Fragment)object) + .commitNowAllowingStateLoss(); } } } diff --git a/app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java b/app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java index c1477f696..6bdc631d8 100644 --- a/app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java @@ -101,28 +101,20 @@ public final class BookmarkFragment itemListAdapter.setSelectedListener(new OnClickGesture() { @Override public void selected(LocalItem selectedItem) { - try { - // Requires the parent fragment to find holder for fragment replacement - final FragmentManager fragmentManager = - getParentFragment() == null - ? getFragmentManager() - : getParentFragment().getFragmentManager(); + final FragmentManager fragmentManager = getFM(); - if (selectedItem instanceof PlaylistMetadataEntry) { - final PlaylistMetadataEntry entry = ((PlaylistMetadataEntry) selectedItem); - NavigationHelper.openLocalPlaylistFragment(fragmentManager, entry.uid, - entry.name); + if (selectedItem instanceof PlaylistMetadataEntry) { + final PlaylistMetadataEntry entry = ((PlaylistMetadataEntry) selectedItem); + NavigationHelper.openLocalPlaylistFragment(fragmentManager, entry.uid, + entry.name); - } else if (selectedItem instanceof PlaylistRemoteEntity) { - final PlaylistRemoteEntity entry = ((PlaylistRemoteEntity) selectedItem); - NavigationHelper.openPlaylistFragment( - fragmentManager, - entry.getServiceId(), - entry.getUrl(), - entry.getName()); - } - } catch (Exception e) { - ErrorActivity.reportUiError((AppCompatActivity) getActivity(), e); + } else if (selectedItem instanceof PlaylistRemoteEntity) { + final PlaylistRemoteEntity entry = ((PlaylistRemoteEntity) selectedItem); + NavigationHelper.openPlaylistFragment( + fragmentManager, + entry.getServiceId(), + entry.getUrl(), + entry.getName()); } } diff --git a/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.java b/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.java index 6da66f418..de5148a75 100644 --- a/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.java @@ -117,12 +117,6 @@ public class FeedFragment extends BaseListFragment, Voi } } - /*@Override - protected RecyclerView.LayoutManager getListLayoutManager() { - boolean isPortrait = getResources().getDisplayMetrics().heightPixels > getResources().getDisplayMetrics().widthPixels; - return new GridLayoutManager(activity, isPortrait ? 1 : 2); - }*/ - @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); diff --git a/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java index d2f44e18c..1991590c5 100644 --- a/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java @@ -140,8 +140,12 @@ public class StatisticsPlaylistFragment public void selected(LocalItem selectedItem) { if (selectedItem instanceof StreamStatisticsEntry) { final StreamStatisticsEntry item = (StreamStatisticsEntry) selectedItem; - NavigationHelper.openVideoDetailFragment(useAsFrontPage ? getParentFragment().getFragmentManager() : getFragmentManager(), item.serviceId, item.url, item.title); - + NavigationHelper.openVideoDetailFragment(useAsFrontPage + ? getParentFragment().getFragmentManager() + : getFragmentManager(), + item.serviceId, + item.url, + item.title); } } diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.java b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.java index 9e658c8ce..7c5eaf6c4 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.java @@ -328,20 +328,13 @@ public class SubscriptionFragment extends BaseStateFragment - { + whatsNewItemListHeader.setOnClickListener(v -> { FragmentManager fragmentManager = getFM(); NavigationHelper.openWhatsNewFragment(fragmentManager); }); importExportListHeader.setOnClickListener(v -> importExportOptions.switchState()); } - private FragmentManager getFM() { - return getParentFragment() == null - ? getFragmentManager() - : getParentFragment().getFragmentManager(); - } - private void resetFragment() { if (disposables != null) disposables.clear(); if (infoListAdapter != null) infoListAdapter.clearStreamItemList(); diff --git a/app/src/main/java/org/schabi/newpipe/settings/AddTabsDialog.java b/app/src/main/java/org/schabi/newpipe/settings/AddTabsDialog.java new file mode 100644 index 000000000..5130df3bf --- /dev/null +++ b/app/src/main/java/org/schabi/newpipe/settings/AddTabsDialog.java @@ -0,0 +1,41 @@ +package org.schabi.newpipe.settings; + +import android.app.Activity; +import android.app.AlertDialog; +import android.content.Context; +import android.content.DialogInterface; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.view.View; +import android.widget.TextView; + +import org.schabi.newpipe.R; +import org.schabi.newpipe.extractor.stream.StreamInfoItem; + +public class AddTabsDialog { + private final AlertDialog dialog; + + public AddTabsDialog(@NonNull final Context context, + @NonNull final String title, + @NonNull final String[] commands, + @NonNull final DialogInterface.OnClickListener actions) { + + final View bannerView = View.inflate(context, R.layout.dialog_title, null); + bannerView.setSelected(true); + + TextView titleView = bannerView.findViewById(R.id.itemTitleView); + titleView.setText(title); + + TextView detailsView = bannerView.findViewById(R.id.itemAdditionalDetails); + detailsView.setVisibility(View.GONE); + + dialog = new AlertDialog.Builder(context) + .setCustomTitle(bannerView) + .setItems(commands, actions) + .create(); + } + + public void show() { + dialog.show(); + } +} diff --git a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsMain.java b/app/src/main/java/org/schabi/newpipe/settings/ChoseTabsFragment.java similarity index 67% rename from app/src/main/java/org/schabi/newpipe/settings/ContentSettingsMain.java rename to app/src/main/java/org/schabi/newpipe/settings/ChoseTabsFragment.java index e4a80ab0f..89148e0b3 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsMain.java +++ b/app/src/main/java/org/schabi/newpipe/settings/ChoseTabsFragment.java @@ -1,63 +1,50 @@ package org.schabi.newpipe.settings; -import android.content.Context; +import android.app.Dialog; +import android.content.DialogInterface; import android.content.SharedPreferences; import android.content.res.ColorStateList; -import android.content.res.TypedArray; -import android.graphics.Canvas; -import android.graphics.Color; -import android.graphics.drawable.Drawable; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.design.widget.FloatingActionButton; import android.support.v4.app.Fragment; import android.support.v7.app.AppCompatActivity; -import android.support.v7.preference.PreferenceManager; import android.support.v7.widget.CardView; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.helper.ItemTouchHelper; import android.util.TypedValue; -import android.view.DragEvent; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; -import android.widget.Button; -import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.TextView; import org.schabi.newpipe.R; -import org.schabi.newpipe.database.LocalItem; -import org.schabi.newpipe.database.playlist.PlaylistStreamEntry; -import org.schabi.newpipe.local.holder.LocalPlaylistStreamItemHolder; -import org.schabi.newpipe.util.NavigationHelper; -import org.schabi.newpipe.util.OnClickGesture; -import org.schabi.newpipe.util.ServiceHelper; +import org.schabi.newpipe.info_list.InfoItemDialog; import org.schabi.newpipe.util.ThemeHelper; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.List; -public class ContentSettingsMain extends Fragment { +public class ChoseTabsFragment extends Fragment { - public ContentSettingsMain.UsedAdapter usedAdapter; + public ChoseTabsFragment.SelectedTabsAdapter selectedTabsAdapter; - RecyclerView usedTabsView; + RecyclerView selectedTabsView; - List usedTabs = new ArrayList<>(); + List selectedTabs = new ArrayList<>(); private String saveString; - public String[] allTabs = new String[7]; + public String[] availableTabs = new String[7]; @Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ((AppCompatActivity)getContext()).getSupportActionBar().setTitle(R.string.main_page_content); - return inflater.inflate(R.layout.dialog_contentsettings, container, false); + return inflater.inflate(R.layout.fragment_chose_tabs, container, false); } @@ -69,24 +56,24 @@ public class ContentSettingsMain extends Fragment { initUsedTabs(); initButton(rootView); - usedTabsView = rootView.findViewById(R.id.usedTabs); - usedTabsView.setLayoutManager(new LinearLayoutManager(getContext())); - usedAdapter = new ContentSettingsMain.UsedAdapter(); + selectedTabsView = rootView.findViewById(R.id.usedTabs); + selectedTabsView.setLayoutManager(new LinearLayoutManager(getContext())); + selectedTabsAdapter = new ChoseTabsFragment.SelectedTabsAdapter(); ItemTouchHelper itemTouchHelper = new ItemTouchHelper(getItemTouchCallback()); - itemTouchHelper.attachToRecyclerView(usedTabsView); - usedAdapter.setOnItemSelectedListener(itemTouchHelper); + itemTouchHelper.attachToRecyclerView(selectedTabsView); + selectedTabsAdapter.setOnItemSelectedListener(itemTouchHelper); - usedTabsView.setAdapter(usedAdapter); + selectedTabsView.setAdapter(selectedTabsAdapter); } private void saveChanges() { StringBuilder save = new StringBuilder(); - if(usedTabs.size()==0) { + if(selectedTabs.size()==0) { save = new StringBuilder("0"); } else { - for(String s: usedTabs) { + for(String s: selectedTabs) { save.append(s); save.append("\n"); } @@ -107,26 +94,30 @@ public class ContentSettingsMain extends Fragment { private void initUsedTabs() { String save = android.preference.PreferenceManager.getDefaultSharedPreferences(getContext()).getString("saveUsedTabs", "1\n2\n4\n"); String tabs[] = save.trim().split("\n"); - usedTabs.addAll(Arrays.asList(tabs)); + selectedTabs.addAll(Arrays.asList(tabs)); } private void tabNames() { - allTabs[0] = getString(R.string.blank_page_summary); - allTabs[1] = getString(R.string.kiosk_page_summary); - allTabs[2] = getString(R.string.subscription_page_summary); - allTabs[3] = getString(R.string.feed_page_summary); - allTabs[4] = getString(R.string.tab_bookmarks); - allTabs[5] = getString(R.string.title_activity_history); - allTabs[6] = getString(R.string.channel_page_summary); + availableTabs[0] = getString(R.string.blank_page_summary); + availableTabs[1] = getString(R.string.kiosk_page_summary); + availableTabs[2] = getString(R.string.subscription_page_summary); + availableTabs[3] = getString(R.string.feed_page_summary); + availableTabs[4] = getString(R.string.tab_bookmarks); + availableTabs[5] = getString(R.string.title_activity_history); + availableTabs[6] = getString(R.string.channel_page_summary); } private void initButton(View rootView) { FloatingActionButton fab = rootView.findViewById(R.id.floatingActionButton); fab.setImageResource(ThemeHelper.getIconByAttr(R.attr.ic_add, getContext())); fab.setOnClickListener(v -> { - ContentSettingsMainDialog contentSettingsMainDialog = new ContentSettingsMainDialog(); - contentSettingsMainDialog.setOnAddListener(ContentSettingsMain.this::addTab); - contentSettingsMainDialog.show(getFragmentManager(), "select_channel"); + Dialog.OnClickListener onClickListener = (dialog, which) -> addTab(which); + + new AddTabsDialog(getContext(), + getString(R.string.tab_chose), + availableTabs, + onClickListener) + .show(); }); TypedValue typedValue = new TypedValue(); @@ -138,23 +129,21 @@ public class ContentSettingsMain extends Fragment { private void addTab(int position) { if(position!=6) { - usedTabs.add(String.valueOf(position)); - usedAdapter.notifyDataSetChanged(); + selectedTabs.add(String.valueOf(position)); + selectedTabsAdapter.notifyDataSetChanged(); saveChanges(); } else { SelectChannelFragment selectChannelFragment = new SelectChannelFragment(); selectChannelFragment.setOnSelectedLisener((String url, String name, int service) -> { - usedTabs.add(position+"\t"+url+"\t"+name+"\t"+service); - usedAdapter.notifyDataSetChanged(); + selectedTabs.add(position+"\t"+url+"\t"+name+"\t"+service); + selectedTabsAdapter.notifyDataSetChanged(); saveChanges(); }); selectChannelFragment.show(getFragmentManager(), "select_channel"); } } - public class UsedAdapter extends RecyclerView.Adapter{ - // ... code from gist - + public class SelectedTabsAdapter extends RecyclerView.Adapter{ private ItemTouchHelper itemTouchHelper; public void setOnItemSelectedListener(ItemTouchHelper mItemTouchHelper) { @@ -162,29 +151,29 @@ public class ContentSettingsMain extends Fragment { } public void swapItems(int fromPosition, int toPosition) { - String temp = usedTabs.get(fromPosition); - usedTabs.set(fromPosition, usedTabs.get(toPosition)); - usedTabs.set(toPosition, temp); + String temp = selectedTabs.get(fromPosition); + selectedTabs.set(fromPosition, selectedTabs.get(toPosition)); + selectedTabs.set(toPosition, temp); notifyItemMoved(fromPosition, toPosition); saveChanges(); } @Override - public ContentSettingsMain.UsedAdapter.TabViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + public ChoseTabsFragment.SelectedTabsAdapter.TabViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { LayoutInflater inflater = LayoutInflater.from(getContext()); - View view = inflater.inflate(R.layout.dialog_contentsettingtab, parent, false); - return new ContentSettingsMain.UsedAdapter.TabViewHolder(view); + View view = inflater.inflate(R.layout.viewholder_chose_tabs, parent, false); + return new ChoseTabsFragment.SelectedTabsAdapter.TabViewHolder(view); } @Override - public void onBindViewHolder(@NonNull ContentSettingsMain.UsedAdapter.TabViewHolder holder, int position) { + public void onBindViewHolder(@NonNull ChoseTabsFragment.SelectedTabsAdapter.TabViewHolder holder, int position) { holder.bind(position, holder); } @Override public int getItemCount() { - return usedTabs.size(); + return selectedTabs.size(); } class TabViewHolder extends RecyclerView.ViewHolder { @@ -203,21 +192,21 @@ public class ContentSettingsMain extends Fragment { view = itemView; } - void bind(int position, ContentSettingsMain.UsedAdapter.TabViewHolder holder) { + void bind(int position, ChoseTabsFragment.SelectedTabsAdapter.TabViewHolder holder) { handle.setImageResource(ThemeHelper.getIconByAttr(R.attr.drag_handle, getContext())); handle.setOnTouchListener(getOnTouchListener(holder)); view.setOnLongClickListener(getOnLongClickListener(holder)); - if(usedTabs.get(position).startsWith("6\t")) { - String channelInfo[] = usedTabs.get(position).split("\t"); + if(selectedTabs.get(position).startsWith("6\t")) { + String channelInfo[] = selectedTabs.get(position).split("\t"); String channelName = ""; if(channelInfo.length==4) channelName = channelInfo[2]; - String textToSet = allTabs[6]+": "+channelName; + String textToSet = availableTabs[6]+": "+channelName; text.setText(textToSet); } else { - text.setText(allTabs[Integer.parseInt(usedTabs.get(position))]); + text.setText(availableTabs[Integer.parseInt(selectedTabs.get(position))]); } } @@ -234,7 +223,7 @@ public class ContentSettingsMain extends Fragment { private View.OnLongClickListener getOnLongClickListener(TabViewHolder holder) { return (view) -> { int position = holder.getAdapterPosition(); - usedTabs.remove(position); + selectedTabs.remove(position); notifyItemRemoved(position); saveChanges(); return false; @@ -261,13 +250,13 @@ public class ContentSettingsMain extends Fragment { public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder source, RecyclerView.ViewHolder target) { if (source.getItemViewType() != target.getItemViewType() || - usedAdapter == null) { + selectedTabsAdapter == null) { return false; } final int sourceIndex = source.getAdapterPosition(); final int targetIndex = target.getAdapterPosition(); - usedAdapter.swapItems(sourceIndex, targetIndex); + selectedTabsAdapter.swapItems(sourceIndex, targetIndex); return true; } diff --git a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsMainDialog.java b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsMainDialog.java deleted file mode 100644 index 4da1c1c33..000000000 --- a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsMainDialog.java +++ /dev/null @@ -1,123 +0,0 @@ -package org.schabi.newpipe.settings; - -import android.app.Dialog; -import android.content.Context; -import android.content.SharedPreferences; -import android.content.res.TypedArray; -import android.graphics.Canvas; -import android.graphics.drawable.Drawable; -import android.os.Bundle; -import android.preference.PreferenceManager; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v4.app.DialogFragment; -import android.support.v7.widget.CardView; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.Button; -import android.widget.TextView; - -import org.schabi.newpipe.R; -import org.schabi.newpipe.database.subscription.SubscriptionEntity; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public class ContentSettingsMainDialog extends DialogFragment { - - - public AllAdapter allAdapter; - - public String[] allTabs = new String[7]; - - @Override - public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - return inflater.inflate(R.layout.dialog_contentsettingsadd, container); - } - - - @Override - public void onViewCreated(@NonNull View rootView, @Nullable Bundle savedInstanceState) { - super.onViewCreated(rootView, savedInstanceState); - - tabNames(); - - RecyclerView allTabs = rootView.findViewById(R.id.allTabs); - allTabs.setLayoutManager(new LinearLayoutManager(getContext())); - allAdapter = new AllAdapter(); - allTabs.setAdapter(allAdapter); - } - - private void tabNames() { - allTabs[0] = getString(R.string.blank_page_summary); - allTabs[1] = getString(R.string.kiosk_page_summary); - allTabs[2] = getString(R.string.subscription_page_summary); - allTabs[3] = getString(R.string.feed_page_summary); - allTabs[4] = getString(R.string.tab_bookmarks); - allTabs[5] = getString(R.string.title_activity_history); - allTabs[6] = getString(R.string.channel_page_summary); - } - - public interface OnAddListener { - void onAddListener(int position); - } - ContentSettingsMainDialog.OnAddListener onAddListener = null; - public void setOnAddListener(ContentSettingsMainDialog.OnAddListener listener) { - onAddListener = listener; - } - - private void addTab(int position) { - if(onAddListener != null) { - onAddListener.onAddListener(position); - } - dismiss(); - } - - public class AllAdapter extends RecyclerView.Adapter{ - - @Override - public TabViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { - - LayoutInflater inflater = LayoutInflater.from(getContext()); - View view = inflater.inflate(R.layout.dialog_contentsettingtab, parent, false); - return new TabViewHolder(view); - } - - @Override - public void onBindViewHolder(@NonNull TabViewHolder holder, int position) { - holder.bind(position); - } - - @Override - public int getItemCount() { - return allTabs.length; - } - - class TabViewHolder extends RecyclerView.ViewHolder { - - TextView text; - View view; - - public TabViewHolder(View itemView) { - super(itemView); - - text = itemView.findViewById(R.id.tabName); - view = itemView.findViewById(R.id.layoutCard); - } - - void bind(int position) { - text.setText(allTabs[position]); - ((CardView) view).setCardElevation(0); - view.setOnClickListener(v -> { - addTab(position); - }); - - } - } - } -} diff --git a/app/src/main/res/layout/dialog_contentsettingsadd.xml b/app/src/main/res/layout/dialog_contentsettingsadd.xml deleted file mode 100644 index e9ad235fa..000000000 --- a/app/src/main/res/layout/dialog_contentsettingsadd.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - diff --git a/app/src/main/res/layout/dialog_contentsettings.xml b/app/src/main/res/layout/fragment_chose_tabs.xml similarity index 100% rename from app/src/main/res/layout/dialog_contentsettings.xml rename to app/src/main/res/layout/fragment_chose_tabs.xml diff --git a/app/src/main/res/layout/dialog_contentsettingtab.xml b/app/src/main/res/layout/viewholder_chose_tabs.xml similarity index 100% rename from app/src/main/res/layout/dialog_contentsettingtab.xml rename to app/src/main/res/layout/viewholder_chose_tabs.xml diff --git a/app/src/main/res/xml/appearance_settings.xml b/app/src/main/res/xml/appearance_settings.xml index 4e638e371..8835e7705 100644 --- a/app/src/main/res/xml/appearance_settings.xml +++ b/app/src/main/res/xml/appearance_settings.xml @@ -28,7 +28,7 @@ android:summary="@string/caption_setting_description"/>