package org.schabi.newpipe.fragments.list.kiosk; import android.os.Bundle; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; import android.view.View; import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.ActionBar; import org.schabi.newpipe.R; import org.schabi.newpipe.error.ErrorInfo; import org.schabi.newpipe.error.UserAction; 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; import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory; import org.schabi.newpipe.extractor.localization.ContentCountry; import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.fragments.list.BaseListInfoFragment; import org.schabi.newpipe.util.ExtractorHelper; import org.schabi.newpipe.util.KioskTranslator; import org.schabi.newpipe.util.Localization; import icepick.State; import io.reactivex.rxjava3.core.Single; /** * 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 NewPipe. If not, see . *

*/ public class KioskFragment extends BaseListInfoFragment { @State String kioskId = ""; String kioskTranslatedName; @State ContentCountry contentCountry; /*////////////////////////////////////////////////////////////////////////// // Views //////////////////////////////////////////////////////////////////////////*/ public static KioskFragment getInstance(final int serviceId) throws ExtractionException { return getInstance(serviceId, NewPipe.getService(serviceId) .getKioskList().getDefaultKioskId()); } public static KioskFragment getInstance(final int serviceId, final String kioskId) throws ExtractionException { final KioskFragment instance = new KioskFragment(); final StreamingService service = NewPipe.getService(serviceId); final ListLinkHandlerFactory kioskLinkHandlerFactory = service.getKioskList() .getListLinkHandlerFactoryByType(kioskId); instance.setInitialData(serviceId, kioskLinkHandlerFactory.fromId(kioskId).getUrl(), kioskId); instance.kioskId = kioskId; return instance; } public KioskFragment() { super(UserAction.REQUESTED_KIOSK); } /*////////////////////////////////////////////////////////////////////////// // LifeCycle //////////////////////////////////////////////////////////////////////////*/ @Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); kioskTranslatedName = KioskTranslator.getTranslatedKioskName(kioskId, activity); name = kioskTranslatedName; contentCountry = Localization.getPreferredContentCountry(requireContext()); } @Override public void onResume() { super.onResume(); if (!Localization.getPreferredContentCountry(requireContext()).equals(contentCountry)) { reloadContent(); } if (useAsFrontPage && activity != null) { try { setTitle(kioskTranslatedName); } catch (final Exception e) { showSnackBarError(new ErrorInfo(e, UserAction.UI_ERROR, "Setting kiosk title")); } } } @Override public View onCreateView(@NonNull final LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable final Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_kiosk, container, false); } /*////////////////////////////////////////////////////////////////////////// // Menu //////////////////////////////////////////////////////////////////////////*/ @Override public void onCreateOptionsMenu(@NonNull final Menu menu, @NonNull final MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); final ActionBar supportActionBar = activity.getSupportActionBar(); if (supportActionBar != null && useAsFrontPage) { supportActionBar.setDisplayHomeAsUpEnabled(false); } } /*////////////////////////////////////////////////////////////////////////// // Load and handle //////////////////////////////////////////////////////////////////////////*/ @Override public Single loadResult(final boolean forceReload) { contentCountry = Localization.getPreferredContentCountry(requireContext()); return ExtractorHelper.getKioskInfo(serviceId, url, forceReload); } @Override public Single> loadMoreItemsLogic() { return ExtractorHelper.getMoreKioskItems(serviceId, url, currentNextPage); } /*////////////////////////////////////////////////////////////////////////// // Contract //////////////////////////////////////////////////////////////////////////*/ @Override public void handleResult(@NonNull final KioskInfo result) { super.handleResult(result); name = kioskTranslatedName; setTitle(kioskTranslatedName); } }