mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-04-20 12:47:18 +02:00
creating a Recents tab
This commit is contained in:
parent
19d7ed33b3
commit
a83886a5bd
@ -37,6 +37,7 @@ import kotlinx.android.synthetic.main.activity_main.*
|
|||||||
import kotlinx.android.synthetic.main.fragment_contacts.*
|
import kotlinx.android.synthetic.main.fragment_contacts.*
|
||||||
import kotlinx.android.synthetic.main.fragment_favorites.*
|
import kotlinx.android.synthetic.main.fragment_favorites.*
|
||||||
import kotlinx.android.synthetic.main.fragment_groups.*
|
import kotlinx.android.synthetic.main.fragment_groups.*
|
||||||
|
import kotlinx.android.synthetic.main.fragment_recents.*
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
|
|
||||||
class MainActivity : SimpleActivity(), RefreshContactsListener {
|
class MainActivity : SimpleActivity(), RefreshContactsListener {
|
||||||
@ -168,7 +169,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||||||
val currentPage = viewpager?.currentItem
|
val currentPage = viewpager?.currentItem
|
||||||
menu.apply {
|
menu.apply {
|
||||||
findItem(R.id.search).isVisible = currentPage != LOCATION_GROUPS_TAB
|
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
|
findItem(R.id.filter).isVisible = currentPage != LOCATION_GROUPS_TAB
|
||||||
}
|
}
|
||||||
setupSearch(menu)
|
setupSearch(menu)
|
||||||
@ -278,7 +279,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||||||
|
|
||||||
private fun initFragments() {
|
private fun initFragments() {
|
||||||
refreshContacts(ALL_TABS_MASK)
|
refreshContacts(ALL_TABS_MASK)
|
||||||
viewpager.offscreenPageLimit = 2
|
viewpager.offscreenPageLimit = 3
|
||||||
viewpager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
|
viewpager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
|
||||||
override fun onPageScrollStateChanged(state: Int) {
|
override fun onPageScrollStateChanged(state: Int) {
|
||||||
if (isSearchOpen) {
|
if (isSearchOpen) {
|
||||||
@ -328,13 +329,14 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
main_tabs_holder.beVisibleIf(skippedTabs < 2)
|
main_tabs_holder.beVisibleIf(skippedTabs < 3)
|
||||||
invalidateOptionsMenu()
|
invalidateOptionsMenu()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getTabIcon(position: Int) = resources.getDrawable(when (position) {
|
private fun getTabIcon(position: Int) = resources.getDrawable(when (position) {
|
||||||
LOCATION_CONTACTS_TAB -> R.drawable.ic_person
|
LOCATION_CONTACTS_TAB -> R.drawable.ic_person
|
||||||
LOCATION_FAVORITES_TAB -> R.drawable.ic_star_on
|
LOCATION_FAVORITES_TAB -> R.drawable.ic_star_on
|
||||||
|
LOCATION_RECENTS_TAB -> R.drawable.ic_clock
|
||||||
else -> R.drawable.ic_group
|
else -> R.drawable.ic_group
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -465,6 +467,10 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||||||
favorites_fragment?.refreshContacts(it)
|
favorites_fragment?.refreshContacts(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (refreshTabsMask and RECENTS_TAB_MASK != 0) {
|
||||||
|
recents_fragment?.refreshContacts(it)
|
||||||
|
}
|
||||||
|
|
||||||
if (refreshTabsMask and GROUPS_TAB_MASK != 0) {
|
if (refreshTabsMask and GROUPS_TAB_MASK != 0) {
|
||||||
if (refreshTabsMask == GROUPS_TAB_MASK) {
|
if (refreshTabsMask == GROUPS_TAB_MASK) {
|
||||||
groups_fragment.skipHashComparing = true
|
groups_fragment.skipHashComparing = true
|
||||||
|
@ -7,9 +7,7 @@ import com.simplemobiletools.contacts.R
|
|||||||
import com.simplemobiletools.contacts.activities.MainActivity
|
import com.simplemobiletools.contacts.activities.MainActivity
|
||||||
import com.simplemobiletools.contacts.extensions.config
|
import com.simplemobiletools.contacts.extensions.config
|
||||||
import com.simplemobiletools.contacts.fragments.MyViewPagerFragment
|
import com.simplemobiletools.contacts.fragments.MyViewPagerFragment
|
||||||
import com.simplemobiletools.contacts.helpers.CONTACTS_TAB_MASK
|
import com.simplemobiletools.contacts.helpers.*
|
||||||
import com.simplemobiletools.contacts.helpers.FAVORITES_TAB_MASK
|
|
||||||
import com.simplemobiletools.contacts.helpers.tabsList
|
|
||||||
import com.simplemobiletools.contacts.models.Contact
|
import com.simplemobiletools.contacts.models.Contact
|
||||||
|
|
||||||
class ViewPagerAdapter(val activity: MainActivity, val contacts: ArrayList<Contact>) : PagerAdapter() {
|
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
|
override fun isViewFromObject(view: View, item: Any) = view == item
|
||||||
|
|
||||||
private fun getFragment(position: Int): Int {
|
private fun getFragment(position: Int): Int {
|
||||||
return when (position) {
|
val fragments = arrayListOf<Int>()
|
||||||
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 -> {
|
|
||||||
if (showTabs and CONTACTS_TAB_MASK != 0) {
|
if (showTabs and CONTACTS_TAB_MASK != 0) {
|
||||||
|
fragments.add(R.layout.fragment_contacts)
|
||||||
|
}
|
||||||
|
|
||||||
if (showTabs and FAVORITES_TAB_MASK != 0) {
|
if (showTabs and FAVORITES_TAB_MASK != 0) {
|
||||||
R.layout.fragment_favorites
|
fragments.add(R.layout.fragment_favorites)
|
||||||
} else {
|
|
||||||
R.layout.fragment_groups
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
R.layout.fragment_groups
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else -> R.layout.fragment_groups
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,10 +6,7 @@ import com.simplemobiletools.commons.extensions.setupDialogStuff
|
|||||||
import com.simplemobiletools.commons.views.MyAppCompatCheckbox
|
import com.simplemobiletools.commons.views.MyAppCompatCheckbox
|
||||||
import com.simplemobiletools.contacts.R
|
import com.simplemobiletools.contacts.R
|
||||||
import com.simplemobiletools.contacts.extensions.config
|
import com.simplemobiletools.contacts.extensions.config
|
||||||
import com.simplemobiletools.contacts.helpers.ALL_TABS_MASK
|
import com.simplemobiletools.contacts.helpers.*
|
||||||
import com.simplemobiletools.contacts.helpers.CONTACTS_TAB_MASK
|
|
||||||
import com.simplemobiletools.contacts.helpers.FAVORITES_TAB_MASK
|
|
||||||
import com.simplemobiletools.contacts.helpers.GROUPS_TAB_MASK
|
|
||||||
|
|
||||||
class ManageVisibleTabsDialog(val activity: BaseSimpleActivity) {
|
class ManageVisibleTabsDialog(val activity: BaseSimpleActivity) {
|
||||||
private var view = activity.layoutInflater.inflate(R.layout.dialog_manage_visible_tabs, null)
|
private var view = activity.layoutInflater.inflate(R.layout.dialog_manage_visible_tabs, null)
|
||||||
@ -19,6 +16,7 @@ class ManageVisibleTabsDialog(val activity: BaseSimpleActivity) {
|
|||||||
tabs.apply {
|
tabs.apply {
|
||||||
put(CONTACTS_TAB_MASK, R.id.manage_visible_tabs_contacts)
|
put(CONTACTS_TAB_MASK, R.id.manage_visible_tabs_contacts)
|
||||||
put(FAVORITES_TAB_MASK, R.id.manage_visible_tabs_favorites)
|
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)
|
put(GROUPS_TAB_MASK, R.id.manage_visible_tabs_groups)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,13 +47,17 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
|||||||
fragment_placeholder_2.underlineText()
|
fragment_placeholder_2.underlineText()
|
||||||
updateViewStuff()
|
updateViewStuff()
|
||||||
|
|
||||||
if (this is FavoritesFragment) {
|
when {
|
||||||
|
this is FavoritesFragment -> {
|
||||||
fragment_placeholder.text = activity.getString(R.string.no_favorites)
|
fragment_placeholder.text = activity.getString(R.string.no_favorites)
|
||||||
fragment_placeholder_2.text = activity.getString(R.string.add_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.text = activity.getString(R.string.no_group_created)
|
||||||
fragment_placeholder_2.text = activity.getString(R.string.create_group)
|
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>) {
|
fun refreshContacts(contacts: ArrayList<Contact>) {
|
||||||
if ((config.showTabs and CONTACTS_TAB_MASK == 0 && this is ContactsFragment) ||
|
if ((config.showTabs and CONTACTS_TAB_MASK == 0 && this is ContactsFragment) ||
|
||||||
(config.showTabs and FAVORITES_TAB_MASK == 0 && this is FavoritesFragment) ||
|
(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)) {
|
(config.showTabs and GROUPS_TAB_MASK == 0 && this is GroupsFragment)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -105,6 +110,7 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
|||||||
val filtered = when {
|
val filtered = when {
|
||||||
this is GroupsFragment -> contacts
|
this is GroupsFragment -> contacts
|
||||||
this is FavoritesFragment -> contacts.filter { it.starred == 1 } as ArrayList<Contact>
|
this is FavoritesFragment -> contacts.filter { it.starred == 1 } as ArrayList<Contact>
|
||||||
|
this is RecentsFragment -> ArrayList()
|
||||||
else -> {
|
else -> {
|
||||||
val contactSources = activity!!.getVisibleContactSources()
|
val contactSources = activity!!.getVisibleContactSources()
|
||||||
contacts.filter { contactSources.contains(it.source) } as ArrayList<Contact>
|
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>) {
|
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_placeholder.beVisibleIf(contacts.isEmpty())
|
||||||
fragment_list.beVisibleIf(contacts.isNotEmpty())
|
fragment_list.beVisibleIf(contacts.isNotEmpty())
|
||||||
|
|
||||||
|
@ -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() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -24,16 +24,19 @@ const val FIRST_GROUP_ID = 10000
|
|||||||
|
|
||||||
const val LOCATION_CONTACTS_TAB = 0
|
const val LOCATION_CONTACTS_TAB = 0
|
||||||
const val LOCATION_FAVORITES_TAB = 1
|
const val LOCATION_FAVORITES_TAB = 1
|
||||||
const val LOCATION_GROUPS_TAB = 2
|
const val LOCATION_RECENTS_TAB = 2
|
||||||
const val LOCATION_GROUP_CONTACTS = 3
|
const val LOCATION_GROUPS_TAB = 3
|
||||||
|
const val LOCATION_GROUP_CONTACTS = 4
|
||||||
|
|
||||||
const val CONTACTS_TAB_MASK = 1
|
const val CONTACTS_TAB_MASK = 1
|
||||||
const val FAVORITES_TAB_MASK = 2
|
const val FAVORITES_TAB_MASK = 2
|
||||||
const val GROUPS_TAB_MASK = 4
|
const val RECENTS_TAB_MASK = 4
|
||||||
const val ALL_TABS_MASK = 7
|
const val GROUPS_TAB_MASK = 8
|
||||||
|
const val ALL_TABS_MASK = 15
|
||||||
|
|
||||||
val tabsList = arrayListOf(CONTACTS_TAB_MASK,
|
val tabsList = arrayListOf(CONTACTS_TAB_MASK,
|
||||||
FAVORITES_TAB_MASK,
|
FAVORITES_TAB_MASK,
|
||||||
|
RECENTS_TAB_MASK,
|
||||||
GROUPS_TAB_MASK
|
GROUPS_TAB_MASK
|
||||||
)
|
)
|
||||||
|
|
||||||
|
BIN
app/src/main/res/drawable-hdpi/ic_clock.png
Normal file
BIN
app/src/main/res/drawable-hdpi/ic_clock.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 487 B |
BIN
app/src/main/res/drawable-xhdpi/ic_clock.png
Normal file
BIN
app/src/main/res/drawable-xhdpi/ic_clock.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 655 B |
BIN
app/src/main/res/drawable-xxhdpi/ic_clock.png
Normal file
BIN
app/src/main/res/drawable-xxhdpi/ic_clock.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 947 B |
BIN
app/src/main/res/drawable-xxxhdpi/ic_clock.png
Normal file
BIN
app/src/main/res/drawable-xxxhdpi/ic_clock.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
@ -30,6 +30,14 @@
|
|||||||
android:paddingTop="@dimen/activity_margin"
|
android:paddingTop="@dimen/activity_margin"
|
||||||
android:text="@string/favorites"/>
|
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
|
<com.simplemobiletools.commons.views.MyAppCompatCheckbox
|
||||||
android:id="@+id/manage_visible_tabs_groups"
|
android:id="@+id/manage_visible_tabs_groups"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
10
app/src/main/res/layout/fragment_recents.xml
Normal file
10
app/src/main/res/layout/fragment_recents.xml
Normal 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>
|
Loading…
x
Reference in New Issue
Block a user