mirror of
https://github.com/TeamNewPipe/NewPipe.git
synced 2024-11-25 12:32:31 +01:00
fix: remember selected channel tab on screen rotation
This commit is contained in:
parent
bb062f07f9
commit
c929f00456
@ -16,6 +16,8 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import com.google.android.material.tabs.TabLayout;
|
||||
|
||||
import org.schabi.newpipe.R;
|
||||
import org.schabi.newpipe.database.subscription.NotificationMode;
|
||||
import org.schabi.newpipe.database.subscription.SubscriptionEntity;
|
||||
@ -58,6 +60,7 @@ public class ChannelFragment extends BaseStateFragment<ChannelInfo> {
|
||||
private Disposable subscriptionMonitor;
|
||||
private final CompositeDisposable disposables = new CompositeDisposable();
|
||||
private SubscriptionManager subscriptionManager;
|
||||
private int lastTab;
|
||||
|
||||
private MenuItem menuRssButton;
|
||||
private MenuItem menuNotifyButton;
|
||||
@ -94,10 +97,16 @@ 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
|
||||
public void onAttach(@NonNull Context context) {
|
||||
public void onAttach(final @NonNull Context context) {
|
||||
super.onAttach(context);
|
||||
subscriptionManager = new SubscriptionManager(activity);
|
||||
}
|
||||
@ -119,6 +128,12 @@ 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();
|
||||
@ -284,8 +299,8 @@ public class ChannelFragment extends BaseStateFragment<ChannelInfo> {
|
||||
}
|
||||
|
||||
final String description = currentInfo.getDescription();
|
||||
if (description != null && !description.isEmpty() &&
|
||||
ChannelTabs.showChannelTab(
|
||||
if (description != null && !description.isEmpty()
|
||||
&& ChannelTabs.showChannelTab(
|
||||
context, preferences, R.string.show_channel_tabs_info)) {
|
||||
tabAdapter.addFragment(
|
||||
ChannelInfoFragment.getInstance(currentInfo), "Info");
|
||||
@ -298,6 +313,12 @@ public class ChannelFragment extends BaseStateFragment<ChannelInfo> {
|
||||
for (int i = 0; i < tabAdapter.getCount(); i++) {
|
||||
binding.tabLayout.getTabAt(i).setText(tabAdapter.getItemTitle(i));
|
||||
}
|
||||
|
||||
// Restore previously selected tab
|
||||
final TabLayout.Tab ltab = binding.tabLayout.getTabAt(lastTab);
|
||||
if (ltab != null) {
|
||||
binding.tabLayout.selectTab(ltab);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -79,7 +79,7 @@ public class ChannelInfoFragment extends BaseFragment {
|
||||
|
||||
private void setupMetadata(final LayoutInflater inflater,
|
||||
final LinearLayout layout) {
|
||||
Context context = getContext();
|
||||
final Context context = getContext();
|
||||
|
||||
if (channelInfo.getSubscriberCount() != UNKNOWN_SUBSCRIBER_COUNT) {
|
||||
addMetadataItem(inflater, layout, R.string.metadata_subscribers,
|
||||
|
@ -46,7 +46,7 @@ public class ChannelTabFragment extends BaseListInfoFragment<InfoItem, ChannelTa
|
||||
//////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
public void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setHasOptionsMenu(false);
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ public class ChannelVideosFragment extends BaseListInfoFragment<StreamInfoItem,
|
||||
//////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
public void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setHasOptionsMenu(false);
|
||||
}
|
||||
|
@ -10,7 +10,10 @@ import org.schabi.newpipe.extractor.linkhandler.ChannelTabHandler.Tab;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class ChannelTabs {
|
||||
public final class ChannelTabs {
|
||||
private ChannelTabs() {
|
||||
}
|
||||
|
||||
@StringRes
|
||||
private static int getShowTabKey(final Tab tab) {
|
||||
switch (tab) {
|
||||
|
Loading…
Reference in New Issue
Block a user