generated from bitwarden/template
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BEEEP: Refactor navigation of unauthenticated and authenticated state. (
#68)
- Loading branch information
1 parent
3b7a607
commit 762e8a6
Showing
9 changed files
with
146 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
app/src/main/java/dev/passwordless/sampleapp/AuthorizedActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package dev.passwordless.sampleapp | ||
|
||
import android.annotation.SuppressLint | ||
import android.os.Bundle | ||
import android.view.Menu | ||
import android.view.MenuItem | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.navigation.findNavController | ||
import androidx.navigation.ui.AppBarConfiguration | ||
import androidx.navigation.ui.setupActionBarWithNavController | ||
import androidx.preference.PreferenceManager | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import dev.passwordless.sampleapp.databinding.ActivityAuthorizedBinding | ||
import dev.passwordless.sampleapp.databinding.ActivityMainBinding | ||
|
||
@AndroidEntryPoint | ||
class AuthorizedActivity : AppCompatActivity() { | ||
|
||
private lateinit var appBarConfiguration: AppBarConfiguration | ||
private lateinit var binding: ActivityAuthorizedBinding | ||
|
||
@SuppressLint("RestrictedApi") | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
binding = ActivityAuthorizedBinding.inflate(layoutInflater) | ||
setContentView(binding.root) | ||
|
||
setSupportActionBar(binding.toolbar) | ||
val navController = findNavController(R.id.authorized_nav_host_fragment_content) | ||
appBarConfiguration = AppBarConfiguration(navController.graph) | ||
setupActionBarWithNavController(navController, appBarConfiguration) | ||
navController.enableOnBackPressed(false) | ||
} | ||
|
||
override fun onCreateOptionsMenu(menu: Menu): Boolean { | ||
// Inflate the menu; this adds items to the action bar if it is present. | ||
menuInflater.inflate(R.menu.menu_main, menu) | ||
return true | ||
} | ||
|
||
override fun onOptionsItemSelected(item: MenuItem): Boolean { | ||
// Handle action bar item clicks here. The action bar will | ||
// automatically handle clicks on the Home/Up button, so long | ||
// as you specify a parent activity in AndroidManifest.xml. | ||
return when (item.itemId) { | ||
R.id.action_settings -> true | ||
else -> super.onOptionsItemSelected(item) | ||
} | ||
} | ||
|
||
override fun onDestroy() { | ||
PreferenceManager.getDefaultSharedPreferences(applicationContext).edit().clear().commit() | ||
super.onDestroy() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.coordinatorlayout.widget.CoordinatorLayout 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:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:fitsSystemWindows="true" | ||
tools:context="dev.passwordless.sampleapp.AuthorizedActivity"> | ||
|
||
<com.google.android.material.appbar.AppBarLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:fitsSystemWindows="true"> | ||
|
||
<com.google.android.material.appbar.MaterialToolbar | ||
android:id="@+id/toolbar" | ||
android:layout_width="match_parent" | ||
android:layout_height="?attr/actionBarSize" | ||
app:titleTextColor="@color/white" /> | ||
|
||
</com.google.android.material.appbar.AppBarLayout> | ||
|
||
<include layout="@layout/authorized_content" /> | ||
|
||
</androidx.coordinatorlayout.widget.CoordinatorLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<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" | ||
app:layout_behavior="@string/appbar_scrolling_view_behavior"> | ||
|
||
<fragment | ||
android:id="@+id/authorized_nav_host_fragment_content" | ||
android:name="androidx.navigation.fragment.NavHostFragment" | ||
android:layout_width="0dp" | ||
android:layout_height="0dp" | ||
app:defaultNavHost="true" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" | ||
app:navGraph="@navigation/authorized_nav_graph" /> | ||
</androidx.constraintlayout.widget.ConstraintLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="utf-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/authorized_nav_graph" | ||
app:startDestination="@id/credentials_fragment"> | ||
|
||
<fragment | ||
android:id="@+id/credentials_fragment" | ||
android:name="dev.passwordless.sampleapp.CredentialsFragment" | ||
android:label="@string/credentials_fragment_label" | ||
tools:layout="@layout/fragment_credentials"> | ||
|
||
<action | ||
android:id="@+id/action_credentials_to_add_credential_fragment" | ||
app:destination="@id/add_credential_fragment" /> | ||
</fragment> | ||
<fragment | ||
android:id="@+id/add_credential_fragment" | ||
android:name="dev.passwordless.sampleapp.AddCredentialFragment" | ||
android:label="@string/add_credential_fragment_label" | ||
tools:layout="@layout/fragment_add_credential"> | ||
|
||
<action | ||
android:id="@+id/action_add_credential_to_credentials_fragment" | ||
app:destination="@id/credentials_fragment" /> | ||
</fragment> | ||
</navigation> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters