2017-09-25 12:49:14 +02:00
|
|
|
package org.schabi.newpipe.fragments.list.kiosk;
|
2017-09-23 17:39:04 +02:00
|
|
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.preference.PreferenceManager;
|
|
|
|
import android.support.annotation.NonNull;
|
|
|
|
import android.support.annotation.Nullable;
|
2017-09-25 12:49:14 +02:00
|
|
|
import android.support.v7.app.ActionBar;
|
2017-12-29 15:02:23 +01:00
|
|
|
import android.util.Log;
|
2017-09-23 17:39:04 +02:00
|
|
|
import android.view.LayoutInflater;
|
2017-09-25 12:49:14 +02:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
2017-09-23 17:39:04 +02:00
|
|
|
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;
|
2017-09-25 12:49:14 +02:00
|
|
|
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
2017-09-23 17:39:04 +02:00
|
|
|
import org.schabi.newpipe.fragments.list.BaseListInfoFragment;
|
2017-09-25 12:49:14 +02:00
|
|
|
import org.schabi.newpipe.info_list.InfoItemBuilder;
|
2017-09-23 17:39:04 +02:00
|
|
|
import org.schabi.newpipe.report.UserAction;
|
|
|
|
import org.schabi.newpipe.util.ExtractorHelper;
|
2017-09-28 16:15:09 +02:00
|
|
|
import org.schabi.newpipe.util.KioskTranslator;
|
2017-09-23 17:39:04 +02:00
|
|
|
import org.schabi.newpipe.util.NavigationHelper;
|
|
|
|
|
2017-11-12 23:56:45 +01:00
|
|
|
import icepick.State;
|
2017-09-23 17:39:04 +02:00
|
|
|
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 <chris.schabesberger@mailbox.org>
|
|
|
|
* 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
|
2017-10-11 15:24:57 +02:00
|
|
|
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
|
2017-09-23 17:39:04 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
public class KioskFragment extends BaseListInfoFragment<KioskInfo> {
|
|
|
|
|
2017-11-12 23:56:45 +01:00
|
|
|
@State
|
2017-11-14 12:14:01 +01:00
|
|
|
protected String kioskId = "";
|
2018-01-30 08:01:57 +01:00
|
|
|
protected String kioskTranslatedName;
|
2017-10-26 15:16:35 +02:00
|
|
|
|
2017-09-23 17:39:04 +02:00
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Views
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
|
|
|
public static KioskFragment getInstance(int serviceId)
|
|
|
|
throws ExtractionException {
|
2017-10-05 14:57:19 +02:00
|
|
|
return getInstance(serviceId, NewPipe.getService(serviceId)
|
|
|
|
.getKioskList()
|
|
|
|
.getDefaultKioskId());
|
|
|
|
}
|
|
|
|
|
|
|
|
public static KioskFragment getInstance(int serviceId, String kioskId)
|
|
|
|
throws ExtractionException {
|
2017-09-23 17:39:04 +02:00
|
|
|
KioskFragment instance = new KioskFragment();
|
|
|
|
StreamingService service = NewPipe.getService(serviceId);
|
2017-10-05 14:57:19 +02:00
|
|
|
UrlIdHandler kioskTypeUrlIdHandler = service.getKioskList()
|
|
|
|
.getUrlIdHandlerByType(kioskId);
|
2017-09-23 17:39:04 +02:00
|
|
|
instance.setInitialData(serviceId,
|
2017-10-05 14:57:19 +02:00
|
|
|
kioskTypeUrlIdHandler.getUrl(kioskId),
|
|
|
|
kioskId);
|
2017-10-26 15:16:35 +02:00
|
|
|
instance.kioskId = kioskId;
|
2017-09-23 17:39:04 +02:00
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// LifeCycle
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
2017-12-17 12:55:30 +01:00
|
|
|
@Override
|
2018-01-30 08:01:57 +01:00
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
kioskTranslatedName = KioskTranslator.getTranslatedKioskName(kioskId, activity);
|
|
|
|
name = kioskTranslatedName;
|
2017-12-17 12:55:30 +01:00
|
|
|
}
|
|
|
|
|
2017-10-26 15:16:35 +02:00
|
|
|
@Override
|
|
|
|
public void setUserVisibleHint(boolean isVisibleToUser) {
|
|
|
|
super.setUserVisibleHint(isVisibleToUser);
|
2017-12-17 12:55:30 +01:00
|
|
|
if(useAsFrontPage && isVisibleToUser && activity != null) {
|
2017-10-26 15:16:35 +02:00
|
|
|
try {
|
2018-01-30 08:01:57 +01:00
|
|
|
setTitle(kioskTranslatedName);
|
2017-10-26 15:16:35 +02:00
|
|
|
} catch (Exception e) {
|
2017-12-17 12:55:30 +01:00
|
|
|
onUnrecoverableError(e, UserAction.UI_ERROR,
|
|
|
|
"none",
|
|
|
|
"none", R.string.app_ui_crash);
|
2017-10-26 15:16:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-23 17:39:04 +02:00
|
|
|
@Override
|
2018-01-30 08:01:57 +01:00
|
|
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
|
|
|
return inflater.inflate(R.layout.fragment_kiosk, container, false);
|
2017-09-23 17:39:04 +02:00
|
|
|
}
|
|
|
|
|
2017-09-25 12:49:14 +02:00
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Menu
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
|
|
|
super.onCreateOptionsMenu(menu, inflater);
|
|
|
|
ActionBar supportActionBar = activity.getSupportActionBar();
|
2017-09-26 18:16:39 +02:00
|
|
|
if (supportActionBar != null && useAsFrontPage) {
|
2017-09-25 12:49:14 +02:00
|
|
|
supportActionBar.setDisplayHomeAsUpEnabled(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-23 17:39:04 +02:00
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Load and handle
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Single<KioskInfo> loadResult(boolean forceReload) {
|
|
|
|
String contentCountry = PreferenceManager
|
|
|
|
.getDefaultSharedPreferences(activity)
|
2018-01-09 12:25:40 +01:00
|
|
|
.getString(getString(R.string.content_country_key),
|
|
|
|
getString(R.string.default_country_value));
|
2017-09-23 17:39:04 +02:00
|
|
|
return ExtractorHelper.getKioskInfo(serviceId, url, contentCountry, forceReload);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-03-18 16:37:49 +01:00
|
|
|
public Single<ListExtractor.InfoItemsPage> loadMoreItemsLogic() {
|
2017-12-29 15:02:23 +01:00
|
|
|
String contentCountry = PreferenceManager
|
|
|
|
.getDefaultSharedPreferences(activity)
|
2018-01-09 12:25:40 +01:00
|
|
|
.getString(getString(R.string.content_country_key),
|
|
|
|
getString(R.string.default_country_value));
|
2018-02-24 22:57:25 +01:00
|
|
|
return ExtractorHelper.getMoreKioskItems(serviceId, url, currentNextPageUrl, contentCountry);
|
2017-09-23 17:39:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Contract
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void showLoading() {
|
|
|
|
super.showLoading();
|
|
|
|
animateView(itemsList, false, 100);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void handleResult(@NonNull final KioskInfo result) {
|
|
|
|
super.handleResult(result);
|
|
|
|
|
2018-01-30 08:01:57 +01:00
|
|
|
name = kioskTranslatedName;
|
|
|
|
setTitle(kioskTranslatedName);
|
2017-09-23 17:39:04 +02:00
|
|
|
|
2017-12-08 15:05:08 +01:00
|
|
|
if (!result.getErrors().isEmpty()) {
|
|
|
|
showSnackBarError(result.getErrors(),
|
2017-09-23 17:39:04 +02:00
|
|
|
UserAction.REQUESTED_PLAYLIST,
|
2017-12-08 15:05:08 +01:00
|
|
|
NewPipe.getNameOfService(result.getServiceId()), result.getUrl(), 0);
|
2017-09-23 17:39:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-03-18 16:37:49 +01:00
|
|
|
public void handleNextItems(ListExtractor.InfoItemsPage result) {
|
2017-09-23 17:39:04 +02:00
|
|
|
super.handleNextItems(result);
|
|
|
|
|
2017-12-08 15:05:08 +01:00
|
|
|
if (!result.getErrors().isEmpty()) {
|
|
|
|
showSnackBarError(result.getErrors(),
|
2017-09-23 17:39:04 +02:00
|
|
|
UserAction.REQUESTED_PLAYLIST, NewPipe.getNameOfService(serviceId)
|
|
|
|
, "Get next page of: " + url, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|