-
Notifications
You must be signed in to change notification settings - Fork 130
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 #10650 from woocommerce/10648-backed-receipt-downl…
…oad-and-share-a-file-not-a-link [Backed Receipt] Download and share a file not a link
- Loading branch information
Showing
17 changed files
with
368 additions
and
98 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
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
59 changes: 59 additions & 0 deletions
59
...mmerce/src/main/kotlin/com/woocommerce/android/ui/payments/receipt/PaymentReceiptShare.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,59 @@ | ||
package com.woocommerce.android.ui.payments.receipt | ||
|
||
import android.app.Application | ||
import android.content.Intent | ||
import android.os.Environment | ||
import androidx.core.content.FileProvider | ||
import com.woocommerce.android.media.FileUtils | ||
import com.woocommerce.android.util.FileDownloader | ||
import javax.inject.Inject | ||
|
||
class PaymentReceiptShare @Inject constructor( | ||
private val fileUtils: FileUtils, | ||
private val fileDownloader: FileDownloader, | ||
private val context: Application, | ||
) { | ||
@Suppress("TooGenericExceptionCaught") | ||
suspend operator fun invoke(receiptUrl: String, orderNumber: Long): ReceiptShareResult { | ||
val receiptFile = fileUtils.createTempTimeStampedFile( | ||
storageDir = context.getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS) | ||
?: context.filesDir, | ||
prefix = "receipt_$orderNumber", | ||
fileExtension = "html" | ||
) | ||
return if (receiptFile == null) { | ||
ReceiptShareResult.Error.FileCreation | ||
} else if (!fileDownloader.downloadFile(receiptUrl, receiptFile)) { | ||
ReceiptShareResult.Error.FileDownload | ||
} else { | ||
val uri = FileProvider.getUriForFile( | ||
context, | ||
context.packageName + ".provider", | ||
receiptFile | ||
) | ||
val intent = Intent(Intent.ACTION_SEND).apply { | ||
type = "application/*" | ||
putExtra(Intent.EXTRA_STREAM, uri) | ||
} | ||
try { | ||
context.startActivity( | ||
Intent.createChooser(intent, null).apply { | ||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) | ||
} | ||
) | ||
ReceiptShareResult.Success | ||
} catch (e: Exception) { | ||
ReceiptShareResult.Error.Sharing(e) | ||
} | ||
} | ||
} | ||
|
||
sealed class ReceiptShareResult { | ||
object Success : ReceiptShareResult() | ||
sealed class Error : ReceiptShareResult() { | ||
data class Sharing(val exception: Exception) : Error() | ||
object FileCreation : Error() | ||
object FileDownload : Error() | ||
} | ||
} | ||
} |
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
3 changes: 0 additions & 3 deletions
3
...otlin/com/woocommerce/android/ui/payments/receipt/preview/ReceiptPreviewViewModelEvent.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,10 +1,7 @@ | ||
package com.woocommerce.android.ui.payments.receipt.preview | ||
|
||
import com.woocommerce.android.model.UiString | ||
import com.woocommerce.android.viewmodel.MultiLiveEvent | ||
|
||
data class LoadUrl(val url: String) : MultiLiveEvent.Event() | ||
|
||
data class PrintReceipt(val receiptUrl: String, val documentName: String) : MultiLiveEvent.Event() | ||
|
||
data class SendReceipt(val content: UiString, val subject: UiString, val address: String) : MultiLiveEvent.Event() |
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
Oops, something went wrong.