mirror of
https://github.com/TeamNewPipe/NewPipe.git
synced 2024-11-22 02:53:09 +01:00
fix: cache channel data
This commit is contained in:
parent
16cd47fa2e
commit
2c98d079de
@ -35,9 +35,11 @@ import org.schabi.newpipe.util.ChannelTabs;
|
||||
import org.schabi.newpipe.util.Constants;
|
||||
import org.schabi.newpipe.util.ExtractorHelper;
|
||||
import org.schabi.newpipe.util.NavigationHelper;
|
||||
import org.schabi.newpipe.util.StateSaver;
|
||||
import org.schabi.newpipe.util.external_communication.ShareUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
|
||||
import icepick.State;
|
||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
||||
@ -47,7 +49,8 @@ import io.reactivex.rxjava3.disposables.Disposable;
|
||||
import io.reactivex.rxjava3.functions.Consumer;
|
||||
import io.reactivex.rxjava3.schedulers.Schedulers;
|
||||
|
||||
public class ChannelFragment extends BaseStateFragment<ChannelInfo> {
|
||||
public class ChannelFragment extends BaseStateFragment<ChannelInfo>
|
||||
implements StateSaver.WriteRead {
|
||||
@State
|
||||
protected int serviceId = Constants.NO_SERVICE_ID;
|
||||
@State
|
||||
@ -97,12 +100,6 @@ public class ChannelFragment extends BaseStateFragment<ChannelInfo> {
|
||||
public void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
lastTab = savedInstanceState.getInt("LastTab");
|
||||
} else {
|
||||
lastTab = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -128,12 +125,6 @@ public class ChannelFragment extends BaseStateFragment<ChannelInfo> {
|
||||
binding.tabLayout.setupWithViewPager(binding.viewPager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(final @NonNull Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putInt("LastTab", binding.tabLayout.getSelectedTabPosition());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
@ -301,7 +292,7 @@ public class ChannelFragment extends BaseStateFragment<ChannelInfo> {
|
||||
final String description = currentInfo.getDescription();
|
||||
if (description != null && !description.isEmpty()
|
||||
&& ChannelTabs.showChannelTab(
|
||||
context, preferences, R.string.show_channel_tabs_info)) {
|
||||
context, preferences, R.string.show_channel_tabs_info)) {
|
||||
tabAdapter.addFragment(
|
||||
ChannelInfoFragment.getInstance(currentInfo), "Info");
|
||||
}
|
||||
@ -321,6 +312,40 @@ public class ChannelFragment extends BaseStateFragment<ChannelInfo> {
|
||||
}
|
||||
}
|
||||
|
||||
/*//////////////////////////////////////////////////////////////////////////
|
||||
// State Saving
|
||||
//////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
@Override
|
||||
public String generateSuffix() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(final Queue<Object> objectsToSave) {
|
||||
objectsToSave.add(currentInfo);
|
||||
if (binding != null) {
|
||||
objectsToSave.add(binding.tabLayout.getSelectedTabPosition());
|
||||
} else {
|
||||
objectsToSave.add(0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFrom(@NonNull final Queue<Object> savedObjects) {
|
||||
currentInfo = (ChannelInfo) savedObjects.poll();
|
||||
lastTab = (Integer) savedObjects.poll();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doInitialLoadLogic() {
|
||||
if (currentInfo == null) {
|
||||
startLoading(false);
|
||||
} else {
|
||||
handleResult(currentInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startLoading(final boolean forceLoad) {
|
||||
super.startLoading(forceLoad);
|
||||
|
@ -158,7 +158,8 @@ public final class ExtractorHelper {
|
||||
final boolean forceLoad) {
|
||||
checkServiceId(serviceId);
|
||||
return checkCache(forceLoad, serviceId,
|
||||
tabHandler.getUrl() + tabHandler.getTab().name(), InfoItem.InfoType.CHANNEL,
|
||||
tabHandler.getUrl() + "/"
|
||||
+ tabHandler.getTab().name(), InfoItem.InfoType.CHANNEL,
|
||||
Single.fromCallable(() ->
|
||||
ChannelTabInfo.getInfo(NewPipe.getService(serviceId), tabHandler)));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user