Commit 59c75921 authored by Harri Kirik's avatar Harri Kirik
Browse files

COVAPP-462: Update the Settings screen

parent 06439532
package org.dpppt.android.app.settings
import android.bluetooth.BluetoothAdapter
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Bundle
......@@ -26,6 +27,7 @@ import org.dpppt.android.app.common.util.ViewBindingHolder
import org.dpppt.android.app.common.util.ViewModelFactory
import org.dpppt.android.app.common.util.exhaustive
import org.dpppt.android.app.common.util.getAppVersionString
import org.dpppt.android.app.common.util.getTextWithBlueSpans
import org.dpppt.android.app.databinding.FragmentSettingsBinding
import org.dpppt.android.app.di.Injector
import org.dpppt.android.app.storage.SecureStorage
......@@ -65,6 +67,10 @@ class SettingsFragment : MvvmFragment(), ViewBindingHolder<FragmentSettingsBindi
initViewModel()
viewModel.start(tracingViewModel.appStatusLiveData, args.scrollDestination, savedInstanceState == null)
setOnBackPressed()
setupViews(view)
}
private fun setupViews(view: View) {
requireBinding {
batteryButton.setOnClickListener {
viewModel.batteryButtonClicked()
......@@ -74,13 +80,25 @@ class SettingsFragment : MvvmFragment(), ViewBindingHolder<FragmentSettingsBindi
viewModel.activateBluetooth()
}
buttonBack.setOnClickListener { navigateBack() }
versionText.text = getAppVersionString(view.context, env.showLongVersionInfo)
versionText.setOnClickListener { viewModel.onVersionClicked() }
setupVersionView(view.context)
languageLayout.setOnClickListener { showLanguageSelectionDialog() }
setupCrossCountryView(view.context)
}
}
private fun FragmentSettingsBinding.setupVersionView(context: Context) {
versionText.text = getAppVersionString(context, env.showLongVersionInfo)
versionText.setOnClickListener { viewModel.onVersionClicked() }
}
private fun FragmentSettingsBinding.setupCrossCountryView(context: Context) {
crossCountryDescription.text = context.getTextWithBlueSpans(
getString(R.string.settings_cross_country_description),
getString(R.string.settings_cross_country_description_blue_part),
)
crossCountryDescription.setOnClickListener { viewModel.crossCountryInfoLinkClicked() }
}
override fun onResume() {
super.onResume()
viewModel.start(tracingViewModel.appStatusLiveData, args.scrollDestination, false)
......@@ -103,9 +121,12 @@ class SettingsFragment : MvvmFragment(), ViewBindingHolder<FragmentSettingsBindi
}
is SettingsViewModel.Action.OpenPlayStoreUrl ->
startActivitySafely(Intent(Intent.ACTION_VIEW).setData(Uri.parse(URL_PLAY_STORE)))
SettingsViewModel.Action.ScrollToCrossCountryItem -> {
is SettingsViewModel.Action.ScrollToCrossCountryItem -> {
scrollToCrossCountryItem()
}
is SettingsViewModel.Action.OpenCountryInfoUrl -> {
startActivitySafely(Intent(Intent.ACTION_VIEW).setData(Uri.parse(action.url)))
}
}.exhaustive
}
......
......@@ -23,6 +23,7 @@ import org.dpppt.android.app.domain.usecase.dp3t.GaenStartUseCase
import org.dpppt.android.app.domain.usecase.dp3t.GaenStopUseCase
import org.dpppt.android.app.domain.usecase.dp3t.GaenSyncUseCase
import org.dpppt.android.app.domain.usecase.dp3t.IsGaenWorkingUseCase
import org.dpppt.android.app.domain.usecase.infopage.CreateGotSickAbroadPageUrlUseCase
import org.dpppt.android.app.domain.usecase.permissions.CheckBatteryOptimizationUseCase
import org.dpppt.android.app.main.model.TracingStatusInterface
import org.dpppt.android.app.util.dispose
......@@ -36,7 +37,8 @@ class SettingsViewModel @Inject constructor(
private val gaenStartUseCase: GaenStartUseCase,
private val gaenStopUseCase: GaenStopUseCase,
private val activityService: ActivityService,
private val syncUseCase: GaenSyncUseCase
private val syncUseCase: GaenSyncUseCase,
private val createGotSickAbroadPageUrlUseCase: CreateGotSickAbroadPageUrlUseCase
) : ViewModel() {
private val _action = MutableLiveData<Event<Action>>()
......@@ -53,6 +55,9 @@ class SettingsViewModel @Inject constructor(
private var disposables: List<Disposable> = listOf()
// Let's use a different disposable for links as these are one-shot things
private var linkDisposable: Disposable? = null
private val tracingStatusObserver = Observer(::tracingStatusChanged)
fun start(status: LiveData<TracingStatusInterface>, settingsScrollDestination: SettingsScrollDestination, isFirstStart: Boolean) {
......@@ -191,6 +196,20 @@ class SettingsViewModel @Inject constructor(
{ error -> Timber.e(error, "Sync error") }
)
fun crossCountryInfoLinkClicked() {
dispose(linkDisposable)
// For now this will be the same URL as on the Home screen
linkDisposable = createGotSickAbroadPageUrlUseCase.execute()
.backgroundToMain()
.subscribe(
{ url -> _action.value = Event(Action.OpenCountryInfoUrl(url)) },
{ error ->
Timber.e(error, "crossCountryInfoLinkClicked")
// NO-OP: This should not happen atm. But for the future we still want to consume this
}
)
}
sealed class Action {
data class GaenError(val e: Throwable) : Action()
object BluetoothError : Action()
......@@ -198,5 +217,6 @@ class SettingsViewModel @Inject constructor(
data class ShowPlayServicesUpdateDialog(val isUpdateRequired: Boolean) : Action()
object OpenPlayStoreUrl : Action()
object ScrollToCrossCountryItem : Action()
data class OpenCountryInfoUrl(val url: String) : Action()
}
}
......@@ -195,8 +195,8 @@
<string name="debug_view_all_logs">"Vaata kõiki logisid"</string>
<string name="debug_error_accessing_logs">"Logide ligipääsu viga."</string>
<string name="settings_cross_country_label">"Lähikontaktide salvestamine Euroopas"</string>
<string name="settings_cross_country_description">"HOIA äpp saab anonüümseid teavitusi enamiku Euroopa Liidu riikide lähikontaktide tuvastamise rakendustelt."</string>
<string name="settings_cross_country_description">"HOIA äpp saab anonüümseid teavitusi enamiku Euroopa Liidu riikide lähikontaktide tuvastamise rakendustelt. Tutvu riikide nimekirja ja tööpõhimõttega siin."</string>
<string name="settings_cross_country_description_blue_part">"Tutvu riikide nimekirja ja tööpõhimõttega siin."</string>
<!-- Debug screen, non-release text -->
<string name="debug_state_scroll_to_cross_country_at_settings">"Ava riikidevaheline Seadetes"</string>
<string name="home_infection_abroad_title">"Jäin haigeks välismaal"</string>
......
......@@ -197,8 +197,8 @@
<string name="debug_view_all_logs">"Посмотреть все логи"</string>
<string name="debug_error_accessing_logs">"Oшибка допуска к логам."</string>
<string name="settings_cross_country_label">"Обнаружение контактов с заболевшими в Европе"</string>
<string name="settings_cross_country_description">"HOIA получает уведомления о контактах из большинства приложений для остлеживания контактов в странах Европейского Союза"</string>
<string name="settings_cross_country_description">"HOIA получает уведомления о контактах из большинства приложений для остлеживания контактов в странах Европейского Союза. Tutvu riikide nimekirja ja tööpõhimõttega siin."</string>
<string name="settings_cross_country_description_blue_part">"Tutvu riikide nimekirja ja tööpõhimõttega siin."</string>
<!-- Debug screen, non-release text -->
<string name="debug_state_scroll_to_cross_country_at_settings">"Открыть международную информацию в настройках"</string>
<string name="home_infection_abroad_title">"Заболел за границей"</string>
......
......@@ -195,8 +195,8 @@
<string name="debug_view_all_logs">"View all logs"</string>
<string name="debug_error_accessing_logs">"Error accessing logs."</string>
<string name="settings_cross_country_label">"Exposure detection in Europe"</string>
<string name="settings_cross_country_description">"HOIA gets contact notifications from most of the contact tracing applications of the European Union countries"</string>
<string name="settings_cross_country_description">"HOIA gets contact notifications from most of the contact tracing applications of the European Union countries. See this for more information and the list of supported countries."</string>
<string name="settings_cross_country_description_blue_part">"See this for more information and the list of supported countries."</string>
<!-- Debug screen, non-release text -->
<string name="debug_state_scroll_to_cross_country_at_settings">"Open cross-country in Settings"</string>
<string name="home_infection_abroad_title">"I've fallen ill while abroad"</string>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment