From 0d2296917a791d26845ffdd7c4040480c867a901 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Sat, 23 Sep 2017 17:39:04 +0200 Subject: [PATCH] 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