mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2025-04-27 21:23:15 +00: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.Constants;
|
||||||
import org.schabi.newpipe.util.ExtractorHelper;
|
import org.schabi.newpipe.util.ExtractorHelper;
|
||||||
import org.schabi.newpipe.util.NavigationHelper;
|
import org.schabi.newpipe.util.NavigationHelper;
|
||||||
|
import org.schabi.newpipe.util.StateSaver;
|
||||||
import org.schabi.newpipe.util.external_communication.ShareUtils;
|
import org.schabi.newpipe.util.external_communication.ShareUtils;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Queue;
|
||||||
|
|
||||||
import icepick.State;
|
import icepick.State;
|
||||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
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.functions.Consumer;
|
||||||
import io.reactivex.rxjava3.schedulers.Schedulers;
|
import io.reactivex.rxjava3.schedulers.Schedulers;
|
||||||
|
|
||||||
public class ChannelFragment extends BaseStateFragment<ChannelInfo> {
|
public class ChannelFragment extends BaseStateFragment<ChannelInfo>
|
||||||
|
implements StateSaver.WriteRead {
|
||||||
@State
|
@State
|
||||||
protected int serviceId = Constants.NO_SERVICE_ID;
|
protected int serviceId = Constants.NO_SERVICE_ID;
|
||||||
@State
|
@State
|
||||||
@ -97,12 +100,6 @@ public class ChannelFragment extends BaseStateFragment<ChannelInfo> {
|
|||||||
public void onCreate(final Bundle savedInstanceState) {
|
public void onCreate(final Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setHasOptionsMenu(true);
|
setHasOptionsMenu(true);
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
|
||||||
lastTab = savedInstanceState.getInt("LastTab");
|
|
||||||
} else {
|
|
||||||
lastTab = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -128,12 +125,6 @@ public class ChannelFragment extends BaseStateFragment<ChannelInfo> {
|
|||||||
binding.tabLayout.setupWithViewPager(binding.viewPager);
|
binding.tabLayout.setupWithViewPager(binding.viewPager);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSaveInstanceState(final @NonNull Bundle outState) {
|
|
||||||
super.onSaveInstanceState(outState);
|
|
||||||
outState.putInt("LastTab", binding.tabLayout.getSelectedTabPosition());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
@ -301,7 +292,7 @@ public class ChannelFragment extends BaseStateFragment<ChannelInfo> {
|
|||||||
final String description = currentInfo.getDescription();
|
final String description = currentInfo.getDescription();
|
||||||
if (description != null && !description.isEmpty()
|
if (description != null && !description.isEmpty()
|
||||||
&& ChannelTabs.showChannelTab(
|
&& ChannelTabs.showChannelTab(
|
||||||
context, preferences, R.string.show_channel_tabs_info)) {
|
context, preferences, R.string.show_channel_tabs_info)) {
|
||||||
tabAdapter.addFragment(
|
tabAdapter.addFragment(
|
||||||
ChannelInfoFragment.getInstance(currentInfo), "Info");
|
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
|
@Override
|
||||||
public void startLoading(final boolean forceLoad) {
|
public void startLoading(final boolean forceLoad) {
|
||||||
super.startLoading(forceLoad);
|
super.startLoading(forceLoad);
|
||||||
|
@ -158,7 +158,8 @@ public final class ExtractorHelper {
|
|||||||
final boolean forceLoad) {
|
final boolean forceLoad) {
|
||||||
checkServiceId(serviceId);
|
checkServiceId(serviceId);
|
||||||
return checkCache(forceLoad, serviceId,
|
return checkCache(forceLoad, serviceId,
|
||||||
tabHandler.getUrl() + tabHandler.getTab().name(), InfoItem.InfoType.CHANNEL,
|
tabHandler.getUrl() + "/"
|
||||||
|
+ tabHandler.getTab().name(), InfoItem.InfoType.CHANNEL,
|
||||||
Single.fromCallable(() ->
|
Single.fromCallable(() ->
|
||||||
ChannelTabInfo.getInfo(NewPipe.getService(serviceId), tabHandler)));
|
ChannelTabInfo.getInfo(NewPipe.getService(serviceId), tabHandler)));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user