Skip to content

Commit f44d4ad

Browse files
Allow sourcing account credentials from local.properties during development
1 parent 3a014f6 commit f44d4ad

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed

app/build.gradle.kts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1+
import java.util.Properties
2+
import java.io.FileInputStream
3+
14
plugins {
25
id("com.android.application")
36
kotlin("android")
47
alias(libs.plugins.compose.compiler)
58
id("com.mikepenz.aboutlibraries.plugin")
69
}
710

11+
val props = Properties().apply {
12+
runCatching {
13+
load(FileInputStream(rootProject.file("local.properties")))
14+
}
15+
}
16+
817

918
android {
1019
namespace = "com.readrops.app"
@@ -21,7 +30,10 @@ android {
2130
isMinifyEnabled = true
2231
isShrinkResources = true
2332

24-
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
33+
proguardFiles(
34+
getDefaultProguardFile("proguard-android-optimize.txt"),
35+
"proguard-rules.pro"
36+
)
2537
}
2638

2739
debug {
@@ -41,6 +53,21 @@ android {
4153
applicationIdSuffix = ".beta"
4254
signingConfig = signingConfigs.getByName("debug")
4355
}
56+
57+
configureEach {
58+
val shouldSource = name == "debug" || name == "beta"
59+
listOf(
60+
"url" to "https://",
61+
"login" to "",
62+
"password" to ""
63+
).forEach { (k, v) ->
64+
resValue(
65+
"string",
66+
"debug.${k}",
67+
if (shouldSource) props.getProperty("debug.$k", v) else v
68+
)
69+
}
70+
}
4471
}
4572

4673
buildFeatures {

app/src/main/java/com/readrops/app/AppModule.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ val appModule = module {
6464
}
6565

6666
factory { (accountType: Account, mode: AccountCredentialsScreenMode) ->
67-
AccountCredentialsScreenModel(accountType, mode, get())
67+
AccountCredentialsScreenModel(accountType, mode, get(), context = androidContext())
6868
}
6969

7070
factory { (account: Account) -> NotificationsScreenModel(account, get(), get(), get()) }

app/src/main/java/com/readrops/app/account/credentials/AccountCredentialsScreenModel.kt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.readrops.app.account.credentials
22

3+
import android.content.Context
34
import android.content.SharedPreferences
45
import android.util.Patterns
56
import cafe.adriel.voyager.core.model.StateScreenModel
@@ -16,14 +17,22 @@ import kotlinx.coroutines.launch
1617
import org.koin.core.component.KoinComponent
1718
import org.koin.core.component.get
1819
import org.koin.core.parameter.parametersOf
20+
import com.readrops.app.R
21+
1922

2023
class AccountCredentialsScreenModel(
2124
private val account: Account,
2225
private val mode: AccountCredentialsScreenMode,
2326
private val database: Database,
24-
private val dispatcher: CoroutineDispatcher = Dispatchers.IO
25-
) : StateScreenModel<AccountCredentialsState>(AccountCredentialsState()), KoinComponent {
26-
27+
private val dispatcher: CoroutineDispatcher = Dispatchers.IO,
28+
context: Context,
29+
) : StateScreenModel<AccountCredentialsState>(
30+
AccountCredentialsState(
31+
url = context.getString(R.string.debug_url),
32+
login = context.getString(R.string.debug_login),
33+
password = context.getString(R.string.debug_password),
34+
)
35+
), KoinComponent {
2736
init {
2837
if (mode == AccountCredentialsScreenMode.EDIT_CREDENTIALS) {
2938
mutableState.update {

0 commit comments

Comments
 (0)