mirror of
https://github.com/SimpleMobileTools/Simple-Dialer.git
synced 2025-03-17 11:50:24 +01:00
update fragments when necessary
This commit is contained in:
parent
7ed54611cd
commit
8dcd610811
app/src/main/kotlin/com/simplemobiletools/dialer
activities
adapters
fragments
helpers
@ -15,7 +15,8 @@ import com.simplemobiletools.dialer.BuildConfig
|
||||
import com.simplemobiletools.dialer.R
|
||||
import com.simplemobiletools.dialer.adapters.ViewPagerAdapter
|
||||
import com.simplemobiletools.dialer.extensions.config
|
||||
import com.simplemobiletools.dialer.helpers.*
|
||||
import com.simplemobiletools.dialer.helpers.RecentsHelper
|
||||
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_recents.*
|
||||
@ -23,6 +24,7 @@ import kotlinx.android.synthetic.main.fragment_recents.*
|
||||
class MainActivity : SimpleActivity() {
|
||||
private var storedTextColor = 0
|
||||
private var storedPrimaryColor = 0
|
||||
private var wasFragmentInit = false
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@ -67,6 +69,10 @@ class MainActivity : SimpleActivity() {
|
||||
it?.primaryColorChanged(configPrimaryColor)
|
||||
}
|
||||
}
|
||||
|
||||
if (wasFragmentInit) {
|
||||
refreshItems()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
@ -154,7 +160,7 @@ class MainActivity : SimpleActivity() {
|
||||
})
|
||||
|
||||
viewpager.onGlobalLayout {
|
||||
refreshItems(ALL_TABS_MASK)
|
||||
refreshItems()
|
||||
}
|
||||
|
||||
main_tabs_holder.onTabSelectionChanged(
|
||||
@ -186,6 +192,8 @@ class MainActivity : SimpleActivity() {
|
||||
startActivity(this)
|
||||
}
|
||||
}
|
||||
|
||||
wasFragmentInit = true
|
||||
}
|
||||
|
||||
private fun getTabIcon(position: Int): Drawable {
|
||||
@ -197,7 +205,7 @@ class MainActivity : SimpleActivity() {
|
||||
return resources.getColoredDrawableWithColor(drawableId, config.textColor)
|
||||
}
|
||||
|
||||
fun refreshItems(refreshTabsMask: Int) {
|
||||
private fun refreshItems() {
|
||||
if (isDestroyed || isFinishing) {
|
||||
return
|
||||
}
|
||||
@ -207,19 +215,15 @@ class MainActivity : SimpleActivity() {
|
||||
viewpager.currentItem = config.lastUsedViewPagerPage
|
||||
}
|
||||
|
||||
if (refreshTabsMask and CONTACTS_TAB_MASK != 0) {
|
||||
SimpleContactsHelper(this).getAvailableContacts { contacts ->
|
||||
runOnUiThread {
|
||||
contacts_fragment.refreshContacts(contacts)
|
||||
}
|
||||
SimpleContactsHelper(this).getAvailableContacts { contacts ->
|
||||
runOnUiThread {
|
||||
contacts_fragment.refreshContacts(contacts)
|
||||
}
|
||||
}
|
||||
|
||||
if (refreshTabsMask and RECENTS_TAB_MASK != 0) {
|
||||
RecentsHelper(this).getRecentCalls { recents ->
|
||||
runOnUiThread {
|
||||
recents_fragment.updateRecents(recents)
|
||||
}
|
||||
RecentsHelper(this).getRecentCalls { recents ->
|
||||
runOnUiThread {
|
||||
recents_fragment.updateRecents(recents)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -66,7 +66,6 @@ class ContactsAdapter(activity: SimpleActivity, var contacts: ArrayList<SimpleCo
|
||||
textToHighlight = highlightText
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
fastScroller?.measureRecyclerView()
|
||||
}
|
||||
|
||||
override fun onViewRecycled(holder: ViewHolder) {
|
||||
|
@ -71,6 +71,14 @@ class RecentCallsAdapter(activity: SimpleActivity, var recentCalls: ArrayList<Re
|
||||
outgoingCallIcon = activity.resources.getColoredDrawableWithColor(R.drawable.ic_outgoing_call_vector, activity.config.textColor)
|
||||
}
|
||||
|
||||
fun updateItems(newItems: ArrayList<RecentCall>) {
|
||||
if (newItems.hashCode() != recentCalls.hashCode()) {
|
||||
recentCalls = newItems.clone() as ArrayList<RecentCall>
|
||||
notifyDataSetChanged()
|
||||
finishActMode()
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupView(view: View, call: RecentCall) {
|
||||
view.apply {
|
||||
item_recents_name.apply {
|
||||
|
@ -81,12 +81,18 @@ class ContactsFragment(context: Context, attributeSet: AttributeSet) : MyViewPag
|
||||
fragment_placeholder.beGone()
|
||||
fragment_placeholder_2.beGone()
|
||||
fragment_list.beVisible()
|
||||
ContactsAdapter(activity as SimpleActivity, contacts, fragment_list) {
|
||||
val lookupKey = SimpleContactsHelper(activity!!).getContactLookupKey((it as SimpleContact).rawId.toString())
|
||||
val publicUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey)
|
||||
activity!!.launchViewContactIntent(publicUri)
|
||||
}.apply {
|
||||
fragment_list.adapter = this
|
||||
|
||||
val currAdapter = fragment_list.adapter
|
||||
if (currAdapter == null) {
|
||||
ContactsAdapter(activity as SimpleActivity, contacts, fragment_list) {
|
||||
val lookupKey = SimpleContactsHelper(activity!!).getContactLookupKey((it as SimpleContact).rawId.toString())
|
||||
val publicUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey)
|
||||
activity!!.launchViewContactIntent(publicUri)
|
||||
}.apply {
|
||||
fragment_list.adapter = this
|
||||
}
|
||||
} else {
|
||||
(currAdapter as ContactsAdapter).updateItems(contacts)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import com.simplemobiletools.dialer.activities.SimpleActivity
|
||||
import com.simplemobiletools.dialer.extensions.config
|
||||
import com.simplemobiletools.dialer.helpers.Config
|
||||
import kotlinx.android.synthetic.main.fragment_letters_layout.view.*
|
||||
import kotlinx.android.synthetic.main.fragment_recents.view.*
|
||||
|
||||
abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet) : RelativeLayout(context, attributeSet) {
|
||||
protected var activity: SimpleActivity? = null
|
||||
@ -24,7 +25,8 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
||||
}
|
||||
|
||||
fun finishActMode() {
|
||||
(fragment_list.adapter as? MyRecyclerViewAdapter)?.finishActMode()
|
||||
(fragment_list?.adapter as? MyRecyclerViewAdapter)?.finishActMode()
|
||||
(recents_list?.adapter as? MyRecyclerViewAdapter)?.finishActMode()
|
||||
}
|
||||
|
||||
abstract fun setupFragment()
|
||||
|
@ -6,6 +6,7 @@ import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.PERMISSION_READ_CALL_LOG
|
||||
import com.simplemobiletools.dialer.R
|
||||
import com.simplemobiletools.dialer.activities.SimpleActivity
|
||||
import com.simplemobiletools.dialer.adapters.ContactsAdapter
|
||||
import com.simplemobiletools.dialer.adapters.RecentCallsAdapter
|
||||
import com.simplemobiletools.dialer.extensions.config
|
||||
import com.simplemobiletools.dialer.helpers.RecentsHelper
|
||||
@ -48,10 +49,16 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
|
||||
recents_placeholder.beGone()
|
||||
recents_placeholder_2.beGone()
|
||||
recents_list.beVisible()
|
||||
RecentCallsAdapter(activity as SimpleActivity, recents, recents_list) {
|
||||
activity?.launchCallIntent((it as RecentCall).phoneNumber)
|
||||
}.apply {
|
||||
recents_list.adapter = this
|
||||
|
||||
val currAdapter = recents_list.adapter
|
||||
if (currAdapter == null) {
|
||||
RecentCallsAdapter(activity as SimpleActivity, recents, recents_list) {
|
||||
activity?.launchCallIntent((it as RecentCall).phoneNumber)
|
||||
}.apply {
|
||||
recents_list.adapter = this
|
||||
}
|
||||
} else {
|
||||
(currAdapter as RecentCallsAdapter).updateItems(recents)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ const val REMEMBER_SIM_PREFIX = "remember_sim_"
|
||||
const val CONTACTS_TAB_MASK = 1
|
||||
const val FAVORITES_TAB_MASK = 2
|
||||
const val RECENTS_TAB_MASK = 4
|
||||
const val ALL_TABS_MASK = CONTACTS_TAB_MASK or FAVORITES_TAB_MASK or RECENTS_TAB_MASK
|
||||
|
||||
val tabsList = arrayListOf(CONTACTS_TAB_MASK, RECENTS_TAB_MASK)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user