1+ import com.android.build.api.dsl.ApplicationProductFlavor
12import java.util.Locale
23import com.squareup.moshi.Moshi
34import com.squareup.moshi.adapter
45import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
5- import org.codehaus.groovy.transform.trait.Traits.Implemented
6- import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask
76
87plugins {
98 alias(libs.plugins.android.application)
@@ -112,24 +111,6 @@ android {
112111 }
113112 }
114113
115- flavorDimensions.add(" type" )
116-
117- productFlavors {
118- register(" alpha" ) {
119- isDefault = true
120- dimension = " type"
121- versionNameSuffix = " -alpha"
122- applicationIdSuffix = " .alpha"
123-
124- buildConfigField(" ${packageName} .app.update.UpdatesChannel" , " CHANNEL" , " ${packageName} .app.update.UpdatesChannel.ALPHA" )
125- buildConfigField(" String" , " FILE_PROVIDER" , " \" ${packageName} .alpha.FileProvider\" " )
126- buildConfigField(" String" , " UPDATES_REPOSITORY" , " \" itsmechinmoy/awery-updater\" " )
127-
128- manifestPlaceholders[" fileProvider" ] = " ${packageName} .alpha.FileProvider"
129- manifestPlaceholders[" appLabel" ] = " Awery Alpha"
130- }
131- }
132-
133114 buildFeatures {
134115 viewBinding = true
135116 buildConfig = true
@@ -149,6 +130,43 @@ android {
149130 jvmTarget = " 17"
150131 freeCompilerArgs = listOf (" -Xcontext-receivers" , " -Xmulti-platform" , " -opt-in=kotlin.ExperimentalStdlibApi" )
151132 }
133+
134+ flavorDimensions + = listOf (" channel" )
135+
136+ productFlavors {
137+ fun ApplicationProductFlavor.createChannelProductFlavor (id : String , title : String ) {
138+ dimension = " channel"
139+ versionNameSuffix = " -$id "
140+ applicationIdSuffix = " .$id "
141+
142+ buildConfigField(" String" , " FILE_PROVIDER" ,
143+ " \" ${packageName} .$id .FileProvider\" " )
144+
145+ buildConfigField(" ${packageName} .app.update.UpdatesChannel" , " CHANNEL" ,
146+ " ${packageName} .app.update.UpdatesChannel.${id.uppercase()} " )
147+
148+ manifestPlaceholders[" fileProvider" ] = " ${packageName} .$id .FileProvider"
149+ manifestPlaceholders[" appLabel" ] = " Awery $title "
150+ }
151+
152+ register(" alpha" ) {
153+ createChannelProductFlavor(" alpha" , " Alpha" )
154+ buildConfigField(" String" , " UPDATES_REPOSITORY" , " \" itsmechinmoy/awery-updater\" " )
155+ isDefault = true
156+ }
157+
158+ register(" beta" ) {
159+ createChannelProductFlavor(" beta" , " Beta" )
160+ buildConfigField(" String" , " UPDATES_REPOSITORY" , " \" MrBoomDeveloper/Awery\" " )
161+ }
162+
163+ register(" stable" ) {
164+ createChannelProductFlavor(" stable" , " Stable" )
165+ buildConfigField(" String" , " UPDATES_REPOSITORY" , " \" MrBoomDeveloper/Awery\" " )
166+ manifestPlaceholders[" appLabel" ] = " Awery"
167+ applicationIdSuffix = null
168+ }
169+ }
152170}
153171
154172dependencies {
@@ -157,7 +175,7 @@ dependencies {
157175 implementation(libs.androidx.appcompat)
158176 implementation(libs.androidx.browser)
159177 implementation(libs.androidx.webkit)
160- implementation(libs.fragment.ktx )
178+ implementation(libs.androidx.fragment )
161179 implementation(libs.androidx.core.google.shortcuts)
162180 implementation(libs.androidx.preference.ktx)
163181 implementation(libs.xcrash.android.lib)
@@ -187,9 +205,9 @@ dependencies {
187205
188206 // Compose
189207 implementation(platform(libs.androidx.compose.bom))
190- implementation(libs.androidx. compose.activity)
191- implementation(libs.compose.ui)
192- implementation(libs.androidx. compose.material)
208+ implementation(libs.compose.android .activity)
209+ implementation(libs.compose.android. ui)
210+ implementation(libs.compose.android .material)
193211 implementation(libs.androidx.navigation.compose)
194212 implementation(libs.compose.tv.material)
195213 implementation(libs.compose.tv.foundation)
@@ -245,7 +263,7 @@ dependencies {
245263 implementation(libs.kotlinx.serialization.protobuf)
246264
247265 // Debugging
248- implementation(libs.androidx. compose.ui.tooling)
266+ implementation(libs.compose.android .ui.tooling)
249267 debugImplementation(libs.leakcanary.android)
250268}
251269
@@ -264,15 +282,14 @@ fun String.toCamelCase(): String {
264282}
265283
266284fun formatKey (o : Setting , usedKeys : MutableSet <String >): String {
267- var result = " public static final "
285+ var result = " \t public static final "
268286
269287 if (o.type == " select" && o.items != null ) {
270- val enumName = o.key!! .uppercase(Locale . ENGLISH ).toCamelCase() + " _Values"
288+ val enumName = o.key!! .uppercase().toCamelCase() + " _Values"
271289
272- result = " \n " + result
273- result + = " EnumSetting<$enumName > ${o.key.uppercase(Locale .ENGLISH )} = new EnumSetting<>(\" ${o.key} \" , $enumName .class);\n\n "
290+ result + = " EnumSetting<$enumName > ${o.key.uppercase()} =\n\t\t\t new EnumSetting<>(\" ${o.key} \" , $enumName .class);\n\n "
274291
275- result + = " public enum $enumName implements EnumWithKey {\n "
292+ result + = " \t public enum $enumName implements EnumWithKey {\n\t\t "
276293
277294 val iterator = o.items.iterator()
278295
@@ -284,22 +301,22 @@ fun formatKey(o: Setting, usedKeys: MutableSet<String>): String {
284301 " \n You have to remove one of them for app to work properly." )
285302 }
286303
287- result + = item.key!! .uppercase(Locale . ENGLISH ) + " (\" ${item.key} \" )"
304+ result + = item.key!! .uppercase() + " (\" ${item.key} \" )"
288305
289306 if (iterator.hasNext()) {
290- result + = " , "
307+ result + = " ,\n\t\t "
291308 }
292309 }
293310
294- result + = " ;\n\n private final String key;\n\n ${enumName} (String key) {\n "
295- result + = " this .key = key;\n }\n\n @Override\n public String getKey() {\n "
296- result + = " return key;\n }\n } \n "
311+ result + = " ;\n\n\t\t private final String key;\n\n\t\t ${enumName} (String key) {\n "
312+ result + = " \t\t\t this .key = key;\n\t\t }\n\n\t\t @Override\n\t\t public String getKey() {\n "
313+ result + = " \t\t\t return key;\n\t\t }\n\t } \n \n"
297314
298315 return result
299316 }
300317
301318 if (listOf (" action" , " select" , " multiselect" ).contains(o.type)) {
302- return result + " String ${o.key!! .uppercase(Locale . ENGLISH )} = \" ${o.key} \" ;\n "
319+ return result + " String ${o.key!! .uppercase()} = \" ${o.key} \" ;\n "
303320 }
304321
305322 when (o.type) {
@@ -308,7 +325,7 @@ fun formatKey(o: Setting, usedKeys: MutableSet<String>): String {
308325 " boolean" , " screen_boolean" -> result + = " Boolean"
309326 }
310327
311- result + = " Setting ${o.key!! .uppercase(Locale . ENGLISH )} = () -> \" ${o.key} \" ;\n "
328+ result + = " Setting ${o.key!! .uppercase()} = () -> \" ${o.key} \" ;\n "
312329 return result
313330}
314331
@@ -318,22 +335,20 @@ fun collectKeys(from: Setting, usedKeys: MutableSet<String>): String {
318335 " \n You have to remove one of them for app to work properly." )
319336 }
320337
321- val builder = StringBuilder ()
322-
323- when (from.type) {
324- " screen " -> {
325- if ( from.items != null ) {
326- for ( item in from.items) {
327- builder.append(collectKeys(item, usedKeys))
338+ return buildString {
339+ when (from.type) {
340+ " screen " -> {
341+ if (from.items != null ) {
342+ for (item in from.items) {
343+ append(collectKeys( item, usedKeys))
344+ }
328345 }
329346 }
330- }
331347
332- " string" , " integer" , " boolean" , " action" ,
333- " select" , " select_integer" , " multiselect" -> builder.append(formatKey(from, usedKeys))
348+ " string" , " integer" , " boolean" , " action" ,
349+ " select" , " select_integer" , " multiselect" -> append(formatKey(from, usedKeys))
350+ }
334351 }
335-
336- return builder.toString()
337352}
338353
339354data class Setting (val key : String? , val type : String? , val items : List <Setting >? )
@@ -343,20 +358,23 @@ fun generateSettingsClass(dir: File) {
343358 val settings = Moshi .Builder ().addLast(KotlinJsonAdapterFactory ()).build().adapter<Setting >().fromJson(
344359 file(" $projectDir /src/main/assets/settings.json" ).readText())!!
345360
346- val builder = StringBuilder ()
347- .append(" package com.mrboomdev.awery.generated;\n " )
348- .append(" \n " )
349- .append(" import com.mrboomdev.awery.app.data.settings.NicePreferences.*;\n " )
350- .append(" \n " )
351- .append(" /**\n " )
352- .append(" * Auto-generated class created during the compilation. Please, do not edit it.\n " )
353- .append(" * @author MrBoomDev\n " )
354- .append(" */\n " )
355- .append(" public class AwerySettings {\n " )
356- .append(collectKeys(settings, HashSet ()))
357- .append(" }" )
358-
359- File (dir, " AwerySettings.java" ).writeText(builder.toString())
361+ File (dir, " AwerySettings.java" ).writeText(buildString {
362+ append(" package com.mrboomdev.awery.generated;\n " )
363+ append(" \n " )
364+ append(" import com.mrboomdev.awery.app.data.settings.NicePreferences.*;\n " )
365+ append(" import com.mrboomdev.awery.app.data.settings.NicePreferences;\n " )
366+ append(" import com.mrboomdev.awery.app.data.settings.SettingsItem;\n " )
367+ append(" \n " )
368+ append(" // Auto-generated class created during the compilation. Please, do not edit it.\n " )
369+ append(" public class AwerySettings {\n " )
370+
371+ append(" \t public static SettingsItem get(String key) {\n " )
372+ append(" \t\t return NicePreferences.getSettingsMap().findItem(key);\n " )
373+ append(" \t }\n\n " )
374+
375+ append(collectKeys(settings, HashSet ()))
376+ append(" }" )
377+ })
360378}
361379
362380tasks.register(" generateClasses" ) {
0 commit comments