Skip to content

Commit 6ed9f31

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

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

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

Lines changed: 38 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,32 @@ 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+
negativeButton(R.string.dialog_cancel)
67+
setView(R.layout.dialog_generic_text_input)
68+
}.input(
69+
hint = "Profile name",
70+
displayKeyboard = true,
71+
validator = { text ->
72+
when {
73+
text.isNotBlank() -> ValidationResult.VALID
74+
else -> ValidationResult.REJECTED
75+
}
76+
},
77+
) { _, _ ->
78+
// TODO: handle profile creation
79+
}
4280
}
4381
}

0 commit comments

Comments
 (0)