Change the bottom navigation bar to the material component one
This commit is contained in:
parent
7993b04cf4
commit
e48c49ce0c
@ -164,7 +164,6 @@ dependencies {
|
||||
implementation 'ch.acra:acra:4.9.1'
|
||||
implementation 'io.reactivex:rxjava:1.1.0'
|
||||
implementation 'com.hannesdorfmann:adapterdelegates3:3.0.1'
|
||||
implementation 'com.ashokvarma.android:bottom-navigation-bar:2.0.5'
|
||||
|
||||
implementation 'com.fasterxml.jackson.core:jackson-core:2.11.1'
|
||||
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.11.1'
|
||||
|
@ -5,18 +5,38 @@
|
||||
tools:ignore="MenuTitle">
|
||||
<!-- android:title and android:icon are set dynamically in MainActivity -->
|
||||
<item
|
||||
app:showAsAction="ifRoom|withText"
|
||||
android:id="@+id/latest"/>
|
||||
android:id="@+id/latest"
|
||||
android:enabled="true"
|
||||
android:icon="@drawable/ic_latest"
|
||||
android:orderInCategory="0"
|
||||
android:title="@string/main_menu__latest_apps"
|
||||
app:showAsAction="ifRoom|withText" />
|
||||
<item
|
||||
app:showAsAction="ifRoom|withText"
|
||||
android:id="@+id/categories"/>
|
||||
android:id="@+id/categories"
|
||||
android:enabled="true"
|
||||
android:icon="@drawable/ic_categories"
|
||||
android:orderInCategory="1"
|
||||
android:title="@string/main_menu__categories"
|
||||
app:showAsAction="ifRoom|withText" />
|
||||
<item
|
||||
app:showAsAction="ifRoom|withText"
|
||||
android:id="@+id/nearby"/>
|
||||
android:id="@+id/nearby"
|
||||
android:enabled="true"
|
||||
android:icon="@drawable/ic_nearby"
|
||||
android:orderInCategory="2"
|
||||
android:title="@string/main_menu__swap_nearby"
|
||||
app:showAsAction="ifRoom|withText" />
|
||||
<item
|
||||
app:showAsAction="ifRoom|withText"
|
||||
android:id="@+id/updates"/>
|
||||
android:id="@+id/updates"
|
||||
android:enabled="true"
|
||||
android:icon="@drawable/ic_updates"
|
||||
android:orderInCategory="3"
|
||||
android:title="@string/main_menu__updates"
|
||||
app:showAsAction="ifRoom|withText" />
|
||||
<item
|
||||
app:showAsAction="ifRoom|withText"
|
||||
android:id="@+id/settings"/>
|
||||
android:id="@+id/settings"
|
||||
android:enabled="true"
|
||||
android:icon="@drawable/ic_settings"
|
||||
android:orderInCategory="4"
|
||||
android:title="@string/menu_settings"
|
||||
app:showAsAction="ifRoom|withText" />
|
||||
</menu>
|
@ -31,20 +31,22 @@ import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.ashokvarma.bottomnavigation.BottomNavigationBar;
|
||||
import com.ashokvarma.bottomnavigation.BottomNavigationItem;
|
||||
import com.ashokvarma.bottomnavigation.TextBadgeItem;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.android.material.badge.BadgeDrawable;
|
||||
import com.google.android.material.bottomnavigation.BottomNavigationView;
|
||||
|
||||
import org.fdroid.fdroid.AppUpdateStatusManager;
|
||||
import org.fdroid.fdroid.AppUpdateStatusManager.AppUpdateStatus;
|
||||
import org.fdroid.fdroid.BuildConfig;
|
||||
import org.fdroid.fdroid.FDroidApp;
|
||||
import org.fdroid.fdroid.NfcHelper;
|
||||
import org.fdroid.fdroid.Preferences;
|
||||
@ -61,17 +63,6 @@ import org.fdroid.fdroid.views.AppDetailsActivity;
|
||||
import org.fdroid.fdroid.views.ManageReposActivity;
|
||||
import org.fdroid.fdroid.views.apps.AppListActivity;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.app.AppCompatDelegate;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
/**
|
||||
* Main view shown to users upon starting F-Droid.
|
||||
* <p>
|
||||
@ -86,7 +77,7 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
* When switching from one screen to the next, we stay within this activity. The new screen will
|
||||
* get inflated (if required)
|
||||
*/
|
||||
public class MainActivity extends AppCompatActivity implements BottomNavigationBar.OnTabSelectedListener {
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
private static final String TAG = "MainActivity";
|
||||
|
||||
@ -107,9 +98,9 @@ public class MainActivity extends AppCompatActivity implements BottomNavigationB
|
||||
|
||||
private RecyclerView pager;
|
||||
private MainViewAdapter adapter;
|
||||
private BottomNavigationBar bottomNavigation;
|
||||
private BottomNavigationView bottomNavigation;
|
||||
private int selectedMenuId;
|
||||
private TextBadgeItem updatesBadge;
|
||||
private BadgeDrawable updatesBadge;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
@ -134,61 +125,20 @@ public class MainActivity extends AppCompatActivity implements BottomNavigationB
|
||||
pager.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
|
||||
}
|
||||
|
||||
updatesBadge = new TextBadgeItem().hide(false);
|
||||
bottomNavigation = (BottomNavigationView) findViewById(R.id.bottom_navigation);
|
||||
bottomNavigation.setOnNavigationItemSelectedListener(item -> {
|
||||
pager.scrollToPosition(item.getOrder());
|
||||
selectedMenuId = (int) adapter.getItemId(item.getItemId());
|
||||
|
||||
bottomNavigation = (BottomNavigationBar) findViewById(R.id.bottom_navigation);
|
||||
bottomNavigation
|
||||
.addItem(new BottomNavigationItem(R.drawable.ic_latest, R.string.main_menu__latest_apps));
|
||||
if (BuildConfig.FLAVOR.startsWith("full")) {
|
||||
bottomNavigation
|
||||
.addItem(new BottomNavigationItem(R.drawable.ic_categories, R.string.main_menu__categories))
|
||||
.addItem(new BottomNavigationItem(R.drawable.ic_nearby, R.string.main_menu__swap_nearby));
|
||||
|
||||
bottomNavigation.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (bottomNavigation.getCurrentSelectedPosition() == 2) {
|
||||
if (item.getItemId() == 2) {
|
||||
NearbyViewBinder.updateUsbOtg(MainActivity.this);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
});
|
||||
}
|
||||
bottomNavigation.setTabSelectedListener(this)
|
||||
.setBarBackgroundColor(getBottomNavigationBackgroundColorResId())
|
||||
.setInActiveColor(R.color.bottom_nav_items)
|
||||
.setActiveColor(R.color.bottom_nav_active)
|
||||
.setMode(BottomNavigationBar.MODE_FIXED)
|
||||
.addItem(new BottomNavigationItem(R.drawable.ic_updates, R.string.main_menu__updates)
|
||||
.setBadgeItem(updatesBadge))
|
||||
.addItem(new BottomNavigationItem(R.drawable.ic_settings, R.string.menu_settings))
|
||||
.setAnimationDuration(0)
|
||||
.initialise();
|
||||
|
||||
// turn off animation, scaling, and truncate labels in the middle
|
||||
final LinearLayout linearLayout = bottomNavigation.findViewById(R.id.bottom_navigation_bar_item_container);
|
||||
final int childCount = linearLayout.getChildCount();
|
||||
for (int i = 0; i < childCount; i++) {
|
||||
final View fixedBottomNavigationTab = linearLayout.getChildAt(i);
|
||||
try {
|
||||
Field labelScale = fixedBottomNavigationTab.getClass().getDeclaredField("labelScale");
|
||||
labelScale.setAccessible(true);
|
||||
labelScale.set(fixedBottomNavigationTab, 1.0f);
|
||||
} catch (IllegalAccessException | NoSuchFieldException | IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
final View container = fixedBottomNavigationTab.findViewById(R.id.fixed_bottom_navigation_container);
|
||||
container.setPadding(
|
||||
2,
|
||||
container.getPaddingTop(),
|
||||
2,
|
||||
container.getPaddingBottom()
|
||||
);
|
||||
|
||||
final TextView title = fixedBottomNavigationTab.findViewById(R.id.fixed_bottom_navigation_title);
|
||||
title.setEllipsize(TextUtils.TruncateAt.MIDDLE);
|
||||
title.setTextSize(TypedValue.COMPLEX_UNIT_SP, 13);
|
||||
}
|
||||
updatesBadge = bottomNavigation.getOrCreateBadge(R.id.updates);
|
||||
updatesBadge.setVisible(false);
|
||||
|
||||
IntentFilter updateableAppsFilter = new IntentFilter(AppUpdateStatusManager.BROADCAST_APPSTATUS_LIST_CHANGED);
|
||||
updateableAppsFilter.addAction(AppUpdateStatusManager.BROADCAST_APPSTATUS_CHANGED);
|
||||
@ -215,7 +165,7 @@ public class MainActivity extends AppCompatActivity implements BottomNavigationB
|
||||
}
|
||||
|
||||
private void setSelectedMenuInNav() {
|
||||
bottomNavigation.selectTab(adapter.adapterPositionFromItemId(selectedMenuId));
|
||||
bottomNavigation.setSelectedItemId(adapter.adapterPositionFromItemId(selectedMenuId));
|
||||
}
|
||||
|
||||
private void initialRepoUpdateIfRequired() {
|
||||
@ -292,22 +242,6 @@ public class MainActivity extends AppCompatActivity implements BottomNavigationB
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabSelected(int position) {
|
||||
pager.scrollToPosition(position);
|
||||
selectedMenuId = (int) adapter.getItemId(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabUnselected(int position) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabReselected(int position) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Since any app could send this {@link Intent}, and the search terms are
|
||||
* fed into a SQL query, the data must be strictly sanitized to avoid
|
||||
@ -455,20 +389,14 @@ public class MainActivity extends AppCompatActivity implements BottomNavigationB
|
||||
|
||||
private void refreshUpdatesBadge(int canUpdateCount) {
|
||||
if (canUpdateCount == 0) {
|
||||
updatesBadge.hide(true);
|
||||
updatesBadge.setVisible(false);
|
||||
updatesBadge.clearNumber();
|
||||
} else {
|
||||
updatesBadge.setText(Integer.toString(canUpdateCount));
|
||||
updatesBadge.show(true);
|
||||
updatesBadge.setNumber(canUpdateCount);
|
||||
updatesBadge.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
private int getBottomNavigationBackgroundColorResId() {
|
||||
if (AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_YES) {
|
||||
return R.color.fdroid_night;
|
||||
}
|
||||
return R.color.fdroid_blue;
|
||||
}
|
||||
|
||||
private static class NonScrollingHorizontalLayoutManager extends LinearLayoutManager {
|
||||
NonScrollingHorizontalLayoutManager(Context context) {
|
||||
super(context, LinearLayoutManager.HORIZONTAL, false);
|
||||
|
@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:color="@android:color/white" android:state_checked="true" />
|
||||
<item android:color="@android:color/white" android:state_pressed="true" />
|
||||
<item android:color="#B8D4F0" />
|
||||
</selector>
|
@ -1,16 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true">
|
||||
|
||||
<com.ashokvarma.bottomnavigation.BottomNavigationBar
|
||||
<com.google.android.material.bottomnavigation.BottomNavigationView
|
||||
android:id="@+id/bottom_navigation"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
android:layout_height="wrap_content"
|
||||
app:menu="@menu/main_activity_screens"
|
||||
app:labelVisibilityMode="labeled"/>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/main_view_pager"
|
||||
|
28
app/src/main/res/menu/main_activity_screens.xml
Normal file
28
app/src/main/res/menu/main_activity_screens.xml
Normal file
@ -0,0 +1,28 @@
|
||||
<?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"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:ignore="MenuTitle">
|
||||
<!-- android:title and android:icon are set dynamically in MainActivity -->
|
||||
<item
|
||||
android:id="@+id/latest"
|
||||
android:enabled="true"
|
||||
android:icon="@drawable/ic_latest"
|
||||
android:orderInCategory="0"
|
||||
android:title="@string/main_menu__latest_apps"
|
||||
app:showAsAction="ifRoom|withText" />
|
||||
<item
|
||||
android:id="@+id/updates"
|
||||
android:enabled="true"
|
||||
android:icon="@drawable/ic_updates"
|
||||
android:orderInCategory="1"
|
||||
android:title="@string/main_menu__updates"
|
||||
app:showAsAction="ifRoom|withText" />
|
||||
<item
|
||||
android:id="@+id/settings"
|
||||
android:enabled="true"
|
||||
android:icon="@drawable/ic_settings"
|
||||
android:orderInCategory="2"
|
||||
android:title="@string/menu_settings"
|
||||
app:showAsAction="ifRoom|withText" />
|
||||
</menu>
|
@ -29,12 +29,9 @@
|
||||
<color name="fdroid_blue_dark">#ff004ba0</color>
|
||||
<color name="fdroid_green_light">#ffbee247</color>
|
||||
<color name="fdroid_green">#ff8ab000</color>
|
||||
<!--https://material.io/design/color/dark-theme.html#properties-->
|
||||
<color name="fdroid_night">#ff121212</color>
|
||||
|
||||
<color name="shadow">#cc222222</color>
|
||||
|
||||
<color name="perms_costs_money">#fff4511e</color>
|
||||
|
||||
<color name="bottom_nav_active">@android:color/white</color>
|
||||
</resources>
|
||||
|
@ -35,10 +35,6 @@
|
||||
|
||||
<style name="AlertDialogBaseThemeNight" parent="AlertDialogBaseThemeDark" />
|
||||
|
||||
<style name="ThemeOverlay.App.MaterialAlertDialog.Night" parent="AlertDialogBaseThemeNight">
|
||||
<item name="android:windowBackground">@color/fdroid_night</item>
|
||||
</style>
|
||||
|
||||
<style name="MinWithDialogBaseThemeDark" parent="Theme.MaterialComponents.Dialog.MinWidth">
|
||||
<item name="colorSecondary">@color/fdroid_green</item>
|
||||
|
||||
|
@ -60,6 +60,7 @@
|
||||
<item name="lightGrayTextColor">#4a4a4a</item>
|
||||
<item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
|
||||
<item name="appDetailsAntiFeatureIconColor">#000000</item>
|
||||
<item name="bottomNavigationStyle">@style/Widget.MaterialComponents.BottomNavigationView.PrimarySurface</item>
|
||||
</style>
|
||||
|
||||
<!-- light app theme with accent colors following roughly android design guidelines -->
|
||||
|
@ -1061,6 +1061,11 @@
|
||||
<sha256 value="a8cdab0debc0072db8dd0b23b6aa4932f7d8872295bba7cfd7ad291c756cbf5d" origin="Generated by Gradle"/>
|
||||
</artifact>
|
||||
</component>
|
||||
<component group="com.ashokvarma.android" name="bottom-navigation-bar" version="2.2.0">
|
||||
<artifact name="bottom-navigation-bar-2.2.0.aar">
|
||||
<pgp value="984460dfd8f76a226f7dede2e483332711b8c7d6"/>
|
||||
</artifact>
|
||||
</component>
|
||||
<component group="com.beust" name="jcommander" version="1.72">
|
||||
<artifact name="jcommander-1.72.jar">
|
||||
<pgp value="67497e9d680ce8e95bd6b8f85ad66315fc018797"/>
|
||||
|
Loading…
x
Reference in New Issue
Block a user