mirror of
https://github.com/SimpleMobileTools/Simple-Dialer.git
synced 2025-02-15 19:10:44 +01:00
adding a Favorites tab
This commit is contained in:
parent
68f8e337fc
commit
b646d18f81
@ -27,6 +27,7 @@ import com.simplemobiletools.dialer.fragments.MyViewPagerFragment
|
||||
import com.simplemobiletools.dialer.helpers.tabsList
|
||||
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_recents.*
|
||||
import java.util.*
|
||||
|
||||
@ -283,6 +284,7 @@ class MainActivity : SimpleActivity() {
|
||||
private fun getTabIcon(position: Int): Drawable {
|
||||
val drawableId = when (position) {
|
||||
0 -> R.drawable.ic_person_vector
|
||||
1 -> R.drawable.ic_star_on_vector
|
||||
else -> R.drawable.ic_clock_vector
|
||||
}
|
||||
|
||||
@ -300,10 +302,11 @@ class MainActivity : SimpleActivity() {
|
||||
}
|
||||
|
||||
contacts_fragment?.refreshItems()
|
||||
favorites_fragment?.refreshItems()
|
||||
recents_fragment?.refreshItems()
|
||||
}
|
||||
|
||||
private fun getAllFragments() = arrayListOf(contacts_fragment, recents_fragment).toMutableList() as ArrayList<MyViewPagerFragment>
|
||||
private fun getAllFragments() = arrayListOf(contacts_fragment, favorites_fragment, recents_fragment).toMutableList() as ArrayList<MyViewPagerFragment>
|
||||
|
||||
private fun launchAbout() {
|
||||
val licenses = LICENSE_GLIDE or LICENSE_INDICATOR_FAST_SCROLL
|
||||
|
@ -27,7 +27,8 @@ import com.simplemobiletools.dialer.activities.SimpleActivity
|
||||
import com.simplemobiletools.dialer.interfaces.RefreshItemsListener
|
||||
|
||||
class ContactsAdapter(activity: SimpleActivity, var contacts: ArrayList<SimpleContact>, recyclerView: MyRecyclerView, val refreshItemsListener: RefreshItemsListener? = null,
|
||||
highlightText: String = "", itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, null, itemClick) {
|
||||
highlightText: String = "", val showDeleteButton: Boolean = true, itemClick: (Any) -> Unit) :
|
||||
MyRecyclerViewAdapter(activity, recyclerView, null, itemClick) {
|
||||
|
||||
private var textToHighlight = highlightText
|
||||
private var adjustedPrimaryColor = activity.getAdjustedPrimaryColor()
|
||||
@ -41,6 +42,7 @@ class ContactsAdapter(activity: SimpleActivity, var contacts: ArrayList<SimpleCo
|
||||
|
||||
override fun prepareActionMode(menu: Menu) {
|
||||
menu.apply {
|
||||
findItem(R.id.cab_delete).isVisible = showDeleteButton
|
||||
findItem(R.id.cab_create_shortcut).isVisible = isOneItemSelected() && isOreoPlus()
|
||||
}
|
||||
}
|
||||
|
@ -25,15 +25,15 @@ class ViewPagerAdapter(val activity: SimpleActivity) : PagerAdapter() {
|
||||
container.removeView(item as View)
|
||||
}
|
||||
|
||||
override fun getCount() = 2
|
||||
override fun getCount() = 3
|
||||
|
||||
override fun isViewFromObject(view: View, item: Any) = view == item
|
||||
|
||||
private fun getFragment(position: Int): Int {
|
||||
return if (position == 0) {
|
||||
R.layout.fragment_contacts
|
||||
} else {
|
||||
R.layout.fragment_recents
|
||||
return when (position) {
|
||||
0 -> R.layout.fragment_contacts
|
||||
1 -> R.layout.fragment_favorites
|
||||
else -> R.layout.fragment_recents
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,91 @@
|
||||
package com.simplemobiletools.dialer.fragments
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import com.reddit.indicatorfastscroll.FastScrollItemIndicator
|
||||
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.PERMISSION_READ_CONTACTS
|
||||
import com.simplemobiletools.commons.helpers.SimpleContactsHelper
|
||||
import com.simplemobiletools.commons.models.SimpleContact
|
||||
import com.simplemobiletools.dialer.R
|
||||
import com.simplemobiletools.dialer.activities.SimpleActivity
|
||||
import com.simplemobiletools.dialer.adapters.ContactsAdapter
|
||||
import com.simplemobiletools.dialer.extensions.config
|
||||
import com.simplemobiletools.dialer.interfaces.RefreshItemsListener
|
||||
import kotlinx.android.synthetic.main.fragment_letters_layout.view.*
|
||||
import java.util.*
|
||||
|
||||
class FavoritesFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet), RefreshItemsListener {
|
||||
private var allContacts = ArrayList<SimpleContact>()
|
||||
|
||||
override fun setupFragment() {
|
||||
val placeholderResId = if (context.hasPermission(PERMISSION_READ_CONTACTS)) {
|
||||
R.string.no_items_found
|
||||
} else {
|
||||
R.string.could_not_access_contacts
|
||||
}
|
||||
|
||||
fragment_placeholder.text = context.getString(placeholderResId)
|
||||
|
||||
letter_fastscroller.textColor = context.config.textColor.getColorStateList()
|
||||
letter_fastscroller_thumb.setupWithFastScroller(letter_fastscroller)
|
||||
letter_fastscroller_thumb.textColor = context.config.primaryColor.getContrastColor()
|
||||
|
||||
fragment_fab.beGone()
|
||||
fragment_placeholder_2.beGone()
|
||||
}
|
||||
|
||||
override fun textColorChanged(color: Int) {
|
||||
(fragment_list?.adapter as? MyRecyclerViewAdapter)?.updateTextColor(color)
|
||||
letter_fastscroller?.textColor = color.getColorStateList()
|
||||
}
|
||||
|
||||
override fun primaryColorChanged(color: Int) {
|
||||
letter_fastscroller_thumb?.thumbColor = color.getColorStateList()
|
||||
letter_fastscroller_thumb?.textColor = color.getContrastColor()
|
||||
}
|
||||
|
||||
override fun refreshItems() {
|
||||
SimpleContactsHelper(context).getAvailableContacts(true) { contacts ->
|
||||
allContacts = contacts
|
||||
activity?.runOnUiThread {
|
||||
gotContacts(contacts)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun gotContacts(contacts: ArrayList<SimpleContact>) {
|
||||
setupLetterFastscroller(contacts)
|
||||
if (contacts.isEmpty()) {
|
||||
fragment_placeholder.beVisible()
|
||||
fragment_list.beGone()
|
||||
} else {
|
||||
fragment_placeholder.beGone()
|
||||
fragment_list.beVisible()
|
||||
|
||||
val currAdapter = fragment_list.adapter
|
||||
if (currAdapter == null) {
|
||||
ContactsAdapter(activity as SimpleActivity, contacts, fragment_list, this, showDeleteButton = false) {
|
||||
activity?.launchCallIntent((it as SimpleContact).phoneNumber)
|
||||
}.apply {
|
||||
fragment_list.adapter = this
|
||||
}
|
||||
} else {
|
||||
(currAdapter as ContactsAdapter).updateItems(contacts)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupLetterFastscroller(contacts: ArrayList<SimpleContact>) {
|
||||
letter_fastscroller.setupWithRecyclerView(fragment_list, { position ->
|
||||
try {
|
||||
val name = contacts[position].name
|
||||
val character = if (name.isNotEmpty()) name.substring(0, 1) else ""
|
||||
FastScrollItemIndicator.Text(character.toUpperCase(Locale.getDefault()))
|
||||
} catch (e: Exception) {
|
||||
FastScrollItemIndicator.Text("")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
@ -8,7 +8,7 @@ const val CONTACTS_TAB_MASK = 1
|
||||
const val FAVORITES_TAB_MASK = 2
|
||||
const val RECENTS_TAB_MASK = 4
|
||||
|
||||
val tabsList = arrayListOf(CONTACTS_TAB_MASK, RECENTS_TAB_MASK)
|
||||
val tabsList = arrayListOf(CONTACTS_TAB_MASK, FAVORITES_TAB_MASK, RECENTS_TAB_MASK)
|
||||
|
||||
private const val PATH = "com.simplemobiletools.dialer.action."
|
||||
const val ACCEPT_CALL = PATH + "accept_call"
|
||||
|
9
app/src/main/res/layout/fragment_favorites.xml
Normal file
9
app/src/main/res/layout/fragment_favorites.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.simplemobiletools.dialer.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">
|
||||
|
||||
<include layout="@layout/fragment_letters_layout" />
|
||||
|
||||
</com.simplemobiletools.dialer.fragments.FavoritesFragment>
|
Loading…
x
Reference in New Issue
Block a user