Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refresh the navbar with new icons and animations #1167

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 48 additions & 8 deletions app/src/main/java/org/torproject/android/OrbotActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@ 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.NavOptions
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
Expand All @@ -27,11 +32,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

Expand Down Expand Up @@ -75,11 +79,48 @@ 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

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(
Expand Down Expand Up @@ -113,7 +154,6 @@ class OrbotActivity : BaseActivity() {
//we didn't find indication of root
}
}

}

override fun onBackPressed() {
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/anim/slide_in_left.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="-100%"
android:toXDelta="0%"
android:duration="300"/>
</set>
7 changes: 7 additions & 0 deletions app/src/main/res/anim/slide_in_right.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="100%"
android:toXDelta="0%"
android:duration="300"/>
</set>
7 changes: 7 additions & 0 deletions app/src/main/res/anim/slide_out_left.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0%"
android:toXDelta="-100%"
android:duration="300"/>
</set>
7 changes: 7 additions & 0 deletions app/src/main/res/anim/slide_out_right.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0%"
android:toXDelta="100%"
android:duration="300"/>
</set>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_connect_filled.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M280,720Q180,720 110,650Q40,580 40,480Q40,380 110,310Q180,240 280,240Q361,240 421.5,285.5Q482,331 506,400L920,400L920,560L840,560L840,720L680,720L680,560L506,560Q482,629 421.5,674.5Q361,720 280,720ZM280,560Q313,560 336.5,536.5Q360,513 360,480Q360,447 336.5,423.5Q313,400 280,400Q247,400 223.5,423.5Q200,447 200,480Q200,513 223.5,536.5Q247,560 280,560Z"/>
</vector>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_connect_outline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M280,720Q180,720 110,650Q40,580 40,480Q40,380 110,310Q180,240 280,240Q346,240 401,273Q456,306 488,360L920,360L920,600L840,600L840,720L600,720L600,600L488,600Q456,654 401,687Q346,720 280,720ZM280,640Q346,640 386,599.5Q426,559 434,520L680,520L680,640L760,640L760,520L840,520L840,440L434,440Q426,401 386,360.5Q346,320 280,320Q214,320 167,367Q120,414 120,480Q120,546 167,593Q214,640 280,640ZM280,560Q313,560 336.5,536.5Q360,513 360,480Q360,447 336.5,423.5Q313,400 280,400Q247,400 223.5,423.5Q200,447 200,480Q200,513 223.5,536.5Q247,560 280,560ZM280,480Q280,480 280,480Q280,480 280,480Q280,480 280,480Q280,480 280,480Q280,480 280,480Q280,480 280,480L280,480L280,480L280,480L280,480L280,480L280,480L280,480Q280,480 280,480Q280,480 280,480Z"/>
</vector>
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_connect_selector.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_connect_filled" android:state_checked="true"/>
<item android:drawable="@drawable/ic_connect_outline" android:state_checked="false"/>
</selector>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_kindness_filled.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M480,840L422,788Q321,697 255,631Q189,565 150,512.5Q111,460 95.5,416Q80,372 80,326Q80,232 143,169Q206,106 300,106Q352,106 399,128Q446,150 480,190Q514,150 561,128Q608,106 660,106Q754,106 817,169Q880,232 880,326Q880,372 864.5,416Q849,460 810,512.5Q771,565 705,631Q639,697 538,788L480,840Z"/>
</vector>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_kindness_outline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M480,840L422,788Q321,697 255,631Q189,565 150,512.5Q111,460 95.5,416Q80,372 80,326Q80,232 143,169Q206,106 300,106Q352,106 399,128Q446,150 480,190Q514,150 561,128Q608,106 660,106Q754,106 817,169Q880,232 880,326Q880,372 864.5,416Q849,460 810,512.5Q771,565 705,631Q639,697 538,788L480,840ZM480,732Q576,646 638,584.5Q700,523 736,477.5Q772,432 786,396.5Q800,361 800,326Q800,266 760,226Q720,186 660,186Q613,186 573,212.5Q533,239 518,280L518,280L442,280L442,280Q427,239 387,212.5Q347,186 300,186Q240,186 200,226Q160,266 160,326Q160,361 174,396.5Q188,432 224,477.5Q260,523 322,584.5Q384,646 480,732ZM480,459Q480,459 480,459Q480,459 480,459Q480,459 480,459Q480,459 480,459Q480,459 480,459Q480,459 480,459Q480,459 480,459Q480,459 480,459L480,459L480,459L480,459Q480,459 480,459Q480,459 480,459Q480,459 480,459Q480,459 480,459Q480,459 480,459Q480,459 480,459Q480,459 480,459Q480,459 480,459Z"/>
</vector>
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_kindness_selector.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_kindness_filled" android:state_checked="true"/>
<item android:drawable="@drawable/ic_kindness_outline" android:state_checked="false"/>
</selector>
11 changes: 11 additions & 0 deletions app/src/main/res/drawable/ic_more_filled.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal"
android:autoMirrored="true">
<path
android:fillColor="@android:color/white"
android:pathData="M318,760L120,480L318,200L840,200L840,760L318,760ZM380,520Q397,520 408.5,508.5Q420,497 420,480Q420,463 408.5,451.5Q397,440 380,440Q363,440 351.5,451.5Q340,463 340,480Q340,497 351.5,508.5Q363,520 380,520ZM520,520Q537,520 548.5,508.5Q560,497 560,480Q560,463 548.5,451.5Q537,440 520,440Q503,440 491.5,451.5Q480,463 480,480Q480,497 491.5,508.5Q503,520 520,520ZM660,520Q677,520 688.5,508.5Q700,497 700,480Q700,463 688.5,451.5Q677,440 660,440Q643,440 631.5,451.5Q620,463 620,480Q620,497 631.5,508.5Q643,520 660,520Z"/>
</vector>
11 changes: 11 additions & 0 deletions app/src/main/res/drawable/ic_more_outline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal"
android:autoMirrored="true">
<path
android:fillColor="@android:color/white"
android:pathData="M380,520Q397,520 408.5,508.5Q420,497 420,480Q420,463 408.5,451.5Q397,440 380,440Q363,440 351.5,451.5Q340,463 340,480Q340,497 351.5,508.5Q363,520 380,520ZM520,520Q537,520 548.5,508.5Q560,497 560,480Q560,463 548.5,451.5Q537,440 520,440Q503,440 491.5,451.5Q480,463 480,480Q480,497 491.5,508.5Q503,520 520,520ZM660,520Q677,520 688.5,508.5Q700,497 700,480Q700,463 688.5,451.5Q677,440 660,440Q643,440 631.5,451.5Q620,463 620,480Q620,497 631.5,508.5Q643,520 660,520ZM360,760Q340,760 322.5,751Q305,742 294,726L120,480L294,234Q305,218 322.5,209Q340,200 360,200L760,200Q793,200 816.5,223.5Q840,247 840,280L840,680Q840,713 816.5,736.5Q793,760 760,760L360,760ZM760,680Q760,680 760,680Q760,680 760,680L760,480L760,280Q760,280 760,280Q760,280 760,280L760,280Q760,280 760,280Q760,280 760,280L760,680Q760,680 760,680Q760,680 760,680ZM360,680L760,680Q760,680 760,680Q760,680 760,680L760,280Q760,280 760,280Q760,280 760,280L360,280Q360,280 360,280Q360,280 360,280L218,480L360,680Q360,680 360,680Q360,680 360,680Z"/>
</vector>
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_more_selector.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_more_filled" android:state_checked="true"/>
<item android:drawable="@drawable/ic_more_outline" android:state_checked="false"/>
</selector>
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_orbot.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 3 additions & 7 deletions app/src/main/res/menu/main_bottom_nav.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/connectFragment"
android:enabled="true"
android:icon="@drawable/ic_onion"
android:icon="@drawable/ic_connect_selector"
android:title="@string/connect"/>
<item
android:id="@+id/kindnessFragment"
android:enabled="true"
android:icon="@drawable/ic_heart"
android:icon="@drawable/ic_kindness_selector"
android:title="@string/menu_kindness"/>

<item
android:id="@+id/moreFragment"
android:enabled="true"
android:icon="@drawable/ic_more"
android:icon="@drawable/ic_more_selector"
android:title="@string/menu_more"/>
</menu>
4 changes: 2 additions & 2 deletions app/src/main/res/navigation/nav_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<navigation 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"
android:id="@+id/nav_graph.xml"
app:startDestination="@id/moreFragment">
android:id="@+id/nav_graph"
app:startDestination="@id/connectFragment">

<fragment
android:id="@+id/connectFragment"
Expand Down