Code cleanup

This commit is contained in:
Sylvain Berfini 2024-10-10 11:18:41 +02:00
parent 865f3b9692
commit 8a39529fd1
20 changed files with 32 additions and 44 deletions

View file

@ -21,7 +21,6 @@ package org.linphone
import android.annotation.SuppressLint
import android.app.Application
import android.content.ComponentCallbacks2
import androidx.annotation.MainThread
import coil.ImageLoader
import coil.ImageLoaderFactory
@ -93,10 +92,10 @@ class LinphoneApplication : Application(), ImageLoaderFactory {
override fun onTrimMemory(level: Int) {
Log.w("$TAG onTrimMemory called with level [${trimLevelToString(level)}]($level) !")
when (level) {
ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW,
ComponentCallbacks2.TRIM_MEMORY_RUNNING_CRITICAL,
ComponentCallbacks2.TRIM_MEMORY_MODERATE,
ComponentCallbacks2.TRIM_MEMORY_COMPLETE -> {
TRIM_MEMORY_RUNNING_LOW,
TRIM_MEMORY_RUNNING_CRITICAL,
TRIM_MEMORY_MODERATE,
TRIM_MEMORY_COMPLETE -> {
Log.i("$TAG Memory trim required, clearing imageLoader memory cache")
imageLoader.memoryCache?.clear()
}
@ -139,13 +138,13 @@ class LinphoneApplication : Application(), ImageLoaderFactory {
private fun trimLevelToString(level: Int): String {
return when (level) {
ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN -> "Hidden UI"
ComponentCallbacks2.TRIM_MEMORY_RUNNING_MODERATE -> "Moderate (Running)"
ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW -> "Low"
ComponentCallbacks2.TRIM_MEMORY_RUNNING_CRITICAL -> "Critical"
ComponentCallbacks2.TRIM_MEMORY_BACKGROUND -> "Background"
ComponentCallbacks2.TRIM_MEMORY_MODERATE -> "Moderate"
ComponentCallbacks2.TRIM_MEMORY_COMPLETE -> "Complete"
TRIM_MEMORY_UI_HIDDEN -> "Hidden UI"
TRIM_MEMORY_RUNNING_MODERATE -> "Moderate (Running)"
TRIM_MEMORY_RUNNING_LOW -> "Low"
TRIM_MEMORY_RUNNING_CRITICAL -> "Critical"
TRIM_MEMORY_BACKGROUND -> "Background"
TRIM_MEMORY_MODERATE -> "Moderate"
TRIM_MEMORY_COMPLETE -> "Complete"
else -> level.toString()
}
}

View file

@ -602,7 +602,7 @@ class ContactsManager @UiThread constructor() {
@WorkerThread
fun getMePerson(localAddress: Address): Person {
val account = coreContext.core.accountList.find {
it.params.identityAddress?.weakEqual(localAddress) ?: false
it.params.identityAddress?.weakEqual(localAddress) == true
}
val name = account?.params?.identityAddress?.displayName ?: LinphoneUtils.getDisplayName(
localAddress
@ -627,7 +627,6 @@ class ContactsManager @UiThread constructor() {
@WorkerThread
fun updateContactsModelDependingOnDefaultAccountMode() {
val account = coreContext.core.defaultAccount
val showTrust = true
Log.i(
"$TAG Default account mode is [${if (showTrust) "end-to-end encryption mandatory" else "interoperable"}], update all contact models showTrust value"

View file

@ -608,7 +608,7 @@ class CoreContext @UiThread constructor(val context: Context) : HandlerThread("C
@WorkerThread
fun isAddressMyself(address: Address): Boolean {
val found = core.accountList.find {
it.params.identityAddress?.weakEqual(address) ?: false
it.params.identityAddress?.weakEqual(address) == true
}
return found != null
}
@ -675,7 +675,7 @@ class CoreContext @UiThread constructor(val context: Context) : HandlerThread("C
if (localAddress != null) {
val account = core.accountList.find { account ->
account.params.identityAddress?.weakEqual(localAddress) ?: false
account.params.identityAddress?.weakEqual(localAddress) == true
}
if (account != null) {
params.account = account

View file

@ -20,7 +20,6 @@
package org.linphone.ui.call
import android.Manifest
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.content.res.Resources
@ -144,7 +143,7 @@ class CallActivity : GenericActivity() {
WindowInsetsCompat.CONSUMED
}
val powerManager = getSystemService(Context.POWER_SERVICE) as PowerManager
val powerManager = getSystemService(POWER_SERVICE) as PowerManager
if (!powerManager.isWakeLockLevelSupported(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK)) {
Log.w("$TAG PROXIMITY_SCREEN_OFF_WAKE_LOCK isn't supported on this device!")
}

View file

@ -636,7 +636,7 @@ class CurrentCallViewModel @UiThread constructor() : GenericViewModel() {
coreContext.postOnCoreThread {
if (::currentCall.isInitialized) {
val micMuted = if (currentCall.conference != null) {
currentCall.conference?.microphoneMuted ?: false
currentCall.conference?.microphoneMuted == true
} else {
currentCall.microphoneMuted
}
@ -660,7 +660,7 @@ class CurrentCallViewModel @UiThread constructor() : GenericViewModel() {
coreContext.postOnCoreThread {
if (::currentCall.isInitialized) {
val micMuted = if (currentCall.conference != null) {
currentCall.conference?.microphoneMuted ?: false
currentCall.conference?.microphoneMuted == true
} else {
currentCall.microphoneMuted
}
@ -1135,7 +1135,7 @@ class CurrentCallViewModel @UiThread constructor() : GenericViewModel() {
isRecording.postValue(call.params.isRecording)
val isRemoteRecording = call.remoteParams?.isRecording ?: false
val isRemoteRecording = call.remoteParams?.isRecording == true
if (isRemoteRecording) {
Log.w("$TAG Remote end [${displayedName.value.orEmpty()}] is recording the call")
isRemoteRecordingEvent.postValue(Event(Pair(true, displayedName.value.orEmpty())))

View file

@ -1,6 +1,5 @@
package org.linphone.ui.file_viewer
import android.app.Activity
import android.content.Intent
import android.net.Uri
import android.os.Bundle
@ -147,7 +146,7 @@ class FileViewerActivity : GenericActivity() {
@Deprecated("Deprecated in Java")
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (requestCode == EXPORT_FILE_AS_DOCUMENT && resultCode == Activity.RESULT_OK) {
if (requestCode == EXPORT_FILE_AS_DOCUMENT && resultCode == RESULT_OK) {
data?.data?.also { documentUri ->
Log.i("$TAG Exported file should be stored in URI [$documentUri]")
viewModel.copyFileToUri(documentUri)

View file

@ -22,7 +22,6 @@ package org.linphone.ui.main
import android.Manifest
import android.annotation.SuppressLint
import android.app.Dialog
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.graphics.Color
@ -339,7 +338,7 @@ class MainActivity : GenericActivity() {
HISTORY_FRAGMENT_ID
}
}
with(getPreferences(Context.MODE_PRIVATE).edit()) {
with(getPreferences(MODE_PRIVATE).edit()) {
putInt(DEFAULT_FRAGMENT_KEY, defaultFragmentId)
apply()
}
@ -403,7 +402,7 @@ class MainActivity : GenericActivity() {
}
}
val defaultFragmentId = getPreferences(Context.MODE_PRIVATE).getInt(
val defaultFragmentId = getPreferences(MODE_PRIVATE).getInt(
DEFAULT_FRAGMENT_KEY,
HISTORY_FRAGMENT_ID
)

View file

@ -379,7 +379,7 @@ class ConversationModel @WorkerThread constructor(val chatRoom: ChatRoom) {
composingFriends.add(name)
label += "$name, "
}
if (composingFriends.size > 0) {
if (composingFriends.isNotEmpty()) {
label = label.dropLast(2)
val format = AppUtils.getStringWithPlural(

View file

@ -17,6 +17,8 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@file:Suppress("EmptyMethod")
package org.linphone.ui.main.chat.viewmodel
import androidx.annotation.UiThread

View file

@ -295,7 +295,7 @@ class ContactsListViewModel @UiThread constructor() : AbstractMainViewModel() {
list.add(model)
count += 1
val starred = friend?.starred ?: false
val starred = friend?.starred == true
model.isFavourite.postValue(starred)
if (starred) {
favouritesList.add(model)

View file

@ -46,7 +46,7 @@ class ContactHistoryListAdapter : ListAdapter<CallLogHistoryModel, RecyclerView.
}
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
(holder as ContactHistoryListAdapter.ViewHolder).bind(getItem(position))
(holder as ViewHolder).bind(getItem(position))
}
inner class ViewHolder(

View file

@ -148,7 +148,6 @@ class MeetingsListFragment : AbstractMainFragment() {
}
listViewModel.meetings.observe(viewLifecycleOwner) {
val currentCount = adapter.itemCount
val newCount = it.size
adapter.submitList(it)

View file

@ -262,7 +262,7 @@ class MeetingViewModel @UiThread constructor() : GenericViewModel() {
var organizerFound = false
for (info in conferenceInfo.participantInfos) {
val participant = info.address
val isOrganizer = organizer?.weakEqual(participant) ?: false
val isOrganizer = organizer?.weakEqual(participant) == true
Log.d(
"$TAG Conference [${conferenceInfo.subject}] ${if (isOrganizer) "organizer" else "participant"} [${participant.asStringUriOnly()}] is a [${info.role}]"
)

View file

@ -117,8 +117,8 @@ class MeetingsListViewModel @UiThread constructor() : AbstractMainViewModel() {
filter,
ignoreCase = true
) ?: false
val subjectCheck = info.subject?.contains(filter, ignoreCase = true) ?: false
val descriptionCheck = info.description?.contains(filter, ignoreCase = true) ?: false
val subjectCheck = info.subject?.contains(filter, ignoreCase = true) == true
val descriptionCheck = info.description?.contains(filter, ignoreCase = true) == true
val participantsCheck = info.participantInfos.find {
it.address.asStringUriOnly().contains(filter, ignoreCase = true)
} != null

View file

@ -27,7 +27,7 @@ class CodecModel @WorkerThread constructor(
val mimeType: String,
clockRate: Int,
recvFmtp: String?,
private val isAudioCodec: Boolean,
isAudioCodec: Boolean,
enabled: Boolean,
val onEnabledChanged: ((enabled: Boolean) -> Unit)
) {

View file

@ -30,7 +30,6 @@ import org.linphone.R
import org.linphone.contacts.ContactsManager
import org.linphone.core.Address
import org.linphone.core.ChatRoom
import org.linphone.core.Friend
import org.linphone.core.MagicSearch
import org.linphone.core.MagicSearchListenerStub
import org.linphone.core.SearchResult

View file

@ -75,7 +75,7 @@ class LinphoneUtils {
@WorkerThread
fun applyInternationalPrefix(account: Account? = null): Boolean {
return account?.params?.useInternationalPrefixForCallsAndChats
?: (getDefaultAccount()?.params?.useInternationalPrefixForCallsAndChats ?: false)
?: (getDefaultAccount()?.params?.useInternationalPrefixForCallsAndChats == true)
}
@WorkerThread

View file

@ -22,6 +22,7 @@
android:layout_height="@dimen/icon_size"
android:adjustViewBounds="true"
coilUrl="@{model.iconUrl}"
android:contentDescription="@null"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>

View file

@ -489,7 +489,6 @@
<string name="conversation_info_no_address_to_add_to_contact_toast">Aucune adresse à ajouter au contact</string>
<string name="conversation_info_confirm_start_group_call_dialog_title">Démarrer un appel de groupe ?</string>
<string name="conversation_info_confirm_start_group_call_dialog_message">Tous les participants de la conversation recevront un appel.</string>
<string name="conversation_info_confirm_start_group_call_dialog_button">Démarrer l\'appel de groupe</string>
<string name="conversation_event_conference_created">Vous avez rejoint le groupe</string>
<string name="conversation_event_conference_destroyed">Vous avez quitté le groupe</string>
@ -526,7 +525,6 @@
<string name="message_voice_message_content_description">message vocal</string>
<!-- Scheduled conferences -->
<string name="meetings_list_empty">Aucune réunion pour le moment…</string>
<string name="meetings_list_no_meeting_for_today">Aucune réunion aujourd\'hui</string>
<string name="meeting_schedule_title">Nouvelle réunion</string>
@ -534,9 +532,7 @@
<string name="meeting_schedule_broadcast_label">Webinar</string>
<string name="meeting_schedule_broadcast_help">Informations sur le mode Webinar.\n<u>En savoir plus</u></string>
<string name="meeting_schedule_subject_hint">Ajouter un titre…</string>
<string name="meeting_schedule_date_all_day_title">Toute la journée</string>
<string name="meeting_schedule_pick_start_date_title">Date de début</string>
<string name="meeting_schedule_pick_end_date_title">Date de fin</string>
<string name="meeting_schedule_pick_start_time_title">Heure de début</string>
<string name="meeting_schedule_pick_end_time_title">Heure de fin</string>
<string name="meeting_schedule_timezone_title">Fuseau horaire</string>

View file

@ -527,7 +527,6 @@
<string name="conversation_info_no_address_to_add_to_contact_toast">No address to add to contact</string>
<string name="conversation_info_confirm_start_group_call_dialog_title">Start a group call?</string>
<string name="conversation_info_confirm_start_group_call_dialog_message">All participants will receive a call.</string>
<string name="conversation_info_confirm_start_group_call_dialog_button">Start a group call</string>
<string name="conversation_event_conference_created">You have joined the group</string>
<string name="conversation_event_conference_destroyed">You have left the group</string>
@ -564,7 +563,6 @@
<string name="message_voice_message_content_description">voice message</string>
<!-- Scheduled conferences -->
<string name="meetings_list_empty">No meeting for the moment…</string>
<string name="meetings_list_no_meeting_for_today">No meeting scheduled for today</string>
<string name="meeting_schedule_title">New meeting</string>
@ -572,9 +570,7 @@
<string name="meeting_schedule_broadcast_label">Broadcast</string>
<string name="meeting_schedule_broadcast_help">Info about broadcast.\n<u>Learn more</u></string>
<string name="meeting_schedule_subject_hint">Add title…</string>
<string name="meeting_schedule_date_all_day_title">All day</string>
<string name="meeting_schedule_pick_start_date_title">Choose the start date</string>
<string name="meeting_schedule_pick_end_date_title">Choose the end date</string>
<string name="meeting_schedule_pick_start_time_title">Choose the start time</string>
<string name="meeting_schedule_pick_end_time_title">Choose the end time</string>
<string name="meeting_schedule_timezone_title">Timezone</string>