-
Notifications
You must be signed in to change notification settings - Fork 27
Redesigned the Admin page with proper functionality #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
siddhigupta075
wants to merge
2
commits into
iiitl:master
Choose a base branch
from
siddhigupta075:feature/admin-page-redesign
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -13,60 +13,95 @@ import com.theayushyadav11.MessEase.utils.Constants.Companion.DESIGNATION | |
| import com.theayushyadav11.MessEase.utils.Mess | ||
|
|
||
| class AdminFragment : Fragment() { | ||
| private lateinit var binding: FragmentAdminBinding | ||
| private lateinit var mess: Mess | ||
|
|
||
| private var _binding: FragmentAdminBinding? = null | ||
| private val binding get() = _binding!! | ||
|
|
||
| private lateinit var mess: Mess | ||
| private val viewModel: AdminViewModel by viewModels() | ||
|
|
||
| override fun onCreateView( | ||
| inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? | ||
| ): View { | ||
| binding = FragmentAdminBinding.inflate(layoutInflater, container, false) | ||
| _binding = FragmentAdminBinding.inflate(inflater, container, false) | ||
| return binding.root | ||
| } | ||
|
|
||
| override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
| super.onViewCreated(view, savedInstanceState) | ||
| initialise() | ||
| listeners() | ||
| } | ||
|
|
||
| private fun initialise() { | ||
| mess = Mess(requireContext()) | ||
| setAdapter() | ||
| } | ||
|
|
||
| private fun listeners() { | ||
| binding.btnAdd.setOnClickListener { | ||
| add() | ||
| validateAndAdd() | ||
| } | ||
| } | ||
|
|
||
| private fun initialise() { | ||
| mess = Mess(requireContext()) | ||
| setAdapter() | ||
| } | ||
| private fun validateAndAdd() { | ||
| val email = binding.etEmail.text.toString().trim() | ||
| val designation = binding.spinnerAutoComplete.text.toString().trim() | ||
|
|
||
| when { | ||
| email.isEmpty() -> { | ||
| binding.tilEmail.error = "Email required" | ||
| } | ||
|
|
||
| fun add() { | ||
| if (binding.etEmail.text.toString().isNotEmpty()) { | ||
| mess.addPb("Adding to Mess Committee") | ||
| viewModel.addToMessCommittee( | ||
| binding.etEmail.text.toString(), | ||
| binding.spinnerAutoComplete.text.toString() | ||
| ) | ||
| { | ||
| mess.pbDismiss() | ||
| mess.toast(it) | ||
| !android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches() -> { | ||
| binding.tilEmail.error = "Invalid email" | ||
| } | ||
| } else { | ||
| mess.toast("Please enter email") | ||
|
|
||
| designation.isEmpty() -> { | ||
| binding.tilspin.error = "Select designation" | ||
| } | ||
|
|
||
| else -> { | ||
| binding.tilEmail.error = null | ||
| binding.tilspin.error = null | ||
| add(email, designation) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private fun add(email: String, designation: String) { | ||
| // Disable button to avoid spam clicking | ||
| binding.btnAdd.isEnabled = false | ||
| binding.btnAdd.text = "Adding..." | ||
|
|
||
| mess.addPb("Adding to Mess Committee") | ||
|
|
||
| viewModel.addToMessCommittee(email, designation) { | ||
| mess.pbDismiss() | ||
|
|
||
| binding.btnAdd.isEnabled = true | ||
| binding.btnAdd.text = "Add to Committee" | ||
|
|
||
| mess.toast(it) | ||
|
|
||
| // Clear fields after success | ||
| binding.etEmail.text?.clear() | ||
| binding.spinnerAutoComplete.text?.clear() | ||
| } | ||
|
Comment on lines
+78
to
89
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guard async callbacks against Fragment view destruction. These callbacks use Safer callback handling private fun add(email: String, designation: String) {
binding.btnAdd.isEnabled = false
binding.btnAdd.text = "Adding..."
mess.addPb("Adding to Mess Committee")
viewModel.addToMessCommittee(email, designation) {
+ val b = _binding ?: return@addToMessCommittee
mess.pbDismiss()
- binding.btnAdd.isEnabled = true
- binding.btnAdd.text = "Add to Committee"
+ b.btnAdd.isEnabled = true
+ b.btnAdd.text = "Add to Committee"
mess.toast(it)
- binding.etEmail.text?.clear()
- binding.spinnerAutoComplete.text?.clear()
+ b.etEmail.text?.clear()
+ b.spinnerAutoComplete.text?.clear()
}
}
private fun setAdapter() {
mess.getLists("${DESIGNATION}s") {
+ val b = _binding ?: return@getLists
+ val ctx = context ?: return@getLists
val adapter = ArrayAdapter(
- requireContext(),
+ ctx,
android.R.layout.simple_dropdown_item_1line,
it
)
- binding.spinnerAutoComplete.setAdapter(adapter)
+ b.spinnerAutoComplete.setAdapter(adapter)
}
}Also applies to: 94-100 🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| private fun setAdapter() { | ||
| mess.getLists("${DESIGNATION}s") { | ||
| val spinner = binding.spinnerAutoComplete | ||
| val spinnerItems = it | ||
| val adapter = | ||
| ArrayAdapter(requireContext(), android.R.layout.simple_spinner_item, spinnerItems) | ||
| adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) | ||
| spinner.setAdapter(adapter) | ||
| val adapter = ArrayAdapter( | ||
| requireContext(), | ||
| android.R.layout.simple_dropdown_item_1line, | ||
| it | ||
| ) | ||
| binding.spinnerAutoComplete.setAdapter(adapter) | ||
| } | ||
| } | ||
|
|
||
| override fun onDestroyView() { | ||
| super.onDestroyView() | ||
| _binding = null | ||
| } | ||
| } | ||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,8 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <shape xmlns:android="http://schemas.android.com/apk/res/android"> | ||
| <gradient | ||
| android:startColor="#FFFFFF" | ||
| android:endColor="#F5F5F5" | ||
| android:angle="270"/> | ||
| <corners android:radius="22dp"/> | ||
| </shape> |
This file contains hidden or 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,7 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <shape> | ||
| <gradient xmlns:android="http://schemas.android.com/apk/res/android" | ||
| android:startColor="#FF6F00" | ||
| android:endColor="#FFB74D" | ||
| android:angle="270"/> | ||
| </shape> |
This file contains hidden or 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,6 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <!-- res/drawable/bg_icon_soft.xml --> | ||
| <shape xmlns:android="http://schemas.android.com/apk/res/android"> | ||
| <solid android:color="#22FFFFFF"/> | ||
| <corners android:radius="50dp"/> | ||
| </shape> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clear field errors before validation branches to avoid stale messages.
If one field becomes valid and another fails, the old error can remain visible.
Small validation cleanup
private fun validateAndAdd() { val email = binding.etEmail.text.toString().trim() val designation = binding.spinnerAutoComplete.text.toString().trim() + binding.tilEmail.error = null + binding.tilspin.error = null + when { email.isEmpty() -> { binding.tilEmail.error = "Email required" } !android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches() -> { binding.tilEmail.error = "Invalid email" } designation.isEmpty() -> { binding.tilspin.error = "Select designation" } else -> { - binding.tilEmail.error = null - binding.tilspin.error = null add(email, designation) } } }🤖 Prompt for AI Agents