chinwag-android/app/src/main/java/com/keylesspalace/tusky/view/MuteAccountDialog.kt
Konrad Pozniak 50ca44a5f6
Material Design 3 (#4637)
I tried to find a balance between going fully M3 and keeping some of the
original Tusky feeling.
For example, I removed the "allCaps" setting we had on most buttons,
which is recommended for M3. On the other hand, I made them less rounded
than the M3 default.

<img
src="https://github.com/user-attachments/assets/9d2485e0-7d1d-42ab-8a4e-c30d044aa5dc"
width="320"/>
<img
src="https://github.com/user-attachments/assets/d65d3c91-afe9-424e-92d7-e0f3e401ea4b"
width="320"/>
<img
src="https://github.com/user-attachments/assets/d5634440-c507-4484-a11e-983f47cbeab7"
width="320"/>
2024-09-10 19:50:09 +02:00

45 lines
1.6 KiB
Kotlin

@file:JvmName("MuteAccountDialog")
package com.keylesspalace.tusky.view
import android.app.Activity
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.keylesspalace.tusky.R
import com.keylesspalace.tusky.databinding.DialogMuteAccountBinding
fun showMuteAccountDialog(
activity: Activity,
accountUsername: String,
onOk: (notifications: Boolean, duration: Int?) -> Unit
) {
val binding = DialogMuteAccountBinding.inflate(activity.layoutInflater)
binding.warning.text = activity.getString(R.string.dialog_mute_warning, accountUsername)
binding.checkbox.isChecked = true
val durationLabels = activity.resources.getStringArray(R.array.mute_duration_names)
binding.durationDropDown.setSimpleItems(durationLabels)
var selectedDurationIndex = 0
binding.durationDropDown.setOnItemClickListener { _, _, position, _ ->
selectedDurationIndex = position
}
binding.durationDropDown.setText(durationLabels[selectedDurationIndex], false)
MaterialAlertDialogBuilder(activity)
.setView(binding.root)
.setPositiveButton(android.R.string.ok) { _, _ ->
val durationValues = activity.resources.getIntArray(R.array.mute_duration_values)
// workaround to make indefinite muting work with Mastodon 3.3.0
// https://github.com/tuskyapp/Tusky/issues/2107
val duration = if (selectedDurationIndex == 0) {
null
} else {
durationValues[selectedDurationIndex]
}
onOk(binding.checkbox.isChecked, duration)
}
.setNegativeButton(android.R.string.cancel, null)
.show()
}