Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Adjusted onboarding flow, adjusted contribution file, small fixes in settings #106

Merged
merged 11 commits into from
Jun 2, 2020
Merged
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ The following rule governs documentation contributions:

## Pull Request Checklist

* Branch from the master branch and, if needed, rebase to the current master branch before submitting your pull request. If it doesn't merge cleanly with master, you may be asked to rebase your changes.
* Branch from the dev branch and ensure it is up to date with the current dev branch before submitting your pull request. If it doesn't merge cleanly with dev, you may be asked to resolve the conflicts. Pull requests to master will be closed.

* Commits should be as small as possible while ensuring that each commit is correct independently (i.e., each commit should compile and pass tests).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@ import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AlertDialog
import androidx.core.app.NotificationManagerCompat
import de.rki.coronawarnapp.R
import de.rki.coronawarnapp.databinding.FragmentOnboardingNotificationsBinding
import de.rki.coronawarnapp.storage.SettingsRepository
import de.rki.coronawarnapp.ui.BaseFragment
import de.rki.coronawarnapp.util.DialogHelper
import de.rki.coronawarnapp.util.SettingsNavigationHelper

/**
* This fragment ask the user if he wants to get notifications and finishes the onboarding afterwards.
Expand Down Expand Up @@ -42,48 +38,14 @@ class OnboardingNotificationsFragment : BaseFragment() {

private fun setButtonOnClickListener() {
binding.onboardingButtonFinish.setOnClickListener {
finishOrSettings()
}
binding.onboardingButtonDisable.setOnClickListener {
// Set default value for notifications to false
SettingsRepository.toggleNotificationsRiskEnabled()
SettingsRepository.toggleNotificationsTestEnabled()
navigateToMain()
}
binding.onboardingButtonBack.buttonIcon.setOnClickListener {
(activity as OnboardingActivity).goBack()
}
}

private fun finishOrSettings() {
// If the os notifications settings are enabled the user can finish the onboarding.
// If the user want to get notifications but they are disabled on the os level he can go
// to the notification settings to activate them.
val areNotificationsEnabled =
NotificationManagerCompat.from(requireContext()).areNotificationsEnabled()
if (areNotificationsEnabled) {
navigateToMain()
} else {
showNotificationsDisabledDialog()
}
}

private fun navigateToMain() {
(requireActivity() as OnboardingActivity).completeOnboarding()
}

private fun showNotificationsDisabledDialog() {
val dialog = DialogHelper.DialogInstance(
requireActivity(),
R.string.onboarding_notifications_headline,
R.string.onboarding_notifications_dialog_body,
R.string.onboarding_notifications_dialog_button_positive,
R.string.onboarding_notifications_dialog_button_negative,
{
SettingsNavigationHelper.toNotifications(requireContext())
}, {
navigateToMain()
})
DialogHelper.showDialog(dialog)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class OnboardingTracingFragment : BaseFragment(),
internalExposureNotificationPermissionHelper.requestPermissionToStartTracing()
}
binding.onboardingButtonDisable.setOnClickListener {
navigate()
showCancelDialog()
}
binding.onboardingButtonBack.buttonIcon.setOnClickListener {
(activity as OnboardingActivity).goBack()
Expand All @@ -72,7 +72,7 @@ class OnboardingTracingFragment : BaseFragment(),
}

override fun onFailure(exception: Exception?) {
showCancelDialog()
navigate()
}

private fun showCancelDialog() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class SettingsTracingFragment : BaseFragment(),
(activity as MainActivity).goBack()
}
binding.settingsTracingStatusBluetooth.tracingStatusCardButton.setOnClickListener {
SettingsNavigationHelper.toBluetooth(requireContext())
SettingsNavigationHelper.toConnections(requireContext())
}
binding.settingsTracingStatusConnection.tracingStatusCardButton.setOnClickListener {
SettingsNavigationHelper.toConnections(requireContext())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,6 @@ import android.provider.Settings
*/
object SettingsNavigationHelper {

/**
* Navigate the user to the os bluetooth settings.
*
* @param context
*/
fun toBluetooth(context: Context) {
val intent = Intent()
intent.action = Settings.ACTION_BLUETOOTH_SETTINGS
context.startActivity(intent)
}

/**
* Navigate the user to the os connection settings.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,40 @@ fun formatStatus(value: Boolean): String = formatText(
)

/**
* Formats the main text display of tracing status depending on tracing status
* Formats the text display of settings notification status depending on notification values
*
* @param notifications
* @param notificationsRisk
* @param notificationsTest
* @return
*/
fun formatNotificationsStatusText(
notifications: Boolean,
notificationsRisk: Boolean,
notificationsTest: Boolean
): String =
formatStatus((notifications && (notificationsRisk || notificationsTest)))

/**
* Change the tracing text in the row based on the tracing status.
*
* @param tracing
* @param bluetooth
* @param connection
* @return String
*/
fun formatTracingStatusText(tracing: Boolean): String = formatText(
tracing,
R.string.settings_tracing_body_active,
R.string.settings_tracing_body_inactive
)
fun formatTracingStatusText(tracing: Boolean, bluetooth: Boolean, connection: Boolean): String {
val appContext = CoronaWarnApplication.getAppContext()
return when (tracingStatusHelper(tracing, bluetooth, connection)) {
TracingStatusHelper.CONNECTION, TracingStatusHelper.BLUETOOTH ->
appContext.getString(R.string.settings_tracing_status_restricted)
TracingStatusHelper.TRACING_ACTIVE ->
appContext.getString(R.string.settings_tracing_status_active)
TracingStatusHelper.TRACING_INACTIVE ->
appContext.getString(R.string.settings_tracing_status_inactive)
else -> ""
}
}

/**
* Format the settings tracing description text display depending on tracing status
Expand Down Expand Up @@ -82,12 +106,12 @@ fun formatNotificationsDescription(notifications: Boolean): String = formatText(
* Formats the tracing body depending on the tracing status and the days since last exposure.
*
* @param tracing
* @param daysSinceLastExposure
* @param activeTracingDaysInRetentionPeriod
* @return String
*/
fun formatTracingStatusBody(tracing: Boolean, daysSinceLastExposure: Int): String {
fun formatTracingStatusBody(tracing: Boolean, activeTracingDaysInRetentionPeriod: Long): String {
val appContext = CoronaWarnApplication.getAppContext()
val daysArg = daysSinceLastExposure.toString()
val daysArg = activeTracingDaysInRetentionPeriod.toString()
return if (tracing) {
appContext.getString(R.string.settings_tracing_status_body_active)
.format(daysArg)
Expand All @@ -107,6 +131,21 @@ fun formatTracingStatusBody(tracing: Boolean, daysSinceLastExposure: Int): Strin
fun formatIconColor(active: Boolean): Int =
formatColor(active, R.color.settingsIconActive, R.color.settingsIconInactive)

/**
* Formats the settings icon color for notifications depending on notification values
*
* @param notifications
* @param notificationsRisk
* @param notificationsTest
* @return Int
*/
fun formatIconColor(
notifications: Boolean,
notificationsRisk: Boolean,
notificationsTest: Boolean
): Int =
formatIconColor((notifications && (notificationsRisk || notificationsTest)))

/**
* Formats the tracing switch status based on the tracing status
*
Expand Down Expand Up @@ -257,27 +296,6 @@ fun formatTracingStatusVisibilityTracing(
)
}

/**
* Change the tracing text in the row based on the tracing status.
*
* @param tracing
* @param bluetooth
* @param connection
* @return String
*/
fun formatTracingStatusText(tracing: Boolean, bluetooth: Boolean, connection: Boolean): String {
val appContext = CoronaWarnApplication.getAppContext()
return when (tracingStatusHelper(tracing, bluetooth, connection)) {
TracingStatusHelper.CONNECTION, TracingStatusHelper.BLUETOOTH ->
appContext.getString(R.string.settings_tracing_status_restricted)
TracingStatusHelper.TRACING_ACTIVE ->
appContext.getString(R.string.settings_tracing_status_active)
TracingStatusHelper.TRACING_INACTIVE ->
appContext.getString(R.string.settings_tracing_status_inactive)
else -> ""
}
}

/**
* Formats the settings notifications details illustration depending on notifications status
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,6 @@
app:layout_constraintStart_toStartOf="@id/guideline_start"
app:layout_constraintTop_toBottomOf="@id/guideline_bottom" />

<Button
android:id="@+id/onboarding_button_disable"
style="@style/buttonLight"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_small"
android:text="@string/onboarding_button_disable"
app:layout_constraintEnd_toEndOf="@id/guideline_end"
app:layout_constraintStart_toStartOf="@id/guideline_start"
app:layout_constraintTop_toBottomOf="@id/onboarding_button_finish" />

<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline_top"
android:layout_width="wrap_content"
Expand All @@ -63,7 +52,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_end="@dimen/guideline_action_large" />
app:layout_constraintGuide_end="@dimen/guideline_action" />

<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline_start"
Expand Down
9 changes: 7 additions & 2 deletions Corona-Warn-App/src/main/res/layout/fragment_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@

<data>

<import type="de.rki.coronawarnapp.util.formatter.FormatterSettingsHelper" />

<variable
name="tracingViewModel"
type="de.rki.coronawarnapp.ui.viewmodel.TracingViewModel" />

<variable
name="settingsViewModel"
type="de.rki.coronawarnapp.ui.viewmodel.SettingsViewModel" />

</data>

<ScrollView
Expand Down Expand Up @@ -47,7 +50,8 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/settings_header"
app:showDivider="@{true}"
app:status="@{tracingViewModel.isTracingEnabled()}"
app:color="@{FormatterSettingsHelper.formatIconColor(tracingViewModel.isTracingEnabled())}"
app:statusText="@{FormatterSettingsHelper.formatTracingStatusText(tracingViewModel.isTracingEnabled(), settingsViewModel.isBluetoothEnabled(), settingsViewModel.isConnectionEnabled())}"
app:subtitle="@{@string/settings_tracing_title}"
app:tracingViewModel="@{tracingViewModel}" />

Expand All @@ -62,7 +66,8 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/settings_tracing"
app:showDivider="@{true}"
app:status="@{settingsViewModel.isNotificationsEnabled()}"
app:color="@{FormatterSettingsHelper.formatIconColor(settingsViewModel.isNotificationsEnabled(), settingsViewModel.isNotificationsRiskEnabled(), settingsViewModel.isNotificationsTestEnabled())}"
app:statusText="@{FormatterSettingsHelper.formatNotificationsStatusText(settingsViewModel.isNotificationsEnabled(), settingsViewModel.isNotificationsRiskEnabled(), settingsViewModel.isNotificationsTestEnabled())}"
app:subtitle="@{@string/settings_notifications_title}"
app:tracingViewModel="@{tracingViewModel}" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
android:layout_width="@dimen/match_constraint"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_small"
android:text="@{FormatterSettingsHelper.formatTracingStatusBody(tracingViewModel.isTracingEnabled(), tracingViewModel.daysSinceLastExposure)}"
android:text="@{FormatterSettingsHelper.formatTracingStatusBody(tracingViewModel.isTracingEnabled(), tracingViewModel.activeTracingDaysInRetentionPeriod)}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Expand Down
12 changes: 8 additions & 4 deletions Corona-Warn-App/src/main/res/layout/include_setting_row.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@
type="String" />

<variable
name="status"
type="Boolean" />
name="color"
type="Integer" />

<variable
name="statusText"
type="String" />

<variable
name="body"
Expand Down Expand Up @@ -53,7 +57,7 @@
android:layout_height="@dimen/icon_size_settings"
android:importantForAccessibility="no"
android:src="@{icon}"
android:tint="@{FormatterSettingsHelper.formatIconColor(status)}"
android:tint="@{color}"
app:layout_constraintBottom_toBottomOf="@id/settings_row_header"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/settings_row_header" />
Expand All @@ -80,7 +84,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingTop="@dimen/spacing_mega_tiny"
android:text="@{FormatterSettingsHelper.formatStatus(status)}"
android:text="@{statusText}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand Down