mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-21 12:39:58 +01:00
show user statuses in conversation list
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
e27ede75ff
commit
6057306ab3
@ -46,6 +46,8 @@ import com.nextcloud.talk.models.database.CapabilitiesUtil;
|
||||
import com.nextcloud.talk.models.database.UserEntity;
|
||||
import com.nextcloud.talk.models.json.chat.ChatMessage;
|
||||
import com.nextcloud.talk.models.json.conversations.Conversation;
|
||||
import com.nextcloud.talk.models.json.status.Status;
|
||||
import com.nextcloud.talk.models.json.status.StatusType;
|
||||
import com.nextcloud.talk.utils.ApiUtils;
|
||||
import com.nextcloud.talk.utils.DisplayUtils;
|
||||
|
||||
@ -73,19 +75,22 @@ public class ConversationItem extends AbstractFlexibleItem<ConversationItem.Conv
|
||||
private UserEntity userEntity;
|
||||
private Context context;
|
||||
private GenericTextHeaderItem header;
|
||||
private Status status;
|
||||
|
||||
public ConversationItem(Conversation conversation, UserEntity userEntity, Context activityContext) {
|
||||
public ConversationItem(Conversation conversation, UserEntity userEntity, Context activityContext, Status status) {
|
||||
this.conversation = conversation;
|
||||
this.userEntity = userEntity;
|
||||
this.context = activityContext;
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public ConversationItem(Conversation conversation, UserEntity userEntity,
|
||||
Context activityContext, GenericTextHeaderItem genericTextHeaderItem) {
|
||||
Context activityContext, GenericTextHeaderItem genericTextHeaderItem, Status status) {
|
||||
this.conversation = conversation;
|
||||
this.userEntity = userEntity;
|
||||
this.context = activityContext;
|
||||
this.header = genericTextHeaderItem;
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -159,7 +164,7 @@ public class ConversationItem extends AbstractFlexibleItem<ConversationItem.Conv
|
||||
holder.dialogUnreadBubble.setChipBackgroundColorResource(R.color.colorPrimary);
|
||||
holder.dialogUnreadBubble.setTextColor(Color.WHITE);
|
||||
} else if (conversation.isUnreadMention()) {
|
||||
if (CapabilitiesUtil.hasSpreedFeatureCapability(userEntity, "direct-mention-flag")){
|
||||
if (CapabilitiesUtil.hasSpreedFeatureCapability(userEntity, "direct-mention-flag")) {
|
||||
if (conversation.getUnreadMentionDirect()) {
|
||||
holder.dialogUnreadBubble.setChipBackgroundColorResource(R.color.colorPrimary);
|
||||
holder.dialogUnreadBubble.setTextColor(Color.WHITE);
|
||||
@ -192,6 +197,21 @@ public class ConversationItem extends AbstractFlexibleItem<ConversationItem.Conv
|
||||
holder.pinnedConversationImageView.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if (status != null && status.getStatus().equals(StatusType.DND.getString())) {
|
||||
setOnlineStateIcon(holder, R.drawable.ic_user_status_dnd_with_border);
|
||||
} else if (status != null && status.getIcon() != null && !status.getIcon().isEmpty()) {
|
||||
holder.userStatusOnlineState.setVisibility(View.GONE);
|
||||
holder.userStatusEmoji.setVisibility(View.VISIBLE);
|
||||
holder.userStatusEmoji.setText(status.getIcon());
|
||||
} else if (status != null && status.getStatus().equals(StatusType.AWAY.getString())) {
|
||||
setOnlineStateIcon(holder, R.drawable.ic_user_status_away_with_border);
|
||||
} else if (status != null && status.getStatus().equals(StatusType.ONLINE.getString())) {
|
||||
setOnlineStateIcon(holder, R.drawable.online_status_with_border);
|
||||
} else {
|
||||
holder.userStatusEmoji.setVisibility(View.GONE);
|
||||
holder.userStatusOnlineState.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if (conversation.getLastMessage() != null) {
|
||||
holder.dialogDate.setVisibility(View.VISIBLE);
|
||||
holder.dialogDate.setText(DateUtils.getRelativeTimeSpanString(conversation.getLastActivity() * 1000L,
|
||||
@ -289,6 +309,12 @@ public class ConversationItem extends AbstractFlexibleItem<ConversationItem.Conv
|
||||
}
|
||||
}
|
||||
|
||||
private void setOnlineStateIcon(ConversationItemViewHolder holder, int icon) {
|
||||
holder.userStatusEmoji.setVisibility(View.GONE);
|
||||
holder.userStatusOnlineState.setVisibility(View.VISIBLE);
|
||||
holder.userStatusOnlineState.setImageDrawable(ContextCompat.getDrawable(context, icon));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean filter(String constraint) {
|
||||
return conversation.getDisplayName() != null &&
|
||||
@ -318,6 +344,11 @@ public class ConversationItem extends AbstractFlexibleItem<ConversationItem.Conv
|
||||
Chip dialogUnreadBubble;
|
||||
@BindView(R.id.favoriteConversationImageView)
|
||||
ImageView pinnedConversationImageView;
|
||||
@BindView(R.id.userStatusEmoji)
|
||||
com.vanniktech.emoji.EmojiEditText userStatusEmoji;
|
||||
@BindView(R.id.userStatusOnlineState)
|
||||
ImageView userStatusOnlineState;
|
||||
|
||||
|
||||
ConversationItemViewHolder(View view, FlexibleAdapter adapter) {
|
||||
super(view, adapter);
|
||||
|
@ -41,6 +41,7 @@ import com.nextcloud.talk.models.json.search.ContactsByNumberOverall;
|
||||
import com.nextcloud.talk.models.json.signaling.SignalingOverall;
|
||||
import com.nextcloud.talk.models.json.signaling.settings.SignalingSettingsOverall;
|
||||
import com.nextcloud.talk.models.json.status.StatusOverall;
|
||||
import com.nextcloud.talk.models.json.statuses.StatusesOverall;
|
||||
import com.nextcloud.talk.models.json.userprofile.UserProfileFieldsOverall;
|
||||
import com.nextcloud.talk.models.json.userprofile.UserProfileOverall;
|
||||
|
||||
@ -478,4 +479,8 @@ public interface NcApi {
|
||||
Observable<GenericOverall> setStatusType(@Header("Authorization") String authorization,
|
||||
@Url String url,
|
||||
@Field("statusType") String statusType);
|
||||
|
||||
@GET
|
||||
Observable<StatusesOverall> getUserStatuses(@Header("Authorization") String authorization, @Url String url);
|
||||
|
||||
}
|
||||
|
@ -81,6 +81,8 @@ import com.nextcloud.talk.jobs.UploadAndShareFilesWorker;
|
||||
import com.nextcloud.talk.models.database.CapabilitiesUtil;
|
||||
import com.nextcloud.talk.models.database.UserEntity;
|
||||
import com.nextcloud.talk.models.json.conversations.Conversation;
|
||||
import com.nextcloud.talk.models.json.status.Status;
|
||||
import com.nextcloud.talk.models.json.statuses.StatusesOverall;
|
||||
import com.nextcloud.talk.ui.dialog.ChooseAccountDialogFragment;
|
||||
import com.nextcloud.talk.ui.dialog.ConversationsListBottomDialog;
|
||||
import com.nextcloud.talk.utils.ApiUtils;
|
||||
@ -128,6 +130,7 @@ import butterknife.BindView;
|
||||
import eu.davidea.flexibleadapter.FlexibleAdapter;
|
||||
import eu.davidea.flexibleadapter.common.SmoothScrollLinearLayoutManager;
|
||||
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem;
|
||||
import io.reactivex.Observer;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
@ -214,6 +217,8 @@ public class ConversationsListController extends BaseController implements Searc
|
||||
|
||||
private ConversationsListBottomDialog conversationsListBottomDialog;
|
||||
|
||||
private HashMap<String, Status> userStatuses = new HashMap<>();
|
||||
|
||||
public ConversationsListController(Bundle bundle) {
|
||||
super();
|
||||
setHasOptionsMenu(true);
|
||||
@ -467,6 +472,37 @@ public class ConversationsListController extends BaseController implements Searc
|
||||
|
||||
@SuppressLint("LongLogTag")
|
||||
public void fetchData() {
|
||||
fetchUserStatuses();
|
||||
}
|
||||
|
||||
private void fetchUserStatuses() {
|
||||
ncApi.getUserStatuses(credentials, ApiUtils.getUrlForUserStatuses(currentUser.getBaseUrl()))
|
||||
.subscribe(new Observer<StatusesOverall>() {
|
||||
@Override
|
||||
public void onSubscribe(@io.reactivex.annotations.NonNull Disposable d) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull StatusesOverall statusesOverall) {
|
||||
for (Status status : statusesOverall.getOcs().getData()) {
|
||||
userStatuses.put(status.getUserId(), status);
|
||||
}
|
||||
fetchRooms();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@io.reactivex.annotations.NonNull Throwable e) {
|
||||
Log.e(TAG, "failed to fetch user statuses", e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void fetchRooms() {
|
||||
dispose(null);
|
||||
|
||||
isRefreshing = true;
|
||||
@ -525,14 +561,16 @@ public class ConversationsListController extends BaseController implements Searc
|
||||
ConversationItem conversationItem = new ConversationItem(
|
||||
conversation,
|
||||
currentUser,
|
||||
getActivity());
|
||||
getActivity(),
|
||||
userStatuses.get(conversation.name));
|
||||
conversationItems.add(conversationItem);
|
||||
|
||||
ConversationItem conversationItemWithHeader = new ConversationItem(
|
||||
conversation,
|
||||
currentUser,
|
||||
getActivity(),
|
||||
callHeaderItems.get(headerTitle));
|
||||
callHeaderItems.get(headerTitle),
|
||||
userStatuses.get(conversation.name));
|
||||
conversationItemsWithHeader.add(conversationItemWithHeader);
|
||||
}
|
||||
}
|
||||
@ -604,7 +642,8 @@ public class ConversationsListController extends BaseController implements Searc
|
||||
conversation,
|
||||
currentUser,
|
||||
getActivity(),
|
||||
callHeaderItems.get(headerTitle));
|
||||
callHeaderItems.get(headerTitle),
|
||||
userStatuses.get(conversation.name));
|
||||
|
||||
openConversationItems.add(conversationItem);
|
||||
}
|
||||
|
@ -0,0 +1,71 @@
|
||||
/*
|
||||
*
|
||||
* 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.statuses;
|
||||
|
||||
import com.bluelinelabs.logansquare.annotation.JsonField;
|
||||
import com.bluelinelabs.logansquare.annotation.JsonObject;
|
||||
import com.nextcloud.talk.models.json.generic.GenericOCS;
|
||||
import com.nextcloud.talk.models.json.status.Status;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@JsonObject
|
||||
public class StatusesOCS extends GenericOCS {
|
||||
@JsonField(name = "data")
|
||||
public List<Status> data;
|
||||
|
||||
public List<Status> getData() {
|
||||
return this.data;
|
||||
}
|
||||
|
||||
public void setData(List<Status> 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;
|
||||
}
|
||||
StatusesOCS that = (StatusesOCS) o;
|
||||
return Objects.equals(data, that.data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(super.hashCode(), data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "StatusesOCS{" +
|
||||
"data=" + data +
|
||||
'}';
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
/*
|
||||
*
|
||||
* 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.statuses;
|
||||
|
||||
import com.bluelinelabs.logansquare.annotation.JsonField;
|
||||
import com.bluelinelabs.logansquare.annotation.JsonObject;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@JsonObject
|
||||
public class StatusesOverall {
|
||||
@JsonField(name = "ocs")
|
||||
public StatusesOCS ocs;
|
||||
|
||||
public StatusesOCS getOcs() {
|
||||
return this.ocs;
|
||||
}
|
||||
|
||||
public void setOcs(StatusesOCS ocs) {
|
||||
this.ocs = ocs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
StatusesOverall that = (StatusesOverall) o;
|
||||
return Objects.equals(ocs, that.ocs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(ocs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "StatusesOverall{" +
|
||||
"ocs=" + ocs +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -440,4 +440,8 @@ public class ApiUtils {
|
||||
public static String getUrlForSetCustomStatus(String baseUrl) {
|
||||
return baseUrl + ocsApiVersion + "/apps/user_status/api/v1/user_status/message/custom";
|
||||
}
|
||||
|
||||
public static String getUrlForUserStatuses(String baseUrl) {
|
||||
return baseUrl + ocsApiVersion + "/apps/user_status/api/v1/statuses";
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,43 @@
|
||||
<!--
|
||||
Nextcloud Android client application
|
||||
|
||||
@author Tobias Kaminsky
|
||||
Copyright (C) 2020 Tobias Kaminsky
|
||||
Copyright (C) 2020 Nextcloud GmbH
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3 of the License, or 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 AFFERO GENERAL PUBLIC LICENSE for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public
|
||||
License along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<vector xmlns:tools="http://schemas.android.com/tools"
|
||||
android:autoMirrored="true"
|
||||
android:height="24dp"
|
||||
android:viewportHeight="24"
|
||||
android:viewportWidth="24"
|
||||
android:width="24dp"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
tools:ignore="VectorRaster">
|
||||
|
||||
<path
|
||||
android:fillColor="@color/bg_default"
|
||||
android:pathData="m12,2c-5.52,0 -10,4.48 -10,10s4.48,10 10,10 10,-4.48 10,-10 -4.48,-10 -10,-10z"
|
||||
android:strokeWidth="4"
|
||||
android:strokeColor="@color/bg_default"/>
|
||||
|
||||
<path
|
||||
android:fillColor="@color/bg_default"
|
||||
android:pathData="m12,2c-5.52,0 -10,4.48 -10,10s4.48,10 10,10 10,-4.48 10,-10 -4.48,-10 -10,-10z" />
|
||||
|
||||
<path
|
||||
android:fillColor="#f4a331"
|
||||
android:pathData="m10.615,2.1094c-4.8491,0.6811 -8.6152,4.8615 -8.6152,9.8906 0,5.5 4.5,10 10,10 5.0292,0 9.2096,-3.7661 9.8906,-8.6152 -1.4654,1.601 -3.5625,2.6152 -5.8906,2.6152 -4.4,0 -8,-3.6 -8,-8 0,-2.3281 1.0143,-4.4252 2.6152,-5.8906z" />
|
||||
</vector>
|
41
app/src/main/res/drawable/ic_user_status_dnd_with_border.xml
Normal file
41
app/src/main/res/drawable/ic_user_status_dnd_with_border.xml
Normal file
@ -0,0 +1,41 @@
|
||||
<!--
|
||||
Nextcloud Android client application
|
||||
|
||||
@author Tobias Kaminsky
|
||||
Copyright (C) 2020 Tobias Kaminsky
|
||||
Copyright (C) 2020 Nextcloud GmbH
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3 of the License, or 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 AFFERO GENERAL PUBLIC LICENSE for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public
|
||||
License along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<vector xmlns:tools="http://schemas.android.com/tools"
|
||||
android:autoMirrored="true"
|
||||
android:height="24dp"
|
||||
android:viewportHeight="24"
|
||||
android:viewportWidth="24"
|
||||
android:width="24dp"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
tools:ignore="VectorRaster">
|
||||
<path
|
||||
android:fillColor="#ed484c"
|
||||
android:pathData="m12,2c-5.52,0 -10,4.48 -10,10s4.48,10 10,10 10,-4.48 10,-10 -4.48,-10 -10,-10z"
|
||||
android:strokeWidth="2"
|
||||
android:strokeColor="@color/bg_default"/>
|
||||
|
||||
<path
|
||||
android:fillColor="#fdffff"
|
||||
android:pathData="m8,10h8c1.108,0 2,0.892 2,2s-0.892,2 -2,2h-8c-1.108,0 -2,-0.892 -2,-2s0.892,-2 2,-2z"
|
||||
android:strokeLineCap="round"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="2" />
|
||||
</vector>
|
26
app/src/main/res/drawable/online_status_with_border.xml
Normal file
26
app/src/main/res/drawable/online_status_with_border.xml
Normal file
@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
Nextcloud Android client application
|
||||
|
||||
@author Andy Scherzinger
|
||||
Copyright (C) 2019 Andy Scherzinger
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="oval">
|
||||
<solid android:color="#00ff00" />
|
||||
|
||||
<stroke android:width="1.3dp"
|
||||
android:color="@color/bg_default"/>
|
||||
</shape>
|
@ -56,6 +56,24 @@
|
||||
app:tint="@color/favorite_icon_tint"
|
||||
app:tintMode="src_in" />
|
||||
|
||||
<com.vanniktech.emoji.EmojiEditText
|
||||
android:id="@+id/userStatusEmoji"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:background="@color/transparent"
|
||||
android:cursorVisible="false"
|
||||
android:gravity="center"
|
||||
android:text="@string/default_emoji"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/userStatusOnlineState"
|
||||
android:layout_width="16dp"
|
||||
android:layout_height="16dp"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:contentDescription="@null"
|
||||
android:src="@drawable/online_status"/>
|
||||
</FrameLayout>
|
||||
|
||||
<RelativeLayout
|
||||
|
@ -457,6 +457,7 @@
|
||||
<string name="nc_phone_book_integration_account_not_found">Account not found</string>
|
||||
|
||||
<string name="starred">Favorite</string>
|
||||
<string name="user_status">Status</string>
|
||||
<string name="encrypted">Encrypted</string>
|
||||
<string name="password_protected">Password protected</string>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user