package com.bassbooster.soundeffects.equalizer.view.activity.setting.language

import android.content.Context
import android.content.SharedPreferences
import android.content.res.Configuration
import android.content.res.Resources
import java.util.Locale

@Suppress("DEPRECATION")
class LanguageManager {
    private lateinit var mContext: Context;
    private lateinit var sharedPreferences: SharedPreferences
    fun languageManager(context: Context) {
        mContext = context
        sharedPreferences = mContext.getSharedPreferences("LANG", Context.MODE_PRIVATE)
    }

    fun updateResource(code: String) {
        val locale = Locale(code)
        Locale.setDefault(locale)
        val resources: Resources = mContext.getResources()
        val configuration: Configuration = resources.configuration
        configuration.locale = locale
        resources.updateConfiguration(configuration, resources.displayMetrics)
//        setLang(code)
    }

    fun getLang(): String? {
        return sharedPreferences.getString("lang", "en")
    }

    private fun setLang(code: String) {
        val editor = sharedPreferences.edit()
        editor.putString("lang", code)
        editor.commit()
    }
}
