Code cleanup

This commit is contained in:
Sylvain Berfini 2025-03-10 11:45:17 +01:00
parent c709c720e4
commit d6d705a975
37 changed files with 72 additions and 159 deletions

View file

@ -31,8 +31,6 @@ import androidx.annotation.RequiresApi
@RequiresApi(Build.VERSION_CODES.Q)
class Api29Compatibility {
companion object {
private const val TAG = "[API 29 Compatibility]"
fun getMediaCollectionUri(isImage: Boolean, isVideo: Boolean, isAudio: Boolean): Uri {
return when {
isImage -> {

View file

@ -26,8 +26,6 @@ import androidx.annotation.RequiresApi
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
class Api33Compatibility {
companion object {
private const val TAG = "[API 33 Compatibility]"
fun getAllRequiredPermissionsArray(): Array<String> {
return arrayOf(
Manifest.permission.POST_NOTIFICATIONS,

View file

@ -38,7 +38,6 @@ class Compatibility {
companion object {
private const val TAG = "[Compatibility]"
const val FOREGROUND_SERVICE_TYPE_DATA_SYNC = 1 // ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC
const val FOREGROUND_SERVICE_TYPE_PHONE_CALL = 4 // ServiceInfo.FOREGROUND_SERVICE_TYPE_PHONE_CALL
const val FOREGROUND_SERVICE_TYPE_CAMERA = 64 // ServiceInfo.FOREGROUND_SERVICE_TYPE_CAMERA
const val FOREGROUND_SERVICE_TYPE_MICROPHONE = 128 // ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE

View file

@ -33,6 +33,8 @@ import androidx.core.content.res.ResourcesCompat
import androidx.core.graphics.drawable.IconCompat
import org.linphone.R
import org.linphone.utils.AppUtils
import androidx.core.graphics.createBitmap
import androidx.core.graphics.drawable.toDrawable
class AvatarGenerator(private val context: Context) {
private var textSize: Float = AppUtils.getDimension(R.dimen.avatar_initials_text_size)
@ -74,7 +76,7 @@ class AvatarGenerator(private val context: Context) {
val textPainter = getTextPainter()
val painter = if (useTransparentBackground) getTransparentPainter() else getBackgroundPainter()
val bitmap = Bitmap.createBitmap(avatarSize, avatarSize, Bitmap.Config.ARGB_8888)
val bitmap = createBitmap(avatarSize, avatarSize)
val canvas = Canvas(bitmap)
val areaRect = Rect(0, 0, avatarSize, avatarSize)
val bounds = RectF(areaRect)
@ -91,7 +93,7 @@ class AvatarGenerator(private val context: Context) {
}
fun buildDrawable(): BitmapDrawable {
return BitmapDrawable(context.resources, buildBitmap(true))
return buildBitmap(true).toDrawable(context.resources)
}
fun buildIcon(): IconCompat {

View file

@ -39,6 +39,7 @@ import javax.crypto.KeyGenerator
import javax.crypto.SecretKey
import javax.crypto.spec.GCMParameterSpec
import org.linphone.core.tools.Log
import androidx.core.content.edit
class VFS {
companion object {
@ -73,7 +74,7 @@ class VFS {
return false
}
preferences.edit().putBoolean("vfs_enabled", true).apply()
preferences.edit { putBoolean("vfs_enabled", true) }
if (corePreferences.makePublicMediaFilesDownloaded) {
Log.w("$TAG VFS is now enabled, disabling auto export of media files to native gallery")
@ -98,10 +99,10 @@ class VFS {
generateSecretKey()
encryptToken(generateToken()).let { data ->
preferences
.edit()
.putString(VFS_IV, data.first)
.putString(VFS_KEY, data.second)
.commit()
.edit(commit = true) {
putString(VFS_IV, data.first)
.putString(VFS_KEY, data.second)
}
}
}

View file

@ -24,10 +24,6 @@ import androidx.fragment.app.Fragment
@UiThread
abstract class GenericFragment : Fragment() {
companion object {
private const val TAG = "[Generic Fragment]"
}
protected fun observeToastEvents(viewModel: GenericViewModel) {
viewModel.showRedToastEvent.observe(viewLifecycleOwner) {
it.consume { pair ->

View file

@ -23,10 +23,10 @@ import androidx.annotation.FontRes
import org.linphone.R
enum class NotoSansFont(@FontRes val fontRes: Int) {
NotoSansLight(R.font.noto_sans_light), // 300
// NotoSansLight(R.font.noto_sans_light), // 300
NotoSansRegular(R.font.noto_sans_regular), // 400
NotoSansMedium(R.font.noto_sans_medium), // 500
NotoSansSemiBold(R.font.noto_sans_semi_bold), // 600
// NotoSansSemiBold(R.font.noto_sans_semi_bold), // 600
NotoSansBold(R.font.noto_sans_bold), // 700
NotoSansExtraBold(R.font.noto_sans_extra_bold) // 800
}

View file

@ -26,6 +26,7 @@ import android.widget.GridLayout
import androidx.annotation.UiThread
import androidx.core.view.children
import org.linphone.core.tools.Log
import androidx.core.view.isEmpty
@UiThread
class GridBoxLayout : GridLayout {
@ -58,7 +59,7 @@ class GridBoxLayout : GridLayout {
@SuppressLint("DrawAllocation")
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
if (childCount == 0 || (!changed && previousChildCount == childCount)) {
if (isEmpty() || (!changed && previousChildCount == childCount)) {
super.onLayout(changed, left, top, right, bottom)
// To prevent display issue the first time conference is locally paused
children.forEach { child ->

View file

@ -242,7 +242,7 @@ class TransferCallFragment : GenericCallFragment() {
private fun showConfirmAttendedTransferDialog(callModel: CallModel) {
val label = AppUtils.getFormattedString(
org.linphone.R.string.call_transfer_confirm_dialog_message,
R.string.call_transfer_confirm_dialog_message,
callViewModel.displayedName.value.orEmpty(),
callModel.displayName.value.orEmpty()
)
@ -278,7 +278,7 @@ class TransferCallFragment : GenericCallFragment() {
private fun showConfirmBlindTransferDialog(contactModel: ConversationContactOrSuggestionModel) {
val label = AppUtils.getFormattedString(
org.linphone.R.string.call_transfer_confirm_dialog_message,
R.string.call_transfer_confirm_dialog_message,
callViewModel.displayedName.value.orEmpty(),
contactModel.name
)

View file

@ -27,10 +27,6 @@ import org.linphone.utils.Event
class ZrtpAlertDialogModel
@UiThread
constructor(val allowTryAgain: Boolean) : GenericViewModel() {
companion object {
private const val TAG = "[ZRTP Alert Dialog]"
}
val tryAgainEvent = MutableLiveData<Event<Boolean>>()
val hangUpEvent = MutableLiveData<Event<Boolean>>()

View file

@ -24,10 +24,6 @@ import android.util.AttributeSet
import android.view.TextureView
class RatioTextureView : TextureView {
companion object {
private const val TAG = "[Ratio TextureView]"
}
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
@ -38,13 +34,6 @@ class RatioTextureView : TextureView {
defStyleAttr
)
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) : super(
context,
attrs,
defStyleAttr,
defStyleRes
)
private var ratioWidth = 0
private var rationHeight = 0

View file

@ -19,7 +19,6 @@
*/
package org.linphone.ui.fileviewer.viewmodel
import android.graphics.Bitmap
import android.graphics.pdf.PdfRenderer
import android.net.Uri
import android.os.ParcelFileDescriptor
@ -31,7 +30,6 @@ import java.io.BufferedReader
import java.io.File
import java.io.FileReader
import java.lang.IllegalStateException
import java.lang.StringBuilder
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
@ -42,6 +40,7 @@ import org.linphone.utils.Event
import org.linphone.utils.FileUtils
import org.linphone.utils.TimestampUtils
import androidx.core.net.toUri
import androidx.core.graphics.createBitmap
class FileViewModel
@UiThread
@ -181,11 +180,7 @@ class FileViewModel
Log.d(
"$TAG Page size is ${page.width}/${page.height}, screen size is $screenWidth/$screenHeight"
)
val bm = Bitmap.createBitmap(
page.width,
page.height,
Bitmap.Config.ARGB_8888
)
val bm = createBitmap(page.width, page.height)
page.render(bm, null, null, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY)
page.close()

View file

@ -50,10 +50,6 @@ class ConversationModel
val id = LinphoneUtils.getConversationId(chatRoom)
val localSipUri = chatRoom.localAddress.asStringUriOnly()
val remoteSipUri = chatRoom.peerAddress.asStringUriOnly()
val isGroup = !chatRoom.hasCapability(Capabilities.OneToOne.toInt()) && chatRoom.hasCapability(
Capabilities.Conference.toInt()
)

View file

@ -319,7 +319,7 @@ class ContactFragment : SlidingPaneChildFragment() {
private fun showConfirmTrustCallDialog(contactName: String, deviceSipUri: String) {
val label = AppUtils.getFormattedString(
org.linphone.R.string.contact_dialog_increase_trust_level_message,
R.string.contact_dialog_increase_trust_level_message,
contactName,
deviceSipUri
)

View file

@ -39,10 +39,6 @@ import org.linphone.ui.main.fragment.GenericMainFragment
import org.linphone.ui.main.help.viewmodel.HelpViewModel
class DebugFragment : GenericMainFragment() {
companion object {
private const val TAG = "[Debug Fragment]"
}
private lateinit var binding: HelpDebugFragmentBinding
val viewModel: HelpViewModel by navGraphViewModels(

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("SameReturnValue")
package org.linphone.ui.main.model
import android.view.View

View file

@ -31,10 +31,6 @@ class SelectedAddressModel
val avatarModel: ContactAvatarModel?,
private val onRemovedFromSelection: ((model: SelectedAddressModel) -> Unit)? = null
) {
companion object {
private const val TAG = "[Selected Address Model]"
}
@UiThread
fun removeFromSelection() {
onRemovedFromSelection?.invoke(this)

View file

@ -35,10 +35,6 @@ import org.linphone.ui.main.settings.viewmodel.SettingsViewModel
@UiThread
class SettingsAdvancedFragment : GenericMainFragment() {
companion object {
private const val TAG = "[Advanced Settings Fragment]"
}
private lateinit var binding: SettingsAdvancedFragmentBinding
private lateinit var viewModel: SettingsViewModel

View file

@ -227,12 +227,6 @@ fun ImageView.setSourceImageResource(resource: Int) {
this.setImageResource(resource)
}
@UiThread
@BindingAdapter("android:textStyle")
fun AppCompatTextView.setTypeface(typeface: Int) {
this.setTypeface(null, typeface)
}
@UiThread
@BindingAdapter("android:drawableTint")
fun AppCompatTextView.setDrawableTint(@ColorInt color: Int) {

View file

@ -39,9 +39,4 @@ open class Event<out T>
handleContent(content)
}
}
@UiThread
fun consumed(): Boolean {
return handled.get()
}
}

View file

@ -34,6 +34,7 @@ import java.io.FileNotFoundException
import org.linphone.contacts.AvatarGenerator
import org.linphone.core.tools.Log
import androidx.core.net.toUri
import androidx.core.graphics.createBitmap
class ImageUtils {
companion object {
@ -91,8 +92,7 @@ class ImageUtils {
@AnyThread
private fun getRoundBitmap(bitmap: Bitmap): Bitmap {
val output =
Bitmap.createBitmap(bitmap.width, bitmap.height, Bitmap.Config.ARGB_8888)
val output = createBitmap(bitmap.width, bitmap.height)
val canvas = Canvas(output)
val color = -0xbdbdbe
val paint = Paint()

View file

@ -26,6 +26,7 @@ import android.util.SparseArray
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import androidx.core.graphics.withSave
class RecyclerViewHeaderDecoration(
private val context: Context,
@ -90,16 +91,17 @@ class RecyclerViewHeaderDecoration(
// Maps the visible view position to the item index in the adapter
val position = parent.getChildAdapterPosition(child)
if (position != RecyclerView.NO_POSITION && adapter.displayHeaderForPosition(position)) {
canvas.save()
val headerView: View = headers.get(position) ?: adapter.getHeaderViewForPosition(
context,
position
)
if (position != 0 || child.y < headerView.height) {
canvas.translate(0f, child.y - headerView.height)
canvas.withSave {
val headerView: View =
headers.get(position) ?: adapter.getHeaderViewForPosition(
context,
position
)
if (position != 0 || child.y < headerView.height) {
translate(0f, child.y - headerView.height)
}
headerView.draw(this)
}
headerView.draw(canvas)
canvas.restore()
}
}
}
@ -114,20 +116,21 @@ class RecyclerViewHeaderDecoration(
val child = parent.getChildAt(index)
val position = parent.getChildAdapterPosition(child)
if (position != RecyclerView.NO_POSITION && adapter.displayHeaderForPosition(position)) {
canvas.save()
val headerView: View = headers.get(position) ?: adapter.getHeaderViewForPosition(
context,
position
)
canvas.withSave {
val headerView: View =
headers.get(position) ?: adapter.getHeaderViewForPosition(
context,
position
)
val top = child.y - headerView.height
if (top >= 0) { // don't move the first header
canvas.translate(0f, top)
val top = child.y - headerView.height
if (top >= 0) { // don't move the first header
translate(0f, top)
}
headerView.draw(this)
}
headerView.draw(canvas)
canvas.restore()
latestPositionHeaderFound = position
nextHeaderTopPosition = child.y
}
@ -140,20 +143,21 @@ class RecyclerViewHeaderDecoration(
val topVisibleChildPosition = parent.getChildAdapterPosition(topVisibleChild)
for (position in topVisibleChildPosition downTo 0) {
if (adapter.displayHeaderForPosition(position)) {
canvas.save()
val headerView: View = headers.get(position) ?: adapter.getHeaderViewForPosition(
context,
position
)
canvas.withSave {
val headerView: View =
headers.get(position) ?: adapter.getHeaderViewForPosition(
context,
position
)
// Do not translate it as we want it sticky to the top unless in contact with next header
if (nextHeaderTopPosition > 0 && nextHeaderTopPosition <= (headerView.height * 2)) {
val top = nextHeaderTopPosition - (headerView.height * 2)
canvas.translate(0f, top)
// Do not translate it as we want it sticky to the top unless in contact with next header
if (nextHeaderTopPosition > 0 && nextHeaderTopPosition <= (headerView.height * 2)) {
val top = nextHeaderTopPosition - (headerView.height * 2)
translate(0f, top)
}
headerView.draw(this)
}
headerView.draw(canvas)
canvas.restore()
break
}
}

View file

@ -31,8 +31,6 @@ import org.linphone.R
class TimestampUtils {
companion object {
private const val TAG = "[Timestamp Utils]"
@AnyThread
fun isToday(timestamp: Long, timestampInSecs: Boolean = true): Boolean {
val cal = getCalendar()

View file

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:color="?attr/color_main1_100"/>
<item android:color="?attr/color_main1_500"/>
</selector>

View file

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true"
android:drawable="@drawable/shape_rectangle_gray_background" />
<item android:state_pressed="true"
android:drawable="@drawable/shape_rectangle_gray_background" />
<item
android:drawable="@color/transparent_color" />
</selector>

View file

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="?attr/color_main2_500" />
</shape>

View file

@ -1,9 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="88dp"
android:height="88dp"
android:viewportWidth="256"
android:viewportHeight="256">
<path
android:pathData="M208,32L48,32A16,16 0,0 0,32 48L32,208a16,16 0,0 0,16 16L208,224a16,16 0,0 0,16 -16L224,48A16,16 0,0 0,208 32ZM48,48L208,48v77.38l-24.69,-24.7a16,16 0,0 0,-22.62 0L53.37,208L48,208ZM208,208L76,208l96,-96 36,36v60ZM96,120A24,24 0,1 0,72 96,24 24,0 0,0 96,120ZM96,88a8,8 0,1 1,-8 8A8,8 0,0 1,96 88Z"
android:fillColor="#4e6074"/>
</vector>

View file

@ -1,9 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="20dp"
android:height="20dp"
android:viewportWidth="256"
android:viewportHeight="256">
<path
android:pathData="M224,128a8,8 0,0 1,-8 8H136v80a8,8 0,0 1,-16 0V136H40a8,8 0,0 1,0 -16h80V40a8,8 0,0 1,16 0v80h80A8,8 0,0 1,224 128Z"
android:fillColor="#4e6074"/>
</vector>

View file

@ -32,7 +32,7 @@
android:src="@drawable/confirm_sms_code_logo"
app:layout_constraintStart_toEndOf="@id/message"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="@id/header"
app:layout_constraintBottom_toTopOf="@id/mountains"
app:layout_constraintTop_toBottomOf="@id/title" />
<ImageView

View file

@ -19,6 +19,7 @@
<ImageView
android:layout_width="0dp"
android:layout_height="0dp"
android:contentDescription="@null"
android:src="@drawable/in_call_button_background_red"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintTop_toTopOf="parent"

View file

@ -24,6 +24,7 @@
<ImageView
android:layout_width="0dp"
android:layout_height="0dp"
android:contentDescription="@null"
android:src="@drawable/in_call_button_background_red"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintTop_toTopOf="parent"

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
<layout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
@ -21,6 +22,7 @@
<ImageView
android:layout_width="0dp"
android:layout_height="0dp"
android:contentDescription="@null"
android:src="@drawable/in_call_button_background_red"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintTop_toTopOf="parent"
@ -55,7 +57,8 @@
app:layout_constraintTop_toBottomOf="@id/digit_label"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
app:layout_constraintEnd_toEndOf="parent"
tools:ignore="HardcodedText" />
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -24,6 +24,7 @@
<ImageView
android:layout_width="0dp"
android:layout_height="0dp"
android:contentDescription="@null"
android:src="@drawable/in_call_button_background_red"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintTop_toTopOf="parent"
@ -51,6 +52,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/voicemail"
android:contentDescription="@string/content_description_call_voicemail"
android:visibility="@{model.voicemailAvailable ? View.VISIBLE : View.GONE, default=gone}"
app:layout_constraintTop_toBottomOf="@id/digit_label"
app:layout_constraintBottom_toBottomOf="parent"

View file

@ -98,7 +98,7 @@
<string name="assistant_dialog_privacy_policy_label">politique de confidentialité</string>
<string name="assistant_dialog_general_terms_and_privacy_policy_message">En continuant, vous acceptez nos %1$s et %2$s.</string>
<string name="assistant_dialog_confirm_phone_number_title">Confirmez votre numéro de téléphone</string>
<string name="assistant_dialog_confirm_phone_number_message">Êtes-vous sûr de vouloir utiliser ce numéro de téléphone ?</string>
<string name="assistant_dialog_confirm_phone_number_message">Êtes-vous sûr que le %s est votre numéro de téléphone ?</string>
<string name="assistant_account_login">Connexion</string>
<string name="assistant_scan_qr_code">Scanner un QR code</string>
<string name="assistant_qr_code_invalid_toast">Ce QR code est invalide !</string>

View file

@ -100,8 +100,6 @@
<dimen name="chat_bubble_emoji_picker_height">425dp</dimen>
<dimen name="chat_bubble_max_height_long_press">340dp</dimen>
<dimen name="recycler_view_min_height">200dp</dimen>
<dimen name="spinner_start_padding">15dp</dimen>
<dimen name="spinner_end_padding">30dp</dimen>
<dimen name="spinner_caret_end_margin">15dp</dimen>

View file

@ -44,7 +44,6 @@
<!-- Common words -->
<string name="sip_address">SIP address</string>
<string name="device_id">Device ID</string>
<string name="sip_address_hint">username@domain</string>
<string name="sip_address_display_name">Display name</string>
<string name="sip_address_domain">Domain</string>
<string name="username">Username</string>
@ -922,6 +921,7 @@
<string name="content_description_go_to_conversation">Go to conversation</string>
<string name="content_description_copy_text_to_clipboard">Copy text to clipboard</string>
<string name="content_description_voicemail_available">Voice message are available</string>
<string name="content_description_call_voicemail">Long press to dial voicemail</string>
<!-- Copy of private hosts_allowlist_sample in androidx.car.app:app:1.7.0-beta01, as they recommend it -->
<string-array name="hosts_allowlist_sample_copy" translatable="false">

View file

@ -149,15 +149,7 @@
<item name="android:drawableTint">?attr/color_danger_500</item>
<item name="android:drawablePadding">8dp</item>
</style>
<style name="call_start_numpad_digits_style">
<item name="android:fontFamily">@font/noto_sans</item>
<item name="android:textColor">@color/gray_main2_600</item>
<item name="android:textSize">32sp</item>
<item name="android:gravity">center</item>
<item name="android:elevation">3dp</item>
<item name="android:paddingBottom">5dp</item>
<item name="android:background">@drawable/circle_white_button_background</item>
</style>
<style name="message_reaction_style">
<item name="android:fontFamily">@font/noto_sans</item>
<item name="android:textColor">?attr/color_text</item>