mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-24 09:00:31 +00:00
save selected tab sate in stream detail fragment, fixes #2238
This commit is contained in:
parent
e98f68e93b
commit
657125f43c
@ -1,5 +1,6 @@
|
|||||||
package org.schabi.newpipe.fragments.detail;
|
package org.schabi.newpipe.fragments.detail;
|
||||||
|
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v4.app.FragmentPagerAdapter;
|
import android.support.v4.app.FragmentPagerAdapter;
|
||||||
@ -61,6 +62,18 @@ public class TabAdaptor extends FragmentPagerAdapter {
|
|||||||
else return POSITION_NONE;
|
else return POSITION_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getItemPositionByTitle(String title) {
|
||||||
|
return mFragmentTitleList.indexOf(title);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public String getItemTitle(int position) {
|
||||||
|
if (position < 0 || position >= mFragmentTitleList.size()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return mFragmentTitleList.get(position);
|
||||||
|
}
|
||||||
|
|
||||||
public void notifyDataSetUpdate(){
|
public void notifyDataSetUpdate(){
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
@ -122,6 +122,7 @@ public class VideoDetailFragment
|
|||||||
private boolean autoPlayEnabled;
|
private boolean autoPlayEnabled;
|
||||||
private boolean showRelatedStreams;
|
private boolean showRelatedStreams;
|
||||||
private boolean showComments;
|
private boolean showComments;
|
||||||
|
private String selectedTabTag;
|
||||||
|
|
||||||
@State
|
@State
|
||||||
protected int serviceId = Constants.NO_SERVICE_ID;
|
protected int serviceId = Constants.NO_SERVICE_ID;
|
||||||
@ -213,6 +214,9 @@ public class VideoDetailFragment
|
|||||||
showComments = PreferenceManager.getDefaultSharedPreferences(activity)
|
showComments = PreferenceManager.getDefaultSharedPreferences(activity)
|
||||||
.getBoolean(getString(R.string.show_comments_key), true);
|
.getBoolean(getString(R.string.show_comments_key), true);
|
||||||
|
|
||||||
|
selectedTabTag = PreferenceManager.getDefaultSharedPreferences(activity)
|
||||||
|
.getString(getString(R.string.stream_info_selected_tab_key), COMMENTS_TAB_TAG);
|
||||||
|
|
||||||
PreferenceManager.getDefaultSharedPreferences(activity)
|
PreferenceManager.getDefaultSharedPreferences(activity)
|
||||||
.registerOnSharedPreferenceChangeListener(this);
|
.registerOnSharedPreferenceChangeListener(this);
|
||||||
}
|
}
|
||||||
@ -226,6 +230,10 @@ public class VideoDetailFragment
|
|||||||
public void onPause() {
|
public void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
if (currentWorker != null) currentWorker.dispose();
|
if (currentWorker != null) currentWorker.dispose();
|
||||||
|
PreferenceManager.getDefaultSharedPreferences(getContext())
|
||||||
|
.edit()
|
||||||
|
.putString(getString(R.string.stream_info_selected_tab_key), pageAdapter.getItemTitle(viewPager.getCurrentItem()))
|
||||||
|
.apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -815,6 +823,9 @@ public class VideoDetailFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initTabs() {
|
private void initTabs() {
|
||||||
|
if (pageAdapter.getCount() != 0) {
|
||||||
|
selectedTabTag = pageAdapter.getItemTitle(viewPager.getCurrentItem());
|
||||||
|
}
|
||||||
pageAdapter.clearAllItems();
|
pageAdapter.clearAllItems();
|
||||||
|
|
||||||
if(shouldShowComments()){
|
if(shouldShowComments()){
|
||||||
@ -835,6 +846,8 @@ public class VideoDetailFragment
|
|||||||
if(pageAdapter.getCount() < 2){
|
if(pageAdapter.getCount() < 2){
|
||||||
tabLayout.setVisibility(View.GONE);
|
tabLayout.setVisibility(View.GONE);
|
||||||
}else{
|
}else{
|
||||||
|
int position = pageAdapter.getItemPositionByTitle(selectedTabTag);
|
||||||
|
if(position != -1) viewPager.setCurrentItem(position);
|
||||||
tabLayout.setVisibility(View.VISIBLE);
|
tabLayout.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -139,6 +139,7 @@
|
|||||||
<string name="show_play_with_kodi_key" translatable="false">show_play_with_kodi</string>
|
<string name="show_play_with_kodi_key" translatable="false">show_play_with_kodi</string>
|
||||||
<string name="show_next_video_key" translatable="false">show_next_video</string>
|
<string name="show_next_video_key" translatable="false">show_next_video</string>
|
||||||
<string name="show_comments_key" translatable="false">show_comments</string>
|
<string name="show_comments_key" translatable="false">show_comments</string>
|
||||||
|
<string name="stream_info_selected_tab_key" translatable="false">stream_info_selected_tab</string>
|
||||||
<string name="show_hold_to_append_key" translatable="false">show_hold_to_append</string>
|
<string name="show_hold_to_append_key" translatable="false">show_hold_to_append</string>
|
||||||
<string name="default_language_value">en</string>
|
<string name="default_language_value">en</string>
|
||||||
<string name="default_country_value">GB</string>
|
<string name="default_country_value">GB</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user