list the last 100 calls at the Recent calls list

This commit is contained in:
tibbi 2018-08-03 16:36:17 +02:00
parent 79e8234d43
commit 71f3e8cb0c
7 changed files with 134 additions and 9 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 {
@ -477,11 +478,11 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
}
groups_fragment?.refreshContacts(it)
}
}
if (refreshTabsMask and RECENTS_TAB_MASK != 0) {
ContactsHelper(this).getRecents {
if (refreshTabsMask and RECENTS_TAB_MASK != 0) {
ContactsHelper(this).getRecents {
recents_fragment?.updateRecentCalls(it)
}
}
}
}

View File

@ -0,0 +1,67 @@
package com.simplemobiletools.contacts.adapters
import android.view.Menu
import android.view.View
import android.view.ViewGroup
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
import com.simplemobiletools.commons.views.FastScroller
import com.simplemobiletools.commons.views.MyRecyclerView
import com.simplemobiletools.contacts.R
import com.simplemobiletools.contacts.activities.SimpleActivity
import com.simplemobiletools.contacts.models.RecentCall
import kotlinx.android.synthetic.main.item_recent_call.view.*
import java.util.*
class RecentCallsAdapter(activity: SimpleActivity, var recentCalls: ArrayList<RecentCall>, recyclerView: MyRecyclerView, fastScroller: FastScroller,
itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) {
init {
setupDragListener(true)
}
override fun getActionMenuId() = 0
override fun prepareActionMode(menu: Menu) {}
override fun prepareItemSelection(viewHolder: ViewHolder) {}
override fun markViewHolderSelection(select: Boolean, viewHolder: ViewHolder?) {}
override fun actionItemPressed(id: Int) {
if (selectedPositions.isEmpty()) {
return
}
}
override fun getSelectableItemCount() = recentCalls.size
override fun getIsItemSelectable(position: Int) = true
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = createViewHolder(R.layout.item_recent_call, parent)
override fun onBindViewHolder(holder: MyRecyclerViewAdapter.ViewHolder, position: Int) {
val recentCall = recentCalls[position]
val view = holder.bindView(recentCall, true, true) { itemView, layoutPosition ->
setupView(itemView, recentCall)
}
bindViewHolder(holder, position, view)
}
override fun getItemCount() = recentCalls.size
fun updateItems(newItems: ArrayList<RecentCall>) {
recentCalls = newItems
notifyDataSetChanged()
finishActMode()
fastScroller?.measureRecyclerView()
}
private fun setupView(view: View, recentCall: RecentCall) {
view.apply {
recent_call_name.apply {
text = recentCall.name ?: recentCall.number
setTextColor(textColor)
}
}
}
}

View File

@ -129,7 +129,7 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
private fun setupContacts(contacts: ArrayList<Contact>) {
if (this is GroupsFragment) {
setupGroupsAdapter(contacts)
} else {
} else if (this !is RecentsFragment) {
setupContactsFavoritesAdapter(contacts)
}
}
@ -176,7 +176,7 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
}
private fun setupContactsFavoritesAdapter(contacts: ArrayList<Contact>) {
fragment_placeholder_2.beVisibleIf(contacts.isEmpty() && this !is RecentsFragment)
fragment_placeholder_2.beVisibleIf(contacts.isEmpty())
fragment_placeholder.beVisibleIf(contacts.isEmpty())
fragment_list.beVisibleIf(contacts.isNotEmpty())

View File

@ -2,6 +2,11 @@ package com.simplemobiletools.contacts.fragments
import android.content.Context
import android.util.AttributeSet
import com.simplemobiletools.commons.extensions.beVisibleIf
import com.simplemobiletools.commons.extensions.isActivityDestroyed
import com.simplemobiletools.contacts.adapters.RecentCallsAdapter
import com.simplemobiletools.contacts.models.RecentCall
import kotlinx.android.synthetic.main.fragment_layout.view.*
class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet) {
override fun fabClicked() {
@ -11,4 +16,25 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
override fun placeholderClicked() {
}
fun updateRecentCalls(recentCalls: ArrayList<RecentCall>) {
if (activity == null || activity!!.isActivityDestroyed()) {
return
}
fragment_placeholder.beVisibleIf(recentCalls.isEmpty())
fragment_list.beVisibleIf(recentCalls.isNotEmpty())
val currAdapter = fragment_list.adapter
if (currAdapter == null) {
RecentCallsAdapter(activity!!, recentCalls, fragment_list, fragment_fastscroller) {
}.apply {
addVerticalDividers(true)
fragment_list.adapter = this
}
} else {
(currAdapter as RecentCallsAdapter).updateItems(recentCalls)
}
}
}

View File

@ -1331,7 +1331,7 @@ class ContactsHelper(val activity: Activity) {
CallLog.Calls.TYPE
)
val sorting = "${CallLog.Calls._ID} DESC LIMIT 50"
val sorting = "${CallLog.Calls._ID} DESC LIMIT 100"
var cursor: Cursor? = null
try {
@ -1342,7 +1342,7 @@ class ContactsHelper(val activity: Activity) {
val number = cursor.getStringValue(CallLog.Calls.NUMBER)
val date = cursor.getLongValue(CallLog.Calls.DATE)
val duration = cursor.getIntValue(CallLog.Calls.DURATION)
val name = cursor.getStringValue(CallLog.Calls.CACHED_NAME) ?: ""
val name = cursor.getStringValue(CallLog.Calls.CACHED_NAME)
val type = cursor.getIntValue(CallLog.Calls.TYPE)
val recentCall = RecentCall(id, number, date, duration, name, type)
calls.add(recentCall)

View File

@ -1,3 +1,3 @@
package com.simplemobiletools.contacts.models
data class RecentCall(var id: Int, var number: String, var date: Long, var duration: Int, var name: String, var type: Int)
data class RecentCall(var id: Int, var number: String, var date: Long, var duration: Int, var name: String?, var type: Int)

View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/recent_call_frame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:foreground="@drawable/selector">
<RelativeLayout
android:id="@+id/recent_call_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingRight="@dimen/activity_margin">
<TextView
android:id="@+id/recent_call_name"
android:layout_width="match_parent"
android:layout_height="@dimen/contact_item_height"
android:ellipsize="end"
android:gravity="center_vertical"
android:maxLines="1"
android:paddingLeft="@dimen/activity_margin"
android:textSize="@dimen/big_text_size"
tools:text="John Doe"/>
</RelativeLayout>
</FrameLayout>