-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ea16fe6
commit 8cf1f0b
Showing
34 changed files
with
1,292 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
app/src/main/java/com/anugrahdev/app/ikurir/preferences/PreferenceProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.anugrahdev.app.ikurir.preferences | ||
|
||
import android.content.Context | ||
import android.content.SharedPreferences | ||
import androidx.preference.PreferenceManager | ||
|
||
private const val KEY_LANGUAGE = "key_language" | ||
|
||
class PreferenceProvider(context: Context) { | ||
|
||
private val appContext = context.applicationContext | ||
|
||
private val preference: SharedPreferences | ||
get() = PreferenceManager.getDefaultSharedPreferences(appContext) | ||
|
||
fun setLanguage(language:String){ | ||
preference.edit().putString( | ||
KEY_LANGUAGE, | ||
language | ||
).apply() | ||
} | ||
|
||
fun getLanguage():String?{ | ||
return preference.getString(KEY_LANGUAGE, "Bahasa Indonesia") | ||
} | ||
|
||
|
||
|
||
} |
33 changes: 31 additions & 2 deletions
33
app/src/main/java/com/anugrahdev/app/ikurir/ui/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,46 @@ | ||
package com.anugrahdev.app.ikurir.ui | ||
|
||
import android.content.res.Configuration | ||
import android.content.res.Resources | ||
import android.os.Build | ||
import android.os.Bundle | ||
import android.util.DisplayMetrics | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.navigation.Navigation | ||
import com.anugrahdev.app.ikurir.R | ||
import com.anugrahdev.app.ikurir.preferences.PreferenceProvider | ||
import java.util.* | ||
|
||
class MainActivity : AppCompatActivity() { | ||
|
||
class MainActivity : AppCompatActivity() { | ||
private lateinit var prefs: PreferenceProvider | ||
var lang:String="id" | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
prefs = PreferenceProvider(this) | ||
setContentView(R.layout.main_activity) | ||
when(prefs.getLanguage()){ | ||
"Bahasa Indonesia" -> lang="id" | ||
"English" -> lang="en" | ||
} | ||
setAppLocale(lang); | ||
|
||
|
||
} | ||
|
||
private fun setAppLocale(localeCode: String) { | ||
val resources: Resources = resources | ||
val dm: DisplayMetrics = resources.getDisplayMetrics() | ||
val config: Configuration = resources.getConfiguration() | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { | ||
config.setLocale(Locale(localeCode.toLowerCase())) | ||
} else { | ||
config.locale = Locale(localeCode.toLowerCase()) | ||
} | ||
resources.updateConfiguration(config, dm) | ||
} | ||
|
||
override fun onConfigurationChanged(newConfig: Configuration) { | ||
super.onConfigurationChanged(newConfig) | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.