use different icons for deleting a contact and removing a favorite

This commit is contained in:
tibbi 2017-12-30 17:43:29 +01:00
parent 0b42a283c0
commit 09c528dd92
3 changed files with 15 additions and 2 deletions

View File

@ -24,7 +24,8 @@ import com.simplemobiletools.contacts.models.Contact
import kotlinx.android.synthetic.main.item_contact_with_number.view.* 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: RefreshRecyclerViewListener?,
recyclerView: MyRecyclerView, itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, itemClick) { val isFavoritesFragment: Boolean, recyclerView: MyRecyclerView, itemClick: (Any) -> Unit) :
MyRecyclerViewAdapter(activity, recyclerView, itemClick) {
var config = activity.config var config = activity.config
lateinit private var contactDrawable: Drawable lateinit private var contactDrawable: Drawable
@ -42,6 +43,8 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: MutableList<Co
override fun prepareActionMode(menu: Menu) { override fun prepareActionMode(menu: Menu) {
menu.apply { menu.apply {
findItem(R.id.cab_edit).isVisible = activity.config.callContact && isOneItemSelected() findItem(R.id.cab_edit).isVisible = activity.config.callContact && isOneItemSelected()
findItem(R.id.cab_remove).isVisible = isFavoritesFragment
findItem(R.id.cab_delete).isVisible = !isFavoritesFragment
} }
} }
@ -56,6 +59,7 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: MutableList<Co
R.id.cab_edit -> editContact() R.id.cab_edit -> editContact()
R.id.cab_select_all -> selectAll() R.id.cab_select_all -> selectAll()
R.id.cab_delete -> askConfirmDelete() R.id.cab_delete -> askConfirmDelete()
R.id.cab_remove -> removeFavorites()
} }
} }
@ -108,6 +112,10 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: MutableList<Co
removeSelectedItems() removeSelectedItems()
} }
private fun removeFavorites() {
}
override fun onViewRecycled(holder: ViewHolder?) { override fun onViewRecycled(holder: ViewHolder?) {
super.onViewRecycled(holder) super.onViewRecycled(holder)
if (!activity.isActivityDestroyed()) { if (!activity.isActivityDestroyed()) {

View File

@ -116,7 +116,7 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
val currAdapter = fragment_list.adapter val currAdapter = fragment_list.adapter
if (currAdapter == null) { if (currAdapter == null) {
ContactsAdapter(activity as SimpleActivity, contacts, this, fragment_list) { ContactsAdapter(activity as SimpleActivity, contacts, this, this is FavoritesFragment, fragment_list) {
if (config.callContact) { if (config.callContact) {
val contact = it as Contact val contact = it as Contact
if (contact.phoneNumbers.isNotEmpty()) { if (contact.phoneNumbers.isNotEmpty()) {

View File

@ -16,4 +16,9 @@
android:icon="@drawable/ic_delete" android:icon="@drawable/ic_delete"
android:title="@string/delete" android:title="@string/delete"
app:showAsAction="ifRoom"/> app:showAsAction="ifRoom"/>
<item
android:id="@+id/cab_remove"
android:icon="@drawable/ic_minus"
android:title="@string/remove_from_favorites"
app:showAsAction="ifRoom"/>
</menu> </menu>