Skip to content

Commit 2b1827b

Browse files
committed
Add enable debug log settings
1 parent d807ba7 commit 2b1827b

File tree

12 files changed

+98
-35
lines changed

12 files changed

+98
-35
lines changed

android/app/build.gradle

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ plugins {
22
id 'com.android.application'
33
id 'org.jetbrains.kotlin.android'
44
id 'com.google.gms.google-services'
5-
id "io.sentry.android.gradle" version "3.1.2"
5+
id "io.sentry.android.gradle" version "4.3.1"
66
}
77

88
def getGitHash = { ->
@@ -44,22 +44,26 @@ android {
4444
jvmTarget = '1.8'
4545
}
4646
namespace 'com.httpsms'
47+
48+
buildFeatures {
49+
buildConfig = true
50+
}
4751
}
4852

4953
dependencies {
50-
implementation platform('com.google.firebase:firebase-bom:30.1.0')
54+
implementation platform('com.google.firebase:firebase-bom:32.7.4')
5155
implementation 'com.google.firebase:firebase-analytics-ktx'
5256
implementation 'com.google.firebase:firebase-messaging-ktx'
5357
implementation 'com.squareup.okhttp3:okhttp:4.10.0'
5458
implementation 'com.jakewharton.timber:timber:5.0.1'
5559
implementation 'androidx.preference:preference-ktx:1.2.1'
56-
implementation 'androidx.work:work-runtime-ktx:2.7.1'
57-
implementation 'androidx.core:core-ktx:1.9.0'
60+
implementation 'androidx.work:work-runtime-ktx:2.9.0'
61+
implementation 'androidx.core:core-ktx:1.12.0'
5862
implementation "androidx.cardview:cardview:1.0.0"
5963
implementation 'com.beust:klaxon:5.5'
6064
implementation 'androidx.appcompat:appcompat:1.6.1'
6165
implementation 'org.apache.commons:commons-text:1.9'
62-
implementation 'com.google.android.material:material:1.9.0'
66+
implementation 'com.google.android.material:material:1.11.0'
6367
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
6468
implementation 'androidx.core:core-ktx:1.12.0'
6569
testImplementation 'junit:junit:4.13.2'

android/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
<service
4949
android:name=".services.StickyNotificationService"
5050
android:enabled="true"
51+
android:foregroundServiceType="remoteMessaging"
5152
android:exported="false">
5253
</service>
5354

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class MyFirebaseMessagingService : FirebaseMessagingService() {
110110
return
111111
}
112112

113-
if (BuildConfig.DEBUG) {
113+
if(Settings.isDebugLogEnabled(this)) {
114114
Timber.plant(Timber.DebugTree())
115115
Timber.plant(LogzTree(this.applicationContext))
116116
}

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,21 @@ import android.telephony.TelephonyManager
1212
import android.view.View
1313
import android.webkit.URLUtil
1414
import android.widget.LinearLayout
15+
import android.widget.Toast
1516
import androidx.activity.result.contract.ActivityResultContracts
1617
import androidx.appcompat.app.AppCompatActivity
1718
import androidx.core.app.ActivityCompat
1819
import androidx.lifecycle.MutableLiveData
20+
import com.google.android.gms.common.ConnectionResult
21+
import com.google.android.gms.common.GoogleApiAvailability
1922
import com.google.android.material.button.MaterialButton
2023
import com.google.android.material.progressindicator.LinearProgressIndicator
2124
import com.google.android.material.textfield.TextInputEditText
2225
import com.google.android.material.textfield.TextInputLayout
2326
import timber.log.Timber
2427
import java.net.URI
2528

29+
2630
class LoginActivity : AppCompatActivity() {
2731
override fun onCreate(savedInstanceState: Bundle?) {
2832
super.onCreate(savedInstanceState)
@@ -123,9 +127,29 @@ class LoginActivity : AppCompatActivity() {
123127
Timber.d("creating permissions launcher")
124128
}
125129

130+
private fun isGooglePlayServicesAvailable(): String? {
131+
val googleApiAvailability = GoogleApiAvailability.getInstance()
132+
val status = googleApiAvailability.isGooglePlayServicesAvailable(this)
133+
if (status != ConnectionResult.SUCCESS) {
134+
if (googleApiAvailability.isUserResolvableError(status)) {
135+
googleApiAvailability.getErrorDialog(this, status, 2404)?.show()
136+
}
137+
return googleApiAvailability.getErrorString(status)
138+
}
139+
return null
140+
}
141+
126142

127143
private fun onLoginClick() {
128144
Timber.d("login button clicked")
145+
146+
val error = isGooglePlayServicesAvailable()
147+
if (error != null) {
148+
Timber.d("google play services not installed [${error}]")
149+
Toast.makeText(this, error, Toast.LENGTH_SHORT).show()
150+
return
151+
}
152+
129153
loginButton().isEnabled = false
130154
val progressBar = findViewById<LinearProgressIndicator>(R.id.loginProgressIndicator)
131155
progressBar.visibility = View.VISIBLE

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import android.app.NotificationChannel
66
import android.app.NotificationManager
77
import android.content.Context
88
import android.content.Intent
9-
import android.content.IntentFilter
109
import android.net.Uri
1110
import android.os.Build
1211
import android.os.Bundle
@@ -24,6 +23,7 @@ import androidx.work.ExistingPeriodicWorkPolicy
2423
import androidx.work.NetworkType
2524
import androidx.work.PeriodicWorkRequestBuilder
2625
import androidx.work.WorkManager
26+
import com.google.android.gms.common.GoogleApiAvailability
2727
import com.google.android.material.button.MaterialButton
2828
import com.google.android.material.card.MaterialCardView
2929
import com.google.android.material.progressindicator.LinearProgressIndicator
@@ -42,9 +42,6 @@ import android.provider.Settings as ProviderSettings
4242

4343

4444
class MainActivity : AppCompatActivity() {
45-
private var sentReceiver: SentReceiver? = null
46-
private var deliveredReceiver: DeliveredReceiver? = null
47-
4845
override fun onCreate(savedInstanceState: Bundle?) {
4946
super.onCreate(savedInstanceState)
5047

@@ -218,7 +215,7 @@ class MainActivity : AppCompatActivity() {
218215
return
219216
}
220217

221-
if (BuildConfig.DEBUG) {
218+
if(Settings.isDebugLogEnabled(this)) {
222219
Timber.plant(Timber.DebugTree())
223220
Timber.plant(LogzTree(this.applicationContext))
224221
}

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ object Settings {
1616
private const val SETTINGS_SIM2_ACTIVE = "SETTINGS_SIM2_ACTIVE_STATUS"
1717
private const val SETTINGS_SIM1_INCOMING_ACTIVE = "SETTINGS_SIM1_INCOMING_ACTIVE"
1818
private const val SETTINGS_SIM2_INCOMING_ACTIVE = "SETTINGS_SIM2_INCOMING_ACTIVE"
19+
private const val SETTINGS_DEBUG_LOG_ENABLED = "SETTINGS_DEBUG_LOG_ENABLED"
1920
private const val SETTINGS_API_KEY = "SETTINGS_API_KEY"
2021
private const val SETTINGS_SERVER_URL = "SETTINGS_SERVER_URL"
2122
private const val SETTINGS_FCM_TOKEN = "SETTINGS_FCM_TOKEN"
@@ -113,6 +114,23 @@ object Settings {
113114
return activeStatus
114115
}
115116

117+
fun isDebugLogEnabled(context: Context) : Boolean {
118+
Timber.d(Settings::isDebugLogEnabled.name)
119+
120+
return PreferenceManager
121+
.getDefaultSharedPreferences(context)
122+
.getBoolean(this.SETTINGS_DEBUG_LOG_ENABLED, false)
123+
}
124+
125+
fun setDebugLogEnabled(context: Context, status: Boolean) {
126+
Timber.d(Settings::setDebugLogEnabled.name)
127+
128+
PreferenceManager.getDefaultSharedPreferences(context)
129+
.edit()
130+
.putBoolean(this.SETTINGS_DEBUG_LOG_ENABLED, status)
131+
.apply()
132+
}
133+
116134
fun setIncomingActiveSIM1(context: Context, status: Boolean) {
117135
Timber.d(Settings::setIncomingActiveSIM1.name)
118136

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ class SettingsActivity : AppCompatActivity() {
2222
}
2323

2424
private fun fillSettings(context: Context) {
25+
val debugLogs = findViewById<SwitchMaterial>(R.id.settingEnableDebugLogs)
26+
debugLogs.isChecked = Settings.isDebugLogEnabled(context)
27+
debugLogs.setOnCheckedChangeListener{ _, isChecked -> run { Settings.setDebugLogEnabled(context, isChecked) } }
28+
29+
2530
val phoneNumber = findViewById<TextInputEditText>(R.id.settingsSIM1Input)
2631
phoneNumber.setText(Settings.getSIM1PhoneNumber(context))
2732
phoneNumber.isEnabled = false

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

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,22 @@
2828
</com.google.android.material.appbar.AppBarLayout>
2929

3030
<LinearLayout
31-
app:layout_constraintTop_toBottomOf="@+id/settings_app_bar_layout"
31+
android:id="@+id/linearLayout2"
3232
android:layout_width="match_parent"
3333
android:layout_height="wrap_content"
34-
android:paddingLeft="16dp"
3534
android:layout_marginTop="16dp"
35+
android:orientation="vertical"
36+
android:paddingLeft="16dp"
3637
android:paddingRight="16dp"
37-
android:orientation="vertical">
38+
app:layout_constraintTop_toBottomOf="@+id/settings_app_bar_layout">
39+
3840
<com.google.android.material.textfield.TextInputLayout
3941
android:id="@+id/settingsSIM1"
4042
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
4143
android:layout_width="match_parent"
4244
android:layout_height="wrap_content"
43-
app:errorEnabled="true"
4445
android:hint="@string/settings_sim1"
46+
app:errorEnabled="true"
4547
app:layout_constraintTop_toTopOf="parent"
4648
tools:layout_editor_absoluteX="16dp">
4749

@@ -58,29 +60,29 @@
5860
android:id="@+id/settings_sim1_outgoing_messages"
5961
android:layout_width="match_parent"
6062
android:layout_height="wrap_content"
61-
android:textSize="18sp"
6263
android:layout_marginBottom="16dp"
63-
android:text="@string/settings_outgoing_messages_sim1"
6464
android:minHeight="48dp"
65+
android:text="@string/settings_outgoing_messages_sim1"
66+
android:textSize="18sp"
6567
tools:ignore="TouchTargetSizeCheck" />
6668

6769
<com.google.android.material.switchmaterial.SwitchMaterial
6870
android:id="@+id/settings_sim1_incoming_messages"
6971
android:layout_width="match_parent"
7072
android:layout_height="wrap_content"
71-
android:textSize="18sp"
7273
android:layout_marginBottom="16dp"
73-
android:text="@string/settings_incoming_messages_sim1"
7474
android:minHeight="48dp"
75+
android:text="@string/settings_incoming_messages_sim1"
76+
android:textSize="18sp"
7577
tools:ignore="TouchTargetSizeCheck" />
7678

7779
<com.google.android.material.textfield.TextInputLayout
7880
android:id="@+id/settingsSIM2Layout"
7981
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
8082
android:layout_width="match_parent"
8183
android:layout_height="wrap_content"
82-
app:errorEnabled="true"
8384
android:hint="@string/settings_sim_2"
85+
app:errorEnabled="true"
8486
app:layout_constraintTop_toTopOf="parent"
8587
tools:layout_editor_absoluteX="16dp">
8688

@@ -97,29 +99,29 @@
9799
android:id="@+id/settings_sim2_outgoing_messages"
98100
android:layout_width="match_parent"
99101
android:layout_height="wrap_content"
100-
android:textSize="18sp"
101-
android:text="@string/settings_outgoing_messages_sim2"
102-
android:minHeight="48dp"
103102
android:layout_marginBottom="16dp"
103+
android:minHeight="48dp"
104+
android:text="@string/settings_outgoing_messages_sim2"
105+
android:textSize="18sp"
104106
tools:ignore="TouchTargetSizeCheck" />
105107

106108
<com.google.android.material.switchmaterial.SwitchMaterial
107109
android:id="@+id/settings_sim2_incoming_messages"
108110
android:layout_width="match_parent"
109111
android:layout_height="wrap_content"
110-
android:textSize="18sp"
111-
android:text="@string/settings_incoming_messages_sim2"
112-
android:minHeight="48dp"
113112
android:layout_marginBottom="16dp"
113+
android:minHeight="48dp"
114+
android:text="@string/settings_incoming_messages_sim2"
115+
android:textSize="18sp"
114116
tools:ignore="TouchTargetSizeCheck" />
115117

116118
<com.google.android.material.textfield.TextInputLayout
117119
android:id="@+id/settingsEncryptionKeyLayout"
118120
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
119121
android:layout_width="match_parent"
120122
android:layout_height="wrap_content"
121-
app:errorEnabled="true"
122123
android:hint="@string/encryption_key"
124+
app:errorEnabled="true"
123125
app:layout_constraintTop_toTopOf="parent"
124126
tools:layout_editor_absoluteX="16dp">
125127

@@ -136,10 +138,20 @@
136138
android:id="@+id/settingsEncryptReceivedMessages"
137139
android:layout_width="match_parent"
138140
android:layout_height="wrap_content"
139-
android:textSize="18sp"
140-
android:text="@string/encrypt_received_messages"
141+
android:layout_marginBottom="16dp"
141142
android:minHeight="48dp"
143+
android:text="@string/encrypt_received_messages"
144+
android:textSize="18sp"
145+
tools:ignore="TouchTargetSizeCheck" />
146+
147+
<com.google.android.material.switchmaterial.SwitchMaterial
148+
android:id="@+id/settingEnableDebugLogs"
149+
android:layout_width="match_parent"
150+
android:layout_height="wrap_content"
142151
android:layout_marginBottom="16dp"
152+
android:minHeight="48dp"
153+
android:text="@string/enable_debug_logs"
154+
android:textSize="18sp"
143155
tools:ignore="TouchTargetSizeCheck" />
144156
</LinearLayout>
145157

@@ -148,17 +160,19 @@
148160
style="@style/Widget.MaterialComponents.Button.Icon"
149161
android:layout_width="wrap_content"
150162
android:layout_height="wrap_content"
151-
android:layout_marginBottom="16dp"
152163
android:backgroundTint="@color/black"
153164
android:drawableTint="@color/white"
154165
android:padding="10dp"
155166
android:text="@string/main_log_out"
156167
android:textColor="@color/white"
157168
android:textSize="16sp"
169+
android:layout_marginTop="16dp"
170+
android:layout_marginLeft="16dp"
171+
android:layout_marginRight="16dp"
158172
app:icon="@drawable/ic_login"
159173
app:iconTint="@color/white"
160-
app:layout_constraintBottom_toBottomOf="parent"
161174
app:layout_constraintEnd_toEndOf="parent"
162175
app:layout_constraintStart_toStartOf="parent"
176+
app:layout_constraintTop_toBottomOf="@+id/linearLayout2"
163177
tools:ignore="TextContrastCheck" />
164178
</androidx.constraintlayout.widget.ConstraintLayout>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@
2828
<string name="login_phone_number_sim2">Phone Number (SIM2)</string>
2929
<string name="encryption_key">Encryption Key</string>
3030
<string name="encrypt_received_messages">Encrypt Received Messages</string>
31+
<string name="enable_debug_logs">Enable Debug Logs</string>
3132
</resources>

android/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ buildscript {
1717
}
1818

1919
plugins {
20-
id 'com.android.application' version '8.2.1' apply false
21-
id 'com.android.library' version '8.2.1' apply false
20+
id 'com.android.application' version '8.3.0' apply false
21+
id 'com.android.library' version '8.3.0' apply false
2222
id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
2323
}
2424

0 commit comments

Comments
 (0)