mirror of
https://github.com/SimpleMobileTools/Simple-Dialer.git
synced 2025-04-27 08:18:42 +02:00
adding the Recents tab
This commit is contained in:
parent
56f53f5659
commit
dc20b20037
@ -18,13 +18,13 @@ import com.simplemobiletools.dialer.R
|
||||
import com.simplemobiletools.dialer.adapters.ViewPagerAdapter
|
||||
import com.simplemobiletools.dialer.extensions.config
|
||||
import com.simplemobiletools.dialer.helpers.ALL_TABS_MASK
|
||||
import com.simplemobiletools.dialer.helpers.CONTACTS_TAB_MASK
|
||||
import com.simplemobiletools.dialer.helpers.RECENTS_TAB_MASK
|
||||
import com.simplemobiletools.dialer.helpers.tabsList
|
||||
import kotlinx.android.synthetic.main.activity_main.*
|
||||
import kotlinx.android.synthetic.main.fragment_contacts.*
|
||||
|
||||
class MainActivity : SimpleActivity() {
|
||||
private var isGettingContacts = false
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_main)
|
||||
@ -94,7 +94,7 @@ class MainActivity : SimpleActivity() {
|
||||
})
|
||||
|
||||
viewpager.onGlobalLayout {
|
||||
refreshContacts(ALL_TABS_MASK)
|
||||
refreshItems(ALL_TABS_MASK)
|
||||
}
|
||||
|
||||
main_tabs_holder.onTabSelectionChanged(
|
||||
@ -124,29 +124,34 @@ class MainActivity : SimpleActivity() {
|
||||
|
||||
private fun getTabIcon(position: Int): Drawable {
|
||||
val drawableId = when (position) {
|
||||
else -> R.drawable.ic_person_vector
|
||||
0 -> R.drawable.ic_person_vector
|
||||
else -> R.drawable.ic_clock_vector
|
||||
}
|
||||
|
||||
return resources.getColoredDrawableWithColor(drawableId, config.textColor)
|
||||
}
|
||||
|
||||
fun refreshContacts(refreshTabsMask: Int) {
|
||||
if (isDestroyed || isFinishing || isGettingContacts) {
|
||||
fun refreshItems(refreshTabsMask: Int) {
|
||||
if (isDestroyed || isFinishing) {
|
||||
return
|
||||
}
|
||||
|
||||
isGettingContacts = true
|
||||
|
||||
if (viewpager.adapter == null) {
|
||||
viewpager.adapter = ViewPagerAdapter(this)
|
||||
viewpager.currentItem = config.lastUsedViewPagerPage
|
||||
}
|
||||
|
||||
ContactsHelper(this).getAvailableContacts { contacts ->
|
||||
runOnUiThread {
|
||||
contacts_fragment.refreshContacts(contacts)
|
||||
if (refreshTabsMask and CONTACTS_TAB_MASK != 0) {
|
||||
ContactsHelper(this).getAvailableContacts { contacts ->
|
||||
runOnUiThread {
|
||||
contacts_fragment.refreshContacts(contacts)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (refreshTabsMask and RECENTS_TAB_MASK != 0) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private fun getAllFragments() = arrayListOf(contacts_fragment)
|
||||
|
@ -25,11 +25,15 @@ class ViewPagerAdapter(val activity: SimpleActivity) : PagerAdapter() {
|
||||
container.removeView(item as View)
|
||||
}
|
||||
|
||||
override fun getCount() = 1
|
||||
override fun getCount() = 2
|
||||
|
||||
override fun isViewFromObject(view: View, item: Any) = view == item
|
||||
|
||||
private fun getFragment(position: Int): Int {
|
||||
return R.layout.fragment_contacts
|
||||
return if (position == 0) {
|
||||
R.layout.fragment_contacts
|
||||
} else {
|
||||
R.layout.fragment_recents
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,6 @@
|
||||
package com.simplemobiletools.dialer.fragments
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
|
||||
class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet)
|
@ -2,7 +2,7 @@ package com.simplemobiletools.dialer.helpers
|
||||
|
||||
const val CONTACTS_TAB_MASK = 1
|
||||
const val FAVORITES_TAB_MASK = 2
|
||||
const val HISTORY_TAB_MASK = 4
|
||||
const val ALL_TABS_MASK = CONTACTS_TAB_MASK or FAVORITES_TAB_MASK or HISTORY_TAB_MASK
|
||||
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)
|
||||
val tabsList = arrayListOf(CONTACTS_TAB_MASK, RECENTS_TAB_MASK)
|
||||
|
44
app/src/main/res/layout/fragment_recents.xml
Normal file
44
app/src/main/res/layout/fragment_recents.xml
Normal file
@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.simplemobiletools.dialer.fragments.RecentsFragment xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/recents_fragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/recents_placeholder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:alpha="0.8"
|
||||
android:gravity="center"
|
||||
android:paddingStart="@dimen/activity_margin"
|
||||
android:paddingTop="@dimen/activity_margin"
|
||||
android:paddingEnd="@dimen/activity_margin"
|
||||
android:text="@string/no_previous_calls"
|
||||
android:textSize="@dimen/bigger_text_size"
|
||||
android:textStyle="italic"
|
||||
android:visibility="gone" />
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/recents_placeholder_2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/fragment_placeholder"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:gravity="center"
|
||||
android:padding="@dimen/activity_margin"
|
||||
android:text="@string/request_access"
|
||||
android:textSize="@dimen/bigger_text_size"
|
||||
android:visibility="gone" />
|
||||
|
||||
<com.simplemobiletools.commons.views.MyRecyclerView
|
||||
android:id="@+id/recents_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clipToPadding="false"
|
||||
android:scrollbars="none"
|
||||
app:layoutManager="com.simplemobiletools.commons.views.MyLinearLayoutManager" />
|
||||
|
||||
</com.simplemobiletools.dialer.fragments.RecentsFragment>
|
@ -1,4 +1,9 @@
|
||||
<resources>
|
||||
<string name="app_name">Simple Dialer</string>
|
||||
<string name="app_launcher_name">Dialer</string>
|
||||
|
||||
<!-- Recents -->
|
||||
<string name="no_previous_calls">No previous calls have been found</string>
|
||||
<string name="could_not_access_the_call_history">Could not access the call history</string>
|
||||
<string name="request_access">Request access</string>
|
||||
</resources>
|
||||
|
Loading…
x
Reference in New Issue
Block a user