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:
|
||||||
// default to the queue
|
// default to the queue
|
||||||
fragment = new QueueFragment();
|
fragment = new QueueFragment();
|
||||||
|
tag = QueueFragment.TAG;
|
||||||
args = null;
|
args = null;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -183,6 +184,7 @@ public class MainActivity extends CastEnabledActivity {
|
||||||
if (args != null) {
|
if (args != null) {
|
||||||
fragment.setArguments(args);
|
fragment.setArguments(args);
|
||||||
}
|
}
|
||||||
|
NavDrawerFragment.saveLastNavFragment(this, tag);
|
||||||
loadFragment(fragment);
|
loadFragment(fragment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,6 +193,7 @@ public class MainActivity extends CastEnabledActivity {
|
||||||
if (args != null) {
|
if (args != null) {
|
||||||
fragment.setArguments(args);
|
fragment.setArguments(args);
|
||||||
}
|
}
|
||||||
|
NavDrawerFragment.saveLastNavFragment(this, String.valueOf(feedId));
|
||||||
loadFragment(fragment);
|
loadFragment(fragment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,7 +370,6 @@ public class MainActivity extends CastEnabledActivity {
|
||||||
super.onBackPressed();
|
super.onBackPressed();
|
||||||
} else {
|
} else {
|
||||||
loadFragment(UserPreferences.getBackButtonGoToPage(), null);
|
loadFragment(UserPreferences.getBackButtonGoToPage(), null);
|
||||||
NavDrawerFragment.saveLastNavFragment(this, UserPreferences.getBackButtonGoToPage());
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default: super.onBackPressed();
|
default: super.onBackPressed();
|
||||||
|
|
|
@ -48,7 +48,7 @@ import org.greenrobot.eventbus.Subscribe;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class NavDrawerFragment extends Fragment implements AdapterView.OnItemClickListener,
|
public class NavDrawerFragment extends Fragment implements AdapterView.OnItemClickListener,
|
||||||
AdapterView.OnItemLongClickListener {
|
AdapterView.OnItemLongClickListener, SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public static final String PREF_LAST_FRAGMENT_TAG = "prefLastFragmentTag";
|
public static final String PREF_LAST_FRAGMENT_TAG = "prefLastFragmentTag";
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
|
@ -88,6 +88,8 @@ public class NavDrawerFragment extends Fragment implements AdapterView.OnItemCli
|
||||||
root.findViewById(R.id.nav_settings).setOnClickListener(v -> {
|
root.findViewById(R.id.nav_settings).setOnClickListener(v -> {
|
||||||
startActivity(new Intent(getActivity(), PreferenceActivity.class));
|
startActivity(new Intent(getActivity(), PreferenceActivity.class));
|
||||||
});
|
});
|
||||||
|
getContext().getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE)
|
||||||
|
.registerOnSharedPreferenceChangeListener(this);
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,6 +126,8 @@ public class NavDrawerFragment extends Fragment implements AdapterView.OnItemCli
|
||||||
if (disposable != null) {
|
if (disposable != null) {
|
||||||
disposable.dispose();
|
disposable.dispose();
|
||||||
}
|
}
|
||||||
|
getContext().getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE)
|
||||||
|
.unregisterOnSharedPreferenceChangeListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -192,7 +196,6 @@ public class NavDrawerFragment extends Fragment implements AdapterView.OnItemCli
|
||||||
} else {
|
} else {
|
||||||
showMainActivity(EpisodesFragment.TAG);
|
showMainActivity(EpisodesFragment.TAG);
|
||||||
}
|
}
|
||||||
saveLastNavFragment(getContext(), EpisodesFragment.TAG);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -371,7 +374,6 @@ public class NavDrawerFragment extends Fragment implements AdapterView.OnItemCli
|
||||||
} else {
|
} else {
|
||||||
showMainActivity(tag);
|
showMainActivity(tag);
|
||||||
}
|
}
|
||||||
saveLastNavFragment(getContext(), tag);
|
|
||||||
} else {
|
} else {
|
||||||
int pos = position - navAdapter.getSubscriptionOffset();
|
int pos = position - navAdapter.getSubscriptionOffset();
|
||||||
long feedId = navDrawerData.feeds.get(pos).getId();
|
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);
|
intent.putExtra(MainActivity.EXTRA_FEED_ID, feedId);
|
||||||
startActivity(intent);
|
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);
|
Log.d(TAG, "getLastNavFragment() -> " + lastFragment);
|
||||||
return 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