rewrite the layout to a viewpager split to contacts and favorites
This commit is contained in:
parent
74064e57d5
commit
1e0d8f383d
11 changed files with 423 additions and 157 deletions
|
@ -36,7 +36,7 @@ ext {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.simplemobiletools:commons:3.4.14'
|
implementation 'com.simplemobiletools:commons:3.4.15'
|
||||||
implementation 'joda-time:joda-time:2.9.9'
|
implementation 'joda-time:joda-time:2.9.9'
|
||||||
|
|
||||||
debugImplementation "com.squareup.leakcanary:leakcanary-android:$leakCanaryVersion"
|
debugImplementation "com.squareup.leakcanary:leakcanary-android:$leakCanaryVersion"
|
||||||
|
|
|
@ -1,45 +1,43 @@
|
||||||
package com.simplemobiletools.contacts.activities
|
package com.simplemobiletools.contacts.activities
|
||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.graphics.Paint
|
import android.graphics.drawable.ColorDrawable
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.*
|
import com.simplemobiletools.commons.helpers.*
|
||||||
import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener
|
|
||||||
import com.simplemobiletools.contacts.BuildConfig
|
import com.simplemobiletools.contacts.BuildConfig
|
||||||
import com.simplemobiletools.contacts.R
|
import com.simplemobiletools.contacts.R
|
||||||
import com.simplemobiletools.contacts.adapters.ContactsAdapter
|
import com.simplemobiletools.contacts.adapters.ViewPagerAdapter
|
||||||
import com.simplemobiletools.contacts.dialogs.ChangeSortingDialog
|
import com.simplemobiletools.contacts.dialogs.ChangeSortingDialog
|
||||||
import com.simplemobiletools.contacts.dialogs.FilterContactSourcesDialog
|
import com.simplemobiletools.contacts.dialogs.FilterContactSourcesDialog
|
||||||
import com.simplemobiletools.contacts.extensions.config
|
import com.simplemobiletools.contacts.extensions.config
|
||||||
import com.simplemobiletools.contacts.extensions.openContact
|
import com.simplemobiletools.contacts.extensions.onPageChanged
|
||||||
import com.simplemobiletools.contacts.extensions.tryStartCall
|
import com.simplemobiletools.contacts.extensions.onTabSelectionChanged
|
||||||
import com.simplemobiletools.contacts.helpers.ContactsHelper
|
|
||||||
import com.simplemobiletools.contacts.models.Contact
|
|
||||||
import kotlinx.android.synthetic.main.activity_main.*
|
import kotlinx.android.synthetic.main.activity_main.*
|
||||||
|
import kotlinx.android.synthetic.main.fragment_contacts.*
|
||||||
|
import kotlinx.android.synthetic.main.fragment_favorites.*
|
||||||
|
|
||||||
|
class MainActivity : SimpleActivity() {
|
||||||
|
private var isFirstResume = true
|
||||||
|
|
||||||
class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|
||||||
private var storedUseEnglish = false
|
private var storedUseEnglish = false
|
||||||
private var storedTextColor = 0
|
private var storedTextColor = 0
|
||||||
private var storedBackgroundColor = 0
|
private var storedBackgroundColor = 0
|
||||||
private var storedPrimaryColor = 0
|
private var storedPrimaryColor = 0
|
||||||
private var storedStartNameWithSurname = false
|
private var storedStartNameWithSurname = false
|
||||||
|
|
||||||
private var isFirstResume = true
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_main)
|
setContentView(R.layout.activity_main)
|
||||||
appLaunched()
|
appLaunched()
|
||||||
contacts_fab.setOnClickListener { addNewContact() }
|
|
||||||
|
|
||||||
handlePermission(PERMISSION_READ_CONTACTS) {
|
handlePermission(PERMISSION_READ_CONTACTS) {
|
||||||
if (it) {
|
if (it) {
|
||||||
handlePermission(PERMISSION_WRITE_CONTACTS) {
|
handlePermission(PERMISSION_WRITE_CONTACTS) {
|
||||||
if (it) {
|
if (it) {
|
||||||
initContacts()
|
initFragments()
|
||||||
} else {
|
} else {
|
||||||
toast(R.string.no_contacts_permission)
|
toast(R.string.no_contacts_permission)
|
||||||
finish()
|
finish()
|
||||||
|
@ -50,7 +48,6 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
storeStateVariables()
|
storeStateVariables()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,37 +58,37 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (storedTextColor != config.textColor) {
|
val configTextColor = config.textColor
|
||||||
(contacts_list.adapter as ContactsAdapter).apply {
|
if (storedTextColor != configTextColor) {
|
||||||
updateTextColor(config.textColor)
|
val inactiveTabIndex = if (viewpager.currentItem == 0) 1 else 0
|
||||||
initDrawables()
|
main_tabs_holder.getTabAt(inactiveTabIndex)?.icon?.applyColorFilter(configTextColor)
|
||||||
}
|
contacts_fragment.textColorChanged(configTextColor)
|
||||||
|
favorites_fragment.textColorChanged(configTextColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (storedPrimaryColor != config.primaryColor) {
|
val configBackgroundColor = config.backgroundColor
|
||||||
contacts_fastscroller.updatePrimaryColor()
|
if (storedBackgroundColor != configBackgroundColor) {
|
||||||
|
main_tabs_holder.background = ColorDrawable(configBackgroundColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (storedStartNameWithSurname != config.startNameWithSurname) {
|
val configPrimaryColor = config.primaryColor
|
||||||
(contacts_list.adapter as ContactsAdapter).apply {
|
if (storedPrimaryColor != configPrimaryColor) {
|
||||||
startNameWithSurname = config.startNameWithSurname
|
main_tabs_holder.setSelectedTabIndicatorColor(getAdjustedPrimaryColor())
|
||||||
config.sorting = if (config.startNameWithSurname) SORT_BY_SURNAME else SORT_BY_FIRST_NAME
|
main_tabs_holder.getTabAt(viewpager.currentItem)?.icon?.applyColorFilter(getAdjustedPrimaryColor())
|
||||||
initContacts()
|
contacts_fragment.primaryColorChanged(configPrimaryColor)
|
||||||
}
|
favorites_fragment.primaryColorChanged(configPrimaryColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
contacts_fastscroller.updateBubbleColors()
|
val configStartNameWithSurname = config.startNameWithSurname
|
||||||
contacts_fastscroller.allowBubbleDisplay = config.showInfoBubble
|
if (storedStartNameWithSurname != configStartNameWithSurname) {
|
||||||
updateTextColors(contacts_holder)
|
contacts_fragment.startNameWithSurnameChanged(configStartNameWithSurname)
|
||||||
|
favorites_fragment.startNameWithSurnameChanged(configStartNameWithSurname)
|
||||||
contacts_placeholder_2.paintFlags = contacts_placeholder_2.paintFlags or Paint.UNDERLINE_TEXT_FLAG
|
|
||||||
contacts_placeholder_2.setTextColor(config.primaryColor)
|
|
||||||
contacts_placeholder_2.setOnClickListener {
|
|
||||||
showFilterDialog()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isFirstResume) {
|
if (!isFirstResume) {
|
||||||
initContacts()
|
contacts_fragment.initContacts()
|
||||||
|
contacts_fragment.onActivityResume()
|
||||||
|
favorites_fragment.onActivityResume()
|
||||||
}
|
}
|
||||||
isFirstResume = false
|
isFirstResume = false
|
||||||
}
|
}
|
||||||
|
@ -117,22 +114,6 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showSortingDialog() {
|
|
||||||
ChangeSortingDialog(this) {
|
|
||||||
initContacts()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun showFilterDialog() {
|
|
||||||
FilterContactSourcesDialog(this) {
|
|
||||||
initContacts()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun launchAbout() {
|
|
||||||
startAboutActivity(R.string.app_name, LICENSE_KOTLIN or LICENSE_MULTISELECT or LICENSE_JODA or LICENSE_GLIDE, BuildConfig.VERSION_NAME)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun storeStateVariables() {
|
private fun storeStateVariables() {
|
||||||
config.apply {
|
config.apply {
|
||||||
storedUseEnglish = useEnglish
|
storedUseEnglish = useEnglish
|
||||||
|
@ -143,63 +124,44 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initContacts() {
|
private fun initFragments() {
|
||||||
ContactsHelper(this).getContacts {
|
viewpager.adapter = ViewPagerAdapter(this)
|
||||||
if (config.lastUsedContactSource.isEmpty()) {
|
viewpager.onPageChanged {
|
||||||
val grouped = it.groupBy { it.source }.maxWith(compareBy { it.value.size })
|
main_tabs_holder.getTabAt(it)?.select()
|
||||||
config.lastUsedContactSource = grouped?.key ?: ""
|
invalidateOptionsMenu()
|
||||||
}
|
}
|
||||||
|
|
||||||
Contact.sorting = config.sorting
|
main_tabs_holder.apply {
|
||||||
it.sort()
|
background = ColorDrawable(config.backgroundColor)
|
||||||
|
setSelectedTabIndicatorColor(getAdjustedPrimaryColor())
|
||||||
|
getTabAt(0)?.icon?.applyColorFilter(getAdjustedPrimaryColor())
|
||||||
|
getTabAt(1)?.icon?.applyColorFilter(config.textColor)
|
||||||
|
}
|
||||||
|
|
||||||
if (it.hashCode() != (contacts_list.adapter as? ContactsAdapter)?.contactItems?.hashCode()) {
|
main_tabs_holder.onTabSelectionChanged(
|
||||||
runOnUiThread {
|
tabUnselectedAction = {
|
||||||
setupContacts(it)
|
it.icon?.applyColorFilter(config.textColor)
|
||||||
|
},
|
||||||
|
tabSelectedAction = {
|
||||||
|
viewpager.currentItem = it.position
|
||||||
|
it.icon?.applyColorFilter(getAdjustedPrimaryColor())
|
||||||
}
|
}
|
||||||
}
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun showSortingDialog() {
|
||||||
|
ChangeSortingDialog(this) {
|
||||||
|
contacts_fragment.initContacts()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupContacts(contacts: ArrayList<Contact>) {
|
fun showFilterDialog() {
|
||||||
contacts_placeholder_2.beVisibleIf(contacts.isEmpty())
|
FilterContactSourcesDialog(this) {
|
||||||
contacts_placeholder.beVisibleIf(contacts.isEmpty())
|
contacts_fragment.initContacts()
|
||||||
|
|
||||||
val currAdapter = contacts_list.adapter
|
|
||||||
if (currAdapter == null) {
|
|
||||||
ContactsAdapter(this, contacts, this, contacts_list) {
|
|
||||||
if (config.callContact) {
|
|
||||||
val contact = it as Contact
|
|
||||||
if (contact.phoneNumbers.isNotEmpty()) {
|
|
||||||
tryStartCall(it)
|
|
||||||
} else {
|
|
||||||
toast(R.string.no_phone_number_found)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
openContact(it as Contact)
|
|
||||||
}
|
|
||||||
}.apply {
|
|
||||||
setupDragListener(true)
|
|
||||||
addVerticalDividers(true)
|
|
||||||
contacts_list.adapter = this
|
|
||||||
}
|
|
||||||
|
|
||||||
contacts_fastscroller.setViews(contacts_list) {
|
|
||||||
val item = (contacts_list.adapter as ContactsAdapter).contactItems.getOrNull(it)
|
|
||||||
contacts_fastscroller.updateBubbleText(item?.getBubbleText() ?: "")
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
(currAdapter as ContactsAdapter).updateItems(contacts)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addNewContact() {
|
private fun launchAbout() {
|
||||||
Intent(applicationContext, ContactActivity::class.java).apply {
|
startAboutActivity(R.string.app_name, LICENSE_KOTLIN or LICENSE_MULTISELECT or LICENSE_JODA or LICENSE_GLIDE, BuildConfig.VERSION_NAME)
|
||||||
startActivity(this)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun refreshItems() {
|
|
||||||
initContacts()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
package com.simplemobiletools.contacts.adapters
|
||||||
|
|
||||||
|
import android.support.v4.view.PagerAdapter
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import com.simplemobiletools.contacts.R
|
||||||
|
import com.simplemobiletools.contacts.activities.MainActivity
|
||||||
|
import com.simplemobiletools.contacts.fragments.MyViewPagerFragment
|
||||||
|
|
||||||
|
class ViewPagerAdapter(val activity: MainActivity) : PagerAdapter() {
|
||||||
|
|
||||||
|
override fun instantiateItem(container: ViewGroup, position: Int): Any {
|
||||||
|
val layout = if (position == 0) R.layout.fragment_contacts else R.layout.fragment_favorites
|
||||||
|
val view = activity.layoutInflater.inflate(layout, container, false)
|
||||||
|
container.addView(view)
|
||||||
|
(view as MyViewPagerFragment).setupFragment(activity)
|
||||||
|
return view
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun destroyItem(container: ViewGroup, position: Int, item: Any) {
|
||||||
|
container.removeView(item as View)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getCount() = 2
|
||||||
|
override fun isViewFromObject(view: View, item: Any) = view == item
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.simplemobiletools.contacts.extensions
|
||||||
|
|
||||||
|
import android.support.design.widget.TabLayout
|
||||||
|
|
||||||
|
fun TabLayout.onTabSelectionChanged(tabUnselectedAction: (inactiveTab: TabLayout.Tab) -> Unit, tabSelectedAction: (activeTab: TabLayout.Tab) -> Unit) =
|
||||||
|
setOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
|
||||||
|
override fun onTabSelected(tab: TabLayout.Tab) {
|
||||||
|
tabSelectedAction(tab)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onTabUnselected(tab: TabLayout.Tab) {
|
||||||
|
tabUnselectedAction(tab)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onTabReselected(tab: TabLayout.Tab) {
|
||||||
|
}
|
||||||
|
})
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.simplemobiletools.contacts.extensions
|
||||||
|
|
||||||
|
import android.support.v4.view.ViewPager
|
||||||
|
|
||||||
|
fun ViewPager.onPageChanged(pageChangedAction: (activePage: Int) -> Unit) =
|
||||||
|
addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
|
||||||
|
override fun onPageSelected(position: Int) {
|
||||||
|
pageChangedAction(position)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPageScrollStateChanged(state: Int) {
|
||||||
|
}
|
||||||
|
})
|
|
@ -0,0 +1,147 @@
|
||||||
|
package com.simplemobiletools.contacts.fragments
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.graphics.Paint
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import com.simplemobiletools.commons.extensions.beVisibleIf
|
||||||
|
import com.simplemobiletools.commons.extensions.isActivityDestroyed
|
||||||
|
import com.simplemobiletools.commons.extensions.toast
|
||||||
|
import com.simplemobiletools.commons.extensions.updateTextColors
|
||||||
|
import com.simplemobiletools.commons.helpers.SORT_BY_FIRST_NAME
|
||||||
|
import com.simplemobiletools.commons.helpers.SORT_BY_SURNAME
|
||||||
|
import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener
|
||||||
|
import com.simplemobiletools.contacts.R
|
||||||
|
import com.simplemobiletools.contacts.activities.ContactActivity
|
||||||
|
import com.simplemobiletools.contacts.activities.MainActivity
|
||||||
|
import com.simplemobiletools.contacts.activities.SimpleActivity
|
||||||
|
import com.simplemobiletools.contacts.adapters.ContactsAdapter
|
||||||
|
import com.simplemobiletools.contacts.extensions.openContact
|
||||||
|
import com.simplemobiletools.contacts.extensions.tryStartCall
|
||||||
|
import com.simplemobiletools.contacts.helpers.ContactsHelper
|
||||||
|
import com.simplemobiletools.contacts.models.Contact
|
||||||
|
import kotlinx.android.synthetic.main.fragment_contacts.view.*
|
||||||
|
|
||||||
|
class ContactsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet), RefreshRecyclerViewListener {
|
||||||
|
var activity: MainActivity? = null
|
||||||
|
|
||||||
|
override fun initFragment(activity: MainActivity) {
|
||||||
|
if (this.activity == null) {
|
||||||
|
this.activity = activity
|
||||||
|
contacts_fab.setOnClickListener {
|
||||||
|
addNewContact()
|
||||||
|
}
|
||||||
|
|
||||||
|
contacts_placeholder_2.setOnClickListener {
|
||||||
|
activity.showFilterDialog()
|
||||||
|
}
|
||||||
|
|
||||||
|
contacts_placeholder_2.paintFlags = contacts_placeholder_2.paintFlags or Paint.UNDERLINE_TEXT_FLAG
|
||||||
|
updateViewStuff()
|
||||||
|
}
|
||||||
|
|
||||||
|
initContacts()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun textColorChanged(color: Int) {
|
||||||
|
(contacts_list.adapter as ContactsAdapter).apply {
|
||||||
|
updateTextColor(color)
|
||||||
|
initDrawables()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun primaryColorChanged(color: Int) {
|
||||||
|
contacts_fastscroller.updatePrimaryColor()
|
||||||
|
contacts_fab.setColors(config.textColor, color, config.backgroundColor)
|
||||||
|
contacts_fastscroller.updateBubblePrimaryColor()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun startNameWithSurnameChanged(startNameWithSurname: Boolean) {
|
||||||
|
(contacts_list.adapter as ContactsAdapter).apply {
|
||||||
|
config.sorting = if (startNameWithSurname) SORT_BY_SURNAME else SORT_BY_FIRST_NAME
|
||||||
|
initContacts()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onActivityResume() {
|
||||||
|
updateViewStuff()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateViewStuff() {
|
||||||
|
context.updateTextColors(contacts_fragment)
|
||||||
|
contacts_fastscroller.updateBubbleColors()
|
||||||
|
contacts_fastscroller.allowBubbleDisplay = config.showInfoBubble
|
||||||
|
contacts_placeholder_2.setTextColor(config.primaryColor)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun initContacts() {
|
||||||
|
if (activity == null || activity!!.isActivityDestroyed()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ContactsHelper(activity!!).getContacts {
|
||||||
|
if (activity == null || activity!!.isActivityDestroyed()) {
|
||||||
|
return@getContacts
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.lastUsedContactSource.isEmpty()) {
|
||||||
|
val grouped = it.groupBy { it.source }.maxWith(compareBy { it.value.size })
|
||||||
|
config.lastUsedContactSource = grouped?.key ?: ""
|
||||||
|
}
|
||||||
|
|
||||||
|
Contact.sorting = config.sorting
|
||||||
|
it.sort()
|
||||||
|
|
||||||
|
if (it.hashCode() != (contacts_list.adapter as? ContactsAdapter)?.contactItems?.hashCode()) {
|
||||||
|
activity!!.runOnUiThread {
|
||||||
|
setupContacts(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setupContacts(contacts: ArrayList<Contact>) {
|
||||||
|
contacts_placeholder_2.beVisibleIf(contacts.isEmpty())
|
||||||
|
contacts_placeholder.beVisibleIf(contacts.isEmpty())
|
||||||
|
|
||||||
|
val currAdapter = contacts_list.adapter
|
||||||
|
if (currAdapter == null) {
|
||||||
|
ContactsAdapter(activity as SimpleActivity, contacts, this, contacts_list) {
|
||||||
|
if (config.callContact) {
|
||||||
|
val contact = it as Contact
|
||||||
|
if (contact.phoneNumbers.isNotEmpty()) {
|
||||||
|
(activity as SimpleActivity).tryStartCall(it)
|
||||||
|
} else {
|
||||||
|
activity!!.toast(R.string.no_phone_number_found)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
context!!.openContact(it as Contact)
|
||||||
|
}
|
||||||
|
}.apply {
|
||||||
|
setupDragListener(true)
|
||||||
|
addVerticalDividers(true)
|
||||||
|
contacts_list.adapter = this
|
||||||
|
}
|
||||||
|
|
||||||
|
contacts_fastscroller.setViews(contacts_list) {
|
||||||
|
val item = (contacts_list.adapter as ContactsAdapter).contactItems.getOrNull(it)
|
||||||
|
contacts_fastscroller.updateBubbleText(item?.getBubbleText() ?: "")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
(currAdapter as ContactsAdapter).apply {
|
||||||
|
startNameWithSurname = config.startNameWithSurname
|
||||||
|
updateItems(contacts)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun addNewContact() {
|
||||||
|
Intent(context, ContactActivity::class.java).apply {
|
||||||
|
context.startActivity(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun refreshItems() {
|
||||||
|
initContacts()
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.simplemobiletools.contacts.fragments
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import com.simplemobiletools.contacts.activities.MainActivity
|
||||||
|
|
||||||
|
class FavoritesFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet) {
|
||||||
|
override fun initFragment(activity: MainActivity) {
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun textColorChanged(color: Int) {
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun primaryColorChanged(color: Int) {
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun startNameWithSurnameChanged(startNameWithSurname: Boolean) {
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onActivityResume() {
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
package com.simplemobiletools.contacts.fragments
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.support.design.widget.CoordinatorLayout
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import com.simplemobiletools.contacts.activities.MainActivity
|
||||||
|
import com.simplemobiletools.contacts.extensions.config
|
||||||
|
import com.simplemobiletools.contacts.helpers.Config
|
||||||
|
|
||||||
|
abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet) : CoordinatorLayout(context, attributeSet) {
|
||||||
|
lateinit var config: Config
|
||||||
|
|
||||||
|
fun setupFragment(activity: MainActivity) {
|
||||||
|
config = activity.config
|
||||||
|
initFragment(activity)
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract fun initFragment(activity: MainActivity)
|
||||||
|
|
||||||
|
abstract fun textColorChanged(color: Int)
|
||||||
|
|
||||||
|
abstract fun primaryColorChanged(color: Int)
|
||||||
|
|
||||||
|
abstract fun startNameWithSurnameChanged(startNameWithSurname: Boolean)
|
||||||
|
|
||||||
|
abstract fun onActivityResume()
|
||||||
|
}
|
|
@ -1,68 +1,41 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<android.support.design.widget.CoordinatorLayout
|
<RelativeLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:id="@+id/contacts_holder"
|
xmlns:tooLs="http://schemas.android.com/tools"
|
||||||
|
android:id="@+id/main_holder"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent"
|
||||||
|
tooLs:ignore="MissingPrefix">
|
||||||
|
|
||||||
<RelativeLayout
|
<android.support.design.widget.TabLayout
|
||||||
android:id="@+id/contacts_wrapper"
|
android:id="@+id/main_tabs_holder"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="48dp"
|
||||||
|
app:elevation="6dp"
|
||||||
|
app:tabIndicatorColor="@android:color/white"
|
||||||
|
app:tabIndicatorHeight="2dp"
|
||||||
|
app:tabMinWidth="150dp"
|
||||||
|
app:tabSelectedTextColor="@android:color/white">
|
||||||
|
|
||||||
<com.simplemobiletools.commons.views.MyTextView
|
<android.support.design.widget.TabItem
|
||||||
android:id="@+id/contacts_placeholder"
|
android:id="@+id/tab_contacts"
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_centerHorizontal="true"
|
|
||||||
android:layout_marginTop="@dimen/activity_margin"
|
|
||||||
android:gravity="center"
|
|
||||||
android:text="@string/no_items_found"
|
|
||||||
android:textSize="@dimen/bigger_text_size"
|
|
||||||
android:visibility="gone"/>
|
|
||||||
|
|
||||||
<com.simplemobiletools.commons.views.MyTextView
|
|
||||||
android:id="@+id/contacts_placeholder_2"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_below="@+id/contacts_placeholder"
|
|
||||||
android:layout_centerHorizontal="true"
|
|
||||||
android:gravity="center"
|
|
||||||
android:paddingBottom="@dimen/medium_margin"
|
|
||||||
android:paddingTop="@dimen/medium_margin"
|
|
||||||
android:text="@string/change_filter"
|
|
||||||
android:textSize="@dimen/bigger_text_size"
|
|
||||||
android:visibility="gone"/>
|
|
||||||
|
|
||||||
<com.simplemobiletools.commons.views.MyRecyclerView
|
|
||||||
android:id="@+id/contacts_list"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:clipToPadding="false"
|
|
||||||
android:scrollbars="none"
|
|
||||||
app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>
|
|
||||||
|
|
||||||
<com.simplemobiletools.commons.views.FastScroller
|
|
||||||
android:id="@+id/contacts_fastscroller"
|
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentEnd="true"
|
android:icon="@drawable/ic_person"/>
|
||||||
android:layout_alignParentRight="true"
|
|
||||||
android:paddingLeft="@dimen/normal_margin"
|
|
||||||
android:paddingStart="@dimen/normal_margin">
|
|
||||||
|
|
||||||
<include layout="@layout/fastscroller_handle_vertical"/>
|
<android.support.design.widget.TabItem
|
||||||
|
android:id="@+id/tab_favorites"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:icon="@drawable/ic_star_on"/>
|
||||||
|
|
||||||
</com.simplemobiletools.commons.views.FastScroller>
|
</android.support.design.widget.TabLayout>
|
||||||
</RelativeLayout>
|
|
||||||
|
|
||||||
<com.simplemobiletools.commons.views.MyFloatingActionButton
|
<com.booking.rtlviewpager.RtlViewPager
|
||||||
android:id="@+id/contacts_fab"
|
android:id="@+id/viewpager"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="match_parent"
|
||||||
android:layout_gravity="bottom|end"
|
android:layout_below="@+id/main_tabs_holder"/>
|
||||||
android:layout_margin="@dimen/activity_margin"
|
|
||||||
android:src="@drawable/ic_plus"/>
|
|
||||||
|
|
||||||
</android.support.design.widget.CoordinatorLayout>
|
</RelativeLayout>
|
||||||
|
|
68
app/src/main/res/layout/fragment_contacts.xml
Normal file
68
app/src/main/res/layout/fragment_contacts.xml
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<com.simplemobiletools.contacts.fragments.ContactsFragment
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:id="@+id/contacts_fragment"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<RelativeLayout
|
||||||
|
android:id="@+id/contacts_wrapper"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyTextView
|
||||||
|
android:id="@+id/contacts_placeholder"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_centerHorizontal="true"
|
||||||
|
android:layout_marginTop="@dimen/activity_margin"
|
||||||
|
android:gravity="center"
|
||||||
|
android:text="@string/no_items_found"
|
||||||
|
android:textSize="@dimen/bigger_text_size"
|
||||||
|
android:visibility="gone"/>
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyTextView
|
||||||
|
android:id="@+id/contacts_placeholder_2"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@+id/contacts_placeholder"
|
||||||
|
android:layout_centerHorizontal="true"
|
||||||
|
android:gravity="center"
|
||||||
|
android:paddingBottom="@dimen/medium_margin"
|
||||||
|
android:paddingTop="@dimen/medium_margin"
|
||||||
|
android:text="@string/change_filter"
|
||||||
|
android:textSize="@dimen/bigger_text_size"
|
||||||
|
android:visibility="gone"/>
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyRecyclerView
|
||||||
|
android:id="@+id/contacts_list"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:clipToPadding="false"
|
||||||
|
android:scrollbars="none"
|
||||||
|
app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.FastScroller
|
||||||
|
android:id="@+id/contacts_fastscroller"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_alignParentEnd="true"
|
||||||
|
android:layout_alignParentRight="true"
|
||||||
|
android:paddingLeft="@dimen/normal_margin"
|
||||||
|
android:paddingStart="@dimen/normal_margin">
|
||||||
|
|
||||||
|
<include layout="@layout/fastscroller_handle_vertical"/>
|
||||||
|
|
||||||
|
</com.simplemobiletools.commons.views.FastScroller>
|
||||||
|
</RelativeLayout>
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyFloatingActionButton
|
||||||
|
android:id="@+id/contacts_fab"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="bottom|end"
|
||||||
|
android:layout_margin="@dimen/activity_margin"
|
||||||
|
android:src="@drawable/ic_plus"/>
|
||||||
|
|
||||||
|
</com.simplemobiletools.contacts.fragments.ContactsFragment>
|
8
app/src/main/res/layout/fragment_favorites.xml
Normal file
8
app/src/main/res/layout/fragment_favorites.xml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<com.simplemobiletools.contacts.fragments.FavoritesFragment
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/favorites_fragment"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
</com.simplemobiletools.contacts.fragments.FavoritesFragment>
|
Loading…
Reference in a new issue