mirror of
https://github.com/SimpleMobileTools/Simple-Dialer.git
synced 2025-02-15 02:50:53 +01:00
ArrayList to Kotlin List refactoring
This commit is contained in:
parent
7f2fa6cf7e
commit
22a2fbb331
@ -272,9 +272,9 @@ class MainActivity : SimpleActivity() {
|
|||||||
|
|
||||||
private fun getInactiveTabIndexes(activeIndex: Int) = (0 until main_tabs_holder.tabCount).filter { it != activeIndex }
|
private fun getInactiveTabIndexes(activeIndex: Int) = (0 until main_tabs_holder.tabCount).filter { it != activeIndex }
|
||||||
|
|
||||||
private fun getSelectedTabDrawableIds(): ArrayList<Int> {
|
private fun getSelectedTabDrawableIds(): List<Int> {
|
||||||
val showTabs = config.showTabs
|
val showTabs = config.showTabs
|
||||||
val icons = ArrayList<Int>()
|
val icons = mutableListOf<Int>()
|
||||||
|
|
||||||
if (showTabs and TAB_CONTACTS != 0) {
|
if (showTabs and TAB_CONTACTS != 0) {
|
||||||
icons.add(R.drawable.ic_person_vector)
|
icons.add(R.drawable.ic_person_vector)
|
||||||
|
@ -320,7 +320,7 @@ class SettingsActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun exportCallHistory(recents: ArrayList<RecentCall>, uri: Uri) {
|
private fun exportCallHistory(recents: List<RecentCall>, uri: Uri) {
|
||||||
if (recents.isEmpty()) {
|
if (recents.isEmpty()) {
|
||||||
toast(R.string.no_entries_for_exporting)
|
toast(R.string.no_entries_for_exporting)
|
||||||
} else {
|
} else {
|
||||||
|
@ -28,7 +28,7 @@ import kotlinx.android.synthetic.main.item_recent_call.view.*
|
|||||||
|
|
||||||
class RecentCallsAdapter(
|
class RecentCallsAdapter(
|
||||||
activity: SimpleActivity,
|
activity: SimpleActivity,
|
||||||
var recentCalls: ArrayList<RecentCall>,
|
private var recentCalls: MutableList<RecentCall>,
|
||||||
recyclerView: MyRecyclerView,
|
recyclerView: MyRecyclerView,
|
||||||
private val refreshItemsListener: RefreshItemsListener?,
|
private val refreshItemsListener: RefreshItemsListener?,
|
||||||
private val showOverflowMenu: Boolean,
|
private val showOverflowMenu: Boolean,
|
||||||
@ -260,9 +260,9 @@ class RecentCallsAdapter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateItems(newItems: ArrayList<RecentCall>, highlightText: String = "") {
|
fun updateItems(newItems: List<RecentCall>, highlightText: String = "") {
|
||||||
if (newItems.hashCode() != recentCalls.hashCode()) {
|
if (newItems.hashCode() != recentCalls.hashCode()) {
|
||||||
recentCalls = newItems.clone() as ArrayList<RecentCall>
|
recentCalls = newItems.toMutableList()
|
||||||
textToHighlight = highlightText
|
textToHighlight = highlightText
|
||||||
recyclerView.resetItemCount()
|
recyclerView.resetItemCount()
|
||||||
notifyDataSetChanged()
|
notifyDataSetChanged()
|
||||||
|
@ -16,8 +16,8 @@ val Context.audioManager: AudioManager get() = getSystemService(Context.AUDIO_SE
|
|||||||
val Context.powerManager: PowerManager get() = getSystemService(Context.POWER_SERVICE) as PowerManager
|
val Context.powerManager: PowerManager get() = getSystemService(Context.POWER_SERVICE) as PowerManager
|
||||||
|
|
||||||
@SuppressLint("MissingPermission")
|
@SuppressLint("MissingPermission")
|
||||||
fun Context.getAvailableSIMCardLabels(): ArrayList<SIMAccount> {
|
fun Context.getAvailableSIMCardLabels(): List<SIMAccount> {
|
||||||
val SIMAccounts = ArrayList<SIMAccount>()
|
val SIMAccounts = mutableListOf<SIMAccount>()
|
||||||
try {
|
try {
|
||||||
telecomManager.callCapablePhoneAccounts.forEachIndexed { index, account ->
|
telecomManager.callCapablePhoneAccounts.forEachIndexed { index, account ->
|
||||||
val phoneAccount = telecomManager.getPhoneAccount(account)
|
val phoneAccount = telecomManager.getPhoneAccount(account)
|
||||||
|
@ -18,10 +18,12 @@ import com.simplemobiletools.dialer.helpers.MIN_RECENTS_THRESHOLD
|
|||||||
import com.simplemobiletools.dialer.helpers.RecentsHelper
|
import com.simplemobiletools.dialer.helpers.RecentsHelper
|
||||||
import com.simplemobiletools.dialer.interfaces.RefreshItemsListener
|
import com.simplemobiletools.dialer.interfaces.RefreshItemsListener
|
||||||
import com.simplemobiletools.dialer.models.RecentCall
|
import com.simplemobiletools.dialer.models.RecentCall
|
||||||
import kotlinx.android.synthetic.main.fragment_recents.view.*
|
import kotlinx.android.synthetic.main.fragment_recents.view.recents_list
|
||||||
|
import kotlinx.android.synthetic.main.fragment_recents.view.recents_placeholder
|
||||||
|
import kotlinx.android.synthetic.main.fragment_recents.view.recents_placeholder_2
|
||||||
|
|
||||||
class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet), RefreshItemsListener {
|
class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet), RefreshItemsListener {
|
||||||
private var allRecentCalls = ArrayList<RecentCall>()
|
private var allRecentCalls = listOf<RecentCall>()
|
||||||
private var recentsAdapter: RecentCallsAdapter? = null
|
private var recentsAdapter: RecentCallsAdapter? = null
|
||||||
|
|
||||||
override fun setupFragment() {
|
override fun setupFragment() {
|
||||||
@ -69,7 +71,7 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun gotRecents(recents: ArrayList<RecentCall>) {
|
private fun gotRecents(recents: List<RecentCall>) {
|
||||||
if (recents.isEmpty()) {
|
if (recents.isEmpty()) {
|
||||||
recents_placeholder.beVisible()
|
recents_placeholder.beVisible()
|
||||||
recents_placeholder_2.beGoneIf(context.hasPermission(PERMISSION_READ_CALL_LOG))
|
recents_placeholder_2.beGoneIf(context.hasPermission(PERMISSION_READ_CALL_LOG))
|
||||||
@ -81,7 +83,7 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
|
|||||||
|
|
||||||
val currAdapter = recents_list.adapter
|
val currAdapter = recents_list.adapter
|
||||||
if (currAdapter == null) {
|
if (currAdapter == null) {
|
||||||
recentsAdapter = RecentCallsAdapter(activity as SimpleActivity, recents, recents_list, this, true) {
|
recentsAdapter = RecentCallsAdapter(activity as SimpleActivity, recents.toMutableList(), recents_list, this, true) {
|
||||||
val recentCall = it as RecentCall
|
val recentCall = it as RecentCall
|
||||||
if (context.config.showCallConfirmation) {
|
if (context.config.showCallConfirmation) {
|
||||||
CallConfirmationDialog(activity as SimpleActivity, recentCall.name) {
|
CallConfirmationDialog(activity as SimpleActivity, recentCall.name) {
|
||||||
@ -165,18 +167,18 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
|
|||||||
}
|
}
|
||||||
|
|
||||||
// hide private contacts from recent calls
|
// hide private contacts from recent calls
|
||||||
private fun List<RecentCall>.hidePrivateContacts(privateContacts: ArrayList<Contact>, shouldHide: Boolean): ArrayList<RecentCall> {
|
private fun List<RecentCall>.hidePrivateContacts(privateContacts: List<Contact>, shouldHide: Boolean): List<RecentCall> {
|
||||||
return if (shouldHide) {
|
return if (shouldHide) {
|
||||||
filterNot { recent ->
|
filterNot { recent ->
|
||||||
val privateNumbers = privateContacts.flatMap { it.phoneNumbers }.map { it.value }
|
val privateNumbers = privateContacts.flatMap { it.phoneNumbers }.map { it.value }
|
||||||
recent.phoneNumber in privateNumbers
|
recent.phoneNumber in privateNumbers
|
||||||
} as ArrayList
|
}
|
||||||
} else {
|
} else {
|
||||||
this as ArrayList
|
this
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun ArrayList<RecentCall>.setNamesIfEmpty(contacts: ArrayList<Contact>, privateContacts: ArrayList<Contact>): ArrayList<RecentCall> {
|
private fun List<RecentCall>.setNamesIfEmpty(contacts: List<Contact>, privateContacts: List<Contact>): ArrayList<RecentCall> {
|
||||||
val contactsWithNumbers = contacts.filter { it.phoneNumbers.isNotEmpty() }
|
val contactsWithNumbers = contacts.filter { it.phoneNumbers.isNotEmpty() }
|
||||||
return map { recent ->
|
return map { recent ->
|
||||||
if (recent.phoneNumber == recent.name) {
|
if (recent.phoneNumber == recent.name) {
|
||||||
|
@ -17,7 +17,7 @@ class RecentsHelper(private val context: Context) {
|
|||||||
private val QUERY_LIMIT = 200
|
private val QUERY_LIMIT = 200
|
||||||
private val contentUri = Calls.CONTENT_URI
|
private val contentUri = Calls.CONTENT_URI
|
||||||
|
|
||||||
fun getRecentCalls(groupSubsequentCalls: Boolean, maxSize: Int = QUERY_LIMIT, callback: (ArrayList<RecentCall>) -> Unit) {
|
fun getRecentCalls(groupSubsequentCalls: Boolean, maxSize: Int = QUERY_LIMIT, callback: (List<RecentCall>) -> Unit) {
|
||||||
val privateCursor = context.getMyContactsCursor(false, true)
|
val privateCursor = context.getMyContactsCursor(false, true)
|
||||||
ensureBackgroundThread {
|
ensureBackgroundThread {
|
||||||
if (!context.hasPermission(PERMISSION_READ_CALL_LOG)) {
|
if (!context.hasPermission(PERMISSION_READ_CALL_LOG)) {
|
||||||
@ -37,7 +37,7 @@ class RecentsHelper(private val context: Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("NewApi")
|
@SuppressLint("NewApi")
|
||||||
private fun getRecents(contacts: ArrayList<Contact>, groupSubsequentCalls: Boolean, maxSize: Int, callback: (ArrayList<RecentCall>) -> Unit) {
|
private fun getRecents(contacts: List<Contact>, groupSubsequentCalls: Boolean, maxSize: Int, callback: (List<RecentCall>) -> Unit) {
|
||||||
|
|
||||||
val recentCalls = mutableListOf<RecentCall>()
|
val recentCalls = mutableListOf<RecentCall>()
|
||||||
var previousRecentCallFrom = ""
|
var previousRecentCallFrom = ""
|
||||||
@ -151,7 +151,7 @@ class RecentsHelper(private val context: Context) {
|
|||||||
val type = cursor.getIntValue(Calls.TYPE)
|
val type = cursor.getIntValue(Calls.TYPE)
|
||||||
val accountId = cursor.getStringValue(Calls.PHONE_ACCOUNT_ID)
|
val accountId = cursor.getStringValue(Calls.PHONE_ACCOUNT_ID)
|
||||||
val simID = accountIdToSimIDMap[accountId] ?: -1
|
val simID = accountIdToSimIDMap[accountId] ?: -1
|
||||||
val neighbourIDs = ArrayList<Int>()
|
val neighbourIDs = mutableListOf<Int>()
|
||||||
var specificNumber = ""
|
var specificNumber = ""
|
||||||
var specificType = ""
|
var specificType = ""
|
||||||
|
|
||||||
@ -196,10 +196,10 @@ class RecentsHelper(private val context: Context) {
|
|||||||
val recentResult = recentCalls
|
val recentResult = recentCalls
|
||||||
.filter { !context.isNumberBlocked(it.phoneNumber, blockedNumbers) }
|
.filter { !context.isNumberBlocked(it.phoneNumber, blockedNumbers) }
|
||||||
|
|
||||||
callback(ArrayList(recentResult))
|
callback(recentResult)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun removeRecentCalls(ids: ArrayList<Int>, callback: () -> Unit) {
|
fun removeRecentCalls(ids: List<Int>, callback: () -> Unit) {
|
||||||
ensureBackgroundThread {
|
ensureBackgroundThread {
|
||||||
ids.chunked(30).forEach { chunk ->
|
ids.chunked(30).forEach { chunk ->
|
||||||
val selection = "${Calls._ID} IN (${getQuestionMarks(chunk.size)})"
|
val selection = "${Calls._ID} IN (${getQuestionMarks(chunk.size)})"
|
||||||
|
@ -16,7 +16,7 @@ data class RecentCall(
|
|||||||
val startTS: Int,
|
val startTS: Int,
|
||||||
val duration: Int,
|
val duration: Int,
|
||||||
val type: Int,
|
val type: Int,
|
||||||
val neighbourIDs: ArrayList<Int>,
|
val neighbourIDs: MutableList<Int>,
|
||||||
val simID: Int,
|
val simID: Int,
|
||||||
val specificNumber: String,
|
val specificNumber: String,
|
||||||
val specificType: String,
|
val specificType: String,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user