diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/adapters/AddFavoritesAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/adapters/AddFavoritesAdapter.kt index 244c0a96..6b40c0dd 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/adapters/AddFavoritesAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/adapters/AddFavoritesAdapter.kt @@ -20,7 +20,8 @@ import com.simplemobiletools.contacts.models.Contact import kotlinx.android.synthetic.main.item_add_favorite_with_number.view.* import java.util.* -class AddFavoritesAdapter(val activity: SimpleActivity, val contacts: List) : RecyclerView.Adapter() { +class AddFavoritesAdapter(val activity: SimpleActivity, val contacts: List, val selectedContacts: Set) + : RecyclerView.Adapter() { private val itemViews = SparseArray() private val selectedPositions = HashSet() private val config = activity.config @@ -29,6 +30,14 @@ class AddFavoritesAdapter(val activity: SimpleActivity, val contacts: List + if (selectedContacts.contains(contact.id.toString())) { + selectedPositions.add(index) + } + } + } + private fun toggleItemSelection(select: Boolean, pos: Int) { if (select) { if (itemViews[pos] != null) { diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/dialogs/AddFavoritesDialog.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/dialogs/AddFavoritesDialog.kt index 62b25097..a9c7dd61 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/dialogs/AddFavoritesDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/dialogs/AddFavoritesDialog.kt @@ -18,7 +18,7 @@ class AddFavoritesDialog(val activity: SimpleActivity, val callback: () -> Unit) ContactsHelper(activity).getContacts { Contact.sorting = activity.config.sorting it.sort() - view.add_favorites_list.adapter = AddFavoritesAdapter(activity, it) + view.add_favorites_list.adapter = AddFavoritesAdapter(activity, it, activity.config.favorites) activity.runOnUiThread { dialog = AlertDialog.Builder(activity) @@ -33,6 +33,10 @@ class AddFavoritesDialog(val activity: SimpleActivity, val callback: () -> Unit) private fun dialogConfirmed() { val selectedItems = (view.add_favorites_list.adapter as AddFavoritesAdapter).getSelectedItemsSet() + if (activity.config.favorites != selectedItems) { + activity.config.favorites = selectedItems + callback() + } dialog?.dismiss() } } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/fragments/FavoritesFragment.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/fragments/FavoritesFragment.kt index 30c0652f..7d374a43 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/fragments/FavoritesFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/fragments/FavoritesFragment.kt @@ -15,6 +15,8 @@ class FavoritesFragment(context: Context, attributeSet: AttributeSet) : MyViewPa addNewFavorites() } } + + initFavorites() } override fun textColorChanged(color: Int) { @@ -29,9 +31,13 @@ class FavoritesFragment(context: Context, attributeSet: AttributeSet) : MyViewPa override fun onActivityResume() { } + private fun initFavorites() { + + } + private fun addNewFavorites() { AddFavoritesDialog(activity!!) { - + initFavorites() } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/Config.kt index 25628b1c..13e8df06 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/Config.kt @@ -4,6 +4,7 @@ import android.content.Context import com.simplemobiletools.commons.helpers.BaseConfig import com.simplemobiletools.commons.helpers.SORTING import com.simplemobiletools.commons.helpers.SORT_BY_FIRST_NAME +import java.util.* class Config(context: Context) : BaseConfig(context) { companion object { @@ -39,4 +40,8 @@ class Config(context: Context) : BaseConfig(context) { var lastUsedViewPagerPage: Int get() = prefs.getInt(LAST_USED_VIEW_PAGER_PAGE, 0) set(lastUsedViewPagerPage) = prefs.edit().putInt(LAST_USED_VIEW_PAGER_PAGE, lastUsedViewPagerPage).apply() + + var favorites: Set + get() = prefs.getStringSet(FAVORITES, HashSet()) + set(favorites) = prefs.edit().remove(FAVORITES).putStringSet(FAVORITES, favorites).apply() } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/Constants.kt index eff937cf..9d54f9fb 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/Constants.kt @@ -7,6 +7,7 @@ val DISPLAY_CONTACT_SOURCES = "display_contact_sources" val START_NAME_WITH_SURNAME = "start_name_with_surname" val LAST_USED_CONTACT_SOURCE = "last_used_contact_source" val LAST_USED_VIEW_PAGER_PAGE = "last_used_view_pager_page" +val FAVORITES = "favorites" val CONTACT_ID = "contact_id"