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.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;
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.appcompat.app.ActionBar;
|
|
|
|
|
2017-09-23 17:39:04 +02:00
|
|
|
import org.schabi.newpipe.R;
|
2020-12-11 14:55:47 +01:00
|
|
|
import org.schabi.newpipe.error.ErrorInfo;
|
2020-12-11 15:07:18 +01:00
|
|
|
import org.schabi.newpipe.error.UserAction;
|
2017-09-23 17:39:04 +02:00
|
|
|
import org.schabi.newpipe.extractor.ListExtractor;
|
|
|
|
import org.schabi.newpipe.extractor.NewPipe;
|
|
|
|
import org.schabi.newpipe.extractor.StreamingService;
|
|
|
|
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
|
|
|
import org.schabi.newpipe.extractor.kiosk.KioskInfo;
|
2018-07-15 21:21:09 +02:00
|
|
|
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
|
2019-10-20 17:31:46 +02:00
|
|
|
import org.schabi.newpipe.extractor.localization.ContentCountry;
|
2017-09-23 17:39:04 +02:00
|
|
|
import org.schabi.newpipe.fragments.list.BaseListInfoFragment;
|
|
|
|
import org.schabi.newpipe.util.ExtractorHelper;
|
2017-09-28 16:15:09 +02:00
|
|
|
import org.schabi.newpipe.util.KioskTranslator;
|
2019-10-20 17:31:46 +02:00
|
|
|
import org.schabi.newpipe.util.Localization;
|
2017-09-23 17:39:04 +02:00
|
|
|
|
2017-11-12 23:56:45 +01:00
|
|
|
import icepick.State;
|
2020-10-31 21:55:45 +01:00
|
|
|
import io.reactivex.rxjava3.core.Single;
|
2017-09-23 17:39:04 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by Christian Schabesberger on 23.09.17.
|
2020-03-31 19:20:15 +02:00
|
|
|
* <p>
|
2017-09-23 17:39:04 +02:00
|
|
|
* Copyright (C) Christian Schabesberger 2017 <chris.schabesberger@mailbox.org>
|
|
|
|
* KioskFragment.java is part of NewPipe.
|
2020-03-31 19:20:15 +02:00
|
|
|
* </p>
|
|
|
|
* <p>
|
2017-09-23 17:39:04 +02:00
|
|
|
* 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.
|
2020-03-31 19:20:15 +02:00
|
|
|
* </p>
|
|
|
|
* <p>
|
2017-09-23 17:39:04 +02:00
|
|
|
* 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.
|
2020-03-31 19:20:15 +02:00
|
|
|
* </p>
|
|
|
|
* <p>
|
2017-09-23 17:39:04 +02:00
|
|
|
* You should have received a copy of the GNU General Public License
|
2020-03-31 19:20:15 +02:00
|
|
|
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* </p>
|
2017-09-23 17:39:04 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
public class KioskFragment extends BaseListInfoFragment<KioskInfo> {
|
2017-11-12 23:56:45 +01:00
|
|
|
@State
|
2020-03-31 19:20:15 +02:00
|
|
|
String kioskId = "";
|
|
|
|
String kioskTranslatedName;
|
2019-10-20 17:31:46 +02:00
|
|
|
@State
|
2020-03-31 19:20:15 +02:00
|
|
|
ContentCountry contentCountry;
|
2018-06-11 11:01:18 +02:00
|
|
|
|
2017-09-23 17:39:04 +02:00
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Views
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
public static KioskFragment getInstance(final int serviceId) throws ExtractionException {
|
2017-10-05 14:57:19 +02:00
|
|
|
return getInstance(serviceId, NewPipe.getService(serviceId)
|
2020-03-31 19:20:15 +02:00
|
|
|
.getKioskList().getDefaultKioskId());
|
2017-10-05 14:57:19 +02:00
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
public static KioskFragment getInstance(final int serviceId, final String kioskId)
|
2017-10-05 14:57:19 +02:00
|
|
|
throws ExtractionException {
|
2020-08-16 10:24:58 +02:00
|
|
|
final KioskFragment instance = new KioskFragment();
|
|
|
|
final StreamingService service = NewPipe.getService(serviceId);
|
|
|
|
final ListLinkHandlerFactory kioskLinkHandlerFactory = service.getKioskList()
|
2018-07-15 21:21:09 +02:00
|
|
|
.getListLinkHandlerFactoryByType(kioskId);
|
2017-09-23 17:39:04 +02:00
|
|
|
instance.setInitialData(serviceId,
|
2018-07-15 21:21:09 +02:00
|
|
|
kioskLinkHandlerFactory.fromId(kioskId).getUrl(), kioskId);
|
2017-10-26 15:16:35 +02:00
|
|
|
instance.kioskId = kioskId;
|
2017-09-23 17:39:04 +02:00
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
2020-12-11 14:55:47 +01:00
|
|
|
public KioskFragment() {
|
|
|
|
super(UserAction.REQUESTED_KIOSK);
|
|
|
|
}
|
|
|
|
|
2017-09-23 17:39:04 +02:00
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// LifeCycle
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
2017-12-17 12:55:30 +01:00
|
|
|
@Override
|
2020-03-31 19:20:15 +02:00
|
|
|
public void onCreate(final Bundle savedInstanceState) {
|
2018-01-30 08:01:57 +01:00
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
kioskTranslatedName = KioskTranslator.getTranslatedKioskName(kioskId, activity);
|
|
|
|
name = kioskTranslatedName;
|
2019-10-20 17:31:46 +02:00
|
|
|
contentCountry = Localization.getPreferredContentCountry(requireContext());
|
2017-12-17 12:55:30 +01:00
|
|
|
}
|
|
|
|
|
2017-10-26 15:16:35 +02:00
|
|
|
@Override
|
2020-03-31 19:20:15 +02:00
|
|
|
public void setUserVisibleHint(final boolean isVisibleToUser) {
|
2017-10-26 15:16:35 +02:00
|
|
|
super.setUserVisibleHint(isVisibleToUser);
|
2020-03-31 19:20:15 +02: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);
|
2020-08-16 10:24:58 +02:00
|
|
|
} catch (final Exception e) {
|
2020-12-11 14:55:47 +01:00
|
|
|
showSnackBarError(new ErrorInfo(e, UserAction.UI_ERROR, "Setting kiosk title"));
|
2017-10-26 15:16:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-23 17:39:04 +02:00
|
|
|
@Override
|
2020-03-31 19:20:15 +02:00
|
|
|
public View onCreateView(@NonNull final LayoutInflater inflater,
|
|
|
|
@Nullable final ViewGroup container,
|
|
|
|
@Nullable final Bundle savedInstanceState) {
|
2018-01-30 08:01:57 +01:00
|
|
|
return inflater.inflate(R.layout.fragment_kiosk, container, false);
|
2017-09-23 17:39:04 +02:00
|
|
|
}
|
|
|
|
|
2019-10-20 17:31:46 +02:00
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
|
|
|
|
if (!Localization.getPreferredContentCountry(requireContext()).equals(contentCountry)) {
|
|
|
|
reloadContent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-25 12:49:14 +02:00
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Menu
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
|
|
|
@Override
|
2021-06-20 00:29:18 +02:00
|
|
|
public void onCreateOptionsMenu(@NonNull final Menu menu,
|
|
|
|
@NonNull final MenuInflater inflater) {
|
2017-09-25 12:49:14 +02:00
|
|
|
super.onCreateOptionsMenu(menu, inflater);
|
2020-08-16 10:24:58 +02:00
|
|
|
final 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
|
2020-03-31 19:20:15 +02:00
|
|
|
public Single<KioskInfo> loadResult(final boolean forceReload) {
|
2019-10-20 17:31:46 +02:00
|
|
|
contentCountry = Localization.getPreferredContentCountry(requireContext());
|
2020-03-31 19:20:15 +02:00
|
|
|
return ExtractorHelper.getKioskInfo(serviceId, url, forceReload);
|
2017-09-23 17:39:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-03-18 16:37:49 +01:00
|
|
|
public Single<ListExtractor.InfoItemsPage> loadMoreItemsLogic() {
|
2020-04-15 15:31:53 +02:00
|
|
|
return ExtractorHelper.getMoreKioskItems(serviceId, url, currentNextPage);
|
2017-09-23 17:39:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Contract
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void handleResult(@NonNull final KioskInfo result) {
|
|
|
|
super.handleResult(result);
|
|
|
|
|
2018-01-30 08:01:57 +01:00
|
|
|
name = kioskTranslatedName;
|
2019-03-10 22:38:30 +01:00
|
|
|
setTitle(kioskTranslatedName);
|
2017-09-23 17:39:04 +02:00
|
|
|
}
|
|
|
|
}
|