Skip to content

Commit 0eb0bb5

Browse files
Merge pull request #363 from Ayush0Chaudhary/signout-btn
signout-btn
2 parents 3e2d807 + 6718a1c commit 0eb0bb5

File tree

4 files changed

+56
-6
lines changed

4 files changed

+56
-6
lines changed

app/src/main/java/com/blurr/voice/SettingsActivity.kt

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@ class SettingsActivity : BaseNavigationActivity() {
4141
private lateinit var editUserName: android.widget.EditText
4242
private lateinit var editUserEmail: android.widget.EditText
4343
private lateinit var editWakeWordKey: android.widget.EditText
44-
private lateinit var textGetPicovoiceKeyLink: TextView // NEW: Declare the TextView for the link
45-
private lateinit var wakeWordButton: TextView // NEW: Declare wake word button
46-
private lateinit var wakeWordManager: WakeWordManager // NEW: Wake word manager
47-
private lateinit var requestPermissionLauncher: ActivityResultLauncher<String> // NEW: Permission launcher
44+
private lateinit var textGetPicovoiceKeyLink: TextView
45+
private lateinit var wakeWordButton: TextView
46+
private lateinit var buttonSignOut: Button
47+
private lateinit var wakeWordManager: WakeWordManager
48+
private lateinit var requestPermissionLauncher: ActivityResultLauncher<String>
4849

4950

5051
private lateinit var sc: SpeechCoordinator
@@ -104,11 +105,12 @@ class SettingsActivity : BaseNavigationActivity() {
104105
batteryOptimizationHelpButton = findViewById(R.id.batteryOptimizationHelpButton)
105106

106107
editWakeWordKey = findViewById(R.id.editWakeWordKey)
107-
wakeWordButton = findViewById(R.id.wakeWordButton) // NEW: Initialize wake word button
108+
wakeWordButton = findViewById(R.id.wakeWordButton)
109+
buttonSignOut = findViewById(R.id.buttonSignOut)
108110

109111
editUserName = findViewById(R.id.editUserName)
110112
editUserEmail = findViewById(R.id.editUserEmail)
111-
textGetPicovoiceKeyLink = findViewById(R.id.textGetPicovoiceKeyLink) // NEW: Initialize the TextView
113+
textGetPicovoiceKeyLink = findViewById(R.id.textGetPicovoiceKeyLink)
112114

113115

114116
setupClickListeners()
@@ -174,6 +176,10 @@ class SettingsActivity : BaseNavigationActivity() {
174176
Log.e("SettingsActivity", "Failed to open Picovoice link", e)
175177
}
176178
}
179+
180+
buttonSignOut.setOnClickListener {
181+
showSignOutConfirmationDialog()
182+
}
177183
}
178184

179185
private fun setupAutoSavingListeners() {
@@ -330,6 +336,34 @@ class SettingsActivity : BaseNavigationActivity() {
330336
androidx.core.content.ContextCompat.getColor(this, R.color.white)
331337
)
332338
}
339+
340+
private fun showSignOutConfirmationDialog() {
341+
AlertDialog.Builder(this)
342+
.setTitle("Sign Out")
343+
.setMessage("Are you sure you want to sign out? This will clear all your settings and data.")
344+
.setPositiveButton("Sign Out") { _, _ ->
345+
signOut()
346+
}
347+
.setNegativeButton("Cancel", null)
348+
.show()
349+
}
350+
351+
private fun signOut() {
352+
// Clear User Profile
353+
val userProfileManager = UserProfileManager(this)
354+
userProfileManager.clearProfile()
355+
356+
// Clear all shared preferences for this app
357+
getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE).edit().clear().apply()
358+
359+
360+
// Restart the app by navigating to the onboarding screen
361+
val intent = Intent(this, LoginActivity::class.java)
362+
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
363+
startActivity(intent)
364+
finish()
365+
}
366+
333367

334368
override fun getContentLayoutId(): Int = R.layout.activity_settings
335369

app/src/main/java/com/blurr/voice/utilities/UserProfileManager.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ class UserProfileManager(private val context: Context) {
2525

2626
fun getName(): String? = prefs.getString(KEY_NAME, null)
2727
fun getEmail(): String? = prefs.getString(KEY_EMAIL, null)
28+
29+
fun clearProfile() {
30+
prefs.edit().clear().apply()
31+
}
32+
2833
}
2934

3035

app/src/main/res/layout/activity_settings.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,16 @@
291291
android:textSize="16sp"
292292
android:textStyle="bold" />
293293

294+
<Button
295+
android:id="@+id/buttonSignOut"
296+
android:layout_width="wrap_content"
297+
android:layout_height="wrap_content"
298+
android:layout_gravity="center_horizontal"
299+
android:layout_marginTop="24dp"
300+
android:background="@drawable/btn_with_border"
301+
android:text="@string/sign_out"
302+
android:textColor="@android:color/white" />
303+
294304

295305
</LinearLayout>
296306

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,5 @@
119119

120120
<string name="microphone_permission_not_granted">Microphone permission not granted</string>
121121
<string name="accessibility_permission_needed_for_task">Hey, accessibility permission is needed to execute any task. I know you might have doubt giving this permission to me, but my code is open source, so can always check it out if you have doubts.</string>
122+
<string name="sign_out">Sign Out</string>
122123
</resources>

0 commit comments

Comments
 (0)