From 9ef6a692a2c9c57639ab52ea502d50c0f72e65e5 Mon Sep 17 00:00:00 2001 From: Meenbeese Date: Sun, 4 Aug 2024 10:27:06 -0400 Subject: [PATCH 1/2] Refresh the navbar with new Material icons --- .../org/torproject/android/OrbotActivity.kt | 19 +++++++++++-------- .../main/res/drawable/ic_connect_filled.xml | 10 ++++++++++ .../main/res/drawable/ic_connect_outline.xml | 10 ++++++++++ .../main/res/drawable/ic_connect_selector.xml | 5 +++++ .../main/res/drawable/ic_kindness_filled.xml | 10 ++++++++++ .../main/res/drawable/ic_kindness_outline.xml | 10 ++++++++++ .../res/drawable/ic_kindness_selector.xml | 5 +++++ app/src/main/res/drawable/ic_more_filled.xml | 11 +++++++++++ app/src/main/res/drawable/ic_more_outline.xml | 11 +++++++++++ .../main/res/drawable/ic_more_selector.xml | 5 +++++ app/src/main/res/menu/main_bottom_nav.xml | 10 +++------- app/src/main/res/navigation/nav_graph.xml | 4 ++-- 12 files changed, 93 insertions(+), 17 deletions(-) create mode 100644 app/src/main/res/drawable/ic_connect_filled.xml create mode 100644 app/src/main/res/drawable/ic_connect_outline.xml create mode 100644 app/src/main/res/drawable/ic_connect_selector.xml create mode 100644 app/src/main/res/drawable/ic_kindness_filled.xml create mode 100644 app/src/main/res/drawable/ic_kindness_outline.xml create mode 100644 app/src/main/res/drawable/ic_kindness_selector.xml create mode 100644 app/src/main/res/drawable/ic_more_filled.xml create mode 100644 app/src/main/res/drawable/ic_more_outline.xml create mode 100644 app/src/main/res/drawable/ic_more_selector.xml diff --git a/app/src/main/java/org/torproject/android/OrbotActivity.kt b/app/src/main/java/org/torproject/android/OrbotActivity.kt index 20473e017..87aeb17f9 100644 --- a/app/src/main/java/org/torproject/android/OrbotActivity.kt +++ b/app/src/main/java/org/torproject/android/OrbotActivity.kt @@ -11,13 +11,17 @@ import android.content.pm.PackageManager import android.content.res.Configuration import android.os.Bundle import android.widget.* + import androidx.activity.result.contract.ActivityResultContracts import androidx.core.content.ContextCompat import androidx.localbroadcastmanager.content.LocalBroadcastManager +import androidx.navigation.NavController import androidx.navigation.findNavController import androidx.navigation.ui.setupWithNavController + import com.google.android.material.bottomnavigation.BottomNavigationView import com.scottyab.rootbeer.RootBeer + import org.torproject.android.core.LocaleHelper import org.torproject.android.core.putNotSystem import org.torproject.android.core.ui.BaseActivity @@ -27,11 +31,10 @@ import org.torproject.android.ui.LogBottomSheet class OrbotActivity : BaseActivity() { - private lateinit var bottomNavigationView: BottomNavigationView - private lateinit var logBottomSheet: LogBottomSheet - lateinit var fragConnect: ConnectFragment - lateinit var fragMore: MoreFragment + var fragConnect: ConnectFragment = ConnectFragment() + var fragKindness: KindnessFragment = KindnessFragment() + var fragMore: MoreFragment = MoreFragment() var previousReceivedTorStatus: String? = null @@ -75,11 +78,12 @@ class OrbotActivity : BaseActivity() { logBottomSheet = LogBottomSheet() - bottomNavigationView = findViewById(R.id.bottom_navigation) + val navController: NavController = findNavController(R.id.nav_fragment) + val bottomNavigationView: BottomNavigationView = findViewById(R.id.bottom_navigation) - val navController = findNavController(R.id.nav_fragment) bottomNavigationView.setupWithNavController(navController) - bottomNavigationView.selectedItemId = R.id.connectFragment + + bottomNavigationView.menu.findItem(R.id.connectFragment).isChecked = true with(LocalBroadcastManager.getInstance(this)) { registerReceiver( @@ -113,7 +117,6 @@ class OrbotActivity : BaseActivity() { //we didn't find indication of root } } - } override fun onBackPressed() { diff --git a/app/src/main/res/drawable/ic_connect_filled.xml b/app/src/main/res/drawable/ic_connect_filled.xml new file mode 100644 index 000000000..cbc006739 --- /dev/null +++ b/app/src/main/res/drawable/ic_connect_filled.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable/ic_connect_outline.xml b/app/src/main/res/drawable/ic_connect_outline.xml new file mode 100644 index 000000000..cef952372 --- /dev/null +++ b/app/src/main/res/drawable/ic_connect_outline.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable/ic_connect_selector.xml b/app/src/main/res/drawable/ic_connect_selector.xml new file mode 100644 index 000000000..14fa72c62 --- /dev/null +++ b/app/src/main/res/drawable/ic_connect_selector.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/src/main/res/drawable/ic_kindness_filled.xml b/app/src/main/res/drawable/ic_kindness_filled.xml new file mode 100644 index 000000000..7c29e5e33 --- /dev/null +++ b/app/src/main/res/drawable/ic_kindness_filled.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable/ic_kindness_outline.xml b/app/src/main/res/drawable/ic_kindness_outline.xml new file mode 100644 index 000000000..2e40a458e --- /dev/null +++ b/app/src/main/res/drawable/ic_kindness_outline.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable/ic_kindness_selector.xml b/app/src/main/res/drawable/ic_kindness_selector.xml new file mode 100644 index 000000000..c310e909b --- /dev/null +++ b/app/src/main/res/drawable/ic_kindness_selector.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/src/main/res/drawable/ic_more_filled.xml b/app/src/main/res/drawable/ic_more_filled.xml new file mode 100644 index 000000000..6b9c1d268 --- /dev/null +++ b/app/src/main/res/drawable/ic_more_filled.xml @@ -0,0 +1,11 @@ + + + diff --git a/app/src/main/res/drawable/ic_more_outline.xml b/app/src/main/res/drawable/ic_more_outline.xml new file mode 100644 index 000000000..8622d5e0d --- /dev/null +++ b/app/src/main/res/drawable/ic_more_outline.xml @@ -0,0 +1,11 @@ + + + diff --git a/app/src/main/res/drawable/ic_more_selector.xml b/app/src/main/res/drawable/ic_more_selector.xml new file mode 100644 index 000000000..29b5d9c84 --- /dev/null +++ b/app/src/main/res/drawable/ic_more_selector.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/src/main/res/menu/main_bottom_nav.xml b/app/src/main/res/menu/main_bottom_nav.xml index d76e92f75..e3f296a84 100644 --- a/app/src/main/res/menu/main_bottom_nav.xml +++ b/app/src/main/res/menu/main_bottom_nav.xml @@ -1,18 +1,14 @@ - \ No newline at end of file diff --git a/app/src/main/res/navigation/nav_graph.xml b/app/src/main/res/navigation/nav_graph.xml index d2952d35f..d4fc7e0e4 100644 --- a/app/src/main/res/navigation/nav_graph.xml +++ b/app/src/main/res/navigation/nav_graph.xml @@ -2,8 +2,8 @@ + android:id="@+id/nav_graph" + app:startDestination="@id/connectFragment"> Date: Sat, 10 Aug 2024 13:08:23 -0400 Subject: [PATCH 2/2] Add left/right sliding animations to the navbar --- .../org/torproject/android/OrbotActivity.kt | 37 +++++++++++++++++++ app/src/main/res/anim/slide_in_left.xml | 7 ++++ app/src/main/res/anim/slide_in_right.xml | 7 ++++ app/src/main/res/anim/slide_out_left.xml | 7 ++++ app/src/main/res/anim/slide_out_right.xml | 7 ++++ app/src/main/res/layout/activity_orbot.xml | 1 + 6 files changed, 66 insertions(+) create mode 100644 app/src/main/res/anim/slide_in_left.xml create mode 100644 app/src/main/res/anim/slide_in_right.xml create mode 100644 app/src/main/res/anim/slide_out_left.xml create mode 100644 app/src/main/res/anim/slide_out_right.xml diff --git a/app/src/main/java/org/torproject/android/OrbotActivity.kt b/app/src/main/java/org/torproject/android/OrbotActivity.kt index 87aeb17f9..0a334cd1f 100644 --- a/app/src/main/java/org/torproject/android/OrbotActivity.kt +++ b/app/src/main/java/org/torproject/android/OrbotActivity.kt @@ -16,6 +16,7 @@ import androidx.activity.result.contract.ActivityResultContracts import androidx.core.content.ContextCompat import androidx.localbroadcastmanager.content.LocalBroadcastManager import androidx.navigation.NavController +import androidx.navigation.NavOptions import androidx.navigation.findNavController import androidx.navigation.ui.setupWithNavController @@ -85,6 +86,42 @@ class OrbotActivity : BaseActivity() { bottomNavigationView.menu.findItem(R.id.connectFragment).isChecked = true + val navOptionsLeftToRight = NavOptions.Builder() + .setEnterAnim(R.anim.slide_in_right) + .setExitAnim(R.anim.slide_out_left) + .setPopEnterAnim(R.anim.slide_in_right) + .setPopExitAnim(R.anim.slide_out_left) + .build() + + val navOptionsRightToLeft = NavOptions.Builder() + .setEnterAnim(R.anim.slide_in_left) + .setExitAnim(R.anim.slide_out_right) + .setPopEnterAnim(R.anim.slide_in_left) + .setPopExitAnim(R.anim.slide_out_right) + .build() + + var lastSelectedItemId = R.id.connectFragment + + bottomNavigationView.setOnItemSelectedListener { item -> + if (item.itemId == lastSelectedItemId) { + return@setOnItemSelectedListener true + } + + val navOptions = if (item.itemId > lastSelectedItemId) { + navOptionsLeftToRight + } else { + navOptionsRightToLeft + } + lastSelectedItemId = item.itemId + + when (item.itemId) { + R.id.connectFragment -> navController.navigate(R.id.connectFragment, null, navOptions) + R.id.kindnessFragment -> navController.navigate(R.id.kindnessFragment, null, navOptions) + R.id.moreFragment -> navController.navigate(R.id.moreFragment, null, navOptions) + } + true + } + with(LocalBroadcastManager.getInstance(this)) { registerReceiver( orbotServiceBroadcastReceiver, IntentFilter(OrbotConstants.LOCAL_ACTION_STATUS) diff --git a/app/src/main/res/anim/slide_in_left.xml b/app/src/main/res/anim/slide_in_left.xml new file mode 100644 index 000000000..c47d5a29a --- /dev/null +++ b/app/src/main/res/anim/slide_in_left.xml @@ -0,0 +1,7 @@ + + + + diff --git a/app/src/main/res/anim/slide_in_right.xml b/app/src/main/res/anim/slide_in_right.xml new file mode 100644 index 000000000..aa3acebed --- /dev/null +++ b/app/src/main/res/anim/slide_in_right.xml @@ -0,0 +1,7 @@ + + + + diff --git a/app/src/main/res/anim/slide_out_left.xml b/app/src/main/res/anim/slide_out_left.xml new file mode 100644 index 000000000..5cc9b68e1 --- /dev/null +++ b/app/src/main/res/anim/slide_out_left.xml @@ -0,0 +1,7 @@ + + + + diff --git a/app/src/main/res/anim/slide_out_right.xml b/app/src/main/res/anim/slide_out_right.xml new file mode 100644 index 000000000..c4a991950 --- /dev/null +++ b/app/src/main/res/anim/slide_out_right.xml @@ -0,0 +1,7 @@ + + + + diff --git a/app/src/main/res/layout/activity_orbot.xml b/app/src/main/res/layout/activity_orbot.xml index dbce870fd..2e3cc8206 100644 --- a/app/src/main/res/layout/activity_orbot.xml +++ b/app/src/main/res/layout/activity_orbot.xml @@ -23,6 +23,7 @@ android:id="@+id/bottom_navigation" android:layout_width="match_parent" android:layout_height="wrap_content" + android:background="@android:color/black" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintBottom_toBottomOf="parent"