@@ -10,46 +10,16 @@ package it.niedermann.owncloud.notes.util
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.owncloud.android.lib.common.utils.Log_OC
16- import java.util.Locale
1714
1815/* *
1916 * Helper class for opening Nextcloud apps if present
2017 * or falling back to opening the app store
2118 * in case the app is not yet installed on the device.
2219 */
2320object LinkHelper {
24- const val APP_NEXTCLOUD_FILES = " com.nextcloud.client"
25- const val APP_NEXTCLOUD_NOTES = " it.niedermann.owncloud.notes"
26- const val APP_NEXTCLOUD_TALK = " com.nextcloud.talk2"
27- const val KEY_ACCOUNT : String = " KEY_ACCOUNT"
2821 private const val TAG = " LinkHelper"
2922
30- /* *
31- * Open specified app and, if not installed redirect to corresponding download.
32- *
33- * @param packageName of app to be opened
34- * @param userHash to pass in intent
35- */
36- fun openAppOrStore (
37- packageName : String ,
38- userHash : String? ,
39- context : Context ,
40- ) {
41- val intent = context.packageManager.getLaunchIntentForPackage(packageName)
42- if (intent != null ) {
43- // app installed - open directly
44- // TODO handle null user?
45- intent.putExtra(KEY_ACCOUNT , userHash)
46- context.startActivity(intent)
47- } else {
48- // app not found - open market (Google Play Store, F-Droid, etc.)
49- openAppStore(packageName, false , context)
50- }
51- }
52-
5323 /* *
5424 * Open app store page of specified app or search for specified string. Will attempt to open browser when no app
5525 * store is available.
@@ -66,7 +36,7 @@ object LinkHelper {
6636 val intent = Intent (Intent .ACTION_VIEW , " market://$suffix " .toUri())
6737 try {
6838 context.startActivity(intent)
69- } catch (activityNotFoundException1 : ActivityNotFoundException ) {
39+ } catch (_ : ActivityNotFoundException ) {
7040 // all is lost: open google play store web page for app
7141 if (! search) {
7242 suffix = " apps/$suffix "
@@ -75,58 +45,4 @@ object LinkHelper {
7545 context.startActivity(intent)
7646 }
7747 }
78-
79- // region Validation
80- private const val HTTP = " http"
81- private const val HTTPS = " https"
82- private const val FILE = " file"
83- private const val CONTENT = " content"
84-
85- /* *
86- * Validates if a string can be converted to a valid URI
87- */
88- @Suppress(" TooGenericExceptionCaught" , " ReturnCount" )
89- fun validateAndGetURI (uriString : String? ): Uri ? {
90- if (uriString.isNullOrBlank()) {
91- Log_OC .w(TAG , " Given uriString is null or blank" )
92- return null
93- }
94-
95- return try {
96- val uri = uriString.toUri()
97- if (uri.scheme == null ) {
98- return null
99- }
100-
101- val validSchemes = listOf (HTTP , HTTPS , FILE , CONTENT )
102- if (uri.scheme in validSchemes) uri else null
103- } catch (e: Exception ) {
104- Log_OC .e(TAG , " Invalid URI string: $uriString -- $e " )
105- null
106- }
107- }
108-
109- /* *
110- * Validates if a URL string is valid
111- */
112- @Suppress(" TooGenericExceptionCaught" , " ReturnCount" )
113- fun validateAndGetURL (url : String? ): String? {
114- if (url.isNullOrBlank()) {
115- Log_OC .w(TAG , " Given url is null or blank" )
116- return null
117- }
118-
119- return try {
120- val uri = url.toUri()
121- if (uri.scheme == null ) {
122- return null
123- }
124- val validSchemes = listOf (HTTP , HTTPS )
125- if (uri.scheme in validSchemes) url else null
126- } catch (e: Exception ) {
127- Log_OC .e(TAG , " Invalid URL: $url -- $e " )
128- null
129- }
130- }
131- // endregion
13248}
0 commit comments