hook up logic for bottom nav

TODO: separate online and local modules into their own tabs

Signed-off-by: androidacy-user <opensource@androidacy.com>
pull/27/head
androidacy-user 2 years ago
parent fcb26c213c
commit a8e71e1bed

@ -95,7 +95,6 @@
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

@ -47,8 +47,8 @@ import com.fox2code.mmm.repo.RepoManager;
import com.fox2code.mmm.settings.SettingsActivity;
import com.fox2code.mmm.utils.BlurUtils;
import com.fox2code.mmm.utils.ExternalHelper;
import com.fox2code.mmm.utils.IntentHelper;
import com.fox2code.mmm.utils.io.Http;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.progressindicator.LinearProgressIndicator;
@ -76,6 +76,7 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
private BlurView actionBarBlur;
private ColorDrawable actionBarBackground;
private RecyclerView moduleList;
private RecyclerView moduleListOnline;
private CardView searchCard;
private SearchView searchView;
private boolean initMode;
@ -93,6 +94,7 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
super.onResume();
}
@SuppressLint("RestrictedApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
this.initMode = true;
@ -124,13 +126,19 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
// Show a toast to warn the user
Toast.makeText(this, R.string.not_official_build, Toast.LENGTH_LONG).show();
}
if (!MainApplication.getSharedPreferences().getBoolean("first_time_setup_done", true)) {
this.setActionBarExtraMenuButton(R.drawable.ic_baseline_settings_24, v -> {
IntentHelper.startActivity(this, SettingsActivity.class);
return true;
}, R.string.pref_category_settings);
}
setContentView(R.layout.activity_main);
// on the bottom nav, there's a settings item. open the settings activity when it's clicked.
BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_navigation);
bottomNavigationView.setOnItemSelectedListener(item -> {
if (item.getItemId() == R.id.settings_menu_item) {
startActivity(new Intent(MainActivity.this, SettingsActivity.class));
}
return true;
});
// set the selected item to the installed tab
bottomNavigationView.setSelectedItemId(R.id.installed_menu_item);
// set the bottom padding of the main layout to the height of the bottom nav
findViewById(R.id.root_container).setPadding(0, 0, 0, bottomNavigationView.getHeight());
this.setTitle(R.string.app_name);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, 0);
setActionBarBackground(null);
@ -149,6 +157,7 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
this.swipeRefreshLayoutOrigEndOffset = this.swipeRefreshLayout.getProgressViewEndOffset();
this.swipeRefreshBlocker = Long.MAX_VALUE;
this.moduleList = findViewById(R.id.module_list);
this.moduleListOnline = findViewById(R.id.module_list_online);
this.searchCard = findViewById(R.id.search_card);
this.searchView = findViewById(R.id.search_bar);
this.moduleViewAdapter = new ModuleViewAdapter();
@ -157,6 +166,7 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
this.moduleList.setItemViewCacheSize(4); // Default is 2
this.swipeRefreshLayout.setOnRefreshListener(this);
this.actionBarBlur.setBackground(this.actionBarBackground);
hideActionBar();
BlurUtils.setupBlur(this.actionBarBlur, this, R.id.blur_frame);
this.updateBlurState();
checkShowInitialSetup();

@ -22,6 +22,7 @@ import android.os.Looper;
import android.provider.Settings;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
@ -71,8 +72,10 @@ import com.fox2code.mmm.utils.realm.ReposList;
import com.fox2code.mmm.utils.sentry.SentryMain;
import com.fox2code.rosettax.LanguageActivity;
import com.fox2code.rosettax.LanguageSwitcher;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.internal.TextWatcherAdapter;
import com.google.android.material.navigation.NavigationBarView;
import com.google.android.material.snackbar.BaseTransientBottomBar;
import com.google.android.material.snackbar.Snackbar;
import com.google.android.material.textfield.MaterialAutoCompleteTextView;
@ -142,17 +145,42 @@ public class SettingsActivity extends FoxActivity implements LanguageActivity {
return devicePerformanceClass;
}
@SuppressLint("RestrictedApi")
private final NavigationBarView.OnItemSelectedListener onItemSelectedListener = item -> {
int itemId = item.getItemId();
if (itemId == R.id.installed_menu_item || itemId == R.id.online_menu_item) {
startActivity(new Intent(this, MainActivity.class));
return true;
} else //noinspection RedundantIfStatement
if (itemId == R.id.settings_menu_item) {
return true;
}
return false;
};
@SuppressLint("RestrictedApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
devModeStep = 0;
super.onCreate(savedInstanceState);
this.setDisplayHomeAsUpEnabled(true);
setContentView(R.layout.settings_activity);
setTitle(R.string.app_name);
setActionBarBackground(null);
hideActionBar();
BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_navigation);
bottomNavigationView.setOnItemSelectedListener(onItemSelectedListener);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction().replace(R.id.settings, new SettingsFragment()).commit();
SettingsFragment settingsFragment = new SettingsFragment();
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.settings, settingsFragment)
.commit();
}
// get height of bottomnavigationview and adjust padding of settings fragment
bottomNavigationView.post(() -> {
int bottomNavigationHeight = bottomNavigationView.getHeight();
View settingsFragment = findViewById(R.id.settings);
settingsFragment.setPadding(0, 0, 0, bottomNavigationHeight);
});
}
@Override
@ -171,6 +199,8 @@ public class SettingsActivity extends FoxActivity implements LanguageActivity {
}
public static class SettingsFragment extends PreferenceFragmentCompat implements FoxActivity.OnBackPressedCallback {
@SuppressLint("UnspecifiedImmutableFlag")
@Override
@SuppressWarnings("ConstantConditions")
@ -178,6 +208,10 @@ public class SettingsActivity extends FoxActivity implements LanguageActivity {
getPreferenceManager().setSharedPreferencesName("mmm");
setPreferencesFromResource(R.xml.root_preferences, rootKey);
applyMaterial3(getPreferenceScreen());
// add bottom navigation bar to the settings
BottomNavigationView bottomNavigationView = requireActivity().findViewById(R.id.bottom_navigation);
bottomNavigationView.setVisibility(View.VISIBLE);
bottomNavigationView.getMenu().findItem(R.id.settings_menu_item).setChecked(true);
findPreference("pref_manage_repos").setOnPreferenceClickListener(p -> {
devModeStep = 0;
openFragment(new RepoFragment(), R.string.manage_repos_pref);
@ -1156,7 +1190,9 @@ public class SettingsActivity extends FoxActivity implements LanguageActivity {
}
private void setRepoData(final RepoData repoData, String preferenceName) {
Timber.d("Setting preference " + preferenceName + " to " + repoData.toString());
if (repoData == null)
return;
Timber.d("Setting preference " + preferenceName + " to " + repoData);
ClipboardManager clipboard = (ClipboardManager) requireContext().getSystemService(Context.CLIPBOARD_SERVICE);
Preference preference = findPreference(preferenceName);
if (preference == null)

@ -29,9 +29,10 @@
app:edgeToEdge="true" />
<!-- online modules -->
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/online_list"
android:id="@+id/module_list_online"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
app:edgeToEdge="true" />
</FrameLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
@ -114,10 +115,9 @@
<!-- bottom md3 navigation bar -->
<!-- used for local and remote module list -->
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_nav"
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:background="?attr/backgroundColor"
android:visibility="visible"
app:compatShadowEnabled="true"

@ -1,9 +1,29 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:id="@+id/settings"
android:layout_width="0dp"
android:layout_height="match_parent"
android:paddingBottom="56dp"
app:layout_constraintBottom_toTopOf="@id/bottom_navigation"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
android:layout_height="wrap_content"
android:background="?attr/backgroundColor"
android:visibility="visible"
app:compatShadowEnabled="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="@menu/bottom_nav_menu" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -1,18 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/bottom_nav_menu">
<!-- two options: "Installed" and "Online" -->
<item
android:id="@+id/installed"
android:id="@+id/installed_menu_item"
android:icon="@drawable/ic_baseline_extension_24"
android:title="@string/installed"
app:showAsAction="ifRoom" />
<item
android:id="@+id/online"
android:id="@+id/online_menu_item"
android:icon="@drawable/baseline_cloud_download_24"
android:title="@string/online"
app:showAsAction="ifRoom" />
<item
android:id="@+id/settings"
android:id="@+id/settings_menu_item"
android:icon="@drawable/ic_baseline_settings_24"
android:title="@string/action_settings"
app:showAsAction="ifRoom" />

@ -240,4 +240,5 @@
app:singleLineTitle="false"
app:summary="@string/loading" />
</PreferenceCategory>
</PreferenceScreen>
</PreferenceScreen>

@ -21,7 +21,7 @@ buildscript {
project.ext.kotlin_version = "1.8.0"
project.ext.sentry_version = "6.13.0"
dependencies {
classpath 'com.android.tools.build:gradle:7.4.0'
classpath 'com.android.tools.build:gradle:7.4.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.mikepenz.aboutlibraries.plugin:aboutlibraries-plugin:${latestAboutLibsRelease}"

@ -1,6 +1,6 @@
#Sun Jun 05 10:40:53 EDT 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-rc-1-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Loading…
Cancel
Save