allow adding contacts to favorites by long pressing and Add
This commit is contained in:
parent
0a72b5040a
commit
d21b3e7c4d
14 changed files with 58 additions and 21 deletions
|
@ -3,6 +3,7 @@ package com.simplemobiletools.contacts.activities
|
|||
import android.content.Intent
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
|
@ -15,11 +16,12 @@ import com.simplemobiletools.contacts.dialogs.FilterContactSourcesDialog
|
|||
import com.simplemobiletools.contacts.extensions.config
|
||||
import com.simplemobiletools.contacts.extensions.onPageChanged
|
||||
import com.simplemobiletools.contacts.extensions.onTabSelectionChanged
|
||||
import com.simplemobiletools.interfaces.RefreshContactsListener
|
||||
import kotlinx.android.synthetic.main.activity_main.*
|
||||
import kotlinx.android.synthetic.main.fragment_contacts.*
|
||||
import kotlinx.android.synthetic.main.fragment_favorites.*
|
||||
|
||||
class MainActivity : SimpleActivity() {
|
||||
class MainActivity : SimpleActivity(), RefreshContactsListener {
|
||||
private var isFirstResume = true
|
||||
|
||||
private var storedUseEnglish = false
|
||||
|
@ -183,4 +185,11 @@ class MainActivity : SimpleActivity() {
|
|||
private fun launchAbout() {
|
||||
startAboutActivity(R.string.app_name, LICENSE_KOTLIN or LICENSE_MULTISELECT or LICENSE_JODA or LICENSE_GLIDE, BuildConfig.VERSION_NAME)
|
||||
}
|
||||
|
||||
override fun refreshItems() {
|
||||
}
|
||||
|
||||
override fun refreshFavorites() {
|
||||
favorites_fragment?.initContacts()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@ import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
|
|||
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
||||
import com.simplemobiletools.commons.extensions.getColoredDrawableWithColor
|
||||
import com.simplemobiletools.commons.extensions.isActivityDestroyed
|
||||
import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener
|
||||
import com.simplemobiletools.commons.views.MyRecyclerView
|
||||
import com.simplemobiletools.contacts.R
|
||||
import com.simplemobiletools.contacts.activities.SimpleActivity
|
||||
|
@ -21,9 +20,10 @@ import com.simplemobiletools.contacts.extensions.config
|
|||
import com.simplemobiletools.contacts.extensions.openContact
|
||||
import com.simplemobiletools.contacts.helpers.ContactsHelper
|
||||
import com.simplemobiletools.contacts.models.Contact
|
||||
import com.simplemobiletools.interfaces.RefreshContactsListener
|
||||
import kotlinx.android.synthetic.main.item_contact_with_number.view.*
|
||||
|
||||
class ContactsAdapter(activity: SimpleActivity, var contactItems: MutableList<Contact>, val listener: RefreshRecyclerViewListener?,
|
||||
class ContactsAdapter(activity: SimpleActivity, var contactItems: MutableList<Contact>, val listener: RefreshContactsListener?,
|
||||
val isFavoritesFragment: Boolean, recyclerView: MyRecyclerView, itemClick: (Any) -> Unit) :
|
||||
MyRecyclerViewAdapter(activity, recyclerView, itemClick) {
|
||||
|
||||
|
@ -45,6 +45,7 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: MutableList<Co
|
|||
findItem(R.id.cab_edit).isVisible = activity.config.callContact && isOneItemSelected()
|
||||
findItem(R.id.cab_remove).isVisible = isFavoritesFragment
|
||||
findItem(R.id.cab_select_all).isVisible = isFavoritesFragment
|
||||
findItem(R.id.cab_add_to_favorites).isVisible = !isFavoritesFragment
|
||||
findItem(R.id.cab_delete).isVisible = !isFavoritesFragment
|
||||
}
|
||||
}
|
||||
|
@ -60,6 +61,7 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: MutableList<Co
|
|||
R.id.cab_edit -> editContact()
|
||||
R.id.cab_select_all -> selectAll()
|
||||
R.id.cab_delete -> askConfirmDelete()
|
||||
R.id.cab_add_to_favorites -> addToFavorites()
|
||||
R.id.cab_remove -> removeFavorites()
|
||||
}
|
||||
}
|
||||
|
@ -107,9 +109,12 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: MutableList<Co
|
|||
return
|
||||
}
|
||||
|
||||
val contacts = ArrayList<Contact>()
|
||||
selectedPositions.forEach { contacts.add(contactItems[it]) }
|
||||
ContactsHelper(activity).deleteContacts(contacts)
|
||||
val contactsToRemove = ArrayList<Contact>()
|
||||
selectedPositions.sortedDescending().forEach {
|
||||
contactsToRemove.add(contactItems[it])
|
||||
}
|
||||
contactItems.removeAll(contactsToRemove)
|
||||
ContactsHelper(activity).deleteContacts(contactsToRemove)
|
||||
removeSelectedItems()
|
||||
}
|
||||
|
||||
|
@ -117,6 +122,19 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: MutableList<Co
|
|||
|
||||
}
|
||||
|
||||
private fun addToFavorites() {
|
||||
if (selectedPositions.isEmpty()) {
|
||||
return
|
||||
}
|
||||
|
||||
val newFavorites = HashSet<String>()
|
||||
selectedPositions.forEach { newFavorites.add(contactItems[it].id.toString()) }
|
||||
newFavorites.addAll(activity.config.favorites)
|
||||
activity.config.favorites = newFavorites
|
||||
listener?.refreshFavorites()
|
||||
finishActMode()
|
||||
}
|
||||
|
||||
override fun onViewRecycled(holder: ViewHolder?) {
|
||||
super.onViewRecycled(holder)
|
||||
if (!activity.isActivityDestroyed()) {
|
||||
|
|
|
@ -14,16 +14,17 @@ class AddFavoritesDialog(val activity: SimpleActivity, val callback: () -> Unit)
|
|||
private var dialog: AlertDialog? = null
|
||||
private var view = activity.layoutInflater.inflate(R.layout.dialog_add_favorites, null)
|
||||
private val config = activity.config
|
||||
private var allContacts = ArrayList<Contact>()
|
||||
|
||||
init {
|
||||
ContactsHelper(activity).getContacts {
|
||||
var contacts = it
|
||||
allContacts = it
|
||||
Contact.sorting = config.sorting
|
||||
contacts.sort()
|
||||
allContacts.sort()
|
||||
|
||||
val contactSources = config.displayContactSources
|
||||
contacts = contacts.filter { contactSources.contains(it.source) } as ArrayList<Contact>
|
||||
view.add_favorites_list.adapter = AddFavoritesAdapter(activity, contacts, config.favorites)
|
||||
allContacts = allContacts.filter { contactSources.contains(it.source) } as ArrayList<Contact>
|
||||
view.add_favorites_list.adapter = AddFavoritesAdapter(activity, allContacts, config.favorites)
|
||||
|
||||
activity.runOnUiThread {
|
||||
dialog = AlertDialog.Builder(activity)
|
||||
|
|
|
@ -15,8 +15,4 @@ class ContactsFragment(context: Context, attributeSet: AttributeSet) : MyViewPag
|
|||
override fun placeholderClicked() {
|
||||
activity!!.showFilterDialog()
|
||||
}
|
||||
|
||||
override fun refreshItems() {
|
||||
initContacts()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,10 +14,6 @@ class FavoritesFragment(context: Context, attributeSet: AttributeSet) : MyViewPa
|
|||
showAddFavoritesDialog()
|
||||
}
|
||||
|
||||
override fun refreshItems() {
|
||||
initContacts()
|
||||
}
|
||||
|
||||
private fun showAddFavoritesDialog() {
|
||||
AddFavoritesDialog(activity!!) {
|
||||
initContacts()
|
||||
|
|
|
@ -10,7 +10,6 @@ import com.simplemobiletools.commons.extensions.toast
|
|||
import com.simplemobiletools.commons.extensions.updateTextColors
|
||||
import com.simplemobiletools.commons.helpers.SORT_BY_FIRST_NAME
|
||||
import com.simplemobiletools.commons.helpers.SORT_BY_SURNAME
|
||||
import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener
|
||||
import com.simplemobiletools.contacts.R
|
||||
import com.simplemobiletools.contacts.activities.MainActivity
|
||||
import com.simplemobiletools.contacts.activities.SimpleActivity
|
||||
|
@ -23,7 +22,7 @@ import com.simplemobiletools.contacts.helpers.ContactsHelper
|
|||
import com.simplemobiletools.contacts.models.Contact
|
||||
import kotlinx.android.synthetic.main.fragment_layout.view.*
|
||||
|
||||
abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet) : CoordinatorLayout(context, attributeSet), RefreshRecyclerViewListener {
|
||||
abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet) : CoordinatorLayout(context, attributeSet) {
|
||||
var activity: MainActivity? = null
|
||||
lateinit var config: Config
|
||||
|
||||
|
@ -116,7 +115,7 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
|||
|
||||
val currAdapter = fragment_list.adapter
|
||||
if (currAdapter == null) {
|
||||
ContactsAdapter(activity as SimpleActivity, contacts, this, this is FavoritesFragment, fragment_list) {
|
||||
ContactsAdapter(activity as SimpleActivity, contacts, activity, this is FavoritesFragment, fragment_list) {
|
||||
if (config.callContact) {
|
||||
val contact = it as Contact
|
||||
if (contact.phoneNumbers.isNotEmpty()) {
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
package com.simplemobiletools.interfaces
|
||||
|
||||
interface RefreshContactsListener {
|
||||
fun refreshItems()
|
||||
|
||||
fun refreshFavorites()
|
||||
}
|
|
@ -11,6 +11,11 @@
|
|||
android:icon="@drawable/ic_select_all"
|
||||
android:title="@string/select_all"
|
||||
app:showAsAction="ifRoom"/>
|
||||
<item
|
||||
android:id="@+id/cab_add_to_favorites"
|
||||
android:icon="@drawable/ic_star_on"
|
||||
android:title="@string/add_to_favorites"
|
||||
app:showAsAction="ifRoom"/>
|
||||
<item
|
||||
android:id="@+id/cab_delete"
|
||||
android:icon="@drawable/ic_delete"
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
<!-- Favorites -->
|
||||
<string name="no_favorites">Sieht so aus, als ob du keine Kontakte zu den Favoriten hinzugefügt hast.</string>
|
||||
<string name="add_favorites">Zu Favoriten hinzufügen</string>
|
||||
<string name="add_to_favorites">Add to favorites</string>
|
||||
<string name="remove_from_favorites">Aus Favoriten entfernen</string>
|
||||
|
||||
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
<!-- Favorites -->
|
||||
<string name="no_favorites">Seems like you haven\'t added any favorite contacts yet.</string>
|
||||
<string name="add_favorites">Add favorites</string>
|
||||
<string name="add_to_favorites">Add to favorites</string>
|
||||
<string name="remove_from_favorites">Remove from favorites</string>
|
||||
|
||||
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
<!-- Favorites -->
|
||||
<string name="no_favorites">Seems like you haven\'t added any favorite contacts yet.</string>
|
||||
<string name="add_favorites">Add favorites</string>
|
||||
<string name="add_to_favorites">Add to favorites</string>
|
||||
<string name="remove_from_favorites">Remove from favorites</string>
|
||||
|
||||
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
<!-- Favorites -->
|
||||
<string name="no_favorites">Seems like you haven\'t added any favorite contacts yet.</string>
|
||||
<string name="add_favorites">Add favorites</string>
|
||||
<string name="add_to_favorites">Add to favorites</string>
|
||||
<string name="remove_from_favorites">Remove from favorites</string>
|
||||
|
||||
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
<!-- Favorites -->
|
||||
<string name="no_favorites">Zdá sa, že ste ešte nepridali žiadne obľúbené kontakty.</string>
|
||||
<string name="add_favorites">Pridať obľúbené</string>
|
||||
<string name="add_to_favorites">Pridať medzi obľúbené</string>
|
||||
<string name="remove_from_favorites">Odstrániť z obľúbených</string>
|
||||
|
||||
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
<!-- Favorites -->
|
||||
<string name="no_favorites">Seems like you haven\'t added any favorite contacts yet.</string>
|
||||
<string name="add_favorites">Add favorites</string>
|
||||
<string name="add_to_favorites">Add to favorites</string>
|
||||
<string name="remove_from_favorites">Remove from favorites</string>
|
||||
|
||||
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
|
||||
|
|
Loading…
Reference in a new issue