mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-01-24 04:42:44 +01:00
store selected favorites
This commit is contained in:
parent
c8a3bfb9b5
commit
0e3f500bb9
@ -20,7 +20,8 @@ import com.simplemobiletools.contacts.models.Contact
|
|||||||
import kotlinx.android.synthetic.main.item_add_favorite_with_number.view.*
|
import kotlinx.android.synthetic.main.item_add_favorite_with_number.view.*
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class AddFavoritesAdapter(val activity: SimpleActivity, val contacts: List<Contact>) : RecyclerView.Adapter<AddFavoritesAdapter.ViewHolder>() {
|
class AddFavoritesAdapter(val activity: SimpleActivity, val contacts: List<Contact>, val selectedContacts: Set<String>)
|
||||||
|
: RecyclerView.Adapter<AddFavoritesAdapter.ViewHolder>() {
|
||||||
private val itemViews = SparseArray<View>()
|
private val itemViews = SparseArray<View>()
|
||||||
private val selectedPositions = HashSet<Int>()
|
private val selectedPositions = HashSet<Int>()
|
||||||
private val config = activity.config
|
private val config = activity.config
|
||||||
@ -29,6 +30,14 @@ class AddFavoritesAdapter(val activity: SimpleActivity, val contacts: List<Conta
|
|||||||
private val startNameWithSurname = config.startNameWithSurname
|
private val startNameWithSurname = config.startNameWithSurname
|
||||||
private val itemLayout = if (config.showPhoneNumbers) R.layout.item_add_favorite_with_number else R.layout.item_add_favorite_without_number
|
private val itemLayout = if (config.showPhoneNumbers) R.layout.item_add_favorite_with_number else R.layout.item_add_favorite_without_number
|
||||||
|
|
||||||
|
init {
|
||||||
|
contacts.forEachIndexed { index, contact ->
|
||||||
|
if (selectedContacts.contains(contact.id.toString())) {
|
||||||
|
selectedPositions.add(index)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun toggleItemSelection(select: Boolean, pos: Int) {
|
private fun toggleItemSelection(select: Boolean, pos: Int) {
|
||||||
if (select) {
|
if (select) {
|
||||||
if (itemViews[pos] != null) {
|
if (itemViews[pos] != null) {
|
||||||
|
@ -18,7 +18,7 @@ class AddFavoritesDialog(val activity: SimpleActivity, val callback: () -> Unit)
|
|||||||
ContactsHelper(activity).getContacts {
|
ContactsHelper(activity).getContacts {
|
||||||
Contact.sorting = activity.config.sorting
|
Contact.sorting = activity.config.sorting
|
||||||
it.sort()
|
it.sort()
|
||||||
view.add_favorites_list.adapter = AddFavoritesAdapter(activity, it)
|
view.add_favorites_list.adapter = AddFavoritesAdapter(activity, it, activity.config.favorites)
|
||||||
|
|
||||||
activity.runOnUiThread {
|
activity.runOnUiThread {
|
||||||
dialog = AlertDialog.Builder(activity)
|
dialog = AlertDialog.Builder(activity)
|
||||||
@ -33,6 +33,10 @@ class AddFavoritesDialog(val activity: SimpleActivity, val callback: () -> Unit)
|
|||||||
|
|
||||||
private fun dialogConfirmed() {
|
private fun dialogConfirmed() {
|
||||||
val selectedItems = (view.add_favorites_list.adapter as AddFavoritesAdapter).getSelectedItemsSet()
|
val selectedItems = (view.add_favorites_list.adapter as AddFavoritesAdapter).getSelectedItemsSet()
|
||||||
|
if (activity.config.favorites != selectedItems) {
|
||||||
|
activity.config.favorites = selectedItems
|
||||||
|
callback()
|
||||||
|
}
|
||||||
dialog?.dismiss()
|
dialog?.dismiss()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,8 @@ class FavoritesFragment(context: Context, attributeSet: AttributeSet) : MyViewPa
|
|||||||
addNewFavorites()
|
addNewFavorites()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
initFavorites()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun textColorChanged(color: Int) {
|
override fun textColorChanged(color: Int) {
|
||||||
@ -29,9 +31,13 @@ class FavoritesFragment(context: Context, attributeSet: AttributeSet) : MyViewPa
|
|||||||
override fun onActivityResume() {
|
override fun onActivityResume() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun initFavorites() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private fun addNewFavorites() {
|
private fun addNewFavorites() {
|
||||||
AddFavoritesDialog(activity!!) {
|
AddFavoritesDialog(activity!!) {
|
||||||
|
initFavorites()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import android.content.Context
|
|||||||
import com.simplemobiletools.commons.helpers.BaseConfig
|
import com.simplemobiletools.commons.helpers.BaseConfig
|
||||||
import com.simplemobiletools.commons.helpers.SORTING
|
import com.simplemobiletools.commons.helpers.SORTING
|
||||||
import com.simplemobiletools.commons.helpers.SORT_BY_FIRST_NAME
|
import com.simplemobiletools.commons.helpers.SORT_BY_FIRST_NAME
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
class Config(context: Context) : BaseConfig(context) {
|
class Config(context: Context) : BaseConfig(context) {
|
||||||
companion object {
|
companion object {
|
||||||
@ -39,4 +40,8 @@ class Config(context: Context) : BaseConfig(context) {
|
|||||||
var lastUsedViewPagerPage: Int
|
var lastUsedViewPagerPage: Int
|
||||||
get() = prefs.getInt(LAST_USED_VIEW_PAGER_PAGE, 0)
|
get() = prefs.getInt(LAST_USED_VIEW_PAGER_PAGE, 0)
|
||||||
set(lastUsedViewPagerPage) = prefs.edit().putInt(LAST_USED_VIEW_PAGER_PAGE, lastUsedViewPagerPage).apply()
|
set(lastUsedViewPagerPage) = prefs.edit().putInt(LAST_USED_VIEW_PAGER_PAGE, lastUsedViewPagerPage).apply()
|
||||||
|
|
||||||
|
var favorites: Set<String>
|
||||||
|
get() = prefs.getStringSet(FAVORITES, HashSet<String>())
|
||||||
|
set(favorites) = prefs.edit().remove(FAVORITES).putStringSet(FAVORITES, favorites).apply()
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ val DISPLAY_CONTACT_SOURCES = "display_contact_sources"
|
|||||||
val START_NAME_WITH_SURNAME = "start_name_with_surname"
|
val START_NAME_WITH_SURNAME = "start_name_with_surname"
|
||||||
val LAST_USED_CONTACT_SOURCE = "last_used_contact_source"
|
val LAST_USED_CONTACT_SOURCE = "last_used_contact_source"
|
||||||
val LAST_USED_VIEW_PAGER_PAGE = "last_used_view_pager_page"
|
val LAST_USED_VIEW_PAGER_PAGE = "last_used_view_pager_page"
|
||||||
|
val FAVORITES = "favorites"
|
||||||
|
|
||||||
val CONTACT_ID = "contact_id"
|
val CONTACT_ID = "contact_id"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user