add predefined statuses

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2022-02-02 19:46:07 +01:00
parent a94f0f1bf1
commit 57a408ac97
No known key found for this signature in database
GPG key ID: C793F8B59F43CE7B
12 changed files with 256 additions and 22 deletions

View file

@ -22,7 +22,7 @@
package com.nextcloud.talk.adapters package com.nextcloud.talk.adapters
import com.nextcloud.talk.models.json.status.PredefinedStatus import com.nextcloud.talk.models.json.status.predefined.PredefinedStatus
interface PredefinedStatusClickListener { interface PredefinedStatusClickListener {
fun onClick(predefinedStatus: PredefinedStatus) fun onClick(predefinedStatus: PredefinedStatus)

View file

@ -27,7 +27,7 @@ import android.view.LayoutInflater
import android.view.ViewGroup import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.nextcloud.talk.databinding.PredefinedStatusBinding import com.nextcloud.talk.databinding.PredefinedStatusBinding
import com.nextcloud.talk.models.json.status.PredefinedStatus import com.nextcloud.talk.models.json.status.predefined.PredefinedStatus
class PredefinedStatusListAdapter( class PredefinedStatusListAdapter(
private val clickListener: PredefinedStatusClickListener, private val clickListener: PredefinedStatusClickListener,

View file

@ -26,7 +26,7 @@ import android.content.Context
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.nextcloud.talk.R import com.nextcloud.talk.R
import com.nextcloud.talk.databinding.PredefinedStatusBinding import com.nextcloud.talk.databinding.PredefinedStatusBinding
import com.nextcloud.talk.models.json.status.PredefinedStatus import com.nextcloud.talk.models.json.status.predefined.PredefinedStatus
import com.nextcloud.talk.utils.DisplayUtils import com.nextcloud.talk.utils.DisplayUtils
private const val ONE_SECOND_IN_MILLIS = 1000 private const val ONE_SECOND_IN_MILLIS = 1000

View file

@ -451,6 +451,9 @@ public interface NcApi {
@GET @GET
Observable<StatusOverall> status(@Header("Authorization") String authorization, @Url String url); Observable<StatusOverall> status(@Header("Authorization") String authorization, @Url String url);
@GET
Observable<ResponseBody> getPredefinedStatuses(@Header("Authorization") String authorization, @Url String url);
@DELETE @DELETE
Observable<GenericOverall> statusDeleteMessage(@Header("Authorization") String authorization, @Url String url); Observable<GenericOverall> statusDeleteMessage(@Header("Authorization") String authorization, @Url String url);

View file

@ -1,4 +1,18 @@
package com.nextcloud.talk.models.json.status package com.nextcloud.talk.models.json.status
import android.os.Parcelable
import com.bluelinelabs.logansquare.annotation.JsonField
import com.bluelinelabs.logansquare.annotation.JsonObject
import kotlinx.android.parcel.Parcelize
class ClearAt(val type: String, val time: String) @Parcelize
@JsonObject
data class ClearAt(
@JsonField(name = ["type"])
var type: String,
@JsonField(name = ["time"])
var time: String
) : Parcelable{
// This constructor is added to work with the 'com.bluelinelabs.logansquare.annotation.JsonObject'
constructor() : this("type", "time")
}

View file

@ -1,3 +0,0 @@
package com.nextcloud.talk.models.json.status
class PredefinedStatus(val id: String, val icon: String, val message: String, val clearAt: ClearAt?)

View file

@ -0,0 +1,53 @@
package com.nextcloud.talk.models.json.status.predefined
import android.os.Parcelable
import com.bluelinelabs.logansquare.annotation.JsonField
import com.bluelinelabs.logansquare.annotation.JsonObject
import com.nextcloud.talk.models.json.status.ClearAt
import kotlinx.android.parcel.Parcelize
@Parcelize
@JsonObject
data class PredefinedStatus(
@JsonField(name = ["id"])
var id: String,
@JsonField(name = ["icon"])
var icon: String,
@JsonField(name = ["message"])
var message: String,
@JsonField(name = ["clearAt"])
var clearAt: ClearAt?
) : Parcelable {
// This constructor is added to work with the 'com.bluelinelabs.logansquare.annotation.JsonObject'
constructor() : this("id", "icon", "message", null)
}
// @Parcelize
// @JsonObject
// data class Status(
// @JsonField(name = ["userId"])
// var userId: String?,
// @JsonField(name = ["message"])
// var message: String?,
// /* TODO: Change to enum */
// @JsonField(name = ["messageId"])
// var messageId: String?,
// @JsonField(name = ["messageIsPredefined"])
// var messageIsPredefined: Boolean,
// @JsonField(name = ["icon"])
// var icon: String?,
// @JsonField(name = ["clearAt"])
// var clearAt: Long = 0,
// /* TODO: Change to enum */
// @JsonField(name = ["status"])
// var status: String = "offline",
// @JsonField(name = ["statusIsUserDefined"])
// var statusIsUserDefined: Boolean
// ) : Parcelable {
// // This constructor is added to work with the 'com.bluelinelabs.logansquare.annotation.JsonObject'
// constructor() : this(null, null, null, false, null, 0, "offline", false)
// }

View file

@ -0,0 +1,74 @@
/*
*
* Nextcloud Talk application
*
* @author Tim Krüger
* Copyright (C) 2021 Tim Krüger <t@timkrueger.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.nextcloud.talk.models.json.status.predefined;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import com.nextcloud.talk.models.json.autocomplete.AutocompleteUser;
import com.nextcloud.talk.models.json.generic.GenericOCS;
import com.nextcloud.talk.models.json.status.Status;
import java.util.List;
import java.util.Objects;
import kotlin.jvm.JvmSuppressWildcards;
@JsonObject
public class PredefinedStatusOCS extends GenericOCS {
@JsonField(name = "data")
List<PredefinedStatus> data;
public List<PredefinedStatus> getData() {
return this.data;
}
public void setData(List<PredefinedStatus> data) {
this.data = data;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
return false;
}
PredefinedStatusOCS that = (PredefinedStatusOCS) o;
return Objects.equals(data, that.data);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), data);
}
@Override
public String toString() {
return "PredefinedStatusOCS{" +
"data=" + data +
'}';
}
}

View file

@ -0,0 +1,65 @@
/*
*
* Nextcloud Talk application
*
* @author Tim Krüger
* Copyright (C) 2021 Tim Krüger <t@timkrueger.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.nextcloud.talk.models.json.status.predefined;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import com.nextcloud.talk.models.json.status.StatusOCS;
import java.util.Objects;
@JsonObject
public class PredefinedStatusOverall {
@JsonField(name = "ocs")
public PredefinedStatusOCS ocs;
public PredefinedStatusOCS getOcs() {
return this.ocs;
}
public void setOcs(PredefinedStatusOCS ocs) {
this.ocs = ocs;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
PredefinedStatusOverall that = (PredefinedStatusOverall) o;
return Objects.equals(ocs, that.ocs);
}
@Override
public int hashCode() {
return Objects.hash(ocs);
}
@Override
public String toString() {
return "PredefinedStatusOverall{" +
"ocs=" + ocs +
'}';
}
}

View file

@ -56,7 +56,6 @@ import com.nextcloud.talk.utils.database.user.UserUtils;
import java.net.CookieManager; import java.net.CookieManager;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
import javax.inject.Inject; import javax.inject.Inject;
@ -66,7 +65,6 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import autodagger.AutoInjector; import autodagger.AutoInjector;
import eu.davidea.flexibleadapter.FlexibleAdapter; import eu.davidea.flexibleadapter.FlexibleAdapter;
import eu.davidea.flexibleadapter.common.SmoothScrollLinearLayoutManager; import eu.davidea.flexibleadapter.common.SmoothScrollLinearLayoutManager;
import io.reactivex.Observable;
import io.reactivex.Observer; import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable; import io.reactivex.disposables.Disposable;

View file

@ -36,6 +36,7 @@ import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import autodagger.AutoInjector import autodagger.AutoInjector
import com.bluelinelabs.logansquare.LoganSquare
import com.nextcloud.talk.R import com.nextcloud.talk.R
import com.nextcloud.talk.adapters.PredefinedStatusClickListener import com.nextcloud.talk.adapters.PredefinedStatusClickListener
import com.nextcloud.talk.adapters.PredefinedStatusListAdapter import com.nextcloud.talk.adapters.PredefinedStatusListAdapter
@ -45,9 +46,10 @@ import com.nextcloud.talk.databinding.DialogSetStatusBinding
import com.nextcloud.talk.models.database.User import com.nextcloud.talk.models.database.User
import com.nextcloud.talk.models.json.generic.GenericOverall import com.nextcloud.talk.models.json.generic.GenericOverall
import com.nextcloud.talk.models.json.status.ClearAt import com.nextcloud.talk.models.json.status.ClearAt
import com.nextcloud.talk.models.json.status.PredefinedStatus
import com.nextcloud.talk.models.json.status.Status import com.nextcloud.talk.models.json.status.Status
import com.nextcloud.talk.models.json.status.StatusType import com.nextcloud.talk.models.json.status.StatusType
import com.nextcloud.talk.models.json.status.predefined.PredefinedStatus
import com.nextcloud.talk.models.json.status.predefined.PredefinedStatusOverall
import com.nextcloud.talk.utils.ApiUtils import com.nextcloud.talk.utils.ApiUtils
import com.nextcloud.talk.utils.DisplayUtils import com.nextcloud.talk.utils.DisplayUtils
import com.vanniktech.emoji.EmojiPopup import com.vanniktech.emoji.EmojiPopup
@ -55,6 +57,7 @@ import io.reactivex.Observer
import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers import io.reactivex.schedulers.Schedulers
import okhttp3.ResponseBody
import java.util.Calendar import java.util.Calendar
import java.util.Locale import java.util.Locale
import javax.inject.Inject import javax.inject.Inject
@ -88,13 +91,16 @@ class SetStatusDialogFragment :
private var currentUser: User? = null private var currentUser: User? = null
private var currentStatus: Status? = null private var currentStatus: Status? = null
// private lateinit var accountManager: UserAccountManager // private lateinit var accountManager: UserAccountManager
private lateinit var predefinedStatus: ArrayList<PredefinedStatus> // private lateinit var predefinedStatus: ArrayList<PredefinedStatus>
val predefinedStatusesList = ArrayList<PredefinedStatus>()
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? = -1
private lateinit var popup: EmojiPopup private lateinit var popup: EmojiPopup
//
// @Inject // @Inject
// lateinit var arbitraryDataProvider: ArbitraryDataProvider // lateinit var arbitraryDataProvider: ArbitraryDataProvider
// //
@ -109,19 +115,36 @@ class SetStatusDialogFragment :
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this)
arguments?.let { arguments?.let {
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 json = arbitraryDataProvider.getValue(currentUser, ArbitraryDataProvider.PREDEFINED_STATUS) val credentials = ApiUtils.getCredentials(currentUser?.username, currentUser?.token)
ncApi.getPredefinedStatuses(credentials, ApiUtils.getUrlForPredefinedStatuses(currentUser?.baseUrl))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(object : Observer<ResponseBody> {
// if (json.isNotEmpty()) { override fun onSubscribe(d: Disposable) {
// val myType = object : TypeToken<ArrayList<PredefinedStatus>>() {}.type
// predefinedStatus = Gson().fromJson(json, myType)
// }
} }
override fun onNext(responseBody: ResponseBody) {
val predefinedStatusOverall : PredefinedStatusOverall = LoganSquare.parse(responseBody
.string(),
PredefinedStatusOverall::class.java)
predefinedStatusesList.addAll(predefinedStatusOverall.getOcs().data)
}
override fun onError(e: Throwable) {
}
override fun onComplete() {}
})
}
// EmojiManager.install(GoogleEmojiProvider()) // EmojiManager.install(GoogleEmojiProvider())
} }
@ -166,9 +189,10 @@ class SetStatusDialogFragment :
} }
adapter = PredefinedStatusListAdapter(this, requireContext()) adapter = PredefinedStatusListAdapter(this, requireContext())
if (this::predefinedStatus.isInitialized) {
adapter.list = predefinedStatus adapter.list = predefinedStatusesList
}
binding.predefinedStatusList.adapter = adapter binding.predefinedStatusList.adapter = adapter
binding.predefinedStatusList.layoutManager = LinearLayoutManager(context) binding.predefinedStatusList.layoutManager = LinearLayoutManager(context)

View file

@ -425,7 +425,13 @@ public class ApiUtils {
return baseUrl + ocsApiVersion + "/apps/user_status/api/v1/user_status"; return baseUrl + ocsApiVersion + "/apps/user_status/api/v1/user_status";
} }
public static String getUrlForPredefinedStatuses(String baseUrl) {
return baseUrl + ocsApiVersion + "/apps/user_status/api/v1/predefined_statuses";
}
public static String getUrlForStatusMessage(String baseUrl) { public static String getUrlForStatusMessage(String baseUrl) {
return getUrlForStatus(baseUrl) + "/message"; return getUrlForStatus(baseUrl) + "/message";
} }
} }