mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-06-05 21:59:27 +02:00
show/hide contact tabs as appropriate
This commit is contained in:
@ -45,7 +45,7 @@ ext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.simplemobiletools:commons:4.5.12'
|
implementation 'com.simplemobiletools:commons:4.5.14'
|
||||||
implementation 'joda-time:joda-time:2.9.9'
|
implementation 'joda-time:joda-time:2.9.9'
|
||||||
implementation 'com.facebook.stetho:stetho:1.5.0'
|
implementation 'com.facebook.stetho:stetho:1.5.0'
|
||||||
|
|
||||||
|
@ -45,6 +45,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||||||
private var werePermissionsHandled = false
|
private var werePermissionsHandled = false
|
||||||
private var isFirstResume = true
|
private var isFirstResume = true
|
||||||
private var isGettingContacts = false
|
private var isGettingContacts = false
|
||||||
|
private var handledShowTabs = 0
|
||||||
|
|
||||||
private var storedTextColor = 0
|
private var storedTextColor = 0
|
||||||
private var storedBackgroundColor = 0
|
private var storedBackgroundColor = 0
|
||||||
@ -53,6 +54,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||||||
private var storedShowPhoneNumbers = false
|
private var storedShowPhoneNumbers = false
|
||||||
private var storedStartNameWithSurname = false
|
private var storedStartNameWithSurname = false
|
||||||
private var storedFilterDuplicates = true
|
private var storedFilterDuplicates = true
|
||||||
|
private var storedShowTabs = 0
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
@ -92,6 +94,10 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (storedShowTabs != config.showTabs) {
|
||||||
|
viewpager.adapter = null
|
||||||
|
}
|
||||||
|
|
||||||
val configShowContactThumbnails = config.showContactThumbnails
|
val configShowContactThumbnails = config.showContactThumbnails
|
||||||
if (storedShowContactThumbnails != configShowContactThumbnails) {
|
if (storedShowContactThumbnails != configShowContactThumbnails) {
|
||||||
getAllFragments().forEach {
|
getAllFragments().forEach {
|
||||||
@ -191,6 +197,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||||||
storedShowPhoneNumbers = showPhoneNumbers
|
storedShowPhoneNumbers = showPhoneNumbers
|
||||||
storedStartNameWithSurname = startNameWithSurname
|
storedStartNameWithSurname = startNameWithSurname
|
||||||
storedFilterDuplicates = filterDuplicates
|
storedFilterDuplicates = filterDuplicates
|
||||||
|
storedShowTabs = showTabs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,6 +242,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun setupTabColors() {
|
private fun setupTabColors() {
|
||||||
|
handledShowTabs = config.showTabs
|
||||||
val lastUsedPage = config.lastUsedViewPagerPage
|
val lastUsedPage = config.lastUsedViewPagerPage
|
||||||
main_tabs_holder.apply {
|
main_tabs_holder.apply {
|
||||||
background = ColorDrawable(config.backgroundColor)
|
background = ColorDrawable(config.backgroundColor)
|
||||||
@ -250,10 +258,10 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||||||
|
|
||||||
private fun storeLocalAccountData() {
|
private fun storeLocalAccountData() {
|
||||||
if (config.localAccountType == "-1") {
|
if (config.localAccountType == "-1") {
|
||||||
ContactsHelper(this).getContactSources {
|
ContactsHelper(this).getContactSources { sources ->
|
||||||
var localAccountType = ""
|
var localAccountType = ""
|
||||||
var localAccountName = ""
|
var localAccountName = ""
|
||||||
it.forEach {
|
sources.forEach {
|
||||||
if (localAccountTypes.contains(it.type)) {
|
if (localAccountTypes.contains(it.type)) {
|
||||||
localAccountType = it.type
|
localAccountType = it.type
|
||||||
localAccountName = it.name
|
localAccountName = it.name
|
||||||
@ -309,6 +317,60 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||||||
tryImportContactsFromFile(intent.data)
|
tryImportContactsFromFile(intent.data)
|
||||||
intent.data = null
|
intent.data = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val showTabs = config.showTabs
|
||||||
|
val indexesToRemove = ArrayList<Int>()
|
||||||
|
tabsList.forEachIndexed { index, value ->
|
||||||
|
if (showTabs and value == 0) {
|
||||||
|
if (main_tabs_holder?.getTabAt(index) != null) {
|
||||||
|
indexesToRemove.add(index)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
indexesToRemove.reversed().forEach {
|
||||||
|
main_tabs_holder.removeTabAt(it)
|
||||||
|
}
|
||||||
|
|
||||||
|
tabsList.forEachIndexed { index, value ->
|
||||||
|
if (showTabs and value != 0 && handledShowTabs and value == 0) {
|
||||||
|
main_tabs_holder.addTab(main_tabs_holder.newTab().setIcon(getTabIcon(value)), getTabPosition(value, showTabs))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
handledShowTabs = config.showTabs
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getTabIcon(position: Int) = resources.getDrawable(when (position) {
|
||||||
|
CONTACTS_TAB_MASK -> R.drawable.ic_person
|
||||||
|
FAVORITES_TAB_MASK -> R.drawable.ic_star_on
|
||||||
|
else -> R.drawable.ic_group
|
||||||
|
})
|
||||||
|
|
||||||
|
private fun getTabPosition(value: Int, showTabs: Int): Int {
|
||||||
|
return when (value) {
|
||||||
|
CONTACTS_TAB_MASK -> 0
|
||||||
|
FAVORITES_TAB_MASK -> {
|
||||||
|
if (showTabs and CONTACTS_TAB_MASK != 0) {
|
||||||
|
1
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
if (showTabs and CONTACTS_TAB_MASK != 0) {
|
||||||
|
if (showTabs and FAVORITES_TAB_MASK != 0) {
|
||||||
|
2
|
||||||
|
} else {
|
||||||
|
1
|
||||||
|
}
|
||||||
|
} else if (showTabs and FAVORITES_TAB_MASK != 0) {
|
||||||
|
1
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showSortingDialog() {
|
private fun showSortingDialog() {
|
||||||
@ -383,13 +445,13 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||||||
FilePickerDialog(this, pickFile = false, showFAB = true) {
|
FilePickerDialog(this, pickFile = false, showFAB = true) {
|
||||||
ExportContactsDialog(this, it) { file, contactSources ->
|
ExportContactsDialog(this, it) { file, contactSources ->
|
||||||
Thread {
|
Thread {
|
||||||
ContactsHelper(this).getContacts {
|
ContactsHelper(this).getContacts { allContacts ->
|
||||||
val contacts = it.filter { contactSources.contains(it.source) }
|
val contacts = allContacts.filter { contactSources.contains(it.source) }
|
||||||
if (contacts.isEmpty()) {
|
if (contacts.isEmpty()) {
|
||||||
toast(R.string.no_entries_for_exporting)
|
toast(R.string.no_entries_for_exporting)
|
||||||
} else {
|
} else {
|
||||||
VcfExporter().exportContacts(this, file, contacts as ArrayList<Contact>, true) {
|
VcfExporter().exportContacts(this, file, contacts as ArrayList<Contact>, true) { result ->
|
||||||
toast(when (it) {
|
toast(when (result) {
|
||||||
VcfExporter.ExportResult.EXPORT_OK -> R.string.exporting_successful
|
VcfExporter.ExportResult.EXPORT_OK -> R.string.exporting_successful
|
||||||
VcfExporter.ExportResult.EXPORT_PARTIAL -> R.string.exporting_some_entries_failed
|
VcfExporter.ExportResult.EXPORT_PARTIAL -> R.string.exporting_some_entries_failed
|
||||||
else -> R.string.exporting_failed
|
else -> R.string.exporting_failed
|
||||||
|
@ -5,15 +5,21 @@ import android.view.View
|
|||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import com.simplemobiletools.contacts.R
|
import com.simplemobiletools.contacts.R
|
||||||
import com.simplemobiletools.contacts.activities.MainActivity
|
import com.simplemobiletools.contacts.activities.MainActivity
|
||||||
|
import com.simplemobiletools.contacts.extensions.config
|
||||||
import com.simplemobiletools.contacts.fragments.MyViewPagerFragment
|
import com.simplemobiletools.contacts.fragments.MyViewPagerFragment
|
||||||
|
import com.simplemobiletools.contacts.helpers.CONTACTS_TAB_MASK
|
||||||
|
import com.simplemobiletools.contacts.helpers.FAVORITES_TAB_MASK
|
||||||
|
import com.simplemobiletools.contacts.helpers.tabsList
|
||||||
import com.simplemobiletools.contacts.models.Contact
|
import com.simplemobiletools.contacts.models.Contact
|
||||||
|
|
||||||
class ViewPagerAdapter(val activity: MainActivity, val contacts: ArrayList<Contact>) : PagerAdapter() {
|
class ViewPagerAdapter(val activity: MainActivity, val contacts: ArrayList<Contact>) : PagerAdapter() {
|
||||||
|
val showTabs = activity.config.showTabs
|
||||||
|
|
||||||
override fun instantiateItem(container: ViewGroup, position: Int): Any {
|
override fun instantiateItem(container: ViewGroup, position: Int): Any {
|
||||||
val layout = getFragment(position)
|
val layout = getFragment(position)
|
||||||
val view = activity.layoutInflater.inflate(layout, container, false)
|
val view = activity.layoutInflater.inflate(layout, container, false)
|
||||||
container.addView(view)
|
container.addView(view)
|
||||||
|
|
||||||
(view as MyViewPagerFragment).apply {
|
(view as MyViewPagerFragment).apply {
|
||||||
setupFragment(activity)
|
setupFragment(activity)
|
||||||
refreshContacts(contacts)
|
refreshContacts(contacts)
|
||||||
@ -25,12 +31,31 @@ class ViewPagerAdapter(val activity: MainActivity, val contacts: ArrayList<Conta
|
|||||||
container.removeView(item as View)
|
container.removeView(item as View)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getCount() = 3
|
override fun getCount() = tabsList.filter { it and showTabs != 0 }.size
|
||||||
|
|
||||||
override fun isViewFromObject(view: View, item: Any) = view == item
|
override fun isViewFromObject(view: View, item: Any) = view == item
|
||||||
|
|
||||||
private fun getFragment(position: Int) = when (position) {
|
private fun getFragment(position: Int): Int {
|
||||||
0 -> R.layout.fragment_contacts
|
return when (position) {
|
||||||
1 -> R.layout.fragment_favorites
|
0 -> {
|
||||||
else -> R.layout.fragment_groups
|
when {
|
||||||
|
showTabs and CONTACTS_TAB_MASK != 0 -> R.layout.fragment_contacts
|
||||||
|
showTabs and FAVORITES_TAB_MASK != 0 -> R.layout.fragment_favorites
|
||||||
|
else -> R.layout.fragment_groups
|
||||||
|
}
|
||||||
|
}
|
||||||
|
1 -> {
|
||||||
|
if (showTabs and CONTACTS_TAB_MASK != 0) {
|
||||||
|
if (showTabs and FAVORITES_TAB_MASK != 0) {
|
||||||
|
R.layout.fragment_favorites
|
||||||
|
} else {
|
||||||
|
R.layout.fragment_groups
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
R.layout.fragment_groups
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> R.layout.fragment_groups
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,11 @@ const val FAVORITES_TAB_MASK = 2
|
|||||||
const val GROUPS_TAB_MASK = 4
|
const val GROUPS_TAB_MASK = 4
|
||||||
const val ALL_TABS_MASK = 7
|
const val ALL_TABS_MASK = 7
|
||||||
|
|
||||||
|
val tabsList = arrayListOf(CONTACTS_TAB_MASK,
|
||||||
|
FAVORITES_TAB_MASK,
|
||||||
|
GROUPS_TAB_MASK
|
||||||
|
)
|
||||||
|
|
||||||
// contact photo changes
|
// contact photo changes
|
||||||
const val PHOTO_ADDED = 1
|
const val PHOTO_ADDED = 1
|
||||||
const val PHOTO_REMOVED = 2
|
const val PHOTO_REMOVED = 2
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||||
|
|
||||||
buildscript {
|
buildscript {
|
||||||
ext.kotlin_version = '1.2.51'
|
ext.kotlin_version = '1.2.60'
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
google()
|
google()
|
||||||
|
Reference in New Issue
Block a user