From e3f43b63eac98b117b2196a158fae152d7ae71fe Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Wed, 7 Nov 2018 02:15:44 +0100 Subject: [PATCH] Fix #325, fix #344 --- .../application/NextcloudTalkApplication.java | 3 + .../talk/controllers/ChatController.java | 4 +- .../ConversationInfoController.java | 202 ++++++++++++++++++ .../talk/dagger/modules/DatabaseModule.java | 2 +- .../talk/jobs/NotificationWorker.java | 74 ++++--- .../models/database/ArbitraryStorage.java | 42 ++++ .../ArbitraryStorageModule.java | 45 ++++ .../ArbitraryStorageUtils.java | 69 ++++++ .../DatabaseStorageFactory.java | 42 ++++ .../DatabaseStorageModule.java | 169 +++++++++++++++ app/src/main/res/layout/conversation_info.xml | 42 ++++ .../res/layout/notification_settings_item.xml | 19 +- app/src/main/res/values/arrays.xml | 7 + app/src/main/res/values/strings.xml | 9 +- 14 files changed, 685 insertions(+), 44 deletions(-) create mode 100644 app/src/main/java/com/nextcloud/talk/controllers/ConversationInfoController.java create mode 100644 app/src/main/java/com/nextcloud/talk/models/database/ArbitraryStorage.java create mode 100644 app/src/main/java/com/nextcloud/talk/utils/database/arbitrarystorage/ArbitraryStorageModule.java create mode 100644 app/src/main/java/com/nextcloud/talk/utils/database/arbitrarystorage/ArbitraryStorageUtils.java create mode 100644 app/src/main/java/com/nextcloud/talk/utils/preferencestorage/DatabaseStorageFactory.java create mode 100644 app/src/main/java/com/nextcloud/talk/utils/preferencestorage/DatabaseStorageModule.java create mode 100644 app/src/main/res/layout/conversation_info.xml diff --git a/app/src/main/java/com/nextcloud/talk/application/NextcloudTalkApplication.java b/app/src/main/java/com/nextcloud/talk/application/NextcloudTalkApplication.java index 067e55ef7..7f2845b40 100644 --- a/app/src/main/java/com/nextcloud/talk/application/NextcloudTalkApplication.java +++ b/app/src/main/java/com/nextcloud/talk/application/NextcloudTalkApplication.java @@ -35,6 +35,7 @@ import com.nextcloud.talk.jobs.SignalingSettingsJob; import com.nextcloud.talk.utils.ClosedInterfaceImpl; import com.nextcloud.talk.utils.DeviceUtils; import com.nextcloud.talk.utils.DisplayUtils; +import com.nextcloud.talk.utils.database.arbitrarystorage.ArbitraryStorageModule; import com.nextcloud.talk.utils.database.user.UserModule; import com.nextcloud.talk.webrtc.MagicWebRTCUtils; @@ -64,6 +65,7 @@ import uk.co.chrisjenx.calligraphy.CalligraphyConfig; DatabaseModule.class, RestModule.class, UserModule.class, + ArbitraryStorageModule.class, } ) @@ -168,6 +170,7 @@ public class NextcloudTalkApplication extends MultiDexApplication implements Lif .databaseModule(new DatabaseModule()) .restModule(new RestModule()) .userModule(new UserModule()) + .arbitraryStorageModule(new ArbitraryStorageModule()) .build(); } diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.java b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.java index 479241d1a..b31bd067a 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.java @@ -995,9 +995,9 @@ public class ChatController extends BaseController implements MessagesListAdapte 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)) + getRouter().pushController((RouterTransaction.with(new ConversationInfoController(bundle)) .pushChangeHandler(new VerticalChangeHandler()) - .popChangeHandler(new VerticalChangeHandler())));*/ + .popChangeHandler(new VerticalChangeHandler()))); return true; default: return super.onOptionsItemSelected(item); diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ConversationInfoController.java b/app/src/main/java/com/nextcloud/talk/controllers/ConversationInfoController.java new file mode 100644 index 000000000..61eeea5ac --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/controllers/ConversationInfoController.java @@ -0,0 +1,202 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017-2018 Mario Danic + * + * 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 . + */ + +package com.nextcloud.talk.controllers; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.MenuItem; +import android.view.View; + +import com.nextcloud.talk.R; + +import android.view.ViewGroup; +import android.widget.ProgressBar; + +import com.nextcloud.talk.api.NcApi; +import com.nextcloud.talk.application.NextcloudTalkApplication; +import com.nextcloud.talk.controllers.base.BaseController; +import com.nextcloud.talk.models.database.UserEntity; +import com.nextcloud.talk.models.json.converters.EnumNotificationLevelConverter; +import com.nextcloud.talk.models.json.rooms.Conversation; +import com.nextcloud.talk.models.json.rooms.RoomOverall; +import com.nextcloud.talk.utils.ApiUtils; +import com.nextcloud.talk.utils.preferencestorage.DatabaseStorageModule; +import com.nextcloud.talk.utils.bundle.BundleKeys; +import com.yarolegovich.mp.MaterialChoicePreference; +import com.yarolegovich.mp.MaterialPreferenceScreen; + + +import org.parceler.Parcels; + +import javax.inject.Inject; + +import androidx.annotation.NonNull; +import autodagger.AutoInjector; +import butterknife.BindView; +import io.reactivex.Observer; +import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.disposables.Disposable; +import io.reactivex.schedulers.Schedulers; + + +@AutoInjector(NextcloudTalkApplication.class) +public class ConversationInfoController extends BaseController { + + private String baseUrl; + private String conversationToken; + private UserEntity conversationUser; + private String credentials; + + @BindView(R.id.notification_settings) + MaterialPreferenceScreen materialPreferenceScreen; + + @BindView(R.id.progressBar) + ProgressBar progressBar; + + @BindView(R.id.conversation_info_message_notifications) + MaterialChoicePreference messageNotificationLevel; + + @Inject + NcApi ncApi; + + private Disposable roomDisposable; + private Conversation conversation; + ConversationInfoController(Bundle args) { + super(args); + setHasOptionsMenu(true); + NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); + conversationUser = Parcels.unwrap(args.getParcelable(BundleKeys.KEY_USER_ENTITY)); + conversationToken = args.getString(BundleKeys.KEY_ROOM_TOKEN); + baseUrl = args.getString(BundleKeys.KEY_BASE_URL); + credentials = ApiUtils.getCredentials(conversationUser.getUsername(), conversationUser.getToken()); + } + + @Override + public boolean onOptionsItemSelected(@NonNull MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + getRouter().popCurrentController(); + return true; + default: + return super.onOptionsItemSelected(item); + } + } + + @Override + protected View inflateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container) { + return inflater.inflate(R.layout.conversation_info, container, false); + } + + @Override + protected void onViewBound(@NonNull View view) { + super.onViewBound(view); + materialPreferenceScreen.setStorageModule(new DatabaseStorageModule(conversationUser, conversationToken)); + if (conversation == null) { + fetchRoomInfo(); + } + } + + @Override + protected void onAttach(@NonNull View view) { + super.onAttach(view); + if (getActionBar() != null) { + getActionBar().setDisplayHomeAsUpEnabled(true); + } + } + + @Override + protected String getTitle() { + return getResources().getString(R.string.nc_conversation_menu_conversation_info); + } + + private void fetchRoomInfo() { + ncApi.getRoom(credentials, ApiUtils.getRoom(conversationUser.getBaseUrl(), conversationToken)) + .subscribeOn(Schedulers.newThread()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Observer() { + @Override + public void onSubscribe(Disposable d) { + roomDisposable = d; + } + + @Override + public void onNext(RoomOverall roomOverall) { + conversation = roomOverall.getOcs().getData(); + + progressBar.setVisibility(View.GONE); + materialPreferenceScreen.setVisibility(View.VISIBLE); + + if (conversationUser.hasSpreedCapabilityWithName("notification-levels")) { + messageNotificationLevel.setEnabled(true); + messageNotificationLevel.setAlpha(1.0f); + if (!conversation.getNotificationLevel().equals(Conversation.NotificationLevel.DEFAULT)) { + String stringValue; + switch (new EnumNotificationLevelConverter().convertToInt(conversation.getNotificationLevel())) { + case 1: + stringValue = "always"; + break; + case 2: + stringValue = "mention"; + break; + case 3: + stringValue = "never"; + break; + default: + stringValue = "mention"; + break; + } + + messageNotificationLevel.setValue(stringValue); + } else { + setProperNotificationValue(conversation); + } + } else { + messageNotificationLevel.setEnabled(false); + messageNotificationLevel.setAlpha(0.38f); + setProperNotificationValue(conversation); + } + } + + @Override + public void onError(Throwable e) { + + } + + @Override + public void onComplete() { + roomDisposable.dispose(); + } + }); + } + + private void setProperNotificationValue(Conversation conversation) { + if (conversation.getType().equals(Conversation.RoomType.ROOM_TYPE_ONE_TO_ONE_CALL)) { + // hack to see if we get mentioned always or just on mention + if (conversationUser.hasSpreedCapabilityWithName("mention-flag")) { + messageNotificationLevel.setValue("always"); + } else { + messageNotificationLevel.setValue("mention"); + } + } else { + messageNotificationLevel.setValue("mention"); + } + } +} diff --git a/app/src/main/java/com/nextcloud/talk/dagger/modules/DatabaseModule.java b/app/src/main/java/com/nextcloud/talk/dagger/modules/DatabaseModule.java index a8eb25cc1..1f723893b 100644 --- a/app/src/main/java/com/nextcloud/talk/dagger/modules/DatabaseModule.java +++ b/app/src/main/java/com/nextcloud/talk/dagger/modules/DatabaseModule.java @@ -49,7 +49,7 @@ public class DatabaseModule { return new SqlCipherDatabaseSource(context, Models.DEFAULT, context.getResources().getString(R.string.nc_app_name).toLowerCase() .replace(" ", "_").trim() + ".sqlite", - context.getString(R.string.nc_talk_database_encryption_key), 5); + context.getString(R.string.nc_talk_database_encryption_key), 6); } @Provides diff --git a/app/src/main/java/com/nextcloud/talk/jobs/NotificationWorker.java b/app/src/main/java/com/nextcloud/talk/jobs/NotificationWorker.java index 76c6bd19d..d237bf624 100644 --- a/app/src/main/java/com/nextcloud/talk/jobs/NotificationWorker.java +++ b/app/src/main/java/com/nextcloud/talk/jobs/NotificationWorker.java @@ -46,6 +46,7 @@ import com.nextcloud.talk.api.NcApi; import com.nextcloud.talk.application.NextcloudTalkApplication; import com.nextcloud.talk.models.RingtoneSettings; import com.nextcloud.talk.models.SignatureVerification; +import com.nextcloud.talk.models.database.ArbitraryStorageEntity; import com.nextcloud.talk.models.database.UserEntity; import com.nextcloud.talk.models.json.chat.ChatUtils; import com.nextcloud.talk.models.json.notifications.NotificationOverall; @@ -57,6 +58,7 @@ import com.nextcloud.talk.utils.DoNotDisturbUtils; import com.nextcloud.talk.utils.NotificationUtils; import com.nextcloud.talk.utils.PushUtils; import com.nextcloud.talk.utils.bundle.BundleKeys; +import com.nextcloud.talk.utils.database.arbitrarystorage.ArbitraryStorageUtils; import com.nextcloud.talk.utils.preferences.AppPreferences; import com.nextcloud.talk.utils.singletons.ApplicationWideCurrentRoomHolder; @@ -93,6 +95,9 @@ public class NotificationWorker extends Worker { @Inject AppPreferences appPreferences; + @Inject + ArbitraryStorageUtils arbitraryStorageUtils; + @Inject Retrofit retrofit; @@ -114,42 +119,53 @@ public class NotificationWorker extends Worker { private void showNotificationForCallWithNoPing(Intent intent) { UserEntity userEntity = signatureVerification.getUserEntity(); - ncApi.getRoom(credentials, ApiUtils.getRoom(userEntity.getBaseUrl(), - intent.getExtras().getString(BundleKeys.KEY_ROOM_TOKEN))) - .blockingSubscribe(new Observer() { - @Override - public void onSubscribe(Disposable d) { - } + ArbitraryStorageEntity arbitraryStorageEntity; + boolean muteCalls = false; - @Override - public void onNext(RoomOverall roomOverall) { - Conversation conversation = roomOverall.getOcs().getData(); + if ((arbitraryStorageEntity = arbitraryStorageUtils.getStorageSetting(userEntity.getId(), + "mute_calls", intent.getExtras().getString(BundleKeys.KEY_ROOM_TOKEN))) != null) { + muteCalls = Boolean.parseBoolean(arbitraryStorageEntity.getValue()); + } + + if (!muteCalls) { + ncApi.getRoom(credentials, ApiUtils.getRoom(userEntity.getBaseUrl(), + intent.getExtras().getString(BundleKeys.KEY_ROOM_TOKEN))) + .blockingSubscribe(new Observer() { + @Override + public void onSubscribe(Disposable d) { - intent.putExtra(BundleKeys.KEY_ROOM, Parcels.wrap(conversation)); - if (conversation.getType().equals(Conversation.RoomType.ROOM_TYPE_ONE_TO_ONE_CALL) || - (!TextUtils.isEmpty(conversation.getObjectType()) && "share:password".equals - (conversation.getObjectType()))) { - context.startActivity(intent); - } else { - if (conversation.getType().equals(Conversation.RoomType.ROOM_GROUP_CALL)) { - conversationType = "group"; - } else { - conversationType = "public"; - } - showNotification(intent); } - } - @Override - public void onError(Throwable e) { - } + @Override + public void onNext(RoomOverall roomOverall) { + Conversation conversation = roomOverall.getOcs().getData(); - @Override - public void onComplete() { + intent.putExtra(BundleKeys.KEY_ROOM, Parcels.wrap(conversation)); + if (conversation.getType().equals(Conversation.RoomType.ROOM_TYPE_ONE_TO_ONE_CALL) || + (!TextUtils.isEmpty(conversation.getObjectType()) && "share:password".equals + (conversation.getObjectType()))) { + context.startActivity(intent); + } else { + if (conversation.getType().equals(Conversation.RoomType.ROOM_GROUP_CALL)) { + conversationType = "group"; + } else { + conversationType = "public"; + } + showNotification(intent); + } + } - } - }); + @Override + public void onError(Throwable e) { + } + + @Override + public void onComplete() { + + } + }); + } } private void showMessageNotificationWithObjectData(Intent intent) { diff --git a/app/src/main/java/com/nextcloud/talk/models/database/ArbitraryStorage.java b/app/src/main/java/com/nextcloud/talk/models/database/ArbitraryStorage.java new file mode 100644 index 000000000..77ae21451 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/models/database/ArbitraryStorage.java @@ -0,0 +1,42 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017-2018 Mario Danic + * + * 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 . + */ + +package com.nextcloud.talk.models.database; + +import android.os.Parcelable; + +import java.io.Serializable; + +import io.requery.Entity; +import io.requery.Key; +import io.requery.Nullable; +import io.requery.Persistable; + +@Entity +public interface ArbitraryStorage extends Parcelable, Persistable, Serializable { + @Key + long getAccountIdentifier(); + + String getKey(); + + String getObject(); + + String getValue(); +} diff --git a/app/src/main/java/com/nextcloud/talk/utils/database/arbitrarystorage/ArbitraryStorageModule.java b/app/src/main/java/com/nextcloud/talk/utils/database/arbitrarystorage/ArbitraryStorageModule.java new file mode 100644 index 000000000..c239b197d --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/utils/database/arbitrarystorage/ArbitraryStorageModule.java @@ -0,0 +1,45 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017-2018 Mario Danic + * + * 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 . + */ +package com.nextcloud.talk.utils.database.arbitrarystorage; + +import com.nextcloud.talk.application.NextcloudTalkApplication; +import com.nextcloud.talk.dagger.modules.DatabaseModule; + +import javax.inject.Inject; + +import autodagger.AutoInjector; +import dagger.Module; +import dagger.Provides; +import io.requery.Persistable; +import io.requery.reactivex.ReactiveEntityStore; + +@Module(includes = DatabaseModule.class) +@AutoInjector(NextcloudTalkApplication.class) +public class ArbitraryStorageModule { + + @Inject + public ArbitraryStorageModule() { + } + + @Provides + public ArbitraryStorageUtils provideArbitraryStorageUtils(ReactiveEntityStore dataStore) { + return new ArbitraryStorageUtils(dataStore); + } +} diff --git a/app/src/main/java/com/nextcloud/talk/utils/database/arbitrarystorage/ArbitraryStorageUtils.java b/app/src/main/java/com/nextcloud/talk/utils/database/arbitrarystorage/ArbitraryStorageUtils.java new file mode 100644 index 000000000..d46ceec9c --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/utils/database/arbitrarystorage/ArbitraryStorageUtils.java @@ -0,0 +1,69 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017-2018 Mario Danic + * + * 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 . + */ +package com.nextcloud.talk.utils.database.arbitrarystorage; + +import android.text.TextUtils; + +import com.nextcloud.talk.models.database.ArbitraryStorage; +import com.nextcloud.talk.models.database.ArbitraryStorageEntity; +import com.nextcloud.talk.models.database.User; +import com.nextcloud.talk.models.database.UserEntity; + +import java.util.List; + +import androidx.annotation.Nullable; +import io.reactivex.Completable; +import io.reactivex.Observable; +import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.schedulers.Schedulers; +import io.requery.Persistable; +import io.requery.query.Result; +import io.requery.reactivex.ReactiveEntityStore; + +public class ArbitraryStorageUtils { + private ReactiveEntityStore dataStore; + + ArbitraryStorageUtils(ReactiveEntityStore dataStore) { + this.dataStore = dataStore; + } + + + public void storeStorageSetting(long accountIdentifier, String key, String value, String object) { + ArbitraryStorageEntity arbitraryStorageEntity = new ArbitraryStorageEntity(); + arbitraryStorageEntity.setAccountIdentifier(accountIdentifier); + arbitraryStorageEntity.setKey(key); + arbitraryStorageEntity.setValue(value); + arbitraryStorageEntity.setObject(object); + + dataStore.upsert(arbitraryStorageEntity) + .toObservable() + .subscribeOn(Schedulers.newThread()) + .subscribe(); + } + + public ArbitraryStorageEntity getStorageSetting(long accountIdentifier, String key, @Nullable String object) { + Result findStorageQueryResult = dataStore.select(ArbitraryStorage.class) + .where(ArbitraryStorageEntity.ACCOUNT_IDENTIFIER.eq(accountIdentifier) + .and(ArbitraryStorageEntity.KEY.eq(key)).and(ArbitraryStorageEntity.OBJECT.eq(object))) + .limit(1).get(); + + return (ArbitraryStorageEntity) findStorageQueryResult.firstOrNull(); + } +} diff --git a/app/src/main/java/com/nextcloud/talk/utils/preferencestorage/DatabaseStorageFactory.java b/app/src/main/java/com/nextcloud/talk/utils/preferencestorage/DatabaseStorageFactory.java new file mode 100644 index 000000000..c0f6e26d0 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/utils/preferencestorage/DatabaseStorageFactory.java @@ -0,0 +1,42 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017-2018 Mario Danic + * + * 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 . + */ + +package com.nextcloud.talk.utils.preferencestorage; + +import android.content.Context; + +import com.nextcloud.talk.models.database.UserEntity; +import com.yarolegovich.mp.io.StorageModule; + +public class DatabaseStorageFactory implements StorageModule.Factory { + private UserEntity conversationUser; + private String conversationToken; + + + public DatabaseStorageFactory(UserEntity conversationUser, String conversationToken) { + this.conversationUser = conversationUser; + this.conversationToken = conversationToken; + } + + @Override + public StorageModule create(Context context) { + return new DatabaseStorageModule(conversationUser, conversationToken); + } +} diff --git a/app/src/main/java/com/nextcloud/talk/utils/preferencestorage/DatabaseStorageModule.java b/app/src/main/java/com/nextcloud/talk/utils/preferencestorage/DatabaseStorageModule.java new file mode 100644 index 000000000..834af04a2 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/utils/preferencestorage/DatabaseStorageModule.java @@ -0,0 +1,169 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017-2018 Mario Danic + * + * 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 . + */ + +package com.nextcloud.talk.utils.preferencestorage; + +import android.os.Bundle; + +import com.nextcloud.talk.api.NcApi; +import com.nextcloud.talk.application.NextcloudTalkApplication; +import com.nextcloud.talk.models.database.ArbitraryStorageEntity; +import com.nextcloud.talk.models.database.UserEntity; +import com.nextcloud.talk.models.json.generic.GenericOverall; +import com.nextcloud.talk.utils.ApiUtils; +import com.nextcloud.talk.utils.database.arbitrarystorage.ArbitraryStorageUtils; +import com.yarolegovich.mp.io.StorageModule; + +import java.util.Set; + +import javax.inject.Inject; + +import autodagger.AutoInjector; +import io.reactivex.Observer; +import io.reactivex.disposables.Disposable; +import io.reactivex.schedulers.Schedulers; + +@AutoInjector(NextcloudTalkApplication.class) +public class DatabaseStorageModule implements StorageModule { + @Inject + ArbitraryStorageUtils arbitraryStorageUtils; + + @Inject + NcApi ncApi; + + private UserEntity conversationUser; + private String conversationToken; + private long accountIdentifier; + + public DatabaseStorageModule(UserEntity conversationUser, String conversationToken) { + NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); + + this.conversationUser = conversationUser; + this.accountIdentifier = conversationUser.getId(); + this.conversationToken = conversationToken; + } + + @Override + public void saveBoolean(String key, boolean value) { + arbitraryStorageUtils.storeStorageSetting(accountIdentifier, key, Boolean.toString(value), conversationToken); + } + + @Override + public void saveString(String key, String value) { + if (!key.equals("message_notification_level")) { + arbitraryStorageUtils.storeStorageSetting(accountIdentifier, key, value, conversationToken); + } else { + int intValue; + switch (value) { + case "never": + intValue = 3; + break; + case "mention": + intValue = 2; + break; + case "always": + intValue = 1; + break; + default: + intValue = 0; + } + + ncApi.setNotificationLevel(ApiUtils.getCredentials(conversationUser.getUsername(), conversationUser.getToken()), + ApiUtils.getUrlForSettingNotificationlevel(conversationUser.getBaseUrl(), conversationToken), + intValue) + .subscribeOn(Schedulers.newThread()) + .subscribe(new Observer() { + @Override + public void onSubscribe(Disposable d) { + + } + + @Override + public void onNext(GenericOverall genericOverall) { + + } + + @Override + public void onError(Throwable e) { + + } + + @Override + public void onComplete() { + } + }); + } + } + + @Override + public void saveInt(String key, int value) { + arbitraryStorageUtils.storeStorageSetting(accountIdentifier, key, Integer.toString(value), conversationToken); + } + + @Override + public void saveStringSet(String key, Set value) { + + } + + @Override + public boolean getBoolean(String key, boolean defaultVal) { + ArbitraryStorageEntity valueFromDb = arbitraryStorageUtils.getStorageSetting(accountIdentifier, key, conversationToken); + if (valueFromDb == null) { + return defaultVal; + } else { + return Boolean.parseBoolean(valueFromDb.getValue()); + } + } + + @Override + public String getString(String key, String defaultVal) { + ArbitraryStorageEntity valueFromDb = arbitraryStorageUtils.getStorageSetting(accountIdentifier, key, conversationToken); + if (valueFromDb == null) { + return defaultVal; + } else { + return valueFromDb.getValue(); + } + } + + @Override + public int getInt(String key, int defaultVal) { + ArbitraryStorageEntity valueFromDb = arbitraryStorageUtils.getStorageSetting(accountIdentifier, key, conversationToken); + if (valueFromDb == null) { + return defaultVal; + } else { + return Integer.parseInt(valueFromDb.getValue()); + } + } + + @Override + public Set getStringSet(String key, Set defaultVal) { + return null; + } + + @Override + public void onSaveInstanceState(Bundle outState) { + + } + + @Override + public void onRestoreInstanceState(Bundle savedState) { + + } +} diff --git a/app/src/main/res/layout/conversation_info.xml b/app/src/main/res/layout/conversation_info.xml new file mode 100644 index 000000000..06bc8a501 --- /dev/null +++ b/app/src/main/res/layout/conversation_info.xml @@ -0,0 +1,42 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/notification_settings_item.xml b/app/src/main/res/layout/notification_settings_item.xml index 7966b9b8e..fb74b9936 100644 --- a/app/src/main/res/layout/notification_settings_item.xml +++ b/app/src/main/res/layout/notification_settings_item.xml @@ -1,5 +1,4 @@ - - + xmlns:apc="http://schemas.android.com/apk/res-auto" + android:id="@+id/notification_settings" + android:layout_width="match_parent" + android:layout_height="wrap_content"> @@ -46,8 +47,10 @@ 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"/> + apc:mp_key="mute_calls" + apc:mp_default_value="false" + apc:mp_summary="@string/nc_mute_calls_description" + apc:mp_title="@string/nc_mute_calls" /> diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index ebb463d31..f3f0d6385 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -32,4 +32,11 @@ @string/nc_notify_me_mention @string/nc_notify_me_always + + + never + mention + always + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 80191bd32..55a4da411 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -154,13 +154,14 @@ Calls notification channel Messages notification channel Shows incoming calls - Shows incoming messages + Shows incoming messages Notification settings Messages - Always - When mentioned - Never + Always notify + Notify when mentioned + Never notify Mute calls + When muted, there will be no notification for incoming calls Sorry, something went wrong!