ArrayList to Kotlin List refactoring

This commit is contained in:
merkost 2023-07-02 10:07:26 +10:00
parent 7f2fa6cf7e
commit 22a2fbb331
7 changed files with 24 additions and 22 deletions

View File

@ -272,9 +272,9 @@ class MainActivity : SimpleActivity() {
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 icons = ArrayList<Int>()
val icons = mutableListOf<Int>()
if (showTabs and TAB_CONTACTS != 0) {
icons.add(R.drawable.ic_person_vector)

View File

@ -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()) {
toast(R.string.no_entries_for_exporting)
} else {

View File

@ -28,7 +28,7 @@ import kotlinx.android.synthetic.main.item_recent_call.view.*
class RecentCallsAdapter(
activity: SimpleActivity,
var recentCalls: ArrayList<RecentCall>,
private var recentCalls: MutableList<RecentCall>,
recyclerView: MyRecyclerView,
private val refreshItemsListener: RefreshItemsListener?,
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()) {
recentCalls = newItems.clone() as ArrayList<RecentCall>
recentCalls = newItems.toMutableList()
textToHighlight = highlightText
recyclerView.resetItemCount()
notifyDataSetChanged()

View File

@ -16,8 +16,8 @@ val Context.audioManager: AudioManager get() = getSystemService(Context.AUDIO_SE
val Context.powerManager: PowerManager get() = getSystemService(Context.POWER_SERVICE) as PowerManager
@SuppressLint("MissingPermission")
fun Context.getAvailableSIMCardLabels(): ArrayList<SIMAccount> {
val SIMAccounts = ArrayList<SIMAccount>()
fun Context.getAvailableSIMCardLabels(): List<SIMAccount> {
val SIMAccounts = mutableListOf<SIMAccount>()
try {
telecomManager.callCapablePhoneAccounts.forEachIndexed { index, account ->
val phoneAccount = telecomManager.getPhoneAccount(account)

View File

@ -18,10 +18,12 @@ import com.simplemobiletools.dialer.helpers.MIN_RECENTS_THRESHOLD
import com.simplemobiletools.dialer.helpers.RecentsHelper
import com.simplemobiletools.dialer.interfaces.RefreshItemsListener
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 {
private var allRecentCalls = ArrayList<RecentCall>()
private var allRecentCalls = listOf<RecentCall>()
private var recentsAdapter: RecentCallsAdapter? = null
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()) {
recents_placeholder.beVisible()
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
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
if (context.config.showCallConfirmation) {
CallConfirmationDialog(activity as SimpleActivity, recentCall.name) {
@ -165,18 +167,18 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
}
// 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) {
filterNot { recent ->
val privateNumbers = privateContacts.flatMap { it.phoneNumbers }.map { it.value }
recent.phoneNumber in privateNumbers
} as ArrayList
}
} 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() }
return map { recent ->
if (recent.phoneNumber == recent.name) {

View File

@ -17,7 +17,7 @@ class RecentsHelper(private val context: Context) {
private val QUERY_LIMIT = 200
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)
ensureBackgroundThread {
if (!context.hasPermission(PERMISSION_READ_CALL_LOG)) {
@ -37,7 +37,7 @@ class RecentsHelper(private val context: Context) {
}
@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>()
var previousRecentCallFrom = ""
@ -151,7 +151,7 @@ class RecentsHelper(private val context: Context) {
val type = cursor.getIntValue(Calls.TYPE)
val accountId = cursor.getStringValue(Calls.PHONE_ACCOUNT_ID)
val simID = accountIdToSimIDMap[accountId] ?: -1
val neighbourIDs = ArrayList<Int>()
val neighbourIDs = mutableListOf<Int>()
var specificNumber = ""
var specificType = ""
@ -196,10 +196,10 @@ class RecentsHelper(private val context: Context) {
val recentResult = recentCalls
.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 {
ids.chunked(30).forEach { chunk ->
val selection = "${Calls._ID} IN (${getQuestionMarks(chunk.size)})"

View File

@ -16,7 +16,7 @@ data class RecentCall(
val startTS: Int,
val duration: Int,
val type: Int,
val neighbourIDs: ArrayList<Int>,
val neighbourIDs: MutableList<Int>,
val simID: Int,
val specificNumber: String,
val specificType: String,