diff --git a/app/build.gradle b/app/build.gradle index 4bcd1af3..19c83ee4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -63,7 +63,7 @@ android { } dependencies { - implementation 'com.github.SimpleMobileTools:Simple-Commons:ed8c5a3657' + implementation 'com.github.SimpleMobileTools:Simple-Commons:8ee6c0c17b' implementation 'com.googlecode.ez-vcard:ez-vcard:0.11.3' implementation 'com.github.tibbi:IndicatorFastScroll:4524cd0b61' implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/InsertOrEditContactActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/InsertOrEditContactActivity.kt index b1d46b00..4b83cc78 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/InsertOrEditContactActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/InsertOrEditContactActivity.kt @@ -235,7 +235,7 @@ class InsertOrEditContactActivity : SimpleActivity(), RefreshContactsListener { updateBottomTabItemColors(inactiveView, false) } - val bottomBarColor = getBottomTabsBackgroundColor() + val bottomBarColor = getBottomNavigationBackgroundColor() insert_or_edit_tabs_holder.setBackgroundColor(bottomBarColor) updateNavigationBarColor(bottomBarColor) } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/MainActivity.kt index 5d95c6ef..713ef22b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/MainActivity.kt @@ -75,7 +75,8 @@ class MainActivity : SimpleActivity(), RefreshContactsListener { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) appLaunched(BuildConfig.APPLICATION_ID) - + setupOptionsMenu() + refreshMenuItems() storeStateVariables() setupTabs() checkContactPermissions() @@ -125,6 +126,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener { } setupTabColors() + setupToolbar(main_toolbar, searchMenuItem = searchMenuItem) val configStartNameWithSurname = config.startNameWithSurname if (storedStartNameWithSurname != configStartNameWithSurname) { @@ -171,35 +173,30 @@ class MainActivity : SimpleActivity(), RefreshContactsListener { } } - override fun onCreateOptionsMenu(menu: Menu): Boolean { - menuInflater.inflate(R.menu.menu, menu) + private fun refreshMenuItems() { val currentFragment = getCurrentFragment() - - menu.apply { + main_toolbar.menu.apply { findItem(R.id.sort).isVisible = currentFragment != groups_fragment findItem(R.id.filter).isVisible = currentFragment != groups_fragment findItem(R.id.dialpad).isVisible = !config.showDialpadButton - - setupSearch(this) - updateMenuItemColors(this) } - - return true } - override fun onOptionsItemSelected(item: MenuItem): Boolean { - - when (item.itemId) { - R.id.sort -> showSortingDialog(showCustomSorting = getCurrentFragment() is FavoritesFragment) - R.id.filter -> showFilterDialog() - R.id.dialpad -> launchDialpad() - R.id.import_contacts -> tryImportContacts() - R.id.export_contacts -> tryExportContacts() - R.id.settings -> launchSettings() - R.id.about -> launchAbout() - else -> return super.onOptionsItemSelected(item) + private fun setupOptionsMenu() { + setupSearch(main_toolbar.menu) + main_toolbar.setOnMenuItemClickListener { menuItem -> + when (menuItem.itemId) { + R.id.sort -> showSortingDialog(showCustomSorting = getCurrentFragment() is FavoritesFragment) + R.id.filter -> showFilterDialog() + R.id.dialpad -> launchDialpad() + R.id.import_contacts -> tryImportContacts() + R.id.export_contacts -> tryExportContacts() + R.id.settings -> launchSettings() + R.id.about -> launchAbout() + else -> return@setOnMenuItemClickListener false + } + return@setOnMenuItemClickListener true } - return true } override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) { @@ -329,7 +326,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener { updateBottomTabItemColors(inactiveView, false) } - val bottomBarColor = getBottomTabsBackgroundColor() + val bottomBarColor = getBottomNavigationBackgroundColor() main_tabs_holder.setBackgroundColor(bottomBarColor) updateNavigationBarColor(bottomBarColor) } @@ -348,7 +345,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener { getAllFragments().forEach { it?.finishActMode() } - invalidateOptionsMenu() + refreshMenuItems() } }) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/SettingsActivity.kt index 17f22837..47deeee0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/SettingsActivity.kt @@ -24,6 +24,7 @@ class SettingsActivity : SimpleActivity() { override fun onResume() { super.onResume() + setupToolbar(settings_toolbar, NavigationIcon.Arrow) setupCustomizeColors() setupManageShownContactFields() @@ -41,7 +42,6 @@ class SettingsActivity : SimpleActivity() { setupOnContactClick() setupDefaultTab() updateTextColors(settings_holder) - invalidateOptionsMenu() arrayOf(settings_color_customization_label, settings_general_settings_label, settings_main_screen_label, settings_list_view_label).forEach { it.setTextColor(getProperPrimaryColor()) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/ChangeSortingDialog.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/ChangeSortingDialog.kt index 9240dc4a..2f05b66c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/ChangeSortingDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/ChangeSortingDialog.kt @@ -1,8 +1,8 @@ package com.simplemobiletools.contacts.pro.dialogs -import androidx.appcompat.app.AlertDialog import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.extensions.beGoneIf +import com.simplemobiletools.commons.extensions.getAlertDialogBuilder import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.contacts.pro.R @@ -15,10 +15,10 @@ class ChangeSortingDialog(val activity: BaseSimpleActivity, private val showCust private var view = activity.layoutInflater.inflate(R.layout.dialog_change_sorting, null) init { - AlertDialog.Builder(activity) + activity.getAlertDialogBuilder() .setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() } .setNegativeButton(R.string.cancel, null) - .create().apply { + .apply { activity.setupDialogStuff(view, this, R.string.sort_by) } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/ChooseSocialDialog.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/ChooseSocialDialog.kt index f211f7dd..364b1e01 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/ChooseSocialDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/ChooseSocialDialog.kt @@ -6,6 +6,7 @@ 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.contacts.pro.R import com.simplemobiletools.contacts.pro.extensions.getPackageDrawable @@ -38,10 +39,12 @@ class ChooseSocialDialog(val activity: Activity, actions: ArrayList + dialog = alertDialog + } } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/CreateNewGroupDialog.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/CreateNewGroupDialog.kt index 58d54f5c..71f90c2e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/CreateNewGroupDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/CreateNewGroupDialog.kt @@ -4,10 +4,7 @@ import android.view.View import androidx.appcompat.app.AlertDialog import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.dialogs.RadioGroupDialog -import com.simplemobiletools.commons.extensions.setupDialogStuff -import com.simplemobiletools.commons.extensions.showKeyboard -import com.simplemobiletools.commons.extensions.toast -import com.simplemobiletools.commons.extensions.value +import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.ensureBackgroundThread import com.simplemobiletools.commons.models.RadioItem import com.simplemobiletools.contacts.pro.R @@ -21,43 +18,43 @@ class CreateNewGroupDialog(val activity: BaseSimpleActivity, val callback: (newG init { val view = activity.layoutInflater.inflate(R.layout.dialog_create_new_group, null) - AlertDialog.Builder(activity) - .setPositiveButton(R.string.ok, null) - .setNegativeButton(R.string.cancel, null) - .create().apply { - activity.setupDialogStuff(view, this, R.string.create_new_group) { - showKeyboard(view.group_name) - getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(View.OnClickListener { - val name = view.group_name.value - if (name.isEmpty()) { - activity.toast(R.string.empty_name) - return@OnClickListener + activity.getAlertDialogBuilder() + .setPositiveButton(R.string.ok, null) + .setNegativeButton(R.string.cancel, null) + .apply { + activity.setupDialogStuff(view, this, R.string.create_new_group) { alertDialog -> + alertDialog.showKeyboard(view.group_name) + alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(View.OnClickListener { + val name = view.group_name.value + if (name.isEmpty()) { + activity.toast(R.string.empty_name) + return@OnClickListener + } + + val contactSources = ArrayList() + ContactsHelper(activity).getContactSources { + it.filter { it.type.contains("google", true) }.mapTo(contactSources) { ContactSource(it.name, it.type, it.name) } + contactSources.add(activity.getPrivateContactSource()) + + val items = ArrayList() + contactSources.forEachIndexed { index, contactSource -> + items.add(RadioItem(index, contactSource.publicName)) } - val contactSources = ArrayList() - ContactsHelper(activity).getContactSources { - it.filter { it.type.contains("google", true) }.mapTo(contactSources) { ContactSource(it.name, it.type, it.name) } - contactSources.add(activity.getPrivateContactSource()) - - val items = ArrayList() - contactSources.forEachIndexed { index, contactSource -> - items.add(RadioItem(index, contactSource.publicName)) - } - - activity.runOnUiThread { - if (items.size == 1) { - createGroupUnder(name, contactSources.first(), this) - } else { - RadioGroupDialog(activity, items, titleId = R.string.create_group_under_account) { - val contactSource = contactSources[it as Int] - createGroupUnder(name, contactSource, this) - } + activity.runOnUiThread { + if (items.size == 1) { + createGroupUnder(name, contactSources.first(), alertDialog) + } else { + RadioGroupDialog(activity, items, titleId = R.string.create_group_under_account) { + val contactSource = contactSources[it as Int] + createGroupUnder(name, contactSource, alertDialog) } } } - }) - } + } + }) } + } } private fun createGroupUnder(name: String, contactSource: ContactSource, dialog: AlertDialog) { diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/CustomLabelDialog.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/CustomLabelDialog.kt index 9f491f26..927a6831 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/CustomLabelDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/CustomLabelDialog.kt @@ -2,10 +2,7 @@ package com.simplemobiletools.contacts.pro.dialogs import androidx.appcompat.app.AlertDialog import com.simplemobiletools.commons.activities.BaseSimpleActivity -import com.simplemobiletools.commons.extensions.setupDialogStuff -import com.simplemobiletools.commons.extensions.showKeyboard -import com.simplemobiletools.commons.extensions.toast -import com.simplemobiletools.commons.extensions.value +import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.contacts.pro.R import kotlinx.android.synthetic.main.dialog_custom_label.view.* @@ -14,23 +11,23 @@ class CustomLabelDialog(val activity: BaseSimpleActivity, val callback: (label: val view = activity.layoutInflater.inflate(R.layout.dialog_custom_label, null) - AlertDialog.Builder(activity) - .setPositiveButton(R.string.ok, null) - .setNegativeButton(R.string.cancel, null) - .create().apply { - activity.setupDialogStuff(view, this, R.string.label) { - showKeyboard(view.custom_label_edittext) - getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { - val label = view.custom_label_edittext.value - if (label.isEmpty()) { - activity.toast(R.string.empty_name) - return@setOnClickListener - } - - callback(label) - dismiss() + activity.getAlertDialogBuilder() + .setPositiveButton(R.string.ok, null) + .setNegativeButton(R.string.cancel, null) + .apply { + activity.setupDialogStuff(view, this, R.string.label) { alertDialog -> + alertDialog.showKeyboard(view.custom_label_edittext) + alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { + val label = view.custom_label_edittext.value + if (label.isEmpty()) { + activity.toast(R.string.empty_name) + return@setOnClickListener } + + callback(label) + alertDialog.dismiss() } } + } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/ExportContactsDialog.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/ExportContactsDialog.kt index ef8e91df..50330838 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/ExportContactsDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/ExportContactsDialog.kt @@ -59,12 +59,12 @@ class ExportContactsDialog( } } - AlertDialog.Builder(activity) + activity.getAlertDialogBuilder() .setPositiveButton(R.string.ok, null) .setNegativeButton(R.string.cancel, null) - .create().apply { - activity.setupDialogStuff(view, this, R.string.export_contacts) { - getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { + .apply { + activity.setupDialogStuff(view, this, R.string.export_contacts) { alertDialog -> + alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { if (view.export_contacts_list.adapter == null || ignoreClicks) { return@setOnClickListener } @@ -88,7 +88,7 @@ class ExportContactsDialog( .map { it.getFullIdentifier() } .toHashSet() callback(file, ignoredSources) - dismiss() + alertDialog.dismiss() } } else -> activity.toast(R.string.invalid_name) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/FilterContactSourcesDialog.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/FilterContactSourcesDialog.kt index 6c2351fc..ddabe511 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/FilterContactSourcesDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/FilterContactSourcesDialog.kt @@ -1,6 +1,7 @@ package com.simplemobiletools.contacts.pro.dialogs import androidx.appcompat.app.AlertDialog +import com.simplemobiletools.commons.extensions.getAlertDialogBuilder import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.contacts.pro.R import com.simplemobiletools.contacts.pro.activities.SimpleActivity @@ -58,11 +59,13 @@ class FilterContactSourcesDialog(val activity: SimpleActivity, private val callb view.filter_contact_sources_list.adapter = FilterContactSourcesAdapter(activity, contactSourcesWithCount, selectedSources) if (dialog == null) { - dialog = AlertDialog.Builder(activity) + activity.getAlertDialogBuilder() .setPositiveButton(R.string.ok) { dialogInterface, i -> confirmContactSources() } .setNegativeButton(R.string.cancel, null) - .create().apply { - activity.setupDialogStuff(view, this) + .apply { + activity.setupDialogStuff(view, this) { alertDialog -> + dialog = alertDialog + } } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/ImportContactsDialog.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/ImportContactsDialog.kt index 31d1ce50..757ea2f2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/ImportContactsDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/ImportContactsDialog.kt @@ -2,6 +2,7 @@ package com.simplemobiletools.contacts.pro.dialogs import android.view.ViewGroup import androidx.appcompat.app.AlertDialog +import com.simplemobiletools.commons.extensions.getAlertDialogBuilder import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.commons.extensions.toast import com.simplemobiletools.commons.helpers.ensureBackgroundThread @@ -48,34 +49,36 @@ class ImportContactsDialog(val activity: SimpleActivity, val path: String, priva } } - AlertDialog.Builder(activity) - .setPositiveButton(R.string.ok, null) - .setNegativeButton(R.string.cancel, null) - .create().apply { - activity.setupDialogStuff(view, this, R.string.import_contacts) { - getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { - if (ignoreClicks) { - return@setOnClickListener - } + activity.getAlertDialogBuilder() + .setPositiveButton(R.string.ok, null) + .setNegativeButton(R.string.cancel, null) + .apply { + activity.setupDialogStuff(view, this, R.string.import_contacts) { alertDialog -> + alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { + if (ignoreClicks) { + return@setOnClickListener + } - ignoreClicks = true - activity.toast(R.string.importing) - ensureBackgroundThread { - val result = VcfImporter(activity).importContacts(path, targetContactSource) - handleParseResult(result) - dismiss() - } + ignoreClicks = true + activity.toast(R.string.importing) + ensureBackgroundThread { + val result = VcfImporter(activity).importContacts(path, targetContactSource) + handleParseResult(result) + alertDialog.dismiss() } } } + } } 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 - }) + 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 + } + ) callback(result != IMPORT_FAIL) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/ManageVisibleFieldsDialog.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/ManageVisibleFieldsDialog.kt index 0ab8ebf8..375a64f9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/ManageVisibleFieldsDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/ManageVisibleFieldsDialog.kt @@ -1,7 +1,7 @@ package com.simplemobiletools.contacts.pro.dialogs -import androidx.appcompat.app.AlertDialog import com.simplemobiletools.commons.activities.BaseSimpleActivity +import com.simplemobiletools.commons.extensions.getAlertDialogBuilder import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.commons.views.MyAppCompatCheckbox import com.simplemobiletools.contacts.pro.R @@ -38,10 +38,10 @@ class ManageVisibleFieldsDialog(val activity: BaseSimpleActivity, val callback: view.findViewById(value).isChecked = showContactFields and key != 0 } - AlertDialog.Builder(activity) + activity.getAlertDialogBuilder() .setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() } .setNegativeButton(R.string.cancel, null) - .create().apply { + .apply { activity.setupDialogStuff(view, this) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/ManageVisibleTabsDialog.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/ManageVisibleTabsDialog.kt index d73a2218..5806242d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/ManageVisibleTabsDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/ManageVisibleTabsDialog.kt @@ -1,7 +1,7 @@ package com.simplemobiletools.contacts.pro.dialogs -import androidx.appcompat.app.AlertDialog import com.simplemobiletools.commons.activities.BaseSimpleActivity +import com.simplemobiletools.commons.extensions.getAlertDialogBuilder import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.commons.helpers.TAB_CONTACTS import com.simplemobiletools.commons.helpers.TAB_FAVORITES @@ -27,10 +27,10 @@ class ManageVisibleTabsDialog(val activity: BaseSimpleActivity) { view.findViewById(value).isChecked = showTabs and key != 0 } - AlertDialog.Builder(activity) + activity.getAlertDialogBuilder() .setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() } .setNegativeButton(R.string.cancel, null) - .create().apply { + .apply { activity.setupDialogStuff(view, this) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/MyDatePickerDialog.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/MyDatePickerDialog.kt index 354bdfb1..2eb37a9f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/MyDatePickerDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/MyDatePickerDialog.kt @@ -1,12 +1,11 @@ package com.simplemobiletools.contacts.pro.dialogs -import androidx.appcompat.app.AlertDialog 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.extensions.config -import kotlinx.android.synthetic.main.dialog_date_picker.* import kotlinx.android.synthetic.main.dialog_date_picker.view.* import org.joda.time.DateTime import java.util.* @@ -15,11 +14,11 @@ class MyDatePickerDialog(val activity: BaseSimpleActivity, val defaultDate: Stri private var view = activity.layoutInflater.inflate(R.layout.dialog_date_picker, null) init { - AlertDialog.Builder(activity) + activity.getAlertDialogBuilder() .setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() } .setNegativeButton(R.string.cancel, null) - .create().apply { - activity.setupDialogStuff(view, this) { + .apply { + activity.setupDialogStuff(view, this) { alertDialog -> val today = Calendar.getInstance() var year = today.get(Calendar.YEAR) var month = today.get(Calendar.MONTH) @@ -41,8 +40,8 @@ class MyDatePickerDialog(val activity: BaseSimpleActivity, val defaultDate: Stri if (activity.config.isUsingSystemTheme && isSPlus()) { val dialogBackgroundColor = activity.getColor(R.color.you_dialog_background_color) - dialog_holder.setBackgroundColor(dialogBackgroundColor) - date_picker.setBackgroundColor(dialogBackgroundColor) + view.dialog_holder.setBackgroundColor(dialogBackgroundColor) + view.date_picker.setBackgroundColor(dialogBackgroundColor) } view.date_picker.updateDate(year, month, day) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/RenameGroupDialog.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/RenameGroupDialog.kt index 6ba6e361..a0f97ce1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/RenameGroupDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/RenameGroupDialog.kt @@ -17,39 +17,39 @@ class RenameGroupDialog(val activity: BaseSimpleActivity, val group: Group, val rename_group_title.setText(group.title) } - AlertDialog.Builder(activity) - .setPositiveButton(R.string.ok, null) - .setNegativeButton(R.string.cancel, null) - .create().apply { - activity.setupDialogStuff(view, this, R.string.rename) { - showKeyboard(view.rename_group_title) - getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { - val newTitle = view.rename_group_title.value - if (newTitle.isEmpty()) { - activity.toast(R.string.empty_name) - return@setOnClickListener - } + activity.getAlertDialogBuilder() + .setPositiveButton(R.string.ok, null) + .setNegativeButton(R.string.cancel, null) + .apply { + activity.setupDialogStuff(view, this, R.string.rename) { alertDialog -> + alertDialog.showKeyboard(view.rename_group_title) + alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { + val newTitle = view.rename_group_title.value + if (newTitle.isEmpty()) { + activity.toast(R.string.empty_name) + return@setOnClickListener + } - if (!newTitle.isAValidFilename()) { - activity.toast(R.string.invalid_name) - return@setOnClickListener - } + if (!newTitle.isAValidFilename()) { + activity.toast(R.string.invalid_name) + return@setOnClickListener + } - group.title = newTitle - group.contactsCount = 0 - ensureBackgroundThread { - if (group.isPrivateSecretGroup()) { - activity.groupsDB.insertOrUpdate(group) - } else { - ContactsHelper(activity).renameGroup(group) - } - activity.runOnUiThread { - callback() - dismiss() - } + group.title = newTitle + group.contactsCount = 0 + ensureBackgroundThread { + if (group.isPrivateSecretGroup()) { + activity.groupsDB.insertOrUpdate(group) + } else { + ContactsHelper(activity).renameGroup(group) + } + activity.runOnUiThread { + callback() + alertDialog.dismiss() } } } } + } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/SelectContactsDialog.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/SelectContactsDialog.kt index f84d7421..e3e42e33 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/SelectContactsDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/SelectContactsDialog.kt @@ -57,14 +57,16 @@ class SelectContactsDialog( setupFastscroller(allContacts) - val builder = AlertDialog.Builder(activity) + val builder = activity.getAlertDialogBuilder() if (allowSelectMultiple) { builder.setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() } } builder.setNegativeButton(R.string.cancel, null) - dialog = builder.create().apply { - activity.setupDialogStuff(view, this) + builder.apply { + activity.setupDialogStuff(view, this) { alertDialog -> + dialog = alertDialog + } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/SelectGroupsDialog.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/SelectGroupsDialog.kt index 1ca5ff9f..ea7defa8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/SelectGroupsDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/SelectGroupsDialog.kt @@ -2,10 +2,7 @@ package com.simplemobiletools.contacts.pro.dialogs import android.view.ViewGroup import androidx.appcompat.app.AlertDialog -import com.simplemobiletools.commons.extensions.getProperBackgroundColor -import com.simplemobiletools.commons.extensions.getProperPrimaryColor -import com.simplemobiletools.commons.extensions.getProperTextColor -import com.simplemobiletools.commons.extensions.setupDialogStuff +import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.views.MyAppCompatCheckbox import com.simplemobiletools.contacts.pro.R import com.simplemobiletools.contacts.pro.activities.SimpleActivity @@ -39,11 +36,13 @@ class SelectGroupsDialog(val activity: SimpleActivity, val selectedGroups: Array addCreateNewGroupButton() - dialog = AlertDialog.Builder(activity) + activity.getAlertDialogBuilder() .setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() } .setNegativeButton(R.string.cancel, null) - .create().apply { - activity.setupDialogStuff(view, this) + .apply { + activity.setupDialogStuff(view, this) { alertDialog -> + dialog = alertDialog + } } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 660175ec..e08bcc19 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,36 +1,59 @@ - - + + + + + + + app:layout_behavior="@string/appbar_scrolling_view_behavior"> - + - + - + + + + diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index 22247bbf..6fb2ddbe 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -1,343 +1,368 @@ - + android:layout_height="match_parent"> - + android:layout_height="wrap_content"> - + android:layout_height="?attr/actionBarSize" + android:background="@color/color_primary" + app:title="@string/settings" + app:titleTextAppearance="@style/AppTheme.ActionBar.TitleTextStyle" /> + + + + - + android:text="@string/color_customization" /> - + + + android:background="@drawable/ripple_all_corners"> - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +