-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e5baae6
commit 8f89208
Showing
8 changed files
with
101 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
common/src/main/kotlin/com/alfresco/content/GetSingleContent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.alfresco.content | ||
|
||
import android.app.Activity | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.net.Uri | ||
import androidx.activity.result.contract.ActivityResultContract | ||
import androidx.annotation.CallSuper | ||
|
||
/** | ||
* An ActivityResultContract similar to | ||
* [androidx.activity.result.contract.ActivityResultContracts.GetSingleContents] | ||
* that allows specifying multiple mimeTypes. | ||
*/ | ||
class GetSingleContent : ActivityResultContract<Array<String>, List<Uri>>() { | ||
|
||
@CallSuper | ||
override fun createIntent(context: Context, input: Array<String>): Intent { | ||
return Intent(Intent.ACTION_GET_CONTENT) | ||
.addCategory(Intent.CATEGORY_OPENABLE) | ||
.setType("*/*") | ||
.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, false) | ||
.putExtra(Intent.EXTRA_MIME_TYPES, input) | ||
} | ||
|
||
override fun parseResult(resultCode: Int, intent: Intent?): List<Uri> { | ||
return if (intent == null || resultCode != Activity.RESULT_OK) { | ||
emptyList() | ||
} else { | ||
getClipDataUris(intent) | ||
} | ||
} | ||
|
||
companion object { | ||
const val MAX_FILE_SIZE = 100 | ||
|
||
/** | ||
* returns true if file exceed the 100mb length otherwise false | ||
*/ | ||
fun isFileSizeExceed(length: Long): Boolean { | ||
val fileLength = length.div(1024L).div(1024L) | ||
return fileLength > MAX_FILE_SIZE.minus(1).toLong() | ||
} | ||
|
||
fun getClipDataUris(intent: Intent): List<Uri> { | ||
// Use a LinkedHashSet to maintain any ordering that may be | ||
// present in the ClipData | ||
val resultSet = LinkedHashSet<Uri>() | ||
|
||
val intentData = intent.data | ||
if (intentData != null) { | ||
resultSet.add(intentData) | ||
} | ||
|
||
val clipData = intent.clipData | ||
if (clipData == null && resultSet.isEmpty()) { | ||
return emptyList() | ||
} else if (clipData != null) { | ||
for (i in 0 until clipData.itemCount) { | ||
val uri = clipData.getItemAt(i).uri | ||
if (uri != null) { | ||
resultSet.add(uri) | ||
} | ||
} | ||
} | ||
return ArrayList(resultSet) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters