Skip to content

Commit 3e0099a

Browse files
criticalAYdavid-allison
authored andcommitted
feat: add profile dialog
1 parent c5d9bbd commit 3e0099a

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

AnkiDroid/src/main/java/com/ichi2/anki/preferences/profiles/SwitchProfilesFragment.kt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,25 @@ package com.ichi2.anki.preferences.profiles
1919

2020
import android.os.Bundle
2121
import android.view.View
22+
import androidx.appcompat.app.AlertDialog
2223
import androidx.fragment.app.Fragment
2324
import com.google.android.material.appbar.MaterialToolbar
2425
import com.ichi2.anki.R
26+
import com.ichi2.anki.databinding.FragmentSwitchProfilesBinding
27+
import com.ichi2.utils.ValidationResult
28+
import com.ichi2.utils.input
29+
import com.ichi2.utils.negativeButton
30+
import com.ichi2.utils.positiveButton
31+
import com.ichi2.utils.show
32+
import com.ichi2.utils.title
33+
import dev.androidbroadcast.vbpd.viewBinding
2534

2635
/**
2736
* A [Fragment] that allows the user to switch between different profiles.
2837
*/
2938
class SwitchProfilesFragment : Fragment(R.layout.fragment_switch_profiles) {
39+
private val binding by viewBinding(FragmentSwitchProfilesBinding::bind)
40+
3041
override fun onViewCreated(
3142
view: View,
3243
savedInstanceState: Bundle?,
@@ -39,5 +50,33 @@ class SwitchProfilesFragment : Fragment(R.layout.fragment_switch_profiles) {
3950
requireActivity().onBackPressedDispatcher.onBackPressed()
4051
}
4152
}
53+
54+
binding.addProfileFab.setOnClickListener {
55+
showAddProfileDialog()
56+
}
57+
}
58+
59+
fun showAddProfileDialog() {
60+
AlertDialog
61+
.Builder(requireContext())
62+
.show {
63+
title(text = "Add profile")
64+
65+
positiveButton(R.string.dialog_add) {
66+
// TODO: handle profile creation
67+
}
68+
69+
negativeButton(R.string.dialog_cancel)
70+
setView(R.layout.dialog_generic_text_input)
71+
}.input(
72+
hint = "Profile name",
73+
displayKeyboard = true,
74+
validator = { text ->
75+
when {
76+
text.isNotBlank() -> ValidationResult.VALID
77+
else -> ValidationResult.REJECTED
78+
}
79+
},
80+
) { _, _ -> }
4281
}
4382
}

0 commit comments

Comments
 (0)