From 45cfbc7257776bd4a543f7662ba097df1118b93d Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Tue, 8 Feb 2022 12:25:30 +0100 Subject: [PATCH] add ability to set status type Signed-off-by: Marcel Hibbe --- .../java/com/nextcloud/talk/api/NcApi.java | 6 +++++ .../talk/ui/dialog/SetStatusDialogFragment.kt | 27 ++++++++++--------- .../com/nextcloud/talk/utils/ApiUtils.java | 4 +++ 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/api/NcApi.java b/app/src/main/java/com/nextcloud/talk/api/NcApi.java index c35ec464f..b7bfb7bc8 100644 --- a/app/src/main/java/com/nextcloud/talk/api/NcApi.java +++ b/app/src/main/java/com/nextcloud/talk/api/NcApi.java @@ -472,4 +472,10 @@ public interface NcApi { @Field("statusIcon") String statusIcon, @Field("message") String message, @Field("clearAt") Long clearAt); + + @FormUrlEncoded + @PUT + Observable setStatusType(@Header("Authorization") String authorization, + @Url String url, + @Field("statusType") String statusType); } diff --git a/app/src/main/java/com/nextcloud/talk/ui/dialog/SetStatusDialogFragment.kt b/app/src/main/java/com/nextcloud/talk/ui/dialog/SetStatusDialogFragment.kt index f70419fc5..546e36e43 100644 --- a/app/src/main/java/com/nextcloud/talk/ui/dialog/SetStatusDialogFragment.kt +++ b/app/src/main/java/com/nextcloud/talk/ui/dialog/SetStatusDialogFragment.kt @@ -352,19 +352,20 @@ class SetStatusDialogFragment : private fun setStatus(statusType: StatusType) { visualizeStatus(statusType) - // asyncRunner.postQuickTask( - // SetStatusTask( - // statusType, - // accountManager.currentOwnCloudAccount?.savedAccount, - // context - // ), - // { - // if (!it) { - // clearTopStatus() - // } - // }, - // { clearTopStatus() } - // ) + ncApi.setStatusType(credentials, ApiUtils.getUrlForSetStatusType(currentUser?.baseUrl), statusType.string) + .subscribeOn(Schedulers + .io()) + .observeOn(AndroidSchedulers.mainThread()).subscribe(object : Observer { + override fun onSubscribe(d: Disposable) {} + override fun onNext(statusOverall: GenericOverall) { + Log.d(TAG, "statusType successfully set") + } + override fun onError(e: Throwable) { + Log.e(logTag, "Failed to set statusType", e) + clearTopStatus() + } + override fun onComplete() {} + }) } private fun visualizeStatus(statusType: String) { diff --git a/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java b/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java index b5cf6ff74..c8781fcae 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java +++ b/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java @@ -425,6 +425,10 @@ public class ApiUtils { return baseUrl + ocsApiVersion + "/apps/user_status/api/v1/user_status"; } + public static String getUrlForSetStatusType(String baseUrl) { + return getUrlForStatus(baseUrl) + "/status"; + } + public static String getUrlForPredefinedStatuses(String baseUrl) { return baseUrl + ocsApiVersion + "/apps/user_status/api/v1/predefined_statuses"; }