mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-02-28 00:57:40 +01:00
rewriting insert/edit activity to new search
This commit is contained in:
parent
86089c9a2a
commit
9ba58c1cc3
@ -42,14 +42,6 @@
|
|||||||
android:configChanges="orientation"
|
android:configChanges="orientation"
|
||||||
android:exported="true">
|
android:exported="true">
|
||||||
|
|
||||||
<meta-data
|
|
||||||
android:name="android.app.default_searchable"
|
|
||||||
android:resource="@xml/searchable" />
|
|
||||||
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.intent.action.SEARCH" />
|
|
||||||
</intent-filter>
|
|
||||||
|
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.VIEW" />
|
<action android:name="android.intent.action.VIEW" />
|
||||||
|
|
||||||
@ -166,14 +158,6 @@
|
|||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:label="@string/select_contact">
|
android:label="@string/select_contact">
|
||||||
|
|
||||||
<meta-data
|
|
||||||
android:name="android.app.default_searchable"
|
|
||||||
android:resource="@xml/searchable" />
|
|
||||||
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.intent.action.SEARCH" />
|
|
||||||
</intent-filter>
|
|
||||||
|
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.INSERT_OR_EDIT" />
|
<action android:name="android.intent.action.INSERT_OR_EDIT" />
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
@ -1,21 +1,16 @@
|
|||||||
package com.simplemobiletools.contacts.pro.activities
|
package com.simplemobiletools.contacts.pro.activities
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.app.SearchManager
|
|
||||||
import android.content.ActivityNotFoundException
|
import android.content.ActivityNotFoundException
|
||||||
import android.content.Context
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.provider.ContactsContract
|
import android.provider.ContactsContract
|
||||||
import android.provider.ContactsContract.CommonDataKinds.Email
|
import android.provider.ContactsContract.CommonDataKinds.Email
|
||||||
import android.provider.ContactsContract.CommonDataKinds.Phone
|
import android.provider.ContactsContract.CommonDataKinds.Phone
|
||||||
import android.view.Menu
|
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.appcompat.widget.SearchView
|
|
||||||
import androidx.core.view.MenuItemCompat
|
|
||||||
import androidx.viewpager.widget.ViewPager
|
import androidx.viewpager.widget.ViewPager
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.*
|
import com.simplemobiletools.commons.helpers.*
|
||||||
@ -55,6 +50,7 @@ class InsertOrEditContactActivity : SimpleActivity(), RefreshContactsListener {
|
|||||||
setContentView(R.layout.activity_insert_edit_contact)
|
setContentView(R.layout.activity_insert_edit_contact)
|
||||||
setupOptionsMenu()
|
setupOptionsMenu()
|
||||||
isSelectContactIntent = intent.action == Intent.ACTION_PICK
|
isSelectContactIntent = intent.action == Intent.ACTION_PICK
|
||||||
|
updateMaterialActivityViews(insert_edit_coordinator, insert_edit_contact_holder, useTransparentNavigation = false, useTopSearchMenu = true)
|
||||||
|
|
||||||
if (isSelectContactIntent) {
|
if (isSelectContactIntent) {
|
||||||
specialMimeType = when (intent.data) {
|
specialMimeType = when (intent.data) {
|
||||||
@ -89,8 +85,8 @@ class InsertOrEditContactActivity : SimpleActivity(), RefreshContactsListener {
|
|||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
|
updateMenuColors()
|
||||||
setupTabColors()
|
setupTabColors()
|
||||||
setupToolbar(insert_edit_toolbar, NavigationIcon.None, searchMenuItem = searchMenuItem)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStop() {
|
override fun onStop() {
|
||||||
@ -99,8 +95,21 @@ class InsertOrEditContactActivity : SimpleActivity(), RefreshContactsListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun setupOptionsMenu() {
|
private fun setupOptionsMenu() {
|
||||||
setupSearch(insert_edit_toolbar.menu)
|
insert_edit_menu.getToolbar().inflateMenu(R.menu.menu_insert_or_edit)
|
||||||
insert_edit_toolbar.setOnMenuItemClickListener { menuItem ->
|
insert_edit_menu.toggleHideOnScroll(false)
|
||||||
|
insert_edit_menu.setupMenu()
|
||||||
|
|
||||||
|
insert_edit_menu.onSearchClosedListener = {
|
||||||
|
getAllFragments().forEach {
|
||||||
|
it?.onSearchClosed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
insert_edit_menu.onSearchTextChangedListener = { text ->
|
||||||
|
getCurrentFragment()?.onSearchQueryChanged(text)
|
||||||
|
}
|
||||||
|
|
||||||
|
insert_edit_menu.getToolbar().setOnMenuItemClickListener { menuItem ->
|
||||||
when (menuItem.itemId) {
|
when (menuItem.itemId) {
|
||||||
R.id.sort -> showSortingDialog()
|
R.id.sort -> showSortingDialog()
|
||||||
R.id.filter -> showFilterDialog()
|
R.id.filter -> showFilterDialog()
|
||||||
@ -110,6 +119,11 @@ class InsertOrEditContactActivity : SimpleActivity(), RefreshContactsListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun updateMenuColors() {
|
||||||
|
updateStatusbarColor(getProperBackgroundColor())
|
||||||
|
insert_edit_menu.updateColors()
|
||||||
|
}
|
||||||
|
|
||||||
override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) {
|
override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) {
|
||||||
super.onActivityResult(requestCode, resultCode, resultData)
|
super.onActivityResult(requestCode, resultCode, resultData)
|
||||||
if (resultCode == Activity.RESULT_OK) {
|
if (resultCode == Activity.RESULT_OK) {
|
||||||
@ -118,6 +132,14 @@ class InsertOrEditContactActivity : SimpleActivity(), RefreshContactsListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onBackPressed() {
|
||||||
|
if (insert_edit_menu.isSearchOpen) {
|
||||||
|
insert_edit_menu.closeSearch()
|
||||||
|
} else {
|
||||||
|
super.onBackPressed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun initFragments() {
|
private fun initFragments() {
|
||||||
view_pager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
|
view_pager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
|
||||||
override fun onPageScrollStateChanged(state: Int) {}
|
override fun onPageScrollStateChanged(state: Int) {}
|
||||||
@ -125,7 +147,7 @@ class InsertOrEditContactActivity : SimpleActivity(), RefreshContactsListener {
|
|||||||
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {}
|
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {}
|
||||||
|
|
||||||
override fun onPageSelected(position: Int) {
|
override fun onPageSelected(position: Int) {
|
||||||
insert_or_edit_tabs_holder.getTabAt(position)?.select()
|
insert_edit_tabs_holder.getTabAt(position)?.select()
|
||||||
getAllFragments().forEach {
|
getAllFragments().forEach {
|
||||||
it?.finishActMode()
|
it?.finishActMode()
|
||||||
}
|
}
|
||||||
@ -145,69 +167,29 @@ class InsertOrEditContactActivity : SimpleActivity(), RefreshContactsListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun setupTabs() {
|
private fun setupTabs() {
|
||||||
insert_or_edit_tabs_holder.removeAllTabs()
|
insert_edit_tabs_holder.removeAllTabs()
|
||||||
contactsFavoritesList.forEachIndexed { index, value ->
|
contactsFavoritesList.forEachIndexed { index, value ->
|
||||||
if (config.showTabs and value != 0) {
|
if (config.showTabs and value != 0) {
|
||||||
insert_or_edit_tabs_holder.newTab().setCustomView(R.layout.bottom_tablayout_item).apply {
|
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<ImageView>(R.id.tab_item_icon)?.setImageDrawable(getTabIcon(index))
|
||||||
customView?.findViewById<TextView>(R.id.tab_item_label)?.text = getTabLabel(index)
|
customView?.findViewById<TextView>(R.id.tab_item_label)?.text = getTabLabel(index)
|
||||||
insert_or_edit_tabs_holder.addTab(this)
|
insert_edit_tabs_holder.addTab(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
insert_or_edit_tabs_holder.onTabSelectionChanged(
|
insert_edit_tabs_holder.onTabSelectionChanged(
|
||||||
tabUnselectedAction = {
|
tabUnselectedAction = {
|
||||||
updateBottomTabItemColors(it.customView, false)
|
updateBottomTabItemColors(it.customView, false, getDeselectedTabDrawableIds()[it.position])
|
||||||
},
|
},
|
||||||
tabSelectedAction = {
|
tabSelectedAction = {
|
||||||
closeSearch()
|
insert_edit_menu.closeSearch()
|
||||||
view_pager.currentItem = it.position
|
view_pager.currentItem = it.position
|
||||||
updateBottomTabItemColors(it.customView, true)
|
updateBottomTabItemColors(it.customView, true, getSelectedTabDrawableIds()[it.position])
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
insert_or_edit_tabs_holder.beGoneIf(insert_or_edit_tabs_holder.tabCount == 1)
|
insert_edit_tabs_holder.beGoneIf(insert_edit_tabs_holder.tabCount == 1)
|
||||||
}
|
|
||||||
|
|
||||||
private fun setupSearch(menu: Menu) {
|
|
||||||
val searchManager = getSystemService(Context.SEARCH_SERVICE) as SearchManager
|
|
||||||
searchMenuItem = menu.findItem(R.id.search)
|
|
||||||
(searchMenuItem!!.actionView as SearchView).apply {
|
|
||||||
setSearchableInfo(searchManager.getSearchableInfo(componentName))
|
|
||||||
isSubmitButtonEnabled = false
|
|
||||||
queryHint = getString(getSearchString())
|
|
||||||
setOnQueryTextListener(object : SearchView.OnQueryTextListener {
|
|
||||||
override fun onQueryTextSubmit(query: String) = false
|
|
||||||
|
|
||||||
override fun onQueryTextChange(newText: String): Boolean {
|
|
||||||
if (isSearchOpen) {
|
|
||||||
getCurrentFragment()?.onSearchQueryChanged(newText)
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
MenuItemCompat.setOnActionExpandListener(searchMenuItem, object : MenuItemCompat.OnActionExpandListener {
|
|
||||||
override fun onMenuItemActionExpand(item: MenuItem?): Boolean {
|
|
||||||
isSearchOpen = true
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onMenuItemActionCollapse(item: MenuItem?): Boolean {
|
|
||||||
getCurrentFragment()?.onSearchClosed()
|
|
||||||
isSearchOpen = false
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getSearchString(): Int {
|
|
||||||
return when (getCurrentFragment()) {
|
|
||||||
favorites_fragment -> R.string.search_favorites
|
|
||||||
else -> R.string.search_contacts
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getCurrentFragment(): MyViewPagerFragment? {
|
private fun getCurrentFragment(): MyViewPagerFragment? {
|
||||||
@ -221,20 +203,30 @@ class InsertOrEditContactActivity : SimpleActivity(), RefreshContactsListener {
|
|||||||
private fun getAllFragments() = arrayListOf(contacts_fragment, favorites_fragment)
|
private fun getAllFragments() = arrayListOf(contacts_fragment, favorites_fragment)
|
||||||
|
|
||||||
private fun setupTabColors() {
|
private fun setupTabColors() {
|
||||||
val activeView = insert_or_edit_tabs_holder.getTabAt(view_pager.currentItem)?.customView
|
val activeView = insert_edit_tabs_holder.getTabAt(view_pager.currentItem)?.customView
|
||||||
updateBottomTabItemColors(activeView, true)
|
updateBottomTabItemColors(activeView, true, getSelectedTabDrawableIds()[view_pager.currentItem])
|
||||||
|
|
||||||
getInactiveTabIndexes(view_pager.currentItem).forEach { index ->
|
getInactiveTabIndexes(view_pager.currentItem).forEach { index ->
|
||||||
val inactiveView = insert_or_edit_tabs_holder.getTabAt(index)?.customView
|
val inactiveView = insert_edit_tabs_holder.getTabAt(index)?.customView
|
||||||
updateBottomTabItemColors(inactiveView, false)
|
updateBottomTabItemColors(inactiveView, false, getDeselectedTabDrawableIds()[index])
|
||||||
}
|
}
|
||||||
|
|
||||||
val bottomBarColor = getBottomNavigationBackgroundColor()
|
val bottomBarColor = getBottomNavigationBackgroundColor()
|
||||||
insert_or_edit_tabs_holder.setBackgroundColor(bottomBarColor)
|
insert_edit_tabs_holder.setBackgroundColor(bottomBarColor)
|
||||||
updateNavigationBarColor(bottomBarColor)
|
updateNavigationBarColor(bottomBarColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getInactiveTabIndexes(activeIndex: Int) = (0 until contactsFavoritesList.size).filter { it != activeIndex }
|
private fun getInactiveTabIndexes(activeIndex: Int) = (0 until insert_edit_tabs_holder.tabCount).filter { it != activeIndex }
|
||||||
|
|
||||||
|
private fun getSelectedTabDrawableIds() = arrayOf(
|
||||||
|
R.drawable.ic_person_vector,
|
||||||
|
R.drawable.ic_star_vector
|
||||||
|
)
|
||||||
|
|
||||||
|
private fun getDeselectedTabDrawableIds() = arrayOf(
|
||||||
|
R.drawable.ic_person_outline_vector,
|
||||||
|
R.drawable.ic_star_outline_vector
|
||||||
|
)
|
||||||
|
|
||||||
override fun refreshContacts(refreshTabsMask: Int) {
|
override fun refreshContacts(refreshTabsMask: Int) {
|
||||||
if (isDestroyed || isFinishing) {
|
if (isDestroyed || isFinishing) {
|
||||||
@ -270,10 +262,12 @@ class InsertOrEditContactActivity : SimpleActivity(), RefreshContactsListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (refreshTabsMask and TAB_CONTACTS != 0) {
|
if (refreshTabsMask and TAB_CONTACTS != 0) {
|
||||||
|
contacts_fragment?.skipHashComparing = true
|
||||||
contacts_fragment?.refreshContacts(contacts, placeholderText)
|
contacts_fragment?.refreshContacts(contacts, placeholderText)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (refreshTabsMask and TAB_FAVORITES != 0) {
|
if (refreshTabsMask and TAB_FAVORITES != 0) {
|
||||||
|
favorites_fragment?.skipHashComparing = true
|
||||||
favorites_fragment?.refreshContacts(contacts, placeholderText)
|
favorites_fragment?.refreshContacts(contacts, placeholderText)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -350,10 +344,6 @@ class InsertOrEditContactActivity : SimpleActivity(), RefreshContactsListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun fabClicked() {
|
|
||||||
createNewContact()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun closeSearch() {
|
private fun closeSearch() {
|
||||||
if (isSearchOpen) {
|
if (isSearchOpen) {
|
||||||
getAllFragments().forEach {
|
getAllFragments().forEach {
|
||||||
|
@ -5,21 +5,10 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<com.google.android.material.appbar.AppBarLayout
|
<com.simplemobiletools.commons.views.MySearchMenu
|
||||||
android:id="@+id/insert_edit_app_bar_layout"
|
android:id="@+id/insert_edit_menu"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
<com.google.android.material.appbar.MaterialToolbar
|
|
||||||
android:id="@+id/insert_edit_toolbar"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="?attr/actionBarSize"
|
|
||||||
android:background="@color/color_primary"
|
|
||||||
app:menu="@menu/menu_insert_or_edit"
|
|
||||||
app:title="@string/select_contact"
|
|
||||||
app:titleTextAppearance="@style/AppTheme.ActionBar.TitleTextStyle" />
|
|
||||||
|
|
||||||
</com.google.android.material.appbar.AppBarLayout>
|
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:id="@+id/insert_edit_contact_holder"
|
android:id="@+id/insert_edit_contact_holder"
|
||||||
@ -77,11 +66,11 @@
|
|||||||
android:id="@+id/view_pager"
|
android:id="@+id/view_pager"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_above="@+id/insert_or_edit_tabs_holder"
|
android:layout_above="@+id/insert_edit_tabs_holder"
|
||||||
android:layout_below="@+id/select_contact_label" />
|
android:layout_below="@+id/select_contact_label" />
|
||||||
|
|
||||||
<com.google.android.material.tabs.TabLayout
|
<com.google.android.material.tabs.TabLayout
|
||||||
android:id="@+id/insert_or_edit_tabs_holder"
|
android:id="@+id/insert_edit_tabs_holder"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentBottom="true"
|
android:layout_alignParentBottom="true"
|
||||||
|
@ -3,12 +3,6 @@
|
|||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
tools:ignore="AppCompatResource,AlwaysShowAction">
|
tools:ignore="AppCompatResource,AlwaysShowAction">
|
||||||
<item
|
|
||||||
android:id="@+id/search"
|
|
||||||
android:icon="@drawable/ic_search_vector"
|
|
||||||
android:title="@string/search"
|
|
||||||
app:actionViewClass="androidx.appcompat.widget.SearchView"
|
|
||||||
app:showAsAction="collapseActionView|always" />
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/sort"
|
android:id="@+id/sort"
|
||||||
android:icon="@drawable/ic_sort_vector"
|
android:icon="@drawable/ic_sort_vector"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user