mirror of
https://github.com/nextcloud/talk-android
synced 2025-07-10 14:24:05 +01:00
add ability to send predefined and custom status
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
8117c775a7
commit
454c6cd8e6
@ -458,4 +458,18 @@ public interface NcApi {
|
|||||||
Observable<GenericOverall> statusDeleteMessage(@Header("Authorization") String authorization, @Url String url);
|
Observable<GenericOverall> statusDeleteMessage(@Header("Authorization") String authorization, @Url String url);
|
||||||
|
|
||||||
|
|
||||||
|
@FormUrlEncoded
|
||||||
|
@PUT
|
||||||
|
Observable<GenericOverall> setPredefinedStatusMessage(@Header("Authorization") String authorization,
|
||||||
|
@Url String url,
|
||||||
|
@Field("messageId") String selectedPredefinedMessageId,
|
||||||
|
@Field("clearAt") Long clearAt);
|
||||||
|
|
||||||
|
@FormUrlEncoded
|
||||||
|
@PUT
|
||||||
|
Observable<GenericOverall> setCustomStatusMessage(@Header("Authorization") String authorization,
|
||||||
|
@Url String url,
|
||||||
|
@Field("statusIcon") String statusIcon,
|
||||||
|
@Field("message") String message,
|
||||||
|
@Field("clearAt") Long clearAt);
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,7 @@ class SetStatusDialogFragment :
|
|||||||
|
|
||||||
private lateinit var adapter: PredefinedStatusListAdapter
|
private lateinit var adapter: PredefinedStatusListAdapter
|
||||||
private var selectedPredefinedMessageId: String? = null
|
private var selectedPredefinedMessageId: String? = null
|
||||||
private var clearAt: Long? = -1
|
private var clearAt: Long? = null
|
||||||
private lateinit var popup: EmojiPopup
|
private lateinit var popup: EmojiPopup
|
||||||
|
|
||||||
// @Inject
|
// @Inject
|
||||||
@ -113,6 +113,8 @@ class SetStatusDialogFragment :
|
|||||||
@Inject
|
@Inject
|
||||||
lateinit var ncApi: NcApi
|
lateinit var ncApi: NcApi
|
||||||
|
|
||||||
|
lateinit var credentials: String
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
@ -122,7 +124,7 @@ class SetStatusDialogFragment :
|
|||||||
currentUser = it.getParcelable(ARG_CURRENT_USER_PARAM)
|
currentUser = it.getParcelable(ARG_CURRENT_USER_PARAM)
|
||||||
currentStatus = it.getParcelable(ARG_CURRENT_STATUS_PARAM)
|
currentStatus = it.getParcelable(ARG_CURRENT_STATUS_PARAM)
|
||||||
|
|
||||||
val credentials = ApiUtils.getCredentials(currentUser?.username, currentUser?.token)
|
credentials = ApiUtils.getCredentials(currentUser?.username, currentUser?.token)
|
||||||
ncApi.getPredefinedStatuses(credentials, ApiUtils.getUrlForPredefinedStatuses(currentUser?.baseUrl))
|
ncApi.getPredefinedStatuses(credentials, ApiUtils.getUrlForPredefinedStatuses(currentUser?.baseUrl))
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
@ -408,6 +410,61 @@ class SetStatusDialogFragment :
|
|||||||
|
|
||||||
|
|
||||||
private fun setStatusMessage() {
|
private fun setStatusMessage() {
|
||||||
|
if (selectedPredefinedMessageId != null) {
|
||||||
|
|
||||||
|
ncApi.setPredefinedStatusMessage(
|
||||||
|
credentials,
|
||||||
|
ApiUtils.getUrlForSetPredefinedStatus(currentUser?.baseUrl),
|
||||||
|
selectedPredefinedMessageId,
|
||||||
|
clearAt)
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
?.subscribe(object : Observer<GenericOverall> {
|
||||||
|
|
||||||
|
override fun onSubscribe(d: Disposable) {
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onNext(t: GenericOverall) {
|
||||||
|
Log.d(TAG, "PredefinedStatusMessage successfully set")
|
||||||
|
dismiss()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onError(e: Throwable) {
|
||||||
|
Log.d(TAG, "failed to set PredefinedStatusMessage", e)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onComplete() {}
|
||||||
|
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
ncApi.setCustomStatusMessage(
|
||||||
|
credentials,
|
||||||
|
ApiUtils.getUrlForSetCustomStatus(currentUser?.baseUrl),
|
||||||
|
binding.emoji.text.toString(),
|
||||||
|
binding.customStatusInput.text.toString(),
|
||||||
|
clearAt)
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
?.subscribe(object : Observer<GenericOverall> {
|
||||||
|
|
||||||
|
override fun onSubscribe(d: Disposable) {
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onNext(t: GenericOverall) {
|
||||||
|
Log.d(TAG, "CustomStatusMessage successfully set")
|
||||||
|
dismiss()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onError(e: Throwable) {
|
||||||
|
Log.d(TAG, "failed to set CustomStatusMessage", e)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onComplete() {}
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// if (selectedPredefinedMessageId != null) {
|
// if (selectedPredefinedMessageId != null) {
|
||||||
// asyncRunner.postQuickTask(
|
// asyncRunner.postQuickTask(
|
||||||
// SetPredefinedCustomStatusTask(
|
// SetPredefinedCustomStatusTask(
|
||||||
@ -439,25 +496,6 @@ class SetStatusDialogFragment :
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fragment creator
|
|
||||||
*/
|
|
||||||
companion object {
|
|
||||||
@JvmStatic
|
|
||||||
fun newInstance(user: User, status: Status): SetStatusDialogFragment {
|
|
||||||
val args = Bundle()
|
|
||||||
args.putParcelable(ARG_CURRENT_USER_PARAM, user)
|
|
||||||
args.putParcelable(ARG_CURRENT_STATUS_PARAM, status)
|
|
||||||
|
|
||||||
|
|
||||||
val dialogFragment = SetStatusDialogFragment()
|
|
||||||
dialogFragment.arguments = args
|
|
||||||
// dialogFragment.setStyle(STYLE_NORMAL, R.style.Theme_ownCloud_Dialog)
|
|
||||||
return dialogFragment
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||||
return binding.root
|
return binding.root
|
||||||
}
|
}
|
||||||
@ -502,5 +540,24 @@ class SetStatusDialogFragment :
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fragment creator
|
||||||
|
*/
|
||||||
|
companion object {
|
||||||
|
private const val TAG = "SetStatusDialogFragment"
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun newInstance(user: User, status: Status): SetStatusDialogFragment {
|
||||||
|
val args = Bundle()
|
||||||
|
args.putParcelable(ARG_CURRENT_USER_PARAM, user)
|
||||||
|
args.putParcelable(ARG_CURRENT_STATUS_PARAM, status)
|
||||||
|
|
||||||
|
|
||||||
|
val dialogFragment = SetStatusDialogFragment()
|
||||||
|
dialogFragment.arguments = args
|
||||||
|
// dialogFragment.setStyle(STYLE_NORMAL, R.style.Theme_ownCloud_Dialog)
|
||||||
|
return dialogFragment
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -434,4 +434,11 @@ public class ApiUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static String getUrlForSetPredefinedStatus(String baseUrl) {
|
||||||
|
return baseUrl + ocsApiVersion + "/apps/user_status/api/v1/user_status/message/predefined";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getUrlForSetCustomStatus(String baseUrl) {
|
||||||
|
return baseUrl + ocsApiVersion + "/apps/user_status/api/v1/user_status/message/custom";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user