Fix various issues & started working on notification levels

This commit is contained in:
Mario Danic 2018-11-06 22:58:14 +01:00
parent ec2557567c
commit 142ceb12e2
19 changed files with 226 additions and 31 deletions

View File

@ -38,12 +38,12 @@ import eu.davidea.flexibleadapter.items.IFilterable;
import eu.davidea.flexibleadapter.items.IFlexible;
import eu.davidea.viewholders.FlexibleViewHolder;
public class UserHeaderItem extends AbstractHeaderItem<UserHeaderItem.HeaderViewHolder> implements IFilterable<String> {
private static final String TAG = "UserHeaderItem";
public class GenericTextHeaderItem extends AbstractHeaderItem<GenericTextHeaderItem.HeaderViewHolder> implements IFilterable<String> {
private static final String TAG = "GenericTextHeaderItem";
private String title;
public UserHeaderItem(String title) {
public GenericTextHeaderItem(String title) {
super();
setHidden(false);
setSelectable(false);
@ -61,8 +61,8 @@ public class UserHeaderItem extends AbstractHeaderItem<UserHeaderItem.HeaderView
@Override
public boolean equals(Object o) {
if (o instanceof UserHeaderItem) {
UserHeaderItem inItem = (UserHeaderItem) o;
if (o instanceof GenericTextHeaderItem) {
GenericTextHeaderItem inItem = (GenericTextHeaderItem) o;
return title.equals(inItem.getModel());
}
return false;

View File

@ -53,19 +53,19 @@ import eu.davidea.flipview.FlipView;
import eu.davidea.viewholders.FlexibleViewHolder;
public class UserItem extends AbstractFlexibleItem<UserItem.UserItemViewHolder> implements
ISectionable<UserItem.UserItemViewHolder, UserHeaderItem>, IFilterable<String> {
ISectionable<UserItem.UserItemViewHolder, GenericTextHeaderItem>, IFilterable<String> {
private Participant participant;
private UserEntity userEntity;
private UserHeaderItem header;
private GenericTextHeaderItem header;
private FlipView flipView;
public UserItem(Participant participant, UserEntity userEntity, UserHeaderItem userHeaderItem) {
public UserItem(Participant participant, UserEntity userEntity, GenericTextHeaderItem genericTextHeaderItem) {
this.participant = participant;
this.userEntity = userEntity;
this.header = userHeaderItem;
this.header = genericTextHeaderItem;
}
@Override
@ -168,12 +168,12 @@ public class UserItem extends AbstractFlexibleItem<UserItem.UserItemViewHolder>
}
@Override
public UserHeaderItem getHeader() {
public GenericTextHeaderItem getHeader() {
return header;
}
@Override
public void setHeader(UserHeaderItem header) {
public void setHeader(GenericTextHeaderItem header) {
this.header = header;
}

View File

@ -308,4 +308,8 @@ public interface NcApi {
@GET
Observable<NotificationOverall> getNotification(@Header("Authorization") String authorization,
@Url String url);
@FormUrlEncoded
@POST
Observable<GenericOverall> setNotificationLevel(@Header("Authorization") String authorization, @Url String url, @Field("level") int level);
}

View File

@ -32,7 +32,6 @@ import com.nextcloud.talk.jobs.AccountRemovalWorker;
import com.nextcloud.talk.jobs.CapabilitiesWorker;
import com.nextcloud.talk.jobs.PushRegistrationWorker;
import com.nextcloud.talk.jobs.SignalingSettingsJob;
import com.nextcloud.talk.models.database.UserEntity;
import com.nextcloud.talk.utils.ClosedInterfaceImpl;
import com.nextcloud.talk.utils.DeviceUtils;
import com.nextcloud.talk.utils.DisplayUtils;

View File

@ -365,7 +365,7 @@ public class AccountVerificationController extends BaseController {
fetchAndStoreExternalSignalingSettings();
}
} else if (eventStatus.getEventType().equals(EventStatus.EventType.SIGNALING_SETTINGS)) {
if (eventStatus.isAllGood()) {
if (internalAccountId == eventStatus.getUserId() && !eventStatus.isAllGood()) {
if (getActivity() != null) {
getActivity().runOnUiThread(() -> progressText.setText(progressText.getText().toString() + "\n" +
getResources().getString(R.string.nc_external_server_failed)));

View File

@ -133,7 +133,6 @@ import butterknife.OnLongClick;
import eu.davidea.flipview.FlipView;
import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.Scheduler;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

View File

@ -49,6 +49,8 @@ import android.widget.RelativeLayout;
import android.widget.TextView;
import com.amulyakhare.textdrawable.TextDrawable;
import com.bluelinelabs.conductor.RouterTransaction;
import com.bluelinelabs.conductor.changehandler.VerticalChangeHandler;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.engine.GlideException;
@ -229,6 +231,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
@Override
public void onNext(RoomOverall roomOverall) {
conversationName = roomOverall.getOcs().getData().getDisplayName();
setTitle();
@ -966,6 +969,12 @@ public class ChatController extends BaseController implements MessagesListAdapte
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.menu_conversation, menu);
if (!conversationUser.hasSpreedCapabilityWithName("notification-levels")) {
menu.findItem(R.id.nc_conversation_info).setVisible(true);
} else {
menu.findItem(R.id.nc_conversation_info).setVisible(false);
}
}
@ -981,7 +990,15 @@ public class ChatController extends BaseController implements MessagesListAdapte
case R.id.conversation_voice_call:
startACall(true);
return true;
case R.id.nc_conversation_info:
Bundle bundle = new Bundle();
bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, Parcels.wrap(conversationUser));
bundle.putString(BundleKeys.KEY_BASE_URL, baseUrl);
bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomToken);
/*getRouter().pushController((RouterTransaction.with(new ConversationInfoController(bundle))
.pushChangeHandler(new VerticalChangeHandler())
.popChangeHandler(new VerticalChangeHandler())));*/
return true;
default:
return super.onOptionsItemSelected(item);
}

View File

@ -46,8 +46,8 @@ import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.kennyc.bottomsheet.BottomSheet;
import com.nextcloud.talk.R;
import com.nextcloud.talk.activities.MagicCallActivity;
import com.nextcloud.talk.adapters.items.GenericTextHeaderItem;
import com.nextcloud.talk.adapters.items.ProgressItem;
import com.nextcloud.talk.adapters.items.UserHeaderItem;
import com.nextcloud.talk.adapters.items.UserItem;
import com.nextcloud.talk.api.NcApi;
import com.nextcloud.talk.application.NextcloudTalkApplication;
@ -154,7 +154,7 @@ public class ContactsController extends BaseController implements SearchView.OnQ
private boolean isNewConversationView;
private boolean isPublicCall;
private HashMap<String, UserHeaderItem> userHeaderItems = new HashMap<>();
private HashMap<String, GenericTextHeaderItem> userHeaderItems = new HashMap<>();
private boolean alreadyFetching = false;
private boolean canFetchFurther = true;
@ -473,6 +473,9 @@ public class ContactsController extends BaseController implements SearchView.OnQ
shareTypesList.add("0");
// groups
shareTypesList.add("1");
// mails
//shareTypesList.add("4");
modifiedQueryMap.put("shareTypes[]", shareTypesList);
}
@ -520,10 +523,10 @@ public class ContactsController extends BaseController implements SearchView.OnQ
headerTitle = sharee.getLabel().substring(0, 1).toUpperCase();
UserHeaderItem userHeaderItem;
GenericTextHeaderItem genericTextHeaderItem;
if (!userHeaderItems.containsKey(headerTitle)) {
userHeaderItem = new UserHeaderItem(headerTitle);
userHeaderItems.put(headerTitle, userHeaderItem);
genericTextHeaderItem = new GenericTextHeaderItem(headerTitle);
userHeaderItems.put(headerTitle, genericTextHeaderItem);
}
participant.setUserId(sharee.getValue().getShareWith());
@ -554,10 +557,10 @@ public class ContactsController extends BaseController implements SearchView.OnQ
headerTitle = participant.getName().substring(0, 1).toUpperCase();
UserHeaderItem userHeaderItem;
GenericTextHeaderItem genericTextHeaderItem;
if (!userHeaderItems.containsKey(headerTitle)) {
userHeaderItem = new UserHeaderItem(headerTitle);
userHeaderItems.put(headerTitle, userHeaderItem);
genericTextHeaderItem = new GenericTextHeaderItem(headerTitle);
userHeaderItems.put(headerTitle, genericTextHeaderItem);
}
participant.setUserId(participant.getUserId());
@ -600,13 +603,13 @@ public class ContactsController extends BaseController implements SearchView.OnQ
if (o1 instanceof UserItem) {
firstName = ((UserItem) o1).getModel().getName();
} else {
firstName = ((UserHeaderItem) o1).getModel();
firstName = ((GenericTextHeaderItem) o1).getModel();
}
if (o2 instanceof UserItem) {
secondName = ((UserItem) o2).getModel().getName();
} else {
secondName = ((UserHeaderItem) o2).getModel();
secondName = ((GenericTextHeaderItem) o2).getModel();
}
return firstName.compareToIgnoreCase(secondName);
@ -695,8 +698,8 @@ public class ContactsController extends BaseController implements SearchView.OnQ
IFlexible abstractFlexibleItem = adapter.getItem(position);
if (abstractFlexibleItem instanceof UserItem) {
return ((UserItem) adapter.getItem(position)).getHeader().getModel();
} else if (abstractFlexibleItem instanceof UserHeaderItem) {
return ((UserHeaderItem) adapter.getItem(position)).getModel();
} else if (abstractFlexibleItem instanceof GenericTextHeaderItem) {
return ((GenericTextHeaderItem) adapter.getItem(position)).getModel();
} else {
return "";
}

View File

@ -26,7 +26,6 @@ import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

View File

@ -134,6 +134,8 @@ public class SignalingSettingsJob extends Worker {
} catch (IOException e) {
Log.e(TAG, "Failed to serialize external signaling server");
}
} else {
eventBus.post(new EventStatus(finalUserEntity.getId(), EventStatus.EventType.SIGNALING_SETTINGS, true));
}
}

View File

@ -0,0 +1,59 @@
/*
* Nextcloud Talk application
*
* @author Mario Danic
* Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
*
* 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.converters;
import com.bluelinelabs.logansquare.typeconverters.IntBasedTypeConverter;
import com.nextcloud.talk.models.json.rooms.Conversation;
public class EnumNotificationLevelConverter extends IntBasedTypeConverter<Conversation.NotificationLevel> {
@Override
public Conversation.NotificationLevel getFromInt(int i) {
switch (i) {
case 0:
return Conversation.NotificationLevel.DEFAULT;
case 1:
return Conversation.NotificationLevel.ALWAYS;
case 2:
return Conversation.NotificationLevel.MENTION;
case 3:
return Conversation.NotificationLevel.NEVER;
default:
return Conversation.NotificationLevel.DEFAULT;
}
}
@Override
public int convertToInt(Conversation.NotificationLevel object) {
switch (object) {
case DEFAULT:
return 0;
case ALWAYS:
return 1;
case MENTION:
return 2;
case NEVER:
return 3;
default:
return 0;
}
}
}

View File

@ -23,6 +23,7 @@ package com.nextcloud.talk.models.json.rooms;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import com.nextcloud.talk.models.json.chat.ChatMessage;
import com.nextcloud.talk.models.json.converters.EnumNotificationLevelConverter;
import com.nextcloud.talk.models.json.converters.EnumParticipantTypeConverter;
import com.nextcloud.talk.models.json.converters.EnumRoomTypeConverter;
import com.nextcloud.talk.models.json.participants.Participant;
@ -76,6 +77,15 @@ public class Conversation {
public ChatMessage lastMessage;
@JsonField(name = "objectType")
String objectType;
@JsonField(name = "notificationLevel", typeConverter = EnumNotificationLevelConverter.class)
NotificationLevel notificationLevel;
public enum NotificationLevel {
DEFAULT,
ALWAYS,
MENTION,
NEVER
}
public boolean isPublic() {
return (RoomType.ROOM_PUBLIC_CALL.equals(type));

View File

@ -66,11 +66,16 @@ public class ApiUtils {
retrofitBucket.setUrl(baseUrl + ocsApiVersion + "/core/autocomplete/get");
retrofitBucket.getQueryMap().put("itemId", "new");
retrofitBucket.getQueryMap().put("limit", "10000");
return retrofitBucket;
}
public static String getUrlForSettingNotificationlevel(String baseUrl, String token) {
return getRoom(baseUrl, token) + "/notify";
}
public static String getUrlForSettingMyselfAsActiveParticipant(String baseUrl, String token) {
return getRoom(baseUrl, token) + "/participants/active";
}

View File

@ -24,6 +24,7 @@ import android.text.TextUtils;
import android.util.Log;
import com.bluelinelabs.logansquare.LoganSquare;
import com.nextcloud.talk.R;
import com.nextcloud.talk.application.NextcloudTalkApplication;
import com.nextcloud.talk.events.WebSocketCommunicationEvent;
import com.nextcloud.talk.models.database.UserEntity;
@ -37,8 +38,6 @@ import com.nextcloud.talk.models.json.websocket.HelloResponseOverallWebSocketMes
import com.nextcloud.talk.models.json.websocket.JoinedRoomOverallWebSocketMessage;
import com.nextcloud.talk.utils.MagicMap;
import com.nextcloud.talk.R;
import org.greenrobot.eventbus.EventBus;
import java.io.IOException;

View File

@ -0,0 +1,25 @@
<!--
~ Nextcloud Talk application
~
~ @author Mario Danic
~ Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
~
~ 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/>.
-->
<vector android:autoMirrored="true" android:height="24dp"
android:tint="#FFFFFF" android:viewportHeight="24.0"
android:viewportWidth="24.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM13,17h-2v-6h2v6zM13,9h-2L11,7h2v2z"/>
</vector>

View File

@ -0,0 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Nextcloud Talk application
~
~ @author Mario Danic
~ Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
~
~ 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/>.
-->
<com.yarolegovich.mp.MaterialPreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:apc="http://schemas.android.com/apk/res-auto"
android:id="@+id/settings_screen"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.yarolegovich.mp.MaterialPreferenceCategory
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
apc:mpc_title="@string/nc_notification_settings"
apc:mpc_title_color="@color/colorPrimary">
<com.yarolegovich.mp.MaterialChoicePreference
android:id="@+id/conversation_info_message_notifications"
android:layout_width="match_parent"
android:layout_height="wrap_content"
apc:mp_entry_descriptions="@array/message_notification_levels"
apc:mp_show_value="onBottom"
apc:mp_title="@string/nc_plain_old_messages">
</com.yarolegovich.mp.MaterialChoicePreference>
<com.yarolegovich.mp.MaterialSwitchPreference
android:id="@+id/conversation_info_mute_calls"
android:layout_width="match_parent"
android:layout_height="wrap_content"
apc:mp_title="@string/nc_mute_calls"
apc:mp_default_value="true"/>
</com.yarolegovich.mp.MaterialPreferenceCategory>
</com.yarolegovich.mp.MaterialPreferenceScreen>

View File

@ -32,5 +32,12 @@
android:id="@+id/conversation_video_call"
android:icon="@drawable/ic_videocam_white_24px"
android:title="@string/nc_conversation_menu_video_call"
app:showAsAction="always"/>
app:showAsAction="ifRoom"/>
<item
android:id="@+id/nc_conversation_info"
android:icon="@drawable/ic_info_black_24dp"
android:title="@string/nc_conversation_menu_conversation_info"
app:showAsAction="ifRoom"
android:visible="false"/>
</menu>

View File

@ -26,4 +26,10 @@
<item>DIRECT</item>
<item>SOCKS</item>
</array>
<array name="message_notification_levels">
<item>@string/nc_notify_me_never</item>
<item>@string/nc_notify_me_mention</item>
<item>@string/nc_notify_me_always</item>
</array>
</resources>

View File

@ -155,6 +155,12 @@
<string name="nc_notification_channel_messages">Messages notification channel</string>
<string name="nc_notification_channel_calls_description">Shows incoming calls</string>
<string name="nc_notification_channel_messages_description">Shows incoming messages</string>
<string name="nc_notification_settings">Notification settings</string>
<string name="nc_plain_old_messages">Messages</string>
<string name="nc_notify_me_always">Always</string>
<string name="nc_notify_me_mention">When mentioned</string>
<string name="nc_notify_me_never">Never</string>
<string name="nc_mute_calls">Mute calls</string>
<!-- Bottom sheet menu -->
<string name="nc_failed_to_perform_operation">Sorry, something went wrong!</string>
@ -208,6 +214,7 @@ Find Nextcloud on https://nextcloud.com</string>
<string name="nc_date_header_today">Today</string>
<string name="nc_conversation_menu_voice_call">Voice call</string>
<string name="nc_conversation_menu_video_call">Video call</string>
<string name="nc_conversation_menu_conversation_info">Conversation info</string>
<string name="nc_new_messages">New messages</string>
<string name="nc_no_messages_yet">No messages yet</string>
<string name="nc_chat_you">You</string>