From be033c85ce5ee8e8c52ed542582184740a917c46 Mon Sep 17 00:00:00 2001 From: Meenbeese Date: Sat, 10 Aug 2024 13:08:23 -0400 Subject: [PATCH] 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"