Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
Add global stringRes() method to access string.xml from any place
Browse files Browse the repository at this point in the history
  • Loading branch information
ILIYANGERMANOV committed Apr 15, 2022
1 parent 0d36354 commit 59a93a0
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions app/src/main/java/com/ivy/wallet/IvyAndroidApp.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.ivy.wallet

import android.annotation.SuppressLint
import android.app.Application
import android.content.Context
import androidx.annotation.StringRes
import androidx.hilt.work.HiltWorkerFactory
import androidx.work.Configuration
import dagger.hilt.android.HiltAndroidApp
Expand All @@ -13,6 +16,11 @@ import javax.inject.Inject
*/
@HiltAndroidApp
class IvyAndroidApp : Application(), Configuration.Provider {
companion object {
@SuppressLint("StaticFieldLeak")
lateinit var appContext: Context
}


@Inject
lateinit var workerFactory: HiltWorkerFactory
Expand All @@ -25,8 +33,18 @@ class IvyAndroidApp : Application(), Configuration.Provider {

override fun onCreate() {
super.onCreate()
appContext = this

if (BuildConfig.DEBUG) {
Timber.plant(DebugTree())
}
}
}

fun stringRes(
@StringRes id: Int,
vararg args: String
): String {
//I don't want strings.xml to handle something different than String at this point
return IvyAndroidApp.appContext.getString(id, *args)
}

0 comments on commit 59a93a0

Please sign in to comment.