Skip to content

Commit a2b07ec

Browse files
committed
feat: add profile dialog
1 parent 8d2e785 commit a2b07ec

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

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

Lines changed: 37 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.getInputTextLayout
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,31 @@ 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+
waitForPositiveButton = false,
75+
) { dialog, text ->
76+
val isValid = text.isNotBlank()
77+
dialog.positiveButton.isEnabled = isValid
78+
}
4279
}
4380
}

0 commit comments

Comments
 (0)