mirror of
https://github.com/wulkanowy/wulkanowy.git
synced 2025-02-20 21:04:45 +01:00
Add language change settings (#577)
This commit is contained in:
parent
323bc188b1
commit
38370d647d
@ -164,6 +164,7 @@ dependencies {
|
||||
implementation "eu.davidea:flexible-adapter-ui:1.0.0"
|
||||
implementation "com.aurelhubert:ahbottomnavigation:2.3.4"
|
||||
implementation "com.ncapdevi:frag-nav:3.3.0"
|
||||
implementation "com.github.YarikSOffice:lingver:1.1.0"
|
||||
|
||||
implementation "com.github.pwittchen:reactivenetwork-rx2:3.0.6"
|
||||
implementation "io.reactivex.rxjava2:rxandroid:2.1.1"
|
||||
|
@ -6,6 +6,7 @@ import android.util.Log.VERBOSE
|
||||
import androidx.multidex.MultiDex
|
||||
import androidx.work.Configuration
|
||||
import com.jakewharton.threetenabp.AndroidThreeTen
|
||||
import com.yariksoffice.lingver.Lingver
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.support.DaggerApplication
|
||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||
@ -44,6 +45,7 @@ class WulkanowyApp : DaggerApplication(), Configuration.Provider {
|
||||
super.onCreate()
|
||||
AndroidThreeTen.init(this)
|
||||
RxJavaPlugins.setErrorHandler(::onError)
|
||||
Lingver.init(this)
|
||||
themeManager.applyDefaultTheme()
|
||||
|
||||
initLogging()
|
||||
|
@ -33,6 +33,10 @@ class PreferencesRepository @Inject constructor(
|
||||
val gradeColorTheme: String
|
||||
get() = getString(R.string.pref_key_grade_color_scheme, R.string.pref_default_grade_color_scheme)
|
||||
|
||||
val appLanguageKey = context.getString(R.string.pref_key_app_language)
|
||||
val appLanguage
|
||||
get() = getString(appLanguageKey, R.string.pref_default_app_language)
|
||||
|
||||
val serviceEnableKey = context.getString(R.string.pref_key_services_enable)
|
||||
val isServiceEnabled: Boolean
|
||||
get() = getBoolean(serviceEnableKey, R.bool.pref_default_services_enable)
|
||||
|
@ -2,6 +2,7 @@ package io.github.wulkanowy.di
|
||||
|
||||
import android.appwidget.AppWidgetManager
|
||||
import android.content.Context
|
||||
import com.yariksoffice.lingver.Lingver
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||
@ -32,4 +33,8 @@ internal class AppModule {
|
||||
@Singleton
|
||||
@Provides
|
||||
fun provideAppInfo() = AppInfo()
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
fun provideLingver() = Lingver.getInstance()
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ import io.github.wulkanowy.ui.base.BaseFragment
|
||||
import io.github.wulkanowy.ui.modules.login.LoginActivity
|
||||
import io.github.wulkanowy.utils.AppInfo
|
||||
import io.github.wulkanowy.utils.hideSoftInput
|
||||
import io.github.wulkanowy.utils.openEmail
|
||||
import io.github.wulkanowy.utils.openEmailClient
|
||||
import io.github.wulkanowy.utils.openInternetBrowser
|
||||
import io.github.wulkanowy.utils.showSoftInput
|
||||
import kotlinx.android.synthetic.main.fragment_login_form.*
|
||||
@ -166,7 +166,7 @@ class LoginFormFragment : BaseFragment(), LoginFormView {
|
||||
}
|
||||
|
||||
override fun openEmail() {
|
||||
context?.openEmail(
|
||||
context?.openEmailClient(
|
||||
requireContext().getString(R.string.login_email_intent_title),
|
||||
"wulkanowyinc@gmail.com",
|
||||
requireContext().getString(R.string.login_email_subject),
|
||||
|
@ -14,7 +14,7 @@ import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.ui.base.BaseFragment
|
||||
import io.github.wulkanowy.ui.modules.main.MainActivity
|
||||
import io.github.wulkanowy.utils.AppInfo
|
||||
import io.github.wulkanowy.utils.openEmail
|
||||
import io.github.wulkanowy.utils.openEmailClient
|
||||
import io.github.wulkanowy.utils.openInternetBrowser
|
||||
import io.github.wulkanowy.utils.setOnItemClickListener
|
||||
import kotlinx.android.synthetic.main.fragment_login_student_select.*
|
||||
@ -102,7 +102,7 @@ class LoginStudentSelectFragment : BaseFragment(), LoginStudentSelectView {
|
||||
}
|
||||
|
||||
override fun openEmail() {
|
||||
context?.openEmail(
|
||||
context?.openEmailClient(
|
||||
requireContext().getString(R.string.login_email_intent_title),
|
||||
"wulkanowyinc@gmail.com",
|
||||
requireContext().getString(R.string.login_email_subject),
|
||||
|
@ -16,7 +16,7 @@ import io.github.wulkanowy.ui.base.BaseFragment
|
||||
import io.github.wulkanowy.ui.modules.login.LoginActivity
|
||||
import io.github.wulkanowy.utils.AppInfo
|
||||
import io.github.wulkanowy.utils.hideSoftInput
|
||||
import io.github.wulkanowy.utils.openEmail
|
||||
import io.github.wulkanowy.utils.openEmailClient
|
||||
import io.github.wulkanowy.utils.openInternetBrowser
|
||||
import io.github.wulkanowy.utils.showSoftInput
|
||||
import kotlinx.android.synthetic.main.fragment_login_symbol.*
|
||||
@ -131,7 +131,7 @@ class LoginSymbolFragment : BaseFragment(), LoginSymbolView {
|
||||
}
|
||||
|
||||
override fun openEmail() {
|
||||
context?.openEmail(
|
||||
context?.openEmailClient(
|
||||
requireContext().getString(R.string.login_email_intent_title),
|
||||
"wulkanowyinc@gmail.com",
|
||||
requireContext().getString(R.string.login_email_subject),
|
||||
|
@ -10,8 +10,8 @@ import io.github.wulkanowy.ui.base.BaseFragment
|
||||
import io.github.wulkanowy.ui.modules.main.MainView
|
||||
import io.github.wulkanowy.ui.modules.schoolandteachers.SchoolAndTeachersChildView
|
||||
import io.github.wulkanowy.ui.modules.schoolandteachers.SchoolAndTeachersFragment
|
||||
import io.github.wulkanowy.utils.dialPhone
|
||||
import io.github.wulkanowy.utils.openMapLocation
|
||||
import io.github.wulkanowy.utils.openDialer
|
||||
import io.github.wulkanowy.utils.openNavigation
|
||||
import kotlinx.android.synthetic.main.fragment_school.*
|
||||
import javax.inject.Inject
|
||||
|
||||
@ -86,10 +86,10 @@ class SchoolFragment : BaseFragment(), SchoolView, MainView.TitledView, SchoolAn
|
||||
}
|
||||
|
||||
override fun openMapsLocation(location: String) {
|
||||
context?.openMapLocation(location)
|
||||
context?.openNavigation(location)
|
||||
}
|
||||
|
||||
override fun dialPhone(phone: String) {
|
||||
context?.dialPhone(phone)
|
||||
context?.openDialer(phone)
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import android.content.SharedPreferences
|
||||
import android.os.Bundle
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
import com.yariksoffice.lingver.Lingver
|
||||
import dagger.android.support.AndroidSupportInjection
|
||||
import io.github.wulkanowy.R
|
||||
import io.github.wulkanowy.ui.base.BaseActivity
|
||||
@ -12,7 +13,8 @@ import io.github.wulkanowy.ui.modules.main.MainView
|
||||
import io.github.wulkanowy.utils.AppInfo
|
||||
import javax.inject.Inject
|
||||
|
||||
class SettingsFragment : PreferenceFragmentCompat(), SharedPreferences.OnSharedPreferenceChangeListener,
|
||||
class SettingsFragment : PreferenceFragmentCompat(),
|
||||
SharedPreferences.OnSharedPreferenceChangeListener,
|
||||
MainView.TitledView, SettingsView {
|
||||
|
||||
@Inject
|
||||
@ -21,6 +23,9 @@ class SettingsFragment : PreferenceFragmentCompat(), SharedPreferences.OnSharedP
|
||||
@Inject
|
||||
lateinit var appInfo: AppInfo
|
||||
|
||||
@Inject
|
||||
lateinit var lingver: Lingver
|
||||
|
||||
companion object {
|
||||
fun newInstance() = SettingsFragment()
|
||||
}
|
||||
@ -50,6 +55,10 @@ class SettingsFragment : PreferenceFragmentCompat(), SharedPreferences.OnSharedP
|
||||
activity?.recreate()
|
||||
}
|
||||
|
||||
override fun updateLanguage(langCode: String) {
|
||||
lingver.setLocale(requireContext(), langCode)
|
||||
}
|
||||
|
||||
override fun setServicesSuspended(serviceEnablesKey: String, isHolidays: Boolean) {
|
||||
findPreference<Preference>(serviceEnablesKey)?.apply {
|
||||
summary = if (isHolidays) getString(R.string.pref_services_suspended) else ""
|
||||
|
@ -6,6 +6,7 @@ import io.github.wulkanowy.data.repositories.student.StudentRepository
|
||||
import io.github.wulkanowy.services.sync.SyncManager
|
||||
import io.github.wulkanowy.ui.base.BasePresenter
|
||||
import io.github.wulkanowy.ui.base.ErrorHandler
|
||||
import io.github.wulkanowy.utils.AppInfo
|
||||
import io.github.wulkanowy.utils.FirebaseAnalyticsHelper
|
||||
import io.github.wulkanowy.utils.SchedulersProvider
|
||||
import io.github.wulkanowy.utils.isHolidays
|
||||
@ -20,7 +21,8 @@ class SettingsPresenter @Inject constructor(
|
||||
private val preferencesRepository: PreferencesRepository,
|
||||
private val analytics: FirebaseAnalyticsHelper,
|
||||
private val syncManager: SyncManager,
|
||||
private val chuckCollector: ChuckCollector
|
||||
private val chuckCollector: ChuckCollector,
|
||||
private val appInfo: AppInfo
|
||||
) : BasePresenter<SettingsView>(errorHandler, studentRepository, schedulers) {
|
||||
|
||||
override fun onAttachView(view: SettingsView) {
|
||||
@ -38,6 +40,10 @@ class SettingsPresenter @Inject constructor(
|
||||
servicesIntervalKey, servicesOnlyWifiKey -> syncManager.startSyncWorker(true)
|
||||
isDebugNotificationEnableKey -> chuckCollector.showNotification(isDebugNotificationEnable)
|
||||
appThemeKey -> view?.recreateView()
|
||||
appLanguageKey -> view?.run {
|
||||
updateLanguage(if (appLanguage == "system") appInfo.systemLanguage else appLanguage)
|
||||
recreateView()
|
||||
}
|
||||
else -> Unit
|
||||
}
|
||||
}
|
||||
|
@ -6,5 +6,7 @@ interface SettingsView : BaseView {
|
||||
|
||||
fun recreateView()
|
||||
|
||||
fun updateLanguage(langCode: String)
|
||||
|
||||
fun setServicesSuspended(serviceEnablesKey: String, isHolidays: Boolean)
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.github.wulkanowy.utils
|
||||
|
||||
import android.content.res.Resources
|
||||
import android.os.Build.MANUFACTURER
|
||||
import android.os.Build.MODEL
|
||||
import android.os.Build.VERSION.SDK_INT
|
||||
@ -25,4 +26,8 @@ open class AppInfo {
|
||||
open val systemManufacturer: String get() = MANUFACTURER
|
||||
|
||||
open val systemModel: String get() = MODEL
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
open val systemLanguage: String
|
||||
get() = Resources.getSystem().configuration.locale.language
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ fun Context.openInternetBrowser(uri: String, onActivityNotFound: (uri: String) -
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.openEmail(chooserTitle: String, email: String, subject: String?, body: String?) {
|
||||
fun Context.openEmailClient(chooserTitle: String, email: String, subject: String?, body: String?) {
|
||||
val emailIntent = Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", email, null))
|
||||
emailIntent.putExtra(Intent.EXTRA_EMAIL, arrayOf(email))
|
||||
if (subject != null) emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject)
|
||||
@ -40,7 +40,7 @@ fun Context.openEmail(chooserTitle: String, email: String, subject: String?, bod
|
||||
startActivity(Intent.createChooser(emailIntent, chooserTitle))
|
||||
}
|
||||
|
||||
fun Context.openMapLocation(location: String) {
|
||||
fun Context.openNavigation(location: String) {
|
||||
val intentUri = Uri.parse("geo:0,0?q=${Uri.encode(location)}")
|
||||
val intent = Intent(Intent.ACTION_VIEW, intentUri)
|
||||
if (intent.resolveActivity(packageManager) != null) {
|
||||
@ -48,7 +48,7 @@ fun Context.openMapLocation(location: String) {
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.dialPhone(phone: String) {
|
||||
fun Context.openDialer(phone: String) {
|
||||
val intentUri = Uri.parse("tel:$phone")
|
||||
val intent = Intent(Intent.ACTION_DIAL, intentUri)
|
||||
startActivity(intent)
|
||||
|
@ -16,6 +16,12 @@
|
||||
<item>Czarny (AMOLED)</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="app_language_entries">
|
||||
<item>Język systemu</item>
|
||||
<item>Polski</item>
|
||||
<item>English</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="grade_modifier_entries">
|
||||
<item>Domyślna</item>
|
||||
<item>0,25</item>
|
||||
|
@ -300,6 +300,7 @@
|
||||
<string name="pref_view_app_theme">Motyw aplikacji</string>
|
||||
<string name="pref_view_expand_grade">Rozwiń oceny</string>
|
||||
<string name="pref_view_grade_color_scheme">Schemat kolorów ocen</string>
|
||||
<string name="pref_view_app_language">Język aplikacji</string>
|
||||
|
||||
<string name="pref_notify_header">Powiadomienia</string>
|
||||
<string name="pref_notify_switch">Pokazuj powiadomienia</string>
|
||||
|
@ -7,6 +7,7 @@
|
||||
<bool name="pref_default_expand_grade">false</bool>
|
||||
<string name="pref_default_app_theme">light</string>
|
||||
<string name="pref_default_grade_color_scheme">vulcan</string>
|
||||
<string name="pref_default_app_language">system</string>
|
||||
<bool name="pref_default_services_enable">true</bool>
|
||||
<string name="pref_default_services_interval">60</string>
|
||||
<bool name="pref_default_services_wifi_only">false</bool>
|
||||
|
@ -7,6 +7,7 @@
|
||||
<string name="pref_key_expand_grade">expand_grade</string>
|
||||
<string name="pref_key_grade_average_mode">grade_average_mode</string>
|
||||
<string name="pref_key_grade_average_force_calc">grade_average_always_calc</string>
|
||||
<string name="pref_key_app_language">app_language</string>
|
||||
<string name="pref_key_services_enable">services_enable</string>
|
||||
<string name="pref_key_services_interval">services_interval</string>
|
||||
<string name="pref_key_services_wifi_only">services_disable_wifi_only</string>
|
||||
|
@ -24,6 +24,17 @@
|
||||
<item>black</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="app_language_entries">
|
||||
<item>System language</item>
|
||||
<item>Polski</item>
|
||||
<item>English</item>
|
||||
</string-array>
|
||||
<string-array name="app_language_values" translatable="false">
|
||||
<item>system</item>
|
||||
<item>pl</item>
|
||||
<item>en</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="services_interval_entries">
|
||||
<item>15 minutes</item>
|
||||
<item>30 minutes</item>
|
||||
|
@ -286,6 +286,7 @@
|
||||
<string name="pref_view_app_theme">Application theme</string>
|
||||
<string name="pref_view_expand_grade">Expand grades</string>
|
||||
<string name="pref_view_grade_color_scheme">Grades color scheme</string>
|
||||
<string name="pref_view_app_language">App language</string>
|
||||
|
||||
<string name="pref_notify_header">Notifications</string>
|
||||
<string name="pref_notify_switch">Show notifications</string>
|
||||
|
@ -37,6 +37,14 @@
|
||||
app:key="@string/pref_key_grade_color_scheme"
|
||||
app:title="@string/pref_view_grade_color_scheme"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
<ListPreference
|
||||
app:defaultValue="@string/pref_default_app_language"
|
||||
app:entries="@array/app_language_entries"
|
||||
app:entryValues="@array/app_language_values"
|
||||
app:iconSpaceReserved="false"
|
||||
app:key="@string/pref_key_app_language"
|
||||
app:title="@string/pref_view_app_language"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory
|
||||
app:iconSpaceReserved="false"
|
||||
@ -106,9 +114,9 @@
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
<SwitchPreferenceCompat
|
||||
app:defaultValue="@bool/pref_default_grade_average_force_calc"
|
||||
app:iconSpaceReserved="false"
|
||||
app:key="@string/pref_key_grade_average_force_calc"
|
||||
app:title="@string/pref_view_grade_average_force_calc"
|
||||
app:iconSpaceReserved="false" />
|
||||
app:title="@string/pref_view_grade_average_force_calc" />
|
||||
<SwitchPreferenceCompat
|
||||
app:defaultValue="@bool/pref_default_fill_message_content"
|
||||
app:iconSpaceReserved="false"
|
||||
|
Loading…
x
Reference in New Issue
Block a user