Modernize Uri.parse()

This commit is contained in:
Davide Depau committed 2025-03-23 22:11:10 +01:00
1 parent 929893bcd1
commit fde4f74c98
7 files changed
+60 -57

No files matched your search

@@ -2,7 +2,7 @@ package eu.depau.etchdroid.plugins.reviews
import android.app.Activity
import android.content.Intent
import android.net.Uri
import androidx.core.net.toUri
class WriteReviewHelper(private val mActivity: Activity) : IWriteReviewHelper {
override val isGPlayFlavor: Boolean
@@ -10,10 +10,7 @@ class WriteReviewHelper(private val mActivity: Activity) : IWriteReviewHelper {
override fun launchReviewFlow() {
mActivity.startActivity(
Intent(
Intent.ACTION_VIEW,
Uri.parse("https://github.com/EtchDroid/EtchDroid/")
)
Intent(Intent.ACTION_VIEW, "https://github.com/EtchDroid/EtchDroid/".toUri())
)
}
}
@@ -3,7 +3,7 @@ package eu.depau.etchdroid.plugins.reviews
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.net.Uri
import androidx.core.net.toUri
import com.google.android.play.core.review.ReviewInfo
import com.google.android.play.core.review.ReviewManagerFactory
import eu.depau.etchdroid.plugins.telemetry.Telemetry
@@ -68,7 +68,7 @@ class WriteReviewHelper(private val mActivity: Activity) : IWriteReviewHelper {
context.startActivity(
Intent(
Intent.ACTION_VIEW,
Uri.parse("https://play.google.com/store/apps/details?id=${context.packageName}")
"https://play.google.com/store/apps/details?id=${context.packageName}".toUri()
)
)
}
@@ -2,7 +2,6 @@ package eu.depau.etchdroid.ui
import android.content.Intent
import android.graphics.Typeface
import android.net.Uri
import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.activity.viewModels
@@ -45,6 +44,7 @@ import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.tooling.preview.PreviewScreenSizes
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.core.net.toUri
import eu.depau.etchdroid.AppSettings
import eu.depau.etchdroid.BuildConfig
import eu.depau.etchdroid.PRIVACY_URL
@@ -314,7 +314,7 @@ fun AboutView(viewModel: ThemeViewModel) {
activity?.startActivity(
Intent(
Intent.ACTION_VIEW,
Uri.parse("https://etchdroid.app")
"https://etchdroid.app".toUri()
)
)
}
@@ -326,7 +326,7 @@ fun AboutView(viewModel: ThemeViewModel) {
activity?.startActivity(
Intent(
Intent.ACTION_VIEW,
Uri.parse("https://etchdroid.app/donate")
"https://etchdroid.app/donate".toUri()
)
)
}
@@ -77,6 +77,7 @@ import androidx.constraintlayout.compose.ChainStyle
import androidx.constraintlayout.compose.ConstraintLayout
import androidx.constraintlayout.compose.Dimension
import androidx.constraintlayout.compose.atLeastWrapContent
import androidx.core.net.toUri
import com.airbnb.lottie.LottieProperty
import com.airbnb.lottie.compose.LottieAnimation
import com.airbnb.lottie.compose.LottieCompositionSpec
@@ -862,9 +863,7 @@ fun ConfirmationViewPreview() {
vidpid = "dead:beef",
)
),
openedImage = Uri.parse(
"file:///storage/emulated/0/Download/etchdroid-test-image-very-long-name-lol-rip-ive-never-seen-a-filename-this-long-its-absolutely-crazy.img"
),
openedImage = "file:///storage/emulated/0/Download/etchdroid-test-image-very-long-name-lol-rip-ive-never-seen-a-filename-this-long-its-absolutely-crazy.img".toUri(),
)
)
}
@@ -93,6 +93,7 @@ import androidx.compose.ui.tooling.preview.PreviewScreenSizes
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.constraintlayout.compose.ConstraintLayout
import androidx.core.net.toUri
import eu.depau.etchdroid.AppSettings
import eu.depau.etchdroid.PRIVACY_URL
import eu.depau.etchdroid.R
@@ -634,7 +635,7 @@ fun StartView(
context.startActivity(
Intent(
Intent.ACTION_VIEW,
Uri.parse(PRIVACY_URL)
PRIVACY_URL.toUri()
)
)
},
@@ -95,6 +95,7 @@ import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.constraintlayout.compose.ConstraintLayout
import androidx.core.net.toUri
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import com.airbnb.lottie.LottieProperty
import com.airbnb.lottie.compose.LottieAnimation
@@ -453,28 +454,29 @@ fun JobInProgressView(
var clickCount by remember { mutableStateOf(0) }
var easterEgg by remember { mutableStateOf(false) }
Column(modifier = Modifier
.fillMaxWidth()
.clipToBounds()
.clickable {
val now = System.currentTimeMillis()
if (now - clickLastTime < 500) {
clickCount++
if (clickCount >= 5) {
clickCount = 0
easterEgg = !easterEgg
Telemetry.addBreadcrumb {
message = "Easter egg activated: $easterEgg"
category = "easter_egg"
level = TelemetryLevel.DEBUG
Column(
modifier = Modifier
.fillMaxWidth()
.clipToBounds()
.clickable {
val now = System.currentTimeMillis()
if (now - clickLastTime < 500) {
clickCount++
if (clickCount >= 5) {
clickCount = 0
easterEgg = !easterEgg
Telemetry.addBreadcrumb {
message = "Easter egg activated: $easterEgg"
category = "easter_egg"
level = TelemetryLevel.DEBUG
}
}
} else {
clickCount = 0
}
} else {
clickCount = 0
clickLastTime = now
}
clickLastTime = now
}
.then(modifier)
.then(modifier)
) {
if (easterEgg) {
GifImage(
@@ -509,11 +511,12 @@ fun JobInProgressView(
val anchor by anchorTransition.animateValue(
initialValue = if (uiState.isVerifying) 100.dp else (100 + repeatWidth).dp,
targetValue = if (uiState.isVerifying) (100 + repeatWidth).dp else 100.dp,
typeConverter = TwoWayConverter(convertToVector = {
AnimationVector1D(
it.value
)
},
typeConverter = TwoWayConverter(
convertToVector = {
AnimationVector1D(
it.value
)
},
convertFromVector = { it.value.dp }),
animationSpec = infiniteRepeatable(
animation = tween(2000, easing = LinearEasing),
@@ -522,20 +525,21 @@ fun JobInProgressView(
label = "anchor"
)
Row(modifier = Modifier
.constrainAs(imagesRow) {
centerVerticallyTo(usbDrive)
if (uiState.isVerifying) {
absoluteLeft.linkTo(usbDrive.absoluteLeft, anchor)
} else {
absoluteRight.linkTo(usbDrive.absoluteRight, anchor)
Row(
modifier = Modifier
.constrainAs(imagesRow) {
centerVerticallyTo(usbDrive)
if (uiState.isVerifying) {
absoluteLeft.linkTo(usbDrive.absoluteLeft, anchor)
} else {
absoluteRight.linkTo(usbDrive.absoluteRight, anchor)
}
}
}
.padding(bottom = 32.dp)
.fillMaxWidth()
.onSizeChanged {
rowSize = it
}, horizontalArrangement = Arrangement.SpaceBetween
.padding(bottom = 32.dp)
.fillMaxWidth()
.onSizeChanged {
rowSize = it
}, horizontalArrangement = Arrangement.SpaceBetween
) {
for (i in 0 until numberOfImages) Icon(
imageVector = ImageVector.vectorResource(
@@ -564,7 +568,8 @@ fun JobInProgressView(
PaddingValues(start = 128.dp)
)
.drawBehind {
drawRect(bgColor,
drawRect(
bgColor,
topLeft = with(density) {
Offset(
88.dp.toPx(),
@@ -903,7 +908,7 @@ fun SuccessView() {
activity?.startActivity(
Intent(
Intent.ACTION_VIEW,
Uri.parse("https://etchdroid.app/donate/")
"https://etchdroid.app/donate/".toUri()
)
)
}) {
@@ -1106,7 +1111,7 @@ fun FatalErrorView(
activity?.startActivity(
Intent(
Intent.ACTION_VIEW,
Uri.parse("https://github.com/EtchDroid/EtchDroid/issues")
"https://github.com/etchdroid/etchdroid/issues".toUri()
)
)
}) {
@@ -7,6 +7,7 @@ import android.os.Environment
import android.provider.DocumentsContract
import android.provider.MediaStore
import android.util.Log
import androidx.core.net.toUri
/**
* Get a file path from a Uri. This will get the the path for Storage Access
@@ -42,15 +43,15 @@ fun Uri.getFilePath(context: Context): String? {
val id = DocumentsContract.getDocumentId(this)
if (id.startsWith("raw:/"))
return Uri.parse(id).path
return id.toUri().path
return try {
val contentUri = ContentUris.withAppendedId(
Uri.parse("content://downloads/public_downloads"),
"content://downloads/public_downloads".toUri(),
java.lang.Long.valueOf(id)
)
contentUri.getDataColumn(context, null, null)
} catch (e: NumberFormatException) {
} catch (_: NumberFormatException) {
null
}
} else if (isMediaDocument) {