Code reviewed
This commit is contained in:
parent
f29fa939ab
commit
8dde25532a
|
@ -4,6 +4,7 @@ import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
@ -92,4 +93,10 @@ public abstract class BaseFragment extends Fragment {
|
||||||
activity.getSupportActionBar().setTitle(title);
|
activity.getSupportActionBar().setTitle(title);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected FragmentManager getFM() {
|
||||||
|
return getParentFragment() == null
|
||||||
|
? getFragmentManager()
|
||||||
|
: getParentFragment().getFragmentManager();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
// Fragment's LifeCycle
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
@ -132,26 +121,22 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setFirstTitle() {
|
private void setFirstTitle() {
|
||||||
if((tabs.size()>0)&&activity != null) {
|
if((tabs.size() > 0)
|
||||||
String tabNumber = tabs.get(0);
|
&& activity != null) {
|
||||||
|
String tabInformation = tabs.get(0);
|
||||||
if (tabNumber.startsWith(TAB_NUMBER_KIOSK + "\t")) {
|
if (tabInformation.startsWith(TAB_NUMBER_KIOSK + "\t")) {
|
||||||
String kiosk[] = tabNumber.split("\t");
|
String kiosk[] = tabInformation.split("\t");
|
||||||
if (kiosk.length == 2) {
|
if (kiosk.length == 2) {
|
||||||
try {
|
setTitle(kiosk[1]);
|
||||||
setTitle(kiosk[1]);
|
|
||||||
} catch (Exception e) {
|
|
||||||
//ignore this. It WILL be thrown while the service is changed.
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} 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) {
|
if(channelInfo.length==4) {
|
||||||
setTitle(channelInfo[2]);
|
setTitle(channelInfo[2]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
switch (tabNumber) {
|
switch (tabInformation) {
|
||||||
case TAB_NUMBER_BLANK:
|
case TAB_NUMBER_BLANK:
|
||||||
setTitle(getString(R.string.app_name));
|
setTitle(getString(R.string.app_name));
|
||||||
break;
|
break;
|
||||||
|
@ -176,26 +161,22 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
|
||||||
|
|
||||||
private void setIcons() {
|
private void setIcons() {
|
||||||
for (int i = 0; i < tabs.size(); i++) {
|
for (int i = 0; i < tabs.size(); i++) {
|
||||||
String tabNumber = tabs.get(i);
|
String tabInformation = tabs.get(i);
|
||||||
|
|
||||||
TabLayout.Tab tabToSet = tabLayout.getTabAt(i);
|
TabLayout.Tab tabToSet = tabLayout.getTabAt(i);
|
||||||
Context c = getContext();
|
Context c = getContext();
|
||||||
|
|
||||||
if (tabToSet != null && c != null) {
|
if (tabToSet != null && c != null) {
|
||||||
|
|
||||||
if (tabNumber.startsWith(TAB_NUMBER_KIOSK + "\t")) {
|
if (tabInformation.startsWith(TAB_NUMBER_KIOSK + "\t")) {
|
||||||
String kiosk[] = tabNumber.split("\t");
|
String kiosk[] = tabInformation.split("\t");
|
||||||
if (kiosk.length == 2) {
|
if (kiosk.length == 2) {
|
||||||
try {
|
tabToSet.setIcon(KioskTranslator.getKioskIcons(kiosk[1], getContext()));
|
||||||
tabToSet.setIcon(KioskTranslator.getKioskIcons(kiosk[1], getContext()));
|
|
||||||
} catch (Exception e) {
|
|
||||||
//ignore this. It WILL be thrown while the service is changed.
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} 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));
|
tabToSet.setIcon(ThemeHelper.resolveResourceIdFromAttr(getContext(), R.attr.ic_channel));
|
||||||
} else {
|
} else {
|
||||||
switch (tabNumber) {
|
switch (tabInformation) {
|
||||||
case TAB_NUMBER_BLANK:
|
case TAB_NUMBER_BLANK:
|
||||||
tabToSet.setIcon(ThemeHelper.resolveResourceIdFromAttr(getContext(), R.attr.ic_hot));
|
tabToSet.setIcon(ThemeHelper.resolveResourceIdFromAttr(getContext(), R.attr.ic_hot));
|
||||||
break;
|
break;
|
||||||
|
@ -238,15 +219,15 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
|
||||||
"none", "", R.string.app_ui_crash));
|
"none", "", R.string.app_ui_crash));
|
||||||
}
|
}
|
||||||
|
|
||||||
for(String tabNumber:tabsArray) {
|
for(String tabInformation:tabsArray) {
|
||||||
if(tabNumber.equals(TAB_NUMBER_KIOSK)) {
|
if(tabInformation.equals(TAB_NUMBER_KIOSK)) {
|
||||||
if (kl != null) {
|
if (kl != null) {
|
||||||
for(String ks : kl.getAvailableKiosks()) {
|
for(String ks : kl.getAvailableKiosks()) {
|
||||||
tabs.add(tabNumber+"\t"+ks);
|
tabs.add(tabInformation+"\t"+ks);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
tabs.add(tabNumber);
|
tabs.add(tabInformation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -308,10 +289,10 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Fragment getItem(int position) {
|
public Fragment getItem(int position) {
|
||||||
String tabNumber = tabs.get(position);
|
String tabInformation = tabs.get(position);
|
||||||
|
|
||||||
if(tabNumber.startsWith(TAB_NUMBER_KIOSK + "\t")) {
|
if(tabInformation.startsWith(TAB_NUMBER_KIOSK + "\t")) {
|
||||||
String kiosk[] = tabNumber.split("\t");
|
String kiosk[] = tabInformation.split("\t");
|
||||||
if(kiosk.length==2) {
|
if(kiosk.length==2) {
|
||||||
KioskFragment fragment = null;
|
KioskFragment fragment = null;
|
||||||
try {
|
try {
|
||||||
|
@ -326,8 +307,8 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
|
||||||
"none", "", R.string.app_ui_crash));
|
"none", "", R.string.app_ui_crash));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} 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) {
|
if(channelInfo.length==4) {
|
||||||
ChannelFragment fragment = ChannelFragment.getInstance(Integer.parseInt(channelInfo[3]), channelInfo[1], channelInfo[2]);
|
ChannelFragment fragment = ChannelFragment.getInstance(Integer.parseInt(channelInfo[3]), channelInfo[1], channelInfo[2]);
|
||||||
fragment.useAsFrontPage(true);
|
fragment.useAsFrontPage(true);
|
||||||
|
@ -336,7 +317,7 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
|
||||||
return new BlankFragment();
|
return new BlankFragment();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
switch (tabNumber) {
|
switch (tabInformation) {
|
||||||
case TAB_NUMBER_BLANK:
|
case TAB_NUMBER_BLANK:
|
||||||
return new BlankFragment();
|
return new BlankFragment();
|
||||||
case TAB_NUMBER_SUBSCIRPTIONS:
|
case TAB_NUMBER_SUBSCIRPTIONS:
|
||||||
|
@ -375,7 +356,10 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroyItem(ViewGroup container, int position, Object object) {
|
public void destroyItem(ViewGroup container, int position, Object object) {
|
||||||
getFragmentManager().beginTransaction().remove((Fragment)object).commitNowAllowingStateLoss();
|
getFragmentManager()
|
||||||
|
.beginTransaction()
|
||||||
|
.remove((Fragment)object)
|
||||||
|
.commitNowAllowingStateLoss();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,28 +101,20 @@ public final class BookmarkFragment
|
||||||
itemListAdapter.setSelectedListener(new OnClickGesture<LocalItem>() {
|
itemListAdapter.setSelectedListener(new OnClickGesture<LocalItem>() {
|
||||||
@Override
|
@Override
|
||||||
public void selected(LocalItem selectedItem) {
|
public void selected(LocalItem selectedItem) {
|
||||||
try {
|
final FragmentManager fragmentManager = getFM();
|
||||||
// Requires the parent fragment to find holder for fragment replacement
|
|
||||||
final FragmentManager fragmentManager =
|
|
||||||
getParentFragment() == null
|
|
||||||
? getFragmentManager()
|
|
||||||
: getParentFragment().getFragmentManager();
|
|
||||||
|
|
||||||
if (selectedItem instanceof PlaylistMetadataEntry) {
|
if (selectedItem instanceof PlaylistMetadataEntry) {
|
||||||
final PlaylistMetadataEntry entry = ((PlaylistMetadataEntry) selectedItem);
|
final PlaylistMetadataEntry entry = ((PlaylistMetadataEntry) selectedItem);
|
||||||
NavigationHelper.openLocalPlaylistFragment(fragmentManager, entry.uid,
|
NavigationHelper.openLocalPlaylistFragment(fragmentManager, entry.uid,
|
||||||
entry.name);
|
entry.name);
|
||||||
|
|
||||||
} else if (selectedItem instanceof PlaylistRemoteEntity) {
|
} else if (selectedItem instanceof PlaylistRemoteEntity) {
|
||||||
final PlaylistRemoteEntity entry = ((PlaylistRemoteEntity) selectedItem);
|
final PlaylistRemoteEntity entry = ((PlaylistRemoteEntity) selectedItem);
|
||||||
NavigationHelper.openPlaylistFragment(
|
NavigationHelper.openPlaylistFragment(
|
||||||
fragmentManager,
|
fragmentManager,
|
||||||
entry.getServiceId(),
|
entry.getServiceId(),
|
||||||
entry.getUrl(),
|
entry.getUrl(),
|
||||||
entry.getName());
|
entry.getName());
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
ErrorActivity.reportUiError((AppCompatActivity) getActivity(), e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -117,12 +117,6 @@ public class FeedFragment extends BaseListFragment<List<SubscriptionEntity>, Voi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*@Override
|
|
||||||
protected RecyclerView.LayoutManager getListLayoutManager() {
|
|
||||||
boolean isPortrait = getResources().getDisplayMetrics().heightPixels > getResources().getDisplayMetrics().widthPixels;
|
|
||||||
return new GridLayoutManager(activity, isPortrait ? 1 : 2);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
super.onCreateOptionsMenu(menu, inflater);
|
super.onCreateOptionsMenu(menu, inflater);
|
||||||
|
|
|
@ -140,8 +140,12 @@ public class StatisticsPlaylistFragment
|
||||||
public void selected(LocalItem selectedItem) {
|
public void selected(LocalItem selectedItem) {
|
||||||
if (selectedItem instanceof StreamStatisticsEntry) {
|
if (selectedItem instanceof StreamStatisticsEntry) {
|
||||||
final StreamStatisticsEntry item = (StreamStatisticsEntry) selectedItem;
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -328,20 +328,13 @@ public class SubscriptionFragment extends BaseStateFragment<List<SubscriptionEnt
|
||||||
});
|
});
|
||||||
|
|
||||||
//noinspection ConstantConditions
|
//noinspection ConstantConditions
|
||||||
whatsNewItemListHeader.setOnClickListener(v ->
|
whatsNewItemListHeader.setOnClickListener(v -> {
|
||||||
{
|
|
||||||
FragmentManager fragmentManager = getFM();
|
FragmentManager fragmentManager = getFM();
|
||||||
NavigationHelper.openWhatsNewFragment(fragmentManager);
|
NavigationHelper.openWhatsNewFragment(fragmentManager);
|
||||||
});
|
});
|
||||||
importExportListHeader.setOnClickListener(v -> importExportOptions.switchState());
|
importExportListHeader.setOnClickListener(v -> importExportOptions.switchState());
|
||||||
}
|
}
|
||||||
|
|
||||||
private FragmentManager getFM() {
|
|
||||||
return getParentFragment() == null
|
|
||||||
? getFragmentManager()
|
|
||||||
: getParentFragment().getFragmentManager();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void resetFragment() {
|
private void resetFragment() {
|
||||||
if (disposables != null) disposables.clear();
|
if (disposables != null) disposables.clear();
|
||||||
if (infoListAdapter != null) infoListAdapter.clearStreamItemList();
|
if (infoListAdapter != null) infoListAdapter.clearStreamItemList();
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,63 +1,50 @@
|
||||||
package org.schabi.newpipe.settings;
|
package org.schabi.newpipe.settings;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.app.Dialog;
|
||||||
|
import android.content.DialogInterface;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.ColorStateList;
|
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.os.Bundle;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.design.widget.FloatingActionButton;
|
import android.support.design.widget.FloatingActionButton;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.support.v7.preference.PreferenceManager;
|
|
||||||
import android.support.v7.widget.CardView;
|
import android.support.v7.widget.CardView;
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.support.v7.widget.helper.ItemTouchHelper;
|
import android.support.v7.widget.helper.ItemTouchHelper;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
import android.view.DragEvent;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.FrameLayout;
|
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import org.schabi.newpipe.R;
|
import org.schabi.newpipe.R;
|
||||||
import org.schabi.newpipe.database.LocalItem;
|
import org.schabi.newpipe.info_list.InfoItemDialog;
|
||||||
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.util.ThemeHelper;
|
import org.schabi.newpipe.util.ThemeHelper;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
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<String> usedTabs = new ArrayList<>();
|
List<String> selectedTabs = new ArrayList<>();
|
||||||
private String saveString;
|
private String saveString;
|
||||||
public String[] allTabs = new String[7];
|
public String[] availableTabs = new String[7];
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
((AppCompatActivity)getContext()).getSupportActionBar().setTitle(R.string.main_page_content);
|
((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();
|
initUsedTabs();
|
||||||
initButton(rootView);
|
initButton(rootView);
|
||||||
|
|
||||||
usedTabsView = rootView.findViewById(R.id.usedTabs);
|
selectedTabsView = rootView.findViewById(R.id.usedTabs);
|
||||||
usedTabsView.setLayoutManager(new LinearLayoutManager(getContext()));
|
selectedTabsView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||||
usedAdapter = new ContentSettingsMain.UsedAdapter();
|
selectedTabsAdapter = new ChoseTabsFragment.SelectedTabsAdapter();
|
||||||
|
|
||||||
|
|
||||||
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(getItemTouchCallback());
|
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(getItemTouchCallback());
|
||||||
itemTouchHelper.attachToRecyclerView(usedTabsView);
|
itemTouchHelper.attachToRecyclerView(selectedTabsView);
|
||||||
usedAdapter.setOnItemSelectedListener(itemTouchHelper);
|
selectedTabsAdapter.setOnItemSelectedListener(itemTouchHelper);
|
||||||
|
|
||||||
usedTabsView.setAdapter(usedAdapter);
|
selectedTabsView.setAdapter(selectedTabsAdapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveChanges() {
|
private void saveChanges() {
|
||||||
StringBuilder save = new StringBuilder();
|
StringBuilder save = new StringBuilder();
|
||||||
if(usedTabs.size()==0) {
|
if(selectedTabs.size()==0) {
|
||||||
save = new StringBuilder("0");
|
save = new StringBuilder("0");
|
||||||
} else {
|
} else {
|
||||||
for(String s: usedTabs) {
|
for(String s: selectedTabs) {
|
||||||
save.append(s);
|
save.append(s);
|
||||||
save.append("\n");
|
save.append("\n");
|
||||||
}
|
}
|
||||||
|
@ -107,26 +94,30 @@ public class ContentSettingsMain extends Fragment {
|
||||||
private void initUsedTabs() {
|
private void initUsedTabs() {
|
||||||
String save = android.preference.PreferenceManager.getDefaultSharedPreferences(getContext()).getString("saveUsedTabs", "1\n2\n4\n");
|
String save = android.preference.PreferenceManager.getDefaultSharedPreferences(getContext()).getString("saveUsedTabs", "1\n2\n4\n");
|
||||||
String tabs[] = save.trim().split("\n");
|
String tabs[] = save.trim().split("\n");
|
||||||
usedTabs.addAll(Arrays.asList(tabs));
|
selectedTabs.addAll(Arrays.asList(tabs));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tabNames() {
|
private void tabNames() {
|
||||||
allTabs[0] = getString(R.string.blank_page_summary);
|
availableTabs[0] = getString(R.string.blank_page_summary);
|
||||||
allTabs[1] = getString(R.string.kiosk_page_summary);
|
availableTabs[1] = getString(R.string.kiosk_page_summary);
|
||||||
allTabs[2] = getString(R.string.subscription_page_summary);
|
availableTabs[2] = getString(R.string.subscription_page_summary);
|
||||||
allTabs[3] = getString(R.string.feed_page_summary);
|
availableTabs[3] = getString(R.string.feed_page_summary);
|
||||||
allTabs[4] = getString(R.string.tab_bookmarks);
|
availableTabs[4] = getString(R.string.tab_bookmarks);
|
||||||
allTabs[5] = getString(R.string.title_activity_history);
|
availableTabs[5] = getString(R.string.title_activity_history);
|
||||||
allTabs[6] = getString(R.string.channel_page_summary);
|
availableTabs[6] = getString(R.string.channel_page_summary);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initButton(View rootView) {
|
private void initButton(View rootView) {
|
||||||
FloatingActionButton fab = rootView.findViewById(R.id.floatingActionButton);
|
FloatingActionButton fab = rootView.findViewById(R.id.floatingActionButton);
|
||||||
fab.setImageResource(ThemeHelper.getIconByAttr(R.attr.ic_add, getContext()));
|
fab.setImageResource(ThemeHelper.getIconByAttr(R.attr.ic_add, getContext()));
|
||||||
fab.setOnClickListener(v -> {
|
fab.setOnClickListener(v -> {
|
||||||
ContentSettingsMainDialog contentSettingsMainDialog = new ContentSettingsMainDialog();
|
Dialog.OnClickListener onClickListener = (dialog, which) -> addTab(which);
|
||||||
contentSettingsMainDialog.setOnAddListener(ContentSettingsMain.this::addTab);
|
|
||||||
contentSettingsMainDialog.show(getFragmentManager(), "select_channel");
|
new AddTabsDialog(getContext(),
|
||||||
|
getString(R.string.tab_chose),
|
||||||
|
availableTabs,
|
||||||
|
onClickListener)
|
||||||
|
.show();
|
||||||
});
|
});
|
||||||
|
|
||||||
TypedValue typedValue = new TypedValue();
|
TypedValue typedValue = new TypedValue();
|
||||||
|
@ -138,23 +129,21 @@ public class ContentSettingsMain extends Fragment {
|
||||||
|
|
||||||
private void addTab(int position) {
|
private void addTab(int position) {
|
||||||
if(position!=6) {
|
if(position!=6) {
|
||||||
usedTabs.add(String.valueOf(position));
|
selectedTabs.add(String.valueOf(position));
|
||||||
usedAdapter.notifyDataSetChanged();
|
selectedTabsAdapter.notifyDataSetChanged();
|
||||||
saveChanges();
|
saveChanges();
|
||||||
} else {
|
} else {
|
||||||
SelectChannelFragment selectChannelFragment = new SelectChannelFragment();
|
SelectChannelFragment selectChannelFragment = new SelectChannelFragment();
|
||||||
selectChannelFragment.setOnSelectedLisener((String url, String name, int service) -> {
|
selectChannelFragment.setOnSelectedLisener((String url, String name, int service) -> {
|
||||||
usedTabs.add(position+"\t"+url+"\t"+name+"\t"+service);
|
selectedTabs.add(position+"\t"+url+"\t"+name+"\t"+service);
|
||||||
usedAdapter.notifyDataSetChanged();
|
selectedTabsAdapter.notifyDataSetChanged();
|
||||||
saveChanges();
|
saveChanges();
|
||||||
});
|
});
|
||||||
selectChannelFragment.show(getFragmentManager(), "select_channel");
|
selectChannelFragment.show(getFragmentManager(), "select_channel");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class UsedAdapter extends RecyclerView.Adapter<ContentSettingsMain.UsedAdapter.TabViewHolder>{
|
public class SelectedTabsAdapter extends RecyclerView.Adapter<ChoseTabsFragment.SelectedTabsAdapter.TabViewHolder>{
|
||||||
// ... code from gist
|
|
||||||
|
|
||||||
private ItemTouchHelper itemTouchHelper;
|
private ItemTouchHelper itemTouchHelper;
|
||||||
|
|
||||||
public void setOnItemSelectedListener(ItemTouchHelper mItemTouchHelper) {
|
public void setOnItemSelectedListener(ItemTouchHelper mItemTouchHelper) {
|
||||||
|
@ -162,29 +151,29 @@ public class ContentSettingsMain extends Fragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void swapItems(int fromPosition, int toPosition) {
|
public void swapItems(int fromPosition, int toPosition) {
|
||||||
String temp = usedTabs.get(fromPosition);
|
String temp = selectedTabs.get(fromPosition);
|
||||||
usedTabs.set(fromPosition, usedTabs.get(toPosition));
|
selectedTabs.set(fromPosition, selectedTabs.get(toPosition));
|
||||||
usedTabs.set(toPosition, temp);
|
selectedTabs.set(toPosition, temp);
|
||||||
notifyItemMoved(fromPosition, toPosition);
|
notifyItemMoved(fromPosition, toPosition);
|
||||||
saveChanges();
|
saveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ContentSettingsMain.UsedAdapter.TabViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
public ChoseTabsFragment.SelectedTabsAdapter.TabViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||||
|
|
||||||
LayoutInflater inflater = LayoutInflater.from(getContext());
|
LayoutInflater inflater = LayoutInflater.from(getContext());
|
||||||
View view = inflater.inflate(R.layout.dialog_contentsettingtab, parent, false);
|
View view = inflater.inflate(R.layout.viewholder_chose_tabs, parent, false);
|
||||||
return new ContentSettingsMain.UsedAdapter.TabViewHolder(view);
|
return new ChoseTabsFragment.SelectedTabsAdapter.TabViewHolder(view);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
holder.bind(position, holder);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
return usedTabs.size();
|
return selectedTabs.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
class TabViewHolder extends RecyclerView.ViewHolder {
|
class TabViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
@ -203,21 +192,21 @@ public class ContentSettingsMain extends Fragment {
|
||||||
view = itemView;
|
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.setImageResource(ThemeHelper.getIconByAttr(R.attr.drag_handle, getContext()));
|
||||||
handle.setOnTouchListener(getOnTouchListener(holder));
|
handle.setOnTouchListener(getOnTouchListener(holder));
|
||||||
|
|
||||||
view.setOnLongClickListener(getOnLongClickListener(holder));
|
view.setOnLongClickListener(getOnLongClickListener(holder));
|
||||||
|
|
||||||
if(usedTabs.get(position).startsWith("6\t")) {
|
if(selectedTabs.get(position).startsWith("6\t")) {
|
||||||
String channelInfo[] = usedTabs.get(position).split("\t");
|
String channelInfo[] = selectedTabs.get(position).split("\t");
|
||||||
String channelName = "";
|
String channelName = "";
|
||||||
if(channelInfo.length==4) channelName = channelInfo[2];
|
if(channelInfo.length==4) channelName = channelInfo[2];
|
||||||
String textToSet = allTabs[6]+": "+channelName;
|
String textToSet = availableTabs[6]+": "+channelName;
|
||||||
text.setText(textToSet);
|
text.setText(textToSet);
|
||||||
} else {
|
} 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) {
|
private View.OnLongClickListener getOnLongClickListener(TabViewHolder holder) {
|
||||||
return (view) -> {
|
return (view) -> {
|
||||||
int position = holder.getAdapterPosition();
|
int position = holder.getAdapterPosition();
|
||||||
usedTabs.remove(position);
|
selectedTabs.remove(position);
|
||||||
notifyItemRemoved(position);
|
notifyItemRemoved(position);
|
||||||
saveChanges();
|
saveChanges();
|
||||||
return false;
|
return false;
|
||||||
|
@ -261,13 +250,13 @@ public class ContentSettingsMain extends Fragment {
|
||||||
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder source,
|
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder source,
|
||||||
RecyclerView.ViewHolder target) {
|
RecyclerView.ViewHolder target) {
|
||||||
if (source.getItemViewType() != target.getItemViewType() ||
|
if (source.getItemViewType() != target.getItemViewType() ||
|
||||||
usedAdapter == null) {
|
selectedTabsAdapter == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final int sourceIndex = source.getAdapterPosition();
|
final int sourceIndex = source.getAdapterPosition();
|
||||||
final int targetIndex = target.getAdapterPosition();
|
final int targetIndex = target.getAdapterPosition();
|
||||||
usedAdapter.swapItems(sourceIndex, targetIndex);
|
selectedTabsAdapter.swapItems(sourceIndex, targetIndex);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<AllAdapter.TabViewHolder>{
|
|
||||||
|
|
||||||
@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);
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,28 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:padding="13dp">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/titleTextView"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginBottom="10dp"
|
|
||||||
android:layout_marginEnd="5dp"
|
|
||||||
android:layout_marginLeft="19dp"
|
|
||||||
android:layout_marginRight="19dp"
|
|
||||||
android:layout_marginStart="10dp"
|
|
||||||
android:layout_marginTop="5dp"
|
|
||||||
android:text="@string/tab_chose"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceLarge" />
|
|
||||||
|
|
||||||
<android.support.v7.widget.RecyclerView
|
|
||||||
android:id="@+id/allTabs"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_below="@+id/titleTextView"
|
|
||||||
android:layout_centerHorizontal="true" />
|
|
||||||
|
|
||||||
</RelativeLayout>
|
|
|
@ -28,7 +28,7 @@
|
||||||
android:summary="@string/caption_setting_description"/>
|
android:summary="@string/caption_setting_description"/>
|
||||||
|
|
||||||
<PreferenceScreen
|
<PreferenceScreen
|
||||||
android:fragment="org.schabi.newpipe.settings.ContentSettingsMain"
|
android:fragment="org.schabi.newpipe.settings.ChoseTabsFragment"
|
||||||
android:summary="@string/main_page_content_summary"
|
android:summary="@string/main_page_content_summary"
|
||||||
android:key="@string/main_page_content_key"
|
android:key="@string/main_page_content_key"
|
||||||
android:title="@string/main_page_content"/>
|
android:title="@string/main_page_content"/>
|
||||||
|
|
Loading…
Reference in New Issue