Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ktiniatros committed May 31, 2023
1 parent 564e2b7 commit 90dfb6c
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import nl.rijksoverheid.ctr.design.R
interface DialogUtil {
fun presentDialog(
context: Context,
@StringRes title: Int? = null,
@StringRes title: Int,
message: String,
@StringRes positiveButtonText: Int,
positiveButtonCallback: () -> Unit,
Expand All @@ -29,7 +29,7 @@ class DialogUtilImpl : DialogUtil {

override fun presentDialog(
context: Context,
@StringRes title: Int?,
@StringRes title: Int,
message: String,
@StringRes positiveButtonText: Int,
positiveButtonCallback: () -> Unit,
Expand All @@ -38,16 +38,13 @@ class DialogUtilImpl : DialogUtil {
onDismissCallback: (() -> Unit)?
) {
val builder = MaterialAlertDialogBuilder(context, R.style.App_Dialog_DayNight)
.setTitle(title)
.setMessage(message)
.setPositiveButton(positiveButtonText) { dialog, _ ->
positiveButtonCallback()
dialog.dismiss()
}

title?.let {
builder.setTitle(title)
}

negativeButtonText?.let {
builder.setNegativeButton(it) { dialog, _ ->
negativeButtonCallback?.invoke()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.content.Context
import android.os.Bundle
import android.os.Parcelable
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.FragmentManager
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import kotlinx.parcelize.Parcelize
import nl.rijksoverheid.ctr.design.R
Expand All @@ -14,8 +15,9 @@ import nl.rijksoverheid.ctr.shared.ext.getParcelableCompat

@Parcelize
data class DialogFragmentData(
val title: Int,
val message: Int,
val title: Int? = null,
val message: Int? = null,
val text: String? = null,
val messageArguments: List<String>? = null,
val positiveButtonData: DialogButtonData,
val negativeButtonData: DialogButtonData? = null
Expand All @@ -24,16 +26,33 @@ data class DialogFragmentData(
class SharedDialogFragment : DialogFragment() {
companion object {
const val argumentsDataKey = "data"
private const val tag = "shared_dialog_fragment"

fun show(fragmentManager: FragmentManager, data: DialogFragmentData) {
val args = Bundle().apply {
putParcelable(argumentsDataKey, data)
}
SharedDialogFragment().apply { arguments = args }.show(fragmentManager, tag)
}
}

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
arguments?.getParcelableCompat<DialogFragmentData>(argumentsDataKey)?.let {
val builder = MaterialAlertDialogBuilder(requireContext(), R.style.App_Dialog_DayNight)
.setTitle(it.title)
.setMessage(it.message)

it.messageArguments?.toTypedArray()?.let { args ->
builder.setMessage(getString(it.message, *args))
it.title?.let { title ->
builder.setTitle(title)
}

it.message?.let { message ->
builder.setMessage(message)
it.messageArguments?.toTypedArray()?.let { args ->
builder.setMessage(getString(it.message, *args))
}
}

it.text?.let { text ->
builder.setMessage(text)
}

it.positiveButtonData.apply {
Expand All @@ -43,9 +62,11 @@ class SharedDialogFragment : DialogFragment() {
navigationActionId,
navigationArguments
)

is DialogButtonData.ResetApp -> {
(context?.getSystemService(Context.ACTIVITY_SERVICE) as? ActivityManager)?.clearApplicationUserData()
}

is DialogButtonData.Dismiss -> {
dialog.dismiss()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ import androidx.navigation.NavController
import androidx.navigation.fragment.NavHostFragment
import nl.rijksoverheid.ctr.appconfig.AppConfigViewModel
import nl.rijksoverheid.ctr.appconfig.models.AppStatus
import nl.rijksoverheid.ctr.design.utils.DialogButtonData
import nl.rijksoverheid.ctr.design.utils.DialogFragmentData
import nl.rijksoverheid.ctr.design.utils.DialogUtil
import nl.rijksoverheid.ctr.design.utils.IntentUtil
import nl.rijksoverheid.ctr.design.utils.SharedDialogFragment
import nl.rijksoverheid.ctr.holder.api.repositories.CoronaCheckRepository
import nl.rijksoverheid.ctr.holder.databinding.ActivityMainBinding
import nl.rijksoverheid.ctr.holder.ui.device_rooted.DeviceRootedViewModel
Expand Down Expand Up @@ -132,11 +135,11 @@ class HolderMainActivity : AppCompatActivity() {
})

priorityNotificationViewModel.showPriorityNotificationLiveData.observe(this, EventObserver {
dialogUtil.presentDialog(
context = this,
message = it,
positiveButtonCallback = {},
positiveButtonText = R.string.ok
SharedDialogFragment.show(
supportFragmentManager, DialogFragmentData(
text = it,
positiveButtonData = DialogButtonData.Dismiss(R.string.ok)
)
)
})

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package nl.rijksoverheid.ctr.holder.ui.priority_notification

import android.os.Bundle
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.DialogFragment
import nl.rijksoverheid.ctr.design.R
import nl.rijksoverheid.ctr.persistence.HolderCachedAppConfigUseCase
import org.koin.android.ext.android.inject

/*
* Copyright (c) 2021 De Staat der Nederlanden, Ministerie van Volksgezondheid, Welzijn en Sport.
* Licensed under the EUROPEAN UNION PUBLIC LICENCE v. 1.2
*
* SPDX-License-Identifier: EUPL-1.2
*
*/

class PriorityNotificationDialogFragment : DialogFragment() {

private val cachedAppConfigUseCase: HolderCachedAppConfigUseCase by inject()

override fun onCreateDialog(savedInstanceState: Bundle?) = AlertDialog.Builder(requireContext())
.setMessage("pou sia re")
.setPositiveButton(getString(R.string.ok)) { _, _ -> }
.create()
}

0 comments on commit 90dfb6c

Please sign in to comment.