-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SchedulingFragment: Implement Material3 based ListPreference
Signed-off-by: Aayush Gupta <[email protected]>
- Loading branch information
1 parent
a160ff7
commit afcffe1
Showing
3 changed files
with
65 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
app/src/main/java/com/stevesoltys/seedvault/settings/preference/M3ListPreference.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 The Calyx Institute | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package com.stevesoltys.seedvault.settings.preference | ||
|
||
import android.app.Dialog | ||
import android.os.Bundle | ||
import androidx.preference.ListPreferenceDialogFragmentCompat | ||
import com.google.android.material.dialog.MaterialAlertDialogBuilder | ||
|
||
class M3ListPreference : ListPreferenceDialogFragmentCompat() { | ||
|
||
companion object { | ||
const val PREFERENCE_DIALOG_FRAGMENT_TAG = "androidx.preference.PreferenceFragment.DIALOG" | ||
|
||
fun newInstance(key: String?): M3ListPreference { | ||
val fragment = M3ListPreference() | ||
val bundle = Bundle(1) | ||
bundle.putString(ARG_KEY, key) | ||
fragment.arguments = bundle | ||
return fragment | ||
} | ||
} | ||
|
||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { | ||
val builder = MaterialAlertDialogBuilder(requireContext()) | ||
.setTitle(preference.dialogTitle) | ||
.setIcon(preference.dialogIcon) | ||
.setPositiveButton(preference.positiveButtonText, this) | ||
.setNegativeButton(preference.negativeButtonText, this) | ||
|
||
val contentView = onCreateDialogView(requireContext()) | ||
if (contentView != null) { | ||
onBindDialogView(contentView) | ||
builder.setView(contentView) | ||
} else { | ||
builder.setMessage(preference.dialogMessage) | ||
} | ||
|
||
onPrepareDialogBuilder(builder) | ||
return builder.create() | ||
} | ||
} | ||
|