Fixed back button no longer closing app

This commit is contained in:
ByteHamster 2020-03-20 14:17:53 +01:00
parent c2734ecb7e
commit 096fb0d427
3 changed files with 8 additions and 5 deletions

View File

@ -101,6 +101,8 @@ public class MainActivityTest {
solo.goBack();
solo.goBack();
assertEquals(solo.getString(R.string.subscriptions_label), getActionbarTitle());
solo.goBack();
assertThat(mActivityRule.getActivityResult(), hasResultCode(Activity.RESULT_CANCELED));
}
@Test

View File

@ -367,6 +367,7 @@ public class MainActivity extends CastEnabledActivity {
super.onBackPressed();
} else {
loadFragment(UserPreferences.getBackButtonGoToPage(), null);
NavDrawerFragment.saveLastNavFragment(this, UserPreferences.getBackButtonGoToPage());
}
break;
default: super.onBackPressed();

View File

@ -192,7 +192,7 @@ public class NavDrawerFragment extends Fragment implements AdapterView.OnItemCli
} else {
showMainActivity(EpisodesFragment.TAG);
}
saveLastNavFragment(EpisodesFragment.TAG);
saveLastNavFragment(getContext(), EpisodesFragment.TAG);
}
}
};
@ -371,7 +371,7 @@ public class NavDrawerFragment extends Fragment implements AdapterView.OnItemCli
} else {
showMainActivity(tag);
}
saveLastNavFragment(tag);
saveLastNavFragment(getContext(), tag);
} else {
int pos = position - navAdapter.getSubscriptionOffset();
long feedId = navDrawerData.feeds.get(pos).getId();
@ -382,7 +382,7 @@ public class NavDrawerFragment extends Fragment implements AdapterView.OnItemCli
intent.putExtra(MainActivity.EXTRA_FEED_ID, feedId);
startActivity(intent);
}
saveLastNavFragment(String.valueOf(feedId));
saveLastNavFragment(getContext(), String.valueOf(feedId));
}
selectedNavListIndex = position;
navAdapter.notifyDataSetChanged();
@ -400,9 +400,9 @@ public class NavDrawerFragment extends Fragment implements AdapterView.OnItemCli
}
}
private void saveLastNavFragment(String tag) {
public static void saveLastNavFragment(Context context, String tag) {
Log.d(TAG, "saveLastNavFragment(tag: " + tag + ")");
SharedPreferences prefs = getContext().getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
SharedPreferences prefs = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
SharedPreferences.Editor edit = prefs.edit();
if (tag != null) {
edit.putString(PREF_LAST_FRAGMENT_TAG, tag);