mirror of
https://github.com/Lime3DS/Lime3DS.git
synced 2025-03-24 06:28:44 +01:00
Refactor SetupWarningDialogFragment to support multiple titles, descriptions, and help links
This commit is contained in:
parent
6f56108170
commit
33e11bf19c
@ -14,18 +14,18 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
|||||||
import org.citra.citra_emu.R
|
import org.citra.citra_emu.R
|
||||||
|
|
||||||
class SetupWarningDialogFragment : DialogFragment() {
|
class SetupWarningDialogFragment : DialogFragment() {
|
||||||
private var titleId: Int = 0
|
private var titleIds: IntArray = intArrayOf()
|
||||||
private var descriptionId: Int = 0
|
private var descriptionIds: IntArray = intArrayOf()
|
||||||
private var helpLinkId: Int = 0
|
private var helpLinkIds: IntArray = intArrayOf()
|
||||||
private var page: Int = 0
|
private var page: Int = 0
|
||||||
|
|
||||||
private lateinit var setupFragment: SetupFragment
|
private lateinit var setupFragment: SetupFragment
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
titleId = requireArguments().getInt(TITLE)
|
titleIds = requireArguments().getIntArray(TITLES) ?: intArrayOf()
|
||||||
descriptionId = requireArguments().getInt(DESCRIPTION)
|
descriptionIds = requireArguments().getIntArray(DESCRIPTIONS) ?: intArrayOf()
|
||||||
helpLinkId = requireArguments().getInt(HELP_LINK)
|
helpLinkIds = requireArguments().getIntArray(HELP_LINKS) ?: intArrayOf()
|
||||||
page = requireArguments().getInt(PAGE)
|
page = requireArguments().getInt(PAGE)
|
||||||
|
|
||||||
setupFragment = requireParentFragment() as SetupFragment
|
setupFragment = requireParentFragment() as SetupFragment
|
||||||
@ -39,16 +39,23 @@ class SetupWarningDialogFragment : DialogFragment() {
|
|||||||
}
|
}
|
||||||
.setNegativeButton(R.string.warning_cancel, null)
|
.setNegativeButton(R.string.warning_cancel, null)
|
||||||
|
|
||||||
if (titleId != 0) {
|
// Message builder to build multiple strings into one
|
||||||
builder.setTitle(titleId)
|
val messageBuilder = StringBuilder()
|
||||||
} else {
|
for (i in titleIds.indices) {
|
||||||
builder.setTitle("")
|
if (titleIds[i] != 0) {
|
||||||
|
messageBuilder.append(getString(titleIds[i])).append("\n\n")
|
||||||
}
|
}
|
||||||
if (descriptionId != 0) {
|
if (descriptionIds[i] != 0) {
|
||||||
builder.setMessage(descriptionId)
|
messageBuilder.append(getString(descriptionIds[i])).append("\n\n")
|
||||||
}
|
}
|
||||||
if (helpLinkId != 0) {
|
}
|
||||||
|
|
||||||
|
builder.setTitle("Warning")
|
||||||
|
builder.setMessage(messageBuilder.toString().trim())
|
||||||
|
|
||||||
|
if (helpLinkIds.any { it != 0 }) {
|
||||||
builder.setNeutralButton(R.string.warning_help) { _: DialogInterface?, _: Int ->
|
builder.setNeutralButton(R.string.warning_help) { _: DialogInterface?, _: Int ->
|
||||||
|
val helpLinkId = helpLinkIds.first { it != 0 }
|
||||||
val helpLink = resources.getString(helpLinkId)
|
val helpLink = resources.getString(helpLinkId)
|
||||||
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(helpLink))
|
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(helpLink))
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
@ -61,23 +68,23 @@ class SetupWarningDialogFragment : DialogFragment() {
|
|||||||
companion object {
|
companion object {
|
||||||
const val TAG = "SetupWarningDialogFragment"
|
const val TAG = "SetupWarningDialogFragment"
|
||||||
|
|
||||||
private const val TITLE = "Title"
|
private const val TITLES = "Titles"
|
||||||
private const val DESCRIPTION = "Description"
|
private const val DESCRIPTIONS = "Descriptions"
|
||||||
private const val HELP_LINK = "HelpLink"
|
private const val HELP_LINKS = "HelpLinks"
|
||||||
private const val PAGE = "Page"
|
private const val PAGE = "Page"
|
||||||
|
|
||||||
fun newInstance(
|
fun newInstance(
|
||||||
titleId: Int,
|
titleIds: IntArray,
|
||||||
descriptionId: Int,
|
descriptionIds: IntArray,
|
||||||
helpLinkId: Int,
|
helpLinkIds: IntArray,
|
||||||
page: Int
|
page: Int
|
||||||
): SetupWarningDialogFragment {
|
): SetupWarningDialogFragment {
|
||||||
val dialog = SetupWarningDialogFragment()
|
val dialog = SetupWarningDialogFragment()
|
||||||
val bundle = Bundle()
|
val bundle = Bundle()
|
||||||
bundle.apply {
|
bundle.apply {
|
||||||
putInt(TITLE, titleId)
|
putIntArray(TITLES, titleIds)
|
||||||
putInt(DESCRIPTION, descriptionId)
|
putIntArray(DESCRIPTIONS, descriptionIds)
|
||||||
putInt(HELP_LINK, helpLinkId)
|
putIntArray(HELP_LINKS, helpLinkIds)
|
||||||
putInt(PAGE, page)
|
putInt(PAGE, page)
|
||||||
}
|
}
|
||||||
dialog.arguments = bundle
|
dialog.arguments = bundle
|
||||||
|
Loading…
x
Reference in New Issue
Block a user