Skip to content

Commit

Permalink
add predefined statuses
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Hibbe <[email protected]>
  • Loading branch information
mahibi committed Feb 3, 2022
1 parent 5d4f7d2 commit 04f3ae8
Show file tree
Hide file tree
Showing 12 changed files with 255 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

package com.nextcloud.talk.adapters

import com.nextcloud.talk.models.json.status.PredefinedStatus
import com.nextcloud.talk.models.json.status.predefined.PredefinedStatus

interface PredefinedStatusClickListener {
fun onClick(predefinedStatus: PredefinedStatus)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
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(
private val clickListener: PredefinedStatusClickListener,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import android.content.Context
import androidx.recyclerview.widget.RecyclerView
import com.nextcloud.talk.R
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

private const val ONE_SECOND_IN_MILLIS = 1000
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/com/nextcloud/talk/api/NcApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,9 @@ Observable<GenericOverall> setChatReadMarker(@Header("Authorization") String aut
@GET
Observable<StatusOverall> status(@Header("Authorization") String authorization, @Url String url);

@GET
Observable<ResponseBody> getPredefinedStatuses(@Header("Authorization") String authorization, @Url String url);

@DELETE
Observable<GenericOverall> statusDeleteMessage(@Header("Authorization") String authorization, @Url String url);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
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")
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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)
// }
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
*
* Nextcloud Talk application
*
* @author Tim Krüger
* Copyright (C) 2021 Tim Krüger <[email protected]>
*
* 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 +
'}';
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
*
* Nextcloud Talk application
*
* @author Tim Krüger
* Copyright (C) 2021 Tim Krüger <[email protected]>
*
* 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 +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
import java.net.CookieManager;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import javax.inject.Inject;

Expand All @@ -66,7 +65,6 @@
import autodagger.AutoInjector;
import eu.davidea.flexibleadapter.FlexibleAdapter;
import eu.davidea.flexibleadapter.common.SmoothScrollLinearLayoutManager;
import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.DialogFragment
import androidx.recyclerview.widget.LinearLayoutManager
import autodagger.AutoInjector
import com.bluelinelabs.logansquare.LoganSquare
import com.nextcloud.talk.R
import com.nextcloud.talk.adapters.PredefinedStatusClickListener
import com.nextcloud.talk.adapters.PredefinedStatusListAdapter
Expand All @@ -45,16 +46,18 @@ import com.nextcloud.talk.databinding.DialogSetStatusBinding
import com.nextcloud.talk.models.database.User
import com.nextcloud.talk.models.json.generic.GenericOverall
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.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.DisplayUtils
import com.vanniktech.emoji.EmojiPopup
import io.reactivex.Observer
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
import okhttp3.ResponseBody
import java.util.Calendar
import java.util.Locale
import javax.inject.Inject
Expand Down Expand Up @@ -88,13 +91,16 @@ class SetStatusDialogFragment :

private var currentUser: User? = null
private var currentStatus: Status? = null

// 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 var selectedPredefinedMessageId: String? = null
private var clearAt: Long? = -1
private lateinit var popup: EmojiPopup
//

// @Inject
// lateinit var arbitraryDataProvider: ArbitraryDataProvider
//
Expand All @@ -109,19 +115,36 @@ class SetStatusDialogFragment :

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this)

arguments?.let {
currentUser = it.getParcelable(ARG_CURRENT_USER_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()) {
// val myType = object : TypeToken<ArrayList<PredefinedStatus>>() {}.type
// predefinedStatus = Gson().fromJson(json, myType)
// }
}
override fun onSubscribe(d: Disposable) {
}

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())
}
Expand Down Expand Up @@ -166,9 +189,10 @@ class SetStatusDialogFragment :
}

adapter = PredefinedStatusListAdapter(this, requireContext())
if (this::predefinedStatus.isInitialized) {
adapter.list = predefinedStatus
}

adapter.list = predefinedStatusesList


binding.predefinedStatusList.adapter = adapter
binding.predefinedStatusList.layoutManager = LinearLayoutManager(context)

Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,13 @@ public static String getUrlForStatus(String baseUrl) {
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) {
return getUrlForStatus(baseUrl) + "/message";
}


}

0 comments on commit 04f3ae8

Please sign in to comment.