@@ -10,53 +10,17 @@ package com.nextcloud.utils
1010import android.content.ActivityNotFoundException
1111import android.content.Context
1212import android.content.Intent
13- import android.net.Uri
1413import androidx.core.net.toUri
15- import com.nextcloud.client.account.User
1614import com.owncloud.android.lib.common.utils.Log_OC
17- import com.owncloud.android.ui.activity.FileDisplayActivity
1815import java.util.Locale
19- import java.util.Optional
20- import kotlin.jvm.optionals.getOrNull
2116
2217object LinkHelper {
23- const val APP_NEXTCLOUD_NOTES = " it.niedermann.owncloud.notes"
24- const val APP_NEXTCLOUD_TALK = " com.nextcloud.talk2"
2518 private const val TAG = " LinkHelper"
2619
2720 fun isHttpOrHttpsLink (link : String? ): Boolean = link?.lowercase(Locale .getDefault())?.let {
2821 it.startsWith(" http://" ) || it.startsWith(" https://" )
2922 } == true
3023
31- /* *
32- * Open specified app and, if not installed redirect to corresponding download.
33- *
34- * @param packageName of app to be opened
35- * @param user to pass in intent
36- */
37- fun openAppOrStore (packageName : String , user : Optional <User >, context : Context ) {
38- openAppOrStore(packageName, user.getOrNull(), context)
39- }
40-
41- /* *
42- * Open specified app and, if not installed redirect to corresponding download.
43- *
44- * @param packageName of app to be opened
45- * @param user to pass in intent
46- */
47- fun openAppOrStore (packageName : String , user : User ? , context : Context ) {
48- val intent = context.packageManager.getLaunchIntentForPackage(packageName)
49- if (intent != null ) {
50- // app installed - open directly
51- // TODO handle null user?
52- intent.putExtra(FileDisplayActivity .KEY_ACCOUNT , user.hashCode())
53- context.startActivity(intent)
54- } else {
55- // app not found - open market (Google Play Store, F-Droid, etc.)
56- openAppStore(packageName, false , context)
57- }
58- }
59-
6024 /* *
6125 * Open app store page of specified app or search for specified string. Will attempt to open browser when no app
6226 * store is available.
@@ -69,7 +33,7 @@ object LinkHelper {
6933 val intent = Intent (Intent .ACTION_VIEW , " market://$suffix " .toUri())
7034 try {
7135 context.startActivity(intent)
72- } catch (activityNotFoundException1 : ActivityNotFoundException ) {
36+ } catch (_ : ActivityNotFoundException ) {
7337 // all is lost: open google play store web page for app
7438 if (! search) {
7539 suffix = " apps/$suffix "
@@ -82,32 +46,6 @@ object LinkHelper {
8246 // region Validation
8347 private const val HTTP = " http"
8448 private const val HTTPS = " https"
85- private const val FILE = " file"
86- private const val CONTENT = " content"
87-
88- /* *
89- * Validates if a string can be converted to a valid URI
90- */
91- @Suppress(" TooGenericExceptionCaught" , " ReturnCount" )
92- fun validateAndGetURI (uriString : String? ): Uri ? {
93- if (uriString.isNullOrBlank()) {
94- Log_OC .w(TAG , " Given uriString is null or blank" )
95- return null
96- }
97-
98- return try {
99- val uri = uriString.toUri()
100- if (uri.scheme == null ) {
101- return null
102- }
103-
104- val validSchemes = listOf (HTTP , HTTPS , FILE , CONTENT )
105- if (uri.scheme in validSchemes) uri else null
106- } catch (e: Exception ) {
107- Log_OC .e(TAG , " Invalid URI string: $uriString -- $e " )
108- null
109- }
110- }
11149
11250 /* *
11351 * Validates if a URL string is valid
0 commit comments