Skip to content

Commit ba07142

Browse files
committed
Add START_WITH_CROP_SCREEN, read from local_debug.properties, to BuildConfig in debug mode and set startDestination based on it
1 parent d6b92fa commit ba07142

File tree

4 files changed

+51
-13
lines changed

4 files changed

+51
-13
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,5 @@ lint/reports/
7777
# Android Profiling
7878
*.hprof
7979

80-
.kotlin/
80+
.kotlin/
81+
local_debug.properties

app/build.gradle.kts

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import com.android.build.api.dsl.VariantDimension
12
import java.io.FileInputStream
23
import java.util.Properties
34

@@ -20,15 +21,6 @@ android {
2021

2122
versionCode = project.findProperty("versionCode")!!.toString().toInt()
2223
versionName = version.toString()
23-
24-
@Suppress("UnstableApiUsage")
25-
externalNativeBuild {
26-
cmake {
27-
cppFlags("-frtti -fexceptions")
28-
abiFilters("x86", "x86_64", "armeabi-v7a", "arm64-v8a")
29-
arguments("-DOpenCV_DIR=${rootProject.projectDir}/opencv/native")
30-
}
31-
}
3224
}
3325
signingConfigs {
3426
create("release") {
@@ -47,9 +39,11 @@ android {
4739
}
4840
buildTypes {
4941
getByName("debug") {
42+
buildStartWithCropScreenConfigField(retrieveStartWithCropScreenValue(default = false))
5043
applicationIdSuffix = ".debug"
5144
}
5245
getByName("release") {
46+
buildStartWithCropScreenConfigField(false)
5347
isMinifyEnabled = true
5448
isShrinkResources = true
5549
proguardFiles(
@@ -86,6 +80,26 @@ android {
8680
}
8781
}
8882

83+
private fun retrieveStartWithCropScreenValue(default: Boolean = false): Boolean {
84+
val localDebugPropertiesFile = rootProject.file("local_debug.properties")
85+
86+
if (localDebugPropertiesFile.exists()) {
87+
val props = Properties()
88+
props.load(FileInputStream(localDebugPropertiesFile))
89+
return (props.getProperty("startWithCropScreen")
90+
?: error("Couldn't find property 'startWithCropScreen'")).toBoolean()
91+
}
92+
return default
93+
}
94+
95+
private fun VariantDimension.buildStartWithCropScreenConfigField(value: Boolean) {
96+
buildConfigField(
97+
"boolean",
98+
"START_WITH_CROP_SCREEN",
99+
value.toString()
100+
)
101+
}
102+
89103
// https://github.com/Triple-T/gradle-play-publisher
90104
play {
91105
serviceAccountCredentials.set(file("service-account-key.json"))

app/src/main/kotlin/com/w2sv/autocrop/MainActivity.kt

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.w2sv.autocrop
22

3+
import android.annotation.SuppressLint
34
import android.os.Bundle
45
import androidx.annotation.IdRes
56
import androidx.appcompat.app.AppCompatActivity
@@ -10,6 +11,7 @@ import androidx.navigation.NavController
1011
import androidx.navigation.fragment.NavHostFragment
1112
import com.w2sv.kotlinutils.coroutines.flow.collectOn
1213
import dagger.hilt.android.AndroidEntryPoint
14+
import kotlinx.coroutines.CoroutineScope
1315
import slimber.log.i
1416

1517
@AndroidEntryPoint
@@ -20,13 +22,30 @@ class MainActivity : AppCompatActivity(R.layout.activity_main) {
2022
super.onCreate(savedInstanceState)
2123

2224
if (BuildConfig.DEBUG) {
23-
val navController = findNavController(R.id.nav_host_fragment)
24-
navController.currentBackStack.collectOn(lifecycleScope) { backStackEntries ->
25-
i { "BackStack: ${backStackEntries.map { it.destination.displayName.substringAfterLast("/") }}" }
25+
findNavController(R.id.nav_host_fragment).apply {
26+
setStartDestinationBasedOnStartWithCropScreen()
27+
setupBackStackLogging(lifecycleScope)
2628
}
2729
}
2830
}
2931
}
3032

3133
private fun FragmentActivity.findNavController(@IdRes id: Int): NavController =
3234
(supportFragmentManager.findFragmentById(id) as NavHostFragment).navController
35+
36+
@SuppressLint("RestrictedApi")
37+
private fun NavController.setupBackStackLogging(scope: CoroutineScope) {
38+
currentBackStack.collectOn(scope) { backStackEntries ->
39+
i { "BackStack: ${backStackEntries.map { it.destination.displayName.substringAfterLast("/") }}" }
40+
}
41+
}
42+
43+
private fun NavController.setStartDestinationBasedOnStartWithCropScreen() {
44+
@Suppress("KotlinConstantConditions")
45+
if (BuildConfig.START_WITH_CROP_SCREEN) {
46+
val graph = navInflater.inflate(R.navigation.nav_graph).apply {
47+
setStartDestination(R.id.crop_nav_graph)
48+
}
49+
this.graph = graph
50+
}
51+
}

app/src/main/res/navigation/nav_graph.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@
6666
<argument
6767
android:name="cropBundleIndex"
6868
app:argType="integer" />
69+
70+
<argument
71+
android:name="transitionName"
72+
app:argType="string" />
6973
</fragment>
7074

7175
<fragment

0 commit comments

Comments
 (0)