@@ -63,18 +63,16 @@ import com.mrboomdev.awery.data.Constants
6363import com.mrboomdev.awery.data.db.AweryDB
6464import com.mrboomdev.awery.data.db.item.DBCatalogList
6565import com.mrboomdev.awery.extensions.data.CatalogList
66- import com.mrboomdev.awery.generated.AwerySettings
67- import com.mrboomdev.awery.generated.GeneratedSetting
68- import com.mrboomdev.awery.platform.PlatformResources
66+ import com.mrboomdev.awery.generated.*
67+ import com.mrboomdev.awery.platform.i18n
6968import com.mrboomdev.awery.ui.mobile.screens.BrowserActivity
7069import com.mrboomdev.awery.ui.mobile.screens.IntentHandlerActivity
7170import com.mrboomdev.awery.ui.mobile.screens.settings.SettingsActivity
7271import com.mrboomdev.awery.ui.tv.TvExperimentsActivity
73- import com.mrboomdev.awery.util.extensions.configuration
74- import com.mrboomdev.awery.util.extensions.startActivity
7572import com.mrboomdev.awery.util.ui.dialog.DialogBuilder
7673import com.mrboomdev.awery.util.ui.markdown.LinkifyPlugin
7774import com.mrboomdev.awery.util.ui.markdown.SpoilerPlugin
75+ import com.mrboomdev.awery.utils.buildIntent
7876import com.squareup.moshi.Moshi
7977import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
8078import dev.mihon.injekt.patchInjekt
@@ -88,6 +86,8 @@ import kotlinx.coroutines.DelicateCoroutinesApi
8886import kotlinx.coroutines.Dispatchers
8987import kotlinx.coroutines.GlobalScope
9088import kotlinx.coroutines.launch
89+ import org.jetbrains.compose.resources.StringResource
90+ import org.jetbrains.compose.resources.stringResource
9191import java.util.WeakHashMap
9292
9393class App : Application () {
@@ -130,16 +130,16 @@ class App : Application() {
130130 if (AwerySettings .USE_DARK_THEME .value == null ) {
131131 AwerySettings .USE_DARK_THEME .value = ThemeManager .isDarkModeEnabled
132132 }
133-
133+
134134 if (AwerySettings .LAST_OPENED_VERSION .value < 1 ) {
135135 CoroutineScope (Dispatchers .IO ).launch {
136136 database.listDao.insert(
137- DBCatalogList .fromCatalogList(CatalogList (getString( R .string.currently_watching), " 1" )),
138- DBCatalogList .fromCatalogList(CatalogList (getString( R .string.planning_watch), " 2" )),
139- DBCatalogList .fromCatalogList(CatalogList (getString( R .string.delayed), " 3" )),
140- DBCatalogList .fromCatalogList(CatalogList (getString( R .string.completed), " 4" )),
141- DBCatalogList .fromCatalogList(CatalogList (getString( R .string.dropped), " 5" )),
142- DBCatalogList .fromCatalogList(CatalogList (getString( R .string.favourites), " 6" )),
137+ DBCatalogList .fromCatalogList(CatalogList (i18n( Res .string.currently_watching), " 1" )),
138+ DBCatalogList .fromCatalogList(CatalogList (i18n( Res .string.planning_watch), " 2" )),
139+ DBCatalogList .fromCatalogList(CatalogList (i18n( Res .string.delayed), " 3" )),
140+ DBCatalogList .fromCatalogList(CatalogList (i18n( Res .string.completed), " 4" )),
141+ DBCatalogList .fromCatalogList(CatalogList (i18n( Res .string.dropped), " 5" )),
142+ DBCatalogList .fromCatalogList(CatalogList (i18n( Res .string.favourites), " 6" )),
143143 DBCatalogList .fromCatalogList(CatalogList (" Hidden" , Constants .CATALOG_LIST_BLACKLIST )),
144144 DBCatalogList .fromCatalogList(CatalogList (" History" , Constants .CATALOG_LIST_HISTORY ))
145145 )
@@ -244,7 +244,7 @@ class App : Application() {
244244 // Android 13 and higher shows a visual confirmation of copied contents
245245 // https://developer.android.com/about/versions/13/features/copy-paste
246246 if (Build .VERSION .SDK_INT <= Build .VERSION_CODES .S_V2 ) {
247- toast(R .string.copied_to_clipboard)
247+ toast(i18n( Res .string.copied_to_clipboard) )
248248 }
249249 }
250250
@@ -257,6 +257,7 @@ class App : Application() {
257257 }
258258
259259 @JvmStatic
260+ @Deprecated(" Old java shit" )
260261 fun getResourceId (type : Class <* >, res : String? ): Int {
261262 if (res == null ) return 0
262263
@@ -280,33 +281,6 @@ class App : Application() {
280281 }
281282 }
282283
283- inline fun <reified T > getResourceId (res : String? ): Int {
284- return getResourceId(T ::class .java, res)
285- }
286-
287- @JvmStatic
288- @Deprecated(" old shit" , ReplaceWith (
289- " PlatformResources.i18n(string, *args)" ,
290- " com.mrboomdev.awery.platform.PlatformResources" ))
291- fun i18n (clazz : Class <* >, string : String? , vararg args : Any ): String? {
292- val id = getResourceId(clazz, string)
293- return if (id == 0 ) null else PlatformResources .i18n(id, * args)
294- }
295-
296- @Deprecated(" old shit" , ReplaceWith (
297- " PlatformResources.i18n(resourceId, *args)" ,
298- " com.mrboomdev.awery.platform.PlatformResources" ))
299- inline fun <reified T > i18n (resourceId : String , vararg args : Any ): String? {
300- return PlatformResources .i18n(resourceId, * args)
301- }
302-
303- @JvmStatic
304- @Deprecated(" old shit" , ReplaceWith (
305- " PlatformResources.i18n(res, *params)" ,
306- " com.mrboomdev.awery.platform.PlatformResources" ))
307- fun i18n (@StringRes res : Int , vararg params : Any ) =
308- ContextCompat .getContextForLanguage(appContext).getString(res, * params)
309-
310284 private fun toastImpl (context : Context ? , text : Any? , duration : Int = 0) {
311285 runOnUiThread { Toast .makeText(context, text.toString(), duration).show() }
312286 }
@@ -317,12 +291,6 @@ class App : Application() {
317291 toastImpl(appContext, text, duration)
318292 }
319293
320- @JvmStatic
321- @JvmOverloads
322- fun toast (@StringRes res : Int , duration : Int = 0) {
323- toast(appContext.getString(res), duration)
324- }
325-
326294 /* *
327295 * There is a bug in an appcompat library which sometimes throws an [NullPointerException].
328296 * This method tries to do it without throwing any exceptions.
@@ -415,7 +383,7 @@ class App : Application() {
415383
416384 @JvmStatic
417385 fun isLandscape (context : Context ): Boolean {
418- return context.configuration.orientation == Configuration .ORIENTATION_LANDSCAPE
386+ return context.resources. configuration.orientation == Configuration .ORIENTATION_LANDSCAPE
419387 }
420388
421389 @JvmStatic
@@ -435,10 +403,10 @@ class App : Application() {
435403
436404 @JvmStatic
437405 @JvmOverloads
438- fun openUrl (context : Context , url : String , forceInternal : Boolean = false) {
406+ fun openUrl (context : Context , url : String , forceInternal : Boolean = false) = with (context) {
439407 if (forceInternal) {
440- context. startActivity(BrowserActivity ::class , BrowserActivity .Extras (url))
441- return
408+ startActivity(buildIntent( BrowserActivity ::class , BrowserActivity .Extras (url) ))
409+ return @with
442410 }
443411
444412 val customTabsIntent = CustomTabsIntent .Builder ().apply {
@@ -449,11 +417,11 @@ class App : Application() {
449417 intent.data = Uri .parse(url)
450418 }
451419
452- customTabsIntent.intent.resolveActivity(context. packageManager)?.also {
453- context. startActivity(customTabsIntent.intent, customTabsIntent.startAnimationBundle)
420+ customTabsIntent.intent.resolveActivity(packageManager)?.also {
421+ startActivity(customTabsIntent.intent, customTabsIntent.startAnimationBundle)
454422 } ? : run {
455423 Log .e(TAG , " No external browser was found, launching a internal one." )
456- context. startActivity(BrowserActivity ::class , BrowserActivity .Extras (url))
424+ startActivity(buildIntent( BrowserActivity ::class , BrowserActivity .Extras (url) ))
457425 }
458426 }
459427
@@ -487,7 +455,7 @@ class App : Application() {
487455 runOnUiThread { DialogBuilder (getAnyActivity<AppCompatActivity >()!! )
488456 .setTitle(" StrictMode.VmPolicy Violation!" )
489457 .setMessage(Log .getStackTraceString(violation))
490- .setPositiveButton(R .string.ok) { it.dismiss() }
458+ .setPositiveButton(i18n( Res .string.ok) ) { it.dismiss() }
491459 .show() }
492460 } catch (e: Throwable ) {
493461 Log .e(TAG , " Failed to warn about an strict mode violation!" , e)
@@ -507,26 +475,6 @@ class App : Application() {
507475 if (isTv) AwerySettings .NavigationStyleValue .MATERIAL else it
508476 }
509477
510- @Deprecated(message = " java shit" )
511- fun getConfiguration (context : Context ): Configuration {
512- return context.configuration
513- }
514-
515- val configuration: Configuration
516- get() = anyContext.configuration
517-
518- @JvmStatic
519- @JvmOverloads
520- fun snackbar (
521- activity : Activity ,
522- @StringRes title : Int ,
523- @StringRes button : Int ,
524- buttonCallback : Runnable ? ,
525- duration : Int = Snackbar .LENGTH_SHORT
526- ) {
527- snackbar(activity, activity.getString(title), activity.getString(button), buttonCallback, duration)
528- }
529-
530478 @JvmStatic
531479 fun snackbar (activity : Activity , title : Any? , button : Any? , buttonCallback : Runnable ? , duration : Int ) {
532480 runOnUiThread {
0 commit comments