updating commons, reuse TAB constants from there

This commit is contained in:
tibbi 2020-05-23 20:00:02 +02:00
parent 697726b7e1
commit c0bfe21032
11 changed files with 62 additions and 69 deletions

View file

@ -57,7 +57,7 @@ android {
}
dependencies {
implementation 'com.simplemobiletools:commons:5.28.10'
implementation 'com.simplemobiletools:commons:5.28.20'
implementation 'joda-time:joda-time:2.10.1'
implementation 'com.googlecode.ez-vcard:ez-vcard:0.10.5'
implementation 'com.github.tibbi:IndicatorFastScroll:08f512858a'

View file

@ -13,10 +13,7 @@ import androidx.appcompat.widget.SearchView
import androidx.core.view.MenuItemCompat
import androidx.viewpager.widget.ViewPager
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.KEY_PHONE
import com.simplemobiletools.commons.helpers.PERMISSION_GET_ACCOUNTS
import com.simplemobiletools.commons.helpers.PERMISSION_READ_CONTACTS
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_CONTACTS
import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.contacts.pro.adapters.ViewPagerAdapter
import com.simplemobiletools.contacts.pro.dialogs.ChangeSortingDialog
@ -39,8 +36,8 @@ class InsertOrEditContactActivity : SimpleActivity(), RefreshContactsListener {
private var searchMenuItem: MenuItem? = null
private val contactsFavoritesList = arrayListOf(
CONTACTS_TAB_MASK,
FAVORITES_TAB_MASK
TAB_CONTACTS,
TAB_FAVORITES
)
override fun onCreate(savedInstanceState: Bundle?) {
@ -133,7 +130,7 @@ class InsertOrEditContactActivity : SimpleActivity(), RefreshContactsListener {
insert_or_edit_tabs_holder.removeAllTabs()
var skippedTabs = 0
contactsFavoritesList.forEachIndexed { index, value ->
if (config.showTabs and value == 0 && value == FAVORITES_TAB_MASK) {
if (config.showTabs and value == 0 && value == TAB_FAVORITES) {
skippedTabs++
} else {
val tab = insert_or_edit_tabs_holder.newTab().setIcon(getTabIcon(index))
@ -220,11 +217,11 @@ class InsertOrEditContactActivity : SimpleActivity(), RefreshContactsListener {
return@getContacts
}
if (refreshTabsMask and CONTACTS_TAB_MASK != 0) {
if (refreshTabsMask and TAB_CONTACTS != 0) {
contacts_fragment?.refreshContacts(contacts)
}
if (refreshTabsMask and FAVORITES_TAB_MASK != 0) {
if (refreshTabsMask and TAB_FAVORITES != 0) {
favorites_fragment?.refreshContacts(contacts)
}
}
@ -298,9 +295,9 @@ class InsertOrEditContactActivity : SimpleActivity(), RefreshContactsListener {
}
fun getTabsMask(): Int {
var mask = CONTACTS_TAB_MASK
if (config.showTabs and FAVORITES_TAB_MASK != 0) {
mask += FAVORITES_TAB_MASK
var mask = TAB_CONTACTS
if (config.showTabs and TAB_FAVORITES != 0) {
mask += TAB_FAVORITES
}
return mask
}

View file

@ -342,15 +342,15 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
private fun getCurrentFragment(): MyViewPagerFragment? {
val showTabs = config.showTabs
val fragments = arrayListOf<MyViewPagerFragment>()
if (showTabs and CONTACTS_TAB_MASK != 0) {
if (showTabs and TAB_CONTACTS != 0) {
fragments.add(contacts_fragment)
}
if (showTabs and FAVORITES_TAB_MASK != 0) {
if (showTabs and TAB_FAVORITES != 0) {
fragments.add(favorites_fragment)
}
if (showTabs and GROUPS_TAB_MASK != 0) {
if (showTabs and TAB_GROUPS != 0) {
fragments.add(groups_fragment)
}
@ -446,14 +446,14 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
private fun showSortingDialog() {
ChangeSortingDialog(this) {
refreshContacts(CONTACTS_TAB_MASK or FAVORITES_TAB_MASK)
refreshContacts(TAB_CONTACTS or TAB_FAVORITES)
}
}
fun showFilterDialog() {
FilterContactSourcesDialog(this) {
contacts_fragment?.forceListRedraw = true
refreshContacts(CONTACTS_TAB_MASK or FAVORITES_TAB_MASK)
refreshContacts(TAB_CONTACTS or TAB_FAVORITES)
}
}
@ -590,16 +590,16 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
return@getContacts
}
if (refreshTabsMask and CONTACTS_TAB_MASK != 0) {
if (refreshTabsMask and TAB_CONTACTS != 0) {
contacts_fragment?.refreshContacts(contacts)
}
if (refreshTabsMask and FAVORITES_TAB_MASK != 0) {
if (refreshTabsMask and TAB_FAVORITES != 0) {
favorites_fragment?.refreshContacts(contacts)
}
if (refreshTabsMask and GROUPS_TAB_MASK != 0) {
if (refreshTabsMask == GROUPS_TAB_MASK) {
if (refreshTabsMask and TAB_GROUPS != 0) {
if (refreshTabsMask == TAB_GROUPS) {
groups_fragment.skipHashComparing = true
}
groups_fragment?.refreshContacts(contacts)

View file

@ -16,8 +16,7 @@ import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.SimpleContactsHelper
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.commons.models.RadioItem
import com.simplemobiletools.commons.views.FastScroller
import com.simplemobiletools.commons.views.MyRecyclerView
@ -137,9 +136,8 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
private fun askConfirmDelete() {
val itemsCnt = selectedKeys.size
val firstItem = getSelectedItems().first()
val items = if (itemsCnt == 1) {
"\"${firstItem.getNameToDisplay()}\""
"\"${getSelectedItems().first().getNameToDisplay()}\""
} else {
resources.getQuantityString(R.plurals.delete_contacts, itemsCnt, itemsCnt)
}
@ -176,7 +174,7 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
finishActMode()
} else {
removeSelectedItems(positions)
refreshListener?.refreshContacts(CONTACTS_TAB_MASK or FAVORITES_TAB_MASK)
refreshListener?.refreshContacts(TAB_CONTACTS or TAB_FAVORITES)
}
}
}
@ -192,7 +190,7 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
if (location == LOCATION_FAVORITES_TAB) {
ContactsHelper(activity).removeFavorites(contactsToRemove)
if (contactItems.isEmpty()) {
refreshListener?.refreshContacts(FAVORITES_TAB_MASK)
refreshListener?.refreshContacts(TAB_FAVORITES)
finishActMode()
} else {
removeSelectedItems(positions)
@ -205,7 +203,7 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
private fun addToFavorites() {
ContactsHelper(activity).addFavorites(getSelectedItems())
refreshListener?.refreshContacts(FAVORITES_TAB_MASK)
refreshListener?.refreshContacts(TAB_FAVORITES)
finishActMode()
}
@ -227,14 +225,14 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
CreateNewGroupDialog(activity) {
ensureBackgroundThread {
activity.addContactsToGroup(selectedContacts, it.id!!.toLong())
refreshListener?.refreshContacts(GROUPS_TAB_MASK)
refreshListener?.refreshContacts(TAB_GROUPS)
}
finishActMode()
}
} else {
ensureBackgroundThread {
activity.addContactsToGroup(selectedContacts, it.toLong())
refreshListener?.refreshContacts(GROUPS_TAB_MASK)
refreshListener?.refreshContacts(TAB_GROUPS)
}
finishActMode()
}

View file

@ -11,6 +11,7 @@ import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor
import com.simplemobiletools.commons.extensions.getTextSize
import com.simplemobiletools.commons.extensions.highlightTextPart
import com.simplemobiletools.commons.helpers.SimpleContactsHelper
import com.simplemobiletools.commons.helpers.TAB_GROUPS
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.commons.views.FastScroller
import com.simplemobiletools.commons.views.MyRecyclerView
@ -20,7 +21,6 @@ import com.simplemobiletools.contacts.pro.dialogs.RenameGroupDialog
import com.simplemobiletools.contacts.pro.extensions.config
import com.simplemobiletools.contacts.pro.extensions.groupsDB
import com.simplemobiletools.contacts.pro.helpers.ContactsHelper
import com.simplemobiletools.contacts.pro.helpers.GROUPS_TAB_MASK
import com.simplemobiletools.contacts.pro.interfaces.RefreshContactsListener
import com.simplemobiletools.contacts.pro.models.Group
import kotlinx.android.synthetic.main.item_group.view.*
@ -102,7 +102,7 @@ class GroupsAdapter(activity: SimpleActivity, var groups: ArrayList<Group>, val
val group = getItemWithKey(selectedKeys.first()) ?: return
RenameGroupDialog(activity, group) {
finishActMode()
refreshListener?.refreshContacts(GROUPS_TAB_MASK)
refreshListener?.refreshContacts(TAB_GROUPS)
}
}
@ -143,7 +143,7 @@ class GroupsAdapter(activity: SimpleActivity, var groups: ArrayList<Group>, val
activity.runOnUiThread {
if (groups.isEmpty()) {
refreshListener?.refreshContacts(GROUPS_TAB_MASK)
refreshListener?.refreshContacts(TAB_GROUPS)
finishActMode()
} else {
removeSelectedItems(positions)

View file

@ -3,12 +3,12 @@ package com.simplemobiletools.contacts.pro.adapters
import android.view.View
import android.view.ViewGroup
import androidx.viewpager.widget.PagerAdapter
import com.simplemobiletools.commons.helpers.TAB_CONTACTS
import com.simplemobiletools.commons.helpers.TAB_FAVORITES
import com.simplemobiletools.commons.helpers.TAB_GROUPS
import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.contacts.pro.activities.SimpleActivity
import com.simplemobiletools.contacts.pro.fragments.MyViewPagerFragment
import com.simplemobiletools.contacts.pro.helpers.CONTACTS_TAB_MASK
import com.simplemobiletools.contacts.pro.helpers.FAVORITES_TAB_MASK
import com.simplemobiletools.contacts.pro.helpers.GROUPS_TAB_MASK
class ViewPagerAdapter(val activity: SimpleActivity, val currTabsList: ArrayList<Int>, val showTabs: Int) : PagerAdapter() {
@ -34,15 +34,15 @@ class ViewPagerAdapter(val activity: SimpleActivity, val currTabsList: ArrayList
private fun getFragment(position: Int): Int {
val fragments = arrayListOf<Int>()
if (showTabs and CONTACTS_TAB_MASK != 0) {
if (showTabs and TAB_CONTACTS != 0) {
fragments.add(R.layout.fragment_contacts)
}
if (showTabs and FAVORITES_TAB_MASK != 0) {
if (showTabs and TAB_FAVORITES != 0) {
fragments.add(R.layout.fragment_favorites)
}
if (showTabs and GROUPS_TAB_MASK != 0) {
if (showTabs and TAB_GROUPS != 0) {
fragments.add(R.layout.fragment_groups)
}

View file

@ -3,13 +3,13 @@ package com.simplemobiletools.contacts.pro.dialogs
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.helpers.TAB_CONTACTS
import com.simplemobiletools.commons.helpers.TAB_FAVORITES
import com.simplemobiletools.commons.helpers.TAB_GROUPS
import com.simplemobiletools.commons.views.MyAppCompatCheckbox
import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.contacts.pro.extensions.config
import com.simplemobiletools.contacts.pro.helpers.ALL_TABS_MASK
import com.simplemobiletools.contacts.pro.helpers.CONTACTS_TAB_MASK
import com.simplemobiletools.contacts.pro.helpers.FAVORITES_TAB_MASK
import com.simplemobiletools.contacts.pro.helpers.GROUPS_TAB_MASK
class ManageVisibleTabsDialog(val activity: BaseSimpleActivity) {
private var view = activity.layoutInflater.inflate(R.layout.dialog_manage_visible_tabs, null)
@ -17,9 +17,9 @@ class ManageVisibleTabsDialog(val activity: BaseSimpleActivity) {
init {
tabs.apply {
put(CONTACTS_TAB_MASK, R.id.manage_visible_tabs_contacts)
put(FAVORITES_TAB_MASK, R.id.manage_visible_tabs_favorites)
put(GROUPS_TAB_MASK, R.id.manage_visible_tabs_groups)
put(TAB_CONTACTS, R.id.manage_visible_tabs_contacts)
put(TAB_FAVORITES, R.id.manage_visible_tabs_favorites)
put(TAB_GROUPS, R.id.manage_visible_tabs_groups)
}
val showTabs = activity.config.showTabs
@ -28,11 +28,11 @@ class ManageVisibleTabsDialog(val activity: BaseSimpleActivity) {
}
AlertDialog.Builder(activity)
.setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() }
.setNegativeButton(R.string.cancel, null)
.create().apply {
activity.setupDialogStuff(view, this)
}
.setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() }
.setNegativeButton(R.string.cancel, null)
.create().apply {
activity.setupDialogStuff(view, this)
}
}
private fun dialogConfirmed() {

View file

@ -2,11 +2,11 @@ package com.simplemobiletools.contacts.pro.fragments
import android.content.Context
import android.util.AttributeSet
import com.simplemobiletools.commons.helpers.TAB_FAVORITES
import com.simplemobiletools.contacts.pro.activities.MainActivity
import com.simplemobiletools.contacts.pro.activities.SimpleActivity
import com.simplemobiletools.contacts.pro.dialogs.SelectContactsDialog
import com.simplemobiletools.contacts.pro.helpers.ContactsHelper
import com.simplemobiletools.contacts.pro.helpers.FAVORITES_TAB_MASK
class FavoritesFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet) {
override fun fabClicked() {
@ -25,7 +25,7 @@ class FavoritesFragment(context: Context, attributeSet: AttributeSet) : MyViewPa
removeFavorites(removedContacts)
}
(activity as? MainActivity)?.refreshContacts(FAVORITES_TAB_MASK)
(activity as? MainActivity)?.refreshContacts(TAB_FAVORITES)
}
}
}

View file

@ -2,10 +2,10 @@ package com.simplemobiletools.contacts.pro.fragments
import android.content.Context
import android.util.AttributeSet
import com.simplemobiletools.commons.helpers.TAB_GROUPS
import com.simplemobiletools.contacts.pro.activities.MainActivity
import com.simplemobiletools.contacts.pro.activities.SimpleActivity
import com.simplemobiletools.contacts.pro.dialogs.CreateNewGroupDialog
import com.simplemobiletools.contacts.pro.helpers.GROUPS_TAB_MASK
class GroupsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet) {
override fun fabClicked() {
@ -19,7 +19,7 @@ class GroupsFragment(context: Context, attributeSet: AttributeSet) : MyViewPager
private fun showNewGroupsDialog() {
CreateNewGroupDialog(activity as SimpleActivity) {
(activity as? MainActivity)?.refreshContacts(GROUPS_TAB_MASK)
(activity as? MainActivity)?.refreshContacts(TAB_GROUPS)
}
}
}

View file

@ -8,9 +8,7 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout
import com.reddit.indicatorfastscroll.FastScrollItemIndicator
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.SORT_BY_FIRST_NAME
import com.simplemobiletools.commons.helpers.SORT_BY_MIDDLE_NAME
import com.simplemobiletools.commons.helpers.SORT_BY_SURNAME
import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.contacts.pro.activities.GroupContactsActivity
import com.simplemobiletools.contacts.pro.activities.InsertOrEditContactActivity
@ -108,15 +106,15 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
if (this !is GroupsFragment) {
(fragment_list.adapter as? ContactsAdapter)?.apply {
config.sorting = if (startNameWithSurname) SORT_BY_SURNAME else SORT_BY_FIRST_NAME
(this@MyViewPagerFragment.activity!! as MainActivity).refreshContacts(CONTACTS_TAB_MASK or FAVORITES_TAB_MASK)
(this@MyViewPagerFragment.activity!! as MainActivity).refreshContacts(TAB_CONTACTS or TAB_FAVORITES)
}
}
}
fun refreshContacts(contacts: ArrayList<Contact>) {
if ((config.showTabs and CONTACTS_TAB_MASK == 0 && this is ContactsFragment && activity !is InsertOrEditContactActivity) ||
(config.showTabs and FAVORITES_TAB_MASK == 0 && this is FavoritesFragment) ||
(config.showTabs and GROUPS_TAB_MASK == 0 && this is GroupsFragment)) {
if ((config.showTabs and TAB_CONTACTS == 0 && this is ContactsFragment && activity !is InsertOrEditContactActivity) ||
(config.showTabs and TAB_FAVORITES == 0 && this is FavoritesFragment) ||
(config.showTabs and TAB_GROUPS == 0 && this is GroupsFragment)) {
return
}

View file

@ -2,6 +2,9 @@ package com.simplemobiletools.contacts.pro.helpers
import android.provider.ContactsContract.CommonDataKinds
import com.simplemobiletools.commons.extensions.normalizeString
import com.simplemobiletools.commons.helpers.TAB_CONTACTS
import com.simplemobiletools.commons.helpers.TAB_FAVORITES
import com.simplemobiletools.commons.helpers.TAB_GROUPS
import com.simplemobiletools.contacts.pro.models.LocalContact
// shared prefs
@ -47,14 +50,11 @@ const val LOCATION_GROUP_CONTACTS = 2
const val LOCATION_DIALPAD = 3
const val LOCATION_INSERT_OR_EDIT = 4
const val CONTACTS_TAB_MASK = 1
const val FAVORITES_TAB_MASK = 2
const val GROUPS_TAB_MASK = 8
const val ALL_TABS_MASK = CONTACTS_TAB_MASK or FAVORITES_TAB_MASK or GROUPS_TAB_MASK
const val ALL_TABS_MASK = TAB_CONTACTS or TAB_FAVORITES or TAB_GROUPS
val tabsList = arrayListOf(CONTACTS_TAB_MASK,
FAVORITES_TAB_MASK,
GROUPS_TAB_MASK
val tabsList = arrayListOf(TAB_CONTACTS,
TAB_FAVORITES,
TAB_GROUPS
)
// contact photo changes