forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80 from software-mansion-labs/share-utils/android…
…-other-filetypes-support android support for remaining file types
- Loading branch information
Showing
15 changed files
with
397 additions
and
183 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
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
114 changes: 0 additions & 114 deletions
114
android/app/src/main/java/com/expensify/chat/image/ImageUtils.kt
This file was deleted.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
android/app/src/main/java/com/expensify/chat/intentHandler/AbstractIntentHandler.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 |
---|---|---|
@@ -1,5 +1,19 @@ | ||
package com.expensify.chat.intentHandler | ||
|
||
import android.content.Context | ||
import com.expensify.chat.utils.FileUtils.clearInternalStorageDirectory | ||
|
||
abstract class AbstractIntentHandler: IntentHandler { | ||
override fun onCompleted() {} | ||
|
||
protected fun clearTemporaryFiles(context: Context) { | ||
// Clear data present in the shared preferences | ||
val sharedPreferences = context.getSharedPreferences(IntentHandlerConstants.preferencesFile, Context.MODE_PRIVATE) | ||
val editor = sharedPreferences.edit() | ||
editor.clear() | ||
editor.apply() | ||
|
||
// Clear leftover temporary files from previous share attempts | ||
clearInternalStorageDirectory(context) | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
android/app/src/main/java/com/expensify/chat/intentHandler/ApplicationIntentHandler.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,51 @@ | ||
package com.expensify.chat.intentHandler | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import android.net.Uri | ||
import android.util.Log | ||
import com.expensify.chat.utils.FileUtils | ||
|
||
|
||
class ApplicationIntentHandler(private val context: Context) : AbstractIntentHandler() { | ||
override fun handle(intent: Intent): Boolean { | ||
super.clearTemporaryFiles(context) | ||
when(intent.action) { | ||
Intent.ACTION_SEND -> { | ||
handleApplicationIntent(intent, context) | ||
onCompleted() | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
private fun handleApplicationIntent(intent: Intent, context: Context) { | ||
(intent.getParcelableExtra<Uri>(Intent.EXTRA_STREAM))?.let { fileUri -> | ||
// Update UI to reflect image being shared | ||
if (fileUri == null) { | ||
return | ||
} | ||
Log.i("AppIntentHandler", "uri: $fileUri") | ||
|
||
val resultingPath: String? = FileUtils.copyUriToStorage(fileUri, context) | ||
if (resultingPath != null) { | ||
val shareFileObject = ShareFileObject(resultingPath, intent.type) | ||
|
||
val sharedPreferences = context.getSharedPreferences(IntentHandlerConstants.preferencesFile, Context.MODE_PRIVATE) | ||
val editor = sharedPreferences.edit() | ||
editor.putString(IntentHandlerConstants.shareObjectProperty, shareFileObject.toString()) | ||
editor.apply() | ||
} | ||
} | ||
} | ||
|
||
|
||
override fun onCompleted() { | ||
val uri: Uri = Uri.parse("new-expensify://share/root") | ||
val deepLinkIntent = Intent(Intent.ACTION_VIEW, uri) | ||
deepLinkIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK | ||
context.startActivity(deepLinkIntent) | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
android/app/src/main/java/com/expensify/chat/intentHandler/AudioVideoIntentHandler.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,49 @@ | ||
package com.expensify.chat.intentHandler | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import android.net.Uri | ||
import com.expensify.chat.utils.FileUtils | ||
|
||
|
||
class AudioVideoIntentHandler(private val context: Context) : AbstractIntentHandler() { | ||
override fun handle(intent: Intent): Boolean { | ||
super.clearTemporaryFiles(context) | ||
when(intent.action) { | ||
Intent.ACTION_SEND -> { | ||
handleAudioVideoIntent(intent, context) | ||
onCompleted() | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
private fun handleAudioVideoIntent(intent: Intent, context: Context) { | ||
(intent.getParcelableExtra<Uri>(Intent.EXTRA_STREAM))?.let { fileUri -> | ||
// Update UI to reflect image being shared | ||
if (fileUri == null) { | ||
return | ||
} | ||
|
||
val resultingPath: String? = FileUtils.copyUriToStorage(fileUri, context) | ||
if (resultingPath != null) { | ||
val shareFileObject = ShareFileObject(resultingPath, intent.type) | ||
|
||
val sharedPreferences = context.getSharedPreferences(IntentHandlerConstants.preferencesFile, Context.MODE_PRIVATE) | ||
val editor = sharedPreferences.edit() | ||
editor.putString(IntentHandlerConstants.shareObjectProperty, shareFileObject.toString()) | ||
editor.apply() | ||
} | ||
} | ||
} | ||
|
||
|
||
override fun onCompleted() { | ||
val uri: Uri = Uri.parse("new-expensify://share/root") | ||
val deepLinkIntent = Intent(Intent.ACTION_VIEW, uri) | ||
deepLinkIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK | ||
context.startActivity(deepLinkIntent) | ||
} | ||
|
||
} |
Oops, something went wrong.