Skip to content

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

feat(android): migrate XML layouts to Jetpack Compose (#943)

Acho Arnolda6ac39319d98
diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts
index 15857e70..f670b8bb 100644
--- a/android/app/build.gradle.kts
+++ b/android/app/build.gradle.kts
@@ -1,7 +1,8 @@
plugins {
id("com.android.application")
id("com.google.gms.google-services")
- id("io.sentry.android.gradle") version "6.2.0"
+ id("io.sentry.android.gradle") version "6.14.0"
+ id("org.jetbrains.kotlin.plugin.compose")
}
val gitHash = providers.exec {
@@ -9,12 +10,12 @@ val gitHash = providers.exec {
}.standardOutput.asText.map { it.trim() }
android {
- compileSdk = 36
+ compileSdk = 37
defaultConfig {
applicationId = "com.httpsms"
minSdk = 28
- targetSdk = 36
+ targetSdk = 37
versionCode = 1
versionName = gitHash.getOrElse("unknown")
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
@@ -38,26 +39,39 @@ android {
buildFeatures {
buildConfig = true
+ compose = true
}
}
dependencies {
- implementation(platform("com.google.firebase:firebase-bom:34.11.0"))
+ val composeBom = platform("androidx.compose:compose-bom:2026.06.01")
+ implementation(composeBom)
+ androidTestImplementation(composeBom)
+
+ implementation("androidx.compose.ui:ui")
+ implementation("androidx.compose.ui:ui-graphics")
+ implementation("androidx.compose.ui:ui-tooling-preview")
+ implementation("androidx.compose.material3:material3")
+ implementation("androidx.compose.material:material-icons-extended")
+ implementation("androidx.activity:activity-compose:1.13.0")
+ implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.11.0")
+
+ implementation(platform("com.google.firebase:firebase-bom:34.16.0"))
implementation("com.journeyapps:zxing-android-embedded:4.3.0")
implementation("com.google.firebase:firebase-analytics")
implementation("com.google.firebase:firebase-messaging")
- implementation("com.squareup.okhttp3:okhttp:5.3.2")
+ implementation("com.squareup.okhttp3:okhttp:5.4.0")
implementation("com.jakewharton.timber:timber:5.0.1")
implementation("androidx.preference:preference-ktx:1.2.1")
- implementation("androidx.work:work-runtime-ktx:2.11.1")
- implementation("androidx.core:core-ktx:1.18.0")
+ implementation("androidx.work:work-runtime-ktx:2.11.2")
+ implementation("androidx.core:core-ktx:1.19.0")
implementation("androidx.cardview:cardview:1.0.0")
implementation("com.beust:klaxon:5.6")
implementation("androidx.appcompat:appcompat:1.7.1")
implementation("org.apache.commons:commons-text:1.15.0")
- implementation("com.google.android.material:material:1.13.0")
+ implementation("com.google.android.material:material:1.14.0")
implementation("androidx.constraintlayout:constraintlayout:2.2.1")
- implementation("com.googlecode.libphonenumber:libphonenumber:9.0.26")
+ implementation("com.googlecode.libphonenumber:libphonenumber:9.0.34")
implementation("com.klinkerapps:android-smsmms:5.2.6")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.3.0")
diff --git a/android/app/src/main/java/com/httpsms/LoginActivity.kt b/android/app/src/main/java/com/httpsms/LoginActivity.kt
index babe12df..17bd6db6 100644
--- a/android/app/src/main/java/com/httpsms/LoginActivity.kt
+++ b/android/app/src/main/java/com/httpsms/LoginActivity.kt
@@ -8,56 +8,75 @@ import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import android.telephony.TelephonyManager
-import android.view.View
-import android.webkit.URLUtil
-import android.widget.LinearLayout
import android.widget.Toast
+import androidx.activity.compose.setContent
import androidx.activity.result.contract.ActivityResultContracts
+import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
+import androidx.compose.runtime.LaunchedEffect
+import androidx.compose.runtime.collectAsState
+import androidx.compose.runtime.getValue
import androidx.core.app.ActivityCompat
-import androidx.lifecycle.MutableLiveData
import com.google.android.gms.common.ConnectionResult
import com.google.android.gms.common.GoogleApiAvailability
-import com.google.android.material.button.MaterialButton
-import com.google.android.material.progressindicator.LinearProgressIndicator
-import com.google.android.material.textfield.TextInputEditText
-import com.google.android.material.textfield.TextInputLayout
-import com.httpsms.validators.PhoneNumberValidator
+import com.httpsms.ui.login.LoginScreen
+import com.httpsms.ui.login.LoginViewModel
+import com.httpsms.ui.theme.HttpSmsTheme
import com.journeyapps.barcodescanner.ScanContract
import com.journeyapps.barcodescanner.ScanOptions
import timber.log.Timber
-import java.net.URI
-
class LoginActivity : AppCompatActivity() {
+ private val viewModel: LoginViewModel by viewModels()
+
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
redirectToMain()
- setContentView(R.layout.activity_login)
- registerListeners()
- setPhoneNumber()
- disableSim2()
- setServerURL()
- setupApiKeyInput()
- }
-
- private fun setupApiKeyInput() {
- val apiKeyInputLayout = findViewById<TextInputLayout>(R.id.loginApiKeyTextInputLayout)
- val apiKeyInput = findViewById<TextInputEditText>(R.id.loginApiKeyTextInput)
-
- apiKeyInput.setOnClickListener {
- startQrCodeScan()
- }
+
+ viewModel.initialize(this, getString(R.string.default_server_url))
+
+ setContent {
+ HttpSmsTheme {
+ val uiState by viewModel.uiState.collectAsState()
+
+ LaunchedEffect(uiState.loginSuccess) {
+ if (uiState.loginSuccess) {
+ redirectToMain()
+ }
+ }
- apiKeyInputLayout.setEndIconOnClickListener {
- startQrCodeScan()
+ LoginScreen(
+ viewModel = viewModel,
+ onQrScanClick = { startQrCodeScan() },
+ onLoginClick = {
+ val error = isGooglePlayServicesAvailable()
+ if (error != null) {
+ Toast.makeText(this@LoginActivity, error, Toast.LENGTH_SHORT).show()
+ } else {
+ viewModel.login(
+ context = this@LoginActivity,
+ countryCode = getCountryCode(),
+ onGooglePlayServicesError = {
+ Toast.makeText(this@LoginActivity, it, Toast.LENGTH_SHORT).show()
+ },
+ onFcmTokenMissing = {
+ Toast.makeText(
+ this@LoginActivity,
+ "Cannot find FCM token. Make sure you have Google Play Services installed",
+ Toast.LENGTH_LONG
+ ).show()
+ }
+ )
+ }
+ }
+ )
+ }
}
}
private val barcodeLauncher = registerForActivityResult(ScanContract()) { result ->
if (result.contents != null) {
- val apiKeyInput = findViewById<TextInputEditText>(R.id.loginApiKeyTextInput)
- apiKeyInput.setText(result.contents)
+ viewModel.onApiKeyChange(result.contents)
Toast.makeText(this, "Scanned: ${result.contents}", Toast.LENGTH_LONG).show()
} else {
Toast.makeText(this, "Scan cancelled", Toast.LENGTH_SHORT).show()
@@ -79,46 +98,6 @@ class LoginActivity : AppCompatActivity() {
requestPermissions()
}
- override fun onResume() {
- super.onResume()
- setPhoneNumber()
- disableSim2()
- }
-
- private fun registerListeners() {
- loginButton().setOnClickListener { onLoginClick() }
- }
-
- private fun disableSim2() {
- if (SmsManagerService.isDualSIM(this)) {
- Timber.d("dual sim detected")
- val sim2Layout = findViewById<LinearLayout>(R.id.loginPhoneNumberLayoutSIM2)
- sim2Layout.visibility = LinearLayout.VISIBLE
- return
- }
- Timber.d("single sim detected")
- val sim2Layout = findViewById<LinearLayout>(R.id.loginPhoneNumberLayoutSIM2)
- sim2Layout.visibility = View.GONE
- }
-
- private fun setPhoneNumber() {
- val phoneNumber = getPhoneNumber(this)
- if(phoneNumber == null) {
- Timber.d("cannot get phone due to no permissions")
- return
- }
-
- val phoneInput = findViewById<TextInputEditText>(R.id.loginPhoneNumberInputSIM1)
- phoneInput.setText(phoneNumber)
- Timber.d("[SIM1] phone number [$phoneNumber] set successfully")
- }
-
- private fun setServerURL() {
- val serverUrlInput = findViewById<TextInputEditText>(R.id.loginServerUrlInput)
- serverUrlInput.setText(getString(R.string.default_server_url))
- Timber.d("default server url [${serverUrlInput.text.toString()}] set successfully")
- }
-
@SuppressLint("HardwareIds")
@Suppress("DEPRECATION")
private fun getPhoneNumber(context: Context): String? {
@@ -139,13 +118,16 @@ class LoginActivity : AppCompatActivity() {
return telephonyManager.line1Number
}
+ private val requestPermissionLauncher = registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { permissions ->
+ permissions.entries.forEach {
+ Timber.d("${it.key} = ${it.value}")
+ }
+ // Try to auto-detect phone numbers after permissions are granted
+ viewModel.autoDetectPhoneNumbers(this)
+ }
+
private fun requestPermissions() {
Timber.d("requesting permissions")
- val requestPermissionLauncher = registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { permissions ->
- permissions.entries.forEach {
- Timber.d("${it.key} = ${it.value}")
- }
- }
var permissions = arrayOf(
Manifest.permission.SEND_SMS,
@@ -175,169 +157,19 @@ class LoginActivity : AppCompatActivity() {
return null
}
-
- private fun onLoginClick() {
- Timber.d("login button clicked")
-
- val error = isGooglePlayServicesAvailable()
- if (error != null) {
- Timber.d("google play services not installed [${error}]")
- Toast.makeText(this, error, Toast.LENGTH_SHORT).show()
- return
- }
-
- if (Settings.getFcmToken(this) == null) {
- Timber.d("The FCM token is not set")
- Toast.makeText(this, "Cannot find FCM token. Make sure you have Google Play Services installed", Toast.LENGTH_LONG).show()
- return
- }
-
- loginButton().isEnabled = false
- val progressBar = findViewById<LinearProgressIndicator>(R.id.loginProgressIndicator)
- progressBar.visibility = View.VISIBLE
-
- val apiKeyLayout = findViewById<TextInputLayout>(R.id.loginApiKeyTextInputLayout)
- apiKeyLayout.error = null
-
- val apiKey = findViewById<TextInputEditText>(R.id.loginApiKeyTextInput)
- apiKey.isEnabled = false
-
- val serverUrlLayout = findViewById<TextInputLayout>(R.id.loginServerUrlLayout)
- serverUrlLayout.error = null
-
- val serverUrl = findViewById<TextInputEditText>(R.id.loginServerUrlInput)
- serverUrl.isEnabled = false
-
- val phoneNumberLayout = findViewById<TextInputLayout>(R.id.loginPhoneNumberLayoutSIM1)
- phoneNumberLayout.error = null
-
- val phoneNumber = findViewById<TextInputEditText>(R.id.loginPhoneNumberInputSIM1)
- phoneNumber.isEnabled = false
-
- val phoneNumberLayoutSIM2 = findViewById<TextInputLayout>(R.id.loginPhoneNumberLayoutSIM2)
- phoneNumberLayoutSIM2.error = null
-
- val phoneNumberSIM2 = findViewById<TextInputEditText>(R.id.loginPhoneNumberInputSIM2)
- phoneNumberSIM2.isEnabled = false
-
- val countryCode = getCountryCode()
-
- val resetView = fun () {
- apiKey.isEnabled = true
- serverUrl.isEnabled = true
- progressBar.visibility = View.INVISIBLE
- phoneNumber.isEnabled = true
- phoneNumberSIM2.isEnabled = true
- loginButton().isEnabled = true
- }
-
- if (!PhoneNumberValidator.isValidPhoneNumber(phoneNumber.text.toString().trim(), countryCode)) {
- Timber.e("[SIM1] phone number [${phoneNumber.text.toString()}] is not valid")
- resetView()
- phoneNumberLayout.error = "Enter an international phone number in the E.164 format"
- return
- }
-
- if (SmsManagerService.isDualSIM(this) && !PhoneNumberValidator.isValidPhoneNumber(phoneNumberSIM2.text.toString().trim(), countryCode)) {
- Timber.e("[SIM2] phone number [${phoneNumberSIM2.text.toString()}] is not valid")
- resetView()
- phoneNumberLayoutSIM2.error = "Enter an international phone number in the E.164 format"
- return
- }
-
- if(!URLUtil.isValidUrl(serverUrl.text.toString().trim())) {
- Timber.e("url number [${serverUrl.text.toString()}] is not a valid URL")
- resetView()
- serverUrlLayout.error = "Server URL [${serverUrl.text.toString()}] is invalid"
- return
- }
-
- if (!URLUtil.isHttpsUrl(serverUrl.text.toString().trim())) {
- Timber.e("url number [${serverUrl.text.toString()}] is not an https URL")
- resetView()
- serverUrlLayout.error = "Server URL [${serverUrl.text.toString()}] must be HTTPS"
- return
- }
-
- val liveData = MutableLiveData<Pair<String?, String?>>()
- liveData.observe(this) { authResult ->
- run {
- progressBar.visibility = View.INVISIBLE
- if (authResult.first != null) {
- resetView()
- apiKeyLayout.error = authResult.first
- return@run
- }
-
- if (authResult.second != null) {
- resetView()
- serverUrlLayout.error = authResult.second
- return@run
- }
-
- Settings.setApiKeyAsync(this, apiKey.text.toString())
- Settings.setServerUrlAsync(this, serverUrl.text.toString().trim())
-
- val e164PhoneNumber = PhoneNumberValidator.formatE164(phoneNumber.text.toString().trim(), countryCode)
- Settings.setSIM1PhoneNumber(this, e164PhoneNumber)
-
- if(SmsManagerService.isDualSIM(this)) {
- val sim2PhoneNumber = PhoneNumberValidator.formatE164(phoneNumberSIM2.text.toString().trim(), countryCode)
- Settings.setSIM2PhoneNumber(this, sim2PhoneNumber)
- }
-
- Timber.d("login successfully redirecting to main view")
- redirectToMain()
- }
- }
-
- Thread {
- val service = HttpSmsApiService(apiKey.text.toString(), URI(serverUrl.text.toString().trim()))
-
- var e164PhoneNumber = PhoneNumberValidator.formatE164(phoneNumber.text.toString().trim(), countryCode)
- var response = service.updateFcmToken(e164PhoneNumber, Constants.SIM1, Settings.getFcmToken(this) ?: "")
- if(response.second != null || response.third != null) {
- Timber.e("error updating fcm token [${response.second}], third [${response.third}]")
- liveData.postValue(Pair(response.second, response.third))
- return@Thread
- }
-
- if (!SmsManagerService.isDualSIM(this)) {
- Timber.d("single sim detected, no need to update sim2")
- liveData.postValue(Pair(null, null))
- return@Thread
- }
-
- e164PhoneNumber = PhoneNumberValidator.formatE164(phoneNumberSIM2.text.toString().trim(), countryCode)
- response = service.updateFcmToken(e164PhoneNumber, Constants.SIM2, Settings.getFcmToken(this) ?: "")
-
- liveData.postValue(Pair(response.second, response.third))
- Timber.d("finished validating api URL")
- }.start()
- }
-
private fun redirectToMain() {
if (!Settings.isLoggedIn(this)) {
return
}
- finish()
+ finish()
val switchActivityIntent = Intent(this, MainActivity::class.java)
startActivity(switchActivityIntent)
}
- private fun loginButton(): MaterialButton {
- return findViewById(R.id.loginButton)
- }
-
private fun getCountryCode() : String {
- // Get the TelephonyManager from the system services
val tm = this.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
-
- // Get the network country ISO code and convert it to uppercase
val code = tm.networkCountryIso.uppercase()
-
- // If the country code is empty, retrieve the country code from the device's locale
if (code.isEmpty()) {
return this.resources.configuration.locales.get(0).country.uppercase()
}
diff --git a/android/app/src/main/java/com/httpsms/MainActivity.kt b/android/app/src/main/java/com/httpsms/MainActivity.kt
index 363e7c19..ff7587db 100644
--- a/android/app/src/main/java/com/httpsms/MainActivity.kt
+++ b/android/app/src/main/java/com/httpsms/MainActivity.kt
@@ -10,37 +10,29 @@ import android.content.pm.PackageManager
import android.net.Uri
import android.os.Build
import android.os.Bundle
-import android.os.PowerManager
-import android.telephony.PhoneNumberUtils
-import android.view.View
-import android.widget.LinearLayout
-import android.widget.TextView
+import android.provider.Settings as ProviderSettings
import android.widget.Toast
+import androidx.activity.compose.setContent
import androidx.activity.result.contract.ActivityResultContracts
+import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
-import androidx.lifecycle.MutableLiveData
import androidx.work.Constraints
import androidx.work.ExistingPeriodicWorkPolicy
import androidx.work.NetworkType
import androidx.work.PeriodicWorkRequestBuilder
import androidx.work.WorkManager
-import com.google.android.material.button.MaterialButton
-import com.google.android.material.card.MaterialCardView
-import com.google.android.material.progressindicator.LinearProgressIndicator
import com.httpsms.services.StickyNotificationService
+import com.httpsms.ui.main.MainScreen
+import com.httpsms.ui.main.MainViewModel
+import com.httpsms.ui.theme.HttpSmsTheme
import com.httpsms.worker.HeartbeatWorker
import timber.log.Timber
-import java.time.Instant
-import java.time.ZoneId
-import java.time.ZoneOffset
-import java.time.ZonedDateTime
-import java.time.format.DateTimeFormatter
-import java.util.*
import java.util.concurrent.TimeUnit
-import android.provider.Settings as ProviderSettings
class MainActivity : AppCompatActivity() {
+ private val viewModel: MainViewModel by viewModels()
+
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@@ -48,20 +40,42 @@ class MainActivity : AppCompatActivity() {
redirectToLogin()
- setContentView(R.layout.activity_main)
+ viewModel.initialize(this, getString(R.string.app_version, BuildConfig.VERSION_NAME))
+
+ setContent {
+ HttpSmsTheme {
+ MainScreen(
+ viewModel = viewModel,
+ onSettingsClick = { onSettingsClick() },
+ onSmsPermissionClick = {
+ val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https://httpsms.com/blog/grant-send-and-read-sms-permissions-on-android"))
+ startActivity(intent)
+ },
+ onBatteryOptimizationClick = {
+ val intent = Intent()
+ intent.action = ProviderSettings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
+ intent.data = Uri.parse("package:$packageName")
+ startActivity(intent)
+ },
+ onHeartbeatClick = {
+ viewModel.sendHeartbeat(this) { error ->
+ if (error != null) {
+ Timber.w("heartbeat sending failed with [$error]")
+ Toast.makeText(this, error, Toast.LENGTH_LONG).show()
+ } else {
+ Toast.makeText(this, "Heartbeat sent successfully", Toast.LENGTH_SHORT).show()
+ }
+ }
+ }
+ )
+ }
+ }
createChannel()
-
- setCardContent(this)
- registerListeners()
refreshToken(this)
startStickyNotification(this)
scheduleHeartbeatWorker(this)
- setVersion()
- setHeartbeatListener(this)
- setSmsPermissionListener()
- setBatteryOptimizationListener()
}
override fun onStart() {
@@ -74,35 +88,7 @@ class MainActivity : AppCompatActivity() {
Timber.d( "on activity resume")
redirectToLogin()
refreshToken(this)
- setCardContent(this)
- setSmsPermissionListener()
- setBatteryOptimizationListener()
- }
-
- private fun setVersion() {
- val appVersionView = findViewById<TextView>(R.id.mainAppVersion)
- appVersionView.text = getString(R.string.app_version, BuildConfig.VERSION_NAME)
- }
-
- private fun setCardContent(context: Context) {
- val titleText = findViewById<TextView>(R.id.cardPhoneNumber)
- titleText.text = PhoneNumberUtils.formatNumber(Settings.getSIM1PhoneNumber(this), Locale.getDefault().country)
- if(!Settings.getActiveStatus(context, Constants.SIM1)) {
- titleText.setCompoundDrawables(null, null, null, null)
- }
-
- val titleTextSIM2 = findViewById<TextView>(R.id.cardPhoneNumberSIM2)
- titleTextSIM2.text = PhoneNumberUtils.formatNumber(Settings.getSIM2PhoneNumber(this), Locale.getDefault().country)
- if(!Settings.getActiveStatus(context, Constants.SIM2)) {
- titleTextSIM2.setCompoundDrawables(null, null, null, null)
- }
-
- setLastHeartbeatTimestamp(context)
-
- if(!Settings.isDualSIM(context)) {
- val sim2Card = findViewById<MaterialCardView>(R.id.mainPhoneCardSIM2)
- sim2Card.visibility = MaterialCardView.GONE
- }
+ viewModel.updateState(this, getString(R.string.app_version, BuildConfig.VERSION_NAME))
}
private fun requestPermissions(context:Context) {
@@ -116,7 +102,7 @@ class MainActivity : AppCompatActivity() {
Settings.setIncomingCallEventsEnabled(context, Constants.SIM2, false)
}
}
- setSmsPermissionListener()
+ viewModel.updateState(context, getString(R.string.app_version, BuildConfig.VERSION_NAME))
}
var permissions = arrayOf(
@@ -229,10 +215,6 @@ class MainActivity : AppCompatActivity() {
}
}
- private fun registerListeners() {
- findViewById<MaterialButton>(R.id.mainSettingsButton).setOnClickListener { onSettingsClick() }
- }
-
private fun onSettingsClick() {
Timber.d("settings button clicked")
val switchActivityIntent = Intent(this, SettingsActivity::class.java)
@@ -248,28 +230,6 @@ class MainActivity : AppCompatActivity() {
return true
}
- private fun setLastHeartbeatTimestamp(context: Context) {
- val refreshTimestampView = findViewById<TextView>(R.id.cardRefreshTime)
- val timestamp = Settings.getHeartbeatTimestamp(context)
-
- if (timestamp == 0.toLong()) {
- Timber.d("no heartbeat timestamp has been set")
- refreshTimestampView.text = "--"
- return
- }
-
- val timestampZdt = ZonedDateTime.ofInstant(Instant.ofEpochMilli(timestamp), ZoneOffset.UTC)
- val localTime = timestampZdt.withZoneSameInstant(ZoneId.systemDefault())
- Timber.d("heartbeat timestamp in UTC is [${timestampZdt}] and local is [$localTime]")
-
- refreshTimestampView.text = localTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
-
- if (Settings.isDualSIM(context)) {
- val refreshTimestampViewSIM2 = findViewById<TextView>(R.id.cardRefreshTimeSIM2)
- refreshTimestampViewSIM2.text = localTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
- }
- }
-
private fun createChannel() {
// Create the NotificationChannel
val name = getString(R.string.notification_channel_default)
@@ -282,109 +242,4 @@ class MainActivity : AppCompatActivity() {
val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
notificationManager.createNotificationChannel(mChannel)
}
-
- @SuppressLint("BatteryLife")
- private fun setBatteryOptimizationListener() {
- val pm = getSystemService(POWER_SERVICE) as PowerManager
- val button = findViewById<MaterialButton>(R.id.batteryOptimizationButtonButton)
- if (!pm.isIgnoringBatteryOptimizations(packageName)) {
- button.visibility = View.VISIBLE
- button.setOnClickListener {
- val intent = Intent()
- intent.action = ProviderSettings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
- intent.data = Uri.parse("package:$packageName")
- startActivity(intent)
- }
- } else {
- button.visibility = View.GONE
- }
- updatePermissionLayoutVisibility()
- }
-
- private fun setSmsPermissionListener() {
- val smsPermissions = arrayOf(
- Manifest.permission.SEND_SMS,
- Manifest.permission.RECEIVE_SMS,
- Manifest.permission.READ_SMS
- )
- val allGranted = smsPermissions.all {
- checkSelfPermission(it) == PackageManager.PERMISSION_GRANTED
- }
-
- val button = findViewById<MaterialButton>(R.id.smsPermissionButton)
- if (!allGranted) {
- button.visibility = View.VISIBLE
- button.setOnClickListener {
- val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https://httpsms.com/blog/grant-send-and-read-sms-permissions-on-android"))
- startActivity(intent)
- }
- } else {
- button.visibility = View.GONE
- }
- updatePermissionLayoutVisibility()
- }
-
- private fun updatePermissionLayoutVisibility() {
- val smsButton = findViewById<MaterialButton>(R.id.smsPermissionButton)
- val batteryButton = findViewById<MaterialButton>(R.id.batteryOptimizationButtonButton)
- val layout = findViewById<LinearLayout>(R.id.batteryOptimizationLinearLayout)
-
- if (smsButton.visibility == View.GONE && batteryButton.visibility == View.GONE) {
- layout.visibility = View.GONE
- } else {
- layout.visibility = View.VISIBLE
- }
- }
-
- private fun setHeartbeatListener(context: Context) {
- findViewById<MaterialButton>(R.id.mainHeartbeatButton).setOnClickListener{onHeartbeatClick(context)}
- }
-
- private fun onHeartbeatClick(context: Context) {
- Timber.d("heartbeat button clicked")
- val heartbeatButton = findViewById<MaterialButton>(R.id.mainHeartbeatButton)
- heartbeatButton.isEnabled = false
-
- val progressBar = findViewById<LinearProgressIndicator>(R.id.mainProgressIndicator)
- progressBar.visibility = View.VISIBLE
-
- val liveData = MutableLiveData<String?>()
- liveData.observe(this) { exception ->
- run {
- progressBar.visibility = View.INVISIBLE
- heartbeatButton.isEnabled = true
-
- if (exception != null) {
- Timber.w("heartbeat sending failed with [$exception]")
- Toast.makeText(context, exception, Toast.LENGTH_LONG).show()
- return@run
- }
- Toast.makeText(context, "Heartbeat sent successfully", Toast.LENGTH_SHORT).show()
-
- setLastHeartbeatTimestamp(this)
- }
- }
-
- Thread {
- val charging = Settings.isCharging(applicationContext)
- var error: String? = null
- try {
- val phoneNumbers = mutableListOf<String>()
- phoneNumbers.add(Settings.getSIM1PhoneNumber(applicationContext))
- if (Settings.getActiveStatus(applicationContext, Constants.SIM2)) {
- phoneNumbers.add(Settings.getSIM2PhoneNumber(applicationContext))
- }
- val isStored = HttpSmsApiService.create(context).storeHeartbeat(phoneNumbers.toTypedArray(), charging)
- if (!isStored) {
- error = "Could not send heartbeat make sure the phone is connected to the internet"
- }
- Settings.setHeartbeatTimestampAsync(applicationContext, System.currentTimeMillis())
- } catch (exception: Exception) {
- Timber.e(exception)
- error = exception.javaClass.simpleName
- }
- liveData.postValue(error)
- Timber.d("finished sending pulse")
- }.start()
- }
}
diff --git a/android/app/src/main/java/com/httpsms/SettingsActivity.kt b/android/app/src/main/java/com/httpsms/SettingsActivity.kt
index cbc2831b..37a8b352 100644
--- a/android/app/src/main/java/com/httpsms/SettingsActivity.kt
+++ b/android/app/src/main/java/com/httpsms/SettingsActivity.kt
@@ -1,121 +1,33 @@
package com.httpsms
-import android.content.Context
import android.content.Intent
import android.os.Bundle
+import androidx.activity.compose.setContent
+import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
-import androidx.core.widget.doAfterTextChanged
-import com.google.android.material.appbar.MaterialToolbar
-import com.google.android.material.button.MaterialButton
import com.google.android.material.dialog.MaterialAlertDialogBuilder
-import com.google.android.material.switchmaterial.SwitchMaterial
-import com.google.android.material.textfield.TextInputEditText
-import com.google.android.material.textfield.TextInputLayout
+import com.httpsms.ui.settings.SettingsScreen
+import com.httpsms.ui.settings.SettingsViewModel
+import com.httpsms.ui.theme.HttpSmsTheme
import timber.log.Timber
class SettingsActivity : AppCompatActivity() {
+ private val viewModel: SettingsViewModel by viewModels()
+
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
- setContentView(R.layout.activity_settings)
- fillSettings(this)
- registerListeners()
- }
-
- private fun fillSettings(context: Context) {
- val debugLogs = findViewById<SwitchMaterial>(R.id.settingEnableDebugLogs)
- debugLogs.isChecked = Settings.isDebugLogEnabled(context)
- debugLogs.setOnCheckedChangeListener{ _, isChecked -> run { Settings.setDebugLogEnabled(context, isChecked) } }
-
-
- val phoneNumber = findViewById<TextInputEditText>(R.id.settingsSIM1Input)
- phoneNumber.setText(Settings.getSIM1PhoneNumber(context))
- phoneNumber.isEnabled = false
-
- val sim1IncomingMessages = findViewById<SwitchMaterial>(R.id.settings_sim1_incoming_messages)
- sim1IncomingMessages.isChecked = Settings.isIncomingMessageEnabled(context, Constants.SIM1)
-
- sim1IncomingMessages.setOnCheckedChangeListener{ _, isChecked -> run { Settings.setIncomingActiveSIM1(context, isChecked) } }
-
- val sim1OutgoingMessages = findViewById<SwitchMaterial>(R.id.settings_sim1_outgoing_messages)
- sim1OutgoingMessages.isChecked = Settings.getActiveStatus(context, Constants.SIM1)
- sim1OutgoingMessages.setOnCheckedChangeListener{ _, isChecked -> run { Settings.setActiveStatusAsync(context, isChecked, Constants.SIM1) } }
-
- if (!Settings.isDualSIM(context)) {
- val layout = findViewById<TextInputLayout>(R.id.settingsSIM2Layout)
- layout.visibility = TextInputLayout.GONE
- val sim2Switch = findViewById<SwitchMaterial>(R.id.settings_sim2_incoming_messages)
- sim2Switch.visibility = SwitchMaterial.GONE
- val outgoingSwitch = findViewById<SwitchMaterial>(R.id.settings_sim2_outgoing_messages)
- outgoingSwitch.visibility = SwitchMaterial.GONE
- } else {
- val phoneNumberSIM2 = findViewById<TextInputEditText>(R.id.settingsSIM2InputEdit)
- phoneNumberSIM2.setText(Settings.getSIM2PhoneNumber(context))
- phoneNumberSIM2.isEnabled = false
-
- val sim2IncomingMessages = findViewById<SwitchMaterial>(R.id.settings_sim2_incoming_messages)
- sim2IncomingMessages.isChecked = Settings.isIncomingMessageEnabled(context, Constants.SIM2)
- sim2IncomingMessages.setOnCheckedChangeListener{ _, isChecked -> run { Settings.setIncomingActiveSIM2(context, isChecked) } }
-
- val sim2OutgoingMessages = findViewById<SwitchMaterial>(R.id.settings_sim2_outgoing_messages)
- sim2OutgoingMessages.isChecked = Settings.getActiveStatus(context, Constants.SIM2)
- sim2OutgoingMessages.setOnCheckedChangeListener{ _, isChecked -> run { Settings.setActiveStatusAsync(context, isChecked, Constants.SIM2) } }
- }
-
- handleEncryptionSettings(context)
- handleIncomingCallEvents(context)
- }
-
- private fun handleIncomingCallEvents(context: Context) {
- val enableIncomingCallEvents = findViewById<SwitchMaterial>(R.id.settingsSim1EnableIncomingCallEvents)
- enableIncomingCallEvents.isChecked = Settings.isIncomingCallEventsEnabled(context, Constants.SIM1)
- enableIncomingCallEvents.setOnCheckedChangeListener{ _, isChecked -> run {
- Settings.setIncomingCallEventsEnabled(context, Constants.SIM1, isChecked)
- }}
-
- val sim2IncomingCalls = findViewById<SwitchMaterial>(R.id.settingsSim2EnableIncomingCallEvents)
- if (!Settings.isDualSIM(context)) {
- sim2IncomingCalls.visibility = SwitchMaterial.GONE
- return
- }
-
- sim2IncomingCalls.isChecked = Settings.isIncomingCallEventsEnabled(context, Constants.SIM2)
- sim2IncomingCalls.setOnCheckedChangeListener{ _, isChecked -> run {
- Settings.setIncomingCallEventsEnabled(context, Constants.SIM2, isChecked)
- }}
- }
-
- private fun handleEncryptionSettings(context: Context) {
- val encryptionKey = findViewById<TextInputEditText>(R.id.settingsEncryptionKeyInputEdit)
- val encryptReceivedMessages = findViewById<SwitchMaterial>(R.id.settingsEncryptReceivedMessages)
-
- val key = Settings.getEncryptionKey(context)
- if(key.isNullOrEmpty()) {
- encryptReceivedMessages.isEnabled = false
- } else {
- encryptionKey.setText(key.trim())
- }
-
- encryptionKey.doAfterTextChanged{
- if (it == null || it.toString().isEmpty()) {
- Settings.setEncryptionKey(context, null)
- Settings.setEncryptReceivedMessages(context, false)
- encryptReceivedMessages.isChecked = false
- encryptReceivedMessages.isEnabled = false
- } else {
- encryptReceivedMessages.isEnabled = true
- Settings.setEncryptionKey(context, it.toString().trim())
+
+ viewModel.initialize(this)
+
+ setContent {
+ HttpSmsTheme {
+ SettingsScreen(
+ viewModel = viewModel,
+ onBackClick = { onBackClicked() },
+ onLogoutClick = { onLogoutClick() }
+ )
}
}
-
- encryptReceivedMessages.isChecked = Settings.encryptReceivedMessages(context)
- encryptReceivedMessages.setOnCheckedChangeListener{ _, isChecked -> run {
- Settings.setEncryptReceivedMessages(context, isChecked)
- }}
- }
-
- private fun registerListeners() {
- appToolbar().setOnClickListener { onBackClicked() }
- findViewById<MaterialButton>(R.id.settingsLogoutButton).setOnClickListener { onLogoutClick() }
}
private fun onBackClicked() {
@@ -129,10 +41,6 @@ class SettingsActivity : AppCompatActivity() {
startActivity(switchActivityIntent)
}
- private fun appToolbar(): MaterialToolbar {
- return findViewById(R.id.settings_toolbar)
- }
-
private fun onLogoutClick() {
Timber.d("logout button clicked")
MaterialAlertDialogBuilder(this)
@@ -141,20 +49,9 @@ class SettingsActivity : AppCompatActivity() {
.setNeutralButton("Cancel"){ _, _ -> Timber.d("logout dialog canceled") }
.setPositiveButton("Logout"){_, _ ->
Timber.d("logging out user")
- Settings.setApiKeyAsync(this, null)
- Settings.setSIM1PhoneNumber(this, null)
- Settings.setSIM2PhoneNumber(this, null)
- Settings.setActiveStatusAsync(this, true, Constants.SIM1)
- Settings.setActiveStatusAsync(this, true, Constants.SIM2)
- Settings.setIncomingActiveSIM1(this, true)
- Settings.setIncomingActiveSIM2(this, true)
- Settings.setUserID(this, null)
- Settings.setEncryptionKey(this, null)
- Settings.setEncryptReceivedMessages(this, false)
- Settings.setFcmTokenLastUpdateTimestampAsync(this, 0)
- Settings.setIncomingCallEventsEnabled(this, Constants.SIM1, false)
- Settings.setIncomingCallEventsEnabled(this, Constants.SIM2, false)
- redirectToLogin()
+ viewModel.logout(this) {
+ redirectToLogin()
+ }
}
.show()
}
diff --git a/android/app/src/main/java/com/httpsms/ui/login/LoginActivityContent.kt b/android/app/src/main/java/com/httpsms/ui/login/LoginActivityContent.kt
new file mode 100644
index 00000000..0fc5e4c9
--- /dev/null
+++ b/android/app/src/main/java/com/httpsms/ui/login/LoginActivityContent.kt
@@ -0,0 +1,217 @@
+package com.httpsms.ui.login
+
+import androidx.compose.foundation.Image
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.PaddingValues
+import androidx.compose.foundation.layout.Spacer
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.height
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.layout.size
+import androidx.compose.foundation.rememberScrollState
+import androidx.compose.foundation.text.ClickableText
+import androidx.compose.foundation.text.KeyboardOptions
+import androidx.compose.foundation.verticalScroll
+import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.filled.QrCodeScanner
+import androidx.compose.material3.Button
+import androidx.compose.material3.ButtonDefaults
+import androidx.compose.material3.CircularProgressIndicator
+import androidx.compose.material3.Icon
+import androidx.compose.material3.IconButton
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.material3.OutlinedTextField
+import androidx.compose.material3.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.collectAsState
+import androidx.compose.runtime.getValue
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.platform.LocalUriHandler
+import androidx.compose.ui.res.painterResource
+import androidx.compose.ui.res.stringResource
+import androidx.compose.ui.text.SpanStyle
+import androidx.compose.ui.text.buildAnnotatedString
+import androidx.compose.ui.text.font.FontWeight
+import androidx.compose.ui.text.input.ImeAction
+import androidx.compose.ui.text.input.KeyboardType
+import androidx.compose.ui.text.style.TextAlign
+import androidx.compose.ui.text.withStyle
+import androidx.compose.ui.unit.dp
+import androidx.compose.ui.unit.sp
+import com.httpsms.R
+import com.httpsms.ui.theme.Blue500
+import com.httpsms.ui.theme.Pink500
+
+@Composable
+fun LoginScreen(
+ viewModel: LoginViewModel,
+ onQrScanClick: () -> Unit,
+ onLoginClick: () -> Unit
+) {
+ val uiState by viewModel.uiState.collectAsState()
+ val uriHandler = LocalUriHandler.current
+
+ Column(
+ modifier = Modifier
+ .fillMaxSize()
+ .verticalScroll(rememberScrollState())
+ .padding(16.dp),
+ horizontalAlignment = Alignment.CenterHorizontally
+ ) {
+ Spacer(modifier = Modifier.height(64.dp))
+
+ Image(
+ painter = painterResource(id = R.drawable.logo_cropped),
+ contentDescription = stringResource(id = R.string.img_http_sms_logo),
+ modifier = Modifier.size(100.dp)
+ )
+
+ Spacer(modifier = Modifier.height(32.dp))
+
+ val annotatedString = buildAnnotatedString {
+ val text = stringResource(id = R.string.get_your_api_key)
+ val linkText = "httpsms.com/settings"
+ val startIndex = text.indexOf(linkText)
+
+ if (startIndex >= 0) {
+ append(text.substring(0, startIndex))
+
+ pushStringAnnotation(tag = "URL", annotation = "https://httpsms.com/settings")
+ withStyle(style = SpanStyle(color = Blue500, fontWeight = FontWeight.Bold)) {
+ append(linkText)
+ }
+ pop()
+
+ append(text.substring(startIndex + linkText.length))
+ } else {
+ append(text)
+ }
+ }
+
+ ClickableText(
+ text = annotatedString,
+ onClick = { offset ->
+ annotatedString.getStringAnnotations(tag = "URL", start = offset, end = offset)
+ .firstOrNull()?.let { annotation ->
+ uriHandler.openUri(annotation.item)
+ }
+ },
+ style = MaterialTheme.typography.bodyLarge.copy(
+ textAlign = TextAlign.Center,
+ fontSize = 20.sp,
+ lineHeight = 28.sp,
+ color = MaterialTheme.colorScheme.onBackground
+ ),
+ modifier = Modifier.fillMaxWidth()
+ )
+
+ Spacer(modifier = Modifier.height(24.dp))
+
+ OutlinedTextField(
+ value = uiState.apiKey,
+ onValueChange = { viewModel.onApiKeyChange(it) },
+ label = { Text(stringResource(id = R.string.text_area_api_key)) },
+ modifier = Modifier.fillMaxWidth(),
+ isError = uiState.apiKeyError != null,
+ supportingText = uiState.apiKeyError?.let { { Text(it) } },
+ trailingIcon = {
+ IconButton(onClick = onQrScanClick) {
+ Icon(
+ imageVector = Icons.Default.QrCodeScanner,
+ contentDescription = "Scan QR Code"
+ )
+ }
+ },
+ keyboardOptions = KeyboardOptions(
+ keyboardType = KeyboardType.Text,
+ imeAction = ImeAction.Done
+ ),
+ enabled = !uiState.isLoading
+ )
+
+ Spacer(modifier = Modifier.height(8.dp))
+
+ OutlinedTextField(
+ value = uiState.phoneNumberSIM1,
+ onValueChange = { viewModel.onPhoneNumberSIM1Change(it) },
+ label = { Text(stringResource(id = R.string.login_phone_number_sim1)) },
+ placeholder = { Text(stringResource(id = R.string.login_phone_number_hint)) },
+ modifier = Modifier.fillMaxWidth(),
+ isError = uiState.phoneNumberSIM1Error != null,
+ supportingText = uiState.phoneNumberSIM1Error?.let { { Text(it) } },
+ keyboardOptions = KeyboardOptions(
+ keyboardType = KeyboardType.Phone,
+ imeAction = ImeAction.Done
+ ),
+ enabled = !uiState.isLoading
+ )
+
+ if (uiState.isDualSim) {
+ Spacer(modifier = Modifier.height(8.dp))
+ OutlinedTextField(
+ value = uiState.phoneNumberSIM2,
+ onValueChange = { viewModel.onPhoneNumberSIM2Change(it) },
+ label = { Text(stringResource(id = R.string.login_phone_number_sim2)) },
+ placeholder = { Text(stringResource(id = R.string.login_phone_number_hint)) },
+ modifier = Modifier.fillMaxWidth(),
+ isError = uiState.phoneNumberSIM2Error != null,
+ supportingText = uiState.phoneNumberSIM2Error?.let { { Text(it) } },
+ keyboardOptions = KeyboardOptions(
+ keyboardType = KeyboardType.Phone,
+ imeAction = ImeAction.Done
+ ),
+ enabled = !uiState.isLoading
+ )
+ }
+
+ Spacer(modifier = Modifier.height(8.dp))
+
+ OutlinedTextField(
+ value = uiState.serverUrl,
+ onValueChange = { viewModel.onServerUrlChange(it) },
+ label = { Text(stringResource(id = R.string.server_url)) },
+ placeholder = { Text(stringResource(id = R.string.login_server_url_hint)) },
+ modifier = Modifier.fillMaxWidth(),
+ isError = uiState.serverUrlError != null,
+ supportingText = uiState.serverUrlError?.let { { Text(it) } },
+ keyboardOptions = KeyboardOptions(
+ keyboardType = KeyboardType.Uri,
+ imeAction = ImeAction.Done
+ ),
+ enabled = !uiState.isLoading
+ )
+
+ Spacer(modifier = Modifier.height(16.dp))
+
+ Button(
+ onClick = onLoginClick,
+ enabled = !uiState.isLoading,
+ modifier = Modifier.align(Alignment.CenterHorizontally),
+ colors = ButtonDefaults.buttonColors(containerColor = Blue500),
+ contentPadding = PaddingValues(horizontal = 32.dp, vertical = 16.dp)
+ ) {
+ Icon(
+ painter = painterResource(id = R.drawable.ic_login),
+ contentDescription = null,
+ modifier = Modifier.padding(end = 8.dp),
+ tint = Color.White
+ )
+ Text(
+ text = stringResource(id = R.string.sign_in_button),
+ color = Color.White,
+ fontSize = 18.sp
+ )
+ }
+
+ if (uiState.isLoading) {
+ Spacer(modifier = Modifier.height(16.dp))
+ CircularProgressIndicator(
+ modifier = Modifier.size(24.dp),
+ color = Pink500
+ )
+ }
+ }
+}
diff --git a/android/app/src/main/java/com/httpsms/ui/login/LoginViewModel.kt b/android/app/src/main/java/com/httpsms/ui/login/LoginViewModel.kt
new file mode 100644
index 00000000..a4803e41
--- /dev/null
+++ b/android/app/src/main/java/com/httpsms/ui/login/LoginViewModel.kt
@@ -0,0 +1,221 @@
+package com.httpsms.ui.login
+
+import android.Manifest
+import android.content.Context
+import android.content.pm.PackageManager
+import android.os.Build
+import android.telephony.SubscriptionManager
+import android.telephony.TelephonyManager
+import android.webkit.URLUtil
+import androidx.core.content.ContextCompat
+import androidx.lifecycle.ViewModel
+import androidx.lifecycle.viewModelScope
+import com.httpsms.Constants
+import com.httpsms.HttpSmsApiService
+import com.httpsms.Settings
+import com.httpsms.SmsManagerService
+import com.httpsms.validators.PhoneNumberValidator
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.flow.MutableStateFlow
+import kotlinx.coroutines.flow.asStateFlow
+import kotlinx.coroutines.launch
+import kotlinx.coroutines.withContext
+import timber.log.Timber
+import java.net.URI
+import java.net.URISyntaxException
+
+data class LoginUiState(
+ val apiKey: String = "",
+ val phoneNumberSIM1: String = "",
+ val phoneNumberSIM2: String = "",
+ val serverUrl: String = "",
+ val isLoading: Boolean = false,
+ val apiKeyError: String? = null,
+ val phoneNumberSIM1Error: String? = null,
+ val phoneNumberSIM2Error: String? = null,
+ val serverUrlError: String? = null,
+ val isDualSim: Boolean = false,
+ val loginSuccess: Boolean = false
+)
+
+class LoginViewModel : ViewModel() {
+ private val _uiState = MutableStateFlow(LoginUiState())
+ val uiState = _uiState.asStateFlow()
+
+ fun initialize(context: Context, defaultServerUrl: String) {
+ val isDualSim = SmsManagerService.isDualSIM(context)
+ val phoneNumberSIM1 = Settings.getSIM1PhoneNumber(context)
+ val phoneNumberSIM2 = Settings.getSIM2PhoneNumber(context)
+
+ _uiState.value = _uiState.value.copy(
+ isDualSim = isDualSim,
+ phoneNumberSIM1 = phoneNumberSIM1,
+ phoneNumberSIM2 = phoneNumberSIM2,
+ serverUrl = defaultServerUrl
+ )
+
+ // Try to auto-detect if fields are empty
+ if (phoneNumberSIM1.isEmpty() || (isDualSim && phoneNumberSIM2.isEmpty())) {
+ autoDetectPhoneNumbers(context)
+ }
+ }
+
+ fun autoDetectPhoneNumbers(context: Context) {
+ if (ContextCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
+ Timber.d("READ_PHONE_STATE permission not granted for auto-detecting phone numbers")
+ return
+ }
+
+ val telephonyManager = context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
+
+ var detectedSIM1 = _uiState.value.phoneNumberSIM1
+ var detectedSIM2 = _uiState.value.phoneNumberSIM2
+
+ try {
+ val subscriptionManager = if (Build.VERSION.SDK_INT >= 31) {
+ context.getSystemService(SubscriptionManager::class.java)
+ } else {
+ SubscriptionManager.from(context)
+ }
+
+ val activeSubscriptions = try { subscriptionManager.activeSubscriptionInfoList } catch (e: Exception) { null }
+
+ if (detectedSIM1.isEmpty()) {
+ val line1Number = try { telephonyManager.line1Number } catch (e: Exception) { null }
+ if (!line1Number.isNullOrEmpty()) {
+ detectedSIM1 = line1Number
+ } else if (activeSubscriptions != null && activeSubscriptions.isNotEmpty()) {
+ detectedSIM1 = activeSubscriptions[0].number ?: ""
+ }
+ }
+
+ if (detectedSIM2.isEmpty() && activeSubscriptions != null && activeSubscriptions.size >= 2) {
+ detectedSIM2 = activeSubscriptions[1].number ?: ""
+ }
+
+ Timber.d("Auto-detected numbers - SIM1: $detectedSIM1, SIM2: $detectedSIM2")
+
+ } catch (e: SecurityException) {
+ Timber.e(e, "Security exception while auto-detecting phone numbers")
+ }
+
+ _uiState.value = _uiState.value.copy(
+ phoneNumberSIM1 = detectedSIM1,
+ phoneNumberSIM2 = detectedSIM2,
+ isDualSim = SmsManagerService.isDualSIM(context)
+ )
+ }
+
+ fun onApiKeyChange(value: String) {
+ _uiState.value = _uiState.value.copy(apiKey = value, apiKeyError = null)
+ }
+
+ fun onPhoneNumberSIM1Change(value: String) {
+ _uiState.value = _uiState.value.copy(phoneNumberSIM1 = value, phoneNumberSIM1Error = null)
+ }
+
+ fun onPhoneNumberSIM2Change(value: String) {
+ _uiState.value = _uiState.value.copy(phoneNumberSIM2 = value, phoneNumberSIM2Error = null)
+ }
+
+ fun onServerUrlChange(value: String) {
+ _uiState.value = _uiState.value.copy(serverUrl = value, serverUrlError = null)
+ }
+
+ fun login(context: Context, countryCode: String, onGooglePlayServicesError: (String) -> Unit, onFcmTokenMissing: () -> Unit) {
+ val currentState = _uiState.value
+
+ // Validation logic from LoginActivity.onLoginClick
+ if (Settings.getFcmToken(context) == null) {
+ onFcmTokenMissing()
+ return
+ }
+
+ _uiState.value = currentState.copy(isLoading = true)
+
+ viewModelScope.launch {
+ val apiKey = currentState.apiKey.trim()
+ val serverUrl = currentState.serverUrl.trim()
+ val phone1 = currentState.phoneNumberSIM1.trim()
+ val phone2 = currentState.phoneNumberSIM2.trim()
+
+ if (!PhoneNumberValidator.isValidPhoneNumber(phone1, countryCode)) {
+ _uiState.value = _uiState.value.copy(
+ isLoading = false,
+ phoneNumberSIM1Error = "Enter an international phone number in the E.164 format"
+ )
+ return@launch
+ }
+
+ if (currentState.isDualSim && !PhoneNumberValidator.isValidPhoneNumber(phone2, countryCode)) {
+ _uiState.value = _uiState.value.copy(
+ isLoading = false,
+ phoneNumberSIM2Error = "Enter an international phone number in the E.164 format"
+ )
+ return@launch
+ }
+
+ if (!URLUtil.isValidUrl(serverUrl)) {
+ _uiState.value = _uiState.value.copy(
+ isLoading = false,
+ serverUrlError = "Server URL [$serverUrl] is invalid"
+ )
+ return@launch
+ }
+
+ if (!URLUtil.isHttpsUrl(serverUrl)) {
+ _uiState.value = _uiState.value.copy(
+ isLoading = false,
+ serverUrlError = "Server URL [$serverUrl] must be HTTPS"
+ )
+ return@launch
+ }
+
+ val authResult = try {
+ withContext(Dispatchers.IO) {
+ val service = HttpSmsApiService(apiKey, URI(serverUrl))
+ val e164Phone1 = PhoneNumberValidator.formatE164(phone1, countryCode)
+ val response1 = service.updateFcmToken(e164Phone1, Constants.SIM1, Settings.getFcmToken(context) ?: "")
+
+ if (response1.second != null || response1.third != null) {
+ return@withContext Pair(response1.second, response1.third)
+ }
+
+ if (currentState.isDualSim) {
+ val e164Phone2 = PhoneNumberValidator.formatE164(phone2, countryCode)
+ val response2 = service.updateFcmToken(e164Phone2, Constants.SIM2, Settings.getFcmToken(context) ?: "")
+ return@withContext Pair(response2.second, response2.third)
+ }
+
+ Pair(null, null)
+ }
+ } catch (e: URISyntaxException) {
+ Timber.e(e, "Invalid URI: $serverUrl")
+ Pair(null, "Server URL [$serverUrl] is invalid")
+ } catch (e: Exception) {
+ Timber.e(e, "Login error")
+ Pair(null, "An unexpected error occurred: ${e.message}")
+ }
+
+ if (authResult.first != null) {
+ _uiState.value = _uiState.value.copy(isLoading = false, apiKeyError = authResult.first)
+ return@launch
+ }
+
+ if (authResult.second != null) {
+ _uiState.value = _uiState.value.copy(isLoading = false, serverUrlError = authResult.second)
+ return@launch
+ }
+
+ // Save settings
+ Settings.setApiKeyAsync(context, apiKey)
+ Settings.setServerUrlAsync(context, serverUrl)
+ Settings.setSIM1PhoneNumber(context, PhoneNumberValidator.formatE164(phone1, countryCode))
+ if (currentState.isDualSim) {
+ Settings.setSIM2PhoneNumber(context, PhoneNumberValidator.formatE164(phone2, countryCode))
+ }
+
+ _uiState.value = _uiState.value.copy(isLoading = false, loginSuccess = true)
+ }
+ }
+}
diff --git a/android/app/src/main/java/com/httpsms/ui/main/MainActivityContent.kt b/android/app/src/main/java/com/httpsms/ui/main/MainActivityContent.kt
new file mode 100644
index 00000000..087bf792
--- /dev/null
+++ b/android/app/src/main/java/com/httpsms/ui/main/MainActivityContent.kt
@@ -0,0 +1,243 @@
+package com.httpsms.ui.main
+
+import android.telephony.PhoneNumberUtils
+import androidx.compose.foundation.Image
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.IntrinsicSize
+import androidx.compose.foundation.layout.PaddingValues
+import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.Spacer
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.height
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.layout.size
+import androidx.compose.foundation.layout.width
+import androidx.compose.foundation.rememberScrollState
+import androidx.compose.foundation.verticalScroll
+import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.filled.BatteryAlert
+import androidx.compose.material.icons.filled.CheckCircle
+import androidx.compose.material.icons.filled.Favorite
+import androidx.compose.material.icons.filled.Settings
+import androidx.compose.material3.Button
+import androidx.compose.material3.ButtonDefaults
+import androidx.compose.material3.Card
+import androidx.compose.material3.CardDefaults
+import androidx.compose.material3.Icon
+import androidx.compose.material3.LinearProgressIndicator
+import androidx.compose.material3.LocalContentColor
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.material3.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.collectAsState
+import androidx.compose.runtime.getValue
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.platform.LocalContext
+import androidx.compose.ui.res.painterResource
+import androidx.compose.ui.res.stringResource
+import androidx.compose.ui.text.font.FontWeight
+import androidx.compose.ui.unit.dp
+import androidx.compose.ui.unit.sp
+import com.httpsms.R
+import com.httpsms.ui.theme.Blue500
+import com.httpsms.ui.theme.Pink500
+import java.util.Locale
+
+@Composable
+fun MainScreen(
+ viewModel: MainViewModel,
+ onSettingsClick: () -> Unit,
+ onSmsPermissionClick: () -> Unit,
+ onBatteryOptimizationClick: () -> Unit,
+ onHeartbeatClick: () -> Unit
+) {
+ val uiState by viewModel.uiState.collectAsState()
+
+ Column(
+ modifier = Modifier
+ .fillMaxSize()
+ .verticalScroll(rememberScrollState())
+ .padding(16.dp),
+ horizontalAlignment = Alignment.CenterHorizontally
+ ) {
+ Spacer(modifier = Modifier.height(64.dp))
+
+ Image(
+ painter = painterResource(id = R.drawable.logo_cropped),
+ contentDescription = stringResource(id = R.string.img_http_sms_logo),
+ modifier = Modifier
+ .width(147.dp)
+ .height(92.dp)
+ )
+
+ Spacer(modifier = Modifier.height(24.dp))
+
+ PhoneCard(
+ phoneNumber = uiState.phoneNumberSIM1,
+ isActive = uiState.isActiveSIM1,
+ refreshTime = uiState.lastHeartbeatTime
+ )
+
+ if (uiState.isDualSim) {
+ Spacer(modifier = Modifier.height(24.dp))
+ PhoneCard(
+ phoneNumber = uiState.phoneNumberSIM2,
+ isActive = uiState.isActiveSIM2,
+ refreshTime = uiState.lastHeartbeatTime
+ )
+ }
+
+ Spacer(modifier = Modifier.height(16.dp))
+
+ if (!uiState.isSmsPermissionGranted || !uiState.isBatteryOptimizationDisabled) {
+ Column(modifier = Modifier.fillMaxWidth()) {
+ if (!uiState.isSmsPermissionGranted) {
+ Button(
+ onClick = onSmsPermissionClick,
+ modifier = Modifier.align(Alignment.CenterHorizontally),
+ colors = ButtonDefaults.buttonColors(containerColor = Color(0xFF4CAF50)),
+ contentPadding = PaddingValues(horizontal = 32.dp, vertical = 16.dp)
+ ) {
+ Text(
+ stringResource(id = R.string.enable_sms_permission),
+ color = Color.White,
+ fontSize = 18.sp
+ )
+ Spacer(modifier = Modifier.width(8.dp))
+ Icon(
+ painter = painterResource(id = R.drawable.open_in_new_24),
+ contentDescription = null,
+ tint = Color.White
+ )
+ }
+ Spacer(modifier = Modifier.height(8.dp))
+ }
+
+ if (!uiState.isBatteryOptimizationDisabled) {
+ Button(
+ onClick = onBatteryOptimizationClick,
+ modifier = Modifier.align(Alignment.CenterHorizontally),
+ colors = ButtonDefaults.buttonColors(containerColor = Pink500),
+ contentPadding = PaddingValues(horizontal = 32.dp, vertical = 16.dp)
+ ) {
+ Icon(
+ imageVector = Icons.Default.BatteryAlert,
+ contentDescription = null,
+ tint = Color.White
+ )
+ Spacer(modifier = Modifier.width(8.dp))
+ Text(
+ stringResource(id = R.string.disable_battery_optimization),
+ color = Color.White,
+ fontSize = 18.sp
+ )
+ }
+ }
+ }
+ }
+
+ Spacer(modifier = Modifier.height(16.dp))
+
+ Column(
+ modifier = Modifier.width(IntrinsicSize.Max),
+ horizontalAlignment = Alignment.CenterHorizontally
+ ) {
+ Button(
+ onClick = onHeartbeatClick,
+ modifier = Modifier.fillMaxWidth(),
+ enabled = !uiState.isHeartbeatLoading,
+ colors = ButtonDefaults.buttonColors(containerColor = Blue500),
+ contentPadding = PaddingValues(horizontal = 32.dp, vertical = 16.dp)
+ ) {
+ Icon(
+ imageVector = Icons.Default.Favorite,
+ contentDescription = null,
+ tint = if (uiState.isHeartbeatLoading) LocalContentColor.current else Pink500
+ )
+ Spacer(modifier = Modifier.width(8.dp))
+ Text(
+ stringResource(id = R.string.send_heartbeat),
+ color = Color.White,
+ fontSize = 18.sp
+ )
+ }
+
+ if (uiState.isHeartbeatLoading) {
+ LinearProgressIndicator(
+ modifier = Modifier
+ .fillMaxWidth()
+ .padding(top = 4.dp),
+ color = Pink500
+ )
+ }
+ }
+
+ Spacer(modifier = Modifier.height(16.dp))
+
+ Text(
+ text = uiState.appVersion,
+ fontSize = 14.sp,
+ color = MaterialTheme.colorScheme.onBackground.copy(alpha = 0.6f)
+ )
+
+ Spacer(modifier = Modifier.weight(1f))
+ Spacer(modifier = Modifier.height(16.dp))
+
+ Button(
+ onClick = onSettingsClick,
+ colors = ButtonDefaults.buttonColors(containerColor = Color.Black),
+ contentPadding = PaddingValues(horizontal = 32.dp, vertical = 16.dp)
+ ) {
+ Icon(Icons.Default.Settings, contentDescription = null, tint = Color.White)
+ Spacer(modifier = Modifier.width(8.dp))
+ Text(
+ stringResource(id = R.string.main_app_settings),
+ color = Color.White,
+ fontSize = 18.sp
+ )
+ }
+
+ Spacer(modifier = Modifier.height(16.dp))
+ }
+}
+
+@Composable
+fun PhoneCard(
+ phoneNumber: String,
+ isActive: Boolean,
+ refreshTime: String
+) {
+ Card(
+ modifier = Modifier.fillMaxWidth(),
+ elevation = CardDefaults.cardElevation(defaultElevation = 8.dp)
+ ) {
+ Column(modifier = Modifier.padding(16.dp)) {
+ Row(verticalAlignment = Alignment.CenterVertically) {
+ Text(
+ text = PhoneNumberUtils.formatNumber(phoneNumber, Locale.getDefault().country) ?: phoneNumber,
+ fontSize = 28.sp,
+ fontWeight = FontWeight.Medium,
+ modifier = Modifier.weight(1f),
+ color = MaterialTheme.colorScheme.onSurface
+ )
+ if (isActive) {
+ Icon(
+ imageVector = Icons.Default.CheckCircle,
+ contentDescription = "Active",
+ tint = Color(0xFF70AB5C),
+ modifier = Modifier.size(24.dp)
+ )
+ }
+ }
+ Spacer(modifier = Modifier.height(8.dp))
+ Text(
+ text = refreshTime,
+ fontSize = 16.sp,
+ color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.6f)
+ )
+ }
+ }
+}
diff --git a/android/app/src/main/java/com/httpsms/ui/main/MainViewModel.kt b/android/app/src/main/java/com/httpsms/ui/main/MainViewModel.kt
new file mode 100644
index 00000000..273cfe78
--- /dev/null
+++ b/android/app/src/main/java/com/httpsms/ui/main/MainViewModel.kt
@@ -0,0 +1,116 @@
+package com.httpsms.ui.main
+
+import android.Manifest
+import android.content.Context
+import android.content.pm.PackageManager
+import android.os.PowerManager
+import androidx.lifecycle.ViewModel
+import androidx.lifecycle.viewModelScope
+import com.httpsms.Constants
+import com.httpsms.HttpSmsApiService
+import com.httpsms.Settings
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.flow.MutableStateFlow
+import kotlinx.coroutines.flow.asStateFlow
+import kotlinx.coroutines.launch
+import kotlinx.coroutines.withContext
+import timber.log.Timber
+import java.time.Instant
+import java.time.ZoneId
+import java.time.ZoneOffset
+import java.time.ZonedDateTime
+import java.time.format.DateTimeFormatter
+
+data class MainUiState(
+ val phoneNumberSIM1: String = "",
+ val isActiveSIM1: Boolean = false,
+ val phoneNumberSIM2: String = "",
+ val isActiveSIM2: Boolean = false,
+ val isDualSim: Boolean = false,
+ val lastHeartbeatTime: String = "--",
+ val isSmsPermissionGranted: Boolean = true,
+ val isBatteryOptimizationDisabled: Boolean = true,
+ val isHeartbeatLoading: Boolean = false,
+ val appVersion: String = ""
+)
+
+class MainViewModel : ViewModel() {
+ private val _uiState = MutableStateFlow(MainUiState())
+ val uiState = _uiState.asStateFlow()
+
+ fun initialize(context: Context, appVersion: String) {
+ updateState(context, appVersion)
+ }
+
+ fun updateState(context: Context, appVersion: String) {
+ val isDualSim = Settings.isDualSIM(context)
+ val phone1 = Settings.getSIM1PhoneNumber(context) ?: ""
+ val active1 = Settings.getActiveStatus(context, Constants.SIM1)
+ val phone2 = Settings.getSIM2PhoneNumber(context) ?: ""
+ val active2 = Settings.getActiveStatus(context, Constants.SIM2)
+
+ val timestamp = Settings.getHeartbeatTimestamp(context)
+ val lastHeartbeat = if (timestamp == 0L) {
+ "--"
+ } else {
+ val timestampZdt = ZonedDateTime.ofInstant(Instant.ofEpochMilli(timestamp), ZoneOffset.UTC)
+ val localTime = timestampZdt.withZoneSameInstant(ZoneId.systemDefault())
+ localTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
+ }
+
+ val smsPermissions = arrayOf(
+ Manifest.permission.SEND_SMS,
+ Manifest.permission.RECEIVE_SMS,
+ Manifest.permission.READ_SMS
+ )
+ val allGranted = smsPermissions.all {
+ context.checkSelfPermission(it) == PackageManager.PERMISSION_GRANTED
+ }
+
+ val pm = context.getSystemService(Context.POWER_SERVICE) as PowerManager
+ val batteryOptimized = pm.isIgnoringBatteryOptimizations(context.packageName)
+
+ _uiState.value = _uiState.value.copy(
+ phoneNumberSIM1 = phone1,
+ isActiveSIM1 = active1,
+ phoneNumberSIM2 = phone2,
+ isActiveSIM2 = active2,
+ isDualSim = isDualSim,
+ lastHeartbeatTime = lastHeartbeat,
+ isSmsPermissionGranted = allGranted,
+ isBatteryOptimizationDisabled = batteryOptimized,
+ appVersion = appVersion
+ )
+ }
+
+ fun sendHeartbeat(context: Context, onComplete: (String?) -> Unit) {
+ _uiState.value = _uiState.value.copy(isHeartbeatLoading = true)
+
+ viewModelScope.launch {
+ val result = withContext(Dispatchers.IO) {
+ val charging = Settings.isCharging(context)
+ try {
+ val phoneNumbers = mutableListOf<String>()
+ phoneNumbers.add(Settings.getSIM1PhoneNumber(context))
+ if (Settings.getActiveStatus(context, Constants.SIM2)) {
+ phoneNumbers.add(Settings.getSIM2PhoneNumber(context))
+ }
+ val isStored = HttpSmsApiService.create(context).storeHeartbeat(phoneNumbers.toTypedArray(), charging)
+ if (!isStored) {
+ "Could not send heartbeat make sure the phone is connected to the internet"
+ } else {
+ Settings.setHeartbeatTimestampAsync(context, System.currentTimeMillis())
+ null
+ }
+ } catch (exception: Exception) {
+ Timber.e(exception)
+ exception.javaClass.simpleName
+ }
+ }
+
+ _uiState.value = _uiState.value.copy(isHeartbeatLoading = false)
+ updateState(context, _uiState.value.appVersion)
+ onComplete(result)
+ }
+ }
+}
diff --git a/android/app/src/main/java/com/httpsms/ui/settings/SettingsActivityContent.kt b/android/app/src/main/java/com/httpsms/ui/settings/SettingsActivityContent.kt
new file mode 100644
index 00000000..3335eb2c
--- /dev/null
+++ b/android/app/src/main/java/com/httpsms/ui/settings/SettingsActivityContent.kt
@@ -0,0 +1,221 @@
+package com.httpsms.ui.settings
+
+import android.app.Activity
+import androidx.compose.foundation.isSystemInDarkTheme
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.PaddingValues
+import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.Spacer
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.height
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.layout.width
+import androidx.compose.foundation.rememberScrollState
+import androidx.compose.foundation.verticalScroll
+import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.automirrored.filled.ArrowBack
+import androidx.compose.material.icons.automirrored.filled.Logout
+import androidx.compose.material3.Button
+import androidx.compose.material3.ButtonDefaults
+import androidx.compose.material3.ExperimentalMaterial3Api
+import androidx.compose.material3.Icon
+import androidx.compose.material3.IconButton
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.material3.OutlinedTextField
+import androidx.compose.material3.Scaffold
+import androidx.compose.material3.Switch
+import androidx.compose.material3.Text
+import androidx.compose.material3.TopAppBar
+import androidx.compose.material3.TopAppBarDefaults
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.SideEffect
+import androidx.compose.runtime.collectAsState
+import androidx.compose.runtime.getValue
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.toArgb
+import androidx.compose.ui.platform.LocalContext
+import androidx.compose.ui.platform.LocalView
+import androidx.compose.ui.res.stringResource
+import androidx.compose.ui.unit.dp
+import androidx.compose.ui.unit.sp
+import androidx.core.view.WindowCompat
+import com.httpsms.R
+import com.httpsms.ui.theme.LogoGreen
+
+@OptIn(ExperimentalMaterial3Api::class)
+@Composable
+fun SettingsScreen(
+ viewModel: SettingsViewModel,
+ onBackClick: () -> Unit,
+ onLogoutClick: () -> Unit
+) {
+ val uiState by viewModel.uiState.collectAsState()
+ val context = LocalContext.current
+ val isDarkTheme = isSystemInDarkTheme()
+ val primaryColor = if (isDarkTheme) Color.Black else LogoGreen
+
+ val view = LocalView.current
+ if (!view.isInEditMode) {
+ SideEffect {
+ val window = (view.context as Activity).window
+ window.statusBarColor = primaryColor.toArgb()
+ WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = false
+ }
+ }
+
+ Scaffold(
+ topBar = {
+ TopAppBar(
+ title = { Text("App Settings") },
+ navigationIcon = {
+ IconButton(onClick = onBackClick) {
+ Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Back")
+ }
+ },
+ colors = TopAppBarDefaults.topAppBarColors(
+ containerColor = primaryColor,
+ titleContentColor = Color.White,
+ navigationIconContentColor = Color.White
+ )
+ )
+ }
+ ) { paddingValues ->
+ Column(
+ modifier = Modifier
+ .fillMaxSize()
+ .padding(paddingValues)
+ .verticalScroll(rememberScrollState())
+ .padding(16.dp)
+ ) {
+ // SIM 1 Settings
+ OutlinedTextField(
+ value = uiState.phoneNumberSIM1,
+ onValueChange = { },
+ label = { Text(stringResource(id = R.string.settings_sim1)) },
+ modifier = Modifier.fillMaxWidth(),
+ enabled = false
+ )
+
+ SwitchSetting(
+ text = stringResource(id = R.string.settings_outgoing_messages_sim1),
+ checked = uiState.isActiveSIM1,
+ onCheckedChange = { viewModel.setActiveSIM1(context, it) }
+ )
+
+ SwitchSetting(
+ text = stringResource(id = R.string.settings_incoming_messages_sim1),
+ checked = uiState.isIncomingSIM1Enabled,
+ onCheckedChange = { viewModel.setIncomingSIM1Enabled(context, it) }
+ )
+
+ SwitchSetting(
+ text = stringResource(id = R.string.enable_incoming_call_events_sim1),
+ checked = uiState.isIncomingCallEventsSIM1Enabled,
+ onCheckedChange = { viewModel.setIncomingCallEventsSIM1Enabled(context, it) }
+ )
+
+ if (uiState.isDualSim) {
+ Spacer(modifier = Modifier.height(16.dp))
+ // SIM 2 Settings
+ OutlinedTextField(
+ value = uiState.phoneNumberSIM2,
+ onValueChange = { },
+ label = { Text(stringResource(id = R.string.settings_sim_2)) },
+ modifier = Modifier.fillMaxWidth(),
+ enabled = false
+ )
+
+ SwitchSetting(
+ text = stringResource(id = R.string.settings_outgoing_messages_sim2),
+ checked = uiState.isActiveSIM2,
+ onCheckedChange = { viewModel.setActiveSIM2(context, it) }
+ )
+
+ SwitchSetting(
+ text = stringResource(id = R.string.settings_incoming_messages_sim2),
+ checked = uiState.isIncomingSIM2Enabled,
+ onCheckedChange = { viewModel.setIncomingSIM2Enabled(context, it) }
+ )
+
+ SwitchSetting(
+ text = stringResource(id = R.string.enable_sim2_incoming_call_events),
+ checked = uiState.isIncomingCallEventsSIM2Enabled,
+ onCheckedChange = { viewModel.setIncomingCallEventsSIM2Enabled(context, it) }
+ )
+ }
+
+ Spacer(modifier = Modifier.height(16.dp))
+
+ OutlinedTextField(
+ value = uiState.encryptionKey,
+ onValueChange = { viewModel.setEncryptionKey(context, it) },
+ label = { Text(stringResource(id = R.string.encryption_key)) },
+ modifier = Modifier.fillMaxWidth()
+ )
+
+ SwitchSetting(
+ text = stringResource(id = R.string.encrypt_received_messages),
+ checked = uiState.isEncryptReceivedMessagesEnabled,
+ onCheckedChange = { viewModel.setEncryptReceivedMessagesEnabled(context, it) },
+ enabled = uiState.encryptionKey.isNotEmpty()
+ )
+
+ SwitchSetting(
+ text = stringResource(id = R.string.enable_debug_logs),
+ checked = uiState.isDebugLogEnabled,
+ onCheckedChange = { viewModel.setDebugLogEnabled(context, it) }
+ )
+
+ Spacer(modifier = Modifier.height(24.dp))
+
+ Button(
+ onClick = onLogoutClick,
+ modifier = Modifier.align(Alignment.CenterHorizontally),
+ colors = ButtonDefaults.buttonColors(containerColor = Color.Black),
+ contentPadding = PaddingValues(horizontal = 32.dp, vertical = 16.dp)
+ ) {
+ Icon(
+ imageVector = Icons.AutoMirrored.Filled.Logout,
+ contentDescription = null,
+ tint = Color.White
+ )
+ Spacer(modifier = Modifier.width(8.dp))
+ Text(
+ stringResource(id = R.string.main_log_out),
+ color = Color.White,
+ fontSize = 18.sp
+ )
+ }
+ }
+ }
+}
+
+@Composable
+fun SwitchSetting(
+ text: String,
+ checked: Boolean,
+ onCheckedChange: (Boolean) -> Unit,
+ enabled: Boolean = true
+) {
+ Row(
+ modifier = Modifier
+ .fillMaxWidth()
+ .padding(vertical = 8.dp),
+ verticalAlignment = Alignment.CenterVertically
+ ) {
+ Text(
+ text = text,
+ modifier = Modifier.weight(1f),
+ fontSize = 18.sp,
+ color = if (enabled) MaterialTheme.colorScheme.onBackground else MaterialTheme.colorScheme.onBackground.copy(alpha = 0.5f)
+ )
+ Switch(
+ checked = checked,
+ onCheckedChange = onCheckedChange,
+ enabled = enabled
+ )
+ }
+}
diff --git a/android/app/src/main/java/com/httpsms/ui/settings/SettingsViewModel.kt b/android/app/src/main/java/com/httpsms/ui/settings/SettingsViewModel.kt
new file mode 100644
index 00000000..33a23e57
--- /dev/null
+++ b/android/app/src/main/java/com/httpsms/ui/settings/SettingsViewModel.kt
@@ -0,0 +1,114 @@
+package com.httpsms.ui.settings
+
+import android.content.Context
+import androidx.lifecycle.ViewModel
+import com.httpsms.Constants
+import com.httpsms.Settings
+import kotlinx.coroutines.flow.MutableStateFlow
+import kotlinx.coroutines.flow.asStateFlow
+
+data class SettingsUiState(
+ val isDebugLogEnabled: Boolean = false,
+ val phoneNumberSIM1: String = "",
+ val isIncomingSIM1Enabled: Boolean = false,
+ val isActiveSIM1: Boolean = false,
+ val isIncomingCallEventsSIM1Enabled: Boolean = false,
+ val isDualSim: Boolean = false,
+ val phoneNumberSIM2: String = "",
+ val isIncomingSIM2Enabled: Boolean = false,
+ val isActiveSIM2: Boolean = false,
+ val isIncomingCallEventsSIM2Enabled: Boolean = false,
+ val encryptionKey: String = "",
+ val isEncryptReceivedMessagesEnabled: Boolean = false
+)
+
+class SettingsViewModel : ViewModel() {
+ private val _uiState = MutableStateFlow(SettingsUiState())
+ val uiState = _uiState.asStateFlow()
+
+ fun initialize(context: Context) {
+ _uiState.value = SettingsUiState(
+ isDebugLogEnabled = Settings.isDebugLogEnabled(context),
+ phoneNumberSIM1 = Settings.getSIM1PhoneNumber(context) ?: "",
+ isIncomingSIM1Enabled = Settings.isIncomingMessageEnabled(context, Constants.SIM1),
+ isActiveSIM1 = Settings.getActiveStatus(context, Constants.SIM1),
+ isIncomingCallEventsSIM1Enabled = Settings.isIncomingCallEventsEnabled(context, Constants.SIM1),
+ isDualSim = Settings.isDualSIM(context),
+ phoneNumberSIM2 = Settings.getSIM2PhoneNumber(context) ?: "",
+ isIncomingSIM2Enabled = Settings.isIncomingMessageEnabled(context, Constants.SIM2),
+ isActiveSIM2 = Settings.getActiveStatus(context, Constants.SIM2),
+ isIncomingCallEventsSIM2Enabled = Settings.isIncomingCallEventsEnabled(context, Constants.SIM2),
+ encryptionKey = Settings.getEncryptionKey(context) ?: "",
+ isEncryptReceivedMessagesEnabled = Settings.encryptReceivedMessages(context)
+ )
+ }
+
+ fun setDebugLogEnabled(context: Context, enabled: Boolean) {
+ Settings.setDebugLogEnabled(context, enabled)
+ _uiState.value = _uiState.value.copy(isDebugLogEnabled = enabled)
+ }
+
+ fun setIncomingSIM1Enabled(context: Context, enabled: Boolean) {
+ Settings.setIncomingActiveSIM1(context, enabled)
+ _uiState.value = _uiState.value.copy(isIncomingSIM1Enabled = enabled)
+ }
+
+ fun setActiveSIM1(context: Context, enabled: Boolean) {
+ Settings.setActiveStatusAsync(context, enabled, Constants.SIM1)
+ _uiState.value = _uiState.value.copy(isActiveSIM1 = enabled)
+ }
+
+ fun setIncomingCallEventsSIM1Enabled(context: Context, enabled: Boolean) {
+ Settings.setIncomingCallEventsEnabled(context, Constants.SIM1, enabled)
+ _uiState.value = _uiState.value.copy(isIncomingCallEventsSIM1Enabled = enabled)
+ }
+
+ fun setIncomingSIM2Enabled(context: Context, enabled: Boolean) {
+ Settings.setIncomingActiveSIM2(context, enabled)
+ _uiState.value = _uiState.value.copy(isIncomingSIM2Enabled = enabled)
+ }
+
+ fun setActiveSIM2(context: Context, enabled: Boolean) {
+ Settings.setActiveStatusAsync(context, enabled, Constants.SIM2)
+ _uiState.value = _uiState.value.copy(isActiveSIM2 = enabled)
+ }
+
+ fun setIncomingCallEventsSIM2Enabled(context: Context, enabled: Boolean) {
+ Settings.setIncomingCallEventsEnabled(context, Constants.SIM2, enabled)
+ _uiState.value = _uiState.value.copy(isIncomingCallEventsSIM2Enabled = enabled)
+ }
+
+ fun setEncryptionKey(context: Context, key: String) {
+ val trimmedKey = key.trim()
+ if (trimmedKey.isEmpty()) {
+ Settings.setEncryptionKey(context, null)
+ Settings.setEncryptReceivedMessages(context, false)
+ _uiState.value = _uiState.value.copy(encryptionKey = "", isEncryptReceivedMessagesEnabled = false)
+ } else {
+ Settings.setEncryptionKey(context, trimmedKey)
+ _uiState.value = _uiState.value.copy(encryptionKey = trimmedKey)
+ }
+ }
+
+ fun setEncryptReceivedMessagesEnabled(context: Context, enabled: Boolean) {
+ Settings.setEncryptReceivedMessages(context, enabled)
+ _uiState.value = _uiState.value.copy(isEncryptReceivedMessagesEnabled = enabled)
+ }
+
+ fun logout(context: Context, onLogoutComplete: () -> Unit) {
+ Settings.setApiKeyAsync(context, null)
+ Settings.setSIM1PhoneNumber(context, null)
+ Settings.setSIM2PhoneNumber(context, null)
+ Settings.setActiveStatusAsync(context, true, Constants.SIM1)
+ Settings.setActiveStatusAsync(context, true, Constants.SIM2)
+ Settings.setIncomingActiveSIM1(context, true)
+ Settings.setIncomingActiveSIM2(context, true)
+ Settings.setUserID(context, null)
+ Settings.setEncryptionKey(context, null)
+ Settings.setEncryptReceivedMessages(context, false)
+ Settings.setFcmTokenLastUpdateTimestampAsync(context, 0)
+ Settings.setIncomingCallEventsEnabled(context, Constants.SIM1, false)
+ Settings.setIncomingCallEventsEnabled(context, Constants.SIM2, false)
+ onLogoutComplete()
+ }
+}
diff --git a/android/app/src/main/java/com/httpsms/ui/theme/Theme.kt b/android/app/src/main/java/com/httpsms/ui/theme/Theme.kt
new file mode 100644
index 00000000..88c032fa
--- /dev/null
+++ b/android/app/src/main/java/com/httpsms/ui/theme/Theme.kt
@@ -0,0 +1,75 @@
+package com.httpsms.ui.theme
+
+import android.app.Activity
+import android.os.Build
+import androidx.compose.foundation.isSystemInDarkTheme
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.material3.darkColorScheme
+import androidx.compose.material3.dynamicDarkColorScheme
+import androidx.compose.material3.dynamicLightColorScheme
+import androidx.compose.material3.lightColorScheme
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.SideEffect
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.toArgb
+import androidx.compose.ui.platform.LocalContext
+import androidx.compose.ui.platform.LocalView
+import androidx.core.view.WindowCompat
+
+val Blue500 = Color(0xFF2196F3)
+val Pink500 = Color(0xFFE91E63)
+val LogoGreen = Color(0xFF70AB5C)
+
+private val DarkColorScheme = darkColorScheme(
+ primary = Blue500,
+ secondary = Pink500,
+ tertiary = Color.White
+)
+
+private val LightColorScheme = lightColorScheme(
+ primary = Blue500,
+ secondary = Pink500,
+ tertiary = Color.Black
+
+ /* Other default colors to override
+ background = Color(0xFFFFFBFE),
+ surface = Color(0xFFFFFBFE),
+ onPrimary = Color.White,
+ onSecondary = Color.White,
+ onTertiary = Color.White,
+ onBackground = Color(0xFF1C1B1F),
+ onSurface = Color(0xFF1C1B1F),
+ */
+)
+
+@Composable
+fun HttpSmsTheme(
+ darkTheme: Boolean = isSystemInDarkTheme(),
+ // Dynamic color is available on Android 12+
+ dynamicColor: Boolean = true,
+ content: @Composable () -> Unit
+) {
+ val colorScheme = when {
+ dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
+ val context = LocalContext.current
+ if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
+ }
+
+ darkTheme -> DarkColorScheme
+ else -> LightColorScheme
+ }
+ val view = LocalView.current
+ if (!view.isInEditMode) {
+ SideEffect {
+ val window = (view.context as Activity).window
+ window.statusBarColor = colorScheme.background.toArgb()
+ WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = !darkTheme
+ }
+ }
+
+ MaterialTheme(
+ colorScheme = colorScheme,
+ typography = Typography,
+ content = content
+ )
+}
diff --git a/android/app/src/main/java/com/httpsms/ui/theme/Typography.kt b/android/app/src/main/java/com/httpsms/ui/theme/Typography.kt
new file mode 100644
index 00000000..d8030fef
--- /dev/null
+++ b/android/app/src/main/java/com/httpsms/ui/theme/Typography.kt
@@ -0,0 +1,17 @@
+package com.httpsms.ui.theme
+
+import androidx.compose.material3.Typography
+import androidx.compose.ui.text.TextStyle
+import androidx.compose.ui.text.font.FontFamily
+import androidx.compose.ui.text.font.FontWeight
+import androidx.compose.ui.unit.sp
+
+val Typography = Typography(
+ bodyLarge = TextStyle(
+ fontFamily = FontFamily.Default,
+ fontWeight = FontWeight.Normal,
+ fontSize = 16.sp,
+ lineHeight = 24.sp,
+ letterSpacing = 0.5.sp
+ )
+)
diff --git a/android/app/src/main/res/layout/activity_login.xml b/android/app/src/main/res/layout/activity_login.xml
deleted file mode 100644
index 03552be5..00000000
--- a/android/app/src/main/res/layout/activity_login.xml
+++ /dev/null
@@ -1,188 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<androidx.core.widget.NestedScrollView 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:fillViewport="true">
-
- <androidx.constraintlayout.widget.ConstraintLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:paddingStart="16dp"
- android:paddingEnd="16dp"
- android:paddingBottom="16dp">
-
- <ImageView
- android:id="@+id/imageView"
- android:layout_width="100dp"
- android:layout_height="100dp"
- android:layout_marginTop="64dp"
- android:contentDescription="@string/img_http_sms_logo"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintHorizontal_bias="0.498"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toTopOf="parent"
- app:srcCompat="@drawable/logo_cropped"
- tools:ignore="ImageContrastCheck" />
-
- <TextView
- android:id="@+id/textView"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_marginTop="32dp"
- android:layout_marginBottom="24dp"
- android:autoLink="web"
- android:lineHeight="28sp"
- android:text="@string/get_your_api_key"
- android:textAlignment="center"
- android:textSize="20sp"
- app:layout_constraintBottom_toTopOf="@+id/loginApiKeyTextInputLayout"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toBottomOf="@+id/imageView"
- app:layout_constraintVertical_bias="0"
- app:layout_constraintVertical_chainStyle="packed" />
-
- <com.google.android.material.textfield.TextInputLayout
- android:id="@+id/loginApiKeyTextInputLayout"
- style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:hint="@string/text_area_api_key"
- app:errorEnabled="true"
- app:endIconMode="custom"
- app:endIconDrawable="@android:drawable/ic_menu_camera"
- app:endIconContentDescription="cameraButton"
- app:layout_constraintBottom_toTopOf="@+id/loginPhoneNumberLayoutSIM1"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toBottomOf="@+id/textView">
-
- <com.google.android.material.textfield.TextInputEditText
- android:id="@+id/loginApiKeyTextInput"
- android:layout_width="match_parent"
- android:imeOptions="actionDone"
- android:inputType="text"
- android:layout_height="wrap_content"
- tools:ignore="TextContrastCheck" />
-
- </com.google.android.material.textfield.TextInputLayout>
-
- <com.google.android.material.textfield.TextInputLayout
- android:id="@+id/loginPhoneNumberLayoutSIM1"
- style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_marginTop="8dp"
- android:hint="@string/login_phone_number_sim1"
- app:errorEnabled="true"
- app:placeholderText="@string/login_phone_number_hint"
- app:layout_constraintBottom_toTopOf="@+id/loginPhoneNumberLayoutSIM2"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toBottomOf="@+id/loginApiKeyTextInputLayout">
-
- <com.google.android.material.textfield.TextInputEditText
- android:id="@+id/loginPhoneNumberInputSIM1"
- android:layout_width="match_parent"
- android:inputType="text"
- android:layout_height="wrap_content"
- android:imeOptions="actionDone"
- tools:ignore="TextContrastCheck" />
-
- </com.google.android.material.textfield.TextInputLayout>
-
- <com.google.android.material.textfield.TextInputLayout
- android:id="@+id/loginPhoneNumberLayoutSIM2"
- style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_marginTop="8dp"
- android:hint="@string/login_phone_number_sim2"
- app:errorEnabled="true"
- app:placeholderText="@string/login_phone_number_hint"
- app:layout_constraintBottom_toTopOf="@+id/loginServerUrlLayoutContainer"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toBottomOf="@+id/loginPhoneNumberLayoutSIM1">
-
- <com.google.android.material.textfield.TextInputEditText
- android:id="@+id/loginPhoneNumberInputSIM2"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:imeOptions="actionDone"
- android:inputType="text"
- tools:ignore="TextContrastCheck" />
-
- </com.google.android.material.textfield.TextInputLayout>
-
- <LinearLayout
- android:id="@+id/loginServerUrlLayoutContainer"
- android:orientation="vertical"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_marginTop="8dp"
- app:layout_constraintBottom_toTopOf="@+id/linearLayout"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toBottomOf="@+id/loginPhoneNumberLayoutSIM2">
- <com.google.android.material.textfield.TextInputLayout
- android:id="@+id/loginServerUrlLayout"
- style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:hint="@string/server_url"
- app:errorEnabled="true"
- app:placeholderText="@string/login_server_url_hint">
-
- <com.google.android.material.textfield.TextInputEditText
- android:id="@+id/loginServerUrlInput"
- android:layout_width="match_parent"
- android:imeOptions="actionDone"
- android:inputType="text"
- android:layout_height="wrap_content"
- tools:ignore="TextContrastCheck" />
-
- </com.google.android.material.textfield.TextInputLayout>
- </LinearLayout>
-
- <LinearLayout
- android:id="@+id/linearLayout"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_marginTop="16dp"
- android:orientation="vertical"
- android:gravity="center"
- app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toBottomOf="@+id/loginServerUrlLayoutContainer">
-
- <com.google.android.material.button.MaterialButton
- android:id="@+id/loginButton"
- style="@style/Widget.MaterialComponents.Button.Icon"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:backgroundTint="#2196f3"
- android:drawableTint="@color/white"
- android:padding="10dp"
- android:text="@string/sign_in_button"
- android:textColor="@color/white"
- android:textSize="16sp"
- app:icon="@drawable/ic_login"
- app:iconTint="@color/white"
- tools:ignore="TextContrastCheck" />
-
- <com.google.android.material.progressindicator.LinearProgressIndicator
- android:id="@+id/loginProgressIndicator"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginTop="4dp"
- android:indeterminate="true"
- android:visibility="invisible"
- app:indicatorColor="@color/pink_500" />
- </LinearLayout>
-
- </androidx.constraintlayout.widget.ConstraintLayout>
-</androidx.core.widget.NestedScrollView>
diff --git a/android/app/src/main/res/layout/activity_main.xml b/android/app/src/main/res/layout/activity_main.xml
deleted file mode 100644
index 75849475..00000000
--- a/android/app/src/main/res/layout/activity_main.xml
+++ /dev/null
@@ -1,232 +0,0 @@
-<?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"
- android:fitsSystemWindows="true"
- tools:context=".MainActivity">
-
- <ImageView
- android:id="@+id/imageView"
- android:layout_width="147dp"
- android:layout_height="92dp"
- android:layout_marginTop="16dp"
- android:contentDescription="@string/img_http_sms_logo"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toTopOf="parent"
- app:srcCompat="@drawable/logo_cropped"
- tools:ignore="ImageContrastCheck" />
-
- <com.google.android.material.card.MaterialCardView
- android:id="@+id/mainPhoneCard"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:elevation="16dp"
- android:layout_marginTop="24dp"
- android:layout_marginStart="16dp"
- android:layout_marginEnd="16dp"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toBottomOf="@+id/imageView">
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical"
- android:padding="16dp">
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="horizontal">
-
- <TextView
- android:id="@+id/cardPhoneNumber"
- android:layout_width="wrap_content"
- android:layout_height="match_parent"
- android:text="@string/phone_number"
- android:drawablePadding="5dp"
- android:textAppearance="?attr/textAppearanceTitleMedium"
- android:textColor="?android:attr/textColorPrimary"
- app:drawableTint="#70ab5c"
- app:drawableEndCompat="@drawable/baseline_check_circle_24"
- android:textSize="28sp" />
- </LinearLayout>
-
- <TextView
- android:id="@+id/cardRefreshTime"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginTop="8dp"
- android:text="@string/nextRefreshTime"
- android:textAppearance="?attr/textAppearanceBodyMedium"
- android:textColor="?android:attr/textColorSecondary"
- android:textSize="16sp" />
-
- </LinearLayout>
- </com.google.android.material.card.MaterialCardView>
-
- <com.google.android.material.card.MaterialCardView
- android:id="@+id/mainPhoneCardSIM2"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:elevation="16dp"
- android:layout_marginTop="24dp"
- android:layout_marginStart="16dp"
- android:layout_marginEnd="16dp"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toBottomOf="@+id/mainPhoneCard">
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical"
- android:padding="16dp">
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="horizontal">
-
- <TextView
- android:id="@+id/cardPhoneNumberSIM2"
- android:layout_width="wrap_content"
- android:layout_height="match_parent"
- android:drawablePadding="5dp"
- android:text="@string/phone_number"
- android:textAppearance="?attr/textAppearanceTitleMedium"
- android:textColor="?android:attr/textColorPrimary"
- app:drawableTint="#70ab5c"
- app:drawableEndCompat="@drawable/baseline_check_circle_24"
- android:textSize="28sp" />
-
- </LinearLayout>
-
- <TextView
- android:id="@+id/cardRefreshTimeSIM2"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginTop="8dp"
- android:text="@string/nextRefreshTime"
- android:textAppearance="?attr/textAppearanceBodyMedium"
- android:textColor="?android:attr/textColorSecondary"
- android:textSize="16sp" />
-
- </LinearLayout>
- </com.google.android.material.card.MaterialCardView>
-
- <LinearLayout
- android:id="@+id/batteryOptimizationLinearLayout"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_marginTop="16dp"
- android:layout_marginStart="16dp"
- android:layout_marginEnd="16dp"
- android:orientation="vertical"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toBottomOf="@+id/mainPhoneCardSIM2">
-
- <com.google.android.material.button.MaterialButton
- android:id="@+id/smsPermissionButton"
- style="@style/Widget.MaterialComponents.Button.Icon"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginBottom="8dp"
- android:backgroundTint="#4CAF50"
- android:padding="10dp"
- android:text="@string/enable_sms_permission"
- android:textColor="@color/white"
- android:textSize="16sp"
- android:visibility="gone"
- app:icon="@drawable/open_in_new_24"
- app:iconGravity="textEnd"
- app:iconPadding="8dp"
- app:iconTint="@color/white"
- tools:ignore="TextContrastCheck" />
-
- <com.google.android.material.button.MaterialButton
- android:id="@+id/batteryOptimizationButtonButton"
- style="@style/Widget.MaterialComponents.Button.Icon"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:backgroundTint="@color/pink_500"
- android:drawableTint="@color/white"
- android:padding="10dp"
- app:icon="@android:drawable/ic_lock_idle_low_battery"
- android:text="@string/disable_battery_optimization"
- android:textColor="@color/white"
- android:textSize="16sp"
- app:iconTint="@color/white"
- tools:ignore="TextContrastCheck" />
- </LinearLayout>
-
- <LinearLayout
- android:id="@+id/linearLayout"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_marginTop="16dp"
- android:layout_marginStart="16dp"
- android:layout_marginEnd="16dp"
- android:orientation="vertical"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toBottomOf="@+id/batteryOptimizationLinearLayout">
-
- <com.google.android.material.button.MaterialButton
- android:id="@+id/mainHeartbeatButton"
- style="@style/Widget.MaterialComponents.Button.Icon"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:backgroundTint="#2196f3"
- android:drawableTint="@color/white"
- android:padding="10dp"
- android:text="@string/send_heartbeat"
- android:textColor="@color/white"
- android:textSize="16sp"
- app:iconTint="@color/white"
- tools:ignore="TextContrastCheck" />
-
- <com.google.android.material.progressindicator.LinearProgressIndicator
- android:id="@+id/mainProgressIndicator"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginTop="4dp"
- android:indeterminate="true"
- android:visibility="invisible"
- app:indicatorColor="@color/pink_500" />
- </LinearLayout>
-
- <TextView
- android:id="@+id/mainAppVersion"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginTop="16dp"
- android:text="@string/app_version"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toBottomOf="@+id/linearLayout" />
-
- <com.google.android.material.button.MaterialButton
- android:id="@+id/mainSettingsButton"
- 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_app_settings"
- android:textColor="@color/white"
- android:textSize="16sp"
- app:icon="@drawable/baseline_settings_24"
- 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/layout/activity_settings.xml b/android/app/src/main/res/layout/activity_settings.xml
deleted file mode 100644
index bfc078ca..00000000
--- a/android/app/src/main/res/layout/activity_settings.xml
+++ /dev/null
@@ -1,200 +0,0 @@
-<?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"
- android:fitsSystemWindows="true">
-
- <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:background="@color/black"
- app:layout_constraintTop_toTopOf="parent"
- app:navigationIcon="?attr/homeAsUpIndicator"
- app:title="App Settings" />
- </com.google.android.material.appbar.AppBarLayout>
-
-
- <ScrollView
- android:layout_width="match_parent"
- android:layout_height="0dp"
- android:fillViewport="true"
- app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintTop_toBottomOf="@+id/settings_app_bar_layout">
-
- <LinearLayout
- android:id="@+id/linearLayout2"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginTop="16dp"
- android:orientation="vertical"
- android:paddingLeft="16dp"
- android:paddingRight="16dp">
-
- <com.google.android.material.textfield.TextInputLayout
- android:id="@+id/settingsSIM1"
- style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:hint="@string/settings_sim1"
- app:errorEnabled="true"
- android:layout_marginTop="16dp"
- tools:layout_editor_absoluteX="16dp">
-
- <com.google.android.material.textfield.TextInputEditText
- android:id="@+id/settingsSIM1Input"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:inputType="textMultiLine"
- tools:ignore="TextContrastCheck" />
-
- </com.google.android.material.textfield.TextInputLayout>
-
- <com.google.android.material.switchmaterial.SwitchMaterial
- android:id="@+id/settings_sim1_outgoing_messages"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginBottom="16dp"
- android:minHeight="48dp"
- android:text="@string/settings_outgoing_messages_sim1"
- android:textSize="18sp"
- tools:ignore="TouchTargetSizeCheck" />
-
- <com.google.android.material.switchmaterial.SwitchMaterial
- android:id="@+id/settings_sim1_incoming_messages"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginBottom="16dp"
- android:minHeight="48dp"
- android:text="@string/settings_incoming_messages_sim1"
- android:textSize="18sp"
- tools:ignore="TouchTargetSizeCheck" />
-
-
- <com.google.android.material.switchmaterial.SwitchMaterial
- android:id="@+id/settingsSim1EnableIncomingCallEvents"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginBottom="16dp"
- android:minHeight="48dp"
- android:text="@string/enable_incoming_call_events_sim1"
- android:textSize="18sp"
- tools:ignore="TouchTargetSizeCheck" />
-
- <com.google.android.material.textfield.TextInputLayout
- android:id="@+id/settingsSIM2Layout"
- style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:hint="@string/settings_sim_2"
- app:errorEnabled="true"
- tools:layout_editor_absoluteX="16dp">
-
- <com.google.android.material.textfield.TextInputEditText
- android:id="@+id/settingsSIM2InputEdit"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:inputType="textMultiLine"
- tools:ignore="TextContrastCheck" />
-
- </com.google.android.material.textfield.TextInputLayout>
-
- <com.google.android.material.switchmaterial.SwitchMaterial
- android:id="@+id/settings_sim2_outgoing_messages"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginBottom="16dp"
- android:minHeight="48dp"
- android:text="@string/settings_outgoing_messages_sim2"
- android:textSize="18sp"
- tools:ignore="TouchTargetSizeCheck" />
-
- <com.google.android.material.switchmaterial.SwitchMaterial
- android:id="@+id/settings_sim2_incoming_messages"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginBottom="16dp"
- android:minHeight="48dp"
- android:text="@string/settings_incoming_messages_sim2"
- android:textSize="18sp"
- tools:ignore="TouchTargetSizeCheck" />
-
- <com.google.android.material.switchmaterial.SwitchMaterial
- android:id="@+id/settingsSim2EnableIncomingCallEvents"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginBottom="16dp"
- android:minHeight="48dp"
- android:text="@string/enable_sim2_incoming_call_events"
- android:textSize="18sp"
- tools:ignore="TouchTargetSizeCheck" />
-
- <com.google.android.material.textfield.TextInputLayout
- android:id="@+id/settingsEncryptionKeyLayout"
- style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:hint="@string/encryption_key"
- app:errorEnabled="true"
- tools:layout_editor_absoluteX="16dp">
-
- <com.google.android.material.textfield.TextInputEditText
- android:id="@+id/settingsEncryptionKeyInputEdit"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:inputType="textMultiLine"
- tools:ignore="TextContrastCheck" />
-
- </com.google.android.material.textfield.TextInputLayout>
-
- <com.google.android.material.switchmaterial.SwitchMaterial
- android:id="@+id/settingsEncryptReceivedMessages"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginBottom="16dp"
- android:minHeight="48dp"
- android:text="@string/encrypt_received_messages"
- android:textSize="18sp"
- tools:ignore="TouchTargetSizeCheck" />
-
- <com.google.android.material.switchmaterial.SwitchMaterial
- android:id="@+id/settingEnableDebugLogs"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginBottom="16dp"
- android:minHeight="48dp"
- android:text="@string/enable_debug_logs"
- android:textSize="18sp"
- tools:ignore="TouchTargetSizeCheck" />
-
-
- <com.google.android.material.button.MaterialButton
- android:id="@+id/settingsLogoutButton"
- style="@style/Widget.MaterialComponents.Button.Icon"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginBottom="24dp"
- 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:iconTint="@color/white"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- tools:ignore="TextContrastCheck" />
- </LinearLayout>
- </ScrollView>
-
-</androidx.constraintlayout.widget.ConstraintLayout>
diff --git a/android/build.gradle.kts b/android/build.gradle.kts
index ee8d1b8d..3be829b6 100644
--- a/android/build.gradle.kts
+++ b/android/build.gradle.kts
@@ -5,13 +5,15 @@ buildscript {
mavenCentral()
}
dependencies {
- classpath("com.google.gms:google-services:4.4.2")
+ classpath("com.google.gms:google-services:4.5.0")
}
}
plugins {
id("com.android.application") version "9.2.1" apply false
id("com.android.library") version "9.2.1" apply false
+ id("org.jetbrains.kotlin.android") version "2.4.0" apply false
+ id("org.jetbrains.kotlin.plugin.compose") version "2.4.0" apply false
}
tasks.register<Delete>("clean") {
diff --git a/web/app/pages/heartbeats/[id].vue b/web/app/pages/heartbeats/[id].vue
index 679fd36b..8a05d694 100644
--- a/web/app/pages/heartbeats/[id].vue
+++ b/web/app/pages/heartbeats/[id].vue
@@ -170,7 +170,7 @@ onMounted(async () => {
</VAppBar>
<VContainer>
<VRow>
- <VCol cols="12" class="mt-n8">
+ <VCol cols="12" class="mt-n4">
<p>
Every 15 minutes, the httpSMS app on your Android phone sends a
heartbeat event to the httpsms API to show that it is alive. The