Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.res.stringResource
import androidx.core.net.toUri
Expand All @@ -42,6 +41,7 @@ import com.looker.droidify.datastore.model.LegacyInstallerComponent
import com.looker.droidify.datastore.model.ProxyType
import com.looker.droidify.datastore.model.Theme
import com.looker.droidify.utility.common.SdkCheck
import com.looker.droidify.utility.common.extension.openLink
import com.looker.droidify.utility.common.isIgnoreBatteryEnabled
import com.looker.droidify.utility.common.requestBatteryFreedom
import java.util.*
Expand Down Expand Up @@ -114,8 +114,6 @@ fun SettingsScreen(
}
}

val uriHandler = LocalUriHandler.current

Scaffold(
topBar = {
TopAppBar(
Expand Down Expand Up @@ -377,15 +375,15 @@ fun SettingsScreen(
ActionSettingItem(
title = stringResource(R.string.special_credits),
description = FOXY_DROID_TITLE,
onClick = { uriHandler.openUri(FOXY_DROID_URL) },
onClick = { context.openLink(FOXY_DROID_URL) },
)
}

item {
ActionSettingItem(
title = DROID_IFY_TITLE,
description = BuildConfig.VERSION_NAME,
onClick = { uriHandler.openUri(DROID_IFY_URL) },
onClick = { context.openLink(DROID_IFY_URL) },
)
}
}
Expand Down Expand Up @@ -588,7 +586,7 @@ private fun Context.translateLocale(locale: Locale?): String {
val capitalizedLanguage = language?.replaceFirstChar { it.uppercase(Locale.getDefault()) }
val countrySuffix = if (country?.isNotEmpty() == true && country.compareTo(
language.toString(),
ignoreCase = true
ignoreCase = true,
) != 0
) {
"($country)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import com.looker.droidify.utility.common.extension.getLauncherActivities
import com.looker.droidify.utility.common.extension.getMutatedIcon
import com.looker.droidify.utility.common.extension.isFirstItemVisible
import com.looker.droidify.utility.common.extension.isSystemApplication
import com.looker.droidify.utility.common.extension.openLink
import com.looker.droidify.utility.common.extension.systemBarsPadding
import com.looker.droidify.utility.common.extension.updateAsMutable
import com.looker.droidify.utility.common.shareUrl
Expand Down Expand Up @@ -246,7 +247,7 @@ class AppDetailFragment() : ScreenFragment(), AppDetailAdapter.Callbacks {
val canInstall = product != null && installed == null && compatible
val canUpdate =
product != null && compatible && product.canUpdate(installed?.installedItem) &&
!preference.shouldIgnoreUpdate(product.versionCode)
!preference.shouldIgnoreUpdate(product.versionCode)
val canUninstall = product != null && installed != null && !installed.isSystem
val canLaunch =
product != null && installed != null && installed.launcherActivities.isNotEmpty()
Expand Down Expand Up @@ -476,7 +477,7 @@ class AppDetailFragment() : ScreenFragment(), AppDetailAdapter.Callbacks {

AppDetailAdapter.Action.SOURCE -> {
val link = products[0].first.source
startActivity(Intent(Intent.ACTION_VIEW, link.toUri()))
context?.openLink(link)
}
}
}
Expand All @@ -486,11 +487,7 @@ class AppDetailFragment() : ScreenFragment(), AppDetailAdapter.Callbacks {
}

override fun onCustomButtonClick(url: String) {
try {
startActivity(Intent(Intent.ACTION_VIEW, url.toUri()))
} catch (e: ActivityNotFoundException) {
e.printStackTrace()
}
context?.openLink(url)
}

private fun startLauncherActivity(name: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package com.looker.droidify.utility.common.extension

import android.app.NotificationManager
import android.app.job.JobScheduler
import android.content.ActivityNotFoundException
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.content.Intent
import android.content.res.ColorStateList
import android.graphics.drawable.Drawable
import android.os.PowerManager
import android.util.Log
import android.view.inputmethod.InputMethodManager
import androidx.annotation.AttrRes
import androidx.annotation.DrawableRes
Expand All @@ -17,6 +19,7 @@ import androidx.core.content.ContextCompat
import androidx.core.content.getSystemService
import androidx.core.net.toUri
import com.looker.droidify.R
import com.looker.droidify.utility.common.log

inline val Context.clipboardManager: ClipboardManager?
get() = getSystemService()
Expand All @@ -39,9 +42,23 @@ fun Context.copyToClipboard(clip: String) {

fun Context.openLink(url: String) {
val intent = intent(Intent.ACTION_VIEW) {
setData(url.toUri())
data = url.toUri()
}
try {
startActivity(intent)
} catch (_: ActivityNotFoundException) {
log("Failed to find dedicated app for $url, trying browser", "OpenLink", Log.WARN)
// If no app found try to force open in browser
Comment thread
Netrifier marked this conversation as resolved.
intent.selector = intent(Intent.ACTION_VIEW) {
data = "https://".toUri()
addCategory(Intent.CATEGORY_BROWSABLE)
}
try {
startActivity(intent)
} catch (e: ActivityNotFoundException) {
e.printStackTrace()
}
}
startActivity(intent)
}

val Context.corneredBackground: Drawable
Expand Down