From 0d2296917a791d26845ffdd7c4040480c867a901 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Sat, 23 Sep 2017 17:39:04 +0200 Subject: [PATCH 01/21] creating first prototype of kiosk page --- app/build.gradle | 2 +- .../newpipe/fragments/MainFragment.java | 17 +- .../fragments/list/kisok/KioskFragment.java | 148 ++++++++++++++++++ .../schabi/newpipe/util/ExtractorHelper.java | 19 +++ app/src/main/res/layout/fragment_kiosk.xml | 64 ++++++++ app/src/main/res/layout/kiosk_header.xml | 23 +++ app/src/main/res/values/dimens.xml | 2 + 7 files changed, 273 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/org/schabi/newpipe/fragments/list/kisok/KioskFragment.java create mode 100644 app/src/main/res/layout/fragment_kiosk.xml create mode 100644 app/src/main/res/layout/kiosk_header.xml diff --git a/app/build.gradle b/app/build.gradle index 941dc72d7..742b00d4b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -45,7 +45,7 @@ dependencies { exclude module: 'support-annotations' } - compile 'com.github.TeamNewPipe:NewPipeExtractor:7ae274b' + compile 'com.github.TeamNewPipe:NewPipeExtractor:7fffef5' testCompile 'junit:junit:4.12' testCompile 'org.mockito:mockito-core:1.10.19' 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 236f95968..6f313aee0 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java @@ -18,11 +18,16 @@ import android.view.ViewGroup; import org.schabi.newpipe.BaseFragment; import org.schabi.newpipe.R; +import org.schabi.newpipe.fragments.list.kisok.KioskFragment; import org.schabi.newpipe.fragments.subscription.SubscriptionFragment; import org.schabi.newpipe.util.NavigationHelper; public class MainFragment extends BaseFragment implements TabLayout.OnTabSelectedListener { private ViewPager viewPager; + private boolean showBlankTab = false; + + //todo: FIX THIS URGENTLY + public int currentServiceId = 0; //for youtube /*////////////////////////////////////////////////////////////////////////// // Fragment's LifeCycle @@ -115,7 +120,17 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte case 1: return new SubscriptionFragment(); default: - return new BlankFragment(); + if(showBlankTab) { + return new BlankFragment(); + } else { + try { + return KioskFragment.getInstance(currentServiceId); + } catch (Exception e) { + //todo: replace this with propper error reporting + e.printStackTrace(); + return new BlankFragment(); + } + } } } diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/kisok/KioskFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/kisok/KioskFragment.java new file mode 100644 index 000000000..a1e5a960f --- /dev/null +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/kisok/KioskFragment.java @@ -0,0 +1,148 @@ +package org.schabi.newpipe.fragments.list.kisok; + +import android.os.Bundle; +import android.preference.PreferenceManager; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.text.TextUtils; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import org.schabi.newpipe.R; +import org.schabi.newpipe.extractor.ListExtractor; +import org.schabi.newpipe.extractor.NewPipe; +import org.schabi.newpipe.extractor.StreamingService; +import org.schabi.newpipe.extractor.UrlIdHandler; +import org.schabi.newpipe.extractor.exceptions.ExtractionException; +import org.schabi.newpipe.extractor.kiosk.KioskInfo; +import org.schabi.newpipe.extractor.kiosk.KioskList; +import org.schabi.newpipe.extractor.playlist.PlaylistInfo; +import org.schabi.newpipe.fragments.list.BaseListInfoFragment; +import org.schabi.newpipe.fragments.list.channel.ChannelFragment; +import org.schabi.newpipe.report.UserAction; +import org.schabi.newpipe.util.ExtractorHelper; +import org.schabi.newpipe.util.NavigationHelper; + +import io.reactivex.Single; + +import static org.schabi.newpipe.util.AnimationUtils.animateView; + +/** + * Created by Christian Schabesberger on 23.09.17. + * + * Copyright (C) Christian Schabesberger 2017 + * KioskFragment.java is part of NewPipe. + * + * NewPipe is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * NewPipe is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with OpenHitboxStreams. If not, see . + */ + +public class KioskFragment extends BaseListInfoFragment { + + + /*////////////////////////////////////////////////////////////////////////// + // Views + //////////////////////////////////////////////////////////////////////////*/ + + private View headerRootLayout; + private TextView headerTitleView; + + public static KioskFragment getInstance(int serviceId) + throws ExtractionException { + KioskFragment instance = new KioskFragment(); + StreamingService service = NewPipe.getService(serviceId); + String defaultKioskType = service.getKioskList().getDefaultKioskType(); + UrlIdHandler defaultKioskTypeUrlIdHandler = service.getKioskList() + .getUrlIdHandlerByType(defaultKioskType); + instance.setInitialData(serviceId, + defaultKioskTypeUrlIdHandler.getUrl(defaultKioskType), + defaultKioskType); + return instance; + } + + /*////////////////////////////////////////////////////////////////////////// + // LifeCycle + //////////////////////////////////////////////////////////////////////////*/ + + @Override + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + return inflater.inflate(R.layout.fragment_kiosk, container, false); + } + + /*////////////////////////////////////////////////////////////////////////// + // Init + //////////////////////////////////////////////////////////////////////////*/ + + protected View getListHeader() { + headerRootLayout = activity.getLayoutInflater().inflate(R.layout.kiosk_header, itemsList, false); + headerTitleView = headerRootLayout.findViewById(R.id.kiosk_title_view); + + return headerRootLayout; + } + + /*////////////////////////////////////////////////////////////////////////// + // Load and handle + //////////////////////////////////////////////////////////////////////////*/ + + @Override + public Single loadResult(boolean forceReload) { + String contentCountry = PreferenceManager + .getDefaultSharedPreferences(activity) + .getString(getString(R.string.search_language_key), + getString(R.string.default_language_value)); + return ExtractorHelper.getKioskInfo(serviceId, url, contentCountry, forceReload); + } + + @Override + public Single loadMoreItemsLogic() { + return ExtractorHelper.getMoreKisokItems(serviceId, url, currentNextItemsUrl); + } + + /*////////////////////////////////////////////////////////////////////////// + // Contract + //////////////////////////////////////////////////////////////////////////*/ + + @Override + public void showLoading() { + super.showLoading(); + animateView(headerRootLayout, false, 200); + animateView(itemsList, false, 100); + } + + @Override + public void handleResult(@NonNull final KioskInfo result) { + super.handleResult(result); + + animateView(headerRootLayout, true, 100); + headerTitleView.setText(result.type); + + if (!result.errors.isEmpty()) { + showSnackBarError(result.errors, + UserAction.REQUESTED_PLAYLIST, + NewPipe.getNameOfService(result.service_id), result.url, 0); + } + } + + @Override + public void handleNextItems(ListExtractor.NextItemsResult result) { + super.handleNextItems(result); + + if (!result.errors.isEmpty()) { + showSnackBarError(result.errors, + UserAction.REQUESTED_PLAYLIST, NewPipe.getNameOfService(serviceId) + , "Get next page of: " + url, 0); + } + } +} diff --git a/app/src/main/java/org/schabi/newpipe/util/ExtractorHelper.java b/app/src/main/java/org/schabi/newpipe/util/ExtractorHelper.java index 5cf9f057e..856769da8 100644 --- a/app/src/main/java/org/schabi/newpipe/util/ExtractorHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/ExtractorHelper.java @@ -26,6 +26,7 @@ import org.schabi.newpipe.extractor.Info; import org.schabi.newpipe.extractor.ListExtractor.NextItemsResult; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.channel.ChannelInfo; +import org.schabi.newpipe.extractor.kiosk.KioskInfo; import org.schabi.newpipe.extractor.playlist.PlaylistInfo; import org.schabi.newpipe.extractor.search.SearchEngine; import org.schabi.newpipe.extractor.search.SearchResult; @@ -124,6 +125,24 @@ public final class ExtractorHelper { }); } + public static Single getKioskInfo(final int serviceId, final String url, final String contentCountry, boolean forceLoad) { + return checkCache(forceLoad, serviceId, url, Single.fromCallable(new Callable() { + @Override + public KioskInfo call() throws Exception { + return KioskInfo.getInfo(NewPipe.getService(serviceId), url, contentCountry); + } + })); + } + + public static Single getMoreKisokItems(final int serviceId, final String url, final String nextStreamsUrl) { + return Single.fromCallable(new Callable() { + @Override + public NextItemsResult call() throws Exception { + return KioskInfo.getMoreItems(NewPipe.getService(serviceId), url, nextStreamsUrl); + } + }); + } + /*////////////////////////////////////////////////////////////////////////// // Utils //////////////////////////////////////////////////////////////////////////*/ diff --git a/app/src/main/res/layout/fragment_kiosk.xml b/app/src/main/res/layout/fragment_kiosk.xml new file mode 100644 index 000000000..a85c30cb1 --- /dev/null +++ b/app/src/main/res/layout/fragment_kiosk.xml @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/kiosk_header.xml b/app/src/main/res/layout/kiosk_header.xml new file mode 100644 index 000000000..c161ca83d --- /dev/null +++ b/app/src/main/res/layout/kiosk_header.xml @@ -0,0 +1,23 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 32e300ca1..1c5265b8b 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -67,4 +67,6 @@ 24dp 28dp + + 30sp From f6c624b59a56904ddbeba1bad2a19bfa5d024c49 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Mon, 25 Sep 2017 12:49:14 +0200 Subject: [PATCH 02/21] make name translatable, fix tab on items, remove back button s/kisok/kiosk/g --- app/build.gradle | 2 +- .../newpipe/fragments/MainFragment.java | 2 +- .../list/{kisok => kiosk}/KioskFragment.java | 52 +++++++++++++++---- .../schabi/newpipe/util/ExtractorHelper.java | 2 +- 4 files changed, 44 insertions(+), 14 deletions(-) rename app/src/main/java/org/schabi/newpipe/fragments/list/{kisok => kiosk}/KioskFragment.java (73%) diff --git a/app/build.gradle b/app/build.gradle index 8bb0d19b2..a3ad71b5c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -48,7 +48,7 @@ dependencies { exclude module: 'support-annotations' } - compile 'com.github.TeamNewPipe:NewPipeExtractor:7fffef5' + compile 'com.github.TeamNewPipe:NewPipeExtractor:466d87c' testCompile 'junit:junit:4.12' testCompile 'org.mockito:mockito-core:1.10.19' 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 6f313aee0..3ca14f552 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java @@ -18,7 +18,7 @@ import android.view.ViewGroup; import org.schabi.newpipe.BaseFragment; import org.schabi.newpipe.R; -import org.schabi.newpipe.fragments.list.kisok.KioskFragment; +import org.schabi.newpipe.fragments.list.kiosk.KioskFragment; import org.schabi.newpipe.fragments.subscription.SubscriptionFragment; import org.schabi.newpipe.util.NavigationHelper; diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/kisok/KioskFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java similarity index 73% rename from app/src/main/java/org/schabi/newpipe/fragments/list/kisok/KioskFragment.java rename to app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java index a1e5a960f..932cf2a44 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/kisok/KioskFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java @@ -1,11 +1,13 @@ -package org.schabi.newpipe.fragments.list.kisok; +package org.schabi.newpipe.fragments.list.kiosk; import android.os.Bundle; import android.preference.PreferenceManager; import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import android.text.TextUtils; +import android.support.v7.app.ActionBar; import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; @@ -17,10 +19,9 @@ import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.UrlIdHandler; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.kiosk.KioskInfo; -import org.schabi.newpipe.extractor.kiosk.KioskList; -import org.schabi.newpipe.extractor.playlist.PlaylistInfo; +import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.fragments.list.BaseListInfoFragment; -import org.schabi.newpipe.fragments.list.channel.ChannelFragment; +import org.schabi.newpipe.info_list.InfoItemBuilder; import org.schabi.newpipe.report.UserAction; import org.schabi.newpipe.util.ExtractorHelper; import org.schabi.newpipe.util.NavigationHelper; @@ -63,12 +64,12 @@ public class KioskFragment extends BaseListInfoFragment { throws ExtractionException { KioskFragment instance = new KioskFragment(); StreamingService service = NewPipe.getService(serviceId); - String defaultKioskType = service.getKioskList().getDefaultKioskType(); + String defaultKioskId = service.getKioskList().getDefaultKioskId(); UrlIdHandler defaultKioskTypeUrlIdHandler = service.getKioskList() - .getUrlIdHandlerByType(defaultKioskType); + .getUrlIdHandlerByType(defaultKioskId); instance.setInitialData(serviceId, - defaultKioskTypeUrlIdHandler.getUrl(defaultKioskType), - defaultKioskType); + defaultKioskTypeUrlIdHandler.getUrl(defaultKioskId), + defaultKioskId); return instance; } @@ -81,6 +82,20 @@ public class KioskFragment extends BaseListInfoFragment { return inflater.inflate(R.layout.fragment_kiosk, container, false); } + /*////////////////////////////////////////////////////////////////////////// + // Menu + //////////////////////////////////////////////////////////////////////////*/ + + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + super.onCreateOptionsMenu(menu, inflater); + ActionBar supportActionBar = activity.getSupportActionBar(); + if (supportActionBar != null) { + supportActionBar.setDisplayShowTitleEnabled(false); + supportActionBar.setDisplayHomeAsUpEnabled(false); + } + } + /*////////////////////////////////////////////////////////////////////////// // Init //////////////////////////////////////////////////////////////////////////*/ @@ -92,6 +107,21 @@ public class KioskFragment extends BaseListInfoFragment { return headerRootLayout; } + @Override + public void initListeners() { + // We have to override this because the default implementation of this function calls + // openVideoDetailFragment on getFragmentManager() but what we want here is + // getParentFragment().getFragmentManager() + infoListAdapter.setOnStreamSelectedListener(new InfoItemBuilder.OnInfoItemSelectedListener() { + @Override + public void selected(StreamInfoItem selectedItem) { + onItemSelected(selectedItem); + NavigationHelper.openVideoDetailFragment(getParentFragment().getFragmentManager(), + selectedItem.service_id, selectedItem.url, selectedItem.name); + } + }); + } + /*////////////////////////////////////////////////////////////////////////// // Load and handle //////////////////////////////////////////////////////////////////////////*/ @@ -107,7 +137,7 @@ public class KioskFragment extends BaseListInfoFragment { @Override public Single loadMoreItemsLogic() { - return ExtractorHelper.getMoreKisokItems(serviceId, url, currentNextItemsUrl); + return ExtractorHelper.getMoreKioskItems(serviceId, url, currentNextItemsUrl); } /*////////////////////////////////////////////////////////////////////////// @@ -126,7 +156,7 @@ public class KioskFragment extends BaseListInfoFragment { super.handleResult(result); animateView(headerRootLayout, true, 100); - headerTitleView.setText(result.type); + headerTitleView.setText("★★ " +result.name+ " ★★"); if (!result.errors.isEmpty()) { showSnackBarError(result.errors, diff --git a/app/src/main/java/org/schabi/newpipe/util/ExtractorHelper.java b/app/src/main/java/org/schabi/newpipe/util/ExtractorHelper.java index 856769da8..b1ed2e901 100644 --- a/app/src/main/java/org/schabi/newpipe/util/ExtractorHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/ExtractorHelper.java @@ -134,7 +134,7 @@ public final class ExtractorHelper { })); } - public static Single getMoreKisokItems(final int serviceId, final String url, final String nextStreamsUrl) { + public static Single getMoreKioskItems(final int serviceId, final String url, final String nextStreamsUrl) { return Single.fromCallable(new Callable() { @Override public NextItemsResult call() throws Exception { From 5ebde97352c28fd540ce6ee1577bb2e0e2bc7145 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Mon, 25 Sep 2017 13:05:54 +0200 Subject: [PATCH 03/21] fix error report and add setting for current_service --- .../schabi/newpipe/fragments/MainFragment.java | 15 +++++++++++---- app/src/main/res/values/settings_keys.xml | 3 +++ 2 files changed, 14 insertions(+), 4 deletions(-) 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 3ca14f552..a92287089 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java @@ -8,6 +8,7 @@ import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; import android.support.v7.app.ActionBar; +import android.support.v7.preference.PreferenceManager; import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; @@ -20,14 +21,15 @@ import org.schabi.newpipe.BaseFragment; import org.schabi.newpipe.R; import org.schabi.newpipe.fragments.list.kiosk.KioskFragment; import org.schabi.newpipe.fragments.subscription.SubscriptionFragment; +import org.schabi.newpipe.report.ErrorActivity; +import org.schabi.newpipe.report.UserAction; import org.schabi.newpipe.util.NavigationHelper; public class MainFragment extends BaseFragment implements TabLayout.OnTabSelectedListener { private ViewPager viewPager; private boolean showBlankTab = false; - //todo: FIX THIS URGENTLY - public int currentServiceId = 0; //for youtube + public int currentServiceId = -1; /*////////////////////////////////////////////////////////////////////////// // Fragment's LifeCycle @@ -41,6 +43,8 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + currentServiceId = Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(getActivity()) + .getString(getString(R.string.current_service_key), "0")); return inflater.inflate(R.layout.fragment_main, container, false); } @@ -126,8 +130,11 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte try { return KioskFragment.getInstance(currentServiceId); } catch (Exception e) { - //todo: replace this with propper error reporting - e.printStackTrace(); + ErrorActivity.reportError(activity, e, + activity.getClass(), + null, + ErrorActivity.ErrorInfo.make(UserAction.UI_ERROR, + "none", "", R.string.app_ui_crash)); return new BlankFragment(); } } diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index 76cd10681..f5cef09a0 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -1,5 +1,8 @@ + + current_service + download_path download_path_audio From 65c8b6e66a14144c59173cc085108526feda12d5 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Tue, 26 Sep 2017 17:29:38 +0200 Subject: [PATCH 04/21] add selection for front page --- .../org/schabi/newpipe/RouterActivity.java | 10 +- .../newpipe/fragments/MainFragment.java | 49 +++-- .../settings/ContentSettingsFragment.java | 49 +++++ .../settings/SelectChannelFragment.java | 184 ++++++++++++++++++ .../res/layout/select_channel_fragment.xml | 42 ++++ .../main/res/layout/select_channel_item.xml | 38 ++++ app/src/main/res/values/settings_keys.xml | 16 ++ app/src/main/res/values/strings.xml | 11 ++ app/src/main/res/xml/content_settings.xml | 7 + 9 files changed, 387 insertions(+), 19 deletions(-) create mode 100644 app/src/main/java/org/schabi/newpipe/settings/SelectChannelFragment.java create mode 100644 app/src/main/res/layout/select_channel_fragment.xml create mode 100644 app/src/main/res/layout/select_channel_item.xml diff --git a/app/src/main/java/org/schabi/newpipe/RouterActivity.java b/app/src/main/java/org/schabi/newpipe/RouterActivity.java index ce9c3802f..41e557b52 100644 --- a/app/src/main/java/org/schabi/newpipe/RouterActivity.java +++ b/app/src/main/java/org/schabi/newpipe/RouterActivity.java @@ -10,22 +10,22 @@ import org.schabi.newpipe.util.NavigationHelper; import java.util.Collection; import java.util.HashSet; -/* +/** * Copyright (C) Christian Schabesberger 2017 - * RouterActivity .java is part of NewPipe. + * RouterActivity.java is part of NewPipe. * - * OpenHitboxStreams is free software: you can redistribute it and/or modify + * NewPipe is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * OpenHitboxStreams is distributed in the hope that it will be useful, + * NewPipe is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with OpenHitboxStreams. If not, see . + * along with NewPipe. If not, see . */ /** 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 a92287089..0a8e9b655 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java @@ -25,6 +25,8 @@ import org.schabi.newpipe.report.ErrorActivity; import org.schabi.newpipe.report.UserAction; import org.schabi.newpipe.util.NavigationHelper; +import java.util.concurrent.ExecutionException; + public class MainFragment extends BaseFragment implements TabLayout.OnTabSelectedListener { private ViewPager viewPager; private boolean showBlankTab = false; @@ -124,20 +126,7 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte case 1: return new SubscriptionFragment(); default: - if(showBlankTab) { - return new BlankFragment(); - } else { - try { - return KioskFragment.getInstance(currentServiceId); - } catch (Exception e) { - ErrorActivity.reportError(activity, e, - activity.getClass(), - null, - ErrorActivity.ErrorInfo.make(UserAction.UI_ERROR, - "none", "", R.string.app_ui_crash)); - return new BlankFragment(); - } - } + return getMainPageFramgent(); } } @@ -151,4 +140,36 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte return this.tabTitles.length; } } + + /*////////////////////////////////////////////////////////////////////////// + // Main page content + //////////////////////////////////////////////////////////////////////////*/ + + private Fragment getMainPageFramgent() { + try { + final String set_main_page = PreferenceManager.getDefaultSharedPreferences(getActivity()) + .getString(getString(R.string.main_page_content_key), + getString(R.string.main_page_selectd_kiosk_id)); + if(set_main_page.equals(getString(R.string.blank_page_key))) { + return new BlankFragment(); + } else if(set_main_page.equals(getString(R.string.kiosk_page_key))) { + return KioskFragment.getInstance(currentServiceId); + } else if(set_main_page.equals(getString(R.string.feed_page_key))) { + return new BlankFragment(); + } else if(set_main_page.equals(getString(R.string.channel_page_key))) { + return new BlankFragment(); + } else { + return new BlankFragment(); + } + + + } catch (Exception e) { + ErrorActivity.reportError(activity, e, + activity.getClass(), + null, + ErrorActivity.ErrorInfo.make(UserAction.UI_ERROR, + "none", "", R.string.app_ui_crash)); + return new BlankFragment(); + } + } } diff --git a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java index 6021b40fd..0164f584e 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java @@ -1,6 +1,9 @@ package org.schabi.newpipe.settings; import android.os.Bundle; +import android.support.v7.preference.ListPreference; +import android.support.v7.preference.Preference; +import android.util.Log; import org.schabi.newpipe.R; @@ -8,5 +11,51 @@ public class ContentSettingsFragment extends BasePreferenceFragment { @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { addPreferencesFromResource(R.xml.content_settings); + + findPreference(getString(R.string.main_page_content_key)) + .setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValueO) { + final String newValue = newValueO.toString(); + + if(newValue.equals(getString(R.string.kiosk_page_key))) { + //todo on multyservice support show a kiosk an service selector here + } else if(newValue.equals(getString(R.string.channel_page_key))) { + SelectChannelFragment selectChannelFragment = new SelectChannelFragment(); + selectChannelFragment.setOnSelectedLisener(new SelectChannelFragment.OnSelectedLisener() { + @Override + public void onChannelSelected(String url, String name, int service) { + defaultPreferences.edit() + .putInt(getString(R.string.main_page_selected_service), service).apply(); + defaultPreferences.edit() + .putString(getString(R.string.main_page_selected_channel_url), url).apply(); + defaultPreferences.edit() + .putString(getString(R.string.main_page_selected_channel_name), name).apply(); + + //change summery + Preference pref = findPreference(getString(R.string.main_page_content_key)); + pref.setSummary(name); + + } + }); + selectChannelFragment.show(getFragmentManager(), "select_channel"); + } + + return true; + } + }); + } + + @Override + public void onResume() { + super.onResume(); + + final String mainPageContentKey = getString(R.string.main_page_content_key); + if(defaultPreferences.getString(mainPageContentKey, + getString(R.string.blank_page_key)) + .equals(getString(R.string.channel_page_key))) { + Preference pref = findPreference(getString(R.string.main_page_content_key)); + pref.setSummary(defaultPreferences.getString(getString(R.string.main_page_selected_channel_name), "error")); + } } } diff --git a/app/src/main/java/org/schabi/newpipe/settings/SelectChannelFragment.java b/app/src/main/java/org/schabi/newpipe/settings/SelectChannelFragment.java new file mode 100644 index 000000000..5cc7070f9 --- /dev/null +++ b/app/src/main/java/org/schabi/newpipe/settings/SelectChannelFragment.java @@ -0,0 +1,184 @@ +package org.schabi.newpipe.settings; + +import android.app.Activity; +import android.content.DialogInterface; +import android.os.Bundle; +import android.support.v4.app.DialogFragment; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ProgressBar; +import android.widget.TextView; + +import org.schabi.newpipe.R; +import org.schabi.newpipe.database.subscription.SubscriptionEntity; +import org.schabi.newpipe.fragments.subscription.SubscriptionService; +import org.schabi.newpipe.report.ErrorActivity; +import org.schabi.newpipe.report.UserAction; + +import java.util.List; +import java.util.Vector; + +import de.hdodenhof.circleimageview.CircleImageView; +import io.reactivex.Observer; +import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.disposables.Disposable; +import io.reactivex.schedulers.Schedulers; + + +/** + * Created by Christian Schabesberger on 26.09.17. + * SelectChannelFragment.java is part of NewPipe. + * + * NewPipe is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * NewPipe is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with NewPipe. If not, see . + */ + +public class SelectChannelFragment extends DialogFragment { + private SelectChannelAdapter channelAdapter; + private SubscriptionService subscriptionService; + + private ProgressBar progressBar; + private TextView emptyView; + private RecyclerView recyclerView; + + private List subscriptions = new Vector<>(); + + public interface OnSelectedLisener { + public void onChannelSelected(String url, String name, int service); + } + + OnSelectedLisener onSelectedLisener; + public void setOnSelectedLisener(OnSelectedLisener listener) { + onSelectedLisener = listener; + } + + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + View v = inflater.inflate(R.layout.select_channel_fragment, container, false); + recyclerView = (RecyclerView) v.findViewById(R.id.items_list); + recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); + channelAdapter = new SelectChannelAdapter(); + recyclerView.setAdapter(channelAdapter); + + progressBar = v.findViewById(R.id.progressBar); + emptyView = v.findViewById(R.id.empty_state_view); + progressBar.setVisibility(View.VISIBLE); + recyclerView.setVisibility(View.GONE); + emptyView.setVisibility(View.GONE); + + + subscriptionService = SubscriptionService.getInstance(); + subscriptionService.getSubscription().toObservable() + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(getSubscriptionObserver()); + + return v; + } + + private void displayChannels(List subscriptions) { + this.subscriptions = subscriptions; + progressBar.setVisibility(View.GONE); + if(subscriptions.isEmpty()) { + emptyView.setVisibility(View.VISIBLE); + return; + } + recyclerView.setVisibility(View.VISIBLE); + + } + + private void clickedItem(int position) { + if(onSelectedLisener != null) { + SubscriptionEntity entry = subscriptions.get(position); + onSelectedLisener.onChannelSelected(entry.getUrl(), entry.getName(), entry.getServiceId()); + } + dismiss(); + } + + private Observer> getSubscriptionObserver() { + return new Observer>() { + @Override + public void onSubscribe(Disposable d) { + } + + @Override + public void onNext(List subscriptions) { + displayChannels(subscriptions); + } + + @Override + public void onError(Throwable exception) { + onError(exception); + } + + @Override + public void onComplete() { + } + }; + } + + private class SelectChannelAdapter extends + RecyclerView.Adapter { + + @Override + public SelectChannelItemHolder onCreateViewHolder(ViewGroup parent, int viewType) { + View item = LayoutInflater.from(parent.getContext()) + .inflate(R.layout.select_channel_item, parent, false); + return new SelectChannelItemHolder(item); + } + + @Override + public void onBindViewHolder(SelectChannelItemHolder holder, final int position) { + SubscriptionEntity entry = subscriptions.get(position); + holder.titleView.setText(entry.getName()); + holder.view.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + clickedItem(position); + } + }); + } + + @Override + public int getItemCount() { + return subscriptions.size(); + } + + public class SelectChannelItemHolder extends RecyclerView.ViewHolder { + public SelectChannelItemHolder(View v) { + super(v); + this.view = v; + thumbnailView = v.findViewById(R.id.itemThumbnailView); + titleView = v.findViewById(R.id.itemTitleView); + } + public View view; + public CircleImageView thumbnailView; + public TextView titleView; + } + } + + protected boolean onError(Throwable e) { + final Activity activity = getActivity(); + ErrorActivity.reportError(activity, e, + activity.getClass(), + null, + ErrorActivity.ErrorInfo.make(UserAction.UI_ERROR, + "none", "", R.string.app_ui_crash)); + return true; + } +} diff --git a/app/src/main/res/layout/select_channel_fragment.xml b/app/src/main/res/layout/select_channel_fragment.xml new file mode 100644 index 000000000..9c8e79779 --- /dev/null +++ b/app/src/main/res/layout/select_channel_fragment.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/select_channel_item.xml b/app/src/main/res/layout/select_channel_item.xml new file mode 100644 index 000000000..903894aeb --- /dev/null +++ b/app/src/main/res/layout/select_channel_item.xml @@ -0,0 +1,38 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index f5cef09a0..878d51741 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -92,6 +92,7 @@ @string/black_theme_title + show_search_suggestions show_play_with_kodi show_next_video @@ -101,6 +102,21 @@ use_tor enable_search_history enable_watch_history + main_page_content + blank_page + feed_page + kiosk_page + channel_page + + @string/blank_page_key + @string/kiosk_page_key + @string/feed_page_key + @string/channel_page_key + + main_page_selected_service + main_page_selected_channel_name + main_page_selected_channel_url + main_page_selectd_kiosk_id file_rename diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a5b3993d8..e16bfca16 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -265,4 +265,15 @@ The history is empty History cleared Item deleted + + + Content of main page + + Blank Page + Trending Page + Feed Page + Channel Page + + Select a channel + No channel subscribed yet diff --git a/app/src/main/res/xml/content_settings.xml b/app/src/main/res/xml/content_settings.xml index 63cd3cd01..11672671e 100644 --- a/app/src/main/res/xml/content_settings.xml +++ b/app/src/main/res/xml/content_settings.xml @@ -21,5 +21,12 @@ android:key="@string/show_search_suggestions_key" android:summary="@string/show_search_suggestions_summary" android:title="@string/show_search_suggestions_title"/> + From 3490273b498156ccd56ee29b63d0db09fa2cb169 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Tue, 26 Sep 2017 18:16:39 +0200 Subject: [PATCH 05/21] made fragments frontpagable --- .../newpipe/fragments/BaseStateFragment.java | 6 +++++ .../newpipe/fragments/MainFragment.java | 22 +++++++++++++++---- .../fragments/list/BaseListFragment.java | 12 +++++++--- .../list/channel/ChannelFragment.java | 19 +++++++++++----- .../fragments/list/feed/FeedFragment.java | 7 ++++-- .../fragments/list/kiosk/KioskFragment.java | 18 +-------------- .../settings/ContentSettingsFragment.java | 2 ++ .../settings/SelectChannelFragment.java | 1 - 8 files changed, 54 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java index 5a8d8dd52..80f05585b 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java @@ -50,6 +50,8 @@ public abstract class BaseStateFragment extends BaseFragment implements ViewC protected Button errorButtonRetry; protected TextView errorTextView; + protected boolean useAsFrontPage = false; + @Override public void onViewCreated(View rootView, Bundle savedInstanceState) { super.onViewCreated(rootView, savedInstanceState); @@ -62,6 +64,10 @@ public abstract class BaseStateFragment extends BaseFragment implements ViewC wasLoading.set(isLoading.get()); } + public void useAsFrontPage(boolean value) { + useAsFrontPage = value; + } + /*////////////////////////////////////////////////////////////////////////// // Init //////////////////////////////////////////////////////////////////////////*/ 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 0a8e9b655..aa28c54fb 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java @@ -1,5 +1,6 @@ package org.schabi.newpipe.fragments; +import android.content.SharedPreferences; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.design.widget.TabLayout; @@ -19,6 +20,8 @@ import android.view.ViewGroup; import org.schabi.newpipe.BaseFragment; import org.schabi.newpipe.R; +import org.schabi.newpipe.fragments.list.channel.ChannelFragment; +import org.schabi.newpipe.fragments.list.feed.FeedFragment; import org.schabi.newpipe.fragments.list.kiosk.KioskFragment; import org.schabi.newpipe.fragments.subscription.SubscriptionFragment; import org.schabi.newpipe.report.ErrorActivity; @@ -153,16 +156,27 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte if(set_main_page.equals(getString(R.string.blank_page_key))) { return new BlankFragment(); } else if(set_main_page.equals(getString(R.string.kiosk_page_key))) { - return KioskFragment.getInstance(currentServiceId); + KioskFragment fragment = KioskFragment.getInstance(currentServiceId); + fragment.useAsFrontPage(true); + return fragment; } else if(set_main_page.equals(getString(R.string.feed_page_key))) { - return new BlankFragment(); + FeedFragment fragment = new FeedFragment(); + fragment.useAsFrontPage(true); + return fragment; } else if(set_main_page.equals(getString(R.string.channel_page_key))) { - return new BlankFragment(); + SharedPreferences preferences = + PreferenceManager.getDefaultSharedPreferences(getActivity()); + int serviceId = preferences.getInt(getString(R.string.main_page_selected_service), 0); + String url = preferences.getString(getString(R.string.main_page_selected_channel_url), + "https://www.youtube.com/channel/UC-9-kyTW8ZkZNDHQJ6FgpwQ"); + String name = preferences.getString(getString(R.string.main_page_selected_channel_name), "Music"); + ChannelFragment fragment = ChannelFragment.getInstance(serviceId, url, name); + fragment.useAsFrontPage(true); + return fragment; } else { return new BlankFragment(); } - } catch (Exception e) { ErrorActivity.reportError(activity, e, activity.getClass(), diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java index 4501ab859..48661969f 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java @@ -135,7 +135,9 @@ public abstract class BaseListFragment extends BaseStateFragment implem @Override public void selected(StreamInfoItem selectedItem) { onItemSelected(selectedItem); - NavigationHelper.openVideoDetailFragment(getFragmentManager(), selectedItem.service_id, selectedItem.url, selectedItem.name); + NavigationHelper.openVideoDetailFragment( + useAsFrontPage?getParentFragment().getFragmentManager():getFragmentManager(), + selectedItem.service_id, selectedItem.url, selectedItem.name); } }); @@ -143,7 +145,9 @@ public abstract class BaseListFragment extends BaseStateFragment implem @Override public void selected(ChannelInfoItem selectedItem) { onItemSelected(selectedItem); - NavigationHelper.openChannelFragment(getFragmentManager(), selectedItem.service_id, selectedItem.url, selectedItem.name); + NavigationHelper.openChannelFragment( + useAsFrontPage?getParentFragment().getFragmentManager():getFragmentManager(), + selectedItem.service_id, selectedItem.url, selectedItem.name); } }); @@ -151,7 +155,9 @@ public abstract class BaseListFragment extends BaseStateFragment implem @Override public void selected(PlaylistInfoItem selectedItem) { onItemSelected(selectedItem); - NavigationHelper.openPlaylistFragment(getFragmentManager(), selectedItem.service_id, selectedItem.url, selectedItem.name); + NavigationHelper.openPlaylistFragment( + useAsFrontPage?getParentFragment().getFragmentManager():getFragmentManager(), + selectedItem.service_id, selectedItem.url, selectedItem.name); } }); diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java index b7148fe63..5a722ec4c 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java @@ -7,6 +7,7 @@ import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; +import android.support.v7.app.ActionBar; import android.text.TextUtils; import android.util.Log; import android.view.LayoutInflater; @@ -118,15 +119,21 @@ public class ChannelFragment extends BaseListInfoFragment { @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { - if (DEBUG) Log.d(TAG, "onCreateOptionsMenu() called with: menu = [" + menu + "], inflater = [" + inflater + "]"); super.onCreateOptionsMenu(menu, inflater); - inflater.inflate(R.menu.menu_channel, menu); + ActionBar supportActionBar = activity.getSupportActionBar(); + if(useAsFrontPage) { + supportActionBar.setDisplayHomeAsUpEnabled(false); + supportActionBar.setDisplayShowTitleEnabled(false); + } else { + inflater.inflate(R.menu.menu_channel, menu); + + if (DEBUG) Log.d(TAG, "onCreateOptionsMenu() called with: menu = [" + menu + "], inflater = [" + inflater + "]"); + menuRssButton = menu.findItem(R.id.menu_item_rss); + if (currentInfo != null) { + menuRssButton.setVisible(!TextUtils.isEmpty(currentInfo.feed_url)); + } - menuRssButton = menu.findItem(R.id.menu_item_rss); - if (currentInfo != null) { - menuRssButton.setVisible(!TextUtils.isEmpty(currentInfo.feed_url)); } - } @Override diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/feed/FeedFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/feed/FeedFragment.java index 2af9a9270..1a8f8e625 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/feed/FeedFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/feed/FeedFragment.java @@ -36,10 +36,8 @@ import io.reactivex.MaybeObserver; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.Disposable; -import io.reactivex.functions.Action; import io.reactivex.functions.Consumer; import io.reactivex.functions.Predicate; -import io.reactivex.schedulers.Schedulers; public class FeedFragment extends BaseListFragment, Void> { @@ -121,6 +119,11 @@ public class FeedFragment extends BaseListFragment, Voi if (supportActionBar != null) { supportActionBar.setTitle(R.string.fragment_whats_new); } + + if(useAsFrontPage) { + supportActionBar.setDisplayHomeAsUpEnabled(false); + supportActionBar.setDisplayShowTitleEnabled(false); + } } @Override diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java index 932cf2a44..3d019e6cb 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java @@ -52,7 +52,6 @@ import static org.schabi.newpipe.util.AnimationUtils.animateView; public class KioskFragment extends BaseListInfoFragment { - /*////////////////////////////////////////////////////////////////////////// // Views //////////////////////////////////////////////////////////////////////////*/ @@ -90,7 +89,7 @@ public class KioskFragment extends BaseListInfoFragment { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); ActionBar supportActionBar = activity.getSupportActionBar(); - if (supportActionBar != null) { + if (supportActionBar != null && useAsFrontPage) { supportActionBar.setDisplayShowTitleEnabled(false); supportActionBar.setDisplayHomeAsUpEnabled(false); } @@ -107,21 +106,6 @@ public class KioskFragment extends BaseListInfoFragment { return headerRootLayout; } - @Override - public void initListeners() { - // We have to override this because the default implementation of this function calls - // openVideoDetailFragment on getFragmentManager() but what we want here is - // getParentFragment().getFragmentManager() - infoListAdapter.setOnStreamSelectedListener(new InfoItemBuilder.OnInfoItemSelectedListener() { - @Override - public void selected(StreamInfoItem selectedItem) { - onItemSelected(selectedItem); - NavigationHelper.openVideoDetailFragment(getParentFragment().getFragmentManager(), - selectedItem.service_id, selectedItem.url, selectedItem.name); - } - }); - } - /*////////////////////////////////////////////////////////////////////////// // Load and handle //////////////////////////////////////////////////////////////////////////*/ diff --git a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java index 0164f584e..9b3ffb5ae 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java @@ -6,6 +6,7 @@ import android.support.v7.preference.Preference; import android.util.Log; import org.schabi.newpipe.R; +import org.schabi.newpipe.util.Constants; public class ContentSettingsFragment extends BasePreferenceFragment { @Override @@ -36,6 +37,7 @@ public class ContentSettingsFragment extends BasePreferenceFragment { Preference pref = findPreference(getString(R.string.main_page_content_key)); pref.setSummary(name); + } }); selectChannelFragment.show(getFragmentManager(), "select_channel"); diff --git a/app/src/main/java/org/schabi/newpipe/settings/SelectChannelFragment.java b/app/src/main/java/org/schabi/newpipe/settings/SelectChannelFragment.java index 5cc7070f9..16b68196a 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/SelectChannelFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/SelectChannelFragment.java @@ -66,7 +66,6 @@ public class SelectChannelFragment extends DialogFragment { onSelectedLisener = listener; } - @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.select_channel_fragment, container, false); From 29fee28d1d2f7e83ecacade996912a129151acfc Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Thu, 28 Sep 2017 15:36:15 +0200 Subject: [PATCH 06/21] fix channel selection --- .../settings/BasePreferenceFragment.java | 2 +- .../settings/ContentSettingsFragment.java | 55 +++++++++++-- .../settings/SelectChannelFragment.java | 79 ++++++++++++++++--- app/src/main/res/values/strings.xml | 12 ++- 4 files changed, 123 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/settings/BasePreferenceFragment.java b/app/src/main/java/org/schabi/newpipe/settings/BasePreferenceFragment.java index a16f7dd79..e3c52cdad 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/BasePreferenceFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/BasePreferenceFragment.java @@ -19,8 +19,8 @@ public abstract class BasePreferenceFragment extends PreferenceFragmentCompat { @Override public void onCreate(@Nullable Bundle savedInstanceState) { - super.onCreate(savedInstanceState); defaultPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity()); + super.onCreate(savedInstanceState); } @Override diff --git a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java index 9b3ffb5ae..02038f9fa 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java @@ -3,22 +3,27 @@ package org.schabi.newpipe.settings; import android.os.Bundle; import android.support.v7.preference.ListPreference; import android.support.v7.preference.Preference; -import android.util.Log; import org.schabi.newpipe.R; -import org.schabi.newpipe.util.Constants; public class ContentSettingsFragment extends BasePreferenceFragment { + @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { + addPreferencesFromResource(R.xml.content_settings); - findPreference(getString(R.string.main_page_content_key)) - .setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + final ListPreference mainPageContentPref = (ListPreference) findPreference(getString(R.string.main_page_content_key)); + + mainPageContentPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValueO) { final String newValue = newValueO.toString(); + final String mainPrefOldValue = + defaultPreferences.getString(getString(R.string.main_page_content_key), "blank_page"); + final String mainPrefOldSummary = getMainPagePrefSummery(mainPrefOldValue, mainPageContentPref); + if(newValue.equals(getString(R.string.kiosk_page_key))) { //todo on multyservice support show a kiosk an service selector here } else if(newValue.equals(getString(R.string.channel_page_key))) { @@ -34,15 +39,25 @@ public class ContentSettingsFragment extends BasePreferenceFragment { .putString(getString(R.string.main_page_selected_channel_name), name).apply(); //change summery - Preference pref = findPreference(getString(R.string.main_page_content_key)); - pref.setSummary(name); - - + mainPageContentPref.setSummary(name); + } + }); + selectChannelFragment.setOnCancelListener(new SelectChannelFragment.OnCancelListener() { + @Override + public void onCancel() { + //defaultPreferences.edit() + // .putString(getString(R.string.main_page_content_key), mainPrefOldValue).apply(); + mainPageContentPref.setSummary(mainPrefOldSummary); + mainPageContentPref.setValue(mainPrefOldValue); } }); selectChannelFragment.show(getFragmentManager(), "select_channel"); } + if(!newValue.equals(getString(R.string.channel_page_key))) { + mainPageContentPref.setSummary(getMainPageSummeryByKey(newValue)); + } + return true; } }); @@ -60,4 +75,28 @@ public class ContentSettingsFragment extends BasePreferenceFragment { pref.setSummary(defaultPreferences.getString(getString(R.string.main_page_selected_channel_name), "error")); } } + + /*////////////////////////////////////////////////////////////////////////// + // Utils + //////////////////////////////////////////////////////////////////////////*/ + private String getMainPagePrefSummery(final String mainPrefOldValue, final ListPreference mainPageContentPref) { + if(mainPrefOldValue.equals(getString(R.string.channel_page_key))) { + return defaultPreferences.getString(getString(R.string.main_page_selected_channel_name), "error"); + } else { + return mainPageContentPref.getSummary().toString(); + } + } + + private int getMainPageSummeryByKey(final String key) { + if(key.equals(getString(R.string.blank_page_key))) { + return R.string.blank_page_summary; + } else if(key.equals(getString(R.string.kiosk_page_key))) { + return R.string.kiosk_page_summary; + } else if(key.equals(getString(R.string.feed_page_key))) { + return R.string.feed_page_summary; + } else if(key.equals(getString(R.string.channel_page_key))) { + return R.string.channel_page_summary; + } + return R.string.blank_page_summary; + } } diff --git a/app/src/main/java/org/schabi/newpipe/settings/SelectChannelFragment.java b/app/src/main/java/org/schabi/newpipe/settings/SelectChannelFragment.java index 16b68196a..97af11f1b 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/SelectChannelFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/SelectChannelFragment.java @@ -13,6 +13,9 @@ import android.view.ViewGroup; import android.widget.ProgressBar; import android.widget.TextView; +import com.nostra13.universalimageloader.core.DisplayImageOptions; +import com.nostra13.universalimageloader.core.ImageLoader; + import org.schabi.newpipe.R; import org.schabi.newpipe.database.subscription.SubscriptionEntity; import org.schabi.newpipe.fragments.subscription.SubscriptionService; @@ -50,6 +53,7 @@ import io.reactivex.schedulers.Schedulers; public class SelectChannelFragment extends DialogFragment { private SelectChannelAdapter channelAdapter; private SubscriptionService subscriptionService; + private ImageLoader imageLoader = ImageLoader.getInstance(); private ProgressBar progressBar; private TextView emptyView; @@ -57,15 +61,31 @@ public class SelectChannelFragment extends DialogFragment { private List subscriptions = new Vector<>(); - public interface OnSelectedLisener { - public void onChannelSelected(String url, String name, int service); - } + /*////////////////////////////////////////////////////////////////////////// + // Interfaces + //////////////////////////////////////////////////////////////////////////*/ - OnSelectedLisener onSelectedLisener; + public interface OnSelectedLisener { + void onChannelSelected(String url, String name, int service); + } + OnSelectedLisener onSelectedLisener = null; public void setOnSelectedLisener(OnSelectedLisener listener) { onSelectedLisener = listener; } + public interface OnCancelListener { + void onCancel(); + } + OnCancelListener onCancelListener = null; + public void setOnCancelListener(OnCancelListener listener) { + onCancelListener = listener; + } + + /*////////////////////////////////////////////////////////////////////////// + // Init + //////////////////////////////////////////////////////////////////////////*/ + + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.select_channel_fragment, container, false); @@ -90,6 +110,31 @@ public class SelectChannelFragment extends DialogFragment { return v; } + + /*////////////////////////////////////////////////////////////////////////// + // Handle actions + //////////////////////////////////////////////////////////////////////////*/ + + @Override + public void onCancel(final DialogInterface dialogInterface) { + super.onCancel(dialogInterface); + if(onCancelListener != null) { + onCancelListener.onCancel(); + } + } + + private void clickedItem(int position) { + if(onSelectedLisener != null) { + SubscriptionEntity entry = subscriptions.get(position); + onSelectedLisener.onChannelSelected(entry.getUrl(), entry.getName(), entry.getServiceId()); + } + dismiss(); + } + + /*////////////////////////////////////////////////////////////////////////// + // Item handling + //////////////////////////////////////////////////////////////////////////*/ + private void displayChannels(List subscriptions) { this.subscriptions = subscriptions; progressBar.setVisibility(View.GONE); @@ -101,14 +146,6 @@ public class SelectChannelFragment extends DialogFragment { } - private void clickedItem(int position) { - if(onSelectedLisener != null) { - SubscriptionEntity entry = subscriptions.get(position); - onSelectedLisener.onChannelSelected(entry.getUrl(), entry.getName(), entry.getServiceId()); - } - dismiss(); - } - private Observer> getSubscriptionObserver() { return new Observer>() { @Override @@ -151,6 +188,7 @@ public class SelectChannelFragment extends DialogFragment { clickedItem(position); } }); + imageLoader.displayImage(entry.getAvatarUrl(), holder.thumbnailView, DISPLAY_IMAGE_OPTIONS); } @Override @@ -171,6 +209,10 @@ public class SelectChannelFragment extends DialogFragment { } } + /*////////////////////////////////////////////////////////////////////////// + // Error + //////////////////////////////////////////////////////////////////////////*/ + protected boolean onError(Throwable e) { final Activity activity = getActivity(); ErrorActivity.reportError(activity, e, @@ -180,4 +222,17 @@ public class SelectChannelFragment extends DialogFragment { "none", "", R.string.app_ui_crash)); return true; } + + + /*////////////////////////////////////////////////////////////////////////// + // ImageLoaderOptions + //////////////////////////////////////////////////////////////////////////*/ + + /** + * Base display options + */ + public static final DisplayImageOptions DISPLAY_IMAGE_OPTIONS = + new DisplayImageOptions.Builder() + .cacheInMemory(true) + .build(); } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e16bfca16..b71bfa7db 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -268,11 +268,15 @@ Content of main page + Blank Page + Kiosk Page + Feed Page + Channel Page - Blank Page - Trending Page - Feed Page - Channel Page + @string/blank_page_summary + @string/kiosk_page_summary + @string/feed_page_summary + @string/channel_page_summary Select a channel No channel subscribed yet From 46fa9a9366cf74e6381384f794027ee6c1034a54 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Thu, 28 Sep 2017 16:15:09 +0200 Subject: [PATCH 07/21] translate kiosk name using resources fix CDATA fuu --- .../newpipe/fragments/MainFragment.java | 24 +++++++++++- .../list/channel/ChannelFragment.java | 6 ++- .../fragments/list/feed/FeedFragment.java | 2 +- .../fragments/list/kiosk/KioskFragment.java | 5 ++- .../subscription/SubscriptionFragment.java | 2 + .../settings/ContentSettingsFragment.java | 2 + .../schabi/newpipe/util/KioskTranslator.java | 38 +++++++++++++++++++ app/src/main/res/menu/main_menu.xml | 2 +- app/src/main/res/values/settings_keys.xml | 2 + app/src/main/res/values/strings.xml | 7 ++++ 10 files changed, 82 insertions(+), 8 deletions(-) create mode 100644 app/src/main/java/org/schabi/newpipe/util/KioskTranslator.java 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 aa28c54fb..c6d3f07f9 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java @@ -126,10 +126,18 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte @Override public Fragment getItem(int position) { switch (position) { + case 0: + if(PreferenceManager.getDefaultSharedPreferences(getActivity()) + .getString(getString(R.string.main_page_content_key), getString(R.string.blank_page_key)) + .equals(getString(R.string.subscription_page_key))) { + return new SubscriptionFragment(); + } else { + return getMainPageFramgent(); + } case 1: return new SubscriptionFragment(); default: - return getMainPageFramgent(); + return new BlankFragment(); } } @@ -140,7 +148,13 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte @Override public int getCount() { - return this.tabTitles.length; + if(PreferenceManager.getDefaultSharedPreferences(getActivity()) + .getString(getString(R.string.main_page_content_key), getString(R.string.blank_page_key)) + .equals(getString(R.string.subscription_page_key))) { + return 1; + } else { + return 2; + } } } @@ -186,4 +200,10 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte return new BlankFragment(); } } + + /*////////////////////////////////////////////////////////////////////////// + // Main page content + //////////////////////////////////////////////////////////////////////////*/ + + } diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java index 5a722ec4c..daa1b62ed 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java @@ -89,7 +89,8 @@ public class ChannelFragment extends BaseListInfoFragment { @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - return inflater.inflate(R.layout.fragment_channel, container, false); + View v = inflater.inflate(R.layout.fragment_channel, container, false); + return v; } @Override @@ -110,6 +111,7 @@ public class ChannelFragment extends BaseListInfoFragment { headerTitleView = headerRootLayout.findViewById(R.id.channel_title_view); headerSubscribersTextView = headerRootLayout.findViewById(R.id.channel_subscriber_view); headerSubscribeButton = headerRootLayout.findViewById(R.id.channel_subscribe_button); + return headerRootLayout; } @@ -123,7 +125,7 @@ public class ChannelFragment extends BaseListInfoFragment { ActionBar supportActionBar = activity.getSupportActionBar(); if(useAsFrontPage) { supportActionBar.setDisplayHomeAsUpEnabled(false); - supportActionBar.setDisplayShowTitleEnabled(false); + //supportActionBar.setDisplayShowTitleEnabled(false); } else { inflater.inflate(R.menu.menu_channel, menu); diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/feed/FeedFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/feed/FeedFragment.java index 1a8f8e625..379ec591a 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/feed/FeedFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/feed/FeedFragment.java @@ -122,7 +122,7 @@ public class FeedFragment extends BaseListFragment, Voi if(useAsFrontPage) { supportActionBar.setDisplayHomeAsUpEnabled(false); - supportActionBar.setDisplayShowTitleEnabled(false); + //supportActionBar.setDisplayShowTitleEnabled(false); } } diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java index 3d019e6cb..451ade674 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java @@ -24,6 +24,7 @@ import org.schabi.newpipe.fragments.list.BaseListInfoFragment; import org.schabi.newpipe.info_list.InfoItemBuilder; import org.schabi.newpipe.report.UserAction; import org.schabi.newpipe.util.ExtractorHelper; +import org.schabi.newpipe.util.KioskTranslator; import org.schabi.newpipe.util.NavigationHelper; import io.reactivex.Single; @@ -90,7 +91,7 @@ public class KioskFragment extends BaseListInfoFragment { super.onCreateOptionsMenu(menu, inflater); ActionBar supportActionBar = activity.getSupportActionBar(); if (supportActionBar != null && useAsFrontPage) { - supportActionBar.setDisplayShowTitleEnabled(false); + //supportActionBar.setDisplayShowTitleEnabled(false); supportActionBar.setDisplayHomeAsUpEnabled(false); } } @@ -140,7 +141,7 @@ public class KioskFragment extends BaseListInfoFragment { super.handleResult(result); animateView(headerRootLayout, true, 100); - headerTitleView.setText("★★ " +result.name+ " ★★"); + headerTitleView.setText("★★ " + KioskTranslator.getTranslatedKioskName(result.id, getActivity())+ " ★★"); if (!result.errors.isEmpty()) { showSnackBarError(result.errors, diff --git a/app/src/main/java/org/schabi/newpipe/fragments/subscription/SubscriptionFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/subscription/SubscriptionFragment.java index 646fe597e..afb2f078e 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/subscription/SubscriptionFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/subscription/SubscriptionFragment.java @@ -62,6 +62,8 @@ public class SubscriptionFragment extends BaseStateFragment. + */ + +public class KioskTranslator { + public static String getTranslatedKioskName(String kioskId, Context c) { + switch(kioskId) { + case "Trending": + return c.getString(R.string.trending); + case "Top 50": + return c.getString(R.string.top_50); + case "New & hot": + return c.getString(R.string.new_and_hot); + default: + return kioskId; + } + } +} diff --git a/app/src/main/res/menu/main_menu.xml b/app/src/main/res/menu/main_menu.xml index be3548532..02402e2e8 100644 --- a/app/src/main/res/menu/main_menu.xml +++ b/app/src/main/res/menu/main_menu.xml @@ -20,6 +20,6 @@ + android:title="@string/action_about"/> \ No newline at end of file diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index 878d51741..dabbfb40d 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -105,12 +105,14 @@ main_page_content blank_page feed_page + subscription_page_key kiosk_page channel_page @string/blank_page_key @string/kiosk_page_key @string/feed_page_key + @string/subscription_page_key @string/channel_page_key main_page_selected_service diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b71bfa7db..bd8bdc048 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -270,14 +270,21 @@ Content of main page Blank Page Kiosk Page + Subscription Page Feed Page Channel Page @string/blank_page_summary @string/kiosk_page_summary @string/feed_page_summary + @string/subscription_page_summary @string/channel_page_summary Select a channel No channel subscribed yet + + + Trending + Top 50 + New & hot From 6d8a361c9af75938ed6480f30c6fd3265aa538bb Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Thu, 5 Oct 2017 14:57:19 +0200 Subject: [PATCH 08/21] add menu to select kiosk of current service --- .../newpipe/fragments/MainFragment.java | 50 ++++++++++++++++++- .../fragments/list/kiosk/KioskFragment.java | 16 ++++-- .../schabi/newpipe/util/NavigationHelper.java | 10 ++++ app/src/main/res/values/strings.xml | 1 + 4 files changed, 70 insertions(+), 7 deletions(-) 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 c6d3f07f9..4ba648402 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java @@ -15,17 +15,22 @@ import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; +import android.view.SubMenu; import android.view.View; import android.view.ViewGroup; import org.schabi.newpipe.BaseFragment; import org.schabi.newpipe.R; +import org.schabi.newpipe.extractor.NewPipe; +import org.schabi.newpipe.extractor.StreamingService; +import org.schabi.newpipe.extractor.kiosk.KioskList; import org.schabi.newpipe.fragments.list.channel.ChannelFragment; import org.schabi.newpipe.fragments.list.feed.FeedFragment; import org.schabi.newpipe.fragments.list.kiosk.KioskFragment; import org.schabi.newpipe.fragments.subscription.SubscriptionFragment; import org.schabi.newpipe.report.ErrorActivity; import org.schabi.newpipe.report.UserAction; +import org.schabi.newpipe.util.KioskTranslator; import org.schabi.newpipe.util.NavigationHelper; import java.util.concurrent.ExecutionException; @@ -36,6 +41,12 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte public int currentServiceId = -1; + /*////////////////////////////////////////////////////////////////////////// + // Konst + //////////////////////////////////////////////////////////////////////////*/ + + private static final int KIOSK_MENU_OFFSETT = 2000; + /*////////////////////////////////////////////////////////////////////////// // Fragment's LifeCycle //////////////////////////////////////////////////////////////////////////*/ @@ -77,6 +88,16 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte super.onCreateOptionsMenu(menu, inflater); if (DEBUG) Log.d(TAG, "onCreateOptionsMenu() called with: menu = [" + menu + "], inflater = [" + inflater + "]"); inflater.inflate(R.menu.main_fragment_menu, menu); + SubMenu kioskMenu = menu.addSubMenu(getString(R.string.kiosk)); + try { + createKioskMenu(kioskMenu, inflater); + } catch (Exception e) { + ErrorActivity.reportError(activity, e, + activity.getClass(), + null, + ErrorActivity.ErrorInfo.make(UserAction.UI_ERROR, + "none", "", R.string.app_ui_crash)); + } ActionBar supportActionBar = activity.getSupportActionBar(); if (supportActionBar != null) { @@ -202,8 +223,33 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte } /*////////////////////////////////////////////////////////////////////////// - // Main page content + // Select Kiosk //////////////////////////////////////////////////////////////////////////*/ - + private void createKioskMenu(Menu menu, MenuInflater menuInflater) + throws Exception { + StreamingService service = NewPipe.getService(currentServiceId); + KioskList kl = service.getKioskList(); + int i = 0; + for(final String ks : kl.getAvailableKisoks()) { + menu.add(0, KIOSK_MENU_OFFSETT + i, Menu.NONE, + KioskTranslator.getTranslatedKioskName(ks, getContext())) + .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem menuItem) { + try { + NavigationHelper.openKioskFragment(getFragmentManager(), currentServiceId, ks); + } catch (Exception e) { + ErrorActivity.reportError(activity, e, + activity.getClass(), + null, + ErrorActivity.ErrorInfo.make(UserAction.UI_ERROR, + "none", "", R.string.app_ui_crash)); + } + return true; + } + }); + i++; + } + } } diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java index 451ade674..8e1acb572 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java @@ -62,14 +62,20 @@ public class KioskFragment extends BaseListInfoFragment { public static KioskFragment getInstance(int serviceId) throws ExtractionException { + return getInstance(serviceId, NewPipe.getService(serviceId) + .getKioskList() + .getDefaultKioskId()); + } + + public static KioskFragment getInstance(int serviceId, String kioskId) + throws ExtractionException { KioskFragment instance = new KioskFragment(); StreamingService service = NewPipe.getService(serviceId); - String defaultKioskId = service.getKioskList().getDefaultKioskId(); - UrlIdHandler defaultKioskTypeUrlIdHandler = service.getKioskList() - .getUrlIdHandlerByType(defaultKioskId); + UrlIdHandler kioskTypeUrlIdHandler = service.getKioskList() + .getUrlIdHandlerByType(kioskId); instance.setInitialData(serviceId, - defaultKioskTypeUrlIdHandler.getUrl(defaultKioskId), - defaultKioskId); + kioskTypeUrlIdHandler.getUrl(kioskId), + kioskId); return instance; } diff --git a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java index 538675685..b30407315 100644 --- a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java @@ -23,6 +23,7 @@ import org.schabi.newpipe.fragments.MainFragment; import org.schabi.newpipe.fragments.detail.VideoDetailFragment; import org.schabi.newpipe.fragments.list.channel.ChannelFragment; import org.schabi.newpipe.fragments.list.feed.FeedFragment; +import org.schabi.newpipe.fragments.list.kiosk.KioskFragment; import org.schabi.newpipe.fragments.list.playlist.PlaylistFragment; import org.schabi.newpipe.fragments.list.search.SearchFragment; import org.schabi.newpipe.history.HistoryActivity; @@ -163,6 +164,15 @@ public class NavigationHelper { .commit(); } + public static void openKioskFragment(FragmentManager fragmentManager, int serviceId, String kioskId) + throws ExtractionException { + fragmentManager.beginTransaction() + .setCustomAnimations(R.animator.custom_fade_in, R.animator.custom_fade_out, R.animator.custom_fade_in, R.animator.custom_fade_out) + .replace(R.id.fragment_holder, KioskFragment.getInstance(serviceId, kioskId)) + .addToBackStack(null) + .commit(); + } + /*////////////////////////////////////////////////////////////////////////// // Through Intents //////////////////////////////////////////////////////////////////////////*/ diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bd8bdc048..e11483ac0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -284,6 +284,7 @@ No channel subscribed yet + Kisok Trending Top 50 New & hot From cbfc359a99c18e37b45c86c98fbeadba20fdb821 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Mon, 9 Oct 2017 12:22:01 +0200 Subject: [PATCH 09/21] add service icons --- app/src/main/res/drawable-nodpi/soud_cloud.png | Bin 0 -> 12259 bytes app/src/main/res/drawable-nodpi/youtube.png | Bin 0 -> 6182 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 app/src/main/res/drawable-nodpi/soud_cloud.png create mode 100644 app/src/main/res/drawable-nodpi/youtube.png diff --git a/app/src/main/res/drawable-nodpi/soud_cloud.png b/app/src/main/res/drawable-nodpi/soud_cloud.png new file mode 100644 index 0000000000000000000000000000000000000000..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mu#Zga;fF&Na_aB)9c$I%d|>HPVlC0-R%Q zYRu{Heg|}UTvkjcYPg>LsBQzScc1ZhKRexIeRtwGF@eK*N~0%`kh9{zyxB6;ohUDQ zyW`Pu?h|h<3EbWC#%GN80}80+wZgg1JMzo9sinCQsVUEMpU~KLIZPRJ0sD2>-0&cK z?8K1rFT48p{%LDVc}>fy8c;&*CBn}jJ%7;XiI-7DVg{B|uLTI(t(9AbR>N^=d?r1J zkJ2ITYtwS=NXuXH%N!s7Fy4Y``c|0=UNJr2gX?7vO3u@tvHgs}>yLKG;CRnp;MGHD ziYpXkagF;+PWx}#o*bL4>G4ehEH6bmJhCv`(fq|da^82l49@;ROJ%xXX<>MN@K=H- zXqf)8_bfTplV3A$3~%J-can*i=ihh1MJkgP# Date: Mon, 9 Oct 2017 14:22:27 +0200 Subject: [PATCH 10/21] add selector for kiosk --- .../settings/ContentSettingsFragment.java | 85 ++++++-- .../newpipe/settings/SelectKioskFragment.java | 185 ++++++++++++++++++ .../newpipe/util/ServiceIconMapper.java | 35 ++++ app/src/main/res/drawable-nodpi/service.png | Bin 0 -> 5765 bytes .../main/res/layout/select_kiosk_fragment.xml | 26 +++ app/src/main/res/layout/select_kiosk_item.xml | 37 ++++ app/src/main/res/values/strings.xml | 1 + assets/service.svg | 109 +++++++++++ 8 files changed, 466 insertions(+), 12 deletions(-) create mode 100644 app/src/main/java/org/schabi/newpipe/settings/SelectKioskFragment.java create mode 100644 app/src/main/java/org/schabi/newpipe/util/ServiceIconMapper.java create mode 100644 app/src/main/res/drawable-nodpi/service.png create mode 100644 app/src/main/res/layout/select_kiosk_fragment.xml create mode 100644 app/src/main/res/layout/select_kiosk_item.xml create mode 100644 assets/service.svg diff --git a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java index 4c0c7aec3..381c20ff1 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java @@ -1,10 +1,17 @@ package org.schabi.newpipe.settings; +import android.app.Activity; import android.os.Bundle; import android.support.v7.preference.ListPreference; import android.support.v7.preference.Preference; import org.schabi.newpipe.R; +import org.schabi.newpipe.extractor.NewPipe; +import org.schabi.newpipe.extractor.StreamingService; +import org.schabi.newpipe.extractor.exceptions.ExtractionException; +import org.schabi.newpipe.report.ErrorActivity; +import org.schabi.newpipe.report.UserAction; +import org.schabi.newpipe.util.KioskTranslator; public class ContentSettingsFragment extends BasePreferenceFragment { @@ -14,7 +21,6 @@ public class ContentSettingsFragment extends BasePreferenceFragment { addPreferencesFromResource(R.xml.content_settings); final ListPreference mainPageContentPref = (ListPreference) findPreference(getString(R.string.main_page_content_key)); - mainPageContentPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValueO) { @@ -25,7 +31,36 @@ public class ContentSettingsFragment extends BasePreferenceFragment { final String mainPrefOldSummary = getMainPagePrefSummery(mainPrefOldValue, mainPageContentPref); if(newValue.equals(getString(R.string.kiosk_page_key))) { - //todo on multyservice support show a kiosk an service selector here + SelectKioskFragment selectKioskFragment = new SelectKioskFragment(); + selectKioskFragment.setOnSelectedLisener(new SelectKioskFragment.OnSelectedLisener() { + @Override + public void onKioskSelected(String kioskId, int service_id) { + defaultPreferences.edit() + .putInt(getString(R.string.main_page_selected_service), service_id).apply(); + defaultPreferences.edit() + .putString(getString(R.string.main_page_selectd_kiosk_id), kioskId).apply(); + String summary = ""; + try { + summary += NewPipe.getService(service_id).getServiceInfo().name; + } catch (ExtractionException e) { + onError(e); + } + summary += "/"; + summary += KioskTranslator.getTranslatedKioskName(kioskId, getContext()); + + + + mainPageContentPref.setSummary(summary); + } + }); + selectKioskFragment.setOnCancelListener(new SelectKioskFragment.OnCancelListener() { + @Override + public void onCancel() { + mainPageContentPref.setSummary(mainPrefOldSummary); + mainPageContentPref.setValue(mainPrefOldValue); + } + }); + selectKioskFragment.show(getFragmentManager(), "select_kiosk"); } else if(newValue.equals(getString(R.string.channel_page_key))) { SelectChannelFragment selectChannelFragment = new SelectChannelFragment(); selectChannelFragment.setOnSelectedLisener(new SelectChannelFragment.OnSelectedLisener() { @@ -38,23 +73,18 @@ public class ContentSettingsFragment extends BasePreferenceFragment { defaultPreferences.edit() .putString(getString(R.string.main_page_selected_channel_name), name).apply(); - //change summery mainPageContentPref.setSummary(name); } }); selectChannelFragment.setOnCancelListener(new SelectChannelFragment.OnCancelListener() { @Override public void onCancel() { - //defaultPreferences.edit() - // .putString(getString(R.string.main_page_content_key), mainPrefOldValue).apply(); mainPageContentPref.setSummary(mainPrefOldSummary); mainPageContentPref.setValue(mainPrefOldValue); } }); selectChannelFragment.show(getFragmentManager(), "select_channel"); - } - - if(!newValue.equals(getString(R.string.channel_page_key))) { + } else { mainPageContentPref.setSummary(getMainPageSummeryByKey(newValue)); } @@ -68,11 +98,28 @@ public class ContentSettingsFragment extends BasePreferenceFragment { super.onResume(); final String mainPageContentKey = getString(R.string.main_page_content_key); - if(defaultPreferences.getString(mainPageContentKey, - getString(R.string.blank_page_key)) + final Preference mainPagePref = findPreference(getString(R.string.main_page_content_key)); + final String bpk = getString(R.string.blank_page_key); + if(defaultPreferences.getString(mainPageContentKey, bpk) .equals(getString(R.string.channel_page_key))) { - Preference pref = findPreference(getString(R.string.main_page_content_key)); - pref.setSummary(defaultPreferences.getString(getString(R.string.main_page_selected_channel_name), "error")); + mainPagePref.setSummary(defaultPreferences.getString(getString(R.string.main_page_selected_channel_name), "error")); + } else if(defaultPreferences.getString(mainPageContentKey, bpk) + .equals(getString(R.string.kiosk_page_key))) { + try { + StreamingService service = NewPipe.getService( + defaultPreferences.getInt( + getString(R.string.main_page_selected_service), 0)); + String summary = ""; + summary += service.getServiceInfo().name; + summary += "/"; + summary += KioskTranslator.getTranslatedKioskName( + defaultPreferences.getString( + getString(R.string.main_page_selectd_kiosk_id), "Trending"), + getContext()); + mainPagePref.setSummary(summary); + } catch (Exception e) { + onError(e); + } } } @@ -101,4 +148,18 @@ public class ContentSettingsFragment extends BasePreferenceFragment { } return R.string.blank_page_summary; } + + /*////////////////////////////////////////////////////////////////////////// + // Error + //////////////////////////////////////////////////////////////////////////*/ + + protected boolean onError(Throwable e) { + final Activity activity = getActivity(); + ErrorActivity.reportError(activity, e, + activity.getClass(), + null, + ErrorActivity.ErrorInfo.make(UserAction.UI_ERROR, + "none", "", R.string.app_ui_crash)); + return true; + } } diff --git a/app/src/main/java/org/schabi/newpipe/settings/SelectKioskFragment.java b/app/src/main/java/org/schabi/newpipe/settings/SelectKioskFragment.java new file mode 100644 index 000000000..6e7ba191e --- /dev/null +++ b/app/src/main/java/org/schabi/newpipe/settings/SelectKioskFragment.java @@ -0,0 +1,185 @@ +package org.schabi.newpipe.settings; + +import android.app.Activity; +import android.content.DialogInterface; +import android.os.Bundle; +import android.support.v4.app.DialogFragment; +import android.support.v4.content.ContextCompat; +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.ImageView; +import android.widget.TextView; + +import org.schabi.newpipe.R; +import org.schabi.newpipe.database.subscription.SubscriptionEntity; +import org.schabi.newpipe.extractor.NewPipe; +import org.schabi.newpipe.extractor.StreamingService; +import org.schabi.newpipe.fragments.subscription.SubscriptionService; +import org.schabi.newpipe.report.ErrorActivity; +import org.schabi.newpipe.report.UserAction; +import org.schabi.newpipe.util.KioskTranslator; +import org.schabi.newpipe.util.ServiceIconMapper; + +import java.util.List; +import java.util.Vector; + +import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.schedulers.Schedulers; + +/** + * Created by Christian Schabesberger on 09.10.17. + * SelectKioskFragment.java is part of NewPipe. + * + * NewPipe is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * NewPipe is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with NewPipe. If not, see . + */ + +public class SelectKioskFragment extends DialogFragment { + + RecyclerView recyclerView = null; + SelectKioskAdapter selectKioskAdapter = null; + + /*////////////////////////////////////////////////////////////////////////// + // Interfaces + //////////////////////////////////////////////////////////////////////////*/ + + public interface OnSelectedLisener { + void onKioskSelected(String kioskId, int service_id); + } + + OnSelectedLisener onSelectedLisener = null; + public void setOnSelectedLisener(OnSelectedLisener listener) { + onSelectedLisener = listener; + } + + public interface OnCancelListener { + void onCancel(); + } + OnCancelListener onCancelListener = null; + public void setOnCancelListener(OnCancelListener listener) { + onCancelListener = listener; + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + View v = inflater.inflate(R.layout.select_kiosk_fragment, container, false); + recyclerView = (RecyclerView) v.findViewById(R.id.items_list); + recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); + try { + selectKioskAdapter = new SelectKioskAdapter(); + } catch (Exception e) { + onError(e); + } + recyclerView.setAdapter(selectKioskAdapter); + + return v; + } + + /*////////////////////////////////////////////////////////////////////////// + // Handle actions + //////////////////////////////////////////////////////////////////////////*/ + + @Override + public void onCancel(final DialogInterface dialogInterface) { + super.onCancel(dialogInterface); + if(onCancelListener != null) { + onCancelListener.onCancel(); + } + } + + private void clickedItem(SelectKioskAdapter.Entry entry) { + if(onSelectedLisener != null) { + onSelectedLisener.onKioskSelected(entry.kioskId, entry.serviceId); + } + dismiss(); + } + + private class SelectKioskAdapter + extends RecyclerView.Adapter { + public class Entry { + public Entry (int i, int si, String ki, String kn){ + icon = i; serviceId=si; kioskId=ki; kioskName = kn; + } + int icon; + int serviceId; + String kioskId; + String kioskName; + }; + + private List kioskList = new Vector<>(); + + public SelectKioskAdapter() + throws Exception { + for(StreamingService service : NewPipe.getServices()) { + for(String kioskId : service.getKioskList().getAvailableKisoks()) { + kioskList.add(new Entry( + ServiceIconMapper.getIconResource(service.getServiceId()), + service.getServiceId(), + kioskId, + KioskTranslator.getTranslatedKioskName(kioskId, getContext()))); + } + } + } + + public int getItemCount() { + return kioskList.size(); + } + + public SelectKioskItemHolder onCreateViewHolder(ViewGroup parent, int type) { + View item = LayoutInflater.from(parent.getContext()) + .inflate(R.layout.select_kiosk_item, parent, false); + return new SelectKioskItemHolder(item); + } + + public class SelectKioskItemHolder extends RecyclerView.ViewHolder { + public SelectKioskItemHolder(View v) { + super(v); + this.view = v; + thumbnailView = v.findViewById(R.id.itemThumbnailView); + titleView = v.findViewById(R.id.itemTitleView); + } + public View view; + public ImageView thumbnailView; + public TextView titleView; + } + + public void onBindViewHolder(SelectKioskItemHolder holder, final int position) { + final Entry entry = kioskList.get(position); + holder.titleView.setText(entry.kioskName); + holder.thumbnailView.setImageDrawable(ContextCompat.getDrawable(getContext(), entry.icon)); + holder.view.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + clickedItem(entry); + } + }); + } + } + + /*////////////////////////////////////////////////////////////////////////// + // Error + //////////////////////////////////////////////////////////////////////////*/ + + protected boolean onError(Throwable e) { + final Activity activity = getActivity(); + ErrorActivity.reportError(activity, e, + activity.getClass(), + null, + ErrorActivity.ErrorInfo.make(UserAction.UI_ERROR, + "none", "", R.string.app_ui_crash)); + return true; + } +} diff --git a/app/src/main/java/org/schabi/newpipe/util/ServiceIconMapper.java b/app/src/main/java/org/schabi/newpipe/util/ServiceIconMapper.java new file mode 100644 index 000000000..060013dd2 --- /dev/null +++ b/app/src/main/java/org/schabi/newpipe/util/ServiceIconMapper.java @@ -0,0 +1,35 @@ +package org.schabi.newpipe.util; + +import org.schabi.newpipe.R; +import org.schabi.newpipe.extractor.NewPipe; + +/** + * Created by Chrsitian Schabesberger on 09.10.17. + * ServiceIconMapper.java is part of NewPipe. + * + * NewPipe is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * NewPipe is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with NewPipe. If not, see . + */ + +public class ServiceIconMapper { + public static int getIconResource(int service_id) { + switch(service_id) { + case 0: + return R.drawable.youtube; + case 1: + return R.drawable.soud_cloud; + default: + return R.drawable.service; + } + } +} diff --git a/app/src/main/res/drawable-nodpi/service.png b/app/src/main/res/drawable-nodpi/service.png new file mode 100644 index 0000000000000000000000000000000000000000..cfaff19e2df8b3954bae3630c1d68bd811a1e279 GIT binary patch literal 5765 zcmYj#2{=^W|NosqCi~d4WGqG5jUrnbBTEQbv+s#PB4jYKjij+ec7@2ErBU|mGRhKS ztXUFSvhRM^=leYW=YO8L%iMGBx$ot5-skmxN9*fp(9>|y002O*rHM8KuU%&c>>PM5 zH7m;kFO-i_T1GIiVPTGV@c(%)P4ma#_>r>%f)Yvh2OnPWQ8)9s=jrU@XXot%`1$!s zxO%ufcChnulJN9)Nncgs0swZX7W$Tvf5ys0pqJ&gFZKG`XTQ<{af<};o&+~iZXQ3U zb`Rb8P<|#6**`ig&~LK3=U+AinkMAR>hbH!Xw_iSs1sA#Yy)}*prL81-;NNnyMG7| z7abcLd#E#5kHkdu>R z{PZtS%r{Q~hkC6kG%T}u*?E$3+8ZzhK2bJbC8%8h)~~{O?G|3A?291zFb^LtZOXsQ z5ui#4GZQoULNaCPuY=T6H(vvWuQ0grTak`v1rGRh2ZKGxJG7B@FNzq7^fg1p5L~g= zg|1`N05&eQ9Kxi}J17uKu}6i|fG9oW>@aBmx0lA+MHjCrq;F#rlAG^ZgWRNs9EC2W zSniy|@iF)B*45T#Jx2@VFX4{RG?dM&6LqhbYl9VWiqVUg0k$FsL&sOCAvDvr>gw%p z>sD*s(7vig;(wr8LdZvu7YnGX%gy+8vqrN)?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osk_fragment.xml b/app/src/main/res/layout/select_kiosk_fragment.xml new file mode 100644 index 000000000..7be96754a --- /dev/null +++ b/app/src/main/res/layout/select_kiosk_fragment.xml @@ -0,0 +1,26 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/select_kiosk_item.xml b/app/src/main/res/layout/select_kiosk_item.xml new file mode 100644 index 000000000..818380849 --- /dev/null +++ b/app/src/main/res/layout/select_kiosk_item.xml @@ -0,0 +1,37 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e11483ac0..371ad1688 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -282,6 +282,7 @@ Select a channel No channel subscribed yet + Select a kiosk Kisok diff --git a/assets/service.svg b/assets/service.svg new file mode 100644 index 000000000..172cc106f --- /dev/null +++ b/assets/service.svg @@ -0,0 +1,109 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + From 7fcc07805a20d0eb350e3efd77b3ca18777243c1 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Mon, 9 Oct 2017 14:34:10 +0200 Subject: [PATCH 11/21] make kiosk selector signle service again --- .../org/schabi/newpipe/fragments/MainFragment.java | 12 +++++++----- .../schabi/newpipe/settings/SelectKioskFragment.java | 12 +++++++++--- 2 files changed, 16 insertions(+), 8 deletions(-) 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 4ba648402..48f2d150e 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java @@ -185,13 +185,17 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte private Fragment getMainPageFramgent() { try { - final String set_main_page = PreferenceManager.getDefaultSharedPreferences(getActivity()) - .getString(getString(R.string.main_page_content_key), + SharedPreferences preferences = + PreferenceManager.getDefaultSharedPreferences(getActivity()); + final String set_main_page = preferences.getString(getString(R.string.main_page_content_key), getString(R.string.main_page_selectd_kiosk_id)); if(set_main_page.equals(getString(R.string.blank_page_key))) { return new BlankFragment(); } else if(set_main_page.equals(getString(R.string.kiosk_page_key))) { - KioskFragment fragment = KioskFragment.getInstance(currentServiceId); + int serviceId = preferences.getInt(getString(R.string.main_page_selected_service), 0); + String kioskId = preferences.getString(getString(R.string.main_page_selectd_kiosk_id), "Trending"); + KioskFragment fragment = KioskFragment.getInstance(serviceId, kioskId + ); fragment.useAsFrontPage(true); return fragment; } else if(set_main_page.equals(getString(R.string.feed_page_key))) { @@ -199,8 +203,6 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte fragment.useAsFrontPage(true); return fragment; } else if(set_main_page.equals(getString(R.string.channel_page_key))) { - SharedPreferences preferences = - PreferenceManager.getDefaultSharedPreferences(getActivity()); int serviceId = preferences.getInt(getString(R.string.main_page_selected_service), 0); String url = preferences.getString(getString(R.string.main_page_selected_channel_url), "https://www.youtube.com/channel/UC-9-kyTW8ZkZNDHQJ6FgpwQ"); diff --git a/app/src/main/java/org/schabi/newpipe/settings/SelectKioskFragment.java b/app/src/main/java/org/schabi/newpipe/settings/SelectKioskFragment.java index 6e7ba191e..204b35905 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/SelectKioskFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/SelectKioskFragment.java @@ -117,25 +117,31 @@ public class SelectKioskFragment extends DialogFragment { int serviceId; String kioskId; String kioskName; - }; + } private List kioskList = new Vector<>(); public SelectKioskAdapter() throws Exception { + for(StreamingService service : NewPipe.getServices()) { for(String kioskId : service.getKioskList().getAvailableKisoks()) { + String name = service.getServiceInfo().name; + name += "/"; + name += KioskTranslator.getTranslatedKioskName(kioskId, getContext()); kioskList.add(new Entry( ServiceIconMapper.getIconResource(service.getServiceId()), service.getServiceId(), kioskId, - KioskTranslator.getTranslatedKioskName(kioskId, getContext()))); + name)); } } } public int getItemCount() { - return kioskList.size(); + //todo: uncommend this line on multyservice support + //return kioskList.size(); + return 1; } public SelectKioskItemHolder onCreateViewHolder(ViewGroup parent, int type) { From 0951f0f824fb55e4a2d4e28487ef1a9ddeb3dfae Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Wed, 11 Oct 2017 15:24:57 +0200 Subject: [PATCH 12/21] small fixes small fixes --- .../schabi/newpipe/fragments/list/kiosk/KioskFragment.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java index 8e1acb572..c308fe1ec 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java @@ -48,7 +48,7 @@ import static org.schabi.newpipe.util.AnimationUtils.animateView; * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with OpenHitboxStreams. If not, see . + * along with NewPipe. If not, see . */ public class KioskFragment extends BaseListInfoFragment { @@ -147,7 +147,10 @@ public class KioskFragment extends BaseListInfoFragment { super.handleResult(result); animateView(headerRootLayout, true, 100); - headerTitleView.setText("★★ " + KioskTranslator.getTranslatedKioskName(result.id, getActivity())+ " ★★"); + String title = KioskTranslator.getTranslatedKioskName(result.id, getActivity()); + headerTitleView.setText("★★ " + title + " ★★"); + ActionBar supportActionBar = activity.getSupportActionBar(); + supportActionBar.setTitle(title); if (!result.errors.isEmpty()) { showSnackBarError(result.errors, From 8e8d74b5b7bb0c3d00b3fbcacd20461ffdc96222 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Fri, 13 Oct 2017 13:01:16 +0200 Subject: [PATCH 13/21] remove header front kiosk --- .../fragments/list/kiosk/KioskFragment.java | 14 ----------- app/src/main/res/layout/kiosk_header.xml | 23 ------------------- 2 files changed, 37 deletions(-) delete mode 100644 app/src/main/res/layout/kiosk_header.xml diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java index c308fe1ec..b1387b1ad 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java @@ -102,17 +102,6 @@ public class KioskFragment extends BaseListInfoFragment { } } - /*////////////////////////////////////////////////////////////////////////// - // Init - //////////////////////////////////////////////////////////////////////////*/ - - protected View getListHeader() { - headerRootLayout = activity.getLayoutInflater().inflate(R.layout.kiosk_header, itemsList, false); - headerTitleView = headerRootLayout.findViewById(R.id.kiosk_title_view); - - return headerRootLayout; - } - /*////////////////////////////////////////////////////////////////////////// // Load and handle //////////////////////////////////////////////////////////////////////////*/ @@ -138,7 +127,6 @@ public class KioskFragment extends BaseListInfoFragment { @Override public void showLoading() { super.showLoading(); - animateView(headerRootLayout, false, 200); animateView(itemsList, false, 100); } @@ -146,9 +134,7 @@ public class KioskFragment extends BaseListInfoFragment { public void handleResult(@NonNull final KioskInfo result) { super.handleResult(result); - animateView(headerRootLayout, true, 100); String title = KioskTranslator.getTranslatedKioskName(result.id, getActivity()); - headerTitleView.setText("★★ " + title + " ★★"); ActionBar supportActionBar = activity.getSupportActionBar(); supportActionBar.setTitle(title); diff --git a/app/src/main/res/layout/kiosk_header.xml b/app/src/main/res/layout/kiosk_header.xml deleted file mode 100644 index c161ca83d..000000000 --- a/app/src/main/res/layout/kiosk_header.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - \ No newline at end of file From 23eeb4353dc96504f1fa6a8fbc8a5e1b5256c757 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Fri, 13 Oct 2017 13:49:31 +0200 Subject: [PATCH 14/21] make main page changes display emediatly --- app/src/main/java/org/schabi/newpipe/MainActivity.java | 6 ++++++ .../java/org/schabi/newpipe/fragments/MainFragment.java | 1 + .../schabi/newpipe/settings/ContentSettingsFragment.java | 3 +++ app/src/main/java/org/schabi/newpipe/util/Constants.java | 1 + .../main/java/org/schabi/newpipe/util/NavigationHelper.java | 2 +- 5 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java index 67689d541..3ff55cb76 100644 --- a/app/src/main/java/org/schabi/newpipe/MainActivity.java +++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java @@ -119,6 +119,12 @@ public class MainActivity extends AppCompatActivity implements HistoryListener { }); } + if(sharedPreferences.getBoolean(Constants.KEY_MAIN_PAGE_CHANGE, false)) { + if (DEBUG) Log.d(TAG, "main page has changed, recreating main fragment..."); + sharedPreferences.edit().putBoolean(Constants.KEY_MAIN_PAGE_CHANGE, false).apply(); + NavigationHelper.openMainActivity(this); + } + } @Override 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 48f2d150e..ba09f4001 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java @@ -30,6 +30,7 @@ import org.schabi.newpipe.fragments.list.kiosk.KioskFragment; import org.schabi.newpipe.fragments.subscription.SubscriptionFragment; import org.schabi.newpipe.report.ErrorActivity; import org.schabi.newpipe.report.UserAction; +import org.schabi.newpipe.util.Constants; import org.schabi.newpipe.util.KioskTranslator; import org.schabi.newpipe.util.NavigationHelper; diff --git a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java index 381c20ff1..aeba78cbd 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java @@ -11,6 +11,7 @@ import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.report.ErrorActivity; import org.schabi.newpipe.report.UserAction; +import org.schabi.newpipe.util.Constants; import org.schabi.newpipe.util.KioskTranslator; public class ContentSettingsFragment extends BasePreferenceFragment { @@ -88,6 +89,8 @@ public class ContentSettingsFragment extends BasePreferenceFragment { mainPageContentPref.setSummary(getMainPageSummeryByKey(newValue)); } + defaultPreferences.edit().putBoolean(Constants.KEY_MAIN_PAGE_CHANGE, true).apply(); + return true; } }); diff --git a/app/src/main/java/org/schabi/newpipe/util/Constants.java b/app/src/main/java/org/schabi/newpipe/util/Constants.java index f9329b0be..08e64aceb 100644 --- a/app/src/main/java/org/schabi/newpipe/util/Constants.java +++ b/app/src/main/java/org/schabi/newpipe/util/Constants.java @@ -9,4 +9,5 @@ public class Constants { public static final String KEY_QUERY = "key_query"; public static final String KEY_THEME_CHANGE = "key_theme_change"; + public static final String KEY_MAIN_PAGE_CHANGE = "key_main_page_change"; } diff --git a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java index b30407315..b08251436 100644 --- a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java @@ -94,7 +94,7 @@ public class NavigationHelper { if (!popped) openMainFragment(fragmentManager); } - private static void openMainFragment(FragmentManager fragmentManager) { + public static void openMainFragment(FragmentManager fragmentManager) { InfoCache.getInstance().trimCache(); fragmentManager.popBackStackImmediate(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); From d928f5759fd358be5e48a309922a8c74b2eb604a Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Fri, 13 Oct 2017 13:55:55 +0200 Subject: [PATCH 15/21] try to fix margin / padding --- app/src/main/res/layout/select_channel_fragment.xml | 6 ++++-- app/src/main/res/layout/select_channel_item.xml | 2 -- app/src/main/res/layout/select_kiosk_fragment.xml | 3 ++- app/src/main/res/layout/select_kiosk_item.xml | 2 -- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/app/src/main/res/layout/select_channel_fragment.xml b/app/src/main/res/layout/select_channel_fragment.xml index 9c8e79779..11c723b4b 100644 --- a/app/src/main/res/layout/select_channel_fragment.xml +++ b/app/src/main/res/layout/select_channel_fragment.xml @@ -3,7 +3,8 @@ xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical" android:layout_width="match_parent" - android:layout_height="match_parent"> + android:layout_height="match_parent" + android:padding="13dp"> + android:layout_marginEnd="5dp" + android:layout_marginBottom="10dp"/> + android:layout_height="match_parent" + android:padding="13dp"> Date: Sun, 22 Oct 2017 21:46:50 +0200 Subject: [PATCH 16/21] fix Kisok spelling error --- app/build.gradle | 2 +- .../main/java/org/schabi/newpipe/fragments/MainFragment.java | 2 +- .../java/org/schabi/newpipe/settings/SelectKioskFragment.java | 2 +- app/src/main/res/values/strings.xml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 2f1dd4005..529d04425 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -48,7 +48,7 @@ dependencies { exclude module: 'support-annotations' } - compile 'com.github.TeamNewPipe:NewPipeExtractor:1df3f67' + compile 'com.github.TeamNewPipe:NewPipeExtractor:7899cd1' testCompile 'junit:junit:4.12' testCompile 'org.mockito:mockito-core:1.10.19' 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 ba09f4001..f26f9739e 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java @@ -234,7 +234,7 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte StreamingService service = NewPipe.getService(currentServiceId); KioskList kl = service.getKioskList(); int i = 0; - for(final String ks : kl.getAvailableKisoks()) { + for(final String ks : kl.getAvailableKiosks()) { menu.add(0, KIOSK_MENU_OFFSETT + i, Menu.NONE, KioskTranslator.getTranslatedKioskName(ks, getContext())) .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { diff --git a/app/src/main/java/org/schabi/newpipe/settings/SelectKioskFragment.java b/app/src/main/java/org/schabi/newpipe/settings/SelectKioskFragment.java index 204b35905..3f84f9006 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/SelectKioskFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/SelectKioskFragment.java @@ -125,7 +125,7 @@ public class SelectKioskFragment extends DialogFragment { throws Exception { for(StreamingService service : NewPipe.getServices()) { - for(String kioskId : service.getKioskList().getAvailableKisoks()) { + for(String kioskId : service.getKioskList().getAvailableKiosks()) { String name = service.getServiceInfo().name; name += "/"; name += KioskTranslator.getTranslatedKioskName(kioskId, getContext()); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e552177c5..035e94418 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -286,7 +286,7 @@ Select a kiosk - Kisok + Kiosk Trending Top 50 New & hot From d1f446aae241357b0294f5bf64829c2e27e6ed3c Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Sun, 22 Oct 2017 22:06:25 +0200 Subject: [PATCH 17/21] make summary a dynamic string --- .../settings/ContentSettingsFragment.java | 25 ++++++++++++------- app/src/main/res/values/strings.xml | 1 + 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java index aeba78cbd..4f6c2d1ae 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java @@ -40,16 +40,19 @@ public class ContentSettingsFragment extends BasePreferenceFragment { .putInt(getString(R.string.main_page_selected_service), service_id).apply(); defaultPreferences.edit() .putString(getString(R.string.main_page_selectd_kiosk_id), kioskId).apply(); - String summary = ""; + String serviceName = ""; try { - summary += NewPipe.getService(service_id).getServiceInfo().name; + serviceName = NewPipe.getService(service_id).getServiceInfo().name; } catch (ExtractionException e) { onError(e); } - summary += "/"; - summary += KioskTranslator.getTranslatedKioskName(kioskId, getContext()); - + String kioskName = KioskTranslator.getTranslatedKioskName(kioskId, + getContext()); + String summary = + String.format(getString(R.string.service_kosk_string), + serviceName, + kioskName); mainPageContentPref.setSummary(summary); } @@ -112,13 +115,17 @@ public class ContentSettingsFragment extends BasePreferenceFragment { StreamingService service = NewPipe.getService( defaultPreferences.getInt( getString(R.string.main_page_selected_service), 0)); - String summary = ""; - summary += service.getServiceInfo().name; - summary += "/"; - summary += KioskTranslator.getTranslatedKioskName( + + String kioskName = KioskTranslator.getTranslatedKioskName( defaultPreferences.getString( getString(R.string.main_page_selectd_kiosk_id), "Trending"), getContext()); + + String summary = + String.format(getString(R.string.service_kosk_string), + service.getServiceInfo().name, + kioskName); + mainPagePref.setSummary(summary); } catch (Exception e) { onError(e); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 035e94418..94b185988 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -290,4 +290,5 @@ Trending Top 50 New & hot + %1$s/%2$s From fd899a2e9505211d301492e5a2e542a940292bd0 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Sun, 22 Oct 2017 22:10:48 +0200 Subject: [PATCH 18/21] fix cammel case --- .../org/schabi/newpipe/fragments/MainFragment.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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 f26f9739e..a1dd34467 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java @@ -188,22 +188,22 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte try { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity()); - final String set_main_page = preferences.getString(getString(R.string.main_page_content_key), + final String setMainPage = preferences.getString(getString(R.string.main_page_content_key), getString(R.string.main_page_selectd_kiosk_id)); - if(set_main_page.equals(getString(R.string.blank_page_key))) { + if(setMainPage.equals(getString(R.string.blank_page_key))) { return new BlankFragment(); - } else if(set_main_page.equals(getString(R.string.kiosk_page_key))) { + } else if(setMainPage.equals(getString(R.string.kiosk_page_key))) { int serviceId = preferences.getInt(getString(R.string.main_page_selected_service), 0); String kioskId = preferences.getString(getString(R.string.main_page_selectd_kiosk_id), "Trending"); KioskFragment fragment = KioskFragment.getInstance(serviceId, kioskId ); fragment.useAsFrontPage(true); return fragment; - } else if(set_main_page.equals(getString(R.string.feed_page_key))) { + } else if(setMainPage.equals(getString(R.string.feed_page_key))) { FeedFragment fragment = new FeedFragment(); fragment.useAsFrontPage(true); return fragment; - } else if(set_main_page.equals(getString(R.string.channel_page_key))) { + } else if(setMainPage.equals(getString(R.string.channel_page_key))) { int serviceId = preferences.getInt(getString(R.string.main_page_selected_service), 0); String url = preferences.getString(getString(R.string.main_page_selected_channel_url), "https://www.youtube.com/channel/UC-9-kyTW8ZkZNDHQJ6FgpwQ"); From 54cdfc0c1650750d5a6c2b98cf4a6b6847903d02 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Sun, 22 Oct 2017 22:53:27 +0200 Subject: [PATCH 19/21] deactivate icon --- .../org/schabi/newpipe/settings/SelectKioskFragment.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/settings/SelectKioskFragment.java b/app/src/main/java/org/schabi/newpipe/settings/SelectKioskFragment.java index 3f84f9006..0a8f3bfdc 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/SelectKioskFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/SelectKioskFragment.java @@ -126,11 +126,12 @@ public class SelectKioskFragment extends DialogFragment { for(StreamingService service : NewPipe.getServices()) { for(String kioskId : service.getKioskList().getAvailableKiosks()) { - String name = service.getServiceInfo().name; - name += "/"; - name += KioskTranslator.getTranslatedKioskName(kioskId, getContext()); + String name = String.format(getString(R.string.service_kosk_string), + service.getServiceInfo().name, + KioskTranslator.getTranslatedKioskName(kioskId, getContext())); kioskList.add(new Entry( - ServiceIconMapper.getIconResource(service.getServiceId()), + //ServiceIconMapper.getIconResource(service.getServiceId()), + 0, service.getServiceId(), kioskId, name)); From ccd26b4146de9d32b622f8577dd28c08db3973e0 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Sun, 22 Oct 2017 23:56:39 +0200 Subject: [PATCH 20/21] fix kiosk service/icon --- .../java/org/schabi/newpipe/settings/SelectKioskFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/org/schabi/newpipe/settings/SelectKioskFragment.java b/app/src/main/java/org/schabi/newpipe/settings/SelectKioskFragment.java index 0a8f3bfdc..a9f0a53ed 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/SelectKioskFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/SelectKioskFragment.java @@ -131,7 +131,7 @@ public class SelectKioskFragment extends DialogFragment { KioskTranslator.getTranslatedKioskName(kioskId, getContext())); kioskList.add(new Entry( //ServiceIconMapper.getIconResource(service.getServiceId()), - 0, + ServiceIconMapper.getIconResource(-1), service.getServiceId(), kioskId, name)); From 7d296ee65056d783253e5b26808da01d29a97588 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Mon, 23 Oct 2017 00:26:20 +0200 Subject: [PATCH 21/21] remove hardcoded strings form MainFragment --- .../newpipe/fragments/MainFragment.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) 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 a1dd34467..317630faa 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java @@ -40,6 +40,12 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte private ViewPager viewPager; private boolean showBlankTab = false; + private static final int FALLBACK_SERVICE_ID = 0; // Youtbe + 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"; + public int currentServiceId = -1; /*////////////////////////////////////////////////////////////////////////// @@ -193,8 +199,10 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte if(setMainPage.equals(getString(R.string.blank_page_key))) { return new BlankFragment(); } else if(setMainPage.equals(getString(R.string.kiosk_page_key))) { - int serviceId = preferences.getInt(getString(R.string.main_page_selected_service), 0); - String kioskId = preferences.getString(getString(R.string.main_page_selectd_kiosk_id), "Trending"); + int serviceId = preferences.getInt(getString(R.string.main_page_selected_service), + FALLBACK_SERVICE_ID); + String kioskId = preferences.getString(getString(R.string.main_page_selectd_kiosk_id), + FALLBACK_KIOSK_ID); KioskFragment fragment = KioskFragment.getInstance(serviceId, kioskId ); fragment.useAsFrontPage(true); @@ -204,10 +212,12 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte fragment.useAsFrontPage(true); return fragment; } else if(setMainPage.equals(getString(R.string.channel_page_key))) { - int serviceId = preferences.getInt(getString(R.string.main_page_selected_service), 0); + int serviceId = preferences.getInt(getString(R.string.main_page_selected_service), + FALLBACK_SERVICE_ID); String url = preferences.getString(getString(R.string.main_page_selected_channel_url), - "https://www.youtube.com/channel/UC-9-kyTW8ZkZNDHQJ6FgpwQ"); - String name = preferences.getString(getString(R.string.main_page_selected_channel_name), "Music"); + FALLBACK_CHANNEL_URL); + String name = preferences.getString(getString(R.string.main_page_selected_channel_name), + FALLBACK_CHANNEL_NAME); ChannelFragment fragment = ChannelFragment.getInstance(serviceId, url, name); fragment.useAsFrontPage(true); return fragment;