Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getPhilologyRepository function always giving locale as Englies #39

Open
prathej opened this issue May 15, 2021 · 0 comments
Open

getPhilologyRepository function always giving locale as Englies #39

prathej opened this issue May 15, 2021 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@prathej
Copy link

prathej commented May 15, 2021

Describe the bug
I have integrated this library in the Application class as mentioned in the docs but I am facing an issue that always I am getting language as English inside getPhilologyRepository function.

In my app, we set the language based on the user profile after login. For Arabic users, it changes to LTR, and for English users, it changes to RTL layout with respective languages. So user can change language in respective settings and I am setting the default language as per the user. As long as the user is logged in the default language will be the one he has set. Once he logs out it will be English.

I am not sure if this causes since I am setting up the logic in the application class and need your advice.

class SampleApp : Application(), HasAndroidInjector {

    @Inject
    lateinit var androidInjector: DispatchingAndroidInjector<Any>

    override fun onCreate() {
        super.onCreate()
        Cyanea.init(this, resources)
        val calligraphyConfig = CalligraphyConfig.Builder()
            .setDefaultFontPath("fonts/poppins_regular.ttf")
            .setFontAttrId(R.attr.fontPath)
            .build()
        Philology.init(MyPhilologyRepositoryFactory)
        ViewPump.init(
            ViewPump.builder()
                .addInterceptor(CalligraphyInterceptor(calligraphyConfig))
                .addInterceptor(PhilologyInterceptor)
                .build()
        )
        if (BuildConfig.DEBUG) {
            Timber.plant(DebugTree())
        }
    `}`

    override fun attachBaseContext(base: Context) {
        super.attachBaseContext(base)
        if (null == appComponent) {
            appComponent = DaggerAppComponent.builder()
                .appModule(AppModule(this))
                .build()
            appComponent?.inject(this)
        }
    }

    companion object {
        var appComponent: AppComponent? = null
            private set
    }

    override fun androidInjector(): AndroidInjector<Any> {
        return androidInjector
    }
}

object MyPhilologyRepositoryFactory : PhilologyRepositoryFactory {
    override fun getPhilologyRepository(locale: Locale): PhilologyRepository {
        Timber.tag("Philology").d("getPhilologyRepository -> locale - %s", locale.language)
        return when (locale.language) {
            ENGLISH -> EnglishPhilologyRepository
            ARABIC -> ArabicPhilologyRepository
            else -> EnglishPhilologyRepository
        }
    }
}
@prathej prathej added the bug Something isn't working label May 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants