๐Ÿ”— Redirect Bluesky links to your preferred client
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

Extract some functions

+104 -80
+7 -53
shared/src/main/java/dev/zwander/shared/components/LinkVerifyLayout.kt
··· 1 1 package dev.zwander.shared.components 2 2 3 - import android.content.ComponentName 4 3 import android.content.Intent 5 4 import android.net.Uri 6 5 import android.os.Build 7 - import android.util.Log 8 6 import androidx.compose.animation.AnimatedVisibility 9 7 import androidx.compose.animation.Crossfade 10 8 import androidx.compose.foundation.clickable ··· 49 47 import dev.zwander.shared.IShizukuService 50 48 import dev.zwander.shared.LaunchStrategy 51 49 import dev.zwander.shared.R 52 - import dev.zwander.shared.RedirectActivity 53 50 import dev.zwander.shared.model.AppModel 54 51 import dev.zwander.shared.model.LocalAppModel 55 52 import dev.zwander.shared.util.BaseLaunchStrategyUtils 56 53 import dev.zwander.shared.util.Expander 57 54 import dev.zwander.shared.util.LinkSheetStatus 58 55 import dev.zwander.shared.util.LinkVerificationModel 59 - import dev.zwander.shared.util.LinkVerifyUtils.launchManualVerification 56 + import dev.zwander.shared.util.LinkVerifyActions.enableWithLinkSheet 57 + import dev.zwander.shared.util.LinkVerifyActions.launchManualVerification 60 58 import dev.zwander.shared.util.Prefs 61 59 import dev.zwander.shared.util.RedirectorTheme 62 60 import dev.zwander.shared.util.ShizukuCommandResult 63 61 import dev.zwander.shared.util.ShizukuUtils.runShizukuCommand 64 62 import dev.zwander.shared.util.locals.LocalLinkSheet 65 - import dev.zwander.shared.util.openLinkNaturally 66 63 import dev.zwander.shared.util.rememberLinkSheetInstallationStatus 67 64 import kotlinx.coroutines.Dispatchers 68 65 import kotlinx.coroutines.launch ··· 263 260 264 261 TextButton( 265 262 onClick = { 266 - when (linkSheetStatus) { 267 - LinkSheetStatus.NOT_INSTALLED -> { 268 - context.openLinkNaturally(Uri.parse("https://github.com/1fexd/LinkSheet")) 269 - } 270 - LinkSheetStatus.INSTALLED_NO_INTERCONNECT -> { 271 - linkSheet?.packageName?.let { pkg -> 272 - try { 273 - context.startActivity( 274 - context.packageManager.getLaunchIntentForPackage( 275 - pkg 276 - )?.apply { 277 - addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) 278 - }, 279 - ) 280 - } catch (e: Exception) { 281 - Log.e( 282 - "FediverseRedirect", 283 - "Failed to open LinkSheet.", 284 - e 285 - ) 286 - } 287 - } 288 - } 289 - LinkSheetStatus.INSTALLED_WITH_INTERCONNECT -> { 290 - scope.launch(Dispatchers.IO) { 291 - val component = ComponentName( 292 - context, 293 - RedirectActivity::class.java, 294 - ) 295 - 296 - try { 297 - linkSheet?.bindService(context)?.selectDomainsWithResult( 298 - packageName = context.packageName, 299 - domains = missingDomains, 300 - componentName = component, 301 - ) 302 - 303 - refresh() 304 - } catch (e: Exception) { 305 - linkSheet?.bindService(context)?.selectDomains( 306 - packageName = context.packageName, 307 - domains = missingDomains, 308 - componentName = component, 309 - ) 310 - } 311 - } 312 - } 313 - } 263 + context.enableWithLinkSheet( 264 + scope, linkSheet, 265 + linkSheetStatus, missingDomains, 266 + refresh, 267 + ) 314 268 }, 315 269 colors = buttonColors, 316 270 enabled = !loading,
+96
shared/src/main/java/dev/zwander/shared/util/LinkVerifyActions.kt
··· 1 + package dev.zwander.shared.util 2 + 3 + import android.annotation.SuppressLint 4 + import android.content.ActivityNotFoundException 5 + import android.content.ComponentName 6 + import android.content.Context 7 + import android.content.Intent 8 + import android.net.Uri 9 + import android.provider.Settings 10 + import android.util.Log 11 + import dev.zwander.shared.RedirectActivity 12 + import fe.linksheet.interconnect.LinkSheet 13 + import kotlinx.coroutines.CoroutineScope 14 + import kotlinx.coroutines.Dispatchers 15 + import kotlinx.coroutines.launch 16 + 17 + object LinkVerifyActions { 18 + @SuppressLint("InlinedApi") 19 + fun Context.launchManualVerification() { 20 + val qDirect = Settings.ACTION_APP_OPEN_BY_DEFAULT_SETTINGS 21 + val pDirect = "android.settings.APPLICATION_DETAILS_SETTINGS_OPEN_BY_DEFAULT_PAGE" 22 + val appDetails = Settings.ACTION_APPLICATION_DETAILS_SETTINGS 23 + 24 + val intent = Intent(Intent.ACTION_VIEW, Uri.parse("package:$packageName")) 25 + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) 26 + 27 + arrayOf(qDirect, pDirect, appDetails).forEach { action -> 28 + try { 29 + intent.action = action 30 + startActivity(intent) 31 + return 32 + } catch (e: ActivityNotFoundException) { 33 + e.printStackTrace() 34 + } catch (e: SecurityException) { 35 + e.printStackTrace() 36 + } 37 + } 38 + } 39 + 40 + fun Context.enableWithLinkSheet( 41 + scope: CoroutineScope, 42 + linkSheet: LinkSheet?, 43 + linkSheetStatus: LinkSheetStatus, 44 + missingDomains: List<String>, 45 + refresh: () -> Unit, 46 + ) { 47 + when (linkSheetStatus) { 48 + LinkSheetStatus.NOT_INSTALLED -> { 49 + openLinkNaturally(Uri.parse("https://github.com/1fexd/LinkSheet")) 50 + } 51 + LinkSheetStatus.INSTALLED_NO_INTERCONNECT -> { 52 + linkSheet?.packageName?.let { pkg -> 53 + try { 54 + startActivity( 55 + packageManager.getLaunchIntentForPackage( 56 + pkg 57 + )?.apply { 58 + addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) 59 + }, 60 + ) 61 + } catch (e: Exception) { 62 + Log.e( 63 + "FediverseRedirect", 64 + "Failed to open LinkSheet.", 65 + e 66 + ) 67 + } 68 + } 69 + } 70 + LinkSheetStatus.INSTALLED_WITH_INTERCONNECT -> { 71 + scope.launch(Dispatchers.IO) { 72 + val component = ComponentName( 73 + this@enableWithLinkSheet, 74 + RedirectActivity::class.java, 75 + ) 76 + 77 + try { 78 + linkSheet?.bindService(this@enableWithLinkSheet)?.selectDomainsWithResult( 79 + packageName = packageName, 80 + domains = missingDomains, 81 + componentName = component, 82 + ) 83 + 84 + refresh() 85 + } catch (e: Exception) { 86 + linkSheet?.bindService(this@enableWithLinkSheet)?.selectDomains( 87 + packageName = packageName, 88 + domains = missingDomains, 89 + componentName = component, 90 + ) 91 + } 92 + } 93 + } 94 + } 95 + } 96 + }
+1 -27
shared/src/main/java/dev/zwander/shared/util/LinkVerifyUtils.kt
··· 1 1 package dev.zwander.shared.util 2 2 3 3 import android.annotation.SuppressLint 4 - import android.content.ActivityNotFoundException 5 4 import android.content.Context 6 - import android.content.Intent 7 5 import android.content.pm.verify.domain.DomainVerificationManager 8 6 import android.content.pm.verify.domain.DomainVerificationUserState 9 - import android.net.Uri 10 7 import android.os.Build 11 - import android.provider.Settings 12 8 import androidx.annotation.RequiresApi 13 9 import androidx.compose.runtime.Composable 14 10 import androidx.compose.runtime.State ··· 20 16 import androidx.lifecycle.Lifecycle 21 17 import dev.zwander.shared.util.hiddenapi.PackageManager 22 18 import dev.zwander.shared.util.locals.LocalLinkSheet 19 + import fe.linksheet.interconnect.LinkSheet 23 20 import kotlinx.coroutines.Dispatchers 24 21 import kotlinx.coroutines.flow.MutableStateFlow 25 22 import kotlinx.coroutines.flow.StateFlow 26 23 import kotlinx.coroutines.launch 27 - import fe.linksheet.interconnect.LinkSheet 28 24 29 25 object LinkVerificationModel { 30 26 private val _refreshFlow = MutableStateFlow(0) ··· 40 36 } 41 37 42 38 object LinkVerifyUtils { 43 - @SuppressLint("InlinedApi") 44 - fun Context.launchManualVerification() { 45 - val qDirect = Settings.ACTION_APP_OPEN_BY_DEFAULT_SETTINGS 46 - val pDirect = "android.settings.APPLICATION_DETAILS_SETTINGS_OPEN_BY_DEFAULT_PAGE" 47 - val appDetails = Settings.ACTION_APPLICATION_DETAILS_SETTINGS 48 - 49 - val intent = Intent(Intent.ACTION_VIEW, Uri.parse("package:$packageName")) 50 - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) 51 - 52 - arrayOf(qDirect, pDirect, appDetails).forEach { action -> 53 - try { 54 - intent.action = action 55 - startActivity(intent) 56 - return 57 - } catch (e: ActivityNotFoundException) { 58 - e.printStackTrace() 59 - } catch (e: SecurityException) { 60 - e.printStackTrace() 61 - } 62 - } 63 - } 64 - 65 39 @SuppressLint("WrongConstant", "MissingPermission") 66 40 @Composable 67 41 fun rememberLinkVerificationAsState(): State<LinkVerificationStatus> {