@@ -22,20 +22,17 @@ package com.owncloud.android.extensions
2222import android.app.Activity
2323import android.app.AlertDialog
2424import android.content.ActivityNotFoundException
25- import android.content.ContentResolver
2625import android.content.Context
2726import android.content.Intent
2827import android.content.Intent.FLAG_ACTIVITY_NO_HISTORY
2928import android.content.pm.PackageManager
3029import android.content.pm.ResolveInfo
3130import android.net.Uri
32- import android.os.Build
3331import android.view.inputmethod.InputMethodManager
3432import android.webkit.MimeTypeMap
3533import android.widget.Toast
3634import androidx.appcompat.app.AppCompatActivity
3735import androidx.core.content.FileProvider
38- import androidx.fragment.app.DialogFragment
3936import androidx.fragment.app.FragmentActivity
4037import androidx.lifecycle.Lifecycle
4138import androidx.lifecycle.lifecycleScope
@@ -44,7 +41,6 @@ import com.google.android.material.snackbar.Snackbar
4441import com.owncloud.android.R
4542import com.owncloud.android.data.providers.implementation.OCSharedPreferencesProvider
4643import com.owncloud.android.domain.files.model.OCFile
47- import com.owncloud.android.lib.common.network.WebdavUtils
4844import com.owncloud.android.presentation.common.ShareSheetHelper
4945import com.owncloud.android.presentation.security.LockEnforcedType
5046import com.owncloud.android.presentation.security.LockEnforcedType.Companion.parseFromInteger
@@ -60,7 +56,6 @@ import com.owncloud.android.presentation.settings.privacypolicy.PrivacyPolicyAct
6056import com.owncloud.android.presentation.settings.security.SettingsSecurityFragment.Companion.EXTRAS_LOCK_ENFORCED
6157import com.owncloud.android.providers.MdmProvider
6258import com.owncloud.android.ui.activity.FileDisplayActivity.Companion.ALL_FILES_SAF_REGEX
63- import com.owncloud.android.ui.dialog.ShareLinkToDialog
6459import com.owncloud.android.utils.CONFIGURATION_DEVICE_PROTECTION
6560import com.owncloud.android.utils.MimetypeIconUtil
6661import com.owncloud.android.utils.UriUtilsKt.getExposedFileUriForOCFile
@@ -197,22 +192,15 @@ private fun getExposedFileUri(context: Context, localPath: String): Uri? {
197192 return null
198193 }
199194
200- if (Build .VERSION .SDK_INT < Build .VERSION_CODES .N ) {
201- // TODO - use FileProvider with any Android version, with deeper testing -> 2.2.0
202- exposedFileUri = Uri .parse(
203- ContentResolver .SCHEME_FILE + " ://" + WebdavUtils .encodePath(localPath)
195+ // Use the FileProvider to get a content URI
196+ try {
197+ exposedFileUri = FileProvider .getUriForFile(
198+ context,
199+ context.getString(R .string.file_provider_authority),
200+ File (localPath)
204201 )
205- } else {
206- // Use the FileProvider to get a content URI
207- try {
208- exposedFileUri = FileProvider .getUriForFile(
209- context,
210- context.getString(R .string.file_provider_authority),
211- File (localPath)
212- )
213- } catch (e: IllegalArgumentException ) {
214- Timber .e(e, " File can't be exported" )
215- }
202+ } catch (e: IllegalArgumentException ) {
203+ Timber .e(e, " File can't be exported" )
216204 }
217205
218206 return exposedFileUri
@@ -248,19 +236,13 @@ fun Activity.openFileWithIntent(intentForSavedMimeType: Intent, intentForGuessed
248236fun AppCompatActivity.sendFile (file : File ? ) {
249237 if (file != null ) {
250238 val sendIntent: Intent = makeIntent(file, this )
251-
252- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .N ) {
253- val shareSheetIntent = ShareSheetHelper ().getShareSheetIntent(
254- intent = sendIntent,
255- context = this ,
256- title = R .string.activity_chooser_send_file_title,
257- packagesToExclude = arrayOf()
258- )
259- this .startActivity(shareSheetIntent)
260- } else {
261- val chooserDialog: DialogFragment = ShareLinkToDialog .newInstance(sendIntent, arrayOf())
262- chooserDialog.show(this .supportFragmentManager, " CHOOSER_DIALOG" )
263- }
239+ val shareSheetIntent = ShareSheetHelper ().getShareSheetIntent(
240+ intent = sendIntent,
241+ context = this ,
242+ title = R .string.activity_chooser_send_file_title,
243+ packagesToExclude = arrayOf()
244+ )
245+ this .startActivity(shareSheetIntent)
264246 } else {
265247 Timber .e(" Trying to send a NULL file" )
266248 }
@@ -309,6 +291,7 @@ fun Activity.checkPasscodeEnforced(securityEnforced: SecurityEnforced) {
309291 showSelectSecurityDialog(passcodeConfigured, patternConfigured, securityEnforced)
310292 }
311293 }
294+
312295 LockEnforcedType .EITHER_ENFORCED -> {
313296 showSelectSecurityDialog(passcodeConfigured, patternConfigured, securityEnforced)
314297 }
@@ -413,18 +396,13 @@ fun FragmentActivity.sendDownloadedFilesByShareSheet(ocFiles: List<OCFile>) {
413396 }
414397
415398 val packagesToExclude = arrayOf<String >(this @sendDownloadedFilesByShareSheet.packageName)
416- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .N ) {
417- val shareSheetIntent = ShareSheetHelper ().getShareSheetIntent(
418- sendIntent,
419- this @sendDownloadedFilesByShareSheet,
420- R .string.activity_chooser_send_file_title,
421- packagesToExclude
422- )
423- startActivity(shareSheetIntent)
424- } else {
425- val chooserDialog: DialogFragment = ShareLinkToDialog .newInstance(sendIntent, packagesToExclude)
426- chooserDialog.show(supportFragmentManager, FRAGMENT_TAG_CHOOSER_DIALOG )
427- }
399+ val shareSheetIntent = ShareSheetHelper ().getShareSheetIntent(
400+ sendIntent,
401+ this @sendDownloadedFilesByShareSheet,
402+ R .string.activity_chooser_send_file_title,
403+ packagesToExclude
404+ )
405+ startActivity(shareSheetIntent)
428406}
429407
430408fun Activity.openOCFile (ocFile : OCFile ) {
0 commit comments