Skip to content

Send and receive SMS messages using your Android phone programmatically via a simple HTTP API

Create settings view

Acho Arnold5c3b7aa29562
diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index 895b5306..9e0586ef 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -39,6 +39,8 @@
</activity>
<activity android:name=".LoginActivity" android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity" />
+ <activity android:name=".SettingsActivity" android:screenOrientation="portrait"
+ tools:ignore="LockedOrientationActivity" />
<service
android:name=".services.StickyNotificationService"
diff --git a/android/app/src/main/java/com/httpsms/MainActivity.kt b/android/app/src/main/java/com/httpsms/MainActivity.kt
index b59ff160..4c74fb83 100644
--- a/android/app/src/main/java/com/httpsms/MainActivity.kt
+++ b/android/app/src/main/java/com/httpsms/MainActivity.kt
@@ -183,26 +183,16 @@ class MainActivity : AppCompatActivity() {
}
private fun registerListeners() {
- findViewById<MaterialButton>(R.id.mainLogoutButton).setOnClickListener { onLogoutClick() }
+ findViewById<MaterialButton>(R.id.mainSettingsButton).setOnClickListener { onSettingsClick() }
}
private fun registerReceivers() {
registerReceiver(SimChangeReceiver(), IntentFilter("android.intent.action.SIM_STATE_CHANGED"))
}
- private fun onLogoutClick() {
- Timber.d("logout button clicked")
- MaterialAlertDialogBuilder(this)
- .setTitle("Confirm")
- .setMessage("Are you sure you want to logout of the Http SMS App?")
- .setNeutralButton("Cancel"){ _, _ -> Timber.d("logout dialog canceled") }
- .setPositiveButton("Logout"){_, _ ->
- Timber.d("logging out user")
- Settings.setApiKeyAsync(this, null)
- Settings.setOwnerAsync(this, null)
- Settings.setFcmTokenLastUpdateTimestampAsync(this, 0)
- redirectToLogin()
- }
- .show()
+ private fun onSettingsClick() {
+ Timber.d("settings button clicked")
+ val switchActivityIntent = Intent(this, SettingsActivity::class.java)
+ startActivity(switchActivityIntent)
}
private fun redirectToLogin():Boolean {
diff --git a/android/app/src/main/java/com/httpsms/SettingsActivity.kt b/android/app/src/main/java/com/httpsms/SettingsActivity.kt
new file mode 100644
index 00000000..c57dc079
--- /dev/null
+++ b/android/app/src/main/java/com/httpsms/SettingsActivity.kt
@@ -0,0 +1,63 @@
+package com.httpsms
+
+import android.content.Intent
+import android.os.Bundle
+import androidx.appcompat.app.AppCompatActivity
+import androidx.appcompat.widget.Toolbar
+import com.google.android.material.appbar.MaterialToolbar
+import com.google.android.material.button.MaterialButton
+import com.google.android.material.dialog.MaterialAlertDialogBuilder
+import timber.log.Timber
+
+class SettingsActivity : AppCompatActivity() {
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_settings)
+ registerListeners()
+ }
+
+ private fun registerListeners() {
+ appToolbar().setOnClickListener { onBackClicked() }
+ }
+
+ private fun onBackClicked() {
+ Timber.e("back button clicked")
+ redirectToMain()
+ }
+
+
+ private fun redirectToMain() {
+ finish()
+ val switchActivityIntent = Intent(this, MainActivity::class.java)
+ startActivity(switchActivityIntent)
+ }
+
+ private fun appToolbar(): MaterialToolbar {
+ return findViewById(R.id.settings_toolbar)
+ }
+
+ private fun onLogoutClick() {
+ Timber.d("logout button clicked")
+ MaterialAlertDialogBuilder(this)
+ .setTitle("Confirm")
+ .setMessage("Are you sure you want to logout of the Http SMS App?")
+ .setNeutralButton("Cancel"){ _, _ -> Timber.d("logout dialog canceled") }
+ .setPositiveButton("Logout"){_, _ ->
+ Timber.d("logging out user")
+ Settings.setApiKeyAsync(this, null)
+ Settings.setOwnerAsync(this, null)
+ Settings.setFcmTokenLastUpdateTimestampAsync(this, 0)
+ redirectToLogin()
+ }
+ .show()
+ }
+
+ private fun redirectToLogin():Boolean {
+ if (Settings.isLoggedIn(this)) {
+ return false
+ }
+ val switchActivityIntent = Intent(this, LoginActivity::class.java)
+ startActivity(switchActivityIntent)
+ return true
+ }
+}
diff --git a/android/app/src/main/res/drawable/baseline_settings_24.xml b/android/app/src/main/res/drawable/baseline_settings_24.xml
new file mode 100644
index 00000000..b240b830
--- /dev/null
+++ b/android/app/src/main/res/drawable/baseline_settings_24.xml
@@ -0,0 +1,5 @@
+<vector android:height="24dp" android:tint="#FFFFFF"
+ android:viewportHeight="24" android:viewportWidth="24"
+ android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
+ <path android:fillColor="@android:color/white" android:pathData="M19.14,12.94c0.04,-0.3 0.06,-0.61 0.06,-0.94c0,-0.32 -0.02,-0.64 -0.07,-0.94l2.03,-1.58c0.18,-0.14 0.23,-0.41 0.12,-0.61l-1.92,-3.32c-0.12,-0.22 -0.37,-0.29 -0.59,-0.22l-2.39,0.96c-0.5,-0.38 -1.03,-0.7 -1.62,-0.94L14.4,2.81c-0.04,-0.24 -0.24,-0.41 -0.48,-0.41h-3.84c-0.24,0 -0.43,0.17 -0.47,0.41L9.25,5.35C8.66,5.59 8.12,5.92 7.63,6.29L5.24,5.33c-0.22,-0.08 -0.47,0 -0.59,0.22L2.74,8.87C2.62,9.08 2.66,9.34 2.86,9.48l2.03,1.58C4.84,11.36 4.8,11.69 4.8,12s0.02,0.64 0.07,0.94l-2.03,1.58c-0.18,0.14 -0.23,0.41 -0.12,0.61l1.92,3.32c0.12,0.22 0.37,0.29 0.59,0.22l2.39,-0.96c0.5,0.38 1.03,0.7 1.62,0.94l0.36,2.54c0.05,0.24 0.24,0.41 0.48,0.41h3.84c0.24,0 0.44,-0.17 0.47,-0.41l0.36,-2.54c0.59,-0.24 1.13,-0.56 1.62,-0.94l2.39,0.96c0.22,0.08 0.47,0 0.59,-0.22l1.92,-3.32c0.12,-0.22 0.07,-0.47 -0.12,-0.61L19.14,12.94zM12,15.6c-1.98,0 -3.6,-1.62 -3.6,-3.6s1.62,-3.6 3.6,-3.6s3.6,1.62 3.6,3.6S13.98,15.6 12,15.6z"/>
+</vector>
diff --git a/android/app/src/main/res/layout/activity_main.xml b/android/app/src/main/res/layout/activity_main.xml
index 5b393e7e..cdae886a 100644
--- a/android/app/src/main/res/layout/activity_main.xml
+++ b/android/app/src/main/res/layout/activity_main.xml
@@ -149,7 +149,7 @@
</LinearLayout>
<com.google.android.material.button.MaterialButton
- android:id="@+id/mainLogoutButton"
+ android:id="@+id/mainSettingsButton"
style="@style/Widget.MaterialComponents.Button.Icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@@ -157,10 +157,10 @@
android:backgroundTint="@color/black"
android:drawableTint="@color/white"
android:padding="10dp"
- android:text="@string/main_log_out"
+ android:text="@string/main_app_settings"
android:textColor="@color/white"
android:textSize="16sp"
- app:icon="@drawable/ic_login"
+ app:icon="@drawable/baseline_settings_24"
app:iconTint="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
diff --git a/android/app/src/main/res/layout/activity_settings.xml b/android/app/src/main/res/layout/activity_settings.xml
new file mode 100644
index 00000000..6dcb96f6
--- /dev/null
+++ b/android/app/src/main/res/layout/activity_settings.xml
@@ -0,0 +1,48 @@
+<?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"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <com.google.android.material.appbar.AppBarLayout
+ android:id="@+id/settings_app_bar_layout"
+ android:layout_width="match_parent"
+ android:layout_height="?attr/actionBarSize"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toTopOf="parent">
+
+ <com.google.android.material.appbar.MaterialToolbar
+ android:id="@+id/settings_toolbar"
+ style="@style/Widget.MaterialComponents.Toolbar.Primary"
+ android:layout_width="match_parent"
+ android:layout_height="?attr/actionBarSize"
+ android:layout_marginBottom="676dp"
+ android:background="@color/black"
+ app:layout_constraintTop_toTopOf="parent"
+ app:layout_constraintHorizontal_bias="0.0"
+ app:layout_constraintLeft_toLeftOf="parent"
+ app:layout_constraintRight_toRightOf="parent"
+ app:navigationIcon="?attr/homeAsUpIndicator"
+ app:title="App Settings" />
+ </com.google.android.material.appbar.AppBarLayout>
+
+ <com.google.android.material.button.MaterialButton
+ android:id="@+id/settingsLogoutButton"
+ style="@style/Widget.MaterialComponents.Button.Icon"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginBottom="16dp"
+ android:backgroundTint="@color/black"
+ android:drawableTint="@color/white"
+ android:padding="10dp"
+ android:text="@string/main_log_out"
+ android:textColor="@color/white"
+ android:textSize="16sp"
+ app:icon="@drawable/ic_login"
+ app:iconTint="@color/white"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ tools:ignore="TextContrastCheck" />
+</androidx.constraintlayout.widget.ConstraintLayout>
diff --git a/android/app/src/main/res/values-night/themes.xml b/android/app/src/main/res/values-night/themes.xml
index e717addb..ab0774cd 100644
--- a/android/app/src/main/res/values-night/themes.xml
+++ b/android/app/src/main/res/values-night/themes.xml
@@ -10,7 +10,7 @@
<item name="colorSecondaryVariant">@color/pink_A400</item>
<item name="colorOnSecondary">@color/white</item>
<!-- Status bar color. -->
- <item name="android:statusBarColor" tools:targetApi="l">#121212</item>
+ <item name="android:statusBarColor">#121212</item>
<!-- Customize your theme here. -->
</style>
</resources>
diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml
index 42bb9a2f..3a255d3e 100644
--- a/android/app/src/main/res/values/strings.xml
+++ b/android/app/src/main/res/values/strings.xml
@@ -17,4 +17,5 @@
<string name="default_server_url">https://api.httpsms.com</string>
<string name="app_version">httpsms.com - %s</string>
<string name="disable_battery_optimization">Disable Battery Optimization</string>
+ <string name="main_app_settings">App Settings</string>
</resources>
diff --git a/android/app/src/main/res/values/themes.xml b/android/app/src/main/res/values/themes.xml
index 69dc47c9..75429247 100644
--- a/android/app/src/main/res/values/themes.xml
+++ b/android/app/src/main/res/values/themes.xml
@@ -10,7 +10,7 @@
<item name="colorSecondaryVariant">@color/pink_A400</item>
<item name="colorOnSecondary">@color/white</item>
<!-- Status bar color. -->
- <item name="android:statusBarColor" tools:targetApi="l">#121212</item>
+ <item name="android:statusBarColor">#121212</item>
<!-- Customize your theme here. -->
</style>
diff --git a/android/build.gradle b/android/build.gradle
index a6c7e3f2..32e3cd73 100644
--- a/android/build.gradle
+++ b/android/build.gradle
@@ -12,8 +12,8 @@ buildscript {
}
plugins {
- id 'com.android.application' version '8.0.1' apply false
- id 'com.android.library' version '8.0.1' apply false
+ id 'com.android.application' version '8.0.2' apply false
+ id 'com.android.library' version '8.0.2' apply false
id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
}