mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-03-13 01:30:05 +01:00
allow reordering favorites by drag and drop
This commit is contained in:
parent
145d781ecb
commit
5b75c5f26b
@ -35,6 +35,7 @@ import com.simplemobiletools.contacts.pro.dialogs.ImportContactsDialog
|
|||||||
import com.simplemobiletools.contacts.pro.extensions.config
|
import com.simplemobiletools.contacts.pro.extensions.config
|
||||||
import com.simplemobiletools.contacts.pro.extensions.getTempFile
|
import com.simplemobiletools.contacts.pro.extensions.getTempFile
|
||||||
import com.simplemobiletools.contacts.pro.extensions.handleGenericContactClick
|
import com.simplemobiletools.contacts.pro.extensions.handleGenericContactClick
|
||||||
|
import com.simplemobiletools.contacts.pro.fragments.FavoritesFragment
|
||||||
import com.simplemobiletools.contacts.pro.fragments.MyViewPagerFragment
|
import com.simplemobiletools.contacts.pro.fragments.MyViewPagerFragment
|
||||||
import com.simplemobiletools.contacts.pro.helpers.ALL_TABS_MASK
|
import com.simplemobiletools.contacts.pro.helpers.ALL_TABS_MASK
|
||||||
import com.simplemobiletools.contacts.pro.helpers.ContactsHelper
|
import com.simplemobiletools.contacts.pro.helpers.ContactsHelper
|
||||||
@ -185,8 +186,9 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
|
|
||||||
when (item.itemId) {
|
when (item.itemId) {
|
||||||
R.id.sort -> showSortingDialog()
|
R.id.sort -> showSortingDialog(showCustomSorting = getCurrentFragment() is FavoritesFragment)
|
||||||
R.id.filter -> showFilterDialog()
|
R.id.filter -> showFilterDialog()
|
||||||
R.id.dialpad -> launchDialpad()
|
R.id.dialpad -> launchDialpad()
|
||||||
R.id.import_contacts -> tryImportContacts()
|
R.id.import_contacts -> tryImportContacts()
|
||||||
@ -410,8 +412,8 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showSortingDialog() {
|
private fun showSortingDialog(showCustomSorting: Boolean) {
|
||||||
ChangeSortingDialog(this) {
|
ChangeSortingDialog(this, showCustomSorting) {
|
||||||
refreshContacts(TAB_CONTACTS or TAB_FAVORITES)
|
refreshContacts(TAB_CONTACTS or TAB_FAVORITES)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -450,7 +450,8 @@ class ContactsAdapter(
|
|||||||
override fun onChange(position: Int) = contactItems.getOrNull(position)?.getBubbleText() ?: ""
|
override fun onChange(position: Int) = contactItems.getOrNull(position)?.getBubbleText() ?: ""
|
||||||
|
|
||||||
override fun onRowMoved(fromPosition: Int, toPosition: Int) {
|
override fun onRowMoved(fromPosition: Int, toPosition: Int) {
|
||||||
activity.config.sorting = SORT_BY_CUSTOM
|
activity.config.isCustomOrderSelected = true
|
||||||
|
|
||||||
if (fromPosition < toPosition) {
|
if (fromPosition < toPosition) {
|
||||||
for (i in fromPosition until toPosition) {
|
for (i in fromPosition until toPosition) {
|
||||||
Collections.swap(contactItems, i, i + 1)
|
Collections.swap(contactItems, i, i + 1)
|
||||||
@ -460,6 +461,7 @@ class ContactsAdapter(
|
|||||||
Collections.swap(contactItems, i, i - 1)
|
Collections.swap(contactItems, i, i - 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
notifyItemMoved(fromPosition, toPosition)
|
notifyItemMoved(fromPosition, toPosition)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ import com.simplemobiletools.contacts.pro.R
|
|||||||
import com.simplemobiletools.contacts.pro.extensions.config
|
import com.simplemobiletools.contacts.pro.extensions.config
|
||||||
import kotlinx.android.synthetic.main.dialog_change_sorting.view.*
|
import kotlinx.android.synthetic.main.dialog_change_sorting.view.*
|
||||||
|
|
||||||
class ChangeSortingDialog(val activity: BaseSimpleActivity, private val callback: () -> Unit) {
|
class ChangeSortingDialog(val activity: BaseSimpleActivity, private val showCustomSorting: Boolean = false, private val callback: () -> Unit) {
|
||||||
private var currSorting = 0
|
private var currSorting = 0
|
||||||
private var config = activity.config
|
private var config = activity.config
|
||||||
private var view = activity.layoutInflater.inflate(R.layout.dialog_change_sorting, null)
|
private var view = activity.layoutInflater.inflate(R.layout.dialog_change_sorting, null)
|
||||||
@ -22,7 +22,16 @@ class ChangeSortingDialog(val activity: BaseSimpleActivity, private val callback
|
|||||||
activity.setupDialogStuff(view, this, R.string.sort_by)
|
activity.setupDialogStuff(view, this, R.string.sort_by)
|
||||||
}
|
}
|
||||||
|
|
||||||
currSorting = config.sorting
|
currSorting = if (showCustomSorting) {
|
||||||
|
if (config.isCustomOrderSelected) {
|
||||||
|
SORT_BY_CUSTOM
|
||||||
|
} else {
|
||||||
|
config.sorting
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
config.sorting
|
||||||
|
}
|
||||||
|
|
||||||
setupSortRadio()
|
setupSortRadio()
|
||||||
setupOrderRadio()
|
setupOrderRadio()
|
||||||
}
|
}
|
||||||
@ -44,6 +53,11 @@ class ChangeSortingDialog(val activity: BaseSimpleActivity, private val callback
|
|||||||
else -> sortingRadio.sorting_dialog_radio_date_created
|
else -> sortingRadio.sorting_dialog_radio_date_created
|
||||||
}
|
}
|
||||||
sortBtn.isChecked = true
|
sortBtn.isChecked = true
|
||||||
|
|
||||||
|
if (showCustomSorting) {
|
||||||
|
sortingRadio.sorting_dialog_radio_custom.isChecked = config.isCustomOrderSelected
|
||||||
|
}
|
||||||
|
view.sorting_dialog_radio_custom.beGoneIf(!showCustomSorting)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupOrderRadio() {
|
private fun setupOrderRadio() {
|
||||||
@ -71,7 +85,17 @@ class ChangeSortingDialog(val activity: BaseSimpleActivity, private val callback
|
|||||||
sorting = sorting or SORT_DESCENDING
|
sorting = sorting or SORT_DESCENDING
|
||||||
}
|
}
|
||||||
|
|
||||||
config.sorting = sorting
|
if (showCustomSorting) {
|
||||||
|
if (sorting == SORT_BY_CUSTOM) {
|
||||||
|
config.isCustomOrderSelected = true
|
||||||
|
} else {
|
||||||
|
config.isCustomOrderSelected = false
|
||||||
|
config.sorting = sorting
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
config.sorting = sorting
|
||||||
|
}
|
||||||
|
|
||||||
callback()
|
callback()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -128,7 +128,7 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
|||||||
this is FavoritesFragment -> {
|
this is FavoritesFragment -> {
|
||||||
val favorites = contacts.filter { it.starred == 1 } as ArrayList<Contact>
|
val favorites = contacts.filter { it.starred == 1 } as ArrayList<Contact>
|
||||||
|
|
||||||
if (activity!!.config.sorting == SORT_BY_CUSTOM) {
|
if (activity!!.config.isCustomOrderSelected) {
|
||||||
sortByCustomOrder(favorites)
|
sortByCustomOrder(favorites)
|
||||||
} else {
|
} else {
|
||||||
favorites
|
favorites
|
||||||
|
@ -70,4 +70,8 @@ class Config(context: Context) : BaseConfig(context) {
|
|||||||
var favoritesContactsOrder: String
|
var favoritesContactsOrder: String
|
||||||
get() = prefs.getString(FAVORITES_CONTACTS_ORDER, "")!!
|
get() = prefs.getString(FAVORITES_CONTACTS_ORDER, "")!!
|
||||||
set(order) = prefs.edit().putString(FAVORITES_CONTACTS_ORDER, order).apply()
|
set(order) = prefs.edit().putString(FAVORITES_CONTACTS_ORDER, order).apply()
|
||||||
|
|
||||||
|
var isCustomOrderSelected: Boolean
|
||||||
|
get() = prefs.getBoolean(FAVORITES_CUSTOM_ORDER_SELECTED, false)
|
||||||
|
set(selected) = prefs.edit().putBoolean(FAVORITES_CUSTOM_ORDER_SELECTED, selected).apply()
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ const val WAS_LOCAL_ACCOUNT_INITIALIZED = "was_local_account_initialized"
|
|||||||
const val SHOW_PRIVATE_CONTACTS = "show_private_contacts"
|
const val SHOW_PRIVATE_CONTACTS = "show_private_contacts"
|
||||||
const val MERGE_DUPLICATE_CONTACTS = "merge_duplicate_contacts"
|
const val MERGE_DUPLICATE_CONTACTS = "merge_duplicate_contacts"
|
||||||
const val FAVORITES_CONTACTS_ORDER = "favorites_contacts_order"
|
const val FAVORITES_CONTACTS_ORDER = "favorites_contacts_order"
|
||||||
|
const val FAVORITES_CUSTOM_ORDER_SELECTED = "favorites_custom_order_selected"
|
||||||
|
|
||||||
const val SMT_PRIVATE = "smt_private" // used at the contact source of local contacts hidden from other apps
|
const val SMT_PRIVATE = "smt_private" // used at the contact source of local contacts hidden from other apps
|
||||||
const val GROUP = "group"
|
const val GROUP = "group"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user