-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8458f66
commit c755920
Showing
21 changed files
with
335 additions
and
68 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 was deleted.
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
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
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
77 changes: 77 additions & 0 deletions
77
bitapp/attendance/src/main/java/com/atech/attendance/sort/SortMenuDialog.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,77 @@ | ||
package com.atech.attendance.sort | ||
|
||
import android.app.Dialog | ||
import android.os.Bundle | ||
import android.util.Log | ||
import androidx.fragment.app.DialogFragment | ||
import androidx.navigation.fragment.navArgs | ||
import com.atech.attendance.databinding.MenuSortBinding | ||
import com.atech.core.datastore.DataStoreCases | ||
import com.atech.core.room.attendance.Sort | ||
import com.atech.core.room.attendance.SortBy | ||
import com.atech.core.room.attendance.SortOrder | ||
import com.atech.core.utils.capitalizeWords | ||
import com.atech.theme.R | ||
import com.atech.theme.launchWhenStarted | ||
import com.google.android.material.dialog.MaterialAlertDialogBuilder | ||
import com.google.android.material.textfield.MaterialAutoCompleteTextView | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import javax.inject.Inject | ||
|
||
@AndroidEntryPoint | ||
class SortMenuDialog : DialogFragment() { | ||
|
||
private lateinit var binding: MenuSortBinding | ||
|
||
@Inject | ||
lateinit var dataStoreCases: DataStoreCases | ||
|
||
private val args: SortMenuDialogArgs by navArgs() | ||
|
||
|
||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { | ||
binding = MenuSortBinding.inflate(layoutInflater) | ||
binding.apply { | ||
setView() | ||
setDropDown() | ||
} | ||
return MaterialAlertDialogBuilder(requireContext()) | ||
.setView(binding.root) | ||
.setTitle(getString(R.string.sort)) | ||
.setPositiveButton("Done") { _, _ -> | ||
saveData() | ||
}.setNegativeButton("Cancel", null) | ||
.create() | ||
} | ||
|
||
private fun saveData() = launchWhenStarted { | ||
val sortBy = SortBy.valueOf( | ||
(binding.textInputLayoutSortBy.editText as? MaterialAutoCompleteTextView)?.text.toString() | ||
.uppercase() | ||
) | ||
val sortOrder = SortOrder.valueOf( | ||
(binding.textInputLayoutSortOrder.editText as? MaterialAutoCompleteTextView)?.text.toString() | ||
.uppercase() | ||
) | ||
val sort = Sort(sortBy, sortOrder) | ||
Log.d("AAA", "saveData: $sort") | ||
dataStoreCases.updateAttendanceSort(sort) | ||
} | ||
|
||
private fun MenuSortBinding.setDropDown() = this.root.apply { | ||
val sortBy = SortBy.values().map { it.name.capitalizeWords() }.toTypedArray() | ||
val sortOrder = SortOrder.values().map { it.name.capitalizeWords() }.toTypedArray() | ||
|
||
(textInputLayoutSortBy.editText as? MaterialAutoCompleteTextView)?.setSimpleItems(sortBy) | ||
(textInputLayoutSortOrder.editText as? MaterialAutoCompleteTextView)?.setSimpleItems( | ||
sortOrder | ||
) | ||
} | ||
|
||
private fun MenuSortBinding.setView() { | ||
val it = args.sort | ||
textInputLayoutSortBy.editText?.setText(it.sortBy.name.capitalizeWords()) | ||
textInputLayoutSortOrder.editText?.setText(it.sortOrder.name.capitalizeWords()) | ||
} | ||
|
||
} |
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,36 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="vertical" | ||
android:padding="@dimen/grid_1" | ||
tools:theme="@style/Base.Theme.BITApp"> | ||
|
||
<com.google.android.material.textfield.TextInputLayout | ||
android:id="@+id/text_input_layout_sort_by" | ||
style="@style/Widget.Material3.TextInputLayout.OutlinedBox.ExposedDropdownMenu" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<AutoCompleteTextView | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:hint="@string/sort_by" | ||
android:inputType="none" /> | ||
</com.google.android.material.textfield.TextInputLayout> | ||
|
||
<com.google.android.material.textfield.TextInputLayout | ||
android:id="@+id/text_input_layout_sort_order" | ||
style="@style/Widget.Material3.TextInputLayout.OutlinedBox.ExposedDropdownMenu" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:layout_marginTop="@dimen/grid_1"> | ||
|
||
<AutoCompleteTextView | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:hint="@string/sort_order" | ||
android:inputType="none" /> | ||
</com.google.android.material.textfield.TextInputLayout> | ||
</LinearLayout> |
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
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
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
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
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
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
Oops, something went wrong.