mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-22 14:47:29 +00:00
Handle bottom nav and settings when logged out
This commit is contained in:
parent
8b502561c2
commit
6b221c463b
@ -89,6 +89,7 @@ public class MainActivity extends BaseLanguageActivity {
|
||||
private boolean showSearch = true;
|
||||
private Handler suggestionsFetchHandler;
|
||||
private int firstFragmentGraphIndex;
|
||||
private boolean isLoggedIn;
|
||||
|
||||
static {
|
||||
NAV_TO_MENU_ID_MAP.put(R.navigation.direct_messages_nav_graph, R.id.direct_messages_nav_graph);
|
||||
@ -107,6 +108,7 @@ public class MainActivity extends BaseLanguageActivity {
|
||||
setContentView(binding.getRoot());
|
||||
final Toolbar toolbar = binding.toolbar;
|
||||
setSupportActionBar(toolbar);
|
||||
isLoggedIn = !Utils.isEmpty(cookie) && Utils.getUserIdFromCookie(cookie) != null;
|
||||
if (savedInstanceState == null) {
|
||||
setupBottomNavigationBar(true);
|
||||
}
|
||||
@ -312,7 +314,13 @@ public class MainActivity extends BaseLanguageActivity {
|
||||
}
|
||||
|
||||
private void setupBottomNavigationBar(final boolean setDefaultFromSettings) {
|
||||
final TypedArray navIds = getResources().obtainTypedArray(R.array.main_nav_ids);
|
||||
int main_nav_ids = R.array.main_nav_ids;
|
||||
if (!isLoggedIn) {
|
||||
main_nav_ids = R.array.logged_out_main_nav_ids;
|
||||
binding.bottomNavView.getMenu().clear();
|
||||
binding.bottomNavView.inflateMenu(R.menu.logged_out_bottom_navigation_menu);
|
||||
}
|
||||
final TypedArray navIds = getResources().obtainTypedArray(main_nav_ids);
|
||||
final List<Integer> mainNavList = new ArrayList<>(navIds.length());
|
||||
final int length = navIds.length();
|
||||
for (int i = 0; i < length; i++) {
|
||||
@ -324,7 +332,9 @@ public class MainActivity extends BaseLanguageActivity {
|
||||
if (setDefaultFromSettings) {
|
||||
final String defaultTabIdString = settingsHelper.getString(Constants.DEFAULT_TAB);
|
||||
try {
|
||||
final int defaultNavId = Utils.isEmpty(defaultTabIdString) ? R.navigation.profile_nav_graph : Integer.parseInt(defaultTabIdString);
|
||||
final int defaultNavId = Utils.isEmpty(defaultTabIdString) || !isLoggedIn
|
||||
? R.navigation.profile_nav_graph
|
||||
: Integer.parseInt(defaultTabIdString);
|
||||
final int index = mainNavList.indexOf(defaultNavId);
|
||||
if (index >= 0) {
|
||||
firstFragmentGraphIndex = index;
|
||||
|
@ -35,11 +35,14 @@ import static awais.instagrabber.utils.Utils.settingsHelper;
|
||||
public class SettingsPreferencesFragment extends BasePreferencesFragment {
|
||||
private static final String TAG = "SettingsPrefsFrag";
|
||||
private static AppCompatTextView customPathTextView;
|
||||
private boolean isLoggedIn;
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setHasOptionsMenu(true);
|
||||
final String cookie = settingsHelper.getString(Constants.COOKIE);
|
||||
isLoggedIn = !Utils.isEmpty(cookie) && Utils.getUserIdFromCookie(cookie) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -75,12 +78,14 @@ public class SettingsPreferencesFragment extends BasePreferencesFragment {
|
||||
localeCategory.addPreference(getLanguagePreference());
|
||||
localeCategory.addPreference(getPostTimePreference());
|
||||
|
||||
if (isLoggedIn) {
|
||||
final PreferenceCategory loggedInUsersPreferenceCategory = new PreferenceCategory(requireContext());
|
||||
screen.addPreference(loggedInUsersPreferenceCategory);
|
||||
loggedInUsersPreferenceCategory.setIconSpaceReserved(false);
|
||||
loggedInUsersPreferenceCategory.setTitle(R.string.login_settings);
|
||||
loggedInUsersPreferenceCategory.addPreference(getMarkStoriesSeenPreference());
|
||||
loggedInUsersPreferenceCategory.addPreference(getEnableActivityNotificationsPreference());
|
||||
}
|
||||
|
||||
final PreferenceCategory anonUsersPreferenceCategory = new PreferenceCategory(requireContext());
|
||||
screen.addPreference(anonUsersPreferenceCategory);
|
||||
@ -115,6 +120,7 @@ public class SettingsPreferencesFragment extends BasePreferencesFragment {
|
||||
|
||||
private Preference getDefaultTabPreference() {
|
||||
final ListPreference preference = new ListPreference(requireContext());
|
||||
preference.setEnabled(isLoggedIn);
|
||||
preference.setSummaryProvider(ListPreference.SimpleSummaryProvider.getInstance());
|
||||
final FragmentActivity activity = getActivity();
|
||||
if (activity == null) {
|
||||
|
17
app/src/main/res/menu/logged_out_bottom_navigation_menu.xml
Normal file
17
app/src/main/res/menu/logged_out_bottom_navigation_menu.xml
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:id="@+id/profile_nav_graph"
|
||||
android:icon="@drawable/ic_profile"
|
||||
android:title="@string/profile" />
|
||||
|
||||
<item
|
||||
android:id="@+id/discover_nav_graph"
|
||||
android:icon="@drawable/ic_discover"
|
||||
android:title="@string/title_discover" />
|
||||
|
||||
<item
|
||||
android:id="@+id/more_nav_graph"
|
||||
android:icon="@drawable/ic_more_horiz_24"
|
||||
android:title="@string/more" />
|
||||
</menu>
|
@ -107,4 +107,9 @@
|
||||
<item>@string/title_discover</item>
|
||||
<item>@string/more</item>
|
||||
</string-array>
|
||||
<array name="logged_out_main_nav_ids">
|
||||
<item>@navigation/profile_nav_graph</item>
|
||||
<item>@navigation/discover_nav_graph</item>
|
||||
<item>@navigation/more_nav_graph</item>
|
||||
</array>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user