creating a Recents tab

This commit is contained in:
tibbi 2018-08-03 13:52:44 +02:00
parent 19d7ed33b3
commit a83886a5bd
12 changed files with 81 additions and 41 deletions

View File

@ -37,6 +37,7 @@ 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 kotlinx.android.synthetic.main.fragment_recents.*
import java.io.FileOutputStream
class MainActivity : SimpleActivity(), RefreshContactsListener {
@ -168,7 +169,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
val currentPage = viewpager?.currentItem
menu.apply {
findItem(R.id.search).isVisible = currentPage != LOCATION_GROUPS_TAB
findItem(R.id.sort).isVisible = currentPage != LOCATION_GROUPS_TAB
findItem(R.id.sort).isVisible = currentPage != LOCATION_GROUPS_TAB && currentPage != LOCATION_RECENTS_TAB
findItem(R.id.filter).isVisible = currentPage != LOCATION_GROUPS_TAB
}
setupSearch(menu)
@ -278,7 +279,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
private fun initFragments() {
refreshContacts(ALL_TABS_MASK)
viewpager.offscreenPageLimit = 2
viewpager.offscreenPageLimit = 3
viewpager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
override fun onPageScrollStateChanged(state: Int) {
if (isSearchOpen) {
@ -328,13 +329,14 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
}
}
main_tabs_holder.beVisibleIf(skippedTabs < 2)
main_tabs_holder.beVisibleIf(skippedTabs < 3)
invalidateOptionsMenu()
}
private fun getTabIcon(position: Int) = resources.getDrawable(when (position) {
LOCATION_CONTACTS_TAB -> R.drawable.ic_person
LOCATION_FAVORITES_TAB -> R.drawable.ic_star_on
LOCATION_RECENTS_TAB -> R.drawable.ic_clock
else -> R.drawable.ic_group
})
@ -465,6 +467,10 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
favorites_fragment?.refreshContacts(it)
}
if (refreshTabsMask and RECENTS_TAB_MASK != 0) {
recents_fragment?.refreshContacts(it)
}
if (refreshTabsMask and GROUPS_TAB_MASK != 0) {
if (refreshTabsMask == GROUPS_TAB_MASK) {
groups_fragment.skipHashComparing = true

View File

@ -7,9 +7,7 @@ import com.simplemobiletools.contacts.R
import com.simplemobiletools.contacts.activities.MainActivity
import com.simplemobiletools.contacts.extensions.config
import com.simplemobiletools.contacts.fragments.MyViewPagerFragment
import com.simplemobiletools.contacts.helpers.CONTACTS_TAB_MASK
import com.simplemobiletools.contacts.helpers.FAVORITES_TAB_MASK
import com.simplemobiletools.contacts.helpers.tabsList
import com.simplemobiletools.contacts.helpers.*
import com.simplemobiletools.contacts.models.Contact
class ViewPagerAdapter(val activity: MainActivity, val contacts: ArrayList<Contact>) : PagerAdapter() {
@ -36,26 +34,23 @@ class ViewPagerAdapter(val activity: MainActivity, val contacts: ArrayList<Conta
override fun isViewFromObject(view: View, item: Any) = view == item
private fun getFragment(position: Int): Int {
return when (position) {
0 -> {
when {
showTabs and CONTACTS_TAB_MASK != 0 -> R.layout.fragment_contacts
showTabs and FAVORITES_TAB_MASK != 0 -> R.layout.fragment_favorites
else -> R.layout.fragment_groups
}
}
1 -> {
val fragments = arrayListOf<Int>()
if (showTabs and CONTACTS_TAB_MASK != 0) {
fragments.add(R.layout.fragment_contacts)
}
if (showTabs and FAVORITES_TAB_MASK != 0) {
R.layout.fragment_favorites
} else {
R.layout.fragment_groups
}
} else {
R.layout.fragment_groups
}
}
else -> R.layout.fragment_groups
fragments.add(R.layout.fragment_favorites)
}
if (showTabs and RECENTS_TAB_MASK != 0) {
fragments.add(R.layout.fragment_recents)
}
if (showTabs and GROUPS_TAB_MASK != 0) {
fragments.add(R.layout.fragment_groups)
}
return fragments[position]
}
}

View File

@ -6,10 +6,7 @@ import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.views.MyAppCompatCheckbox
import com.simplemobiletools.contacts.R
import com.simplemobiletools.contacts.extensions.config
import com.simplemobiletools.contacts.helpers.ALL_TABS_MASK
import com.simplemobiletools.contacts.helpers.CONTACTS_TAB_MASK
import com.simplemobiletools.contacts.helpers.FAVORITES_TAB_MASK
import com.simplemobiletools.contacts.helpers.GROUPS_TAB_MASK
import com.simplemobiletools.contacts.helpers.*
class ManageVisibleTabsDialog(val activity: BaseSimpleActivity) {
private var view = activity.layoutInflater.inflate(R.layout.dialog_manage_visible_tabs, null)
@ -19,6 +16,7 @@ class ManageVisibleTabsDialog(val activity: BaseSimpleActivity) {
tabs.apply {
put(CONTACTS_TAB_MASK, R.id.manage_visible_tabs_contacts)
put(FAVORITES_TAB_MASK, R.id.manage_visible_tabs_favorites)
put(RECENTS_TAB_MASK, R.id.manage_visible_tabs_recents)
put(GROUPS_TAB_MASK, R.id.manage_visible_tabs_groups)
}

View File

@ -47,13 +47,17 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
fragment_placeholder_2.underlineText()
updateViewStuff()
if (this is FavoritesFragment) {
when {
this is FavoritesFragment -> {
fragment_placeholder.text = activity.getString(R.string.no_favorites)
fragment_placeholder_2.text = activity.getString(R.string.add_favorites)
} else if (this is GroupsFragment) {
}
this is GroupsFragment -> {
fragment_placeholder.text = activity.getString(R.string.no_group_created)
fragment_placeholder_2.text = activity.getString(R.string.create_group)
}
this is RecentsFragment -> fragment_fab.beGone()
}
}
}
@ -88,6 +92,7 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
fun refreshContacts(contacts: ArrayList<Contact>) {
if ((config.showTabs and CONTACTS_TAB_MASK == 0 && this is ContactsFragment) ||
(config.showTabs and FAVORITES_TAB_MASK == 0 && this is FavoritesFragment) ||
(config.showTabs and RECENTS_TAB_MASK == 0 && this is RecentsFragment) ||
(config.showTabs and GROUPS_TAB_MASK == 0 && this is GroupsFragment)) {
return
}
@ -105,6 +110,7 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
val filtered = when {
this is GroupsFragment -> contacts
this is FavoritesFragment -> contacts.filter { it.starred == 1 } as ArrayList<Contact>
this is RecentsFragment -> ArrayList()
else -> {
val contactSources = activity!!.getVisibleContactSources()
contacts.filter { contactSources.contains(it.source) } as ArrayList<Contact>
@ -170,7 +176,7 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
}
private fun setupContactsFavoritesAdapter(contacts: ArrayList<Contact>) {
fragment_placeholder_2.beVisibleIf(contacts.isEmpty())
fragment_placeholder_2.beVisibleIf(contacts.isEmpty() && this !is RecentsFragment)
fragment_placeholder.beVisibleIf(contacts.isEmpty())
fragment_list.beVisibleIf(contacts.isNotEmpty())

View File

@ -0,0 +1,14 @@
package com.simplemobiletools.contacts.fragments
import android.content.Context
import android.util.AttributeSet
class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet) {
override fun fabClicked() {
finishActMode()
}
override fun placeholderClicked() {
}
}

View File

@ -24,16 +24,19 @@ const val FIRST_GROUP_ID = 10000
const val LOCATION_CONTACTS_TAB = 0
const val LOCATION_FAVORITES_TAB = 1
const val LOCATION_GROUPS_TAB = 2
const val LOCATION_GROUP_CONTACTS = 3
const val LOCATION_RECENTS_TAB = 2
const val LOCATION_GROUPS_TAB = 3
const val LOCATION_GROUP_CONTACTS = 4
const val CONTACTS_TAB_MASK = 1
const val FAVORITES_TAB_MASK = 2
const val GROUPS_TAB_MASK = 4
const val ALL_TABS_MASK = 7
const val RECENTS_TAB_MASK = 4
const val GROUPS_TAB_MASK = 8
const val ALL_TABS_MASK = 15
val tabsList = arrayListOf(CONTACTS_TAB_MASK,
FAVORITES_TAB_MASK,
RECENTS_TAB_MASK,
GROUPS_TAB_MASK
)

Binary file not shown.

After

Width:  |  Height:  |  Size: 487 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 655 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 947 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -30,6 +30,14 @@
android:paddingTop="@dimen/activity_margin"
android:text="@string/favorites"/>
<com.simplemobiletools.commons.views.MyAppCompatCheckbox
android:id="@+id/manage_visible_tabs_recents"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/activity_margin"
android:paddingTop="@dimen/activity_margin"
android:text="@string/recent_calls"/>
<com.simplemobiletools.commons.views.MyAppCompatCheckbox
android:id="@+id/manage_visible_tabs_groups"
android:layout_width="match_parent"

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<com.simplemobiletools.contacts.fragments.RecentsFragment
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/recents_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/fragment_layout"/>
</com.simplemobiletools.contacts.fragments.RecentsFragment>