-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 #21115 from wordpress-mobile/issue/21105-feedback-…
…form-upload-attachments Feedback form: upload attachments
- Loading branch information
Showing
4 changed files
with
133 additions
and
28 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
57 changes: 57 additions & 0 deletions
57
WordPress/src/main/java/org/wordpress/android/support/ZendeskUploadHelper.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,57 @@ | ||
package org.wordpress.android.support | ||
|
||
import com.zendesk.service.ErrorResponse | ||
import com.zendesk.service.ZendeskCallback | ||
import org.wordpress.android.util.AppLog | ||
import org.wordpress.android.util.AppLog.T | ||
import zendesk.support.Support | ||
import zendesk.support.UploadResponse | ||
import java.io.File | ||
import javax.inject.Inject | ||
|
||
/** | ||
* https://zendesk.github.io/mobile_sdk_javadocs/supportv2/v301/index.html?zendesk/support/UploadProvider.html | ||
*/ | ||
class ZendeskUploadHelper @Inject constructor() { | ||
/** | ||
* Uploads an attachment to Zendesk. Note that the UploadResponse will contain the attachment token. | ||
*/ | ||
fun uploadAttachment( | ||
file: File, | ||
mimeType: String, | ||
callback: ZendeskCallback<UploadResponse>, | ||
) { | ||
val uploadProvider = Support.INSTANCE.provider()?.uploadProvider() | ||
if (uploadProvider == null) { | ||
AppLog.e(T.SUPPORT, "Upload provider is null") | ||
return | ||
} | ||
uploadProvider.uploadAttachment( | ||
file.name, | ||
file, | ||
mimeType, | ||
callback | ||
) | ||
} | ||
|
||
/** | ||
* Deletes an attachment from Zendesk. This is currently used only during development. | ||
*/ | ||
@Suppress("unused") | ||
fun deleteAttachment(token: String) { | ||
val uploadProvider = Support.INSTANCE.provider()?.uploadProvider() | ||
if (uploadProvider == null) { | ||
AppLog.e(T.SUPPORT, "Upload provider is null") | ||
return | ||
} | ||
uploadProvider.deleteAttachment(token, object : ZendeskCallback<Void>() { | ||
override fun onSuccess(result: Void) { | ||
AppLog.i(T.SUPPORT, "Successfully deleted Zendesk attachment") | ||
} | ||
|
||
override fun onError(error: ErrorResponse?) { | ||
AppLog.e(T.SUPPORT, "Unable to delete Zendesk attachment") | ||
} | ||
}) | ||
} | ||
} |
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