Migrate to viewbinding and kotlin gradle scripts

- Replaced kotlinx sythetic with viewbinding
- Update build scripts to kotlin
- Intoduced version catalog, similar to Commons
- Updated kotlin from 1.7.10 to 1.9.0
- Updated room from 2.5.2 to 2.6.0-alpha02 (same as Commons)
- Updated Android Gradle Plugin to 8.1.0
This commit is contained in:
Ensar Sarajčić 2023-08-07 16:13:37 +02:00
parent c573e659e9
commit e1ca1d4a86
50 changed files with 1553 additions and 1309 deletions

View file

@ -1,77 +0,0 @@
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-android-extensions'
id 'kotlin-kapt'
}
def keystorePropertiesFile = rootProject.file("keystore.properties")
def keystoreProperties = new Properties()
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
android {
compileSdkVersion 33
defaultConfig {
applicationId "com.simplemobiletools.contacts.pro"
minSdkVersion 23
targetSdkVersion 33
versionCode 104
versionName "6.22.4"
setProperty("archivesBaseName", "contacts")
}
signingConfigs {
if (keystorePropertiesFile.exists()) {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
}
buildTypes {
debug {
applicationIdSuffix ".debug"
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
if (keystorePropertiesFile.exists()) {
signingConfig signingConfigs.release
}
}
}
flavorDimensions "variants"
productFlavors {
core {}
fdroid {}
prepaid {}
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
checkReleaseBuilds false
abortOnError false
}
}
dependencies {
implementation 'com.github.SimpleMobileTools:Simple-Commons:91763fe00f'
implementation 'com.googlecode.ez-vcard:ez-vcard:0.11.3'
implementation 'com.github.tibbi:IndicatorFastScroll:4524cd0b61'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'me.grantland:autofittextview:0.2.1'
kapt "androidx.room:room-compiler:2.5.1"
implementation "androidx.room:room-runtime:2.5.1"
annotationProcessor "androidx.room:room-compiler:2.5.1"
}

98
app/build.gradle.kts Normal file
View file

@ -0,0 +1,98 @@
import java.io.FileInputStream
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlin.konan.properties.Properties
plugins {
alias(libs.plugins.android)
alias(libs.plugins.kotlinAndroid)
alias(libs.plugins.ksp)
}
val keystorePropertiesFile: File = rootProject.file("keystore.properties")
val keystoreProperties = Properties()
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(FileInputStream(keystorePropertiesFile))
}
android {
compileSdk = project.libs.versions.app.build.compileSDKVersion.get().toInt()
defaultConfig {
applicationId = libs.versions.app.version.appId.get()
minSdk = project.libs.versions.app.build.minimumSDK.get().toInt()
targetSdk = project.libs.versions.app.build.targetSDK.get().toInt()
versionName = project.libs.versions.app.version.versionName.get()
versionCode = project.libs.versions.app.version.versionCode.get().toInt()
setProperty("archivesBaseName", "contacts")
}
signingConfigs {
if (keystorePropertiesFile.exists()) {
register("release") {
keyAlias = keystoreProperties.getProperty("keyAlias")
keyPassword = keystoreProperties.getProperty("keyPassword")
storeFile = file(keystoreProperties.getProperty("storeFile"))
storePassword = keystoreProperties.getProperty("storePassword")
}
}
}
buildFeatures {
viewBinding = true
buildConfig = true
}
buildTypes {
debug {
applicationIdSuffix = ".debug"
}
release {
isMinifyEnabled = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
if (keystorePropertiesFile.exists()) {
signingConfig = signingConfigs.getByName("release")
}
}
}
flavorDimensions.add("variants")
productFlavors {
register("core")
register("fdroid")
register("prepaid")
}
sourceSets {
getByName("main").java.srcDirs("src/main/kotlin")
}
compileOptions {
val currentJavaVersionFromLibs = JavaVersion.valueOf(libs.versions.app.build.javaVersion.get().toString())
sourceCompatibility = currentJavaVersionFromLibs
targetCompatibility = currentJavaVersionFromLibs
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = project.libs.versions.app.build.kotlinJVMTarget.get()
}
namespace = libs.versions.app.version.appId.get()
lint {
checkReleaseBuilds = false
abortOnError = false
}
}
dependencies {
implementation(libs.simple.tools.commons)
implementation(libs.androidx.swiperefreshlayout)
implementation(libs.autofittextview)
implementation(libs.ezvcard)
implementation(libs.indicatorfastscroll)
implementation(libs.bundles.room)
ksp(libs.androidx.room.compiler)
}

View file

@ -27,9 +27,9 @@ import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.ContactsHelper
import com.simplemobiletools.commons.helpers.letterBackgroundColors
import com.simplemobiletools.commons.models.RadioItem
import com.simplemobiletools.commons.models.contacts.Contact
import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.contacts.pro.extensions.shareContacts
import com.simplemobiletools.commons.models.contacts.Contact
abstract class ContactActivity : SimpleActivity() {
protected val PICK_RINGTONE_INTENT_ID = 1500
@ -164,10 +164,10 @@ abstract class ContactActivity : SimpleActivity() {
} else {
getString(
when (type) {
Email.TYPE_HOME -> R.string.home
Email.TYPE_WORK -> R.string.work
Email.TYPE_MOBILE -> R.string.mobile
else -> R.string.other
Email.TYPE_HOME -> com.simplemobiletools.commons.R.string.home
Email.TYPE_WORK -> com.simplemobiletools.commons.R.string.work
Email.TYPE_MOBILE -> com.simplemobiletools.commons.R.string.mobile
else -> com.simplemobiletools.commons.R.string.other
}
)
}
@ -179,9 +179,9 @@ abstract class ContactActivity : SimpleActivity() {
} else {
getString(
when (type) {
StructuredPostal.TYPE_HOME -> R.string.home
StructuredPostal.TYPE_WORK -> R.string.work
else -> R.string.other
StructuredPostal.TYPE_HOME -> com.simplemobiletools.commons.R.string.home
StructuredPostal.TYPE_WORK -> com.simplemobiletools.commons.R.string.work
else -> com.simplemobiletools.commons.R.string.other
}
)
}
@ -207,9 +207,9 @@ abstract class ContactActivity : SimpleActivity() {
}
fun getEventTextId(type: Int) = when (type) {
Event.TYPE_ANNIVERSARY -> R.string.anniversary
Event.TYPE_BIRTHDAY -> R.string.birthday
else -> R.string.other
Event.TYPE_ANNIVERSARY -> com.simplemobiletools.commons.R.string.anniversary
Event.TYPE_BIRTHDAY -> com.simplemobiletools.commons.R.string.birthday
else -> com.simplemobiletools.commons.R.string.other
}
private fun getBigLetterPlaceholder(name: String): Bitmap {

View file

@ -14,20 +14,20 @@ import com.simplemobiletools.commons.models.contacts.Contact
import com.simplemobiletools.commons.models.contacts.Group
import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.contacts.pro.adapters.ContactsAdapter
import com.simplemobiletools.contacts.pro.databinding.ActivityGroupContactsBinding
import com.simplemobiletools.contacts.pro.dialogs.SelectContactsDialog
import com.simplemobiletools.contacts.pro.extensions.handleGenericContactClick
import com.simplemobiletools.contacts.pro.helpers.GROUP
import com.simplemobiletools.contacts.pro.helpers.LOCATION_GROUP_CONTACTS
import com.simplemobiletools.contacts.pro.interfaces.RefreshContactsListener
import com.simplemobiletools.contacts.pro.interfaces.RemoveFromGroupListener
import kotlinx.android.synthetic.main.activity_group_contacts.*
import kotlinx.android.synthetic.main.fragment_layout.fragment_list
class GroupContactsActivity : SimpleActivity(), RemoveFromGroupListener, RefreshContactsListener {
private var allContacts = ArrayList<Contact>()
private var groupContacts = ArrayList<Contact>()
private var wasInit = false
lateinit var group: Group
private lateinit var binding: ActivityGroupContactsBinding
protected val INTENT_SELECT_RINGTONE = 600
@ -36,42 +36,43 @@ class GroupContactsActivity : SimpleActivity(), RemoveFromGroupListener, Refresh
override fun onCreate(savedInstanceState: Bundle?) {
isMaterialActivity = true
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_group_contacts)
updateTextColors(group_contacts_coordinator)
binding = ActivityGroupContactsBinding.inflate(layoutInflater)
setContentView(binding.root)
updateTextColors(binding.groupContactsCoordinator)
setupOptionsMenu()
updateMaterialActivityViews(group_contacts_coordinator, group_contacts_list, useTransparentNavigation = true, useTopSearchMenu = false)
setupMaterialScrollListener(group_contacts_list, group_contacts_toolbar)
updateMaterialActivityViews(binding.groupContactsCoordinator, binding.groupContactsList, useTransparentNavigation = true, useTopSearchMenu = false)
setupMaterialScrollListener(binding.groupContactsList, binding.groupContactsToolbar)
group = intent.extras?.getSerializable(GROUP) as Group
group_contacts_toolbar.title = group.title
binding.groupContactsToolbar.title = group.title
group_contacts_fab.setOnClickListener {
binding.groupContactsFab.setOnClickListener {
if (wasInit) {
fabClicked()
}
}
group_contacts_placeholder_2.setOnClickListener {
binding.groupContactsPlaceholder2.setOnClickListener {
fabClicked()
}
val properPrimaryColor = getProperPrimaryColor()
group_contacts_fastscroller?.updateColors(properPrimaryColor)
group_contacts_placeholder_2.underlineText()
group_contacts_placeholder_2.setTextColor(properPrimaryColor)
binding.groupContactsFastscroller?.updateColors(properPrimaryColor)
binding.groupContactsPlaceholder2.underlineText()
binding.groupContactsPlaceholder2.setTextColor(properPrimaryColor)
}
override fun onResume() {
super.onResume()
refreshContacts()
setupToolbar(group_contacts_toolbar, NavigationIcon.Arrow)
(group_contacts_fab.layoutParams as CoordinatorLayout.LayoutParams).bottomMargin =
navigationBarHeight + resources.getDimension(R.dimen.activity_margin).toInt()
setupToolbar(binding.groupContactsToolbar, NavigationIcon.Arrow)
(binding.groupContactsFab.layoutParams as CoordinatorLayout.LayoutParams).bottomMargin =
navigationBarHeight + resources.getDimension(com.simplemobiletools.commons.R.dimen.activity_margin).toInt()
}
private fun setupOptionsMenu() {
group_contacts_toolbar.setOnMenuItemClickListener { menuItem ->
binding.groupContactsToolbar.setOnMenuItemClickListener { menuItem ->
when (menuItem.itemId) {
R.id.send_sms_to_group -> sendSMSToGroup()
R.id.send_email_to_group -> sendEmailToGroup()
@ -113,16 +114,16 @@ class GroupContactsActivity : SimpleActivity(), RemoveFromGroupListener, Refresh
allContacts = it
groupContacts = it.filter { it.groups.map { it.id }.contains(group.id) } as ArrayList<Contact>
group_contacts_placeholder_2.beVisibleIf(groupContacts.isEmpty())
group_contacts_placeholder.beVisibleIf(groupContacts.isEmpty())
group_contacts_fastscroller.beVisibleIf(groupContacts.isNotEmpty())
binding.groupContactsPlaceholder2.beVisibleIf(groupContacts.isEmpty())
binding.groupContactsPlaceholder.beVisibleIf(groupContacts.isEmpty())
binding.groupContactsFastscroller.beVisibleIf(groupContacts.isNotEmpty())
updateContacts(groupContacts)
}
}
private fun sendSMSToGroup() {
if (groupContacts.isEmpty()) {
toast(R.string.no_contacts_found)
toast(com.simplemobiletools.commons.R.string.no_contacts_found)
} else {
sendSMSToContacts(groupContacts)
}
@ -130,7 +131,7 @@ class GroupContactsActivity : SimpleActivity(), RemoveFromGroupListener, Refresh
private fun sendEmailToGroup() {
if (groupContacts.isEmpty()) {
toast(R.string.no_contacts_found)
toast(com.simplemobiletools.commons.R.string.no_contacts_found)
} else {
sendEmailToContacts(groupContacts)
}
@ -146,23 +147,23 @@ class GroupContactsActivity : SimpleActivity(), RemoveFromGroupListener, Refresh
}
private fun updateContacts(contacts: ArrayList<Contact>) {
val currAdapter = group_contacts_list.adapter
val currAdapter = binding.groupContactsList.adapter
if (currAdapter == null) {
ContactsAdapter(
this,
contactItems = contacts,
recyclerView = fragment_list,
recyclerView = binding.groupContactsList,
location = LOCATION_GROUP_CONTACTS,
removeListener = this,
refreshListener = this
) {
contactClicked(it as Contact)
}.apply {
group_contacts_list.adapter = this
binding.groupContactsList.adapter = this
}
if (areSystemAnimationsEnabled) {
group_contacts_list.scheduleLayoutAnimation()
binding.groupContactsList.scheduleLayoutAnimation()
}
} else {
(currAdapter as ContactsAdapter).updateItems(contacts)

View file

@ -8,14 +8,14 @@ import android.os.Bundle
import android.provider.ContactsContract
import android.provider.ContactsContract.CommonDataKinds.Email
import android.provider.ContactsContract.CommonDataKinds.Phone
import android.widget.ImageView
import android.widget.TextView
import androidx.viewpager.widget.ViewPager
import com.simplemobiletools.commons.databinding.BottomTablayoutItemBinding
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.commons.models.contacts.*
import com.simplemobiletools.commons.models.contacts.Contact
import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.contacts.pro.adapters.ViewPagerAdapter
import com.simplemobiletools.contacts.pro.databinding.ActivityInsertEditContactBinding
import com.simplemobiletools.contacts.pro.dialogs.ChangeSortingDialog
import com.simplemobiletools.contacts.pro.dialogs.FilterContactSourcesDialog
import com.simplemobiletools.contacts.pro.extensions.config
@ -24,16 +24,16 @@ import com.simplemobiletools.contacts.pro.helpers.ADD_NEW_CONTACT_NUMBER
import com.simplemobiletools.contacts.pro.helpers.KEY_EMAIL
import com.simplemobiletools.contacts.pro.helpers.KEY_NAME
import com.simplemobiletools.contacts.pro.interfaces.RefreshContactsListener
import kotlinx.android.synthetic.main.activity_insert_edit_contact.*
import kotlinx.android.synthetic.main.fragment_contacts.*
import kotlinx.android.synthetic.main.fragment_favorites.*
class InsertOrEditContactActivity : SimpleActivity(), RefreshContactsListener {
private val START_INSERT_ACTIVITY = 1
private val START_EDIT_ACTIVITY = 2
companion object {
private const val START_INSERT_ACTIVITY = 1
private const val START_EDIT_ACTIVITY = 2
}
private var isSelectContactIntent = false
private var specialMimeType: String? = null
private lateinit var binding: ActivityInsertEditContactBinding
private val contactsFavoritesList = arrayListOf(
TAB_CONTACTS,
@ -42,10 +42,11 @@ class InsertOrEditContactActivity : SimpleActivity(), RefreshContactsListener {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_insert_edit_contact)
binding = ActivityInsertEditContactBinding.inflate(layoutInflater)
setContentView(binding.root)
setupOptionsMenu()
isSelectContactIntent = intent.action == Intent.ACTION_PICK
updateMaterialActivityViews(insert_edit_coordinator, insert_edit_contact_holder, useTransparentNavigation = false, useTopSearchMenu = true)
updateMaterialActivityViews(binding.insertEditCoordinator, binding.insertEditContactHolder, useTransparentNavigation = false, useTopSearchMenu = true)
if (isSelectContactIntent) {
specialMimeType = when (intent.data) {
@ -55,8 +56,8 @@ class InsertOrEditContactActivity : SimpleActivity(), RefreshContactsListener {
}
}
new_contact_holder.beGoneIf(isSelectContactIntent)
select_contact_label.beGoneIf(isSelectContactIntent)
binding.newContactHolder.beGoneIf(isSelectContactIntent)
binding.selectContactLabel.beGoneIf(isSelectContactIntent)
if (checkAppSideloading()) {
return
@ -85,21 +86,21 @@ class InsertOrEditContactActivity : SimpleActivity(), RefreshContactsListener {
}
private fun setupOptionsMenu() {
insert_edit_menu.getToolbar().inflateMenu(R.menu.menu_insert_or_edit)
insert_edit_menu.toggleHideOnScroll(false)
insert_edit_menu.setupMenu()
binding.insertEditMenu.getToolbar().inflateMenu(R.menu.menu_insert_or_edit)
binding.insertEditMenu.toggleHideOnScroll(false)
binding.insertEditMenu.setupMenu()
insert_edit_menu.onSearchClosedListener = {
binding.insertEditMenu.onSearchClosedListener = {
getAllFragments().forEach {
it?.onSearchClosed()
}
}
insert_edit_menu.onSearchTextChangedListener = { text ->
binding.insertEditMenu.onSearchTextChangedListener = { text ->
getCurrentFragment()?.onSearchQueryChanged(text)
}
insert_edit_menu.getToolbar().setOnMenuItemClickListener { menuItem ->
binding.insertEditMenu.getToolbar().setOnMenuItemClickListener { menuItem ->
when (menuItem.itemId) {
R.id.sort -> showSortingDialog()
R.id.filter -> showFilterDialog()
@ -111,7 +112,7 @@ class InsertOrEditContactActivity : SimpleActivity(), RefreshContactsListener {
private fun updateMenuColors() {
updateStatusbarColor(getProperBackgroundColor())
insert_edit_menu.updateColors()
binding.insertEditMenu.updateColors()
}
override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) {
@ -123,99 +124,106 @@ class InsertOrEditContactActivity : SimpleActivity(), RefreshContactsListener {
}
override fun onBackPressed() {
if (insert_edit_menu.isSearchOpen) {
insert_edit_menu.closeSearch()
if (binding.insertEditMenu.isSearchOpen) {
binding.insertEditMenu.closeSearch()
} else {
super.onBackPressed()
}
}
private fun initFragments() {
view_pager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
binding.viewPager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
override fun onPageScrollStateChanged(state: Int) {}
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {}
override fun onPageSelected(position: Int) {
insert_edit_tabs_holder.getTabAt(position)?.select()
binding.insertEditTabsHolder.getTabAt(position)?.select()
getAllFragments().forEach {
it?.finishActMode()
}
}
})
view_pager.onGlobalLayout {
binding.viewPager.onGlobalLayout {
refreshContacts(getTabsMask())
}
select_contact_label?.setTextColor(getProperPrimaryColor())
new_contact_tmb?.setImageDrawable(resources.getColoredDrawableWithColor(R.drawable.ic_add_person_vector, getProperTextColor()))
new_contact_name.setTextColor(getProperTextColor())
new_contact_holder?.setOnClickListener {
binding.selectContactLabel?.setTextColor(getProperPrimaryColor())
binding.newContactTmb?.setImageDrawable(
resources.getColoredDrawableWithColor(
com.simplemobiletools.commons.R.drawable.ic_add_person_vector,
getProperTextColor()
)
)
binding.newContactName.setTextColor(getProperTextColor())
binding.newContactHolder.setOnClickListener {
createNewContact()
}
}
private fun setupTabs() {
insert_edit_tabs_holder.removeAllTabs()
binding.insertEditTabsHolder.removeAllTabs()
contactsFavoritesList.forEachIndexed { index, value ->
if (config.showTabs and value != 0) {
insert_edit_tabs_holder.newTab().setCustomView(R.layout.bottom_tablayout_item).apply {
customView?.findViewById<ImageView>(R.id.tab_item_icon)?.setImageDrawable(getTabIcon(index))
customView?.findViewById<TextView>(R.id.tab_item_label)?.text = getTabLabel(index)
insert_edit_tabs_holder.addTab(this)
binding.insertEditTabsHolder.newTab().setCustomView(com.simplemobiletools.commons.R.layout.bottom_tablayout_item).apply tab@{
customView?.let { BottomTablayoutItemBinding.bind(it) }?.apply {
tabItemIcon.setImageDrawable(getTabIcon(index))
tabItemLabel.text = getTabLabel(index)
binding.insertEditTabsHolder.addTab(this@tab)
}
}
}
}
insert_edit_tabs_holder.onTabSelectionChanged(
binding.insertEditTabsHolder.onTabSelectionChanged(
tabUnselectedAction = {
updateBottomTabItemColors(it.customView, false, getDeselectedTabDrawableIds()[it.position])
},
tabSelectedAction = {
insert_edit_menu.closeSearch()
view_pager.currentItem = it.position
binding.insertEditMenu.closeSearch()
binding.viewPager.currentItem = it.position
updateBottomTabItemColors(it.customView, true, getSelectedTabDrawableIds()[it.position])
}
)
insert_edit_tabs_holder.beGoneIf(insert_edit_tabs_holder.tabCount == 1)
binding.insertEditTabsHolder.beGoneIf(binding.insertEditTabsHolder.tabCount == 1)
}
private fun getCurrentFragment(): MyViewPagerFragment? {
return if (view_pager.currentItem == 0) {
contacts_fragment
private fun getCurrentFragment(): MyViewPagerFragment<*>? {
return if (binding.viewPager.currentItem == 0) {
findViewById(R.id.contacts_fragment)
} else {
favorites_fragment
findViewById(R.id.favorites_fragment)
}
}
private fun getAllFragments() = arrayListOf(contacts_fragment, favorites_fragment)
private fun getAllFragments() = arrayListOf<MyViewPagerFragment<*>>(findViewById(R.id.contacts_fragment), findViewById(R.id.favorites_fragment))
private fun setupTabColors() {
val activeView = insert_edit_tabs_holder.getTabAt(view_pager.currentItem)?.customView
updateBottomTabItemColors(activeView, true, getSelectedTabDrawableIds()[view_pager.currentItem])
val activeView = binding.insertEditTabsHolder.getTabAt(binding.viewPager.currentItem)?.customView
updateBottomTabItemColors(activeView, true, getSelectedTabDrawableIds()[binding.viewPager.currentItem])
getInactiveTabIndexes(view_pager.currentItem).forEach { index ->
val inactiveView = insert_edit_tabs_holder.getTabAt(index)?.customView
getInactiveTabIndexes(binding.viewPager.currentItem).forEach { index ->
val inactiveView = binding.insertEditTabsHolder.getTabAt(index)?.customView
updateBottomTabItemColors(inactiveView, false, getDeselectedTabDrawableIds()[index])
}
val bottomBarColor = getBottomNavigationBackgroundColor()
insert_edit_tabs_holder.setBackgroundColor(bottomBarColor)
binding.insertEditTabsHolder.setBackgroundColor(bottomBarColor)
updateNavigationBarColor(bottomBarColor)
}
private fun getInactiveTabIndexes(activeIndex: Int) = (0 until insert_edit_tabs_holder.tabCount).filter { it != activeIndex }
private fun getInactiveTabIndexes(activeIndex: Int) = (0 until binding.insertEditTabsHolder.tabCount).filter { it != activeIndex }
private fun getSelectedTabDrawableIds() = arrayOf(
R.drawable.ic_person_vector,
R.drawable.ic_star_vector
com.simplemobiletools.commons.R.drawable.ic_person_vector,
com.simplemobiletools.commons.R.drawable.ic_star_vector
)
private fun getDeselectedTabDrawableIds() = arrayOf(
R.drawable.ic_person_outline_vector,
R.drawable.ic_star_outline_vector
com.simplemobiletools.commons.R.drawable.ic_person_outline_vector,
com.simplemobiletools.commons.R.drawable.ic_star_outline_vector
)
override fun refreshContacts(refreshTabsMask: Int) {
@ -223,8 +231,8 @@ class InsertOrEditContactActivity : SimpleActivity(), RefreshContactsListener {
return
}
if (view_pager.adapter == null) {
view_pager.adapter = ViewPagerAdapter(this, contactsFavoritesList, getTabsMask())
if (binding.viewPager.adapter == null) {
binding.viewPager.adapter = ViewPagerAdapter(this, contactsFavoritesList, getTabsMask())
}
ContactsHelper(this).getContacts {
@ -252,13 +260,17 @@ class InsertOrEditContactActivity : SimpleActivity(), RefreshContactsListener {
}
if (refreshTabsMask and TAB_CONTACTS != 0) {
contacts_fragment?.skipHashComparing = true
contacts_fragment?.refreshContacts(contacts, placeholderText)
findViewById<MyViewPagerFragment<*>>(R.id.contacts_fragment)?.apply {
skipHashComparing = true
refreshContacts(contacts, placeholderText)
}
}
if (refreshTabsMask and TAB_FAVORITES != 0) {
favorites_fragment?.skipHashComparing = true
favorites_fragment?.refreshContacts(contacts, placeholderText)
findViewById<MyViewPagerFragment<*>>(R.id.favorites_fragment)?.apply {
skipHashComparing = true
refreshContacts(contacts, placeholderText)
}
}
}
}
@ -299,6 +311,7 @@ class InsertOrEditContactActivity : SimpleActivity(), RefreshContactsListener {
val contactId = ContactsHelper(this).getContactMimeTypeId(contact.id.toString(), specialMimeType!!)
Uri.withAppendedPath(ContactsContract.Data.CONTENT_URI, contactId)
}
else -> getContactPublicUri(contact)
}
}
@ -327,7 +340,7 @@ class InsertOrEditContactActivity : SimpleActivity(), RefreshContactsListener {
try {
startActivityForResult(this, START_INSERT_ACTIVITY)
} catch (e: ActivityNotFoundException) {
toast(R.string.no_app_found)
toast(com.simplemobiletools.commons.R.string.no_app_found)
} catch (e: Exception) {
showErrorToast(e)
}
@ -342,7 +355,7 @@ class InsertOrEditContactActivity : SimpleActivity(), RefreshContactsListener {
fun showFilterDialog() {
FilterContactSourcesDialog(this) {
contacts_fragment?.forceListRedraw = true
findViewById<MyViewPagerFragment<*>>(R.id.contacts_fragment)?.forceListRedraw = true
refreshContacts(getTabsMask())
}
}

View file

@ -10,11 +10,10 @@ import android.graphics.drawable.Icon
import android.graphics.drawable.LayerDrawable
import android.net.Uri
import android.os.Bundle
import android.widget.ImageView
import android.widget.TextView
import android.widget.Toast
import androidx.viewpager.widget.ViewPager
import com.simplemobiletools.commons.databases.ContactsDatabase
import com.simplemobiletools.commons.databinding.BottomTablayoutItemBinding
import com.simplemobiletools.commons.dialogs.ChangeViewTypeDialog
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
import com.simplemobiletools.commons.dialogs.FilePickerDialog
@ -28,6 +27,7 @@ import com.simplemobiletools.commons.models.contacts.Contact
import com.simplemobiletools.contacts.pro.BuildConfig
import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.contacts.pro.adapters.ViewPagerAdapter
import com.simplemobiletools.contacts.pro.databinding.ActivityMainBinding
import com.simplemobiletools.contacts.pro.dialogs.ChangeSortingDialog
import com.simplemobiletools.contacts.pro.dialogs.ExportContactsDialog
import com.simplemobiletools.contacts.pro.dialogs.FilterContactSourcesDialog
@ -40,18 +40,16 @@ import com.simplemobiletools.contacts.pro.helpers.ALL_TABS_MASK
import com.simplemobiletools.contacts.pro.helpers.VcfExporter
import com.simplemobiletools.contacts.pro.helpers.tabsList
import com.simplemobiletools.contacts.pro.interfaces.RefreshContactsListener
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.fragment_contacts.*
import kotlinx.android.synthetic.main.fragment_favorites.*
import kotlinx.android.synthetic.main.fragment_groups.*
import me.grantland.widget.AutofitHelper
import java.io.FileOutputStream
import java.io.OutputStream
import java.util.*
class MainActivity : SimpleActivity(), RefreshContactsListener {
private val PICK_IMPORT_SOURCE_INTENT = 1
private val PICK_EXPORT_FILE_INTENT = 2
companion object {
private const val PICK_IMPORT_SOURCE_INTENT = 1
private const val PICK_EXPORT_FILE_INTENT = 2
}
private var werePermissionsHandled = false
private var isFirstResume = true
@ -63,22 +61,24 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
private var storedStartNameWithSurname = false
private var storedFontSize = 0
private var storedShowTabs = 0
private lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
appLaunched(BuildConfig.APPLICATION_ID)
setupOptionsMenu()
refreshMenuItems()
updateMaterialActivityViews(main_coordinator, main_holder, useTransparentNavigation = false, useTopSearchMenu = true)
updateMaterialActivityViews(binding.mainCoordinator, binding.mainHolder, useTransparentNavigation = false, useTopSearchMenu = true)
storeStateVariables()
setupTabs()
checkContactPermissions()
checkWhatsNewDialog()
if (isPackageInstalled("com.simplemobiletools.contacts")) {
val dialogText = getString(R.string.upgraded_from_free_contacts, getString(R.string.phone_storage_hidden))
ConfirmationDialog(this, dialogText, 0, R.string.ok, 0, false) {}
val dialogText = getString(com.simplemobiletools.commons.R.string.upgraded_from_free_contacts, getString(R.string.phone_storage_hidden))
ConfirmationDialog(this, dialogText, 0, com.simplemobiletools.commons.R.string.ok, 0, false) {}
}
}
@ -119,8 +119,8 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
}
val properPrimaryColor = getProperPrimaryColor()
main_tabs_holder.background = ColorDrawable(getProperBackgroundColor())
main_tabs_holder.setSelectedTabIndicatorColor(properPrimaryColor)
binding.mainTabsHolder.background = ColorDrawable(getProperBackgroundColor())
binding.mainTabsHolder.setSelectedTabIndicatorColor(properPrimaryColor)
getAllFragments().forEach {
it?.setupColors(getProperTextColor(), properPrimaryColor)
}
@ -130,8 +130,8 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
val configStartNameWithSurname = config.startNameWithSurname
if (storedStartNameWithSurname != configStartNameWithSurname) {
contacts_fragment?.startNameWithSurnameChanged(configStartNameWithSurname)
favorites_fragment?.startNameWithSurnameChanged(configStartNameWithSurname)
findViewById<MyViewPagerFragment<*>>(R.id.contacts_fragment)?.startNameWithSurnameChanged(configStartNameWithSurname)
findViewById<MyViewPagerFragment<*>>(R.id.favorites_fragment)?.startNameWithSurnameChanged(configStartNameWithSurname)
}
val configFontSize = config.fontSize
@ -142,15 +142,16 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
}
if (werePermissionsHandled && !isFirstResume) {
if (view_pager.adapter == null) {
if (binding.viewPager.adapter == null) {
initFragments()
} else {
refreshContacts(ALL_TABS_MASK)
}
}
val dialpadIcon = resources.getColoredDrawableWithColor(R.drawable.ic_dialpad_vector, properPrimaryColor.getContrastColor())
main_dialpad_button.apply {
val dialpadIcon =
resources.getColoredDrawableWithColor(com.simplemobiletools.commons.R.drawable.ic_dialpad_vector, properPrimaryColor.getContrastColor())
binding.mainDialpadButton.apply {
setImageDrawable(dialpadIcon)
background.applyColorFilter(properPrimaryColor)
beVisibleIf(config.showDialpadButton)
@ -163,7 +164,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
override fun onPause() {
super.onPause()
storeStateVariables()
config.lastUsedViewPagerPage = view_pager.currentItem
config.lastUsedViewPagerPage = binding.viewPager.currentItem
}
override fun onDestroy() {
@ -188,8 +189,8 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
}
override fun onBackPressed() {
if (main_menu.isSearchOpen) {
main_menu.closeSearch()
if (binding.mainMenu.isSearchOpen) {
binding.mainMenu.closeSearch()
} else {
super.onBackPressed()
}
@ -197,32 +198,32 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
private fun refreshMenuItems() {
val currentFragment = getCurrentFragment()
main_menu.getToolbar().menu.apply {
findItem(R.id.sort).isVisible = currentFragment != groups_fragment
findItem(R.id.filter).isVisible = currentFragment != groups_fragment
binding.mainMenu.getToolbar().menu.apply {
findItem(R.id.sort).isVisible = currentFragment != findViewById(R.id.groups_fragment)
findItem(R.id.filter).isVisible = currentFragment != findViewById(R.id.groups_fragment)
findItem(R.id.dialpad).isVisible = !config.showDialpadButton
findItem(R.id.change_view_type).isVisible = currentFragment == favorites_fragment
findItem(R.id.column_count).isVisible = currentFragment == favorites_fragment && config.viewType == VIEW_TYPE_GRID
findItem(R.id.more_apps_from_us).isVisible = !resources.getBoolean(R.bool.hide_google_relations)
findItem(R.id.change_view_type).isVisible = currentFragment == findViewById(R.id.favorites_fragment)
findItem(R.id.column_count).isVisible = currentFragment == findViewById(R.id.favorites_fragment) && config.viewType == VIEW_TYPE_GRID
findItem(R.id.more_apps_from_us).isVisible = !resources.getBoolean(com.simplemobiletools.commons.R.bool.hide_google_relations)
}
}
private fun setupOptionsMenu() {
main_menu.getToolbar().inflateMenu(R.menu.menu)
main_menu.toggleHideOnScroll(false)
main_menu.setupMenu()
binding.mainMenu.getToolbar().inflateMenu(R.menu.menu)
binding.mainMenu.toggleHideOnScroll(false)
binding.mainMenu.setupMenu()
main_menu.onSearchClosedListener = {
binding.mainMenu.onSearchClosedListener = {
getAllFragments().forEach {
it?.onSearchClosed()
}
}
main_menu.onSearchTextChangedListener = { text ->
binding.mainMenu.onSearchTextChangedListener = { text ->
getCurrentFragment()?.onSearchQueryChanged(text)
}
main_menu.getToolbar().setOnMenuItemClickListener { menuItem ->
binding.mainMenu.getToolbar().setOnMenuItemClickListener { menuItem ->
when (menuItem.itemId) {
R.id.sort -> showSortingDialog(showCustomSorting = getCurrentFragment() is FavoritesFragment)
R.id.filter -> showFilterDialog()
@ -243,14 +244,14 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
private fun changeViewType() {
ChangeViewTypeDialog(this) {
refreshMenuItems()
favorites_fragment?.updateFavouritesAdapter()
findViewById<FavoritesFragment>(R.id.favorites_fragment)?.updateFavouritesAdapter()
}
}
private fun changeColumnCount() {
val items = ArrayList<RadioItem>()
for (i in 1..CONTACTS_GRID_MAX_COLUMNS_COUNT) {
items.add(RadioItem(i, resources.getQuantityString(R.plurals.column_counts, i, i)))
items.add(RadioItem(i, resources.getQuantityString(com.simplemobiletools.commons.R.plurals.column_counts, i, i)))
}
val currentColumnCount = config.contactsGridColumnCount
@ -258,14 +259,14 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
val newColumnCount = it as Int
if (currentColumnCount != newColumnCount) {
config.contactsGridColumnCount = newColumnCount
favorites_fragment?.columnCountChanged()
findViewById<FavoritesFragment>(R.id.favorites_fragment)?.columnCountChanged()
}
}
}
private fun updateMenuColors() {
updateStatusbarColor(getProperBackgroundColor())
main_menu.updateColors()
binding.mainMenu.updateColors()
}
private fun storeStateVariables() {
@ -294,9 +295,9 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
@SuppressLint("NewApi")
private fun getCreateNewContactShortcut(appIconColor: Int): ShortcutInfo {
val newEvent = getString(R.string.create_new_contact)
val drawable = resources.getDrawable(R.drawable.shortcut_plus)
(drawable as LayerDrawable).findDrawableByLayerId(R.id.shortcut_plus_background).applyColorFilter(appIconColor)
val newEvent = getString(com.simplemobiletools.commons.R.string.create_new_contact)
val drawable = resources.getDrawable(com.simplemobiletools.commons.R.drawable.shortcut_plus)
(drawable as LayerDrawable).findDrawableByLayerId(com.simplemobiletools.commons.R.id.shortcut_plus_background).applyColorFilter(appIconColor)
val bmp = drawable.convertToBitmap()
val intent = Intent(this, EditContactActivity::class.java)
@ -309,54 +310,54 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
.build()
}
private fun getCurrentFragment(): MyViewPagerFragment? {
private fun getCurrentFragment(): MyViewPagerFragment<*>? {
val showTabs = config.showTabs
val fragments = arrayListOf<MyViewPagerFragment>()
val fragments = arrayListOf<MyViewPagerFragment<*>>()
if (showTabs and TAB_CONTACTS != 0) {
fragments.add(contacts_fragment)
fragments.add(findViewById(R.id.contacts_fragment))
}
if (showTabs and TAB_FAVORITES != 0) {
fragments.add(favorites_fragment)
fragments.add(findViewById(R.id.favorites_fragment))
}
if (showTabs and TAB_GROUPS != 0) {
fragments.add(groups_fragment)
fragments.add(findViewById(R.id.groups_fragment))
}
return fragments.getOrNull(view_pager.currentItem)
return fragments.getOrNull(binding.viewPager.currentItem)
}
private fun setupTabColors() {
val activeView = main_tabs_holder.getTabAt(view_pager.currentItem)?.customView
updateBottomTabItemColors(activeView, true, getSelectedTabDrawableIds()[view_pager.currentItem])
val activeView = binding.mainTabsHolder.getTabAt(binding.viewPager.currentItem)?.customView
updateBottomTabItemColors(activeView, true, getSelectedTabDrawableIds()[binding.viewPager.currentItem])
getInactiveTabIndexes(view_pager.currentItem).forEach { index ->
val inactiveView = main_tabs_holder.getTabAt(index)?.customView
getInactiveTabIndexes(binding.viewPager.currentItem).forEach { index ->
val inactiveView = binding.mainTabsHolder.getTabAt(index)?.customView
updateBottomTabItemColors(inactiveView, false, getDeselectedTabDrawableIds()[index])
}
val bottomBarColor = getBottomNavigationBackgroundColor()
main_tabs_holder.setBackgroundColor(bottomBarColor)
binding.mainTabsHolder.setBackgroundColor(bottomBarColor)
updateNavigationBarColor(bottomBarColor)
}
private fun getInactiveTabIndexes(activeIndex: Int) = (0 until main_tabs_holder.tabCount).filter { it != activeIndex }
private fun getInactiveTabIndexes(activeIndex: Int) = (0 until binding.mainTabsHolder.tabCount).filter { it != activeIndex }
private fun getSelectedTabDrawableIds(): ArrayList<Int> {
val showTabs = config.showTabs
val icons = ArrayList<Int>()
if (showTabs and TAB_CONTACTS != 0) {
icons.add(R.drawable.ic_person_vector)
icons.add(com.simplemobiletools.commons.R.drawable.ic_person_vector)
}
if (showTabs and TAB_FAVORITES != 0) {
icons.add(R.drawable.ic_star_vector)
icons.add(com.simplemobiletools.commons.R.drawable.ic_star_vector)
}
if (showTabs and TAB_GROUPS != 0) {
icons.add(R.drawable.ic_people_vector)
icons.add(com.simplemobiletools.commons.R.drawable.ic_people_vector)
}
return icons
@ -367,29 +368,29 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
val icons = ArrayList<Int>()
if (showTabs and TAB_CONTACTS != 0) {
icons.add(R.drawable.ic_person_outline_vector)
icons.add(com.simplemobiletools.commons.R.drawable.ic_person_outline_vector)
}
if (showTabs and TAB_FAVORITES != 0) {
icons.add(R.drawable.ic_star_outline_vector)
icons.add(com.simplemobiletools.commons.R.drawable.ic_star_outline_vector)
}
if (showTabs and TAB_GROUPS != 0) {
icons.add(R.drawable.ic_people_outline_vector)
icons.add(com.simplemobiletools.commons.R.drawable.ic_people_outline_vector)
}
return icons
}
private fun initFragments() {
view_pager.offscreenPageLimit = tabsList.size - 1
view_pager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
binding.viewPager.offscreenPageLimit = tabsList.size - 1
binding.viewPager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
override fun onPageScrollStateChanged(state: Int) {}
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {}
override fun onPageSelected(position: Int) {
main_tabs_holder.getTabAt(position)?.select()
binding.mainTabsHolder.getTabAt(position)?.select()
getAllFragments().forEach {
it?.finishActMode()
}
@ -397,7 +398,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
}
})
view_pager.onGlobalLayout {
binding.viewPager.onGlobalLayout {
refreshContacts(ALL_TABS_MASK)
refreshMenuItems()
}
@ -407,36 +408,38 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
intent.data = null
}
main_dialpad_button.setOnClickListener {
binding.mainDialpadButton.setOnClickListener {
launchDialpad()
}
}
private fun setupTabs() {
main_tabs_holder.removeAllTabs()
binding.mainTabsHolder.removeAllTabs()
tabsList.forEachIndexed { index, value ->
if (config.showTabs and value != 0) {
main_tabs_holder.newTab().setCustomView(R.layout.bottom_tablayout_item).apply {
customView?.findViewById<ImageView>(R.id.tab_item_icon)?.setImageDrawable(getTabIcon(index))
customView?.findViewById<TextView>(R.id.tab_item_label)?.text = getTabLabel(index)
AutofitHelper.create(customView?.findViewById(R.id.tab_item_label))
main_tabs_holder.addTab(this)
binding.mainTabsHolder.newTab().setCustomView(com.simplemobiletools.commons.R.layout.bottom_tablayout_item).apply tab@{
customView?.let { BottomTablayoutItemBinding.bind(it) }?.apply {
tabItemIcon.setImageDrawable(getTabIcon(index))
tabItemLabel.text = getTabLabel(index)
AutofitHelper.create(tabItemLabel)
binding.mainTabsHolder.addTab(this@tab)
}
}
}
}
main_tabs_holder.onTabSelectionChanged(
binding.mainTabsHolder.onTabSelectionChanged(
tabUnselectedAction = {
updateBottomTabItemColors(it.customView, false, getDeselectedTabDrawableIds()[it.position])
},
tabSelectedAction = {
main_menu.closeSearch()
view_pager.currentItem = it.position
binding.mainMenu.closeSearch()
binding.viewPager.currentItem = it.position
updateBottomTabItemColors(it.customView, true, getSelectedTabDrawableIds()[it.position])
}
)
main_tabs_holder.beGoneIf(main_tabs_holder.tabCount == 1)
binding.mainTabsHolder.beGoneIf(binding.mainTabsHolder.tabCount == 1)
}
private fun showSortingDialog(showCustomSorting: Boolean) {
@ -447,7 +450,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
fun showFilterDialog() {
FilterContactSourcesDialog(this) {
contacts_fragment?.forceListRedraw = true
findViewById<MyViewPagerFragment<*>>(R.id.contacts_fragment)?.forceListRedraw = true
refreshContacts(TAB_CONTACTS or TAB_FAVORITES)
}
}
@ -458,7 +461,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
try {
startActivity(this)
} catch (e: ActivityNotFoundException) {
toast(R.string.no_app_found)
toast(com.simplemobiletools.commons.R.string.no_app_found)
} catch (e: Exception) {
showErrorToast(e)
}
@ -474,7 +477,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
try {
startActivityForResult(this, PICK_IMPORT_SOURCE_INTENT)
} catch (e: ActivityNotFoundException) {
toast(R.string.system_service_disabled, Toast.LENGTH_LONG)
toast(com.simplemobiletools.commons.R.string.system_service_disabled, Toast.LENGTH_LONG)
} catch (e: Exception) {
showErrorToast(e)
}
@ -510,7 +513,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
uri.scheme == "content" -> {
val tempFile = getTempFile()
if (tempFile == null) {
toast(R.string.unknown_error_occurred)
toast(com.simplemobiletools.commons.R.string.unknown_error_occurred)
return
}
@ -523,7 +526,8 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
showErrorToast(e)
}
}
else -> toast(R.string.invalid_file_format)
else -> toast(com.simplemobiletools.commons.R.string.invalid_file_format)
}
}
@ -540,7 +544,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
try {
startActivityForResult(this, PICK_EXPORT_FILE_INTENT)
} catch (e: ActivityNotFoundException) {
toast(R.string.no_app_found, Toast.LENGTH_LONG)
toast(com.simplemobiletools.commons.R.string.no_app_found, Toast.LENGTH_LONG)
} catch (e: Exception) {
showErrorToast(e)
}
@ -562,14 +566,14 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
private fun exportContactsTo(ignoredContactSources: HashSet<String>, outputStream: OutputStream?) {
ContactsHelper(this).getContacts(true, false, ignoredContactSources) { contacts ->
if (contacts.isEmpty()) {
toast(R.string.no_entries_for_exporting)
toast(com.simplemobiletools.commons.R.string.no_entries_for_exporting)
} else {
VcfExporter().exportContacts(this, outputStream, contacts, true) { result ->
toast(
when (result) {
VcfExporter.ExportResult.EXPORT_OK -> R.string.exporting_successful
VcfExporter.ExportResult.EXPORT_PARTIAL -> R.string.exporting_some_entries_failed
else -> R.string.exporting_failed
VcfExporter.ExportResult.EXPORT_OK -> com.simplemobiletools.commons.R.string.exporting_successful
VcfExporter.ExportResult.EXPORT_PARTIAL -> com.simplemobiletools.commons.R.string.exporting_some_entries_failed
else -> com.simplemobiletools.commons.R.string.exporting_failed
}
)
}
@ -587,13 +591,13 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
val faqItems = arrayListOf(
FAQItem(R.string.faq_1_title, R.string.faq_1_text),
FAQItem(R.string.faq_9_title_commons, R.string.faq_9_text_commons)
FAQItem(com.simplemobiletools.commons.R.string.faq_9_title_commons, com.simplemobiletools.commons.R.string.faq_9_text_commons)
)
if (!resources.getBoolean(R.bool.hide_google_relations)) {
faqItems.add(FAQItem(R.string.faq_2_title_commons, R.string.faq_2_text_commons))
faqItems.add(FAQItem(R.string.faq_6_title_commons, R.string.faq_6_text_commons))
faqItems.add(FAQItem(R.string.faq_7_title_commons, R.string.faq_7_text_commons))
if (!resources.getBoolean(com.simplemobiletools.commons.R.bool.hide_google_relations)) {
faqItems.add(FAQItem(com.simplemobiletools.commons.R.string.faq_2_title_commons, com.simplemobiletools.commons.R.string.faq_2_text_commons))
faqItems.add(FAQItem(com.simplemobiletools.commons.R.string.faq_6_title_commons, com.simplemobiletools.commons.R.string.faq_6_text_commons))
faqItems.add(FAQItem(com.simplemobiletools.commons.R.string.faq_7_title_commons, com.simplemobiletools.commons.R.string.faq_7_text_commons))
}
startAboutActivity(R.string.app_name, licenses, BuildConfig.VERSION_NAME, faqItems, true)
@ -606,9 +610,9 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
isGettingContacts = true
if (view_pager.adapter == null) {
view_pager.adapter = ViewPagerAdapter(this, tabsList, config.showTabs)
view_pager.currentItem = getDefaultTab()
if (binding.viewPager.adapter == null) {
binding.viewPager.adapter = ViewPagerAdapter(this, tabsList, config.showTabs)
binding.viewPager.currentItem = getDefaultTab()
}
ContactsHelper(this).getContacts { contacts ->
@ -618,24 +622,30 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
}
if (refreshTabsMask and TAB_CONTACTS != 0) {
contacts_fragment?.skipHashComparing = true
contacts_fragment?.refreshContacts(contacts)
findViewById<MyViewPagerFragment<*>>(R.id.contacts_fragment)?.apply {
skipHashComparing = true
refreshContacts(contacts)
}
}
if (refreshTabsMask and TAB_FAVORITES != 0) {
favorites_fragment?.skipHashComparing = true
favorites_fragment?.refreshContacts(contacts)
findViewById<MyViewPagerFragment<*>>(R.id.favorites_fragment)?.apply {
skipHashComparing = true
refreshContacts(contacts)
}
}
if (refreshTabsMask and TAB_GROUPS != 0) {
if (refreshTabsMask == TAB_GROUPS) {
groups_fragment.skipHashComparing = true
findViewById<MyViewPagerFragment<*>>(R.id.groups_fragment)?.apply {
if (refreshTabsMask == TAB_GROUPS) {
skipHashComparing = true
}
refreshContacts(contacts)
}
groups_fragment?.refreshContacts(contacts)
}
if (main_menu.isSearchOpen) {
getCurrentFragment()?.onSearchQueryChanged(main_menu.getCurrentQuery())
if (binding.mainMenu.isSearchOpen) {
getCurrentFragment()?.onSearchQueryChanged(binding.mainMenu.getCurrentQuery())
}
}
}
@ -644,7 +654,11 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
handleGenericContactClick(contact)
}
private fun getAllFragments() = arrayListOf(contacts_fragment, favorites_fragment, groups_fragment)
private fun getAllFragments() = arrayListOf<MyViewPagerFragment<*>?>(
findViewById(R.id.contacts_fragment),
findViewById(R.id.favorites_fragment),
findViewById(R.id.groups_fragment)
)
private fun getDefaultTab(): Int {
val showTabsMask = config.showTabs

View file

@ -6,29 +6,32 @@ import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.commons.models.RadioItem
import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.contacts.pro.databinding.ActivitySettingsBinding
import com.simplemobiletools.contacts.pro.dialogs.ManageAutoBackupsDialog
import com.simplemobiletools.contacts.pro.dialogs.ManageVisibleFieldsDialog
import com.simplemobiletools.contacts.pro.dialogs.ManageVisibleTabsDialog
import com.simplemobiletools.contacts.pro.extensions.cancelScheduledAutomaticBackup
import com.simplemobiletools.contacts.pro.extensions.config
import com.simplemobiletools.contacts.pro.extensions.scheduleNextAutomaticBackup
import kotlinx.android.synthetic.main.activity_settings.*
import java.util.Locale
import kotlin.system.exitProcess
class SettingsActivity : SimpleActivity() {
private lateinit var binding: ActivitySettingsBinding
override fun onCreate(savedInstanceState: Bundle?) {
isMaterialActivity = true
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_settings)
updateMaterialActivityViews(settings_coordinator, settings_holder, useTransparentNavigation = true, useTopSearchMenu = false)
setupMaterialScrollListener(settings_nested_scrollview, settings_toolbar)
binding = ActivitySettingsBinding.inflate(layoutInflater)
setContentView(binding.root)
updateMaterialActivityViews(binding.settingsCoordinator, binding.settingsHolder, useTransparentNavigation = true, useTopSearchMenu = false)
setupMaterialScrollListener(binding.settingsNestedScrollview, binding.settingsToolbar)
}
override fun onResume() {
super.onResume()
setupToolbar(settings_toolbar, NavigationIcon.Arrow)
setupToolbar(binding.settingsToolbar, NavigationIcon.Arrow)
setupCustomizeColors()
setupManageShownContactFields()
@ -48,149 +51,149 @@ class SettingsActivity : SimpleActivity() {
setupDefaultTab()
setupEnableAutomaticBackups()
setupManageAutomaticBackups()
updateTextColors(settings_holder)
updateTextColors(binding.settingsHolder)
arrayOf(
settings_color_customization_section_label,
settings_general_settings_label,
settings_main_screen_label,
settings_list_view_label,
settings_backups_label
binding.settingsColorCustomizationSectionLabel,
binding.settingsGeneralSettingsLabel,
binding.settingsMainScreenLabel,
binding.settingsListViewLabel,
binding.settingsBackupsLabel
).forEach {
it.setTextColor(getProperPrimaryColor())
}
}
private fun setupCustomizeColors() {
settings_color_customization_holder.setOnClickListener {
binding.settingsColorCustomizationHolder.setOnClickListener {
startCustomizationActivity()
}
}
private fun setupManageShownContactFields() {
settings_manage_contact_fields_holder.setOnClickListener {
binding.settingsManageContactFieldsHolder.setOnClickListener {
ManageVisibleFieldsDialog(this) {}
}
}
private fun setupManageShownTabs() {
settings_manage_shown_tabs_holder.setOnClickListener {
binding.settingsManageShownTabsHolder.setOnClickListener {
ManageVisibleTabsDialog(this)
}
}
private fun setupDefaultTab() {
settings_default_tab.text = getDefaultTabText()
settings_default_tab_holder.setOnClickListener {
binding.settingsDefaultTab.text = getDefaultTabText()
binding.settingsDefaultTabHolder.setOnClickListener {
val items = arrayListOf(
RadioItem(TAB_CONTACTS, getString(R.string.contacts_tab)),
RadioItem(TAB_FAVORITES, getString(R.string.favorites_tab)),
RadioItem(TAB_GROUPS, getString(R.string.groups_tab)),
RadioItem(TAB_LAST_USED, getString(R.string.last_used_tab))
RadioItem(TAB_CONTACTS, getString(com.simplemobiletools.commons.R.string.contacts_tab)),
RadioItem(TAB_FAVORITES, getString(com.simplemobiletools.commons.R.string.favorites_tab)),
RadioItem(TAB_GROUPS, getString(com.simplemobiletools.commons.R.string.groups_tab)),
RadioItem(TAB_LAST_USED, getString(com.simplemobiletools.commons.R.string.last_used_tab))
)
RadioGroupDialog(this@SettingsActivity, items, config.defaultTab) {
config.defaultTab = it as Int
settings_default_tab.text = getDefaultTabText()
binding.settingsDefaultTab.text = getDefaultTabText()
}
}
}
private fun getDefaultTabText() = getString(
when (baseConfig.defaultTab) {
TAB_CONTACTS -> R.string.contacts_tab
TAB_FAVORITES -> R.string.favorites_tab
TAB_GROUPS -> R.string.groups_tab
else -> R.string.last_used_tab
TAB_CONTACTS -> com.simplemobiletools.commons.R.string.contacts_tab
TAB_FAVORITES -> com.simplemobiletools.commons.R.string.favorites_tab
TAB_GROUPS -> com.simplemobiletools.commons.R.string.groups_tab
else -> com.simplemobiletools.commons.R.string.last_used_tab
}
)
private fun setupFontSize() {
settings_font_size.text = getFontSizeText()
settings_font_size_holder.setOnClickListener {
binding.settingsFontSize.text = getFontSizeText()
binding.settingsFontSizeHolder.setOnClickListener {
val items = arrayListOf(
RadioItem(FONT_SIZE_SMALL, getString(R.string.small)),
RadioItem(FONT_SIZE_MEDIUM, getString(R.string.medium)),
RadioItem(FONT_SIZE_LARGE, getString(R.string.large)),
RadioItem(FONT_SIZE_EXTRA_LARGE, getString(R.string.extra_large))
RadioItem(FONT_SIZE_SMALL, getString(com.simplemobiletools.commons.R.string.small)),
RadioItem(FONT_SIZE_MEDIUM, getString(com.simplemobiletools.commons.R.string.medium)),
RadioItem(FONT_SIZE_LARGE, getString(com.simplemobiletools.commons.R.string.large)),
RadioItem(FONT_SIZE_EXTRA_LARGE, getString(com.simplemobiletools.commons.R.string.extra_large))
)
RadioGroupDialog(this@SettingsActivity, items, config.fontSize) {
config.fontSize = it as Int
settings_font_size.text = getFontSizeText()
binding.settingsFontSize.text = getFontSizeText()
}
}
}
private fun setupUseEnglish() {
settings_use_english_holder.beVisibleIf((config.wasUseEnglishToggled || Locale.getDefault().language != "en") && !isTiramisuPlus())
settings_use_english.isChecked = config.useEnglish
settings_use_english_holder.setOnClickListener {
settings_use_english.toggle()
config.useEnglish = settings_use_english.isChecked
binding.settingsUseEnglishHolder.beVisibleIf((config.wasUseEnglishToggled || Locale.getDefault().language != "en") && !isTiramisuPlus())
binding.settingsUseEnglish.isChecked = config.useEnglish
binding.settingsUseEnglishHolder.setOnClickListener {
binding.settingsUseEnglish.toggle()
config.useEnglish = binding.settingsUseEnglish.isChecked
exitProcess(0)
}
}
private fun setupLanguage() {
settings_language.text = Locale.getDefault().displayLanguage
settings_language_holder.beVisibleIf(isTiramisuPlus())
settings_language_holder.setOnClickListener {
binding.settingsLanguage.text = Locale.getDefault().displayLanguage
binding.settingsLanguageHolder.beVisibleIf(isTiramisuPlus())
binding.settingsLanguageHolder.setOnClickListener {
launchChangeAppLanguageIntent()
}
}
private fun setupShowContactThumbnails() {
settings_show_contact_thumbnails.isChecked = config.showContactThumbnails
settings_show_contact_thumbnails_holder.setOnClickListener {
settings_show_contact_thumbnails.toggle()
config.showContactThumbnails = settings_show_contact_thumbnails.isChecked
binding.settingsShowContactThumbnails.isChecked = config.showContactThumbnails
binding.settingsShowContactThumbnailsHolder.setOnClickListener {
binding.settingsShowContactThumbnails.toggle()
config.showContactThumbnails = binding.settingsShowContactThumbnails.isChecked
}
}
private fun setupShowPhoneNumbers() {
settings_show_phone_numbers.isChecked = config.showPhoneNumbers
settings_show_phone_numbers_holder.setOnClickListener {
settings_show_phone_numbers.toggle()
config.showPhoneNumbers = settings_show_phone_numbers.isChecked
binding.settingsShowPhoneNumbers.isChecked = config.showPhoneNumbers
binding.settingsShowPhoneNumbersHolder.setOnClickListener {
binding.settingsShowPhoneNumbers.toggle()
config.showPhoneNumbers = binding.settingsShowPhoneNumbers.isChecked
}
}
private fun setupShowContactsWithNumbers() {
settings_show_only_contacts_with_numbers.isChecked = config.showOnlyContactsWithNumbers
settings_show_only_contacts_with_numbers_holder.setOnClickListener {
settings_show_only_contacts_with_numbers.toggle()
config.showOnlyContactsWithNumbers = settings_show_only_contacts_with_numbers.isChecked
binding.settingsShowOnlyContactsWithNumbers.isChecked = config.showOnlyContactsWithNumbers
binding.settingsShowOnlyContactsWithNumbersHolder.setOnClickListener {
binding.settingsShowOnlyContactsWithNumbers.toggle()
config.showOnlyContactsWithNumbers = binding.settingsShowOnlyContactsWithNumbers.isChecked
}
}
private fun setupStartNameWithSurname() {
settings_start_name_with_surname.isChecked = config.startNameWithSurname
settings_start_name_with_surname_holder.setOnClickListener {
settings_start_name_with_surname.toggle()
config.startNameWithSurname = settings_start_name_with_surname.isChecked
binding.settingsStartNameWithSurname.isChecked = config.startNameWithSurname
binding.settingsStartNameWithSurnameHolder.setOnClickListener {
binding.settingsStartNameWithSurname.toggle()
config.startNameWithSurname = binding.settingsStartNameWithSurname.isChecked
}
}
private fun setupShowDialpadButton() {
settings_show_dialpad_button.isChecked = config.showDialpadButton
settings_show_dialpad_button_holder.setOnClickListener {
settings_show_dialpad_button.toggle()
config.showDialpadButton = settings_show_dialpad_button.isChecked
binding.settingsShowDialpadButton.isChecked = config.showDialpadButton
binding.settingsShowDialpadButtonHolder.setOnClickListener {
binding.settingsShowDialpadButton.toggle()
config.showDialpadButton = binding.settingsShowDialpadButton.isChecked
}
}
private fun setupShowPrivateContacts() {
settings_show_private_contacts.isChecked = config.showPrivateContacts
settings_show_private_contacts_holder.setOnClickListener {
settings_show_private_contacts.toggle()
config.showPrivateContacts = settings_show_private_contacts.isChecked
binding.settingsShowPrivateContacts.isChecked = config.showPrivateContacts
binding.settingsShowPrivateContactsHolder.setOnClickListener {
binding.settingsShowPrivateContacts.toggle()
config.showPrivateContacts = binding.settingsShowPrivateContacts.isChecked
}
}
private fun setupOnContactClick() {
settings_on_contact_click.text = getOnContactClickText()
settings_on_contact_click_holder.setOnClickListener {
binding.settingsOnContactClick.text = getOnContactClickText()
binding.settingsOnContactClickHolder.setOnClickListener {
val items = arrayListOf(
RadioItem(ON_CLICK_CALL_CONTACT, getString(R.string.call_contact)),
RadioItem(ON_CLICK_VIEW_CONTACT, getString(R.string.view_contact)),
@ -199,7 +202,7 @@ class SettingsActivity : SimpleActivity() {
RadioGroupDialog(this@SettingsActivity, items, config.onContactClick) {
config.onContactClick = it as Int
settings_on_contact_click.text = getOnContactClickText()
binding.settingsOnContactClick.text = getOnContactClickText()
}
}
}
@ -213,26 +216,26 @@ class SettingsActivity : SimpleActivity() {
)
private fun setupShowCallConfirmation() {
settings_show_call_confirmation.isChecked = config.showCallConfirmation
settings_show_call_confirmation_holder.setOnClickListener {
settings_show_call_confirmation.toggle()
config.showCallConfirmation = settings_show_call_confirmation.isChecked
binding.settingsShowCallConfirmation.isChecked = config.showCallConfirmation
binding.settingsShowCallConfirmationHolder.setOnClickListener {
binding.settingsShowCallConfirmation.toggle()
config.showCallConfirmation = binding.settingsShowCallConfirmation.isChecked
}
}
private fun setupMergeDuplicateContacts() {
settings_merge_duplicate_contacts.isChecked = config.mergeDuplicateContacts
settings_merge_duplicate_contacts_holder.setOnClickListener {
settings_merge_duplicate_contacts.toggle()
config.mergeDuplicateContacts = settings_merge_duplicate_contacts.isChecked
binding.settingsMergeDuplicateContacts.isChecked = config.mergeDuplicateContacts
binding.settingsMergeDuplicateContactsHolder.setOnClickListener {
binding.settingsMergeDuplicateContacts.toggle()
config.mergeDuplicateContacts = binding.settingsMergeDuplicateContacts.isChecked
}
}
private fun setupEnableAutomaticBackups() {
settings_backups_label.beVisibleIf(isRPlus())
settings_enable_automatic_backups_holder.beVisibleIf(isRPlus())
settings_enable_automatic_backups.isChecked = config.autoBackup
settings_enable_automatic_backups_holder.setOnClickListener {
binding.settingsBackupsLabel.beVisibleIf(isRPlus())
binding.settingsEnableAutomaticBackupsHolder.beVisibleIf(isRPlus())
binding.settingsEnableAutomaticBackups.isChecked = config.autoBackup
binding.settingsEnableAutomaticBackupsHolder.setOnClickListener {
val wasBackupDisabled = !config.autoBackup
if (wasBackupDisabled) {
ManageAutoBackupsDialog(
@ -250,8 +253,8 @@ class SettingsActivity : SimpleActivity() {
}
private fun setupManageAutomaticBackups() {
settings_manage_automatic_backups_holder.beVisibleIf(isRPlus() && config.autoBackup)
settings_manage_automatic_backups_holder.setOnClickListener {
binding.settingsManageAutomaticBackupsHolder.beVisibleIf(isRPlus() && config.autoBackup)
binding.settingsManageAutomaticBackupsHolder.setOnClickListener {
ManageAutoBackupsDialog(
activity = this,
onSuccess = {
@ -263,7 +266,7 @@ class SettingsActivity : SimpleActivity() {
private fun enableOrDisableAutomaticBackups(enable: Boolean) {
config.autoBackup = enable
settings_enable_automatic_backups.isChecked = enable
settings_manage_automatic_backups_holder.beVisibleIf(enable)
binding.settingsEnableAutomaticBackups.isChecked = enable
binding.settingsManageAutomaticBackupsHolder.beVisibleIf(enable)
}
}

View file

@ -65,9 +65,9 @@ open class SimpleActivity : BaseSimpleActivity() {
protected fun getTabIcon(position: Int): Drawable {
val drawableId = when (position) {
LOCATION_CONTACTS_TAB -> R.drawable.ic_person_vector
LOCATION_FAVORITES_TAB -> R.drawable.ic_star_vector
else -> R.drawable.ic_people_vector
LOCATION_CONTACTS_TAB -> com.simplemobiletools.commons.R.drawable.ic_person_vector
LOCATION_FAVORITES_TAB -> com.simplemobiletools.commons.R.drawable.ic_star_vector
else -> com.simplemobiletools.commons.R.drawable.ic_people_vector
}
return resources.getColoredDrawableWithColor(drawableId, getProperTextColor())
@ -75,9 +75,9 @@ open class SimpleActivity : BaseSimpleActivity() {
protected fun getTabLabel(position: Int): String {
val stringId = when (position) {
LOCATION_CONTACTS_TAB -> R.string.contacts_tab
LOCATION_FAVORITES_TAB -> R.string.favorites_tab
else -> R.string.groups_tab
LOCATION_CONTACTS_TAB -> com.simplemobiletools.commons.R.string.contacts_tab
LOCATION_FAVORITES_TAB -> com.simplemobiletools.commons.R.string.favorites_tab
else -> com.simplemobiletools.commons.R.string.groups_tab
}
return resources.getString(stringId)

View file

@ -24,19 +24,14 @@ import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.commons.models.PhoneNumber
import com.simplemobiletools.commons.models.contacts.*
import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.contacts.pro.databinding.*
import com.simplemobiletools.contacts.pro.dialogs.ChooseSocialDialog
import com.simplemobiletools.contacts.pro.dialogs.ManageVisibleFieldsDialog
import com.simplemobiletools.contacts.pro.extensions.*
import com.simplemobiletools.contacts.pro.extensions.config
import com.simplemobiletools.contacts.pro.extensions.editContact
import com.simplemobiletools.contacts.pro.extensions.getPackageDrawable
import com.simplemobiletools.contacts.pro.extensions.startCallIntent
import com.simplemobiletools.contacts.pro.helpers.*
import kotlinx.android.synthetic.main.activity_view_contact.*
import kotlinx.android.synthetic.main.item_view_address.view.*
import kotlinx.android.synthetic.main.item_view_contact_source.view.*
import kotlinx.android.synthetic.main.item_view_email.view.*
import kotlinx.android.synthetic.main.item_view_event.view.*
import kotlinx.android.synthetic.main.item_view_group.view.*
import kotlinx.android.synthetic.main.item_view_im.view.*
import kotlinx.android.synthetic.main.item_view_phone_number.view.*
import kotlinx.android.synthetic.main.item_website.view.*
class ViewContactActivity : ContactActivity() {
private var isViewIntent = false
@ -47,20 +42,24 @@ class ViewContactActivity : ContactActivity() {
private var fullContact: Contact? = null // contact with all fields filled from duplicates
private var duplicateInitialized = false
private val mergeDuplicate: Boolean get() = config.mergeDuplicateContacts
private lateinit var binding: ActivityViewContactBinding
private val COMPARABLE_PHONE_NUMBER_LENGTH = 9
companion object {
private const val COMPARABLE_PHONE_NUMBER_LENGTH = 9
}
override fun onCreate(savedInstanceState: Bundle?) {
showTransparentTop = true
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_view_contact)
binding = ActivityViewContactBinding.inflate(layoutInflater)
setContentView(binding.root)
if (checkAppSideloading()) {
return
}
showFields = config.showContactFields
contact_wrapper.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
binding.contactWrapper.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
setupMenu()
}
@ -74,7 +73,7 @@ class ViewContactActivity : ContactActivity() {
initContact()
}
} else {
toast(R.string.no_contacts_permission)
toast(com.simplemobiletools.commons.R.string.no_contacts_permission)
finish()
}
}
@ -86,7 +85,7 @@ class ViewContactActivity : ContactActivity() {
}
override fun onBackPressed() {
if (contact_photo_big.alpha == 1f) {
if (binding.contactPhotoBig.alpha == 1f) {
hideBigContactPhoto()
} else {
super.onBackPressed()
@ -94,8 +93,8 @@ class ViewContactActivity : ContactActivity() {
}
private fun setupMenu() {
(contact_appbar.layoutParams as RelativeLayout.LayoutParams).topMargin = statusBarHeight
contact_toolbar.menu.apply {
(binding.contactAppbar.layoutParams as RelativeLayout.LayoutParams).topMargin = statusBarHeight
binding.contactToolbar.menu.apply {
findItem(R.id.share).setOnMenuItemClickListener {
if (fullContact != null) {
shareContact(fullContact!!)
@ -131,7 +130,7 @@ class ViewContactActivity : ContactActivity() {
}
}
contact_toolbar.setNavigationOnClickListener {
binding.contactToolbar.setNavigationOnClickListener {
finish()
}
}
@ -173,7 +172,7 @@ class ViewContactActivity : ContactActivity() {
if (contact == null) {
if (!wasEditLaunched) {
toast(R.string.unknown_error_occurred)
toast(com.simplemobiletools.commons.R.string.unknown_error_occurred)
}
finish()
} else {
@ -197,54 +196,55 @@ class ViewContactActivity : ContactActivity() {
return
}
contact_scrollview.beVisible()
binding.contactScrollview.beVisible()
setupViewContact()
contact_send_sms.beVisibleIf(contact!!.phoneNumbers.isNotEmpty())
contact_start_call.beVisibleIf(contact!!.phoneNumbers.isNotEmpty())
contact_send_email.beVisibleIf(contact!!.emails.isNotEmpty())
binding.contactSendSms.beVisibleIf(contact!!.phoneNumbers.isNotEmpty())
binding.contactStartCall.beVisibleIf(contact!!.phoneNumbers.isNotEmpty())
binding.contactSendEmail.beVisibleIf(contact!!.emails.isNotEmpty())
if (contact!!.photoUri.isEmpty() && contact!!.photo == null) {
showPhotoPlaceholder(contact_photo)
contact_photo_bottom_shadow.beGone()
showPhotoPlaceholder(binding.contactPhoto)
binding.contactPhotoBottomShadow.beGone()
} else {
updateContactPhoto(contact!!.photoUri, contact_photo, contact_photo_bottom_shadow, contact!!.photo)
updateContactPhoto(contact!!.photoUri, binding.contactPhoto, binding.contactPhotoBottomShadow, contact!!.photo)
val options = RequestOptions()
.transform(FitCenter(), RoundedCorners(resources.getDimension(R.dimen.normal_margin).toInt()))
.transform(FitCenter(), RoundedCorners(resources.getDimension(com.simplemobiletools.commons.R.dimen.normal_margin).toInt()))
Glide.with(this)
.load(contact!!.photo ?: currentContactPhotoPath)
.apply(options)
.into(contact_photo_big)
.into(binding.contactPhotoBig)
contact_photo.setOnClickListener {
contact_photo_big.alpha = 0f
contact_photo_big.beVisible()
contact_photo_big.animate().alpha(1f).start()
binding.contactPhoto.setOnClickListener {
binding.contactPhotoBig.alpha = 0f
binding.contactPhotoBig.beVisible()
binding.contactPhotoBig.animate().alpha(1f).start()
}
contact_photo_big.setOnClickListener {
binding.contactPhotoBig.setOnClickListener {
hideBigContactPhoto()
}
}
val textColor = getProperTextColor()
arrayOf(
contact_name_image, contact_numbers_image, contact_emails_image, contact_addresses_image, contact_ims_image, contact_events_image,
contact_source_image, contact_notes_image, contact_ringtone_image, contact_organization_image, contact_websites_image, contact_groups_image
binding.contactNameImage, binding.contactNumbersImage, binding.contactEmailsImage, binding.contactAddressesImage, binding.contactImsImage,
binding.contactEventsImage, binding.contactSourceImage, binding.contactNotesImage, binding.contactRingtoneImage, binding.contactOrganizationImage,
binding.contactWebsitesImage, binding.contactGroupsImage
).forEach {
it.applyColorFilter(textColor)
}
contact_send_sms.setOnClickListener { trySendSMS() }
contact_start_call.setOnClickListener { tryInitiateCall(contact!!) { startCallIntent(it) } }
contact_send_email.setOnClickListener { trySendEmail() }
binding.contactSendSms.setOnClickListener { trySendSMS() }
binding.contactStartCall.setOnClickListener { tryInitiateCall(contact!!) { startCallIntent(it) } }
binding.contactSendEmail.setOnClickListener { trySendEmail() }
contact_send_sms.setOnLongClickListener { toast(R.string.send_sms); true; }
contact_start_call.setOnLongClickListener { toast(R.string.call_contact); true; }
contact_send_email.setOnLongClickListener { toast(R.string.send_email); true; }
binding.contactSendSms.setOnLongClickListener { toast(com.simplemobiletools.commons.R.string.send_sms); true; }
binding.contactStartCall.setOnLongClickListener { toast(R.string.call_contact); true; }
binding.contactSendEmail.setOnLongClickListener { toast(com.simplemobiletools.commons.R.string.send_email); true; }
updateTextColors(contact_scrollview)
contact_toolbar.menu.findItem(R.id.open_with).isVisible = contact?.isPrivate() == false
updateTextColors(binding.contactScrollview)
binding.contactToolbar.menu.findItem(R.id.open_with).isVisible = contact?.isPrivate() == false
}
private fun setupViewContact() {
@ -281,7 +281,7 @@ class ViewContactActivity : ContactActivity() {
setupNotes()
setupRingtone()
setupOrganization()
updateTextColors(contact_scrollview)
updateTextColors(binding.contactScrollview)
}
private fun launchEditContact(contact: Contact) {
@ -298,7 +298,7 @@ class ViewContactActivity : ContactActivity() {
}
private fun setupFavorite() {
contact_toggle_favorite.apply {
binding.contactToggleFavorite.apply {
beVisible()
tag = contact!!.starred
setImageDrawable(getStarDrawable(tag == 1))
@ -331,10 +331,10 @@ class ViewContactActivity : ContactActivity() {
val showNameFields = showFields and SHOW_PREFIX_FIELD != 0 || showFields and SHOW_FIRST_NAME_FIELD != 0 || showFields and SHOW_MIDDLE_NAME_FIELD != 0 ||
showFields and SHOW_SURNAME_FIELD != 0 || showFields and SHOW_SUFFIX_FIELD != 0
contact_name.text = displayName
contact_name.copyOnLongClick(displayName)
contact_name.beVisibleIf(displayName.isNotEmpty() && !contact!!.isABusinessContact() && showNameFields)
contact_name_image.beInvisibleIf(contact_name.isGone())
binding.contactName.text = displayName
binding.contactName.copyOnLongClick(displayName)
binding.contactName.beVisibleIf(displayName.isNotEmpty() && !contact!!.isABusinessContact() && showNameFields)
binding.contactNameImage.beInvisibleIf(binding.contactName.isGone())
}
private fun setupPhoneNumbers() {
@ -377,17 +377,17 @@ class ViewContactActivity : ContactActivity() {
phoneNumbers = phoneNumbers.sortedBy { it.type }.toMutableSet() as LinkedHashSet<PhoneNumber>
fullContact!!.phoneNumbers = phoneNumbers.toMutableList() as ArrayList<PhoneNumber>
contact_numbers_holder.removeAllViews()
binding.contactNumbersHolder.removeAllViews()
if (phoneNumbers.isNotEmpty() && showFields and SHOW_PHONE_NUMBERS_FIELD != 0) {
phoneNumbers.forEach { phoneNumber ->
layoutInflater.inflate(R.layout.item_view_phone_number, contact_numbers_holder, false).apply {
contact_numbers_holder.addView(this)
contact_number.text = phoneNumber.value
contact_number_type.text = getPhoneNumberTypeText(phoneNumber.type, phoneNumber.label)
copyOnLongClick(phoneNumber.value)
ItemViewPhoneNumberBinding.inflate(layoutInflater, binding.contactNumbersHolder, false).apply {
binding.contactNumbersHolder.addView(root)
contactNumber.text = phoneNumber.value
contactNumberType.text = getPhoneNumberTypeText(phoneNumber.type, phoneNumber.label)
root.copyOnLongClick(phoneNumber.value)
setOnClickListener {
root.setOnClickListener {
if (config.showCallConfirmation) {
CallConfirmationDialog(this@ViewContactActivity, phoneNumber.value) {
startCallIntent(phoneNumber.value)
@ -397,46 +397,46 @@ class ViewContactActivity : ContactActivity() {
}
}
contact_number_holder.default_toggle_icon.isVisible = phoneNumber.isPrimary
defaultToggleIcon.isVisible = phoneNumber.isPrimary
}
}
contact_numbers_image.beVisible()
contact_numbers_holder.beVisible()
binding.contactNumbersImage.beVisible()
binding.contactNumbersHolder.beVisible()
} else {
contact_numbers_image.beGone()
contact_numbers_holder.beGone()
binding.contactNumbersImage.beGone()
binding.contactNumbersHolder.beGone()
}
// make sure the Call and SMS buttons are visible if any phone number is shown
if (phoneNumbers.isNotEmpty()) {
contact_send_sms.beVisible()
contact_start_call.beVisible()
binding.contactSendSms.beVisible()
binding.contactStartCall.beVisible()
}
}
// a contact cannot have different emails per contact source. Such contacts are handled as separate ones, not duplicates of each other
private fun setupEmails() {
contact_emails_holder.removeAllViews()
binding.contactEmailsHolder.removeAllViews()
val emails = contact!!.emails
if (emails.isNotEmpty() && showFields and SHOW_EMAILS_FIELD != 0) {
emails.forEach {
layoutInflater.inflate(R.layout.item_view_email, contact_emails_holder, false).apply {
ItemViewEmailBinding.inflate(layoutInflater, binding.contactEmailsHolder, false).apply {
val email = it
contact_emails_holder.addView(this)
contact_email.text = email.value
contact_email_type.text = getEmailTypeText(email.type, email.label)
copyOnLongClick(email.value)
binding.contactEmailsHolder.addView(root)
contactEmail.text = email.value
contactEmailType.text = getEmailTypeText(email.type, email.label)
root.copyOnLongClick(email.value)
setOnClickListener {
root.setOnClickListener {
sendEmailIntent(email.value)
}
}
}
contact_emails_image.beVisible()
contact_emails_holder.beVisible()
binding.contactEmailsImage.beVisible()
binding.contactEmailsHolder.beVisible()
} else {
contact_emails_image.beGone()
contact_emails_holder.beGone()
binding.contactEmailsImage.beGone()
binding.contactEmailsHolder.beGone()
}
}
@ -451,27 +451,27 @@ class ViewContactActivity : ContactActivity() {
addresses = addresses.sortedBy { it.type }.toMutableSet() as LinkedHashSet<Address>
fullContact!!.addresses = addresses.toMutableList() as ArrayList<Address>
contact_addresses_holder.removeAllViews()
binding.contactAddressesHolder.removeAllViews()
if (addresses.isNotEmpty() && showFields and SHOW_ADDRESSES_FIELD != 0) {
addresses.forEach {
layoutInflater.inflate(R.layout.item_view_address, contact_addresses_holder, false).apply {
ItemViewAddressBinding.inflate(layoutInflater, binding.contactAddressesHolder, false).apply {
val address = it
contact_addresses_holder.addView(this)
contact_address.text = address.value
contact_address_type.text = getAddressTypeText(address.type, address.label)
copyOnLongClick(address.value)
binding.contactAddressesHolder.addView(root)
contactAddress.text = address.value
contactAddressType.text = getAddressTypeText(address.type, address.label)
root.copyOnLongClick(address.value)
setOnClickListener {
root.setOnClickListener {
sendAddressIntent(address.value)
}
}
}
contact_addresses_image.beVisible()
contact_addresses_holder.beVisible()
binding.contactAddressesImage.beVisible()
binding.contactAddressesHolder.beVisible()
} else {
contact_addresses_image.beGone()
contact_addresses_holder.beGone()
binding.contactAddressesImage.beGone()
binding.contactAddressesHolder.beGone()
}
}
@ -486,23 +486,23 @@ class ViewContactActivity : ContactActivity() {
IMs = IMs.sortedBy { it.type }.toMutableSet() as LinkedHashSet<IM>
fullContact!!.IMs = IMs.toMutableList() as ArrayList<IM>
contact_ims_holder.removeAllViews()
binding.contactImsHolder.removeAllViews()
if (IMs.isNotEmpty() && showFields and SHOW_IMS_FIELD != 0) {
IMs.forEach {
layoutInflater.inflate(R.layout.item_view_im, contact_ims_holder, false).apply {
ItemViewImBinding.inflate(layoutInflater, binding.contactImsHolder, false).apply {
val IM = it
contact_ims_holder.addView(this)
contact_im.text = IM.value
contact_im_type.text = getIMTypeText(IM.type, IM.label)
copyOnLongClick(IM.value)
binding.contactImsHolder.addView(root)
contactIm.text = IM.value
contactImType.text = getIMTypeText(IM.type, IM.label)
root.copyOnLongClick(IM.value)
}
}
contact_ims_image.beVisible()
contact_ims_holder.beVisible()
binding.contactImsImage.beVisible()
binding.contactImsHolder.beVisible()
} else {
contact_ims_image.beGone()
contact_ims_holder.beGone()
binding.contactImsImage.beGone()
binding.contactImsHolder.beGone()
}
}
@ -517,22 +517,22 @@ class ViewContactActivity : ContactActivity() {
events = events.sortedBy { it.type }.toMutableSet() as LinkedHashSet<Event>
fullContact!!.events = events.toMutableList() as ArrayList<Event>
contact_events_holder.removeAllViews()
binding.contactEventsHolder.removeAllViews()
if (events.isNotEmpty() && showFields and SHOW_EVENTS_FIELD != 0) {
events.forEach {
layoutInflater.inflate(R.layout.item_view_event, contact_events_holder, false).apply {
contact_events_holder.addView(this)
it.value.getDateTimeFromDateString(true, contact_event)
contact_event_type.setText(getEventTextId(it.type))
copyOnLongClick(it.value)
ItemViewEventBinding.inflate(layoutInflater, binding.contactEventsHolder, false).apply {
binding.contactEventsHolder.addView(root)
it.value.getDateTimeFromDateString(true, contactEvent)
contactEventType.setText(getEventTextId(it.type))
root.copyOnLongClick(it.value)
}
}
contact_events_image.beVisible()
contact_events_holder.beVisible()
binding.contactEventsImage.beVisible()
binding.contactEventsHolder.beVisible()
} else {
contact_events_image.beGone()
contact_events_holder.beGone()
binding.contactEventsImage.beGone()
binding.contactEventsHolder.beGone()
}
}
@ -547,26 +547,26 @@ class ViewContactActivity : ContactActivity() {
websites = websites.sorted().toMutableSet() as LinkedHashSet<String>
fullContact!!.websites = websites.toMutableList() as ArrayList<String>
contact_websites_holder.removeAllViews()
binding.contactWebsitesHolder.removeAllViews()
if (websites.isNotEmpty() && showFields and SHOW_WEBSITES_FIELD != 0) {
websites.forEach {
val url = it
layoutInflater.inflate(R.layout.item_website, contact_websites_holder, false).apply {
contact_websites_holder.addView(this)
contact_website.text = url
copyOnLongClick(url)
ItemWebsiteBinding.inflate(layoutInflater, binding.contactWebsitesHolder, false).apply {
binding.contactWebsitesHolder.addView(root)
contactWebsite.text = url
root.copyOnLongClick(url)
setOnClickListener {
root.setOnClickListener {
openWebsiteIntent(url)
}
}
}
contact_websites_image.beVisible()
contact_websites_holder.beVisible()
binding.contactWebsitesImage.beVisible()
binding.contactWebsitesHolder.beVisible()
} else {
contact_websites_image.beGone()
contact_websites_holder.beGone()
binding.contactWebsitesImage.beGone()
binding.contactWebsitesHolder.beGone()
}
}
@ -581,27 +581,27 @@ class ViewContactActivity : ContactActivity() {
groups = groups.sortedBy { it.title }.toMutableSet() as LinkedHashSet<Group>
fullContact!!.groups = groups.toMutableList() as ArrayList<Group>
contact_groups_holder.removeAllViews()
binding.contactGroupsHolder.removeAllViews()
if (groups.isNotEmpty() && showFields and SHOW_GROUPS_FIELD != 0) {
groups.forEach {
layoutInflater.inflate(R.layout.item_view_group, contact_groups_holder, false).apply {
ItemViewGroupBinding.inflate(layoutInflater, binding.contactGroupsHolder, false).apply {
val group = it
contact_groups_holder.addView(this)
contact_group.text = group.title
copyOnLongClick(group.title)
binding.contactGroupsHolder.addView(root)
contactGroup.text = group.title
root.copyOnLongClick(group.title)
}
}
contact_groups_image.beVisible()
contact_groups_holder.beVisible()
binding.contactGroupsImage.beVisible()
binding.contactGroupsHolder.beVisible()
} else {
contact_groups_image.beGone()
contact_groups_holder.beGone()
binding.contactGroupsImage.beGone()
binding.contactGroupsHolder.beGone()
}
}
private fun setupContactSources() {
contact_sources_holder.removeAllViews()
binding.contactSourcesHolder.removeAllViews()
if (showFields and SHOW_CONTACT_SOURCE_FIELD != 0) {
var sources = HashMap<Contact, String>()
sources[contact!!] = getPublicContactSourceSync(contact!!.source, contactSources)
@ -617,101 +617,101 @@ class ViewContactActivity : ContactActivity() {
}
for ((key, value) in sources) {
layoutInflater.inflate(R.layout.item_view_contact_source, contact_sources_holder, false).apply {
contact_source.text = if (value == "") getString(R.string.phone_storage) else value
contact_source.copyOnLongClick(value)
contact_sources_holder.addView(this)
ItemViewContactSourceBinding.inflate(layoutInflater, binding.contactSourcesHolder, false).apply {
contactSource.text = if (value == "") getString(R.string.phone_storage) else value
contactSource.copyOnLongClick(value)
binding.contactSourcesHolder.addView(root)
contact_source.setOnClickListener {
contactSource.setOnClickListener {
launchEditContact(key)
}
if (value.toLowerCase() == WHATSAPP) {
contact_source_image.setImageDrawable(getPackageDrawable(WHATSAPP_PACKAGE))
contact_source_image.beVisible()
contact_source_image.setOnClickListener {
contactSourceImage.setImageDrawable(getPackageDrawable(WHATSAPP_PACKAGE))
contactSourceImage.beVisible()
contactSourceImage.setOnClickListener {
showSocialActions(key.id)
}
}
if (value.toLowerCase() == SIGNAL) {
contact_source_image.setImageDrawable(getPackageDrawable(SIGNAL_PACKAGE))
contact_source_image.beVisible()
contact_source_image.setOnClickListener {
contactSourceImage.setImageDrawable(getPackageDrawable(SIGNAL_PACKAGE))
contactSourceImage.beVisible()
contactSourceImage.setOnClickListener {
showSocialActions(key.id)
}
}
if (value.toLowerCase() == VIBER) {
contact_source_image.setImageDrawable(getPackageDrawable(VIBER_PACKAGE))
contact_source_image.beVisible()
contact_source_image.setOnClickListener {
contactSourceImage.setImageDrawable(getPackageDrawable(VIBER_PACKAGE))
contactSourceImage.beVisible()
contactSourceImage.setOnClickListener {
showSocialActions(key.id)
}
}
if (value.toLowerCase() == TELEGRAM) {
contact_source_image.setImageDrawable(getPackageDrawable(TELEGRAM_PACKAGE))
contact_source_image.beVisible()
contact_source_image.setOnClickListener {
contactSourceImage.setImageDrawable(getPackageDrawable(TELEGRAM_PACKAGE))
contactSourceImage.beVisible()
contactSourceImage.setOnClickListener {
showSocialActions(key.id)
}
}
if (value.toLowerCase() == THREEMA) {
contact_source_image.setImageDrawable(getPackageDrawable(THREEMA_PACKAGE))
contact_source_image.beVisible()
contact_source_image.setOnClickListener {
contactSourceImage.setImageDrawable(getPackageDrawable(THREEMA_PACKAGE))
contactSourceImage.beVisible()
contactSourceImage.setOnClickListener {
showSocialActions(key.id)
}
}
}
}
contact_source_image.beVisible()
contact_sources_holder.beVisible()
binding.contactSourceImage.beVisible()
binding.contactSourcesHolder.beVisible()
} else {
contact_source_image.beGone()
contact_sources_holder.beGone()
binding.contactSourceImage.beGone()
binding.contactSourcesHolder.beGone()
}
}
private fun setupNotes() {
val notes = contact!!.notes
if (notes.isNotEmpty() && showFields and SHOW_NOTES_FIELD != 0) {
contact_notes.text = notes
contact_notes_image.beVisible()
contact_notes.beVisible()
contact_notes.copyOnLongClick(notes)
binding.contactNotes.text = notes
binding.contactNotesImage.beVisible()
binding.contactNotes.beVisible()
binding.contactNotes.copyOnLongClick(notes)
} else {
contact_notes_image.beGone()
contact_notes.beGone()
binding.contactNotesImage.beGone()
binding.contactNotes.beGone()
}
}
private fun setupRingtone() {
if (showFields and SHOW_RINGTONE_FIELD != 0) {
contact_ringtone_image.beVisible()
contact_ringtone.beVisible()
binding.contactRingtoneImage.beVisible()
binding.contactRingtone.beVisible()
val ringtone = contact!!.ringtone
if (ringtone?.isEmpty() == true) {
contact_ringtone.text = getString(R.string.no_sound)
binding.contactRingtone.text = getString(com.simplemobiletools.commons.R.string.no_sound)
} else if (ringtone?.isNotEmpty() == true && ringtone != getDefaultRingtoneUri().toString()) {
if (ringtone == SILENT) {
contact_ringtone.text = getString(R.string.no_sound)
binding.contactRingtone.text = getString(com.simplemobiletools.commons.R.string.no_sound)
} else {
systemRingtoneSelected(Uri.parse(ringtone))
}
} else {
contact_ringtone_image.beGone()
contact_ringtone.beGone()
binding.contactRingtoneImage.beGone()
binding.contactRingtone.beGone()
return
}
contact_ringtone.copyOnLongClick(contact_ringtone.text.toString())
binding.contactRingtone.copyOnLongClick(binding.contactRingtone.text.toString())
contact_ringtone.setOnClickListener {
binding.contactRingtone.setOnClickListener {
val ringtonePickerIntent = getRingtonePickerIntent()
try {
startActivityForResult(ringtonePickerIntent, INTENT_SELECT_RINGTONE)
@ -724,7 +724,7 @@ class ViewContactActivity : ContactActivity() {
RingtoneManager.TYPE_RINGTONE,
true,
onAlarmPicked = {
contact_ringtone.text = it?.title
binding.contactRingtone.text = it?.title
ringtoneUpdated(it?.uri)
},
onAlarmSoundDeleted = {}
@ -732,29 +732,32 @@ class ViewContactActivity : ContactActivity() {
}
}
} else {
contact_ringtone_image.beGone()
contact_ringtone.beGone()
binding.contactRingtoneImage.beGone()
binding.contactRingtone.beGone()
}
}
private fun setupOrganization() {
val organization = contact!!.organization
if (organization.isNotEmpty() && showFields and SHOW_ORGANIZATION_FIELD != 0) {
contact_organization_company.text = organization.company
contact_organization_job_position.text = organization.jobPosition
contact_organization_image.beGoneIf(organization.isEmpty())
contact_organization_company.beGoneIf(organization.company.isEmpty())
contact_organization_job_position.beGoneIf(organization.jobPosition.isEmpty())
contact_organization_company.copyOnLongClick(contact_organization_company.value)
contact_organization_job_position.copyOnLongClick(contact_organization_job_position.value)
binding.contactOrganizationCompany.text = organization.company
binding.contactOrganizationJobPosition.text = organization.jobPosition
binding.contactOrganizationImage.beGoneIf(organization.isEmpty())
binding.contactOrganizationCompany.beGoneIf(organization.company.isEmpty())
binding.contactOrganizationJobPosition.beGoneIf(organization.jobPosition.isEmpty())
binding.contactOrganizationCompany.copyOnLongClick(binding.contactOrganizationCompany.value)
binding.contactOrganizationJobPosition.copyOnLongClick(binding.contactOrganizationJobPosition.value)
if (organization.company.isEmpty() && organization.jobPosition.isNotEmpty()) {
(contact_organization_image.layoutParams as RelativeLayout.LayoutParams).addRule(RelativeLayout.ALIGN_TOP, contact_organization_job_position.id)
(binding.contactOrganizationImage.layoutParams as RelativeLayout.LayoutParams).addRule(
RelativeLayout.ALIGN_TOP,
binding.contactOrganizationJobPosition.id
)
}
} else {
contact_organization_image.beGone()
contact_organization_company.beGone()
contact_organization_job_position.beGone()
binding.contactOrganizationImage.beGone()
binding.contactOrganizationCompany.beGone()
binding.contactOrganizationJobPosition.beGone()
}
}
@ -775,11 +778,11 @@ class ViewContactActivity : ContactActivity() {
if (success) {
startActivity(this)
} else {
toast(R.string.no_phone_call_permission)
toast(com.simplemobiletools.commons.R.string.no_phone_call_permission)
}
}
} catch (e: ActivityNotFoundException) {
toast(R.string.no_app_found)
toast(com.simplemobiletools.commons.R.string.no_app_found)
} catch (e: Exception) {
showErrorToast(e)
}
@ -791,13 +794,13 @@ class ViewContactActivity : ContactActivity() {
}
override fun customRingtoneSelected(ringtonePath: String) {
contact_ringtone.text = ringtonePath.getFilenameFromPath()
binding.contactRingtone.text = ringtonePath.getFilenameFromPath()
ringtoneUpdated(ringtonePath)
}
override fun systemRingtoneSelected(uri: Uri?) {
val contactRingtone = RingtoneManager.getRingtone(this, uri)
contact_ringtone.text = contactRingtone.getTitle(this)
binding.contactRingtone.text = contactRingtone.getTitle(this)
ringtoneUpdated(uri?.toString() ?: "")
}
@ -833,13 +836,13 @@ class ViewContactActivity : ContactActivity() {
}
private fun deleteContactFromAllSources() {
val addition = if (contact_sources_holder.childCount > 1) {
val addition = if (binding.contactSourcesHolder.childCount > 1) {
"\n\n${getString(R.string.delete_from_all_sources)}"
} else {
""
}
val message = "${getString(R.string.proceed_with_deletion)}$addition"
val message = "${getString(com.simplemobiletools.commons.R.string.proceed_with_deletion)}$addition"
ConfirmationDialog(this, message) {
if (contact != null) {
ContactsHelper(this).deleteContact(contact!!, true) {
@ -849,10 +852,11 @@ class ViewContactActivity : ContactActivity() {
}
}
private fun getStarDrawable(on: Boolean) = resources.getDrawable(if (on) R.drawable.ic_star_vector else R.drawable.ic_star_outline_vector)
private fun getStarDrawable(on: Boolean) =
resources.getDrawable(if (on) com.simplemobiletools.commons.R.drawable.ic_star_vector else com.simplemobiletools.commons.R.drawable.ic_star_outline_vector)
private fun hideBigContactPhoto() {
contact_photo_big.animate().alpha(0f).withEndAction { contact_photo_big.beGone() }.start()
binding.contactPhotoBig.animate().alpha(0f).withEndAction { binding.contactPhotoBig.beGone() }.start()
}
private fun View.copyOnLongClick(value: String) {

View file

@ -1,7 +1,6 @@
package com.simplemobiletools.contacts.pro.adapters
import android.graphics.drawable.BitmapDrawable
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
@ -16,11 +15,8 @@ import com.simplemobiletools.commons.extensions.getProperTextColor
import com.simplemobiletools.commons.extensions.normalizeString
import com.simplemobiletools.commons.helpers.SimpleContactsHelper
import com.simplemobiletools.commons.models.contacts.Contact
import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.contacts.pro.activities.SimpleActivity
import kotlinx.android.synthetic.main.item_autocomplete_name_number.view.item_autocomplete_image
import kotlinx.android.synthetic.main.item_autocomplete_name_number.view.item_autocomplete_name
import kotlinx.android.synthetic.main.item_autocomplete_name_number.view.item_autocomplete_number
import com.simplemobiletools.contacts.pro.databinding.ItemAutocompleteNameNumberBinding
class AutoCompleteTextViewAdapter(
val activity: SimpleActivity,
@ -34,23 +30,23 @@ class AutoCompleteTextViewAdapter(
var listItem = convertView
val nameToUse = contact.getNameToDisplay()
if (listItem == null || listItem.tag != nameToUse.isNotEmpty()) {
listItem = LayoutInflater.from(activity).inflate(R.layout.item_autocomplete_name_number, parent, false)
listItem = ItemAutocompleteNameNumberBinding.inflate(activity.layoutInflater, parent, false).root
}
val placeholder = BitmapDrawable(activity.resources, SimpleContactsHelper(context).getContactLetterIcon(nameToUse))
listItem!!.apply {
setBackgroundColor(context.getProperBackgroundColor())
item_autocomplete_name.setTextColor(context.getProperTextColor())
item_autocomplete_number.setTextColor(context.getProperTextColor())
ItemAutocompleteNameNumberBinding.bind(listItem).apply {
root.setBackgroundColor(context.getProperBackgroundColor())
itemAutocompleteName.setTextColor(context.getProperTextColor())
itemAutocompleteNumber.setTextColor(context.getProperTextColor())
tag = nameToUse.isNotEmpty()
item_autocomplete_name.text = nameToUse
root.tag = nameToUse.isNotEmpty()
itemAutocompleteName.text = nameToUse
contact.phoneNumbers.apply {
val phoneNumber = firstOrNull { it.isPrimary }?.normalizedNumber ?: firstOrNull()?.normalizedNumber
if (phoneNumber.isNullOrEmpty()) {
item_autocomplete_number.beGone()
itemAutocompleteNumber.beGone()
} else {
item_autocomplete_number.text = phoneNumber
itemAutocompleteNumber.text = phoneNumber
}
}
@ -65,7 +61,7 @@ class AutoCompleteTextViewAdapter(
.placeholder(placeholder)
.apply(options)
.apply(RequestOptions.circleCropTransform())
.into(item_autocomplete_image)
.into(itemAutocompleteImage)
}
return listItem

View file

@ -146,10 +146,11 @@ class ContactsAdapter(
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val layout = when (viewType) {
VIEW_TYPE_GRID -> {
if (showPhoneNumbers) R.layout.item_contact_with_number_grid else R.layout.item_contact_without_number_grid
if (showPhoneNumbers) com.simplemobiletools.commons.R.layout.item_contact_with_number_grid else com.simplemobiletools.commons.R.layout.item_contact_without_number_grid
}
else -> {
if (showPhoneNumbers) R.layout.item_contact_with_number else R.layout.item_contact_without_number
if (showPhoneNumbers) com.simplemobiletools.commons.R.layout.item_contact_with_number else com.simplemobiletools.commons.R.layout.item_contact_without_number
}
}
return createViewHolder(layout, parent)
@ -194,10 +195,10 @@ class ContactsAdapter(
val items = if (itemsCnt == 1) {
"\"${getSelectedItems().first().getNameToDisplay()}\""
} else {
resources.getQuantityString(R.plurals.delete_contacts, itemsCnt, itemsCnt)
resources.getQuantityString(com.simplemobiletools.commons.R.plurals.delete_contacts, itemsCnt, itemsCnt)
}
val baseString = R.string.deletion_confirmation
val baseString = com.simplemobiletools.commons.R.string.deletion_confirmation
val question = String.format(resources.getString(baseString), items)
ConfirmationDialog(activity, question) {
@ -345,7 +346,7 @@ class ContactsAdapter(
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.error(placeholderImage)
val size = activity.resources.getDimension(R.dimen.shortcut_size).toInt()
val size = activity.resources.getDimension(com.simplemobiletools.commons.R.dimen.shortcut_size).toInt()
val itemToLoad: Any? = if (contact.photoUri.isNotEmpty()) {
contact.photoUri
} else {
@ -377,16 +378,16 @@ class ContactsAdapter(
override fun onViewRecycled(holder: ViewHolder) {
super.onViewRecycled(holder)
if (!activity.isDestroyed && !activity.isFinishing) {
Glide.with(activity).clear(holder.itemView.findViewById<ImageView>(R.id.item_contact_image))
Glide.with(activity).clear(holder.itemView.findViewById<ImageView>(com.simplemobiletools.commons.R.id.item_contact_image))
}
}
private fun setupView(view: View, contact: Contact, holder: ViewHolder) {
view.apply {
setupViewBackground(activity)
findViewById<ConstraintLayout>(R.id.item_contact_frame)?.isSelected = selectedKeys.contains(contact.id)
findViewById<ConstraintLayout>(com.simplemobiletools.commons.R.id.item_contact_frame)?.isSelected = selectedKeys.contains(contact.id)
val fullName = contact.getNameToDisplay()
findViewById<TextView>(R.id.item_contact_name).text = if (textToHighlight.isEmpty()) fullName else {
findViewById<TextView>(com.simplemobiletools.commons.R.id.item_contact_name).text = if (textToHighlight.isEmpty()) fullName else {
if (fullName.contains(textToHighlight, true)) {
fullName.highlightTextPart(textToHighlight, properPrimaryColor)
} else {
@ -394,12 +395,12 @@ class ContactsAdapter(
}
}
findViewById<TextView>(R.id.item_contact_name).apply {
findViewById<TextView>(com.simplemobiletools.commons.R.id.item_contact_name).apply {
setTextColor(textColor)
setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize)
}
if (findViewById<TextView>(R.id.item_contact_number) != null) {
if (findViewById<TextView>(com.simplemobiletools.commons.R.id.item_contact_number) != null) {
val phoneNumberToUse = if (textToHighlight.isEmpty()) {
contact.phoneNumbers.firstOrNull()
} else {
@ -407,19 +408,19 @@ class ContactsAdapter(
}
val numberText = phoneNumberToUse?.value ?: ""
findViewById<TextView>(R.id.item_contact_number).apply {
findViewById<TextView>(com.simplemobiletools.commons.R.id.item_contact_number).apply {
text = if (textToHighlight.isEmpty()) numberText else numberText.highlightTextPart(textToHighlight, properPrimaryColor, false, true)
setTextColor(textColor)
setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize)
}
}
findViewById<TextView>(R.id.item_contact_image).beVisibleIf(showContactThumbnails)
findViewById<TextView>(com.simplemobiletools.commons.R.id.item_contact_image).beVisibleIf(showContactThumbnails)
if (showContactThumbnails) {
val placeholderImage = BitmapDrawable(resources, SimpleContactsHelper(context).getContactLetterIcon(fullName))
if (contact.photoUri.isEmpty() && contact.photo == null) {
findViewById<ImageView>(R.id.item_contact_image).setImageDrawable(placeholderImage)
findViewById<ImageView>(com.simplemobiletools.commons.R.id.item_contact_image).setImageDrawable(placeholderImage)
} else {
val options = RequestOptions()
.signature(ObjectKey(contact.getSignatureKey()))
@ -437,11 +438,11 @@ class ContactsAdapter(
.load(itemToLoad)
.apply(options)
.apply(RequestOptions.circleCropTransform())
.into(findViewById(R.id.item_contact_image))
.into(findViewById(com.simplemobiletools.commons.R.id.item_contact_image))
}
}
val dragIcon = findViewById<ImageView>(R.id.drag_handle_icon)
val dragIcon = findViewById<ImageView>(com.simplemobiletools.commons.R.id.drag_handle_icon)
if (enableDrag && textToHighlight.isEmpty()) {
dragIcon.apply {
beVisibleIf(selectedKeys.isNotEmpty())

View file

@ -8,9 +8,8 @@ import com.simplemobiletools.commons.extensions.getProperPrimaryColor
import com.simplemobiletools.commons.extensions.getProperTextColor
import com.simplemobiletools.commons.helpers.SMT_PRIVATE
import com.simplemobiletools.commons.models.contacts.ContactSource
import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.contacts.pro.activities.SimpleActivity
import kotlinx.android.synthetic.main.item_filter_contact_source.view.*
import com.simplemobiletools.contacts.pro.databinding.ItemFilterContactSourceBinding
class FilterContactSourcesAdapter(
val activity: SimpleActivity,
@ -45,8 +44,7 @@ class FilterContactSourcesAdapter(
fun getSelectedContactSources() = contactSources.filter { selectedKeys.contains(it.hashCode()) }
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = activity.layoutInflater.inflate(R.layout.item_filter_contact_source, parent, false)
return ViewHolder(view)
return ViewHolder(ItemFilterContactSourceBinding.inflate(activity.layoutInflater, parent, false).root)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
@ -59,13 +57,13 @@ class FilterContactSourcesAdapter(
inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
fun bindView(contactSource: ContactSource): View {
val isSelected = selectedKeys.contains(contactSource.hashCode())
itemView.apply {
filter_contact_source_checkbox.isChecked = isSelected
filter_contact_source_checkbox.setColors(activity.getProperTextColor(), activity.getProperPrimaryColor(), activity.getProperBackgroundColor())
ItemFilterContactSourceBinding.bind(itemView).apply {
filterContactSourceCheckbox.isChecked = isSelected
filterContactSourceCheckbox.setColors(activity.getProperTextColor(), activity.getProperPrimaryColor(), activity.getProperBackgroundColor())
val countText = if (contactSource.count >= 0) " (${contactSource.count})" else ""
val displayName = "${contactSource.publicName}$countText"
filter_contact_source_checkbox.text = displayName
filter_contact_source_holder.setOnClickListener { viewClicked(!isSelected, contactSource) }
filterContactSourceCheckbox.text = displayName
filterContactSourceHolder.setOnClickListener { viewClicked(!isSelected, contactSource) }
}
return itemView

View file

@ -7,20 +7,22 @@ import android.view.ViewGroup
import com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.extensions.beVisibleIf
import com.simplemobiletools.commons.extensions.getTextSize
import com.simplemobiletools.commons.extensions.groupsDB
import com.simplemobiletools.commons.extensions.highlightTextPart
import com.simplemobiletools.commons.helpers.ContactsHelper
import com.simplemobiletools.commons.helpers.SimpleContactsHelper
import com.simplemobiletools.commons.helpers.TAB_GROUPS
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.commons.models.contacts.Group
import com.simplemobiletools.commons.views.MyRecyclerView
import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.contacts.pro.activities.SimpleActivity
import com.simplemobiletools.contacts.pro.databinding.ItemGroupBinding
import com.simplemobiletools.contacts.pro.dialogs.RenameGroupDialog
import com.simplemobiletools.commons.helpers.ContactsHelper
import com.simplemobiletools.commons.models.contacts.Group
import com.simplemobiletools.contacts.pro.extensions.config
import com.simplemobiletools.contacts.pro.interfaces.RefreshContactsListener
import kotlinx.android.synthetic.main.item_group.view.*
import java.util.*
class GroupsAdapter(
activity: SimpleActivity, var groups: ArrayList<Group>, val refreshListener: RefreshContactsListener?, recyclerView: MyRecyclerView,
@ -67,7 +69,9 @@ class GroupsAdapter(
override fun onActionModeDestroyed() {}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = createViewHolder(R.layout.item_group, parent)
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return createViewHolder(ItemGroupBinding.inflate(layoutInflater, parent, false).root)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val group = groups[position]
@ -110,7 +114,7 @@ class GroupsAdapter(
resources.getQuantityString(R.plurals.delete_groups, itemsCnt, itemsCnt)
}
val baseString = R.string.deletion_confirmation
val baseString = com.simplemobiletools.commons.R.string.deletion_confirmation
val question = String.format(resources.getString(baseString), items)
ConfirmationDialog(activity, question) {
@ -149,8 +153,8 @@ class GroupsAdapter(
private fun getSelectedItems() = groups.filter { selectedKeys.contains(it.id?.toInt()) } as ArrayList<Group>
private fun setupView(view: View, group: Group) {
view.apply {
group_frame?.isSelected = selectedKeys.contains(group.id!!.toInt())
ItemGroupBinding.bind(view).apply {
groupFrame.isSelected = selectedKeys.contains(group.id!!.toInt())
val titleWithCnt = "${group.title} (${group.contactsCount})"
val groupTitle = if (textToHighlight.isEmpty()) {
titleWithCnt
@ -158,15 +162,15 @@ class GroupsAdapter(
titleWithCnt.highlightTextPart(textToHighlight, properPrimaryColor)
}
group_name.apply {
groupName.apply {
setTextColor(textColor)
setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize)
text = groupTitle
}
group_tmb.beVisibleIf(showContactThumbnails)
groupTmb.beVisibleIf(showContactThumbnails)
if (showContactThumbnails) {
group_tmb.setImageDrawable(SimpleContactsHelper(activity).getColoredGroupIcon(group.title))
groupTmb.setImageDrawable(SimpleContactsHelper(activity).getColoredGroupIcon(group.title))
}
}
}

View file

@ -3,21 +3,26 @@ package com.simplemobiletools.contacts.pro.adapters
import android.graphics.drawable.BitmapDrawable
import android.util.SparseArray
import android.util.TypedValue
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import androidx.viewbinding.ViewBinding
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.request.RequestOptions
import com.bumptech.glide.signature.ObjectKey
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.SimpleContactsHelper
import com.simplemobiletools.commons.models.contacts.*
import com.simplemobiletools.commons.models.contacts.Contact
import com.simplemobiletools.commons.views.MyAppCompatCheckbox
import com.simplemobiletools.commons.views.MyRecyclerView
import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.contacts.pro.activities.SimpleActivity
import com.simplemobiletools.contacts.pro.databinding.ItemAddFavoriteWithNumberBinding
import com.simplemobiletools.contacts.pro.databinding.ItemAddFavoriteWithoutNumberBinding
import com.simplemobiletools.contacts.pro.extensions.config
import kotlinx.android.synthetic.main.item_add_favorite_with_number.view.*
class SelectContactsAdapter(
val activity: SimpleActivity, var contacts: ArrayList<Contact>, private val selectedContacts: ArrayList<Contact>, private val allowPickMultiple: Boolean,
@ -32,7 +37,7 @@ class SelectContactsAdapter(
private val showContactThumbnails = config.showContactThumbnails
private val showPhoneNumbers = config.showPhoneNumbers
private val itemLayout = if (showPhoneNumbers) R.layout.item_add_favorite_with_number else R.layout.item_add_favorite_without_number
private val itemBindingClass = if (showPhoneNumbers) Binding.WithNumber else Binding.WithoutNumber
private var textToHighlight = ""
init {
@ -56,7 +61,7 @@ class SelectContactsAdapter(
selectedPositions.remove(pos)
}
itemViews[pos]?.contact_checkbox?.isChecked = select
itemBindingClass.bind(itemViews[pos]).contactCheckbox.isChecked = select
}
fun getSelectedItemsSet(): HashSet<Contact> {
@ -66,8 +71,8 @@ class SelectContactsAdapter(
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = activity.layoutInflater.inflate(itemLayout, parent, false)
return ViewHolder(view)
val binding = itemBindingClass.inflate(activity.layoutInflater, parent, false)
return ViewHolder(binding.root)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
@ -81,19 +86,19 @@ class SelectContactsAdapter(
override fun onViewRecycled(holder: ViewHolder) {
super.onViewRecycled(holder)
if (!activity.isDestroyed && !activity.isFinishing) {
Glide.with(activity).clear(holder.itemView.contact_tmb)
Glide.with(activity).clear(itemBindingClass.bind(holder.itemView).contactTmb)
}
}
inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
fun bindView(contact: Contact): View {
itemView.apply {
contact_checkbox.beVisibleIf(allowPickMultiple)
contact_checkbox.setColors(context.getProperTextColor(), context.getProperPrimaryColor(), context.getProperBackgroundColor())
val textColor = context.getProperTextColor()
itemBindingClass.bind(itemView).apply {
contactCheckbox.beVisibleIf(allowPickMultiple)
contactCheckbox.setColors(root.context.getProperTextColor(), root.context.getProperPrimaryColor(), root.context.getProperBackgroundColor())
val textColor = root.context.getProperTextColor()
val fullName = contact.getNameToDisplay()
contact_name.text = if (textToHighlight.isEmpty()) fullName else {
contactName.text = if (textToHighlight.isEmpty()) fullName else {
if (fullName.contains(textToHighlight, true)) {
fullName.highlightTextPart(textToHighlight, adjustedPrimaryColor)
} else {
@ -101,10 +106,10 @@ class SelectContactsAdapter(
}
}
contact_name.setTextColor(textColor)
contact_name.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize)
contactName.setTextColor(textColor)
contactName.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize)
if (contact_number != null) {
contactNumber?.apply {
val phoneNumberToUse = if (textToHighlight.isEmpty()) {
contact.phoneNumbers.firstOrNull()
} else {
@ -112,21 +117,20 @@ class SelectContactsAdapter(
}
val numberText = phoneNumberToUse?.value ?: ""
contact_number.text =
if (textToHighlight.isEmpty()) numberText else numberText.highlightTextPart(textToHighlight, adjustedPrimaryColor, false, true)
contact_number.setTextColor(textColor)
contact_number.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize)
text = if (textToHighlight.isEmpty()) numberText else numberText.highlightTextPart(textToHighlight, adjustedPrimaryColor, false, true)
setTextColor(textColor)
setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize)
}
contact_frame.setOnClickListener {
root.setOnClickListener {
if (itemClick != null) {
itemClick.invoke(contact)
} else {
viewClicked(!contact_checkbox.isChecked)
viewClicked(!contactCheckbox.isChecked)
}
}
contact_tmb.beVisibleIf(showContactThumbnails)
contactTmb.beVisibleIf(showContactThumbnails)
if (showContactThumbnails) {
val avatarName = when {
@ -135,10 +139,10 @@ class SelectContactsAdapter(
else -> contact.firstName
}
val placeholderImage = BitmapDrawable(resources, SimpleContactsHelper(context).getContactLetterIcon(avatarName))
val placeholderImage = BitmapDrawable(root.resources, SimpleContactsHelper(root.context).getContactLetterIcon(avatarName))
if (contact.photoUri.isEmpty() && contact.photo == null) {
contact_tmb.setImageDrawable(placeholderImage)
contactTmb.setImageDrawable(placeholderImage)
} else {
val options = RequestOptions()
.signature(ObjectKey(contact.getSignatureKey()))
@ -156,7 +160,7 @@ class SelectContactsAdapter(
.load(itemToLoad)
.apply(options)
.apply(RequestOptions.circleCropTransform())
.into(contact_tmb)
.into(contactTmb)
}
}
}
@ -168,4 +172,56 @@ class SelectContactsAdapter(
toggleItemSelection(select, adapterPosition)
}
}
private sealed interface Binding {
fun inflate(layoutInflater: LayoutInflater, viewGroup: ViewGroup, attachToRoot: Boolean): ItemAddFavoriteBinding
fun bind(view: View): ItemAddFavoriteBinding
data object WithNumber : Binding {
override fun inflate(layoutInflater: LayoutInflater, viewGroup: ViewGroup, attachToRoot: Boolean): ItemAddFavoriteBinding {
return ItemAddFavoriteWithNumberBindingAdapter(ItemAddFavoriteWithNumberBinding.inflate(layoutInflater, viewGroup, attachToRoot))
}
override fun bind(view: View): ItemAddFavoriteBinding {
return ItemAddFavoriteWithNumberBindingAdapter(ItemAddFavoriteWithNumberBinding.bind(view))
}
}
data object WithoutNumber : Binding {
override fun inflate(layoutInflater: LayoutInflater, viewGroup: ViewGroup, attachToRoot: Boolean): ItemAddFavoriteBinding {
return ItemAddFavoriteWithoutNumberBindingAdapter(ItemAddFavoriteWithoutNumberBinding.inflate(layoutInflater, viewGroup, attachToRoot))
}
override fun bind(view: View): ItemAddFavoriteBinding {
return ItemAddFavoriteWithoutNumberBindingAdapter(ItemAddFavoriteWithoutNumberBinding.bind(view))
}
}
}
private interface ItemAddFavoriteBinding : ViewBinding {
val contactName: TextView
val contactNumber: TextView?
val contactTmb: ImageView
val contactCheckbox: MyAppCompatCheckbox
}
private class ItemAddFavoriteWithoutNumberBindingAdapter(val binding: ItemAddFavoriteWithoutNumberBinding) : ItemAddFavoriteBinding {
override val contactName: TextView = binding.contactName
override val contactNumber: TextView? = null
override val contactTmb: ImageView = binding.contactTmb
override val contactCheckbox: MyAppCompatCheckbox = binding.contactCheckbox
override fun getRoot(): View = binding.root
}
private class ItemAddFavoriteWithNumberBindingAdapter(val binding: ItemAddFavoriteWithNumberBinding) : ItemAddFavoriteBinding {
override val contactName: TextView = binding.contactName
override val contactNumber: TextView = binding.contactNumber
override val contactTmb: ImageView = binding.contactTmb
override val contactCheckbox: MyAppCompatCheckbox = binding.contactCheckbox
override fun getRoot(): View = binding.root
}
}

View file

@ -19,7 +19,7 @@ class ViewPagerAdapter(val activity: SimpleActivity, val currTabsList: ArrayList
val view = activity.layoutInflater.inflate(layout, container, false)
container.addView(view)
(view as MyViewPagerFragment).apply {
(view as MyViewPagerFragment<*>).apply {
setupFragment(activity)
setupColors(activity.getProperTextColor(), activity.getProperPrimaryColor())
}

View file

@ -6,8 +6,8 @@ import android.database.Cursor
import android.database.MatrixCursor
import android.net.Uri
import com.google.gson.Gson
import com.simplemobiletools.commons.helpers.MyContactsContentProvider
import com.simplemobiletools.commons.helpers.LocalContactsHelper
import com.simplemobiletools.commons.helpers.MyContactsContentProvider
import com.simplemobiletools.contacts.pro.extensions.config
class MyContactsContentProvider : ContentProvider() {

View file

@ -6,20 +6,20 @@ import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.contacts.pro.databinding.DialogChangeSortingBinding
import com.simplemobiletools.contacts.pro.extensions.config
import kotlinx.android.synthetic.main.dialog_change_sorting.view.*
class ChangeSortingDialog(val activity: BaseSimpleActivity, private val showCustomSorting: Boolean = false, private val callback: () -> Unit) {
private var currSorting = 0
private var config = activity.config
private var view = activity.layoutInflater.inflate(R.layout.dialog_change_sorting, null)
private val binding = DialogChangeSortingBinding.inflate(activity.layoutInflater)
init {
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() }
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(com.simplemobiletools.commons.R.string.ok) { dialog, which -> dialogConfirmed() }
.setNegativeButton(com.simplemobiletools.commons.R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this, R.string.sort_by)
activity.setupDialogStuff(binding.root, this, com.simplemobiletools.commons.R.string.sort_by)
}
currSorting = if (showCustomSorting && config.isCustomOrderSelected) {
@ -33,42 +33,41 @@ class ChangeSortingDialog(val activity: BaseSimpleActivity, private val showCust
}
private fun setupSortRadio() {
val sortingRadio = view.sorting_dialog_radio_sorting
val sortingRadio = binding.sortingDialogRadioSorting
sortingRadio.setOnCheckedChangeListener { group, checkedId ->
val isCustomSorting = checkedId == sortingRadio.sorting_dialog_radio_custom.id
view.sorting_dialog_radio_order.beGoneIf(isCustomSorting)
view.divider.beGoneIf(isCustomSorting)
val isCustomSorting = checkedId == binding.sortingDialogRadioCustom.id
binding.sortingDialogRadioOrder.beGoneIf(isCustomSorting)
binding.divider.beGoneIf(isCustomSorting)
}
val sortBtn = when {
currSorting and SORT_BY_FIRST_NAME != 0 -> sortingRadio.sorting_dialog_radio_first_name
currSorting and SORT_BY_MIDDLE_NAME != 0 -> sortingRadio.sorting_dialog_radio_middle_name
currSorting and SORT_BY_SURNAME != 0 -> sortingRadio.sorting_dialog_radio_surname
currSorting and SORT_BY_FULL_NAME != 0 -> sortingRadio.sorting_dialog_radio_full_name
currSorting and SORT_BY_CUSTOM != 0 -> sortingRadio.sorting_dialog_radio_custom
else -> sortingRadio.sorting_dialog_radio_date_created
currSorting and SORT_BY_FIRST_NAME != 0 -> binding.sortingDialogRadioFirstName
currSorting and SORT_BY_MIDDLE_NAME != 0 -> binding.sortingDialogRadioMiddleName
currSorting and SORT_BY_SURNAME != 0 -> binding.sortingDialogRadioSurname
currSorting and SORT_BY_FULL_NAME != 0 -> binding.sortingDialogRadioFullName
currSorting and SORT_BY_CUSTOM != 0 -> binding.sortingDialogRadioCustom
else -> binding.sortingDialogRadioDateCreated
}
sortBtn.isChecked = true
if (showCustomSorting) {
sortingRadio.sorting_dialog_radio_custom.isChecked = config.isCustomOrderSelected
binding.sortingDialogRadioCustom.isChecked = config.isCustomOrderSelected
}
view.sorting_dialog_radio_custom.beGoneIf(!showCustomSorting)
binding.sortingDialogRadioCustom.beGoneIf(!showCustomSorting)
}
private fun setupOrderRadio() {
val orderRadio = view.sorting_dialog_radio_order
var orderBtn = orderRadio.sorting_dialog_radio_ascending
var orderBtn = binding.sortingDialogRadioAscending
if (currSorting and SORT_DESCENDING != 0) {
orderBtn = orderRadio.sorting_dialog_radio_descending
orderBtn = binding.sortingDialogRadioDescending
}
orderBtn.isChecked = true
}
private fun dialogConfirmed() {
val sortingRadio = view.sorting_dialog_radio_sorting
val sortingRadio = binding.sortingDialogRadioSorting
var sorting = when (sortingRadio.checkedRadioButtonId) {
R.id.sorting_dialog_radio_first_name -> SORT_BY_FIRST_NAME
R.id.sorting_dialog_radio_middle_name -> SORT_BY_MIDDLE_NAME
@ -78,7 +77,7 @@ class ChangeSortingDialog(val activity: BaseSimpleActivity, private val showCust
else -> SORT_BY_DATE_CREATED
}
if (sorting != SORT_BY_CUSTOM && view.sorting_dialog_radio_order.checkedRadioButtonId == R.id.sorting_dialog_radio_descending) {
if (sorting != SORT_BY_CUSTOM && binding.sortingDialogRadioOrder.checkedRadioButtonId == R.id.sorting_dialog_radio_descending) {
sorting = sorting or SORT_DESCENDING
}

View file

@ -3,46 +3,44 @@ package com.simplemobiletools.contacts.pro.dialogs
import android.app.Activity
import android.view.ViewGroup
import android.widget.RadioGroup
import android.widget.RelativeLayout
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.extensions.beGone
import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.models.contacts.SocialAction
import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.contacts.pro.databinding.DialogChooseSocialBinding
import com.simplemobiletools.contacts.pro.databinding.ItemChooseSocialBinding
import com.simplemobiletools.contacts.pro.extensions.getPackageDrawable
import kotlinx.android.synthetic.main.dialog_choose_social.view.*
import kotlinx.android.synthetic.main.item_choose_social.view.*
class ChooseSocialDialog(val activity: Activity, actions: ArrayList<SocialAction>, val callback: (action: SocialAction) -> Unit) {
private lateinit var dialog: AlertDialog
init {
val view = activity.layoutInflater.inflate(R.layout.dialog_choose_social, null)
val binding = DialogChooseSocialBinding.inflate(activity.layoutInflater)
actions.sortBy { it.type }
actions.forEach { action ->
val item = (activity.layoutInflater.inflate(R.layout.item_choose_social, null) as RelativeLayout).apply {
item_social_label.text = action.label
setOnClickListener {
val item = ItemChooseSocialBinding.inflate(activity.layoutInflater).apply {
itemSocialLabel.text = action.label
root.setOnClickListener {
callback(action)
dialog.dismiss()
}
val drawable = activity.getPackageDrawable(action.packageName)
if (drawable == null) {
item_social_image.beGone()
itemSocialImage.beGone()
} else {
item_social_image.setImageDrawable(drawable)
itemSocialImage.setImageDrawable(drawable)
}
}
view.dialog_choose_social.addView(item, RadioGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT))
binding.dialogChooseSocial.addView(item.root, RadioGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT))
}
val builder = activity.getAlertDialogBuilder()
builder.apply {
activity.setupDialogStuff(view, this) { alertDialog ->
activity.setupDialogStuff(binding.root, this) { alertDialog ->
dialog = alertDialog
}
}

View file

@ -11,22 +11,22 @@ import com.simplemobiletools.commons.models.RadioItem
import com.simplemobiletools.commons.models.contacts.ContactSource
import com.simplemobiletools.commons.models.contacts.Group
import com.simplemobiletools.contacts.pro.R
import kotlinx.android.synthetic.main.dialog_create_new_group.view.*
import com.simplemobiletools.contacts.pro.databinding.DialogCreateNewGroupBinding
class CreateNewGroupDialog(val activity: BaseSimpleActivity, val callback: (newGroup: Group) -> Unit) {
init {
val view = activity.layoutInflater.inflate(R.layout.dialog_create_new_group, null)
val binding = DialogCreateNewGroupBinding.inflate(activity.layoutInflater)
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(com.simplemobiletools.commons.R.string.ok, null)
.setNegativeButton(com.simplemobiletools.commons.R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this, R.string.create_new_group) { alertDialog ->
alertDialog.showKeyboard(view.group_name)
activity.setupDialogStuff(binding.root, this, R.string.create_new_group) { alertDialog ->
alertDialog.showKeyboard(binding.groupName)
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(View.OnClickListener {
val name = view.group_name.value
val name = binding.groupName.value
if (name.isEmpty()) {
activity.toast(R.string.empty_name)
activity.toast(com.simplemobiletools.commons.R.string.empty_name)
return@OnClickListener
}

View file

@ -3,23 +3,22 @@ package com.simplemobiletools.contacts.pro.dialogs
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.contacts.pro.R
import kotlinx.android.synthetic.main.dialog_custom_label.view.*
import com.simplemobiletools.contacts.pro.databinding.DialogCustomLabelBinding
class CustomLabelDialog(val activity: BaseSimpleActivity, val callback: (label: String) -> Unit) {
init {
val view = activity.layoutInflater.inflate(R.layout.dialog_custom_label, null)
val binding = DialogCustomLabelBinding.inflate(activity.layoutInflater)
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(com.simplemobiletools.commons.R.string.ok, null)
.setNegativeButton(com.simplemobiletools.commons.R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this, R.string.label) { alertDialog ->
alertDialog.showKeyboard(view.custom_label_edittext)
activity.setupDialogStuff(binding.root, this, com.simplemobiletools.commons.R.string.label) { alertDialog ->
alertDialog.showKeyboard(binding.customLabelEdittext)
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
val label = view.custom_label_edittext.value
val label = binding.customLabelEdittext.value
if (label.isEmpty()) {
activity.toast(R.string.empty_name)
activity.toast(com.simplemobiletools.commons.R.string.empty_name)
return@setOnClickListener
}

View file

@ -10,7 +10,7 @@ class DateTimePatternInfoDialog(activity: BaseSimpleActivity) {
init {
val view = activity.layoutInflater.inflate(R.layout.datetime_pattern_info_layout, null)
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok) { _, _ -> { } }
.setPositiveButton(com.simplemobiletools.commons.R.string.ok) { _, _ -> { } }
.apply {
activity.setupDialogStuff(view, this)
}

View file

@ -1,18 +1,17 @@
package com.simplemobiletools.contacts.pro.dialogs
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.dialogs.FilePickerDialog
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.ContactsHelper
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.commons.models.contacts.*
import com.simplemobiletools.commons.models.contacts.Contact
import com.simplemobiletools.commons.models.contacts.ContactSource
import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.contacts.pro.activities.SimpleActivity
import com.simplemobiletools.contacts.pro.adapters.FilterContactSourcesAdapter
import com.simplemobiletools.contacts.pro.databinding.DialogExportContactsBinding
import com.simplemobiletools.contacts.pro.extensions.config
import kotlinx.android.synthetic.main.dialog_export_contacts.view.*
import java.io.File
class ExportContactsDialog(
@ -27,17 +26,17 @@ class ExportContactsDialog(
private var isContactsReady = false
init {
val view = (activity.layoutInflater.inflate(R.layout.dialog_export_contacts, null) as ViewGroup).apply {
export_contacts_folder.setText(activity.humanizePath(realPath))
export_contacts_filename.setText("contacts_${activity.getCurrentFormattedDateTime()}")
val binding = DialogExportContactsBinding.inflate(activity.layoutInflater).apply {
exportContactsFolder.setText(activity.humanizePath(realPath))
exportContactsFilename.setText("contacts_${activity.getCurrentFormattedDateTime()}")
if (hidePath) {
export_contacts_folder_hint.beGone()
exportContactsFolderHint.beGone()
} else {
export_contacts_folder.setOnClickListener {
activity.hideKeyboard(export_contacts_filename)
exportContactsFolder.setOnClickListener {
activity.hideKeyboard(exportContactsFilename)
FilePickerDialog(activity, realPath, false, showFAB = true) {
export_contacts_folder.setText(activity.humanizePath(it))
exportContactsFolder.setText(activity.humanizePath(it))
realPath = it
}
}
@ -57,29 +56,29 @@ class ExportContactsDialog(
}
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(com.simplemobiletools.commons.R.string.ok, null)
.setNegativeButton(com.simplemobiletools.commons.R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this, R.string.export_contacts) { alertDialog ->
activity.setupDialogStuff(binding.root, this, R.string.export_contacts) { alertDialog ->
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
if (view.export_contacts_list.adapter == null || ignoreClicks) {
if (binding.exportContactsList.adapter == null || ignoreClicks) {
return@setOnClickListener
}
val filename = view.export_contacts_filename.value
val filename = binding.exportContactsFilename.value
when {
filename.isEmpty() -> activity.toast(R.string.empty_name)
filename.isEmpty() -> activity.toast(com.simplemobiletools.commons.R.string.empty_name)
filename.isAValidFilename() -> {
val file = File(realPath, "$filename.vcf")
if (!hidePath && file.exists()) {
activity.toast(R.string.name_taken)
activity.toast(com.simplemobiletools.commons.R.string.name_taken)
return@setOnClickListener
}
ignoreClicks = true
ensureBackgroundThread {
activity.config.lastExportPath = file.absolutePath.getParentPath()
val selectedSources = (view.export_contacts_list.adapter as FilterContactSourcesAdapter).getSelectedContactSources()
val selectedSources = (binding.exportContactsList.adapter as FilterContactSourcesAdapter).getSelectedContactSources()
val ignoredSources = contactSources
.filter { !selectedSources.contains(it) }
.map { it.getFullIdentifier() }
@ -88,14 +87,15 @@ class ExportContactsDialog(
alertDialog.dismiss()
}
}
else -> activity.toast(R.string.invalid_name)
else -> activity.toast(com.simplemobiletools.commons.R.string.invalid_name)
}
}
}
}
}
private fun processDataIfReady(view: View) {
private fun processDataIfReady(binding: DialogExportContactsBinding) {
if (!isContactSourcesReady || !isContactsReady) {
return
}
@ -110,7 +110,7 @@ class ExportContactsDialog(
contactSources.addAll(contactSourcesWithCount)
activity.runOnUiThread {
view.export_contacts_list.adapter = FilterContactSourcesAdapter(activity, contactSourcesWithCount, activity.getVisibleContactSources())
binding.exportContactsList.adapter = FilterContactSourcesAdapter(activity, contactSourcesWithCount, activity.getVisibleContactSources())
}
}
}

View file

@ -2,20 +2,20 @@ package com.simplemobiletools.contacts.pro.dialogs
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
import com.simplemobiletools.commons.extensions.getVisibleContactSources
import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.helpers.ContactsHelper
import com.simplemobiletools.commons.helpers.SMT_PRIVATE
import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.commons.models.contacts.Contact
import com.simplemobiletools.commons.models.contacts.ContactSource
import com.simplemobiletools.contacts.pro.activities.SimpleActivity
import com.simplemobiletools.contacts.pro.adapters.FilterContactSourcesAdapter
import com.simplemobiletools.commons.extensions.getVisibleContactSources
import com.simplemobiletools.commons.helpers.ContactsHelper
import com.simplemobiletools.commons.models.contacts.*
import com.simplemobiletools.contacts.pro.databinding.DialogFilterContactSourcesBinding
import com.simplemobiletools.contacts.pro.extensions.config
import kotlinx.android.synthetic.main.dialog_filter_contact_sources.view.*
class FilterContactSourcesDialog(val activity: SimpleActivity, private val callback: () -> Unit) {
private var dialog: AlertDialog? = null
private val view = activity.layoutInflater.inflate(R.layout.dialog_filter_contact_sources, null)
private val binding = DialogFilterContactSourcesBinding.inflate(activity.layoutInflater)
private var contactSources = ArrayList<ContactSource>()
private var contacts = ArrayList<Contact>()
private var isContactSourcesReady = false
@ -55,14 +55,14 @@ class FilterContactSourcesDialog(val activity: SimpleActivity, private val callb
activity.runOnUiThread {
val selectedSources = activity.getVisibleContactSources()
view.filter_contact_sources_list.adapter = FilterContactSourcesAdapter(activity, contactSourcesWithCount, selectedSources)
binding.filterContactSourcesList.adapter = FilterContactSourcesAdapter(activity, contactSourcesWithCount, selectedSources)
if (dialog == null) {
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok) { dialogInterface, i -> confirmContactSources() }
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(com.simplemobiletools.commons.R.string.ok) { dialogInterface, i -> confirmContactSources() }
.setNegativeButton(com.simplemobiletools.commons.R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this) { alertDialog ->
activity.setupDialogStuff(binding.root, this) { alertDialog ->
dialog = alertDialog
}
}
@ -71,7 +71,7 @@ class FilterContactSourcesDialog(val activity: SimpleActivity, private val callb
}
private fun confirmContactSources() {
val selectedContactSources = (view.filter_contact_sources_list.adapter as FilterContactSourcesAdapter).getSelectedContactSources()
val selectedContactSources = (binding.filterContactSourcesList.adapter as FilterContactSourcesAdapter).getSelectedContactSources()
val ignoredContactSources = contactSources.filter { !selectedContactSources.contains(it) }.map {
if (it.type == SMT_PRIVATE) SMT_PRIVATE else it.getFullIdentifier()
}.toHashSet()

View file

@ -1,64 +1,66 @@
package com.simplemobiletools.contacts.pro.dialogs
import android.view.ViewGroup
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
import com.simplemobiletools.commons.extensions.getPublicContactSource
import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.commons.helpers.ContactsHelper
import com.simplemobiletools.commons.helpers.SMT_PRIVATE
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.contacts.pro.activities.SimpleActivity
import com.simplemobiletools.contacts.pro.databinding.DialogImportContactsBinding
import com.simplemobiletools.contacts.pro.extensions.config
import com.simplemobiletools.contacts.pro.extensions.showContactSourcePicker
import com.simplemobiletools.contacts.pro.helpers.VcfImporter
import com.simplemobiletools.contacts.pro.helpers.VcfImporter.ImportResult.IMPORT_FAIL
import kotlinx.android.synthetic.main.dialog_import_contacts.view.*
class ImportContactsDialog(val activity: SimpleActivity, val path: String, private val callback: (refreshView: Boolean) -> Unit) {
private var targetContactSource = ""
private var ignoreClicks = false
init {
val view = (activity.layoutInflater.inflate(R.layout.dialog_import_contacts, null) as ViewGroup).apply {
val binding = DialogImportContactsBinding.inflate(activity.layoutInflater).apply {
targetContactSource = activity.config.lastUsedContactSource
activity.getPublicContactSource(targetContactSource) {
import_contacts_title.setText(it)
importContactsTitle.setText(it)
if (it.isEmpty()) {
ContactsHelper(activity).getContactSources {
val localSource = it.firstOrNull { it.name == SMT_PRIVATE }
if (localSource != null) {
targetContactSource = localSource.name
activity.runOnUiThread {
import_contacts_title.setText(localSource.publicName)
importContactsTitle.setText(localSource.publicName)
}
}
}
}
}
import_contacts_title.setOnClickListener {
importContactsTitle.setOnClickListener {
activity.showContactSourcePicker(targetContactSource) {
targetContactSource = if (it == activity.getString(R.string.phone_storage_hidden)) SMT_PRIVATE else it
activity.getPublicContactSource(it) {
val title = if (it == "") activity.getString(R.string.phone_storage) else it
import_contacts_title.setText(title)
importContactsTitle.setText(title)
}
}
}
}
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(com.simplemobiletools.commons.R.string.ok, null)
.setNegativeButton(com.simplemobiletools.commons.R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this, R.string.import_contacts) { alertDialog ->
activity.setupDialogStuff(binding.root, this, R.string.import_contacts) { alertDialog ->
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
if (ignoreClicks) {
return@setOnClickListener
}
ignoreClicks = true
activity.toast(R.string.importing)
activity.toast(com.simplemobiletools.commons.R.string.importing)
ensureBackgroundThread {
val result = VcfImporter(activity).importContacts(path, targetContactSource)
handleParseResult(result)
@ -72,9 +74,9 @@ class ImportContactsDialog(val activity: SimpleActivity, val path: String, priva
private fun handleParseResult(result: VcfImporter.ImportResult) {
activity.toast(
when (result) {
VcfImporter.ImportResult.IMPORT_OK -> R.string.importing_successful
VcfImporter.ImportResult.IMPORT_PARTIAL -> R.string.importing_some_entries_failed
else -> R.string.importing_failed
VcfImporter.ImportResult.IMPORT_OK -> com.simplemobiletools.commons.R.string.importing_successful
VcfImporter.ImportResult.IMPORT_PARTIAL -> com.simplemobiletools.commons.R.string.importing_some_entries_failed
else -> com.simplemobiletools.commons.R.string.importing_failed
}
)
callback(result != IMPORT_FAIL)

View file

@ -1,7 +1,5 @@
package com.simplemobiletools.contacts.pro.dialogs
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.dialogs.FilePickerDialog
import com.simplemobiletools.commons.extensions.*
@ -12,15 +10,12 @@ import com.simplemobiletools.commons.models.contacts.ContactSource
import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.contacts.pro.activities.SimpleActivity
import com.simplemobiletools.contacts.pro.adapters.FilterContactSourcesAdapter
import com.simplemobiletools.contacts.pro.databinding.DialogManageAutomaticBackupsBinding
import com.simplemobiletools.contacts.pro.extensions.config
import kotlinx.android.synthetic.main.dialog_manage_automatic_backups.view.backup_contact_sources_list
import kotlinx.android.synthetic.main.dialog_manage_automatic_backups.view.backup_contacts_filename
import kotlinx.android.synthetic.main.dialog_manage_automatic_backups.view.backup_contacts_filename_hint
import kotlinx.android.synthetic.main.dialog_manage_automatic_backups.view.backup_contacts_folder
import java.io.File
class ManageAutoBackupsDialog(private val activity: SimpleActivity, onSuccess: () -> Unit) {
private val view = (activity.layoutInflater.inflate(R.layout.dialog_manage_automatic_backups, null) as ViewGroup)
private val binding = DialogManageAutomaticBackupsBinding.inflate(activity.layoutInflater)
private val config = activity.config
private var backupFolder = config.autoBackupFolder
private var contactSources = mutableListOf<ContactSource>()
@ -30,23 +25,23 @@ class ManageAutoBackupsDialog(private val activity: SimpleActivity, onSuccess: (
private var isContactsReady = false
init {
view.apply {
backup_contacts_folder.setText(activity.humanizePath(backupFolder))
binding.apply {
backupContactsFolder.setText(activity.humanizePath(backupFolder))
val filename = config.autoBackupFilename.ifEmpty {
"${activity.getString(R.string.contacts)}_%Y%M%D_%h%m%s"
}
backup_contacts_filename.setText(filename)
backup_contacts_filename_hint.setEndIconOnClickListener {
backupContactsFilename.setText(filename)
backupContactsFilenameHint.setEndIconOnClickListener {
DateTimePatternInfoDialog(activity)
}
backup_contacts_filename_hint.setEndIconOnLongClickListener {
backupContactsFilenameHint.setEndIconOnLongClickListener {
DateTimePatternInfoDialog(activity)
true
}
backup_contacts_folder.setOnClickListener {
backupContactsFolder.setOnClickListener {
selectBackupFolder()
}
@ -64,27 +59,27 @@ class ManageAutoBackupsDialog(private val activity: SimpleActivity, onSuccess: (
}
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(com.simplemobiletools.commons.R.string.ok, null)
.setNegativeButton(com.simplemobiletools.commons.R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this, R.string.manage_automatic_backups) { dialog ->
activity.setupDialogStuff(binding.root, this, com.simplemobiletools.commons.R.string.manage_automatic_backups) { dialog ->
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
if (view.backup_contact_sources_list.adapter == null) {
if (binding.backupContactSourcesList.adapter == null) {
return@setOnClickListener
}
val filename = view.backup_contacts_filename.value
val filename = binding.backupContactsFilename.value
when {
filename.isEmpty() -> activity.toast(R.string.empty_name)
filename.isEmpty() -> activity.toast(com.simplemobiletools.commons.R.string.empty_name)
filename.isAValidFilename() -> {
val file = File(backupFolder, "$filename.vcf")
if (file.exists() && !file.canWrite()) {
activity.toast(R.string.name_taken)
activity.toast(com.simplemobiletools.commons.R.string.name_taken)
return@setOnClickListener
}
val selectedSources = (view.backup_contact_sources_list.adapter as FilterContactSourcesAdapter).getSelectedContactSources()
val selectedSources = (binding.backupContactSourcesList.adapter as FilterContactSourcesAdapter).getSelectedContactSources()
if (selectedSources.isEmpty()) {
activity.toast(R.string.no_entries_for_exporting)
activity.toast(com.simplemobiletools.commons.R.string.no_entries_for_exporting)
return@setOnClickListener
}
@ -104,14 +99,14 @@ class ManageAutoBackupsDialog(private val activity: SimpleActivity, onSuccess: (
}
}
else -> activity.toast(R.string.invalid_name)
else -> activity.toast(com.simplemobiletools.commons.R.string.invalid_name)
}
}
}
}
}
private fun processDataIfReady(view: View) {
private fun processDataIfReady(binding: DialogManageAutomaticBackupsBinding) {
if (!isContactSourcesReady || !isContactsReady) {
return
}
@ -130,12 +125,12 @@ class ManageAutoBackupsDialog(private val activity: SimpleActivity, onSuccess: (
contactSources.addAll(contactSourcesWithCount)
activity.runOnUiThread {
view.backup_contact_sources_list.adapter = FilterContactSourcesAdapter(activity, contactSourcesWithCount, selectedContactSources.toList())
binding.backupContactSourcesList.adapter = FilterContactSourcesAdapter(activity, contactSourcesWithCount, selectedContactSources.toList())
}
}
private fun selectBackupFolder() {
activity.hideKeyboard(view.backup_contacts_filename)
activity.hideKeyboard(binding.backupContactsFilename)
FilePickerDialog(activity, backupFolder, false, showFAB = true) { path ->
activity.handleSAFDialog(path) { grantedSAF ->
if (!grantedSAF) {
@ -148,7 +143,7 @@ class ManageAutoBackupsDialog(private val activity: SimpleActivity, onSuccess: (
}
backupFolder = path
view.backup_contacts_folder.setText(activity.humanizePath(path))
binding.backupContactsFolder.setText(activity.humanizePath(path))
}
}
}

View file

@ -3,9 +3,9 @@ package com.simplemobiletools.contacts.pro.dialogs
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.commons.views.MyAppCompatCheckbox
import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.contacts.pro.extensions.config
class ManageVisibleFieldsDialog(val activity: BaseSimpleActivity, val callback: (hasSomethingChanged: Boolean) -> Unit) {
@ -39,8 +39,8 @@ class ManageVisibleFieldsDialog(val activity: BaseSimpleActivity, val callback:
}
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() }
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(com.simplemobiletools.commons.R.string.ok) { dialog, which -> dialogConfirmed() }
.setNegativeButton(com.simplemobiletools.commons.R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this)
}

View file

@ -28,8 +28,8 @@ class ManageVisibleTabsDialog(val activity: BaseSimpleActivity) {
}
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() }
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(com.simplemobiletools.commons.R.string.ok) { dialog, which -> dialogConfirmed() }
.setNegativeButton(com.simplemobiletools.commons.R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this)
}

View file

@ -4,21 +4,20 @@ import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.helpers.isSPlus
import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.contacts.pro.databinding.DialogDatePickerBinding
import com.simplemobiletools.contacts.pro.extensions.config
import kotlinx.android.synthetic.main.dialog_date_picker.view.*
import org.joda.time.DateTime
import java.util.*
import java.util.Calendar
class MyDatePickerDialog(val activity: BaseSimpleActivity, val defaultDate: String, val callback: (dateTag: String) -> Unit) {
private var view = activity.layoutInflater.inflate(R.layout.dialog_date_picker, null)
private val binding = DialogDatePickerBinding.inflate(activity.layoutInflater)
init {
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() }
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(com.simplemobiletools.commons.R.string.ok) { dialog, which -> dialogConfirmed() }
.setNegativeButton(com.simplemobiletools.commons.R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this) { alertDialog ->
activity.setupDialogStuff(binding.root, this) { alertDialog ->
val today = Calendar.getInstance()
var year = today.get(Calendar.YEAR)
var month = today.get(Calendar.MONTH)
@ -26,7 +25,7 @@ class MyDatePickerDialog(val activity: BaseSimpleActivity, val defaultDate: Stri
if (defaultDate.isNotEmpty()) {
val ignoreYear = defaultDate.startsWith("-")
view.hide_year.isChecked = ignoreYear
binding.hideYear.isChecked = ignoreYear
if (ignoreYear) {
month = defaultDate.substring(2, 4).toInt() - 1
@ -39,23 +38,23 @@ class MyDatePickerDialog(val activity: BaseSimpleActivity, val defaultDate: Stri
}
if (activity.config.isUsingSystemTheme && isSPlus()) {
val dialogBackgroundColor = activity.getColor(R.color.you_dialog_background_color)
view.dialog_holder.setBackgroundColor(dialogBackgroundColor)
view.date_picker.setBackgroundColor(dialogBackgroundColor)
val dialogBackgroundColor = activity.getColor(com.simplemobiletools.commons.R.color.you_dialog_background_color)
binding.dialogHolder.setBackgroundColor(dialogBackgroundColor)
binding.datePicker.setBackgroundColor(dialogBackgroundColor)
}
view.date_picker.updateDate(year, month, day)
binding.datePicker.updateDate(year, month, day)
}
}
}
private fun dialogConfirmed() {
val year = view.date_picker.year
val month = view.date_picker.month + 1
val day = view.date_picker.dayOfMonth
val year = binding.datePicker.year
val month = binding.datePicker.month + 1
val day = binding.datePicker.dayOfMonth
val date = DateTime().withDate(year, month, day).withTimeAtStartOfDay()
val tag = if (view.hide_year.isChecked) {
val tag = if (binding.hideYear.isChecked) {
date.toString("--MM-dd")
} else {
date.toString("yyyy-MM-dd")

View file

@ -6,30 +6,29 @@ import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.ContactsHelper
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.commons.models.contacts.Group
import com.simplemobiletools.contacts.pro.R
import kotlinx.android.synthetic.main.dialog_rename_group.view.*
import com.simplemobiletools.contacts.pro.databinding.DialogRenameGroupBinding
class RenameGroupDialog(val activity: BaseSimpleActivity, val group: Group, val callback: () -> Unit) {
init {
val view = activity.layoutInflater.inflate(R.layout.dialog_rename_group, null).apply {
rename_group_title.setText(group.title)
val binding = DialogRenameGroupBinding.inflate(activity.layoutInflater).apply {
renameGroupTitle.setText(group.title)
}
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(com.simplemobiletools.commons.R.string.ok, null)
.setNegativeButton(com.simplemobiletools.commons.R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this, R.string.rename) { alertDialog ->
alertDialog.showKeyboard(view.rename_group_title)
activity.setupDialogStuff(binding.root, this, com.simplemobiletools.commons.R.string.rename) { alertDialog ->
alertDialog.showKeyboard(binding.renameGroupTitle)
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
val newTitle = view.rename_group_title.value
val newTitle = binding.renameGroupTitle.value
if (newTitle.isEmpty()) {
activity.toast(R.string.empty_name)
activity.toast(com.simplemobiletools.commons.R.string.empty_name)
return@setOnClickListener
}
if (!newTitle.isAValidFilename()) {
activity.toast(R.string.invalid_name)
activity.toast(com.simplemobiletools.commons.R.string.invalid_name)
return@setOnClickListener
}

View file

@ -4,19 +4,18 @@ import androidx.appcompat.app.AlertDialog
import com.reddit.indicatorfastscroll.FastScrollItemIndicator
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.commons.models.contacts.Contact
import com.simplemobiletools.contacts.pro.activities.SimpleActivity
import com.simplemobiletools.contacts.pro.adapters.SelectContactsAdapter
import com.simplemobiletools.commons.models.contacts.*
import kotlinx.android.synthetic.main.dialog_select_contact.view.*
import java.util.*
import com.simplemobiletools.contacts.pro.databinding.DialogSelectContactBinding
import java.util.Locale
class SelectContactsDialog(
val activity: SimpleActivity, initialContacts: ArrayList<Contact>, val allowSelectMultiple: Boolean, val showOnlyContactsWithNumber: Boolean,
selectContacts: ArrayList<Contact>? = null, val callback: (addedContacts: ArrayList<Contact>, removedContacts: ArrayList<Contact>) -> Unit
) {
private var dialog: AlertDialog? = null
private var view = activity.layoutInflater.inflate(R.layout.dialog_select_contact, null)
private val binding = DialogSelectContactBinding.inflate(activity.layoutInflater)
private var initiallySelectedContacts = ArrayList<Contact>()
init {
@ -42,30 +41,30 @@ class SelectContactsDialog(
dialog!!.dismiss()
}
view.apply {
select_contact_list.adapter = SelectContactsAdapter(
binding.apply {
selectContactList.adapter = SelectContactsAdapter(
activity, allContacts, initiallySelectedContacts, allowSelectMultiple,
select_contact_list, contactClickCallback
selectContactList, contactClickCallback
)
if (context.areSystemAnimationsEnabled) {
select_contact_list.scheduleLayoutAnimation()
if (root.context.areSystemAnimationsEnabled) {
selectContactList.scheduleLayoutAnimation()
}
select_contact_list.beVisibleIf(allContacts.isNotEmpty())
select_contact_placeholder.beVisibleIf(allContacts.isEmpty())
selectContactList.beVisibleIf(allContacts.isNotEmpty())
selectContactPlaceholder.beVisibleIf(allContacts.isEmpty())
}
setupFastscroller(allContacts)
val builder = activity.getAlertDialogBuilder()
if (allowSelectMultiple) {
builder.setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() }
builder.setPositiveButton(com.simplemobiletools.commons.R.string.ok) { dialog, which -> dialogConfirmed() }
}
builder.setNegativeButton(R.string.cancel, null)
builder.setNegativeButton(com.simplemobiletools.commons.R.string.cancel, null)
builder.apply {
activity.setupDialogStuff(view, this) { alertDialog ->
activity.setupDialogStuff(binding.root, this) { alertDialog ->
dialog = alertDialog
}
}
@ -73,7 +72,7 @@ class SelectContactsDialog(
private fun dialogConfirmed() {
ensureBackgroundThread {
val adapter = view?.select_contact_list?.adapter as? SelectContactsAdapter
val adapter = binding.selectContactList.adapter as? SelectContactsAdapter
val selectedContacts = adapter?.getSelectedItemsSet()?.toList() ?: ArrayList()
val newlySelectedContacts = selectedContacts.filter { !initiallySelectedContacts.contains(it) } as ArrayList
@ -84,16 +83,16 @@ class SelectContactsDialog(
private fun setupFastscroller(allContacts: ArrayList<Contact>) {
val adjustedPrimaryColor = activity.getProperPrimaryColor()
view.apply {
letter_fastscroller?.textColor = context.getProperTextColor().getColorStateList()
letter_fastscroller?.pressedTextColor = adjustedPrimaryColor
letter_fastscroller_thumb?.fontSize = context.getTextSize()
letter_fastscroller_thumb?.textColor = adjustedPrimaryColor.getContrastColor()
letter_fastscroller_thumb?.thumbColor = adjustedPrimaryColor.getColorStateList()
letter_fastscroller_thumb.setupWithFastScroller(letter_fastscroller)
binding.apply {
letterFastscroller.textColor = root.context.getProperTextColor().getColorStateList()
letterFastscroller.pressedTextColor = adjustedPrimaryColor
letterFastscrollerThumb.fontSize = root.context.getTextSize()
letterFastscrollerThumb.textColor = adjustedPrimaryColor.getContrastColor()
letterFastscrollerThumb.thumbColor = adjustedPrimaryColor.getColorStateList()
letterFastscrollerThumb.setupWithFastScroller(letterFastscroller)
}
view.letter_fastscroller.setupWithRecyclerView(view.select_contact_list, { position ->
binding.letterFastscroller.setupWithRecyclerView(binding.selectContactList, { position ->
try {
val name = allContacts[position].getNameToDisplay()
val character = if (name.isNotEmpty()) name.substring(0, 1) else ""

View file

@ -1,6 +1,5 @@
package com.simplemobiletools.contacts.pro.dialogs
import android.view.ViewGroup
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.ContactsHelper
@ -8,12 +7,12 @@ import com.simplemobiletools.commons.models.contacts.Group
import com.simplemobiletools.commons.views.MyAppCompatCheckbox
import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.contacts.pro.activities.SimpleActivity
import kotlinx.android.synthetic.main.dialog_select_groups.view.*
import kotlinx.android.synthetic.main.item_checkbox.view.*
import kotlinx.android.synthetic.main.item_textview.view.*
import com.simplemobiletools.contacts.pro.databinding.DialogSelectGroupsBinding
import com.simplemobiletools.contacts.pro.databinding.ItemCheckboxBinding
import com.simplemobiletools.contacts.pro.databinding.ItemTextviewBinding
class SelectGroupsDialog(val activity: SimpleActivity, val selectedGroups: ArrayList<Group>, val callback: (newGroups: ArrayList<Group>) -> Unit) {
private val view = activity.layoutInflater.inflate(R.layout.dialog_select_groups, null) as ViewGroup
private val binding = DialogSelectGroupsBinding.inflate(activity.layoutInflater)
private val checkboxes = ArrayList<MyAppCompatCheckbox>()
private var groups = ArrayList<Group>()
private var dialog: AlertDialog? = null
@ -35,44 +34,44 @@ class SelectGroupsDialog(val activity: SimpleActivity, val selectedGroups: Array
addCreateNewGroupButton()
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() }
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(com.simplemobiletools.commons.R.string.ok) { dialog, which -> dialogConfirmed() }
.setNegativeButton(com.simplemobiletools.commons.R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this) { alertDialog ->
activity.setupDialogStuff(binding.root, this) { alertDialog ->
dialog = alertDialog
}
}
}
private fun addGroupCheckbox(group: Group) {
activity.layoutInflater.inflate(R.layout.item_checkbox, null, false).apply {
checkboxes.add(item_checkbox)
item_checkbox_holder.setOnClickListener {
item_checkbox.toggle()
ItemCheckboxBinding.inflate(activity.layoutInflater, null, false).apply {
checkboxes.add(itemCheckbox)
itemCheckboxHolder.setOnClickListener {
itemCheckbox.toggle()
}
item_checkbox.apply {
itemCheckbox.apply {
isChecked = selectedGroups.contains(group)
text = group.title
tag = group.id
setColors(activity.getProperTextColor(), activity.getProperPrimaryColor(), activity.getProperBackgroundColor())
}
view.dialog_groups_holder.addView(this)
binding.dialogGroupsHolder.addView(this.root)
}
}
private fun addCreateNewGroupButton() {
val newGroup = Group(0, activity.getString(R.string.create_new_group))
activity.layoutInflater.inflate(R.layout.item_textview, null, false).item_textview.apply {
ItemTextviewBinding.inflate(activity.layoutInflater, null, false).itemTextview.apply {
text = newGroup.title
tag = newGroup.id
setTextColor(activity.getProperTextColor())
view.dialog_groups_holder.addView(this)
binding.dialogGroupsHolder.addView(this)
setOnClickListener {
CreateNewGroupDialog(activity) {
selectedGroups.add(it)
groups.add(it)
view.dialog_groups_holder.removeViewAt(view.dialog_groups_holder.childCount - 1)
binding.dialogGroupsHolder.removeViewAt(binding.dialogGroupsHolder.childCount - 1)
addGroupCheckbox(it)
addCreateNewGroupButton()
}

View file

@ -59,7 +59,7 @@ fun BaseSimpleActivity.shareContacts(contacts: ArrayList<Contact>) {
val file = getTempFile(filename)
if (file == null) {
toast(R.string.unknown_error_occurred)
toast(com.simplemobiletools.commons.R.string.unknown_error_occurred)
return
}
@ -89,7 +89,7 @@ fun SimpleActivity.callContact(contact: Contact) {
if (contact.phoneNumbers.isNotEmpty()) {
tryInitiateCall(contact) { startCallIntent(it) }
} else {
toast(R.string.no_phone_number_found)
toast(com.simplemobiletools.commons.R.string.no_phone_number_found)
}
}

View file

@ -78,7 +78,7 @@ fun Context.backupContacts() {
val config = config
ContactsHelper(this).getContactsToExport(selectedContactSources = config.autoBackupContactSources) { contactsToBackup ->
if (contactsToBackup.isEmpty()) {
toast(R.string.no_entries_for_exporting)
toast(com.simplemobiletools.commons.R.string.no_entries_for_exporting)
config.lastAutoBackupTime = DateTime.now().millis
scheduleNextAutomaticBackup()
return@getContactsToExport
@ -136,8 +136,8 @@ fun Context.backupContacts() {
}
when (exportResult) {
ExportResult.EXPORT_OK -> toast(R.string.exporting_successful)
else -> toast(R.string.exporting_failed)
ExportResult.EXPORT_OK -> toast(com.simplemobiletools.commons.R.string.exporting_successful)
else -> toast(com.simplemobiletools.commons.R.string.exporting_failed)
}
config.lastAutoBackupTime = DateTime.now().millis

View file

@ -11,12 +11,22 @@ import com.simplemobiletools.contacts.pro.activities.InsertOrEditContactActivity
import com.simplemobiletools.contacts.pro.activities.MainActivity
import com.simplemobiletools.contacts.pro.activities.SimpleActivity
import com.simplemobiletools.contacts.pro.adapters.ContactsAdapter
import com.simplemobiletools.contacts.pro.databinding.FragmentContactsBinding
import com.simplemobiletools.contacts.pro.databinding.FragmentLettersLayoutBinding
import com.simplemobiletools.contacts.pro.extensions.config
import com.simplemobiletools.contacts.pro.helpers.LOCATION_CONTACTS_TAB
import com.simplemobiletools.contacts.pro.interfaces.RefreshContactsListener
import kotlinx.android.synthetic.main.fragment_layout.view.fragment_list
class ContactsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet) {
class ContactsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment<MyViewPagerFragment.LetterLayout>(context, attributeSet) {
private lateinit var binding: FragmentContactsBinding
override fun onFinishInflate() {
super.onFinishInflate()
binding = FragmentContactsBinding.bind(this)
innerBinding = LetterLayout(FragmentLettersLayoutBinding.bind(binding.root))
}
override fun fabClicked() {
activity?.hideKeyboard()
Intent(context, EditContactActivity::class.java).apply {
@ -34,7 +44,7 @@ class ContactsFragment(context: Context, attributeSet: AttributeSet) : MyViewPag
fun setupContactsAdapter(contacts: List<Contact>) {
setupViewVisibility(contacts.isNotEmpty())
val currAdapter = fragment_list.adapter
val currAdapter = innerBinding.fragmentList.adapter
if (currAdapter == null || forceListRedraw) {
forceListRedraw = false
@ -46,16 +56,16 @@ class ContactsFragment(context: Context, attributeSet: AttributeSet) : MyViewPag
refreshListener = activity as RefreshContactsListener,
location = location,
removeListener = null,
recyclerView = fragment_list,
recyclerView = innerBinding.fragmentList,
enableDrag = false,
) {
(activity as RefreshContactsListener).contactClicked(it as Contact)
}.apply {
fragment_list.adapter = this
innerBinding.fragmentList.adapter = this
}
if (context.areSystemAnimationsEnabled) {
fragment_list.scheduleLayoutAnimation()
innerBinding.fragmentList.scheduleLayoutAnimation()
}
} else {
(currAdapter as ContactsAdapter).apply {

View file

@ -17,17 +17,23 @@ import com.simplemobiletools.commons.views.MyRecyclerView
import com.simplemobiletools.contacts.pro.activities.MainActivity
import com.simplemobiletools.contacts.pro.activities.SimpleActivity
import com.simplemobiletools.contacts.pro.adapters.ContactsAdapter
import com.simplemobiletools.contacts.pro.databinding.FragmentFavoritesBinding
import com.simplemobiletools.contacts.pro.databinding.FragmentLettersLayoutBinding
import com.simplemobiletools.contacts.pro.dialogs.SelectContactsDialog
import com.simplemobiletools.contacts.pro.extensions.config
import com.simplemobiletools.contacts.pro.helpers.LOCATION_FAVORITES_TAB
import com.simplemobiletools.contacts.pro.interfaces.RefreshContactsListener
import kotlinx.android.synthetic.main.dialog_select_contact.view.letter_fastscroller
import kotlinx.android.synthetic.main.fragment_favorites.view.favorites_fragment
import kotlinx.android.synthetic.main.fragment_layout.view.fragment_list
class FavoritesFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet) {
class FavoritesFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment<MyViewPagerFragment.LetterLayout>(context, attributeSet) {
private var favouriteContacts = listOf<Contact>()
private var zoomListener: MyRecyclerView.MyZoomListener? = null
lateinit var binding: FragmentFavoritesBinding
override fun onFinishInflate() {
super.onFinishInflate()
binding = FragmentFavoritesBinding.bind(this)
innerBinding = LetterLayout(FragmentLettersLayoutBinding.bind(binding.root))
}
override fun fabClicked() {
finishActMode()
@ -38,7 +44,7 @@ class FavoritesFragment(context: Context, attributeSet: AttributeSet) : MyViewPa
showAddFavoritesDialog()
}
private fun getRecyclerAdapter() = fragment_list.adapter as? ContactsAdapter
private fun getRecyclerAdapter() = innerBinding.fragmentList.adapter as? ContactsAdapter
private fun showAddFavoritesDialog() {
SelectContactsDialog(activity!!, allContacts, true, false) { addedContacts, removedContacts ->
@ -71,15 +77,15 @@ class FavoritesFragment(context: Context, attributeSet: AttributeSet) : MyViewPa
location = location,
viewType = viewType,
removeListener = null,
recyclerView = fragment_list,
recyclerView = innerBinding.fragmentList,
enableDrag = true,
) {
(activity as RefreshContactsListener).contactClicked(it as Contact)
}.apply {
fragment_list.adapter = this
innerBinding.fragmentList.adapter = this
setupZoomListener(zoomListener)
onDragEndListener = {
val adapter = fragment_list?.adapter
val adapter = innerBinding.fragmentList.adapter
if (adapter is ContactsAdapter) {
val items = adapter.contactItems
saveCustomOrderToPrefs(items)
@ -89,7 +95,7 @@ class FavoritesFragment(context: Context, attributeSet: AttributeSet) : MyViewPa
}
if (context.areSystemAnimationsEnabled) {
fragment_list.scheduleLayoutAnimation()
innerBinding.fragmentList.scheduleLayoutAnimation()
}
} else {
currAdapter.apply {
@ -110,17 +116,17 @@ class FavoritesFragment(context: Context, attributeSet: AttributeSet) : MyViewPa
val spanCount = context.config.contactsGridColumnCount
if (viewType == VIEW_TYPE_GRID) {
favorites_fragment.letter_fastscroller.beGone()
fragment_list.layoutManager = MyGridLayoutManager(context, spanCount)
innerBinding.letterFastscroller.beGone()
innerBinding.fragmentList.layoutManager = MyGridLayoutManager(context, spanCount)
} else {
favorites_fragment.letter_fastscroller.beVisible()
fragment_list.layoutManager = MyLinearLayoutManager(context)
innerBinding.letterFastscroller.beVisible()
innerBinding.fragmentList.layoutManager = MyLinearLayoutManager(context)
}
}
private fun initZoomListener(viewType: Int) {
if (viewType == VIEW_TYPE_GRID) {
val layoutManager = fragment_list.layoutManager as MyGridLayoutManager
val layoutManager = innerBinding.fragmentList.layoutManager as MyGridLayoutManager
zoomListener = object : MyRecyclerView.MyZoomListener {
override fun zoomIn() {
if (layoutManager.spanCount > 1) {
@ -156,7 +162,7 @@ class FavoritesFragment(context: Context, attributeSet: AttributeSet) : MyViewPa
}
fun columnCountChanged() {
(fragment_list.layoutManager as? MyGridLayoutManager)?.spanCount = context!!.config.contactsGridColumnCount
(innerBinding.fragmentList.layoutManager as? MyGridLayoutManager)?.spanCount = context!!.config.contactsGridColumnCount
getRecyclerAdapter()?.apply {
notifyItemRangeChanged(0, favouriteContacts.size)
}

View file

@ -5,9 +5,20 @@ 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.databinding.FragmentGroupsBinding
import com.simplemobiletools.contacts.pro.databinding.FragmentLayoutBinding
import com.simplemobiletools.contacts.pro.dialogs.CreateNewGroupDialog
class GroupsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet) {
class GroupsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment<MyViewPagerFragment.FragmentLayout>(context, attributeSet) {
private lateinit var binding: FragmentGroupsBinding
override fun onFinishInflate() {
super.onFinishInflate()
binding = FragmentGroupsBinding.bind(this)
innerBinding = FragmentLayout(FragmentLayoutBinding.bind(binding.root))
}
override fun fabClicked() {
finishActMode()
showNewGroupsDialog()

View file

@ -4,13 +4,20 @@ import android.content.Context
import android.content.Intent
import android.util.AttributeSet
import android.view.ViewGroup
import android.widget.RelativeLayout
import androidx.coordinatorlayout.widget.CoordinatorLayout
import com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller
import com.reddit.indicatorfastscroll.FastScrollItemIndicator
import com.reddit.indicatorfastscroll.FastScrollerThumbView
import com.reddit.indicatorfastscroll.FastScrollerView
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.commons.models.contacts.Contact
import com.simplemobiletools.commons.models.contacts.Group
import com.simplemobiletools.commons.views.MyFloatingActionButton
import com.simplemobiletools.commons.views.MyRecyclerView
import com.simplemobiletools.commons.views.MyTextView
import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.contacts.pro.activities.GroupContactsActivity
import com.simplemobiletools.contacts.pro.activities.InsertOrEditContactActivity
@ -18,20 +25,18 @@ import com.simplemobiletools.contacts.pro.activities.MainActivity
import com.simplemobiletools.contacts.pro.activities.SimpleActivity
import com.simplemobiletools.contacts.pro.adapters.ContactsAdapter
import com.simplemobiletools.contacts.pro.adapters.GroupsAdapter
import com.simplemobiletools.contacts.pro.databinding.FragmentLayoutBinding
import com.simplemobiletools.contacts.pro.databinding.FragmentLettersLayoutBinding
import com.simplemobiletools.contacts.pro.extensions.config
import com.simplemobiletools.contacts.pro.helpers.AVOID_CHANGING_TEXT_TAG
import com.simplemobiletools.contacts.pro.helpers.AVOID_CHANGING_VISIBILITY_TAG
import com.simplemobiletools.contacts.pro.helpers.Config
import com.simplemobiletools.contacts.pro.helpers.GROUP
import com.simplemobiletools.contacts.pro.interfaces.RefreshContactsListener
import kotlinx.android.synthetic.main.dialog_select_contact.view.letter_fastscroller
import kotlinx.android.synthetic.main.fragment_contacts.view.contacts_fragment
import kotlinx.android.synthetic.main.fragment_favorites.view.favorites_fragment
import kotlinx.android.synthetic.main.fragment_layout.view.*
import kotlinx.android.synthetic.main.fragment_letters_layout.view.letter_fastscroller_thumb
import java.util.Locale
abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet) : CoordinatorLayout(context, attributeSet) {
abstract class MyViewPagerFragment<BINDING : MyViewPagerFragment.InnerBinding>(context: Context, attributeSet: AttributeSet) :
CoordinatorLayout(context, attributeSet) {
protected var activity: SimpleActivity? = null
protected var allContacts = ArrayList<Contact>()
@ -39,67 +44,69 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
private var contactsIgnoringSearch = listOf<Contact>()
private var groupsIgnoringSearch = listOf<Group>()
private lateinit var config: Config
protected lateinit var innerBinding: BINDING
var skipHashComparing = false
var forceListRedraw = false
fun setupFragment(activity: SimpleActivity) {
config = activity.config
if (this.activity == null) {
this.activity = activity
fragment_fab?.beGoneIf(activity is InsertOrEditContactActivity)
fragment_fab?.setOnClickListener {
innerBinding.fragmentFab.beGoneIf(activity is InsertOrEditContactActivity)
innerBinding.fragmentFab.setOnClickListener {
fabClicked()
}
fragment_placeholder_2?.setOnClickListener {
innerBinding.fragmentPlaceholder2.setOnClickListener {
placeholderClicked()
}
fragment_placeholder_2?.underlineText()
innerBinding.fragmentPlaceholder2.underlineText()
when {
this is ContactsFragment -> {
fragment_fab.contentDescription = activity.getString(R.string.create_new_contact)
when (this) {
is ContactsFragment -> {
innerBinding.fragmentFab.contentDescription = activity.getString(com.simplemobiletools.commons.R.string.create_new_contact)
}
this is FavoritesFragment -> {
fragment_placeholder.text = activity.getString(R.string.no_favorites)
fragment_placeholder_2.text = activity.getString(R.string.add_favorites)
fragment_fab.contentDescription = activity.getString(R.string.add_favorites)
is FavoritesFragment -> {
innerBinding.fragmentPlaceholder.text = activity.getString(R.string.no_favorites)
innerBinding.fragmentPlaceholder2.text = activity.getString(com.simplemobiletools.commons.R.string.add_favorites)
innerBinding.fragmentFab.contentDescription = activity.getString(com.simplemobiletools.commons.R.string.add_favorites)
}
this is GroupsFragment -> {
fragment_placeholder.text = activity.getString(R.string.no_group_created)
fragment_placeholder_2.text = activity.getString(R.string.create_group)
fragment_fab.contentDescription = activity.getString(R.string.create_group)
is GroupsFragment -> {
innerBinding.fragmentPlaceholder.text = activity.getString(R.string.no_group_created)
innerBinding.fragmentPlaceholder2.text = activity.getString(R.string.create_group)
innerBinding.fragmentFab.contentDescription = activity.getString(R.string.create_group)
}
}
}
}
fun setupColors(textColor: Int, adjustedPrimaryColor: Int) {
when {
this is GroupsFragment -> (fragment_list.adapter as? GroupsAdapter)?.updateTextColor(textColor)
else -> (fragment_list.adapter as? ContactsAdapter)?.apply {
when (this) {
is GroupsFragment -> (innerBinding.fragmentList.adapter as? GroupsAdapter)?.updateTextColor(textColor)
else -> (innerBinding.fragmentList.adapter as? ContactsAdapter)?.apply {
updateTextColor(textColor)
}
}
context.updateTextColors(fragment_wrapper.parent as ViewGroup)
fragment_fastscroller?.updateColors(adjustedPrimaryColor)
fragment_placeholder_2?.setTextColor(adjustedPrimaryColor)
context.updateTextColors(innerBinding.fragmentWrapper.parent as ViewGroup)
innerBinding.fragmentFastscroller?.updateColors(adjustedPrimaryColor)
innerBinding.fragmentPlaceholder2.setTextColor(adjustedPrimaryColor)
letter_fastscroller?.textColor = textColor.getColorStateList()
letter_fastscroller?.pressedTextColor = adjustedPrimaryColor
letter_fastscroller_thumb?.fontSize = context.getTextSize()
letter_fastscroller_thumb?.textColor = adjustedPrimaryColor.getContrastColor()
letter_fastscroller_thumb?.thumbColor = adjustedPrimaryColor.getColorStateList()
innerBinding.letterFastscroller?.textColor = textColor.getColorStateList()
innerBinding.letterFastscroller?.pressedTextColor = adjustedPrimaryColor
innerBinding.letterFastscrollerThumb?.fontSize = context.getTextSize()
innerBinding.letterFastscrollerThumb?.textColor = adjustedPrimaryColor.getContrastColor()
innerBinding.letterFastscrollerThumb?.thumbColor = adjustedPrimaryColor.getColorStateList()
}
fun startNameWithSurnameChanged(startNameWithSurname: Boolean) {
if (this !is GroupsFragment) {
(fragment_list.adapter as? ContactsAdapter)?.apply {
(innerBinding.fragmentList.adapter as? ContactsAdapter)?.apply {
config.sorting = if (startNameWithSurname) SORT_BY_SURNAME else SORT_BY_FIRST_NAME
(this@MyViewPagerFragment.activity!! as MainActivity).refreshContacts(TAB_CONTACTS or TAB_FAVORITES)
}
@ -150,10 +157,10 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
setupContacts(filtered)
if (placeholderText != null) {
fragment_placeholder.text = placeholderText
fragment_placeholder.tag = AVOID_CHANGING_TEXT_TAG
fragment_placeholder_2.beGone()
fragment_placeholder_2.tag = AVOID_CHANGING_VISIBILITY_TAG
innerBinding.fragmentPlaceholder.text = placeholderText
innerBinding.fragmentPlaceholder.tag = AVOID_CHANGING_TEXT_TAG
innerBinding.fragmentPlaceholder2.beGone()
innerBinding.fragmentPlaceholder2.tag = AVOID_CHANGING_VISIBILITY_TAG
}
}
}
@ -177,22 +184,22 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
when (this) {
is GroupsFragment -> {
setupGroupsAdapter(contacts) {
groupsIgnoringSearch = (fragment_list?.adapter as? GroupsAdapter)?.groups ?: ArrayList()
groupsIgnoringSearch = (innerBinding.fragmentList.adapter as? GroupsAdapter)?.groups ?: ArrayList()
}
}
is FavoritesFragment -> {
favorites_fragment.setupContactsFavoritesAdapter(contacts)
contactsIgnoringSearch = (fragment_list?.adapter as? ContactsAdapter)?.contactItems ?: listOf()
setupContactsFavoritesAdapter(contacts)
contactsIgnoringSearch = (innerBinding.fragmentList.adapter as? ContactsAdapter)?.contactItems ?: listOf()
setupLetterFastscroller(contacts)
letter_fastscroller_thumb.setupWithFastScroller(letter_fastscroller)
innerBinding.letterFastscrollerThumb.setupWithFastScroller(innerBinding.letterFastscroller)
}
else -> {
contacts_fragment.setupContactsAdapter(contacts)
contactsIgnoringSearch = (fragment_list?.adapter as? ContactsAdapter)?.contactItems ?: ArrayList()
is ContactsFragment -> {
setupContactsAdapter(contacts)
contactsIgnoringSearch = (innerBinding.fragmentList.adapter as? ContactsAdapter)?.contactItems ?: ArrayList()
setupLetterFastscroller(contacts)
letter_fastscroller_thumb.setupWithFastScroller(letter_fastscroller)
innerBinding.letterFastscrollerThumb.setupWithFastScroller(innerBinding.letterFastscroller)
}
}
}
@ -210,24 +217,24 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
storedGroups = storedGroups.asSequence().sortedWith(compareBy { it.title.toLowerCase().normalizeString() }).toMutableList() as ArrayList<Group>
fragment_placeholder_2.beVisibleIf(storedGroups.isEmpty())
fragment_placeholder.beVisibleIf(storedGroups.isEmpty())
fragment_fastscroller.beVisibleIf(storedGroups.isNotEmpty())
innerBinding.fragmentPlaceholder2.beVisibleIf(storedGroups.isEmpty())
innerBinding.fragmentPlaceholder.beVisibleIf(storedGroups.isEmpty())
innerBinding.letterFastscroller?.beVisibleIf(storedGroups.isNotEmpty())
val currAdapter = fragment_list.adapter
val currAdapter = innerBinding.fragmentList.adapter
if (currAdapter == null) {
GroupsAdapter(activity as SimpleActivity, storedGroups, activity as RefreshContactsListener, fragment_list) {
GroupsAdapter(activity as SimpleActivity, storedGroups, activity as RefreshContactsListener, innerBinding.fragmentList) {
activity?.hideKeyboard()
Intent(activity, GroupContactsActivity::class.java).apply {
putExtra(GROUP, it as Group)
activity!!.startActivity(this)
}
}.apply {
fragment_list.adapter = this
innerBinding.fragmentList.adapter = this
}
if (context.areSystemAnimationsEnabled) {
fragment_list.scheduleLayoutAnimation()
innerBinding.fragmentList.scheduleLayoutAnimation()
}
} else {
(currAdapter as GroupsAdapter).apply {
@ -242,12 +249,12 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
fun showContactThumbnailsChanged(showThumbnails: Boolean) {
if (this is GroupsFragment) {
(fragment_list.adapter as? GroupsAdapter)?.apply {
(innerBinding.fragmentList.adapter as? GroupsAdapter)?.apply {
showContactThumbnails = showThumbnails
notifyDataSetChanged()
}
} else {
(fragment_list.adapter as? ContactsAdapter)?.apply {
(innerBinding.fragmentList.adapter as? ContactsAdapter)?.apply {
showContactThumbnails = showThumbnails
notifyDataSetChanged()
}
@ -256,7 +263,7 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
fun setupLetterFastscroller(contacts: List<Contact>) {
val sorting = context.config.sorting
letter_fastscroller.setupWithRecyclerView(fragment_list, { position ->
innerBinding.letterFastscroller?.setupWithRecyclerView(innerBinding.fragmentList, { position ->
try {
val contact = contacts[position]
var name = when {
@ -282,12 +289,12 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
fun fontSizeChanged() {
if (this is GroupsFragment) {
(fragment_list.adapter as? GroupsAdapter)?.apply {
(innerBinding.fragmentList.adapter as? GroupsAdapter)?.apply {
fontSize = activity.getTextSize()
notifyDataSetChanged()
}
} else {
(fragment_list.adapter as? ContactsAdapter)?.apply {
(innerBinding.fragmentList.adapter as? ContactsAdapter)?.apply {
fontSize = activity.getTextSize()
notifyDataSetChanged()
}
@ -295,11 +302,11 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
}
fun finishActMode() {
(fragment_list.adapter as? MyRecyclerViewAdapter)?.finishActMode()
(innerBinding.fragmentList.adapter as? MyRecyclerViewAdapter)?.finishActMode()
}
fun onSearchQueryChanged(text: String) {
val adapter = fragment_list.adapter
val adapter = innerBinding.fragmentList.adapter
if (adapter is ContactsAdapter) {
val shouldNormalize = text.normalizeString() == text
val filtered = contactsIgnoringSearch.filter {
@ -324,12 +331,12 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
}
if (filtered.isEmpty() && this@MyViewPagerFragment is FavoritesFragment) {
if (fragment_placeholder.tag != AVOID_CHANGING_TEXT_TAG) {
fragment_placeholder.text = activity?.getString(R.string.no_contacts_found)
if (innerBinding.fragmentPlaceholder.tag != AVOID_CHANGING_TEXT_TAG) {
innerBinding.fragmentPlaceholder.text = activity?.getString(com.simplemobiletools.commons.R.string.no_contacts_found)
}
}
fragment_placeholder.beVisibleIf(filtered.isEmpty())
innerBinding.fragmentPlaceholder.beVisibleIf(filtered.isEmpty())
(adapter as? ContactsAdapter)?.updateItems(filtered, text.normalizeString())
setupLetterFastscroller(filtered)
} else if (adapter is GroupsAdapter) {
@ -338,39 +345,72 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
} as ArrayList
if (filtered.isEmpty()) {
fragment_placeholder.text = activity?.getString(R.string.no_items_found)
innerBinding.fragmentPlaceholder.text = activity?.getString(com.simplemobiletools.commons.R.string.no_items_found)
}
fragment_placeholder.beVisibleIf(filtered.isEmpty())
innerBinding.fragmentPlaceholder.beVisibleIf(filtered.isEmpty())
(adapter as? GroupsAdapter)?.updateItems(filtered, text)
}
}
fun onSearchClosed() {
if (fragment_list.adapter is ContactsAdapter) {
(fragment_list.adapter as? ContactsAdapter)?.updateItems(contactsIgnoringSearch)
if (innerBinding.fragmentList.adapter is ContactsAdapter) {
(innerBinding.fragmentList.adapter as? ContactsAdapter)?.updateItems(contactsIgnoringSearch)
setupLetterFastscroller(contactsIgnoringSearch)
setupViewVisibility(contactsIgnoringSearch.isNotEmpty())
} else if (fragment_list.adapter is GroupsAdapter) {
(fragment_list.adapter as? GroupsAdapter)?.updateItems(ArrayList(groupsIgnoringSearch))
} else if (innerBinding.fragmentList.adapter is GroupsAdapter) {
(innerBinding.fragmentList.adapter as? GroupsAdapter)?.updateItems(ArrayList(groupsIgnoringSearch))
setupViewVisibility(groupsIgnoringSearch.isNotEmpty())
}
if (this is FavoritesFragment && fragment_placeholder.tag != AVOID_CHANGING_TEXT_TAG) {
fragment_placeholder.text = activity?.getString(R.string.no_favorites)
if (this is FavoritesFragment && innerBinding.fragmentPlaceholder.tag != AVOID_CHANGING_TEXT_TAG) {
innerBinding.fragmentPlaceholder.text = activity?.getString(R.string.no_favorites)
}
}
fun setupViewVisibility(hasItemsToShow: Boolean) {
if (fragment_placeholder_2.tag != AVOID_CHANGING_VISIBILITY_TAG) {
fragment_placeholder_2?.beVisibleIf(!hasItemsToShow)
if (innerBinding.fragmentPlaceholder2.tag != AVOID_CHANGING_VISIBILITY_TAG) {
innerBinding.fragmentPlaceholder2.beVisibleIf(!hasItemsToShow)
}
fragment_placeholder?.beVisibleIf(!hasItemsToShow)
fragment_list.beVisibleIf(hasItemsToShow)
innerBinding.fragmentPlaceholder.beVisibleIf(!hasItemsToShow)
innerBinding.fragmentList.beVisibleIf(hasItemsToShow)
}
abstract fun fabClicked()
abstract fun placeholderClicked()
interface InnerBinding {
val fragmentList: MyRecyclerView
val fragmentPlaceholder: MyTextView
val fragmentPlaceholder2: MyTextView
val fragmentFab: MyFloatingActionButton
val fragmentWrapper: RelativeLayout
val letterFastscroller: FastScrollerView?
val letterFastscrollerThumb: FastScrollerThumbView?
val fragmentFastscroller: RecyclerViewFastScroller?
}
class LetterLayout(val binding: FragmentLettersLayoutBinding) : InnerBinding {
override val fragmentList: MyRecyclerView = binding.fragmentList
override val fragmentPlaceholder: MyTextView = binding.fragmentPlaceholder
override val fragmentPlaceholder2: MyTextView = binding.fragmentPlaceholder2
override val fragmentFab: MyFloatingActionButton = binding.fragmentFab
override val fragmentWrapper: RelativeLayout = binding.fragmentWrapper
override val letterFastscroller: FastScrollerView = binding.letterFastscroller
override val letterFastscrollerThumb: FastScrollerThumbView = binding.letterFastscrollerThumb
override val fragmentFastscroller: RecyclerViewFastScroller? = null
}
class FragmentLayout(val binding: FragmentLayoutBinding) : InnerBinding {
override val fragmentList: MyRecyclerView = binding.fragmentList
override val fragmentPlaceholder: MyTextView = binding.fragmentPlaceholder
override val fragmentPlaceholder2: MyTextView = binding.fragmentPlaceholder2
override val fragmentFab: MyFloatingActionButton = binding.fragmentFab
override val fragmentWrapper: RelativeLayout = binding.fragmentWrapper
override val letterFastscroller: FastScrollerView? = null
override val letterFastscrollerThumb: FastScrollerThumbView? = null
override val fragmentFastscroller: RecyclerViewFastScroller = binding.fragmentFastscroller
}
}

View file

@ -15,6 +15,7 @@ class Config(context: Context) : BaseConfig(context) {
var autoBackupContactSources: Set<String>
get() = prefs.getStringSet(AUTO_BACKUP_CONTACT_SOURCES, setOf())!!
set(autoBackupContactSources) = prefs.edit().remove(AUTO_BACKUP_CONTACT_SOURCES).putStringSet(AUTO_BACKUP_CONTACT_SOURCES, autoBackupContactSources).apply()
set(autoBackupContactSources) = prefs.edit().remove(AUTO_BACKUP_CONTACT_SOURCES).putStringSet(AUTO_BACKUP_CONTACT_SOURCES, autoBackupContactSources)
.apply()
}

View file

@ -13,7 +13,6 @@ import com.simplemobiletools.commons.extensions.getDateTimeFromDateString
import com.simplemobiletools.commons.extensions.showErrorToast
import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.commons.models.contacts.Contact
import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.contacts.pro.helpers.VcfExporter.ExportResult.EXPORT_FAIL
import ezvcard.Ezvcard
import ezvcard.VCard
@ -21,7 +20,7 @@ import ezvcard.VCardVersion
import ezvcard.parameter.ImageType
import ezvcard.property.*
import java.io.OutputStream
import java.util.*
import java.util.Calendar
class VcfExporter {
enum class ExportResult {
@ -46,7 +45,7 @@ class VcfExporter {
}
if (showExportingToast) {
activity.toast(R.string.exporting)
activity.toast(com.simplemobiletools.commons.R.string.exporting)
}
val cards = ArrayList<VCard>()

View file

@ -7,16 +7,16 @@ import android.provider.ContactsContract.CommonDataKinds.Im
import android.provider.ContactsContract.CommonDataKinds.Phone
import android.provider.ContactsContract.CommonDataKinds.StructuredPostal
import android.widget.Toast
import com.simplemobiletools.commons.extensions.getCachePhoto
import com.simplemobiletools.commons.extensions.groupsDB
import com.simplemobiletools.commons.extensions.normalizePhoneNumber
import com.simplemobiletools.commons.extensions.showErrorToast
import com.simplemobiletools.commons.extensions.getCachePhoto
import com.simplemobiletools.contacts.pro.extensions.getCachePhotoUri
import com.simplemobiletools.commons.helpers.ContactsHelper
import com.simplemobiletools.commons.helpers.DEFAULT_MIMETYPE
import com.simplemobiletools.commons.models.PhoneNumber
import com.simplemobiletools.commons.models.contacts.*
import com.simplemobiletools.contacts.pro.activities.SimpleActivity
import com.simplemobiletools.contacts.pro.extensions.getCachePhotoUri
import com.simplemobiletools.contacts.pro.helpers.VcfImporter.ImportResult.IMPORT_FAIL
import com.simplemobiletools.contacts.pro.helpers.VcfImporter.ImportResult.IMPORT_OK
import com.simplemobiletools.contacts.pro.helpers.VcfImporter.ImportResult.IMPORT_PARTIAL
@ -26,7 +26,7 @@ import ezvcard.util.PartialDate
import java.io.File
import java.io.FileOutputStream
import java.net.URLDecoder
import java.util.*
import java.util.Date
class VcfImporter(val activity: SimpleActivity) {
enum class ImportResult {
@ -261,6 +261,7 @@ class VcfImporter(val activity: SimpleActivity) {
Phone.TYPE_HOME
}
}
WORK -> {
if (subtype?.toUpperCase() == FAX) {
Phone.TYPE_FAX_WORK
@ -268,6 +269,7 @@ class VcfImporter(val activity: SimpleActivity) {
Phone.TYPE_WORK
}
}
MAIN -> Phone.TYPE_MAIN
WORK_FAX -> Phone.TYPE_FAX_WORK
HOME_FAX -> Phone.TYPE_FAX_HOME

View file

@ -1,6 +1,6 @@
package com.simplemobiletools.contacts.pro.interfaces
import com.simplemobiletools.commons.models.contacts.*
import com.simplemobiletools.commons.models.contacts.Contact
interface RefreshContactsListener {
fun refreshContacts(refreshTabsMask: Int)

View file

@ -1,6 +1,6 @@
package com.simplemobiletools.contacts.pro.interfaces
import com.simplemobiletools.commons.models.contacts.*
import com.simplemobiletools.commons.models.contacts.Contact
interface RemoveFromGroupListener {
fun removeFromGroup(contacts: ArrayList<Contact>)

View file

@ -1,30 +0,0 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.7.10'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.3.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

5
build.gradle.kts Normal file
View file

@ -0,0 +1,5 @@
plugins {
alias(libs.plugins.android).apply(false)
alias(libs.plugins.kotlinAndroid).apply(false)
alias(libs.plugins.ksp).apply(false)
}

View file

@ -1,2 +1,3 @@
android.enableJetifier=true
android.useAndroidX=true
android.nonTransitiveRClass=true

53
gradle/libs.versions.toml Normal file
View file

@ -0,0 +1,53 @@
[versions]
#jetbrains
kotlin = "1.9.0"
#KSP
ksp = "1.9.0-1.0.12"
#AndroidX
androidx-swiperefreshlayout = "1.1.0"
#AutoFitTextView
autofittextview = "0.2.1"
#EzVCard
ezvcard = "0.11.3"
#IndicatorFastScroll
indicatorfastscroll = "4524cd0b61"
#Room
room = "2.6.0-alpha02"
#Simple tools
simple-commons = "c5a32fb1f3"
#Gradle
gradlePlugins-agp = "8.1.0"
#build
app-build-compileSDKVersion = "34"
app-build-targetSDK = "34"
app-build-minimumSDK = "23"
app-build-javaVersion = "VERSION_17"
app-build-kotlinJVMTarget = "17"
#versioning
app-version-appId = "com.simplemobiletools.contacts.pro"
app-version-versionCode = "104"
app-version-versionName = "6.22.4"
[libraries]
#AndroidX
androidx-swiperefreshlayout = { module = "androidx.swiperefreshlayout:swiperefreshlayout", version.ref = "androidx-swiperefreshlayout" }
#AutoFitTextView
autofittextview = { module = "me.grantland:autofittextview", version.ref = "autofittextview" }
#EzVcard
ezvcard = { module = "com.googlecode.ez-vcard:ez-vcard", version.ref = "ezvcard" }
#IndicatorFastScroll
indicatorfastscroll = { module = "com.github.tibbi:IndicatorFastScroll", version.ref = "indicatorfastscroll" }
#Room
androidx-room-runtime = { module = "androidx.room:room-runtime", version.ref = "room" }
androidx-room-ktx = { module = "androidx.room:room-ktx", version.ref = "room" }
androidx-room-compiler = { module = "androidx.room:room-compiler", version.ref = "room" }
#Simple Mobile Tools
simple-tools-commons = { module = "com.github.SimpleMobileTools:Simple-Commons", version.ref = "simple-commons" }
[bundles]
room = [
"androidx-room-ktx",
"androidx-room-runtime",
]
[plugins]
android = { id = "com.android.application", version.ref = "gradlePlugins-agp" }
kotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }

View file

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip

View file

@ -1 +0,0 @@
include ':app'

16
settings.gradle.kts Normal file
View file

@ -0,0 +1,16 @@
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven { setUrl("https://jitpack.io") }
}
}
include(":app")