add a sorting dialog
This commit is contained in:
parent
8678a7d109
commit
cb6c3fedec
|
@ -14,6 +14,7 @@ import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener
|
||||||
import com.simplemobiletools.contacts.BuildConfig
|
import com.simplemobiletools.contacts.BuildConfig
|
||||||
import com.simplemobiletools.contacts.R
|
import com.simplemobiletools.contacts.R
|
||||||
import com.simplemobiletools.contacts.adapters.ContactsAdapter
|
import com.simplemobiletools.contacts.adapters.ContactsAdapter
|
||||||
|
import com.simplemobiletools.contacts.dialogs.ChangeSortingDialog
|
||||||
import com.simplemobiletools.contacts.extensions.config
|
import com.simplemobiletools.contacts.extensions.config
|
||||||
import com.simplemobiletools.contacts.helpers.ContactsHelper
|
import com.simplemobiletools.contacts.helpers.ContactsHelper
|
||||||
import com.simplemobiletools.contacts.models.Contact
|
import com.simplemobiletools.contacts.models.Contact
|
||||||
|
@ -36,6 +37,8 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
storeStateVariables()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
|
@ -58,6 +61,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
when (item.itemId) {
|
when (item.itemId) {
|
||||||
|
R.id.sort -> showSortingDialog()
|
||||||
R.id.settings -> startActivity(Intent(applicationContext, SettingsActivity::class.java))
|
R.id.settings -> startActivity(Intent(applicationContext, SettingsActivity::class.java))
|
||||||
R.id.about -> launchAbout()
|
R.id.about -> launchAbout()
|
||||||
else -> return super.onOptionsItemSelected(item)
|
else -> return super.onOptionsItemSelected(item)
|
||||||
|
@ -65,14 +69,20 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun storeStateVariables() {
|
private fun showSortingDialog() {
|
||||||
storedUseEnglish = config.useEnglish
|
ChangeSortingDialog(this) {
|
||||||
|
initContacts()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun launchAbout() {
|
private fun launchAbout() {
|
||||||
startAboutActivity(R.string.app_name, LICENSE_KOTLIN or LICENSE_MULTISELECT, BuildConfig.VERSION_NAME)
|
startAboutActivity(R.string.app_name, LICENSE_KOTLIN or LICENSE_MULTISELECT, BuildConfig.VERSION_NAME)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun storeStateVariables() {
|
||||||
|
storedUseEnglish = config.useEnglish
|
||||||
|
}
|
||||||
|
|
||||||
private fun initContacts() {
|
private fun initContacts() {
|
||||||
ContactsHelper(this).getContacts {
|
ContactsHelper(this).getContacts {
|
||||||
Contact.sorting = config.sorting
|
Contact.sorting = config.sorting
|
||||||
|
@ -113,6 +123,6 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun refreshItems() {
|
override fun refreshItems() {
|
||||||
|
initContacts()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,64 @@
|
||||||
|
package com.simplemobiletools.contacts.dialogs
|
||||||
|
|
||||||
|
import android.support.v7.app.AlertDialog
|
||||||
|
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||||
|
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||||
|
import com.simplemobiletools.commons.helpers.SORT_BY_NAME
|
||||||
|
import com.simplemobiletools.commons.helpers.SORT_BY_NUMBER
|
||||||
|
import com.simplemobiletools.commons.helpers.SORT_DESCENDING
|
||||||
|
import com.simplemobiletools.contacts.R
|
||||||
|
import com.simplemobiletools.contacts.extensions.config
|
||||||
|
import kotlinx.android.synthetic.main.dialog_change_sorting.view.*
|
||||||
|
|
||||||
|
class ChangeSortingDialog(val activity: BaseSimpleActivity, val callback: () -> Unit) {
|
||||||
|
private var currSorting = 0
|
||||||
|
private var config = activity.config
|
||||||
|
private var view = activity.layoutInflater.inflate(R.layout.dialog_change_sorting, null)
|
||||||
|
|
||||||
|
init {
|
||||||
|
AlertDialog.Builder(activity)
|
||||||
|
.setPositiveButton(R.string.ok, { dialog, which -> dialogConfirmed() })
|
||||||
|
.setNegativeButton(R.string.cancel, null)
|
||||||
|
.create().apply {
|
||||||
|
activity.setupDialogStuff(view, this, R.string.sort_by)
|
||||||
|
}
|
||||||
|
|
||||||
|
currSorting = config.sorting
|
||||||
|
setupSortRadio()
|
||||||
|
setupOrderRadio()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setupSortRadio() {
|
||||||
|
val sortingRadio = view.sorting_dialog_radio_sorting
|
||||||
|
val sortBtn = when {
|
||||||
|
currSorting and SORT_BY_NUMBER != 0 -> sortingRadio.sorting_dialog_radio_number
|
||||||
|
else -> sortingRadio.sorting_dialog_radio_name
|
||||||
|
}
|
||||||
|
sortBtn.isChecked = true
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setupOrderRadio() {
|
||||||
|
val orderRadio = view.sorting_dialog_radio_order
|
||||||
|
var orderBtn = orderRadio.sorting_dialog_radio_ascending
|
||||||
|
|
||||||
|
if (currSorting and SORT_DESCENDING != 0) {
|
||||||
|
orderBtn = orderRadio.sorting_dialog_radio_descending
|
||||||
|
}
|
||||||
|
orderBtn.isChecked = true
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun dialogConfirmed() {
|
||||||
|
val sortingRadio = view.sorting_dialog_radio_sorting
|
||||||
|
var sorting = when (sortingRadio.checkedRadioButtonId) {
|
||||||
|
R.id.sorting_dialog_radio_number -> SORT_BY_NUMBER
|
||||||
|
else -> SORT_BY_NAME
|
||||||
|
}
|
||||||
|
|
||||||
|
if (view.sorting_dialog_radio_order.checkedRadioButtonId == R.id.sorting_dialog_radio_descending) {
|
||||||
|
sorting = sorting or SORT_DESCENDING
|
||||||
|
}
|
||||||
|
|
||||||
|
config.sorting = sorting
|
||||||
|
callback()
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,68 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<ScrollView
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/sorting_dialog_scrollview"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/sorting_dialog_holder"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:paddingLeft="@dimen/activity_margin"
|
||||||
|
android:paddingRight="@dimen/activity_margin"
|
||||||
|
android:paddingTop="@dimen/activity_margin">
|
||||||
|
|
||||||
|
<RadioGroup
|
||||||
|
android:id="@+id/sorting_dialog_radio_sorting"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="@dimen/medium_margin">
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||||
|
android:id="@+id/sorting_dialog_radio_name"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingBottom="@dimen/medium_margin"
|
||||||
|
android:paddingTop="@dimen/medium_margin"
|
||||||
|
android:text="@string/name"/>
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||||
|
android:id="@+id/sorting_dialog_radio_number"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingBottom="@dimen/medium_margin"
|
||||||
|
android:paddingTop="@dimen/medium_margin"
|
||||||
|
android:text="@string/number"/>
|
||||||
|
|
||||||
|
</RadioGroup>
|
||||||
|
|
||||||
|
<include
|
||||||
|
layout="@layout/divider"/>
|
||||||
|
|
||||||
|
<RadioGroup
|
||||||
|
android:id="@+id/sorting_dialog_radio_order"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="@dimen/medium_margin"
|
||||||
|
android:paddingBottom="@dimen/medium_margin">
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||||
|
android:id="@+id/sorting_dialog_radio_ascending"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingBottom="@dimen/medium_margin"
|
||||||
|
android:paddingTop="@dimen/medium_margin"
|
||||||
|
android:text="@string/ascending"/>
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||||
|
android:id="@+id/sorting_dialog_radio_descending"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingBottom="@dimen/medium_margin"
|
||||||
|
android:paddingTop="@dimen/medium_margin"
|
||||||
|
android:text="@string/descending"/>
|
||||||
|
</RadioGroup>
|
||||||
|
</LinearLayout>
|
||||||
|
</ScrollView>
|
|
@ -1,6 +1,11 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
<item
|
||||||
|
android:id="@+id/sort"
|
||||||
|
android:icon="@drawable/ic_sort"
|
||||||
|
android:title="@string/sort_by"
|
||||||
|
app:showAsAction="ifRoom"/>
|
||||||
<item
|
<item
|
||||||
android:id="@+id/settings"
|
android:id="@+id/settings"
|
||||||
android:title="@string/settings"
|
android:title="@string/settings"
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">Jednoduché kontakty</string>
|
<string name="app_name">Jednoduché kontakty</string>
|
||||||
<string name="app_launcher_name">Kontakty</string>
|
<string name="app_launcher_name">Kontakty</string>
|
||||||
|
<string name="number">Číslo</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">Simple Contacts</string>
|
<string name="app_name">Simple Contacts</string>
|
||||||
<string name="app_launcher_name">Contacts</string>
|
<string name="app_launcher_name">Contacts</string>
|
||||||
|
<string name="number">Number</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in New Issue