Skip to content

Commit 7c29649

Browse files
feat(android): add settings button to the session view (firezone#3755)
Adds a `Settings` button similar to the sign in view: ![Screenshot_20240224_120508](https://github.com/firezone/firezone/assets/5115126/12826481-0013-4d46-9d65-b48d22fa859e) Then, while signed in, there is a warning dialog when the user attempts to "save" their settings: ![Screenshot_20240224_120724](https://github.com/firezone/firezone/assets/5115126/c4b8b2b0-2b0d-4175-9e00-c4aafa9a3ef0)
1 parent 77b00b3 commit 7c29649

File tree

6 files changed

+54
-5
lines changed

6 files changed

+54
-5
lines changed

kotlin/android/app/src/main/java/dev/firezone/android/features/session/ui/SessionActivity.kt

+8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
1515
import dagger.hilt.android.AndroidEntryPoint
1616
import dev.firezone.android.core.utils.ClipboardUtils
1717
import dev.firezone.android.databinding.ActivitySessionBinding
18+
import dev.firezone.android.features.settings.ui.SettingsActivity
1819
import dev.firezone.android.tunnel.TunnelService
1920
import dev.firezone.android.tunnel.model.Resource
2021

@@ -78,6 +79,13 @@ internal class SessionActivity : AppCompatActivity() {
7879
tunnelService?.disconnect()
7980
}
8081

82+
binding.btSettings.setOnClickListener {
83+
Log.d(TAG, "Settings button clicked")
84+
val intent = Intent(this, SettingsActivity::class.java)
85+
intent.putExtra("isUserSignedIn", true)
86+
startActivity(intent)
87+
}
88+
8189
binding.tvActorName.text = viewModel.getActorName()
8290

8391
val layoutManager = LinearLayoutManager(this@SessionActivity)

kotlin/android/app/src/main/java/dev/firezone/android/features/settings/ui/SettingsActivity.kt

+21-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package dev.firezone.android.features.settings.ui
33

44
import android.os.Bundle
55
import androidx.activity.viewModels
6+
import androidx.appcompat.app.AlertDialog
67
import androidx.appcompat.app.AppCompatActivity
78
import androidx.fragment.app.Fragment
89
import androidx.fragment.app.FragmentActivity
@@ -55,8 +56,15 @@ internal class SettingsActivity : AppCompatActivity() {
5556
}
5657
}.attach()
5758

58-
btSaveSettings.setOnClickListener {
59-
viewModel.onSaveSettingsCompleted()
59+
val isUserSignedIn = intent.getBooleanExtra("isUserSignedIn", false)
60+
if (isUserSignedIn) {
61+
btSaveSettings.setOnClickListener {
62+
showSaveWarningDialog()
63+
}
64+
} else {
65+
btSaveSettings.setOnClickListener {
66+
viewModel.onSaveSettingsCompleted()
67+
}
6068
}
6169

6270
btCancel.setOnClickListener {
@@ -82,6 +90,17 @@ internal class SettingsActivity : AppCompatActivity() {
8290
viewModel.onViewResume(this@SettingsActivity)
8391
}
8492

93+
private fun showSaveWarningDialog() {
94+
AlertDialog.Builder(this).apply {
95+
setTitle("Warning")
96+
setMessage("Changed settings will not be applied until you sign out and sign back in.")
97+
setPositiveButton("Okay") { dialog, which ->
98+
viewModel.onSaveSettingsCompleted()
99+
}
100+
create().show()
101+
}
102+
}
103+
85104
override fun onStop() {
86105
super.onStop()
87106
if (isFinishing) {

kotlin/android/app/src/main/java/dev/firezone/android/features/settings/ui/SettingsViewModel.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ internal class SettingsViewModel
191191
emit(Result.failure(e))
192192
}.flowOn(Dispatchers.IO)
193193

194-
private fun getLogZipPath(context: Context) = "${context.cacheDir.absolutePath}/connlib-logs.zip"
194+
private fun getLogZipPath(context: Context) = "${context.cacheDir.absolutePath}/logs.zip"
195195

196196
private fun onFieldUpdated() {
197197
_uiState.value =

kotlin/android/app/src/main/java/dev/firezone/android/features/signin/ui/SignInFragment.kt

+5
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,13 @@ internal class SignInFragment : Fragment(R.layout.fragment_sign_in) {
3737
requireActivity().finish()
3838
}
3939
btSettings.setOnClickListener {
40+
val bundle =
41+
Bundle().apply {
42+
putBoolean("isUserSignedIn", false)
43+
}
4044
findNavController().navigate(
4145
R.id.settingsActivity,
46+
bundle,
4247
)
4348
}
4449
}

kotlin/android/app/src/main/res/layout/activity_session.xml

+13-1
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,26 @@
6161
app:layout_constraintTop_toBottomOf="@id/tvResourcesList"
6262
tools:layout_editor_absoluteX="16dp" />
6363

64+
<com.google.android.material.button.MaterialButton
65+
android:id="@+id/btSettings"
66+
style="?attr/materialButtonOutlinedStyle"
67+
android:layout_width="0dp"
68+
android:layout_height="wrap_content"
69+
android:layout_marginEnd="8dp"
70+
android:text="@string/settings"
71+
app:layout_constraintBottom_toBottomOf="parent"
72+
app:layout_constraintEnd_toStartOf="@+id/btSignOut"
73+
app:layout_constraintStart_toStartOf="parent" />
74+
6475
<com.google.android.material.button.MaterialButton
6576
android:id="@+id/btSignOut"
6677
android:layout_width="0dp"
6778
android:layout_height="wrap_content"
79+
android:layout_marginStart="8dp"
6880
android:text="@string/sign_out"
6981
app:layout_constraintBottom_toBottomOf="parent"
7082
app:layout_constraintEnd_toEndOf="parent"
71-
app:layout_constraintStart_toStartOf="parent" />
83+
app:layout_constraintStart_toEndOf="@+id/btSettings" />
7284

7385
<TextView
7486
android:id="@+id/tvActorName"

kotlin/android/app/src/main/res/navigation/app_nav_graph.xml

+6-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@
1818
<activity
1919
android:id="@+id/settingsActivity"
2020
android:name="dev.firezone.android.features.settings.ui.SettingsActivity"
21-
tools:layout="@layout/activity_settings" />
21+
android:label="SettingsActivity"
22+
tools:layout="@layout/activity_settings">
23+
<argument
24+
android:name="isUserSignedIn"
25+
app:argType="boolean" />
26+
</activity>
2227

2328
<activity
2429
android:id="@+id/sessionActivity"

0 commit comments

Comments
 (0)