Skip to content

Commit 84dfd11

Browse files
committed
Implemented logout button
1 parent c36cf58 commit 84dfd11

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

android/app/src/main/java/com/httpsms/MainActivity.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import android.widget.Toast
1616
import androidx.activity.result.contract.ActivityResultContracts
1717
import androidx.appcompat.app.AppCompatActivity
1818
import androidx.core.app.ActivityCompat
19+
import com.google.android.material.button.MaterialButton
1920
import com.google.android.material.switchmaterial.SwitchMaterial
2021
import timber.log.Timber
2122
import java.util.*
@@ -41,6 +42,8 @@ class MainActivity : AppCompatActivity() {
4142

4243
setOwner(getPhoneNumber(this))
4344
setActiveStatus(this)
45+
registerListeners()
46+
refreshToken()
4447
}
4548

4649
override fun onResume() {
@@ -49,12 +52,26 @@ class MainActivity : AppCompatActivity() {
4952
redirectToLogin()
5053
}
5154

55+
private fun refreshToken() {
56+
57+
}
58+
5259
private fun initTimber() {
5360
if (BuildConfig.DEBUG) {
5461
Timber.plant(Timber.DebugTree())
5562
}
5663
}
5764

65+
private fun registerListeners() {
66+
findViewById<MaterialButton>(R.id.mainLogoutButton).setOnClickListener { onLogoutClick() }
67+
}
68+
69+
private fun onLogoutClick() {
70+
Timber.d("logout button clicked")
71+
Settings.setApiKeyAsync(this, null)
72+
redirectToLogin()
73+
}
74+
5875
private fun redirectToLogin() {
5976
if (Settings.isLoggedIn(this)) {
6077
return

android/app/src/main/java/com/httpsms/Settings.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ object Settings {
8080
return getApiKey(context) ?: ""
8181
}
8282

83-
fun setApiKeyAsync(context: Context, apiKey: String) {
83+
fun setApiKeyAsync(context: Context, apiKey: String?) {
8484
Timber.d(Settings::setApiKeyAsync.name)
8585

8686
PreferenceManager.getDefaultSharedPreferences(context)

android/app/src/main/res/layout/activity_login.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
android:indeterminate="true"
9393
android:layout_marginTop="4dp"
9494
app:indicatorColor="@color/pink_500"
95-
app:layout_constraintTop_toBottomOf="@+id/button"
95+
app:layout_constraintTop_toBottomOf="@+id/loginButton"
9696
tools:layout_editor_absoluteX="16dp" />
9797
</LinearLayout>
9898

android/app/src/main/res/layout/activity_main.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
</LinearLayout>
8181

8282
<com.google.android.material.button.MaterialButton
83+
android:id="@+id/mainLogoutButton"
8384
style="@style/Widget.MaterialComponents.Button.Icon"
8485
android:layout_width="wrap_content"
8586
android:layout_height="wrap_content"

0 commit comments

Comments
 (0)