Merge pull request #3958 from ByteHamster/fix-sidebar-position
Fixed sidebar sometimes highlighting wrong fragment
This commit is contained in:
commit
3bb222089e
|
@ -176,6 +176,7 @@ public class MainActivity extends CastEnabledActivity {
|
|||
default:
|
||||
// default to the queue
|
||||
fragment = new QueueFragment();
|
||||
tag = QueueFragment.TAG;
|
||||
args = null;
|
||||
break;
|
||||
}
|
||||
|
@ -183,6 +184,7 @@ public class MainActivity extends CastEnabledActivity {
|
|||
if (args != null) {
|
||||
fragment.setArguments(args);
|
||||
}
|
||||
NavDrawerFragment.saveLastNavFragment(this, tag);
|
||||
loadFragment(fragment);
|
||||
}
|
||||
|
||||
|
@ -191,6 +193,7 @@ public class MainActivity extends CastEnabledActivity {
|
|||
if (args != null) {
|
||||
fragment.setArguments(args);
|
||||
}
|
||||
NavDrawerFragment.saveLastNavFragment(this, String.valueOf(feedId));
|
||||
loadFragment(fragment);
|
||||
}
|
||||
|
||||
|
@ -367,7 +370,6 @@ public class MainActivity extends CastEnabledActivity {
|
|||
super.onBackPressed();
|
||||
} else {
|
||||
loadFragment(UserPreferences.getBackButtonGoToPage(), null);
|
||||
NavDrawerFragment.saveLastNavFragment(this, UserPreferences.getBackButtonGoToPage());
|
||||
}
|
||||
break;
|
||||
default: super.onBackPressed();
|
||||
|
|
|
@ -48,7 +48,7 @@ import org.greenrobot.eventbus.Subscribe;
|
|||
import java.util.List;
|
||||
|
||||
public class NavDrawerFragment extends Fragment implements AdapterView.OnItemClickListener,
|
||||
AdapterView.OnItemLongClickListener {
|
||||
AdapterView.OnItemLongClickListener, SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
@VisibleForTesting
|
||||
public static final String PREF_LAST_FRAGMENT_TAG = "prefLastFragmentTag";
|
||||
@VisibleForTesting
|
||||
|
@ -88,6 +88,8 @@ public class NavDrawerFragment extends Fragment implements AdapterView.OnItemCli
|
|||
root.findViewById(R.id.nav_settings).setOnClickListener(v -> {
|
||||
startActivity(new Intent(getActivity(), PreferenceActivity.class));
|
||||
});
|
||||
getContext().getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE)
|
||||
.registerOnSharedPreferenceChangeListener(this);
|
||||
return root;
|
||||
}
|
||||
|
||||
|
@ -124,6 +126,8 @@ public class NavDrawerFragment extends Fragment implements AdapterView.OnItemCli
|
|||
if (disposable != null) {
|
||||
disposable.dispose();
|
||||
}
|
||||
getContext().getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE)
|
||||
.unregisterOnSharedPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -192,7 +196,6 @@ public class NavDrawerFragment extends Fragment implements AdapterView.OnItemCli
|
|||
} else {
|
||||
showMainActivity(EpisodesFragment.TAG);
|
||||
}
|
||||
saveLastNavFragment(getContext(), EpisodesFragment.TAG);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -371,7 +374,6 @@ public class NavDrawerFragment extends Fragment implements AdapterView.OnItemCli
|
|||
} else {
|
||||
showMainActivity(tag);
|
||||
}
|
||||
saveLastNavFragment(getContext(), tag);
|
||||
} else {
|
||||
int pos = position - navAdapter.getSubscriptionOffset();
|
||||
long feedId = navDrawerData.feeds.get(pos).getId();
|
||||
|
@ -382,10 +384,7 @@ public class NavDrawerFragment extends Fragment implements AdapterView.OnItemCli
|
|||
intent.putExtra(MainActivity.EXTRA_FEED_ID, feedId);
|
||||
startActivity(intent);
|
||||
}
|
||||
saveLastNavFragment(getContext(), String.valueOf(feedId));
|
||||
}
|
||||
selectedNavListIndex = position;
|
||||
navAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -418,4 +417,12 @@ public class NavDrawerFragment extends Fragment implements AdapterView.OnItemCli
|
|||
Log.d(TAG, "getLastNavFragment() -> " + lastFragment);
|
||||
return lastFragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
if (PREF_LAST_FRAGMENT_TAG.equals(key)) {
|
||||
updateSelection();
|
||||
navAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue