Skip to content

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

Fix user loading

Acho Arnold5e796f7998be
diff --git a/android/app/src/main/java/com/httpsms/DeliveredReceiver.kt b/android/app/src/main/java/com/httpsms/DeliveredReceiver.kt
index 18bb8856..eb2f9d4b 100644
--- a/android/app/src/main/java/com/httpsms/DeliveredReceiver.kt
+++ b/android/app/src/main/java/com/httpsms/DeliveredReceiver.kt
@@ -12,32 +12,31 @@ import java.time.ZonedDateTime
internal class DeliveredReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
when (resultCode) {
- Activity.RESULT_OK -> handleMessageDelivered(intent.getStringExtra(Constants.KEY_MESSAGE_ID))
- else -> handleMessageFailed(intent.getStringExtra(Constants.KEY_MESSAGE_ID))
+ Activity.RESULT_OK -> handleMessageDelivered(context, intent.getStringExtra(Constants.KEY_MESSAGE_ID))
+ else -> handleMessageFailed(context, intent.getStringExtra(Constants.KEY_MESSAGE_ID))
}
}
- private fun handleMessageDelivered(messageId: String?) {
+ private fun handleMessageDelivered(context: Context, messageId: String?) {
val timestamp = ZonedDateTime.now(ZoneOffset.UTC)
+ if (!Receiver.isValid(context, messageId)) {
+ return
+ }
Thread {
Timber.i("delivered message with ID [${messageId}]")
- if (messageId == null) {
- Timber.e("cannot handle event because the message ID is null")
- return@Thread
- }
- HttpSmsApiService().sendDeliveredEvent(messageId, timestamp)
+ HttpSmsApiService(Settings.getApiKeyOrDefault(context)).sendDeliveredEvent(messageId!!, timestamp)
}.start()
}
- private fun handleMessageFailed(messageId: String?) {
+ private fun handleMessageFailed(context: Context, messageId: String?) {
val timestamp = ZonedDateTime.now(ZoneOffset.UTC)
+ if (!Receiver.isValid(context, messageId)) {
+ return
+ }
+
Thread {
Timber.i("message with ID [${messageId}] not delivered")
- if (messageId == null) {
- Timber.e("cannot handle event because the message ID is null")
- return@Thread
- }
- HttpSmsApiService().sendFailedEvent(messageId,timestamp, "NOT_DELIVERED")
+ HttpSmsApiService(Settings.getApiKeyOrDefault(context)).sendFailedEvent(messageId!!,timestamp, "NOT_DELIVERED")
}.start()
}
}
diff --git a/android/app/src/main/java/com/httpsms/FirebaseMessagingService.kt b/android/app/src/main/java/com/httpsms/FirebaseMessagingService.kt
index 747fdd2a..da015ea0 100644
--- a/android/app/src/main/java/com/httpsms/FirebaseMessagingService.kt
+++ b/android/app/src/main/java/com/httpsms/FirebaseMessagingService.kt
@@ -51,22 +51,19 @@ class MyFirebaseMessagingService : FirebaseMessagingService() {
}
private fun sendRegistrationToServer(token: String) {
Timber.d("sendRegistrationTokenToServer($token)")
- Settings.setApiKeyAsync(this, token)
+ Settings.setFcmTokenAsync(this, token)
if (Settings.isLoggedIn(this)) {
Timber.d("updating phone with new fcm token")
- HttpSmsApiService().updatePhone(Settings.getPhoneOrDefault(this), token)
+ HttpSmsApiService(Settings.getApiKeyOrDefault(this)).updatePhone(Settings.getOwnerOrDefault(this), token)
}
- }
- companion object {
- private val TAG = MyFirebaseMessagingService::class.simpleName
}
internal class SendSmsWorker(appContext: Context, workerParams: WorkerParameters) : Worker(appContext, workerParams) {
override fun doWork(): Result {
val owner = Settings.getOwner(applicationContext) ?: return Result.failure()
- val message = getMessage(owner) ?: return Result.failure()
+ val message = getMessage(applicationContext, owner) ?: return Result.failure()
registerReceivers()
@@ -79,9 +76,9 @@ class MyFirebaseMessagingService : FirebaseMessagingService() {
return Result.success()
}
- private fun getMessage(owner: String): Message? {
+ private fun getMessage(context: Context, owner: String): Message? {
Timber.d("fetching message")
- val messages = HttpSmsApiService().getOutstandingMessages(owner)
+ val messages = HttpSmsApiService(Settings.getApiKeyOrDefault(context)).getOutstandingMessages(owner)
if (messages.isNotEmpty()) {
Timber.d("fetched message with ID [${messages.first().id}]")
diff --git a/android/app/src/main/java/com/httpsms/HttpSmsApiService.kt b/android/app/src/main/java/com/httpsms/HttpSmsApiService.kt
index ee7d8819..a333faaf 100644
--- a/android/app/src/main/java/com/httpsms/HttpSmsApiService.kt
+++ b/android/app/src/main/java/com/httpsms/HttpSmsApiService.kt
@@ -1,6 +1,5 @@
package com.httpsms
-import android.util.Log
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.Request
@@ -10,11 +9,12 @@ import java.net.URI
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
import java.util.logging.Level
-import java.util.logging.Logger.*
+import java.util.logging.Logger.getLogger
-class HttpSmsApiService {
- private val baseURL = URI("https://eooi9srbmxw09ng.m.pipedream.net")
+class HttpSmsApiService(private val apiKey: String) {
+ private val apiKeyHeader = "X-API-KEY"
+ private val baseURL = URI("https://api.httpsms.com")
private val jsonMediaType = "application/json; charset=utf-8".toMediaType()
init {
@@ -26,6 +26,7 @@ class HttpSmsApiService {
val request: Request = Request.Builder()
.url(baseURL.resolve("/v1/messages/outstanding?owner=${owner}").toURL())
+ .header(apiKeyHeader, apiKey)
.build()
val response = client.newCall(request).execute()
@@ -74,6 +75,7 @@ class HttpSmsApiService {
val request: Request = Request.Builder()
.url(baseURL.resolve("/v1/messages/receive").toURL())
.post(body.toRequestBody(jsonMediaType))
+ .header(apiKeyHeader, apiKey)
.build()
val response = client.newCall(request).execute()
@@ -105,6 +107,7 @@ class HttpSmsApiService {
val request: Request = Request.Builder()
.url(baseURL.resolve("/v1/messages/${messageId}/events").toURL())
.post(body.toRequestBody(jsonMediaType))
+ .header(apiKeyHeader, apiKey)
.build()
val response = client.newCall(request).execute()
@@ -131,6 +134,7 @@ class HttpSmsApiService {
val request: Request = Request.Builder()
.url(baseURL.resolve("/v1/phones").toURL())
.put(body.toRequestBody(jsonMediaType))
+ .header(apiKeyHeader, apiKey)
.build()
val response = client.newCall(request).execute()
@@ -142,4 +146,25 @@ class HttpSmsApiService {
response.close()
Timber.i("fcm token sent successfully for phone [$phoneNumber]" )
}
+
+
+ fun validateApiKey(): String? {
+ val client = OkHttpClient()
+
+ val request: Request = Request.Builder()
+ .url(baseURL.resolve("/v1/users/me").toURL())
+ .header(apiKeyHeader, apiKey)
+ .get()
+ .build()
+
+ val response = client.newCall(request).execute()
+ if (!response.isSuccessful) {
+ Timber.e("error response [${response.body?.string()}] with code [${response.code}] while verifying apiKey [$apiKey]")
+ return "Cannot validate the API key. Check if it is correct and try again."
+ }
+
+ response.close()
+ Timber.i("api key [$apiKey] is valid" )
+ return null
+ }
}
diff --git a/android/app/src/main/java/com/httpsms/LoginActivity.kt b/android/app/src/main/java/com/httpsms/LoginActivity.kt
index 1ff57558..c878f3b9 100644
--- a/android/app/src/main/java/com/httpsms/LoginActivity.kt
+++ b/android/app/src/main/java/com/httpsms/LoginActivity.kt
@@ -1,11 +1,69 @@
package com.httpsms
import android.os.Bundle
+import android.view.View
import androidx.appcompat.app.AppCompatActivity
+import androidx.lifecycle.MutableLiveData
+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 timber.log.Timber
class LoginActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_login)
+ registerListeners()
+ }
+
+ private fun registerListeners() {
+ loginButton().setOnClickListener { onLoginClick() }
+ }
+
+ private fun onLoginClick() {
+ Timber.e("login button clicked")
+ 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 liveData = MutableLiveData<String?>()
+ liveData.observe(this) { authResult ->
+ run {
+ progressBar.visibility = View.INVISIBLE
+ if (authResult != null) {
+ apiKey.isEnabled = true
+ loginButton().isEnabled = true
+ apiKeyLayout.error = authResult
+ return@run
+ }
+ Settings.setApiKeyAsync(this, apiKey.text.toString())
+ redirectToMain()
+ }
+ }
+
+ Thread {
+ val error = HttpSmsApiService(apiKey.text.toString()).validateApiKey()
+ liveData.postValue(error)
+ Timber.i("login successful")
+ }.start()
+ }
+
+
+ private fun redirectToMain() {
+ if (!Settings.isLoggedIn(this)) {
+ return
+ }
+ finish()
+ }
+
+ private fun loginButton(): MaterialButton {
+ return findViewById(R.id.loginButton)
}
}
diff --git a/android/app/src/main/java/com/httpsms/Models.kt b/android/app/src/main/java/com/httpsms/Models.kt
index 2c0e88dd..6aea90aa 100644
--- a/android/app/src/main/java/com/httpsms/Models.kt
+++ b/android/app/src/main/java/com/httpsms/Models.kt
@@ -4,7 +4,8 @@
package com.httpsms
-import com.beust.klaxon.*
+import com.beust.klaxon.Json
+import com.beust.klaxon.Klaxon
private val klaxon = Klaxon()
@@ -14,7 +15,7 @@ data class ResponseMessagesOutstanding (
val status: String
) {
companion object {
- public fun fromJson(json: String) = klaxon.parse<ResponseMessagesOutstanding>(json)
+ fun fromJson(json: String) = klaxon.parse<ResponseMessagesOutstanding>(json)
}
}
@@ -24,7 +25,7 @@ data class ResponseMessage (
val status: String
) {
companion object {
- public fun fromJson(json: String) = klaxon.parse<ResponseMessage>(json)
+ fun fromJson(json: String) = klaxon.parse<ResponseMessage>(json)
}
}
diff --git a/android/app/src/main/java/com/httpsms/ReceivedReceiver.kt b/android/app/src/main/java/com/httpsms/ReceivedReceiver.kt
index b0df89dd..f4c35f6f 100644
--- a/android/app/src/main/java/com/httpsms/ReceivedReceiver.kt
+++ b/android/app/src/main/java/com/httpsms/ReceivedReceiver.kt
@@ -25,17 +25,18 @@ class ReceivedReceiver: BroadcastReceiver()
}
handleMessageReceived(
+ context,
smsSender,
- Settings.getOwner(context) ?: Settings.DEFAULT_PHONE_NUMBER,
+ Settings.getOwnerOrDefault(context),
smsBody
)
}
- private fun handleMessageReceived(from: String, to : String, content: String) {
+ private fun handleMessageReceived(context: Context, from: String, to : String, content: String) {
val timestamp = ZonedDateTime.now(ZoneOffset.UTC)
Thread {
Timber.i("forwarding received message from [${from}]")
- HttpSmsApiService().receive(from, to, content, timestamp)
+ HttpSmsApiService(Settings.getApiKeyOrDefault(context)).receive(from, to, content, timestamp)
}.start()
}
}
diff --git a/android/app/src/main/java/com/httpsms/Receiver.kt b/android/app/src/main/java/com/httpsms/Receiver.kt
new file mode 100644
index 00000000..8c832ff8
--- /dev/null
+++ b/android/app/src/main/java/com/httpsms/Receiver.kt
@@ -0,0 +1,19 @@
+package com.httpsms
+
+import android.content.Context
+import timber.log.Timber
+
+object Receiver {
+ fun isValid(context: Context, messageId: String?): Boolean {
+ if (messageId == null) {
+ Timber.e("cannot handle event because the message ID is null")
+ return false
+ }
+
+ if (Settings.isLoggedIn(context)) {
+ Timber.w("cannot handle message with id [$messageId] because the user is not logged in")
+ return false
+ }
+ return true
+ }
+}
diff --git a/android/app/src/main/java/com/httpsms/SentReceiver.kt b/android/app/src/main/java/com/httpsms/SentReceiver.kt
index b15a2d81..6c251277 100644
--- a/android/app/src/main/java/com/httpsms/SentReceiver.kt
+++ b/android/app/src/main/java/com/httpsms/SentReceiver.kt
@@ -12,36 +12,36 @@ import java.time.ZonedDateTime
internal class SentReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
when (resultCode) {
- Activity.RESULT_OK -> handleMessageSent(intent.getStringExtra(Constants.KEY_MESSAGE_ID))
- SmsManager.RESULT_ERROR_GENERIC_FAILURE -> handleMessageFailed(intent.getStringExtra(Constants.KEY_MESSAGE_ID), "GENERIC_FAILURE")
- SmsManager.RESULT_ERROR_NO_SERVICE -> handleMessageFailed(intent.getStringExtra(Constants.KEY_MESSAGE_ID), "NO_SERVICE")
- SmsManager.RESULT_ERROR_NULL_PDU -> handleMessageFailed(intent.getStringExtra(Constants.KEY_MESSAGE_ID), "NULL_PDU")
- SmsManager.RESULT_ERROR_RADIO_OFF -> handleMessageFailed(intent.getStringExtra(Constants.KEY_MESSAGE_ID), "RADIO_OFF")
- else -> handleMessageFailed(intent.getStringExtra(Constants.KEY_MESSAGE_ID), "UNKNOWN")
+ Activity.RESULT_OK -> handleMessageSent(context, intent.getStringExtra(Constants.KEY_MESSAGE_ID))
+ SmsManager.RESULT_ERROR_GENERIC_FAILURE -> handleMessageFailed(context, intent.getStringExtra(Constants.KEY_MESSAGE_ID), "GENERIC_FAILURE")
+ SmsManager.RESULT_ERROR_NO_SERVICE -> handleMessageFailed(context, intent.getStringExtra(Constants.KEY_MESSAGE_ID), "NO_SERVICE")
+ SmsManager.RESULT_ERROR_NULL_PDU -> handleMessageFailed(context, intent.getStringExtra(Constants.KEY_MESSAGE_ID), "NULL_PDU")
+ SmsManager.RESULT_ERROR_RADIO_OFF -> handleMessageFailed(context, intent.getStringExtra(Constants.KEY_MESSAGE_ID), "RADIO_OFF")
+ else -> handleMessageFailed(context, intent.getStringExtra(Constants.KEY_MESSAGE_ID), "UNKNOWN")
}
}
- private fun handleMessageSent(messageId: String?) {
+ private fun handleMessageSent(context: Context, messageId: String?) {
val timestamp = ZonedDateTime.now(ZoneOffset.UTC)
+ if (!Receiver.isValid(context, messageId)) {
+ return
+ }
+
Thread {
Timber.d("sent message with ID [${messageId}]")
- if (messageId == null) {
- Timber.e("cannot handle event because the message ID is null")
- return@Thread
- }
- HttpSmsApiService().sendSentEvent(messageId,timestamp)
+ HttpSmsApiService(Settings.getApiKeyOrDefault(context)).sendSentEvent(messageId!!,timestamp)
}.start()
}
- private fun handleMessageFailed(messageId: String?, reason: String) {
+ private fun handleMessageFailed(context: Context, messageId: String?, reason: String) {
val timestamp = ZonedDateTime.now(ZoneOffset.UTC)
+ if (!Receiver.isValid(context, messageId)) {
+ return
+ }
+
Thread {
Timber.i("message with ID [${messageId}] not sent with reason [$reason]")
- if (messageId == null) {
- Timber.e("cannot handle event because the message ID is null")
- return@Thread
- }
- HttpSmsApiService().sendFailedEvent(messageId, timestamp, reason)
+ HttpSmsApiService(Settings.getApiKeyOrDefault(context)).sendFailedEvent(messageId!!, timestamp, reason)
}.start()
}
}
diff --git a/android/app/src/main/java/com/httpsms/Settings.kt b/android/app/src/main/java/com/httpsms/Settings.kt
index 5775e31d..309bcf1e 100644
--- a/android/app/src/main/java/com/httpsms/Settings.kt
+++ b/android/app/src/main/java/com/httpsms/Settings.kt
@@ -5,7 +5,7 @@ import androidx.preference.PreferenceManager
import timber.log.Timber
object Settings {
- const val DEFAULT_PHONE_NUMBER = "NO_PHONE_NUMBER"
+ private const val DEFAULT_PHONE_NUMBER = "66836863" // NOT_FOUND :)
private const val SETTINGS_OWNER = "SETTINGS_OWNER"
private const val SETTINGS_ACTIVE = "SETTINGS_ACTIVE_STATUS"
@@ -28,7 +28,7 @@ object Settings {
return owner
}
- fun getPhoneOrDefault(context: Context): String {
+ fun getOwnerOrDefault(context: Context): String {
return getOwner(context) ?: return DEFAULT_PHONE_NUMBER
}
@@ -65,15 +65,19 @@ object Settings {
return getApiKey(context) != null
}
- fun getApiKey(context: Context): String?{
+ private fun getApiKey(context: Context): String?{
Timber.d(Settings::getApiKey.name)
- val activeStatus = PreferenceManager
+ val apiKey = PreferenceManager
.getDefaultSharedPreferences(context)
.getString(this.SETTINGS_API_KEY,null)
- Timber.d("API_KEY: [$activeStatus]")
- return activeStatus
+ Timber.d("API_KEY: [$apiKey]")
+ return apiKey
+ }
+
+ fun getApiKeyOrDefault(context:Context): String {
+ return getApiKey(context) ?: ""
}
fun setApiKeyAsync(context: Context, apiKey: String) {
@@ -96,7 +100,7 @@ object Settings {
return activeStatus
}
- fun setFcmToken(context: Context, apiKey: String) {
+ fun setFcmTokenAsync(context: Context, apiKey: String) {
Timber.d(Settings::setApiKeyAsync.name)
PreferenceManager.getDefaultSharedPreferences(context)
diff --git a/android/app/src/main/java/com/httpsms/SmsManagerService.kt b/android/app/src/main/java/com/httpsms/SmsManagerService.kt
index 2269dff1..07d8f5a8 100644
--- a/android/app/src/main/java/com/httpsms/SmsManagerService.kt
+++ b/android/app/src/main/java/com/httpsms/SmsManagerService.kt
@@ -7,9 +7,9 @@ import android.telephony.SmsManager
class SmsManagerService {
companion object {
const val ACTION_SMS_SENT = "SMS_SENT"
- const val ACTION_SMS_RECEIVED = "SMS_RECEIVED"
const val ACTION_SMS_DELIVERED = "SMS_DELIVERED"
}
+
fun sendMessage(context: Context, message: Message, sentIntent:PendingIntent, deliveryIntent: PendingIntent) {
val smsManager: SmsManager = context.getSystemService(SmsManager::class.java)
smsManager.sendTextMessage(message.contact, message.owner, message.content, sentIntent, deliveryIntent)
diff --git a/android/app/src/main/res/layout/activity_login.xml b/android/app/src/main/res/layout/activity_login.xml
index 016b5e59..22f6a3d5 100644
--- a/android/app/src/main/res/layout/activity_login.xml
+++ b/android/app/src/main/res/layout/activity_login.xml
@@ -3,45 +3,9 @@
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:paddingLeft="16dp"
- android:paddingRight="16dp"
- android:layout_height="match_parent">
-
- <com.google.android.material.textfield.TextInputLayout
- android:id="@+id/textField"
- style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:hint="@string/text_area_api_key"
- app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintTop_toTopOf="parent">
-
- <com.google.android.material.textfield.TextInputEditText
- 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.button.MaterialButton
- android:id="@+id/button"
- style="@style/Widget.MaterialComponents.Button.Icon"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginTop="40dp"
- 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"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toBottomOf="@+id/textField"
- tools:ignore="TextContrastCheck" />
+ android:paddingRight="16dp">
<ImageView
android:id="@+id/imageView"
@@ -63,12 +27,73 @@
android:layout_marginBottom="20dp"
android:autoLink="web"
android:lineHeight="28sp"
+ android:text="@string/get_your_api_key"
android:textAlignment="center"
android:textSize="20sp"
- android:text="@string/get_your_api_key"
- app:layout_constraintBottom_toTopOf="@+id/textField"
+ app:layout_constraintBottom_toTopOf="@+id/loginApiKeyTextInputLayout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent" />
+ <com.google.android.material.textfield.TextInputLayout
+ android:id="@+id/loginApiKeyTextInputLayout"
+ style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ app:errorEnabled="true"
+ app:errorContentDescription="How are you"
+ android:hint="@string/text_area_api_key"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintTop_toTopOf="parent"
+ tools:layout_editor_absoluteX="16dp">
+
+ <com.google.android.material.textfield.TextInputEditText
+ android:id="@+id/loginApiKeyTextInput"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:inputType="textMultiLine"
+ tools:ignore="TextContrastCheck" />
+
+ </com.google.android.material.textfield.TextInputLayout>
+
+ <LinearLayout
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_weight="50"
+ android:orientation="vertical"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toBottomOf="@+id/loginApiKeyTextInputLayout">
+
+ <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:layout_marginTop="16dp"
+ 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"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toBottomOf="@+id/loginApiKeyTextInputLayout"
+ tools:ignore="TextContrastCheck" />
+
+ <com.google.android.material.progressindicator.LinearProgressIndicator
+ android:id="@+id/loginProgressIndicator"
+ android:layout_width="match_parent"
+ android:visibility="invisible"
+ android:layout_height="wrap_content"
+ android:indeterminate="true"
+ android:layout_marginTop="4dp"
+ app:indicatorColor="@color/pink_500"
+ app:layout_constraintTop_toBottomOf="@+id/button"
+ tools:layout_editor_absoluteX="16dp" />
+ </LinearLayout>
+
</androidx.constraintlayout.widget.ConstraintLayout>
diff --git a/android/app/src/main/res/values-night/themes.xml b/android/app/src/main/res/values-night/themes.xml
index 9d120d1c..e717addb 100644
--- a/android/app/src/main/res/values-night/themes.xml
+++ b/android/app/src/main/res/values-night/themes.xml
@@ -2,13 +2,13 @@
<!-- Base application theme. -->
<style name="Theme.HttpSMS" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Primary brand color. -->
- <item name="colorPrimary">@color/purple_200</item>
- <item name="colorPrimaryVariant">@color/purple_700</item>
- <item name="colorOnPrimary">@color/black</item>
+ <item name="colorPrimary">@color/blue_500</item>
+ <item name="colorPrimaryVariant">@color/blue_700</item>
+ <item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
- <item name="colorSecondary">@color/teal_200</item>
- <item name="colorSecondaryVariant">@color/teal_200</item>
- <item name="colorOnSecondary">@color/black</item>
+ <item name="colorSecondary">@color/pink_500</item>
+ <item name="colorSecondaryVariant">@color/pink_A400</item>
+ <item name="colorOnSecondary">@color/white</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">#121212</item>
<!-- Customize your theme here. -->
diff --git a/android/app/src/main/res/values/colors.xml b/android/app/src/main/res/values/colors.xml
index ca1931bc..87a74536 100644
--- a/android/app/src/main/res/values/colors.xml
+++ b/android/app/src/main/res/values/colors.xml
@@ -7,4 +7,9 @@
<color name="teal_700">#FF018786</color>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
+ <color name="blue_200">#90CAF9</color>
+ <color name="blue_500">#2196F3</color>
+ <color name="blue_700">#1976D2</color>
+ <color name="pink_A400">#F50057</color>
+ <color name="pink_500">#E91E63</color>
</resources>
diff --git a/android/app/src/main/res/values/themes.xml b/android/app/src/main/res/values/themes.xml
index f8f4268d..69dc47c9 100644
--- a/android/app/src/main/res/values/themes.xml
+++ b/android/app/src/main/res/values/themes.xml
@@ -2,15 +2,16 @@
<!-- Base application theme. -->
<style name="Theme.HttpSMS" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Primary brand color. -->
- <item name="colorPrimary">@color/purple_500</item>
- <item name="colorPrimaryVariant">@color/purple_700</item>
+ <item name="colorPrimary">@color/blue_500</item>
+ <item name="colorPrimaryVariant">@color/blue_700</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
- <item name="colorSecondary">@color/teal_200</item>
- <item name="colorSecondaryVariant">@color/teal_700</item>
- <item name="colorOnSecondary">@color/black</item>
+ <item name="colorSecondary">@color/pink_500</item>
+ <item name="colorSecondaryVariant">@color/pink_A400</item>
+ <item name="colorOnSecondary">@color/white</item>
<!-- Status bar color. -->
- <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
+ <item name="android:statusBarColor" tools:targetApi="l">#121212</item>
<!-- Customize your theme here. -->
</style>
+
</resources>
diff --git a/api/pkg/repositories/gorm_user_repository.go b/api/pkg/repositories/gorm_user_repository.go
index 0b55167c..ddb5a5dd 100644
--- a/api/pkg/repositories/gorm_user_repository.go
+++ b/api/pkg/repositories/gorm_user_repository.go
@@ -60,7 +60,7 @@ func (repository *gormUserRepository) Update(ctx context.Context, user *entities
return nil
}
-func (repository *gormUserRepository) LoadAuthUser(ctx context.Context, apiKey string) (*entities.AuthUser, error) {
+func (repository *gormUserRepository) LoadAuthUser(ctx context.Context, apiKey string) (entities.AuthUser, error) {
ctx, span := repository.tracer.Start(ctx)
defer span.End()
@@ -68,15 +68,15 @@ func (repository *gormUserRepository) LoadAuthUser(ctx context.Context, apiKey s
err := repository.db.Where("api_key = ?", apiKey).First(user).Error
if errors.Is(err, gorm.ErrRecordNotFound) {
msg := fmt.Sprintf("user with api key [%s] does not exist", apiKey)
- return nil, repository.tracer.WrapErrorSpan(span, stacktrace.PropagateWithCode(err, ErrCodeNotFound, msg))
+ return entities.AuthUser{}, repository.tracer.WrapErrorSpan(span, stacktrace.PropagateWithCode(err, ErrCodeNotFound, msg))
}
if err != nil {
msg := fmt.Sprintf("cannot load user with api key [%s]", apiKey)
- return nil, repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))
+ return entities.AuthUser{}, repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))
}
- return &entities.AuthUser{
+ return entities.AuthUser{
ID: user.ID,
Email: user.Email,
}, nil
@@ -86,10 +86,10 @@ func (repository *gormUserRepository) Load(ctx context.Context, userID entities.
ctx, span := repository.tracer.Start(ctx)
defer span.End()
- message := new(entities.User)
- err := repository.db.First(message, userID).Error
+ user := new(entities.User)
+ err := repository.db.First(user, userID).Error
if errors.Is(err, gorm.ErrRecordNotFound) {
- msg := fmt.Sprintf("user with ID [%s] does not exist", message.ID)
+ msg := fmt.Sprintf("user with ID [%s] does not exist", user.ID)
return nil, repository.tracer.WrapErrorSpan(span, stacktrace.PropagateWithCode(err, ErrCodeNotFound, msg))
}
@@ -98,7 +98,7 @@ func (repository *gormUserRepository) Load(ctx context.Context, userID entities.
return nil, repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))
}
- return message, nil
+ return user, nil
}
func (repository *gormUserRepository) LoadOrStore(ctx context.Context, authUser entities.AuthUser) (*entities.User, error) {
diff --git a/api/pkg/repositories/user_repository.go b/api/pkg/repositories/user_repository.go
index 3b66ff41..ede97a4a 100644
--- a/api/pkg/repositories/user_repository.go
+++ b/api/pkg/repositories/user_repository.go
@@ -15,7 +15,7 @@ type UserRepository interface {
Update(ctx context.Context, user *entities.User) error
// LoadAuthUser fetches an entities.AuthUser by apiKey
- LoadAuthUser(ctx context.Context, apiKey string) (*entities.AuthUser, error)
+ LoadAuthUser(ctx context.Context, apiKey string) (entities.AuthUser, error)
// Load an entities.User by entities.UserID
Load(ctx context.Context, userID entities.UserID) (*entities.User, error)