From 6a5aaac2244aa207aae39a033dba170d257dbb29 Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Fri, 30 Aug 2019 12:12:40 +0200 Subject: [PATCH] Lobby & Various bugfixes and improvements Includes conversion to Kotlin of some files Signed-off-by: Mario Danic --- app/build.gradle | 6 + .../talk/ExampleInstrumentedTest.java | 20 + .../MagicFirebaseMessagingService.java | 6 +- .../talk/utils/ClosedInterfaceImpl.java | 5 +- .../talk/activities/BaseActivity.java | 2 +- .../talk/activities/MagicCallActivity.java | 4 +- .../talk/activities/MainActivity.java | 12 +- .../talk/adapters/items/AdvancedUserItem.java | 4 +- .../talk/adapters/items/AppItem.java | 2 +- .../talk/adapters/items/CallItem.java | 6 +- .../talk/adapters/items/ConversationItem.java | 10 +- .../items/MentionAutocompleteItem.java | 6 +- .../talk/adapters/items/MenuItem.java | 4 +- .../adapters/items/NotificationSoundItem.java | 2 +- .../talk/adapters/items/UserItem.java | 20 +- .../MagicIncomingTextMessageViewHolder.java | 8 +- .../MagicOutcomingTextMessageViewHolder.java | 4 +- .../MagicPreviewMessageViewHolder.java | 12 +- .../MagicSystemMessageViewHolder.java | 4 +- .../java/com/nextcloud/talk/api/NcApi.java | 11 +- .../application/NextcloudTalkApplication.java | 239 -------- .../application/NextcloudTalkApplication.kt | 217 +++++++ .../adapters/items/BrowserFileItem.java | 6 +- .../controllers/BrowserController.java | 14 +- .../AccountVerificationController.java | 20 +- .../talk/controllers/CallController.java | 18 +- .../CallNotificationController.java | 22 +- .../talk/controllers/ChatController.java | 270 +++++---- .../talk/controllers/ContactsController.java | 38 +- .../ConversationInfoController.java | 507 ---------------- .../controllers/ConversationInfoController.kt | 552 ++++++++++++++++++ .../ConversationsListController.java | 32 +- .../talk/controllers/LockedController.java | 2 +- .../RingtoneSelectionController.java | 4 +- .../ServerSelectionController.java | 18 +- .../talk/controllers/SettingsController.java | 14 +- .../controllers/SwitchAccountController.java | 18 +- .../controllers/WebViewLoginController.java | 10 +- .../talk/controllers/base/BaseController.java | 2 +- .../bottomsheet/CallMenuController.java | 38 +- .../bottomsheet/EntryMenuController.java | 42 +- .../bottomsheet/OperationsMenuController.java | 64 +- .../talk/dagger/modules/RestModule.java | 4 +- .../talk/events/MoreMenuClickEvent.java | 2 +- .../events/WebSocketCommunicationEvent.java | 2 +- ...ctionInterface.java => ClosedInterface.kt} | 8 +- ...face.java => ConversationMenuInterface.kt} | 8 +- ...edInterface.java => SelectionInterface.kt} | 8 +- .../talk/jobs/AccountRemovalWorker.java | 2 +- .../talk/jobs/CapabilitiesWorker.java | 4 +- .../talk/jobs/DeleteConversationWorker.java | 6 +- .../talk/jobs/LeaveConversationWorker.java | 6 +- .../talk/jobs/NotificationWorker.java | 38 +- .../talk/jobs/ShareOperationWorker.java | 8 +- .../talk/jobs/SignalingSettingsWorker.java | 4 +- .../talk/jobs/WebsocketConnectionsWorker.java | 2 +- .../talk/models/json/chat/ChatMessage.java | 41 +- .../Conversation.java | 32 +- .../{rooms => conversations}/RoomOCS.java | 4 +- .../{rooms => conversations}/RoomOverall.java | 4 +- .../{rooms => conversations}/RoomsOCS.java | 4 +- .../RoomsOverall.java | 4 +- .../converters/EnumLobbyStateConverter.java | 50 ++ .../EnumNotificationLevelConverter.java | 2 +- .../EnumReadOnlyConversationConverter.java | 2 +- .../converters/EnumRoomTypeConverter.java | 2 +- .../EnumSystemMessageTypeConverter.java | 126 ---- .../EnumSystemMessageTypeConverter.kt | 98 ++++ .../talk/models/json/generic/GenericMeta.java | 6 +- .../talk/models/json/generic/GenericOCS.java | 2 +- .../models/json/generic/GenericOverall.java | 2 +- .../json/participants/AddParticipantOCS.java | 2 +- .../participants/AddParticipantOverall.java | 2 +- .../models/json/participants/Participant.java | 20 +- .../json/participants/ParticipantsOCS.java | 2 +- .../participants/ParticipantsOverall.java | 2 +- .../RoomPropertiesWebSocketMessage.java | 2 +- .../MentionAutocompletePresenter.java | 4 +- .../receivers/PackageReplacedReceiver.java | 2 +- .../nextcloud/talk/utils/AccountUtils.java | 156 ----- .../com/nextcloud/talk/utils/AccountUtils.kt | 149 +++++ .../com/nextcloud/talk/utils/ApiUtils.java | 8 +- .../talk/utils/BottomNavigationUtils.java | 39 -- .../talk/utils/ConductorRemapping.java | 59 -- .../talk/utils/ConductorRemapping.kt | 57 ++ .../utils/{DateUtils.java => DateUtils.kt} | 30 +- .../com/nextcloud/talk/utils/DeviceUtils.java | 4 +- .../nextcloud/talk/utils/DisplayUtils.java | 6 +- .../talk/utils/DoNotDisturbUtils.java | 79 --- .../nextcloud/talk/utils/DoNotDisturbUtils.kt | 74 +++ .../nextcloud/talk/utils/DrawableUtils.java | 161 ----- .../com/nextcloud/talk/utils/DrawableUtils.kt | 158 +++++ .../nextcloud/talk/utils/LoggingUtils.java | 77 --- .../com/nextcloud/talk/utils/LoggingUtils.kt | 78 +++ .../talk/utils/{MagicMap.java => MagicMap.kt} | 14 +- .../talk/utils/NotificationUtils.java | 14 +- .../com/nextcloud/talk/utils/PushUtils.java | 10 +- .../nextcloud/talk/utils/SecurityUtils.java | 2 +- .../com/nextcloud/talk/utils/ShareUtils.java | 2 +- .../talk/utils/bundle/BundleBuilder.java | 191 ------ .../talk/utils/bundle/BundleKeys.java | 59 -- .../nextcloud/talk/utils/bundle/BundleKeys.kt | 59 ++ .../talk/utils/power/PowerManagerUtils.java | 2 +- .../preferences/MagicUserInputModule.java | 4 +- .../DatabaseStorageModule.java | 22 +- .../talk/utils/ssl/MagicKeyManager.java | 2 +- .../talk/utils/ssl/MagicTrustManager.java | 2 +- .../webrtc/MagicPeerConnectionWrapper.java | 12 +- .../talk/webrtc/MagicWebSocketInstance.java | 22 +- .../webrtc/WebSocketConnectionHelper.java | 2 +- .../res/drawable/ic_mimetype_application.xml | 20 + .../drawable/ic_mimetype_application_pdf.xml | 20 + .../main/res/drawable/ic_mimetype_audio.xml | 20 + .../main/res/drawable/ic_mimetype_file.xml | 20 + .../main/res/drawable/ic_mimetype_folder.xml | 20 + .../ic_mimetype_folder_drag_accept.xml | 20 + .../drawable/ic_mimetype_folder_encrypted.xml | 20 + .../drawable/ic_mimetype_folder_external.xml | 20 + .../drawable/ic_mimetype_folder_public.xml | 20 + .../drawable/ic_mimetype_folder_shared.xml | 20 + .../drawable/ic_mimetype_folder_starred.xml | 20 + .../main/res/drawable/ic_mimetype_image.xml | 20 + .../main/res/drawable/ic_mimetype_link.xml | 20 + .../res/drawable/ic_mimetype_location.xml | 20 + .../ic_mimetype_package_x_generic.xml | 20 + .../main/res/drawable/ic_mimetype_text.xml | 20 + .../drawable/ic_mimetype_text_calendar.xml | 20 + .../res/drawable/ic_mimetype_text_code.xml | 20 + .../res/drawable/ic_mimetype_text_vcard.xml | 20 + .../main/res/drawable/ic_mimetype_video.xml | 20 + .../ic_mimetype_x_office_document.xml | 20 + .../ic_mimetype_x_office_presentation.xml | 20 + .../ic_mimetype_x_office_spreadsheet.xml | 20 + .../drawable/ic_room_service_black_24dp.xml | 25 + .../main/res/drawable/ic_timer_black_24dp.xml | 25 + app/src/main/res/layout/activity_main.xml | 16 +- app/src/main/res/layout/call_item.xml | 48 +- app/src/main/res/layout/call_states.xml | 18 +- .../main/res/layout/controller_browser.xml | 14 +- app/src/main/res/layout/controller_call.xml | 99 ++-- .../layout/controller_call_notification.xml | 76 +-- app/src/main/res/layout/controller_chat.xml | 64 +- .../layout/controller_conversation_info.xml | 39 +- .../layout/controller_conversations_rv.xml | 4 +- .../main/res/layout/controller_entry_menu.xml | 36 +- app/src/main/res/layout/controller_locked.xml | 2 +- .../res/layout/controller_operations_menu.xml | 24 +- .../layout/controller_server_selection.xml | 50 +- .../main/res/layout/controller_settings.xml | 67 ++- app/src/main/res/layout/dialog_standard.xml | 68 +-- .../res/layout/dialog_standard_vertical.xml | 28 +- app/src/main/res/layout/emoji_view.xml | 18 +- .../item_custom_incoming_preview_message.xml | 21 +- .../item_custom_incoming_text_message.xml | 4 +- .../item_custom_outcoming_preview_message.xml | 3 +- .../item_custom_outcoming_text_message.xml | 2 +- .../layout/library_fast_scroller_layout.xml | 34 +- app/src/main/res/layout/lobby_view.xml | 47 ++ .../res/layout/notification_settings_item.xml | 2 +- .../main/res/layout/rv_item_browser_file.xml | 78 +-- app/src/main/res/layout/rv_item_contact.xml | 42 +- .../main/res/layout/rv_item_conversation.xml | 36 +- .../rv_item_conversation_info_participant.xml | 12 +- ...rv_item_conversation_with_last_message.xml | 85 ++- app/src/main/res/layout/rv_item_mention.xml | 4 +- .../res/layout/rv_item_notification_sound.xml | 40 +- .../main/res/layout/rv_item_title_header.xml | 10 +- .../main/res/layout/view_message_input.xml | 52 +- app/src/main/res/layout/webinar_info_item.xml | 58 ++ app/src/main/res/values/strings.xml | 12 + .../talk/utils/DoNotDisturbUtilsTest.java | 30 +- .../nextcloud/talk/utils/ShareUtilsTest.java | 22 +- .../talk/utils/TextMatchersTest.java | 20 + build.gradle | 20 + findbugs-filter.xml | 20 + gradle.properties | 20 + gradle/wrapper/gradle-wrapper.properties | 20 + settings.gradle | 20 + 178 files changed, 3497 insertions(+), 2764 deletions(-) delete mode 100644 app/src/main/java/com/nextcloud/talk/application/NextcloudTalkApplication.java create mode 100644 app/src/main/java/com/nextcloud/talk/application/NextcloudTalkApplication.kt delete mode 100644 app/src/main/java/com/nextcloud/talk/controllers/ConversationInfoController.java create mode 100644 app/src/main/java/com/nextcloud/talk/controllers/ConversationInfoController.kt rename app/src/main/java/com/nextcloud/talk/interfaces/{SelectionInterface.java => ClosedInterface.kt} (82%) rename app/src/main/java/com/nextcloud/talk/interfaces/{ConversationMenuInterface.java => ConversationMenuInterface.kt} (81%) rename app/src/main/java/com/nextcloud/talk/interfaces/{ClosedInterface.java => SelectionInterface.kt} (82%) rename app/src/main/java/com/nextcloud/talk/models/json/{rooms => conversations}/Conversation.java (82%) rename app/src/main/java/com/nextcloud/talk/models/json/{rooms => conversations}/RoomOCS.java (92%) rename app/src/main/java/com/nextcloud/talk/models/json/{rooms => conversations}/RoomOverall.java (92%) rename app/src/main/java/com/nextcloud/talk/models/json/{rooms => conversations}/RoomsOCS.java (92%) rename app/src/main/java/com/nextcloud/talk/models/json/{rooms => conversations}/RoomsOverall.java (92%) create mode 100644 app/src/main/java/com/nextcloud/talk/models/json/converters/EnumLobbyStateConverter.java delete mode 100644 app/src/main/java/com/nextcloud/talk/models/json/converters/EnumSystemMessageTypeConverter.java create mode 100644 app/src/main/java/com/nextcloud/talk/models/json/converters/EnumSystemMessageTypeConverter.kt delete mode 100644 app/src/main/java/com/nextcloud/talk/utils/AccountUtils.java create mode 100644 app/src/main/java/com/nextcloud/talk/utils/AccountUtils.kt delete mode 100644 app/src/main/java/com/nextcloud/talk/utils/BottomNavigationUtils.java delete mode 100644 app/src/main/java/com/nextcloud/talk/utils/ConductorRemapping.java create mode 100644 app/src/main/java/com/nextcloud/talk/utils/ConductorRemapping.kt rename app/src/main/java/com/nextcloud/talk/utils/{DateUtils.java => DateUtils.kt} (55%) delete mode 100644 app/src/main/java/com/nextcloud/talk/utils/DoNotDisturbUtils.java create mode 100644 app/src/main/java/com/nextcloud/talk/utils/DoNotDisturbUtils.kt delete mode 100644 app/src/main/java/com/nextcloud/talk/utils/DrawableUtils.java create mode 100644 app/src/main/java/com/nextcloud/talk/utils/DrawableUtils.kt delete mode 100644 app/src/main/java/com/nextcloud/talk/utils/LoggingUtils.java create mode 100644 app/src/main/java/com/nextcloud/talk/utils/LoggingUtils.kt rename app/src/main/java/com/nextcloud/talk/utils/{MagicMap.java => MagicMap.kt} (72%) delete mode 100644 app/src/main/java/com/nextcloud/talk/utils/bundle/BundleBuilder.java delete mode 100644 app/src/main/java/com/nextcloud/talk/utils/bundle/BundleKeys.java create mode 100644 app/src/main/java/com/nextcloud/talk/utils/bundle/BundleKeys.kt create mode 100644 app/src/main/res/drawable/ic_room_service_black_24dp.xml create mode 100644 app/src/main/res/drawable/ic_timer_black_24dp.xml create mode 100644 app/src/main/res/layout/lobby_view.xml create mode 100644 app/src/main/res/layout/webinar_info_item.xml diff --git a/app/build.gradle b/app/build.gradle index 99adb8568..6d708d2e3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -232,6 +232,12 @@ dependencies { implementation 'com.github.mario:PopupBubble:a365177d96' implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1' implementation 'eu.medsea.mimeutil:mime-util:2.1.3' + + implementation 'com.afollestad.material-dialogs:core:3.1.0' + implementation 'com.afollestad.material-dialogs:datetime:3.1.0' + implementation 'com.afollestad.material-dialogs:bottomsheets:3.1.0' + implementation 'com.afollestad.material-dialogs:lifecycle:3.1.0' + testImplementation 'junit:junit:4.12' testImplementation 'org.mockito:mockito-core:3.0.0' testImplementation 'org.powermock:powermock-core:2.0.2' diff --git a/app/src/androidTest/java/com/nextcloud/talk/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/nextcloud/talk/ExampleInstrumentedTest.java index 8bbb7ae99..5514687d6 100644 --- a/app/src/androidTest/java/com/nextcloud/talk/ExampleInstrumentedTest.java +++ b/app/src/androidTest/java/com/nextcloud/talk/ExampleInstrumentedTest.java @@ -1,3 +1,23 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017-2019 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; import android.content.Context; diff --git a/app/src/gplay/java/com/nextcloud/talk/services/firebase/MagicFirebaseMessagingService.java b/app/src/gplay/java/com/nextcloud/talk/services/firebase/MagicFirebaseMessagingService.java index 8a04d3906..12a3006a6 100644 --- a/app/src/gplay/java/com/nextcloud/talk/services/firebase/MagicFirebaseMessagingService.java +++ b/app/src/gplay/java/com/nextcloud/talk/services/firebase/MagicFirebaseMessagingService.java @@ -45,7 +45,7 @@ public class MagicFirebaseMessagingService extends FirebaseMessagingService { @Override public void onNewToken(String token) { super.onNewToken(token); - NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); + NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); appPreferences.setPushToken(token); OneTimeWorkRequest pushRegistrationWork = new OneTimeWorkRequest.Builder(PushRegistrationWorker.class).build(); WorkManager.getInstance().enqueue(pushRegistrationWork); @@ -60,8 +60,8 @@ public class MagicFirebaseMessagingService extends FirebaseMessagingService { if (remoteMessage.getData() != null) { Data messageData = new Data.Builder() - .putString(BundleKeys.KEY_NOTIFICATION_SUBJECT, remoteMessage.getData().get("subject")) - .putString(BundleKeys.KEY_NOTIFICATION_SIGNATURE, remoteMessage.getData().get("signature")) + .putString(BundleKeys.INSTANCE.getKEY_NOTIFICATION_SUBJECT(), remoteMessage.getData().get("subject")) + .putString(BundleKeys.INSTANCE.getKEY_NOTIFICATION_SIGNATURE(), remoteMessage.getData().get("signature")) .build(); OneTimeWorkRequest pushNotificationWork = new OneTimeWorkRequest.Builder(NotificationWorker.class) diff --git a/app/src/gplay/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.java b/app/src/gplay/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.java index 18a5cfdc6..7be5866f2 100644 --- a/app/src/gplay/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.java +++ b/app/src/gplay/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.java @@ -33,14 +33,15 @@ import com.nextcloud.talk.interfaces.ClosedInterface; public class ClosedInterfaceImpl implements ClosedInterface, ProviderInstallListener { @Override public void providerInstallerInstallIfNeededAsync() { - ProviderInstaller.installIfNeededAsync(NextcloudTalkApplication.getSharedApplication().getApplicationContext(), + ProviderInstaller.installIfNeededAsync(NextcloudTalkApplication.Companion.getSharedApplication().getApplicationContext(), this); } @Override public boolean isGooglePlayServicesAvailable() { GoogleApiAvailability api = GoogleApiAvailability.getInstance(); - int code = api.isGooglePlayServicesAvailable(NextcloudTalkApplication.getSharedApplication().getApplicationContext()); + int code = + api.isGooglePlayServicesAvailable(NextcloudTalkApplication.Companion.getSharedApplication().getApplicationContext()); return code == ConnectionResult.SUCCESS; } diff --git a/app/src/main/java/com/nextcloud/talk/activities/BaseActivity.java b/app/src/main/java/com/nextcloud/talk/activities/BaseActivity.java index 49c3b33cc..737cd566a 100644 --- a/app/src/main/java/com/nextcloud/talk/activities/BaseActivity.java +++ b/app/src/main/java/com/nextcloud/talk/activities/BaseActivity.java @@ -62,7 +62,7 @@ public class BaseActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { - NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); + NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); super.onCreate(savedInstanceState); } diff --git a/app/src/main/java/com/nextcloud/talk/activities/MagicCallActivity.java b/app/src/main/java/com/nextcloud/talk/activities/MagicCallActivity.java index ee1122420..b0e9cbddf 100644 --- a/app/src/main/java/com/nextcloud/talk/activities/MagicCallActivity.java +++ b/app/src/main/java/com/nextcloud/talk/activities/MagicCallActivity.java @@ -64,7 +64,7 @@ public class MagicCallActivity extends BaseActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); + NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN | @@ -80,7 +80,7 @@ public class MagicCallActivity extends BaseActivity { router.setPopsLastView(false); if (!router.hasRootController()) { - if (getIntent().getBooleanExtra(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL, false)) { + if (getIntent().getBooleanExtra(BundleKeys.INSTANCE.getKEY_FROM_NOTIFICATION_START_CALL(), false)) { router.setRoot(RouterTransaction.with(new CallNotificationController(getIntent().getExtras())) .pushChangeHandler(new HorizontalChangeHandler()) .popChangeHandler(new HorizontalChangeHandler())); diff --git a/app/src/main/java/com/nextcloud/talk/activities/MainActivity.java b/app/src/main/java/com/nextcloud/talk/activities/MainActivity.java index 8e0e9f19c..099f14344 100644 --- a/app/src/main/java/com/nextcloud/talk/activities/MainActivity.java +++ b/app/src/main/java/com/nextcloud/talk/activities/MainActivity.java @@ -77,7 +77,7 @@ public final class MainActivity extends BaseActivity implements ActionBarProvide setContentView(R.layout.activity_main); - NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); + NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); ButterKnife.bind(this); setSupportActionBar(toolbar); @@ -92,7 +92,7 @@ public final class MainActivity extends BaseActivity implements ActionBarProvide hasDb = false; } - if (getIntent().hasExtra(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL)) { + if (getIntent().hasExtra(BundleKeys.INSTANCE.getKEY_FROM_NOTIFICATION_START_CALL())) { if (!router.hasRootController()) { router.setRoot(RouterTransaction.with(new ConversationsListController()) .pushChangeHandler(new HorizontalChangeHandler()) @@ -148,14 +148,14 @@ public final class MainActivity extends BaseActivity implements ActionBarProvide protected void onNewIntent(Intent intent) { super.onNewIntent(intent); - if (intent.hasExtra(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL)) { - if (intent.getBooleanExtra(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL, false)) { + if (intent.hasExtra(BundleKeys.INSTANCE.getKEY_FROM_NOTIFICATION_START_CALL())) { + if (intent.getBooleanExtra(BundleKeys.INSTANCE.getKEY_FROM_NOTIFICATION_START_CALL(), false)) { router.pushController(RouterTransaction.with(new CallNotificationController(intent.getExtras())) .pushChangeHandler(new HorizontalChangeHandler()) .popChangeHandler(new HorizontalChangeHandler())); } else { - ConductorRemapping.remapChatController(router, intent.getLongExtra(BundleKeys.KEY_INTERNAL_USER_ID, -1), - intent.getStringExtra(BundleKeys.KEY_ROOM_TOKEN), intent.getExtras(), false); + ConductorRemapping.INSTANCE.remapChatController(router, intent.getLongExtra(BundleKeys.INSTANCE.getKEY_INTERNAL_USER_ID(), -1), + intent.getStringExtra(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN()), intent.getExtras(), false); ; } } diff --git a/app/src/main/java/com/nextcloud/talk/adapters/items/AdvancedUserItem.java b/app/src/main/java/com/nextcloud/talk/adapters/items/AdvancedUserItem.java index bc353b9ee..64aa5bc18 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/items/AdvancedUserItem.java +++ b/app/src/main/java/com/nextcloud/talk/adapters/items/AdvancedUserItem.java @@ -105,7 +105,7 @@ public class AdvancedUserItem extends AbstractFlexibleItem { if (position == 0) { Spannable spannableString = new SpannableString(title); - spannableString.setSpan(new ForegroundColorSpan(NextcloudTalkApplication.getSharedApplication() + spannableString.setSpan(new ForegroundColorSpan(NextcloudTalkApplication.Companion.getSharedApplication() .getResources().getColor(R.color.grey_600)), 0, spannableString.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); diff --git a/app/src/main/java/com/nextcloud/talk/adapters/items/CallItem.java b/app/src/main/java/com/nextcloud/talk/adapters/items/CallItem.java index c09801d03..58a730f1f 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/items/CallItem.java +++ b/app/src/main/java/com/nextcloud/talk/adapters/items/CallItem.java @@ -36,7 +36,7 @@ import com.nextcloud.talk.R; import com.nextcloud.talk.application.NextcloudTalkApplication; import com.nextcloud.talk.events.MoreMenuClickEvent; import com.nextcloud.talk.models.database.UserEntity; -import com.nextcloud.talk.models.json.rooms.Conversation; +import com.nextcloud.talk.models.json.conversations.Conversation; import com.nextcloud.talk.utils.ApiUtils; import com.nextcloud.talk.utils.DisplayUtils; import eu.davidea.flexibleadapter.FlexibleAdapter; @@ -99,7 +99,7 @@ public class CallItem extends AbstractFlexibleItem public void bindViewHolder(final FlexibleAdapter adapter, RoomItemViewHolder holder, int position, List payloads) { if (adapter.hasFilter()) { FlexibleUtils.highlightText(holder.roomDisplayName, conversation.getDisplayName(), - String.valueOf(adapter.getFilter(String.class)), NextcloudTalkApplication.getSharedApplication() + String.valueOf(adapter.getFilter(String.class)), NextcloudTalkApplication.Companion.getSharedApplication() .getResources().getColor(R.color.colorPrimary)); } else { holder.roomDisplayName.setText(conversation.getDisplayName()); @@ -118,7 +118,7 @@ public class CallItem extends AbstractFlexibleItem holder.passwordProtectedImageView.setVisibility(View.GONE); } - Resources resources = NextcloudTalkApplication.getSharedApplication().getResources(); + Resources resources = NextcloudTalkApplication.Companion.getSharedApplication().getResources(); switch (conversation.getType()) { case ROOM_TYPE_ONE_TO_ONE_CALL: holder.avatarImageView.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/com/nextcloud/talk/adapters/items/ConversationItem.java b/app/src/main/java/com/nextcloud/talk/adapters/items/ConversationItem.java index 8906c207d..0fc5cf9d0 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/items/ConversationItem.java +++ b/app/src/main/java/com/nextcloud/talk/adapters/items/ConversationItem.java @@ -39,7 +39,7 @@ import com.nextcloud.talk.R; import com.nextcloud.talk.application.NextcloudTalkApplication; import com.nextcloud.talk.models.database.UserEntity; import com.nextcloud.talk.models.json.chat.ChatMessage; -import com.nextcloud.talk.models.json.rooms.Conversation; +import com.nextcloud.talk.models.json.conversations.Conversation; import com.nextcloud.talk.utils.ApiUtils; import com.nextcloud.talk.utils.DisplayUtils; import eu.davidea.flexibleadapter.FlexibleAdapter; @@ -94,14 +94,14 @@ public class ConversationItem extends AbstractFlexibleItem adapter, ConversationItemViewHolder holder, int position, List payloads) { - Context context = NextcloudTalkApplication.getSharedApplication().getApplicationContext(); + Context context = NextcloudTalkApplication.Companion.getSharedApplication().getApplicationContext(); holder.dialogAvatar.setController(null); holder.dialogLastMessageUserAvatar.setController(null); if (adapter.hasFilter()) { FlexibleUtils.highlightText(holder.dialogName, conversation.getDisplayName(), - String.valueOf(adapter.getFilter(String.class)), NextcloudTalkApplication.getSharedApplication() + String.valueOf(adapter.getFilter(String.class)), NextcloudTalkApplication.Companion.getSharedApplication() .getResources().getColor(R.color.colorPrimary)); } else { holder.dialogName.setText(conversation.getDisplayName()); @@ -156,7 +156,7 @@ public class ConversationItem extends AbstractFlexibleItem this.tag = tag; this.icon = icon; padding = (int) DisplayUtils.convertDpToPixel(16, - NextcloudTalkApplication.getSharedApplication().getApplicationContext()); + NextcloudTalkApplication.Companion.getSharedApplication().getApplicationContext()); } @Override @@ -81,7 +81,7 @@ public class MenuItem extends AbstractFlexibleItem public void bindViewHolder(FlexibleAdapter adapter, MenuItem.MenuItemViewHolder holder, int position, List payloads) { if (position == 0) { Spannable spannableString = new SpannableString(title); - spannableString.setSpan(new ForegroundColorSpan(NextcloudTalkApplication.getSharedApplication() + spannableString.setSpan(new ForegroundColorSpan(NextcloudTalkApplication.Companion.getSharedApplication() .getResources().getColor(R.color.grey_600)), 0, spannableString.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); diff --git a/app/src/main/java/com/nextcloud/talk/adapters/items/NotificationSoundItem.java b/app/src/main/java/com/nextcloud/talk/adapters/items/NotificationSoundItem.java index f7ddc367c..ffa33fbcc 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/items/NotificationSoundItem.java +++ b/app/src/main/java/com/nextcloud/talk/adapters/items/NotificationSoundItem.java @@ -80,7 +80,7 @@ public class NotificationSoundItem extends AbstractFlexibleItem if (adapter.hasFilter()) { FlexibleUtils.highlightText(holder.contactDisplayName, participant.getDisplayName(), - String.valueOf(adapter.getFilter(String.class)), NextcloudTalkApplication.getSharedApplication() + String.valueOf(adapter.getFilter(String.class)), NextcloudTalkApplication.Companion.getSharedApplication() .getResources().getColor(R.color.colorPrimary)); } else { holder.contactDisplayName.setText(participant.getDisplayName()); if (TextUtils.isEmpty(participant.getDisplayName()) && (participant.getType().equals(Participant.ParticipantType.GUEST) || participant.getType().equals(Participant.ParticipantType.USER_FOLLOWING_LINK))) { - holder.contactDisplayName.setText(NextcloudTalkApplication.getSharedApplication().getString(R.string.nc_guest)); + holder.contactDisplayName.setText(NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_guest)); } } @@ -146,7 +146,7 @@ public class UserItem extends AbstractFlexibleItem } } else if ("groups".equals(participant.getSource())) { - holder.simpleDraweeView.getHierarchy().setImage(new BitmapDrawable(DisplayUtils.getRoundedBitmapFromVectorDrawableResource(NextcloudTalkApplication.getSharedApplication().getResources(), R.drawable.ic_people_group_white_24px)), 100, true); + holder.simpleDraweeView.getHierarchy().setImage(new BitmapDrawable(DisplayUtils.getRoundedBitmapFromVectorDrawableResource(NextcloudTalkApplication.Companion.getSharedApplication().getResources(), R.drawable.ic_people_group_white_24px)), 100, true); } if (!isEnabled()) { @@ -155,7 +155,7 @@ public class UserItem extends AbstractFlexibleItem holder.itemView.setAlpha(1.0f); } - Resources resources = NextcloudTalkApplication.getSharedApplication().getResources(); + Resources resources = NextcloudTalkApplication.Companion.getSharedApplication().getResources(); if (header == null) { Participant.ParticipantFlags participantFlags = participant.getParticipantFlags(); @@ -198,19 +198,19 @@ public class UserItem extends AbstractFlexibleItem switch (new EnumParticipantTypeConverter().convertToInt(participant.getType())) { case 1: - //userType = NextcloudTalkApplication.getSharedApplication().getString(R.string.nc_owner); + //userType = NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_owner); //break; case 2: - userType = NextcloudTalkApplication.getSharedApplication().getString(R.string.nc_moderator); + userType = NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_moderator); break; case 3: - userType = NextcloudTalkApplication.getSharedApplication().getString(R.string.nc_user); + userType = NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_user); break; case 4: - userType = NextcloudTalkApplication.getSharedApplication().getString(R.string.nc_guest); + userType = NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_guest); break; case 5: - userType = NextcloudTalkApplication.getSharedApplication().getString(R.string.nc_following_link); + userType = NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_following_link); break; default: break; @@ -218,7 +218,7 @@ public class UserItem extends AbstractFlexibleItem if (!holder.contactMentionId.getText().equals(userType)) { holder.contactMentionId.setText(userType); - holder.contactMentionId.setTextColor(NextcloudTalkApplication.getSharedApplication().getResources().getColor(R.color.colorPrimary)); + holder.contactMentionId.setTextColor(NextcloudTalkApplication.Companion.getSharedApplication().getResources().getColor(R.color.colorPrimary)); } } } diff --git a/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicIncomingTextMessageViewHolder.java b/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicIncomingTextMessageViewHolder.java index 547a5eed1..c65295683 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicIncomingTextMessageViewHolder.java +++ b/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicIncomingTextMessageViewHolder.java @@ -82,7 +82,7 @@ public class MagicIncomingTextMessageViewHolder public MagicIncomingTextMessageViewHolder(View itemView) { super(itemView); ButterKnife.bind(this, itemView); - NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); + NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); this.itemView = itemView; } @@ -103,8 +103,8 @@ public class MagicIncomingTextMessageViewHolder messageUserAvatarView.setVisibility(View.VISIBLE); if (message.getActorType().equals("guests")) { TextDrawable drawable = TextDrawable.builder().beginConfig().bold() - .endConfig().buildRound(String.valueOf(messageAuthor.getText().charAt(0)), NextcloudTalkApplication - .getSharedApplication().getResources().getColor(R.color.nc_grey)); + .endConfig().buildRound(String.valueOf(messageAuthor.getText().charAt(0)) + , NextcloudTalkApplication.Companion.getSharedApplication().getResources().getColor(R.color.nc_grey)); messageUserAvatarView.getHierarchy().setPlaceholderImage(drawable); } else if (message.getActorType().equals("bots") && message.getActorId().equals("changelog")) { messageUserAvatarView.setController(null); @@ -139,7 +139,7 @@ public class MagicIncomingTextMessageViewHolder HashMap> messageParameters = message.getMessageParameters(); - Context context = NextcloudTalkApplication.getSharedApplication().getApplicationContext(); + Context context = NextcloudTalkApplication.Companion.getSharedApplication().getApplicationContext(); itemView.setSelected(false); messageTimeView.setTextColor(context.getResources().getColor(R.color.warm_grey_four)); diff --git a/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicOutcomingTextMessageViewHolder.java b/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicOutcomingTextMessageViewHolder.java index 9d8b886e0..6e41ad6fd 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicOutcomingTextMessageViewHolder.java +++ b/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicOutcomingTextMessageViewHolder.java @@ -66,7 +66,7 @@ public class MagicOutcomingTextMessageViewHolder extends MessageHolders.Outcomin public MagicOutcomingTextMessageViewHolder(View itemView) { super(itemView); ButterKnife.bind(this, itemView); - NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); + NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); this.itemView = itemView; } @@ -128,7 +128,7 @@ public class MagicOutcomingTextMessageViewHolder extends MessageHolders.Outcomin itemView.setSelected(true); } - Resources resources = NextcloudTalkApplication.getSharedApplication().getResources(); + Resources resources = NextcloudTalkApplication.Companion.getSharedApplication().getResources(); if (message.isGrouped) { Drawable bubbleDrawable = DisplayUtils.getMessageSelector(resources.getColor(R.color.colorPrimary), resources.getColor(R.color.transparent), diff --git a/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicPreviewMessageViewHolder.java b/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicPreviewMessageViewHolder.java index 44eef2b4a..ef8f1ed4a 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicPreviewMessageViewHolder.java +++ b/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicPreviewMessageViewHolder.java @@ -70,7 +70,7 @@ public class MagicPreviewMessageViewHolder extends MessageHolders.IncomingImageM public MagicPreviewMessageViewHolder(View itemView) { super(itemView); ButterKnife.bind(this, itemView); - NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); + NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); } @SuppressLint("SetTextI18n") @@ -99,7 +99,7 @@ public class MagicPreviewMessageViewHolder extends MessageHolders.IncomingImageM messageText.setText(message.getSelectedIndividualHashMap().get("name")); DisplayUtils.setClickableString(message.getSelectedIndividualHashMap().get("name"), message.getSelectedIndividualHashMap().get("link"), messageText); if (message.getSelectedIndividualHashMap().containsKey("mimetype")) { - image.getHierarchy().setPlaceholderImage(context.getDrawable(DrawableUtils.getDrawableResourceIdForMimeType(message.getSelectedIndividualHashMap().get("mimetype")))); + image.getHierarchy().setPlaceholderImage(context.getDrawable(DrawableUtils.INSTANCE.getDrawableResourceIdForMimeType(message.getSelectedIndividualHashMap().get("mimetype")))); } else { fetchFileInformation("/" + message.getSelectedIndividualHashMap().get("path"), message.getActiveUser()); } @@ -109,14 +109,14 @@ public class MagicPreviewMessageViewHolder extends MessageHolders.IncomingImageM String accountString = message.getActiveUser().getUsername() + "@" + message.getActiveUser().getBaseUrl().replace("https://", "").replace("http://", ""); - if (AccountUtils.canWeOpenFilesApp(context, accountString)) { + if (AccountUtils.INSTANCE.canWeOpenFilesApp(context, accountString)) { Intent filesAppIntent = new Intent(Intent.ACTION_VIEW, null); final ComponentName componentName = new ComponentName(context.getString(R.string.nc_import_accounts_from), "com.owncloud.android.ui.activity.FileDisplayActivity"); filesAppIntent.setComponent(componentName); filesAppIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); filesAppIntent.setPackage(context.getString(R.string.nc_import_accounts_from)); - filesAppIntent.putExtra(BundleKeys.KEY_ACCOUNT, accountString); - filesAppIntent.putExtra(BundleKeys.KEY_FILE_ID, message.getSelectedIndividualHashMap().get("id")); + filesAppIntent.putExtra(BundleKeys.INSTANCE.getKEY_ACCOUNT(), accountString); + filesAppIntent.putExtra(BundleKeys.INSTANCE.getKEY_FILE_ID(), message.getSelectedIndividualHashMap().get("id")); context.startActivity(filesAppIntent); } else { Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(message.getSelectedIndividualHashMap().get("link"))); @@ -163,7 +163,7 @@ public class MagicPreviewMessageViewHolder extends MessageHolders.IncomingImageM if (davResponse.getData() != null) { List browserFileList = (List) davResponse.getData(); if (!browserFileList.isEmpty()) { - new Handler(context.getMainLooper()).post(() -> image.getHierarchy().setPlaceholderImage(context.getDrawable(DrawableUtils.getDrawableResourceIdForMimeType(browserFileList.get(0).getMimeType())))); + new Handler(context.getMainLooper()).post(() -> image.getHierarchy().setPlaceholderImage(context.getDrawable(DrawableUtils.INSTANCE.getDrawableResourceIdForMimeType(browserFileList.get(0).getMimeType())))); } } } diff --git a/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicSystemMessageViewHolder.java b/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicSystemMessageViewHolder.java index ffef89eab..c1ec285a0 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicSystemMessageViewHolder.java +++ b/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicSystemMessageViewHolder.java @@ -49,14 +49,14 @@ public class MagicSystemMessageViewHolder extends MessageHolders.IncomingTextMes public MagicSystemMessageViewHolder(View itemView) { super(itemView); - NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); + NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); } @Override public void onBind(ChatMessage message) { super.onBind(message); - Resources resources = NextcloudTalkApplication.getSharedApplication().getResources(); + Resources resources = NextcloudTalkApplication.Companion.getSharedApplication().getResources(); int normalColor; int pressedColor; int mentionYouColor; diff --git a/app/src/main/java/com/nextcloud/talk/api/NcApi.java b/app/src/main/java/com/nextcloud/talk/api/NcApi.java index ef7963ef2..84a9afc56 100644 --- a/app/src/main/java/com/nextcloud/talk/api/NcApi.java +++ b/app/src/main/java/com/nextcloud/talk/api/NcApi.java @@ -31,8 +31,8 @@ import com.nextcloud.talk.models.json.notifications.NotificationOverall; import com.nextcloud.talk.models.json.participants.AddParticipantOverall; import com.nextcloud.talk.models.json.participants.ParticipantsOverall; import com.nextcloud.talk.models.json.push.PushRegistrationOverall; -import com.nextcloud.talk.models.json.rooms.RoomOverall; -import com.nextcloud.talk.models.json.rooms.RoomsOverall; +import com.nextcloud.talk.models.json.conversations.RoomOverall; +import com.nextcloud.talk.models.json.conversations.RoomsOverall; import com.nextcloud.talk.models.json.signaling.SignalingOverall; import com.nextcloud.talk.models.json.signaling.settings.SignalingSettingsOverall; import com.nextcloud.talk.models.json.userprofile.UserProfileOverall; @@ -311,4 +311,11 @@ public interface NcApi { @Field("path") String remotePath, @Field("shareWith") String roomToken, @Field("shareType") String shareType); + + @FormUrlEncoded + @PUT + Observable setLobbyForConversation(@Header("Authorization") String authorization, + @Url String url, @Field("state") Integer state, + @Field("timer") Long timer); + } diff --git a/app/src/main/java/com/nextcloud/talk/application/NextcloudTalkApplication.java b/app/src/main/java/com/nextcloud/talk/application/NextcloudTalkApplication.java deleted file mode 100644 index b060fa6d7..000000000 --- a/app/src/main/java/com/nextcloud/talk/application/NextcloudTalkApplication.java +++ /dev/null @@ -1,239 +0,0 @@ -/* - * - * Nextcloud Talk application - * - * @author Mario Danic - * Copyright (C) 2017 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 . - */ -package com.nextcloud.talk.application; - -import android.content.Context; -import android.os.Build; -import android.util.Log; -import androidx.emoji.bundled.BundledEmojiCompatConfig; -import androidx.emoji.text.EmojiCompat; - -import androidx.appcompat.app.AppCompatDelegate; -import androidx.lifecycle.LifecycleObserver; -import androidx.multidex.MultiDex; -import androidx.multidex.MultiDexApplication; -import androidx.work.ExistingPeriodicWorkPolicy; -import androidx.work.OneTimeWorkRequest; -import androidx.work.PeriodicWorkRequest; -import androidx.work.WorkManager; -import autodagger.AutoComponent; -import autodagger.AutoInjector; -import com.facebook.cache.disk.DiskCacheConfig; -import com.facebook.drawee.backends.pipeline.Fresco; -import com.facebook.imagepipeline.core.ImagePipelineConfig; -import com.nextcloud.talk.BuildConfig; -import com.nextcloud.talk.components.filebrowser.webdav.DavUtils; -import com.nextcloud.talk.dagger.modules.BusModule; -import com.nextcloud.talk.dagger.modules.ContextModule; -import com.nextcloud.talk.dagger.modules.DatabaseModule; -import com.nextcloud.talk.dagger.modules.RestModule; -import com.nextcloud.talk.jobs.AccountRemovalWorker; -import com.nextcloud.talk.jobs.CapabilitiesWorker; -import com.nextcloud.talk.jobs.PushRegistrationWorker; -import com.nextcloud.talk.jobs.SignalingSettingsWorker; -import com.nextcloud.talk.utils.ClosedInterfaceImpl; -import com.nextcloud.talk.utils.DeviceUtils; -import com.nextcloud.talk.utils.DisplayUtils; -import com.nextcloud.talk.utils.OkHttpNetworkFetcherWithCache; -import com.nextcloud.talk.utils.database.arbitrarystorage.ArbitraryStorageModule; -import com.nextcloud.talk.utils.database.user.UserModule; -import com.nextcloud.talk.utils.preferences.AppPreferences; -import com.nextcloud.talk.webrtc.MagicWebRTCUtils; -import com.vanniktech.emoji.EmojiManager; -import com.vanniktech.emoji.googlecompat.GoogleCompatEmojiProvider; - -import de.cotech.hw.SecurityKeyManager; -import de.cotech.hw.SecurityKeyManagerConfig; -import okhttp3.OkHttpClient; -import org.conscrypt.Conscrypt; -import org.webrtc.PeerConnectionFactory; -import org.webrtc.voiceengine.WebRtcAudioManager; -import org.webrtc.voiceengine.WebRtcAudioUtils; - -import javax.inject.Inject; -import javax.inject.Singleton; -import java.security.Security; -import java.util.concurrent.TimeUnit; - -@AutoComponent( - modules = { - BusModule.class, - ContextModule.class, - DatabaseModule.class, - RestModule.class, - UserModule.class, - ArbitraryStorageModule.class, - } -) - -@Singleton -@AutoInjector(NextcloudTalkApplication.class) -public class NextcloudTalkApplication extends MultiDexApplication implements LifecycleObserver { - private static final String TAG = NextcloudTalkApplication.class.getSimpleName(); - //region Singleton - protected static NextcloudTalkApplication sharedApplication; - //region Fields (components) - protected NextcloudTalkApplicationComponent componentApplication; - - @Inject - AppPreferences appPreferences; - @Inject - OkHttpClient okHttpClient; - //endregion - - public static NextcloudTalkApplication getSharedApplication() { - return sharedApplication; - } - //endregion - - //region private methods - private void initializeWebRtc() { - try { - if (MagicWebRTCUtils.HARDWARE_AEC_BLACKLIST.contains(Build.MODEL)) { - WebRtcAudioUtils.setWebRtcBasedAcousticEchoCanceler(true); - } - - if (!MagicWebRTCUtils.OPEN_SL_ES_WHITELIST.contains(Build.MODEL)) { - WebRtcAudioManager.setBlacklistDeviceForOpenSLESUsage(true); - } - - - PeerConnectionFactory.initialize(PeerConnectionFactory.InitializationOptions.builder(this) - .setEnableVideoHwAcceleration(MagicWebRTCUtils.shouldEnableVideoHardwareAcceleration()) - .createInitializationOptions()); - } catch (UnsatisfiedLinkError e) { - Log.w(TAG, e); - } - } - - //endregion - - //region Overridden methods - @Override - public void onCreate() { - sharedApplication = this; - - SecurityKeyManager securityKeyManager = SecurityKeyManager.getInstance(); - SecurityKeyManagerConfig securityKeyConfig = new SecurityKeyManagerConfig.Builder() - .setEnableDebugLogging(BuildConfig.DEBUG) - .build(); - securityKeyManager.init(this, securityKeyConfig); - - initializeWebRtc(); - DisplayUtils.useCompatVectorIfNeeded(); - buildComponent(); - DavUtils.registerCustomFactories(); - - componentApplication.inject(this); - - setAppTheme(appPreferences.getTheme()); - super.onCreate(); - - ImagePipelineConfig imagePipelineConfig = ImagePipelineConfig.newBuilder(this) - .setNetworkFetcher(new OkHttpNetworkFetcherWithCache(okHttpClient)) - .setMainDiskCacheConfig(DiskCacheConfig.newBuilder(this) - .setMaxCacheSize(0) - .setMaxCacheSizeOnLowDiskSpace(0) - .setMaxCacheSizeOnVeryLowDiskSpace(0) - .build()) - .build(); - - Fresco.initialize(this, imagePipelineConfig); - Security.insertProviderAt(Conscrypt.newProvider(), 1); - - new ClosedInterfaceImpl().providerInstallerInstallIfNeededAsync(); - DeviceUtils.ignoreSpecialBatteryFeatures(); - - OneTimeWorkRequest pushRegistrationWork = new OneTimeWorkRequest.Builder(PushRegistrationWorker.class).build(); - OneTimeWorkRequest accountRemovalWork = new OneTimeWorkRequest.Builder(AccountRemovalWorker.class).build(); - PeriodicWorkRequest periodicCapabilitiesUpdateWork = new PeriodicWorkRequest.Builder(CapabilitiesWorker.class, - 12, TimeUnit.HOURS).build(); - OneTimeWorkRequest capabilitiesUpdateWork = new OneTimeWorkRequest.Builder(CapabilitiesWorker.class).build(); - OneTimeWorkRequest signalingSettingsWork = new OneTimeWorkRequest.Builder(SignalingSettingsWorker.class).build(); - - WorkManager.getInstance().enqueue(pushRegistrationWork); - WorkManager.getInstance().enqueue(accountRemovalWork); - WorkManager.getInstance().enqueue(capabilitiesUpdateWork); - WorkManager.getInstance().enqueue(signalingSettingsWork); - WorkManager.getInstance().enqueueUniquePeriodicWork("DailyCapabilitiesUpdateWork", ExistingPeriodicWorkPolicy.REPLACE, periodicCapabilitiesUpdateWork); - - final EmojiCompat.Config config = new BundledEmojiCompatConfig(this); - config.setReplaceAll(true); - EmojiCompat emojiCompat = EmojiCompat.init(config); - - EmojiManager.install(new GoogleCompatEmojiProvider(emojiCompat)); - } - - @Override - public void onTerminate() { - super.onTerminate(); - sharedApplication = null; - } - - //endregion - - //region Getters - public NextcloudTalkApplicationComponent getComponentApplication() { - return componentApplication; - } - //endregion - - //region Setters - public static void setAppTheme(String theme) { - switch (theme) { - case "night_no": - AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); - break; - case "night_yes": - AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); - break; - case "battery_saver": - AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY); - break; - default: - // will be "follow_system" only for now - AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM); - - } - } - //endregion - - - - //region Protected methods - protected void buildComponent() { - componentApplication = DaggerNextcloudTalkApplicationComponent.builder() - .busModule(new BusModule()) - .contextModule(new ContextModule(getApplicationContext())) - .databaseModule(new DatabaseModule()) - .restModule(new RestModule(getApplicationContext())) - .userModule(new UserModule()) - .arbitraryStorageModule(new ArbitraryStorageModule()) - .build(); - } - - @Override - protected void attachBaseContext(Context base) { - super.attachBaseContext(base); - MultiDex.install(this); - } - //endregion -} diff --git a/app/src/main/java/com/nextcloud/talk/application/NextcloudTalkApplication.kt b/app/src/main/java/com/nextcloud/talk/application/NextcloudTalkApplication.kt new file mode 100644 index 000000000..a78be6018 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/application/NextcloudTalkApplication.kt @@ -0,0 +1,217 @@ +/* + * + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 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 . + */ +package com.nextcloud.talk.application + +import android.content.Context +import android.os.Build +import android.util.Log +import androidx.emoji.bundled.BundledEmojiCompatConfig +import androidx.emoji.text.EmojiCompat + +import androidx.appcompat.app.AppCompatDelegate +import androidx.lifecycle.LifecycleObserver +import androidx.multidex.MultiDex +import androidx.multidex.MultiDexApplication +import androidx.work.ExistingPeriodicWorkPolicy +import androidx.work.OneTimeWorkRequest +import androidx.work.PeriodicWorkRequest +import androidx.work.WorkManager +import autodagger.AutoComponent +import autodagger.AutoInjector +import com.facebook.cache.disk.DiskCacheConfig +import com.facebook.drawee.backends.pipeline.Fresco +import com.facebook.imagepipeline.core.ImagePipelineConfig +import com.nextcloud.talk.BuildConfig +import com.nextcloud.talk.components.filebrowser.webdav.DavUtils +import com.nextcloud.talk.dagger.modules.BusModule +import com.nextcloud.talk.dagger.modules.ContextModule +import com.nextcloud.talk.dagger.modules.DatabaseModule +import com.nextcloud.talk.dagger.modules.RestModule +import com.nextcloud.talk.jobs.AccountRemovalWorker +import com.nextcloud.talk.jobs.CapabilitiesWorker +import com.nextcloud.talk.jobs.PushRegistrationWorker +import com.nextcloud.talk.jobs.SignalingSettingsWorker +import com.nextcloud.talk.utils.ClosedInterfaceImpl +import com.nextcloud.talk.utils.DeviceUtils +import com.nextcloud.talk.utils.DisplayUtils +import com.nextcloud.talk.utils.OkHttpNetworkFetcherWithCache +import com.nextcloud.talk.utils.database.arbitrarystorage.ArbitraryStorageModule +import com.nextcloud.talk.utils.database.user.UserModule +import com.nextcloud.talk.utils.preferences.AppPreferences +import com.nextcloud.talk.webrtc.MagicWebRTCUtils +import com.vanniktech.emoji.EmojiManager +import com.vanniktech.emoji.googlecompat.GoogleCompatEmojiProvider + +import de.cotech.hw.SecurityKeyManager +import de.cotech.hw.SecurityKeyManagerConfig +import okhttp3.OkHttpClient +import org.conscrypt.Conscrypt +import org.webrtc.PeerConnectionFactory +import org.webrtc.voiceengine.WebRtcAudioManager +import org.webrtc.voiceengine.WebRtcAudioUtils + +import javax.inject.Inject +import javax.inject.Singleton +import java.security.Security +import java.util.concurrent.TimeUnit + +@AutoComponent(modules = [BusModule::class, ContextModule::class, DatabaseModule::class, RestModule::class, UserModule::class, ArbitraryStorageModule::class]) +@Singleton +@AutoInjector(NextcloudTalkApplication::class) +class NextcloudTalkApplication : MultiDexApplication(), LifecycleObserver { + //region Fields (components) + lateinit var componentApplication: NextcloudTalkApplicationComponent + private set + //endregion + + //region Getters + + @Inject + lateinit var appPreferences: AppPreferences + @Inject + lateinit var okHttpClient: OkHttpClient + //endregion + + //region private methods + private fun initializeWebRtc() { + try { + if (MagicWebRTCUtils.HARDWARE_AEC_BLACKLIST.contains(Build.MODEL)) { + WebRtcAudioUtils.setWebRtcBasedAcousticEchoCanceler(true) + } + + if (!MagicWebRTCUtils.OPEN_SL_ES_WHITELIST.contains(Build.MODEL)) { + WebRtcAudioManager.setBlacklistDeviceForOpenSLESUsage(true) + } + + + PeerConnectionFactory.initialize(PeerConnectionFactory.InitializationOptions.builder(this) + .setEnableVideoHwAcceleration(MagicWebRTCUtils.shouldEnableVideoHardwareAcceleration()) + .createInitializationOptions()) + } catch (e: UnsatisfiedLinkError) { + Log.w(TAG, e) + } + + } + + //endregion + + //region Overridden methods + override fun onCreate() { + sharedApplication = this + + val securityKeyManager = SecurityKeyManager.getInstance() + val securityKeyConfig = SecurityKeyManagerConfig.Builder() + .setEnableDebugLogging(BuildConfig.DEBUG) + .build() + securityKeyManager.init(this, securityKeyConfig) + + initializeWebRtc() + DisplayUtils.useCompatVectorIfNeeded() + buildComponent() + DavUtils.registerCustomFactories() + + componentApplication.inject(this) + + setAppTheme(appPreferences!!.theme) + super.onCreate() + + val imagePipelineConfig = ImagePipelineConfig.newBuilder(this) + .setNetworkFetcher(OkHttpNetworkFetcherWithCache(okHttpClient)) + .setMainDiskCacheConfig(DiskCacheConfig.newBuilder(this) + .setMaxCacheSize(0) + .setMaxCacheSizeOnLowDiskSpace(0) + .setMaxCacheSizeOnVeryLowDiskSpace(0) + .build()) + .build() + + Fresco.initialize(this, imagePipelineConfig) + Security.insertProviderAt(Conscrypt.newProvider(), 1) + + ClosedInterfaceImpl().providerInstallerInstallIfNeededAsync() + DeviceUtils.ignoreSpecialBatteryFeatures() + + val pushRegistrationWork = OneTimeWorkRequest.Builder(PushRegistrationWorker::class.java).build() + val accountRemovalWork = OneTimeWorkRequest.Builder(AccountRemovalWorker::class.java).build() + val periodicCapabilitiesUpdateWork = PeriodicWorkRequest.Builder(CapabilitiesWorker::class.java, + 12, TimeUnit.HOURS).build() + val capabilitiesUpdateWork = OneTimeWorkRequest.Builder(CapabilitiesWorker::class.java).build() + val signalingSettingsWork = OneTimeWorkRequest.Builder(SignalingSettingsWorker::class.java).build() + + WorkManager.getInstance().enqueue(pushRegistrationWork) + WorkManager.getInstance().enqueue(accountRemovalWork) + WorkManager.getInstance().enqueue(capabilitiesUpdateWork) + WorkManager.getInstance().enqueue(signalingSettingsWork) + WorkManager.getInstance().enqueueUniquePeriodicWork("DailyCapabilitiesUpdateWork", ExistingPeriodicWorkPolicy.REPLACE, periodicCapabilitiesUpdateWork) + + val config = BundledEmojiCompatConfig(this) + config.setReplaceAll(true) + val emojiCompat = EmojiCompat.init(config) + + EmojiManager.install(GoogleCompatEmojiProvider(emojiCompat)) + } + + override fun onTerminate() { + super.onTerminate() + sharedApplication = null + } + //endregion + + + //region Protected methods + protected fun buildComponent() { + componentApplication = DaggerNextcloudTalkApplicationComponent.builder() + .busModule(BusModule()) + .contextModule(ContextModule(applicationContext)) + .databaseModule(DatabaseModule()) + .restModule(RestModule(applicationContext)) + .userModule(UserModule()) + .arbitraryStorageModule(ArbitraryStorageModule()) + .build() + } + + override fun attachBaseContext(base: Context) { + super.attachBaseContext(base) + MultiDex.install(this) + } + + companion object { + private val TAG = NextcloudTalkApplication::class.java.simpleName + //region Singleton + //endregion + + var sharedApplication: NextcloudTalkApplication? = null + protected set + //endregion + + //region Setters + fun setAppTheme(theme: String) { + when (theme) { + "night_no" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO) + "night_yes" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES) + "battery_saver" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY) + else -> + // will be "follow_system" only for now + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM) + } + } + } + //endregion +} diff --git a/app/src/main/java/com/nextcloud/talk/components/filebrowser/adapters/items/BrowserFileItem.java b/app/src/main/java/com/nextcloud/talk/components/filebrowser/adapters/items/BrowserFileItem.java index 38b7aa862..4ad6fa10a 100644 --- a/app/src/main/java/com/nextcloud/talk/components/filebrowser/adapters/items/BrowserFileItem.java +++ b/app/src/main/java/com/nextcloud/talk/components/filebrowser/adapters/items/BrowserFileItem.java @@ -63,7 +63,7 @@ public class BrowserFileItem extends AbstractFlexibleItem + * Copyright (C) 2017-2019 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 @@ -25,7 +25,6 @@ import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; import android.content.Intent; -import android.graphics.Color; import android.graphics.PorterDuff; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; @@ -36,17 +35,23 @@ import android.text.InputFilter; import android.text.TextUtils; import android.text.TextWatcher; import android.util.Log; -import android.view.*; +import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; import android.widget.AbsListView; import android.widget.EditText; import android.widget.ImageButton; import android.widget.ProgressBar; +import android.widget.RelativeLayout; +import android.widget.TextView; + import androidx.annotation.NonNull; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; -import autodagger.AutoInjector; -import butterknife.BindView; -import butterknife.OnClick; + import com.bluelinelabs.conductor.RouterTransaction; import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler; import com.bluelinelabs.conductor.changehandler.VerticalChangeHandler; @@ -72,13 +77,19 @@ import com.nextcloud.talk.models.json.call.Call; import com.nextcloud.talk.models.json.call.CallOverall; import com.nextcloud.talk.models.json.chat.ChatMessage; import com.nextcloud.talk.models.json.chat.ChatOverall; +import com.nextcloud.talk.models.json.conversations.Conversation; +import com.nextcloud.talk.models.json.conversations.RoomOverall; +import com.nextcloud.talk.models.json.conversations.RoomsOverall; import com.nextcloud.talk.models.json.generic.GenericOverall; import com.nextcloud.talk.models.json.mention.Mention; -import com.nextcloud.talk.models.json.rooms.Conversation; -import com.nextcloud.talk.models.json.rooms.RoomOverall; -import com.nextcloud.talk.models.json.rooms.RoomsOverall; import com.nextcloud.talk.presenters.MentionAutocompletePresenter; -import com.nextcloud.talk.utils.*; +import com.nextcloud.talk.utils.ApiUtils; +import com.nextcloud.talk.utils.ConductorRemapping; +import com.nextcloud.talk.utils.DateUtils; +import com.nextcloud.talk.utils.DisplayUtils; +import com.nextcloud.talk.utils.KeyboardUtils; +import com.nextcloud.talk.utils.MagicCharPolicy; +import com.nextcloud.talk.utils.NotificationUtils; import com.nextcloud.talk.utils.bundle.BundleKeys; import com.nextcloud.talk.utils.database.user.UserUtils; import com.nextcloud.talk.utils.preferences.AppPreferences; @@ -103,21 +114,32 @@ import com.vanniktech.emoji.listeners.OnEmojiClickListener; import com.vanniktech.emoji.listeners.OnEmojiPopupDismissListener; import com.vanniktech.emoji.listeners.OnEmojiPopupShownListener; import com.webianks.library.PopupBubble; -import io.reactivex.Observer; -import io.reactivex.android.schedulers.AndroidSchedulers; -import io.reactivex.disposables.Disposable; -import io.reactivex.schedulers.Schedulers; + import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; import org.parceler.Parcels; -import retrofit2.HttpException; -import retrofit2.Response; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.TimeUnit; import javax.inject.Inject; -import java.lang.reflect.Field; -import java.util.*; -import java.util.concurrent.TimeUnit; + +import autodagger.AutoInjector; +import butterknife.BindView; +import butterknife.OnClick; +import io.reactivex.Observer; +import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.disposables.Disposable; +import io.reactivex.schedulers.Schedulers; +import retrofit2.HttpException; +import retrofit2.Response; @AutoInjector(NextcloudTalkApplication.class) public class ChatController extends BaseController implements MessagesListAdapter.OnLoadMoreListener, @@ -146,6 +168,10 @@ public class ChatController extends BaseController implements MessagesListAdapte ProgressBar loadingProgressBar; @BindView(R.id.smileyButton) ImageButton smileyButton; + @BindView(R.id.lobby_view) + RelativeLayout lobbyView; + @BindView(R.id.lobby_text_view) + TextView conversationLobbyText; private List disposableList = new ArrayList<>(); private String conversationName; private String roomToken; @@ -167,41 +193,39 @@ public class ChatController extends BaseController implements MessagesListAdapte private String roomId; private boolean voiceOnly; private boolean isFirstMessagesProcessing = true; - private boolean havePulledFutureBefore = false; private boolean isLeavingForConversation; private boolean isLinkPreviewAllowed; private boolean wasDetached; private EmojiPopup emojiPopup; private CharSequence myFirstMessage; - - private boolean waitingForFutureResponse = false; + private boolean checkingLobbyStatus; private MenuItem conversationInfoMenuItem; private MenuItem conversationVoiceCallMenuItem; private MenuItem conversationVideoMenuItem; - private boolean readOnlyCheckPerformed; - private MagicWebSocketInstance magicWebSocketInstance; + private Handler lobbyTimerHandler; + public ChatController(Bundle args) { super(args); setHasOptionsMenu(true); - NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); + NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); - this.conversationUser = args.getParcelable(BundleKeys.KEY_USER_ENTITY); - this.roomId = args.getString(BundleKeys.KEY_ROOM_ID, ""); - this.roomToken = args.getString(BundleKeys.KEY_ROOM_TOKEN, ""); + this.conversationUser = args.getParcelable(BundleKeys.INSTANCE.getKEY_USER_ENTITY()); + this.roomId = args.getString(BundleKeys.INSTANCE.getKEY_ROOM_ID(), ""); + this.roomToken = args.getString(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN(), ""); - if (args.containsKey(BundleKeys.KEY_ACTIVE_CONVERSATION)) { - this.currentConversation = Parcels.unwrap(args.getParcelable(BundleKeys.KEY_ACTIVE_CONVERSATION)); + if (args.containsKey(BundleKeys.INSTANCE.getKEY_ACTIVE_CONVERSATION())) { + this.currentConversation = Parcels.unwrap(args.getParcelable(BundleKeys.INSTANCE.getKEY_ACTIVE_CONVERSATION())); if (currentConversation != null) { conversationName = currentConversation.getDisplayName(); } } - this.roomPassword = args.getString(BundleKeys.KEY_CONVERSATION_PASSWORD, ""); + this.roomPassword = args.getString(BundleKeys.INSTANCE.getKEY_CONVERSATION_PASSWORD(), ""); if (conversationUser.getUserId().equals("?")) { credentials = null; @@ -209,14 +233,19 @@ public class ChatController extends BaseController implements MessagesListAdapte credentials = ApiUtils.getCredentials(conversationUser.getUsername(), conversationUser.getToken()); } - if (args.containsKey(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL)) { - this.startCallFromNotification = args.getBoolean(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL); + if (args.containsKey(BundleKeys.INSTANCE.getKEY_FROM_NOTIFICATION_START_CALL())) { + this.startCallFromNotification = args.getBoolean(BundleKeys.INSTANCE.getKEY_FROM_NOTIFICATION_START_CALL()); } - this.voiceOnly = args.getBoolean(BundleKeys.KEY_CALL_VOICE_ONLY, false); + this.voiceOnly = args.getBoolean(BundleKeys.INSTANCE.getKEY_CALL_VOICE_ONLY(), false); } private void getRoomInfo() { + boolean shouldRepeat = conversationUser.hasSpreedFeatureCapability("webinary-lobby"); + if (shouldRepeat) { + checkingLobbyStatus = true; + } + ncApi.getRoom(credentials, ApiUtils.getRoom(conversationUser.getBaseUrl(), roomToken)) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) @@ -228,12 +257,28 @@ public class ChatController extends BaseController implements MessagesListAdapte @Override public void onNext(RoomOverall roomOverall) { - currentConversation = roomOverall.getOcs().getData(); - conversationName = currentConversation.getDisplayName(); - setTitle(); + Conversation oldConversation = null; - setupMentionAutocomplete(); - joinRoomWithPassword(); + if (currentConversation != null) { + oldConversation = currentConversation; + } + + currentConversation = roomOverall.getOcs().getData(); + + if (oldConversation == null) { + conversationName = currentConversation.getDisplayName(); + setTitle(); + setupMentionAutocomplete(); + } + + checkReadOnlyState(); + if (oldConversation == null || (!oldConversation.getLobbyState().equals(currentConversation.getLobbyState()) || !oldConversation.getLobbyTimer().equals(currentConversation.getLobbyTimer()))) { + checkLobbyState(oldConversation != null && (!oldConversation.getLobbyState().equals(currentConversation.getLobbyState()))); + } + + if (oldConversation == null) { + joinRoomWithPassword(); + } } @@ -244,7 +289,13 @@ public class ChatController extends BaseController implements MessagesListAdapte @Override public void onComplete() { + if (shouldRepeat) { + if (lobbyTimerHandler == null) { + lobbyTimerHandler = new Handler(); + } + lobbyTimerHandler.postDelayed(() -> getRoomInfo(), 5000); + } } }); } @@ -265,6 +316,8 @@ public class ChatController extends BaseController implements MessagesListAdapte if (roomId.equals(conversation.getRoomId())) { roomToken = conversation.getToken(); currentConversation = conversation; + checkLobbyState(false); + checkReadOnlyState(); conversationName = conversation.getDisplayName(); setTitle(); break; @@ -377,10 +430,10 @@ public class ChatController extends BaseController implements MessagesListAdapte InputFilter[] filters = new InputFilter[1]; - int lenghtFilter = conversationUser.getMessageMaxLength(); + int lengthFilter = conversationUser.getMessageMaxLength(); - filters[0] = new InputFilter.LengthFilter(lenghtFilter); + filters[0] = new InputFilter.LengthFilter(lengthFilter); messageInput.setFilters(filters); messageInput.addTextChangedListener(new TextWatcher() { @@ -391,8 +444,8 @@ public class ChatController extends BaseController implements MessagesListAdapte @Override public void onTextChanged(CharSequence s, int start, int before, int count) { - if (s.length() >= lenghtFilter) { - messageInput.setError(String.format(Objects.requireNonNull(getResources()).getString(R.string.nc_limit_hit), Integer.toString(lenghtFilter))); + if (s.length() >= lengthFilter) { + messageInput.setError(String.format(Objects.requireNonNull(getResources()).getString(R.string.nc_limit_hit), Integer.toString(lengthFilter))); } else { messageInput.setError(null); } @@ -433,6 +486,10 @@ public class ChatController extends BaseController implements MessagesListAdapte getActivity().findViewById(R.id.toolbar).setOnClickListener(v -> showConversationInfoScreen()); } + if (currentConversation != null) { + checkLobbyState(false); + } + if (adapterWasNull) { // we're starting if (TextUtils.isEmpty(roomToken)) { @@ -448,19 +505,16 @@ public class ChatController extends BaseController implements MessagesListAdapte private void checkReadOnlyState() { - if (currentConversation != null && !readOnlyCheckPerformed) { - - readOnlyCheckPerformed = true; - if (currentConversation.getConversationReadOnlyState() != null && currentConversation.getConversationReadOnlyState().equals(Conversation.ConversationReadOnlyState.CONVERSATION_READ_ONLY)) { - messageInput.setHint(R.string.nc_readonly_hint); + if (currentConversation != null) { + if (currentConversation.shouldShowLobby(conversationUser) || (currentConversation.getConversationReadOnlyState() != null && currentConversation.getConversationReadOnlyState().equals(Conversation.ConversationReadOnlyState.CONVERSATION_READ_ONLY))) { conversationVoiceCallMenuItem.getIcon().setAlpha(99); conversationVideoMenuItem.getIcon().setAlpha(99); + if (messageInputView != null) { + messageInputView.setVisibility(View.GONE); + } - setChildrenState(messageInputView, false); } else { - messageInput.setHint(""); - if (conversationVoiceCallMenuItem != null) { conversationVoiceCallMenuItem.getIcon().setAlpha(255); } @@ -468,38 +522,57 @@ public class ChatController extends BaseController implements MessagesListAdapte if (conversationVideoMenuItem != null) { conversationVideoMenuItem.getIcon().setAlpha(255); } - - setChildrenState(messageInputView, true); + + if (messageInputView != null) { + if (currentConversation.shouldShowLobby(conversationUser)) { + messageInputView.setVisibility(View.GONE); + } else { + messageInputView.setVisibility(View.VISIBLE); + } + } } } } - private void setChildrenState(View view, boolean enabled) { - if (view.getId() != R.id.messageSendButton) { - view.setEnabled(enabled); - } + private void checkLobbyState(boolean lobbyStateChanged) { + if (currentConversation != null) { - if (enabled) { - view.setAlpha(1.0f); - } else { - view.setAlpha(0.38f); - } + if (!checkingLobbyStatus) { + getRoomInfo(); + } - if (view instanceof ViewGroup) { - ViewGroup viewGroup = (ViewGroup) view; - for (int i = 0; i < viewGroup.getChildCount(); i++) { - View child = viewGroup.getChildAt(i); - setChildrenState(child, enabled); + if (currentConversation.shouldShowLobby(conversationUser)) { + lobbyView.setVisibility(View.VISIBLE); + messagesListView.setVisibility(View.GONE); + messageInputView.setVisibility(View.GONE); + loadingProgressBar.setVisibility(View.GONE); + + if (currentConversation.getLobbyTimer() != null && currentConversation.getLobbyTimer() != 0) { + conversationLobbyText.setText(String.format(getResources().getString(R.string.nc_lobby_waiting_with_date), DateUtils.INSTANCE.getLocalDateStringFromTimestampForLobby(currentConversation.getLobbyTimer()))); + } else { + conversationLobbyText.setText(R.string.nc_lobby_waiting); + } + } else { + lobbyView.setVisibility(View.GONE); + messagesListView.setVisibility(View.VISIBLE); + messageInput.setVisibility(View.VISIBLE); + if (lobbyStateChanged) { + loadingProgressBar.setVisibility(View.VISIBLE); + if (isFirstMessagesProcessing) { + pullChatMessages(0); + } else { + pullChatMessages(1); + } + } } } } - private void showBrowserScreen(BrowserController.BrowserType browserType) { Bundle bundle = new Bundle(); - bundle.putParcelable(BundleKeys.KEY_BROWSER_TYPE, Parcels.wrap(browserType)); - bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, Parcels.wrap(conversationUser)); - bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomToken); + bundle.putParcelable(BundleKeys.INSTANCE.getKEY_BROWSER_TYPE(), Parcels.wrap(browserType)); + bundle.putParcelable(BundleKeys.INSTANCE.getKEY_USER_ENTITY(), Parcels.wrap(conversationUser)); + bundle.putString(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN(), roomToken); getRouter().pushController((RouterTransaction.with(new BrowserController(bundle)) .pushChangeHandler(new VerticalChangeHandler()) .popChangeHandler(new VerticalChangeHandler()))); @@ -507,8 +580,8 @@ public class ChatController extends BaseController implements MessagesListAdapte private void showConversationInfoScreen() { Bundle bundle = new Bundle(); - bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, conversationUser); - bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomToken); + bundle.putParcelable(BundleKeys.INSTANCE.getKEY_USER_ENTITY(), conversationUser); + bundle.putString(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN(), roomToken); getRouter().pushController((RouterTransaction.with(new ConversationInfoController(bundle)) .pushChangeHandler(new HorizontalChangeHandler()) .popChangeHandler(new HorizontalChangeHandler()))); @@ -689,7 +762,8 @@ public class ChatController extends BaseController implements MessagesListAdapte currentCall = callOverall.getOcs().getData(); ApplicationWideCurrentRoomHolder.getInstance().setSession(currentCall.getSessionId()); startPing(); - havePulledFutureBefore = false; + + checkLobbyState(false); setupWebsocket(); @@ -751,6 +825,12 @@ public class ChatController extends BaseController implements MessagesListAdapte public void onNext(GenericOverall genericOverall) { dispose(); + checkingLobbyStatus = false; + + if (lobbyTimerHandler != null) { + lobbyTimerHandler.removeCallbacksAndMessages(null); + } + if (magicWebSocketInstance != null && currentCall != null) { magicWebSocketInstance.joinRoomWithRoomTokenAndSession("", currentCall.getSessionId()); } @@ -858,23 +938,14 @@ public class ChatController extends BaseController implements MessagesListAdapte return; } - if (havePulledFutureBefore && lookIntoFuture == 1 && magicWebSocketInstance != null ) { + if (currentConversation.shouldShowLobby(conversationUser)) { return; } if (lookIntoFuture > 0) { - if (waitingForFutureResponse) { - return; - } else { - waitingForFutureResponse = true; - } - lookingIntoFuture = true; - havePulledFutureBefore = true; } - lookIntoFuture = lookIntoFuture > 0 ? 1 : 0; - Map fieldMap = new HashMap<>(); fieldMap.put("lookIntoFuture", lookIntoFuture); fieldMap.put("limit", 25); @@ -906,19 +977,17 @@ public class ChatController extends BaseController implements MessagesListAdapte @Override public void onNext(Response response) { - waitingForFutureResponse = false; processMessages(response, true); } @Override public void onError(Throwable e) { - waitingForFutureResponse = false; } @Override public void onComplete() { - if (magicWebSocketInstance == null) { + if (currentConversation.shouldShowLobby(conversationUser)) { pullChatMessages(1); } } @@ -1116,7 +1185,6 @@ public class ChatController extends BaseController implements MessagesListAdapte @Override public void onPrepareOptionsMenu(@NonNull Menu menu) { super.onPrepareOptionsMenu(menu); - if (conversationUser.hasSpreedFeatureCapability("read-only-rooms")) { checkReadOnlyState(); } @@ -1167,14 +1235,14 @@ public class ChatController extends BaseController implements MessagesListAdapte private Intent getIntentForCall(boolean isVoiceOnlyCall) { if (currentConversation != null) { Bundle bundle = new Bundle(); - bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomToken); - bundle.putString(BundleKeys.KEY_ROOM_ID, roomId); - bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, conversationUser); - bundle.putString(BundleKeys.KEY_CONVERSATION_PASSWORD, roomPassword); - bundle.putString(BundleKeys.KEY_MODIFIED_BASE_URL, conversationUser.getBaseUrl()); + bundle.putString(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN(), roomToken); + bundle.putString(BundleKeys.INSTANCE.getKEY_ROOM_ID(), roomId); + bundle.putParcelable(BundleKeys.INSTANCE.getKEY_USER_ENTITY(), conversationUser); + bundle.putString(BundleKeys.INSTANCE.getKEY_CONVERSATION_PASSWORD(), roomPassword); + bundle.putString(BundleKeys.INSTANCE.getKEY_MODIFIED_BASE_URL(), conversationUser.getBaseUrl()); if (isVoiceOnlyCall) { - bundle.putBoolean(BundleKeys.KEY_CALL_VOICE_ONLY, true); + bundle.putBoolean(BundleKeys.INSTANCE.getKEY_CALL_VOICE_ONLY(), true); } if (getActivity() != null) { @@ -1215,8 +1283,10 @@ public class ChatController extends BaseController implements MessagesListAdapte @Subscribe(threadMode = ThreadMode.BACKGROUND) public void onMessageEvent(WebSocketCommunicationEvent webSocketCommunicationEvent) { + /* switch (webSocketCommunicationEvent.getType()) { case "refreshChat": + if (webSocketCommunicationEvent.getHashMap().get(BundleKeys.KEY_INTERNAL_USER_ID).equals(Long.toString(conversationUser.getId()))) { if (roomToken.equals(webSocketCommunicationEvent.getHashMap().get(BundleKeys.KEY_ROOM_TOKEN))) { pullChatMessages(2); @@ -1224,7 +1294,7 @@ public class ChatController extends BaseController implements MessagesListAdapte } break; default: - } + }*/ } @Subscribe(threadMode = ThreadMode.BACKGROUND) @@ -1248,16 +1318,16 @@ public class ChatController extends BaseController implements MessagesListAdapte public void onNext(RoomOverall roomOverall) { Intent conversationIntent = new Intent(getActivity(), MagicCallActivity.class); Bundle bundle = new Bundle(); - bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, conversationUser); - bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomOverall.getOcs().getData().getToken()); - bundle.putString(BundleKeys.KEY_ROOM_ID, roomOverall.getOcs().getData().getRoomId()); + bundle.putParcelable(BundleKeys.INSTANCE.getKEY_USER_ENTITY(), conversationUser); + bundle.putString(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN(), roomOverall.getOcs().getData().getToken()); + bundle.putString(BundleKeys.INSTANCE.getKEY_ROOM_ID(), roomOverall.getOcs().getData().getRoomId()); if (conversationUser.hasSpreedFeatureCapability("chat-v2")) { - bundle.putParcelable(BundleKeys.KEY_ACTIVE_CONVERSATION, + bundle.putParcelable(BundleKeys.INSTANCE.getKEY_ACTIVE_CONVERSATION(), Parcels.wrap(roomOverall.getOcs().getData())); conversationIntent.putExtras(bundle); - ConductorRemapping.remapChatController(getRouter(), conversationUser.getId(), + ConductorRemapping.INSTANCE.remapChatController(getRouter(), conversationUser.getId(), roomOverall.getOcs().getData().getToken(), bundle, false); } else { diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ContactsController.java b/app/src/main/java/com/nextcloud/talk/controllers/ContactsController.java index ca85ba3a0..45172bc97 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ContactsController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/ContactsController.java @@ -64,8 +64,8 @@ import com.nextcloud.talk.models.database.UserEntity; import com.nextcloud.talk.models.json.autocomplete.AutocompleteOverall; import com.nextcloud.talk.models.json.autocomplete.AutocompleteUser; import com.nextcloud.talk.models.json.participants.Participant; -import com.nextcloud.talk.models.json.rooms.Conversation; -import com.nextcloud.talk.models.json.rooms.RoomOverall; +import com.nextcloud.talk.models.json.conversations.Conversation; +import com.nextcloud.talk.models.json.conversations.RoomOverall; import com.nextcloud.talk.models.json.sharees.Sharee; import com.nextcloud.talk.models.json.sharees.ShareesOverall; import com.nextcloud.talk.utils.ApiUtils; @@ -170,7 +170,7 @@ public class ContactsController extends BaseController implements SearchView.OnQ public ContactsController(Bundle args) { super(args); setHasOptionsMenu(true); - if (args.containsKey(BundleKeys.KEY_NEW_CONVERSATION)) { + if (args.containsKey(BundleKeys.INSTANCE.getKEY_NEW_CONVERSATION())) { isNewConversationView = true; } @@ -196,7 +196,7 @@ public class ContactsController extends BaseController implements SearchView.OnQ @Override protected void onViewBound(@NonNull View view) { super.onViewBound(view); - NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); + NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); currentUser = userUtils.getCurrentUser(); @@ -259,15 +259,15 @@ public class ContactsController extends BaseController implements SearchView.OnQ public void onNext(RoomOverall roomOverall) { Intent conversationIntent = new Intent(getActivity(), MagicCallActivity.class); Bundle bundle = new Bundle(); - bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, currentUser); - bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomOverall.getOcs().getData().getToken()); - bundle.putString(BundleKeys.KEY_ROOM_ID, roomOverall.getOcs().getData().getRoomId()); + bundle.putParcelable(BundleKeys.INSTANCE.getKEY_USER_ENTITY(), currentUser); + bundle.putString(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN(), roomOverall.getOcs().getData().getToken()); + bundle.putString(BundleKeys.INSTANCE.getKEY_ROOM_ID(), roomOverall.getOcs().getData().getRoomId()); if (currentUser.hasSpreedFeatureCapability("chat-v2")) { - bundle.putParcelable(BundleKeys.KEY_ACTIVE_CONVERSATION, + bundle.putParcelable(BundleKeys.INSTANCE.getKEY_ACTIVE_CONVERSATION(), Parcels.wrap(roomOverall.getOcs().getData())); - ConductorRemapping.remapChatController(getRouter(), currentUser.getId(), + ConductorRemapping.INSTANCE.remapChatController(getRouter(), currentUser.getId(), roomOverall.getOcs().getData().getToken(), bundle, true); } else { conversationIntent.putExtras(bundle); @@ -306,10 +306,10 @@ public class ContactsController extends BaseController implements SearchView.OnQ ArrayList groupIdsArray = new ArrayList<>(selectedGroupIds); - bundle.putParcelable(BundleKeys.KEY_CONVERSATION_TYPE, Parcels.wrap(roomType)); - bundle.putStringArrayList(BundleKeys.KEY_INVITED_PARTICIPANTS, userIdsArray); - bundle.putStringArrayList(BundleKeys.KEY_INVITED_GROUP, groupIdsArray); - bundle.putInt(BundleKeys.KEY_OPERATION_CODE, 11); + bundle.putParcelable(BundleKeys.INSTANCE.getKEY_CONVERSATION_TYPE(), Parcels.wrap(roomType)); + bundle.putStringArrayList(BundleKeys.INSTANCE.getKEY_INVITED_PARTICIPANTS(), userIdsArray); + bundle.putStringArrayList(BundleKeys.INSTANCE.getKEY_INVITED_GROUP(), groupIdsArray); + bundle.putInt(BundleKeys.INSTANCE.getKEY_OPERATION_CODE(), 11); prepareAndShowBottomSheetWithBundle(bundle, true); } } @@ -839,16 +839,16 @@ public class ContactsController extends BaseController implements SearchView.OnQ if (getActivity() != null) { Intent conversationIntent = new Intent(getActivity(), MagicCallActivity.class); Bundle bundle = new Bundle(); - bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, currentUser); - bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomOverall.getOcs().getData().getToken()); - bundle.putString(BundleKeys.KEY_ROOM_ID, roomOverall.getOcs().getData().getRoomId()); + bundle.putParcelable(BundleKeys.INSTANCE.getKEY_USER_ENTITY(), currentUser); + bundle.putString(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN(), roomOverall.getOcs().getData().getToken()); + bundle.putString(BundleKeys.INSTANCE.getKEY_ROOM_ID(), roomOverall.getOcs().getData().getRoomId()); conversationIntent.putExtras(bundle); if (currentUser.hasSpreedFeatureCapability("chat-v2")) { - bundle.putParcelable(BundleKeys.KEY_ACTIVE_CONVERSATION, + bundle.putParcelable(BundleKeys.INSTANCE.getKEY_ACTIVE_CONVERSATION(), Parcels.wrap(roomOverall.getOcs().getData())); - ConductorRemapping.remapChatController(getRouter(), currentUser.getId(), + ConductorRemapping.INSTANCE.remapChatController(getRouter(), currentUser.getId(), roomOverall.getOcs().getData().getToken(), bundle, true); } else { startActivity(conversationIntent); @@ -914,7 +914,7 @@ public class ContactsController extends BaseController implements SearchView.OnQ @OnClick(R.id.joinConversationViaLinkRelativeLayout) void joinConversationViaLink() { Bundle bundle = new Bundle(); - bundle.putInt(BundleKeys.KEY_OPERATION_CODE, 10); + bundle.putInt(BundleKeys.INSTANCE.getKEY_OPERATION_CODE(), 10); prepareAndShowBottomSheetWithBundle(bundle, true); } diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ConversationInfoController.java b/app/src/main/java/com/nextcloud/talk/controllers/ConversationInfoController.java deleted file mode 100644 index 5f8d4350c..000000000 --- a/app/src/main/java/com/nextcloud/talk/controllers/ConversationInfoController.java +++ /dev/null @@ -1,507 +0,0 @@ -/* - * 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.app.Activity; -import android.content.Context; -import android.graphics.drawable.Drawable; -import android.graphics.drawable.LayerDrawable; -import android.os.Bundle; -import android.text.TextUtils; -import android.view.LayoutInflater; -import android.view.MenuItem; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ProgressBar; -import android.widget.TextView; -import androidx.annotation.NonNull; -import androidx.recyclerview.widget.RecyclerView; -import androidx.work.Data; -import androidx.work.OneTimeWorkRequest; -import androidx.work.WorkManager; -import autodagger.AutoInjector; -import butterknife.BindView; -import butterknife.OnClick; -import com.bluelinelabs.conductor.RouterTransaction; -import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler; -import com.facebook.drawee.backends.pipeline.Fresco; -import com.facebook.drawee.interfaces.DraweeController; -import com.facebook.drawee.view.SimpleDraweeView; -import com.nextcloud.talk.R; -import com.nextcloud.talk.adapters.items.UserItem; -import com.nextcloud.talk.api.NcApi; -import com.nextcloud.talk.application.NextcloudTalkApplication; -import com.nextcloud.talk.controllers.base.BaseController; -import com.nextcloud.talk.jobs.DeleteConversationWorker; -import com.nextcloud.talk.jobs.LeaveConversationWorker; -import com.nextcloud.talk.models.database.UserEntity; -import com.nextcloud.talk.models.json.converters.EnumNotificationLevelConverter; -import com.nextcloud.talk.models.json.participants.Participant; -import com.nextcloud.talk.models.json.participants.ParticipantsOverall; -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.DisplayUtils; -import com.nextcloud.talk.utils.bundle.BundleKeys; -import com.nextcloud.talk.utils.preferences.preferencestorage.DatabaseStorageModule; -import com.yarolegovich.lovelydialog.LovelySaveStateHandler; -import com.yarolegovich.lovelydialog.LovelyStandardDialog; -import com.yarolegovich.mp.*; -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; - -import javax.inject.Inject; -import java.util.ArrayList; -import java.util.List; - - -@AutoInjector(NextcloudTalkApplication.class) -public class ConversationInfoController extends BaseController { - - private static final int ID_DELETE_CONVERSATION_DIALOG = 0; - - @BindView(R.id.notification_settings) - MaterialPreferenceScreen materialPreferenceScreen; - @BindView(R.id.progressBar) - ProgressBar progressBar; - @BindView(R.id.conversation_info_message_notifications) - MaterialChoicePreference messageNotificationLevel; - @BindView(R.id.conversation_info_name) - MaterialPreferenceCategory nameCategoryView; - @BindView(R.id.avatar_image) - SimpleDraweeView conversationAvatarImageView; - @BindView(R.id.display_name_text) - TextView conversationDisplayName; - @BindView(R.id.participants_list_category) - MaterialPreferenceCategory participantsListCategory; - @BindView(R.id.recycler_view) - RecyclerView recyclerView; - @BindView(R.id.deleteConversationAction) - MaterialStandardPreference deleteConversationAction; - @BindView(R.id.leaveConversationAction) - MaterialStandardPreference leaveConversationAction; - @BindView(R.id.ownOptions) - MaterialPreferenceCategory ownOptionsCategory; - @BindView(R.id.muteCalls) - MaterialSwitchPreference muteCalls; - - @Inject - NcApi ncApi; - @Inject - Context context; - - private String conversationToken; - private UserEntity conversationUser; - private String credentials; - private Disposable roomDisposable; - private Disposable participantsDisposable; - - private Conversation conversation; - - private FlexibleAdapter adapter; - private List recyclerViewItems = new ArrayList<>(); - - private LovelySaveStateHandler saveStateHandler; - - public ConversationInfoController(Bundle args) { - super(args); - setHasOptionsMenu(true); - NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); - conversationUser = args.getParcelable(BundleKeys.KEY_USER_ENTITY); - conversationToken = args.getString(BundleKeys.KEY_ROOM_TOKEN); - 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.controller_conversation_info, container, false); - } - - @Override - protected void onViewBound(@NonNull View view) { - super.onViewBound(view); - - if (saveStateHandler == null) { - saveStateHandler = new LovelySaveStateHandler(); - } - - materialPreferenceScreen.setStorageModule(new DatabaseStorageModule(conversationUser, conversationToken)); - if (adapter == null) { - fetchRoomInfo(); - } else { - loadConversationAvatar(); - materialPreferenceScreen.setVisibility(View.VISIBLE); - nameCategoryView.setVisibility(View.VISIBLE); - participantsListCategory.setVisibility(View.VISIBLE); - progressBar.setVisibility(View.GONE); - conversationDisplayName.setText(conversation.getDisplayName()); - setupAdapter(); - } - } - - private void showLovelyDialog(int dialogId, Bundle savedInstanceState) { - switch (dialogId) { - case ID_DELETE_CONVERSATION_DIALOG: - showDeleteConversationDialog(savedInstanceState); - break; - default: - break; - } - } - - - private void showDeleteConversationDialog(Bundle savedInstanceState) { - if (getActivity() != null) { - new LovelyStandardDialog(getActivity(), LovelyStandardDialog.ButtonLayout.HORIZONTAL) - .setTopColorRes(R.color.nc_darkRed) - .setIcon(DisplayUtils.getTintedDrawable(context.getResources(), - R.drawable.ic_delete_black_24dp, R.color.bg_default)) - .setPositiveButtonColor(context.getResources().getColor(R.color.nc_darkRed)) - .setTitle(R.string.nc_delete_call) - .setMessage(conversation.getDeleteWarningMessage()) - .setPositiveButton(R.string.nc_delete, new View.OnClickListener() { - @Override - public void onClick(View v) { - deleteConversation(); - } - }) - .setNegativeButton(R.string.nc_cancel, null) - .setInstanceStateHandler(ID_DELETE_CONVERSATION_DIALOG, saveStateHandler) - .setSavedInstanceState(savedInstanceState) - .show(); - } - } - - @Override - protected void onSaveViewState(@NonNull View view, @NonNull Bundle outState) { - saveStateHandler.saveInstanceState(outState); - super.onSaveViewState(view, outState); - } - - @Override - protected void onRestoreViewState(@NonNull View view, @NonNull Bundle savedViewState) { - super.onRestoreViewState(view, savedViewState); - if (LovelySaveStateHandler.wasDialogOnScreen(savedViewState)) { - //Dialog won't be restarted automatically, so we need to call this method. - //Each dialog knows how to restore its state - showLovelyDialog(LovelySaveStateHandler.getSavedDialogId(savedViewState), savedViewState); - } - } - - private void setupAdapter() { - Activity activity; - - if ((activity = getActivity()) != null) { - if (adapter == null) { - adapter = new FlexibleAdapter<>(recyclerViewItems, activity, true); - } - - if (recyclerView != null) { - SmoothScrollLinearLayoutManager layoutManager = - new SmoothScrollLinearLayoutManager(activity); - recyclerView.setLayoutManager(layoutManager); - recyclerView.setHasFixedSize(true); - recyclerView.setAdapter(adapter); - } - } - } - - private void handleParticipants(List participants) { - UserItem userItem; - Participant participant; - - recyclerViewItems = new ArrayList<>(); - UserItem ownUserItem = null; - - for (int i = 0; i < participants.size(); i++) { - participant = participants.get(i); - userItem = new UserItem(participant, conversationUser, null); - userItem.setEnabled(!participant.getSessionId().equals("0")); - if (!TextUtils.isEmpty(participant.getUserId()) && participant.getUserId().equals(conversationUser.getUserId())) { - ownUserItem = userItem; - userItem.getModel().setSessionId("-1"); - userItem.setEnabled(true); - } else { - recyclerViewItems.add(userItem); - } - } - - - if (ownUserItem != null) { - recyclerViewItems.add(0, ownUserItem); - } - - setupAdapter(); - - if (participantsListCategory != null) { - participantsListCategory.setVisibility(View.VISIBLE); - } - adapter.notifyDataSetChanged(); - } - - @Override - protected String getTitle() { - return getResources().getString(R.string.nc_conversation_menu_conversation_info); - } - - private void getListOfParticipants() { - ncApi.getPeersForCall(credentials, ApiUtils.getUrlForParticipants(conversationUser.getBaseUrl(), conversationToken)) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Observer() { - @Override - public void onSubscribe(Disposable d) { - participantsDisposable = d; - } - - @Override - public void onNext(ParticipantsOverall participantsOverall) { - handleParticipants(participantsOverall.getOcs().getData()); - } - - @Override - public void onError(Throwable e) { - - } - - @Override - public void onComplete() { - participantsDisposable.dispose(); - } - }); - - } - - @OnClick(R.id.leaveConversationAction) - void leaveConversation() { - Data data; - if ((data = getWorkerData()) != null) { - OneTimeWorkRequest leaveConversationWorker = - new OneTimeWorkRequest.Builder(LeaveConversationWorker.class).setInputData(data).build(); - WorkManager.getInstance().enqueue(leaveConversationWorker); - popTwoLastControllers(); - } - } - - private void deleteConversation() { - Data data; - if ((data = getWorkerData()) != null) { - OneTimeWorkRequest deleteConversationWorker = - new OneTimeWorkRequest.Builder(DeleteConversationWorker.class).setInputData(data).build(); - WorkManager.getInstance().enqueue(deleteConversationWorker); - popTwoLastControllers(); - } - } - - @OnClick(R.id.deleteConversationAction) - void deleteConversationClick() { - showDeleteConversationDialog(null); - } - - private Data getWorkerData() { - if (!TextUtils.isEmpty(conversationToken) && conversationUser != null) { - Data.Builder data = new Data.Builder(); - data.putString(BundleKeys.KEY_ROOM_TOKEN, conversationToken); - data.putLong(BundleKeys.KEY_INTERNAL_USER_ID, conversationUser.getId()); - return data.build(); - } - - return null; - } - - private void popTwoLastControllers() { - List backstack = getRouter().getBackstack(); - backstack = backstack.subList(0, backstack.size() - 2); - getRouter().setBackstack(backstack, new HorizontalChangeHandler()); - } - - private void fetchRoomInfo() { - ncApi.getRoom(credentials, ApiUtils.getRoom(conversationUser.getBaseUrl(), conversationToken)) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Observer() { - @Override - public void onSubscribe(Disposable d) { - roomDisposable = d; - } - - @Override - public void onNext(RoomOverall roomOverall) { - conversation = roomOverall.getOcs().getData(); - - if (isAttached() && (!isBeingDestroyed() || !isDestroyed())) { - ownOptionsCategory.setVisibility(View.VISIBLE); - - if (leaveConversationAction != null) { - if (!conversation.canLeave(conversationUser)) { - leaveConversationAction.setVisibility(View.GONE); - } else { - leaveConversationAction.setVisibility(View.VISIBLE); - } - } - - if (!conversation.canModerate(conversationUser)) { - deleteConversationAction.setVisibility(View.GONE); - } else { - deleteConversationAction.setVisibility(View.VISIBLE); - } - - if (Conversation.ConversationType.ROOM_SYSTEM.equals(conversation.getType())) { - muteCalls.setVisibility(View.GONE); - } - - getListOfParticipants(); - - if (progressBar != null) { - progressBar.setVisibility(View.GONE); - } - - if (nameCategoryView != null) { - nameCategoryView.setVisibility(View.VISIBLE); - } - - if (conversationDisplayName != null) { - conversationDisplayName.setText(conversation.getDisplayName()); - } - - loadConversationAvatar(); - - if (conversationUser.hasSpreedFeatureCapability("notification-levels")) { - if (messageNotificationLevel != null) { - 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; - } - - if (messageNotificationLevel != null) { - messageNotificationLevel.setValue(stringValue); - } - } else { - setProperNotificationValue(conversation); - } - } else { - if (messageNotificationLevel != null) { - messageNotificationLevel.setEnabled(false); - messageNotificationLevel.setAlpha(0.38f); - } - setProperNotificationValue(conversation); - } - - materialPreferenceScreen.setVisibility(View.VISIBLE); - } - } - - @Override - public void onError(Throwable e) { - - } - - @Override - public void onComplete() { - roomDisposable.dispose(); - } - }); - } - - private void setProperNotificationValue(Conversation conversation) { - if (messageNotificationLevel != null) { - if (conversation.getType().equals(Conversation.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL)) { - // hack to see if we get mentioned always or just on mention - if (conversationUser.hasSpreedFeatureCapability("mention-flag")) { - messageNotificationLevel.setValue("always"); - } else { - messageNotificationLevel.setValue("mention"); - } - } else { - messageNotificationLevel.setValue("mention"); - } - } - } - - private void loadConversationAvatar() { - if (conversationAvatarImageView != null) { - switch (conversation.getType()) { - case ROOM_TYPE_ONE_TO_ONE_CALL: - if (!TextUtils.isEmpty(conversation.getName())) { - DraweeController draweeController = Fresco.newDraweeControllerBuilder() - .setOldController(conversationAvatarImageView.getController()) - .setAutoPlayAnimations(true) - .setImageRequest(DisplayUtils.getImageRequestForUrl(ApiUtils.getUrlForAvatarWithName(conversationUser.getBaseUrl(), - conversation.getName(), R.dimen.avatar_size_big), null)) - .build(); - conversationAvatarImageView.setController(draweeController); - } - break; - case ROOM_GROUP_CALL: - conversationAvatarImageView.getHierarchy().setPlaceholderImage(DisplayUtils - .getRoundedBitmapDrawableFromVectorDrawableResource(getResources(), - R.drawable.ic_people_group_white_24px)); - break; - case ROOM_PUBLIC_CALL: - conversationAvatarImageView.getHierarchy().setPlaceholderImage(DisplayUtils - .getRoundedBitmapDrawableFromVectorDrawableResource(getResources(), - R.drawable.ic_link_white_24px)); - break; - case ROOM_SYSTEM: - Drawable[] layers = new Drawable[2]; - layers[0] = context.getDrawable(R.drawable.ic_launcher_background); - layers[1] = context.getDrawable(R.drawable.ic_launcher_foreground); - LayerDrawable layerDrawable = new LayerDrawable(layers); - conversationAvatarImageView.getHierarchy().setPlaceholderImage(DisplayUtils.getRoundedDrawable(layerDrawable)); - - default: - break; - } - } - } -} diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ConversationInfoController.kt b/app/src/main/java/com/nextcloud/talk/controllers/ConversationInfoController.kt new file mode 100644 index 000000000..d0fd74503 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/controllers/ConversationInfoController.kt @@ -0,0 +1,552 @@ +/* + * 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.content.Context +import android.graphics.drawable.Drawable +import android.graphics.drawable.LayerDrawable +import android.os.Bundle +import android.text.TextUtils +import android.view.LayoutInflater +import android.view.MenuItem +import android.view.View +import android.view.ViewGroup +import android.widget.ProgressBar +import android.widget.TextView +import androidx.appcompat.widget.SwitchCompat +import androidx.recyclerview.widget.RecyclerView +import androidx.work.Data +import androidx.work.OneTimeWorkRequest +import androidx.work.WorkManager +import autodagger.AutoInjector +import butterknife.BindView +import butterknife.OnClick +import com.afollestad.materialdialogs.LayoutMode.WRAP_CONTENT +import com.afollestad.materialdialogs.MaterialDialog +import com.afollestad.materialdialogs.bottomsheets.BottomSheet +import com.afollestad.materialdialogs.datetime.dateTimePicker +import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler +import com.facebook.drawee.backends.pipeline.Fresco +import com.facebook.drawee.view.SimpleDraweeView +import com.nextcloud.talk.R +import com.nextcloud.talk.adapters.items.UserItem +import com.nextcloud.talk.api.NcApi +import com.nextcloud.talk.application.NextcloudTalkApplication +import com.nextcloud.talk.controllers.base.BaseController +import com.nextcloud.talk.jobs.DeleteConversationWorker +import com.nextcloud.talk.jobs.LeaveConversationWorker +import com.nextcloud.talk.models.database.UserEntity +import com.nextcloud.talk.models.json.conversations.Conversation +import com.nextcloud.talk.models.json.conversations.RoomOverall +import com.nextcloud.talk.models.json.converters.EnumNotificationLevelConverter +import com.nextcloud.talk.models.json.generic.GenericOverall +import com.nextcloud.talk.models.json.participants.Participant +import com.nextcloud.talk.models.json.participants.ParticipantsOverall +import com.nextcloud.talk.utils.ApiUtils +import com.nextcloud.talk.utils.DateUtils +import com.nextcloud.talk.utils.DisplayUtils +import com.nextcloud.talk.utils.bundle.BundleKeys +import com.nextcloud.talk.utils.preferences.preferencestorage.DatabaseStorageModule +import com.yarolegovich.lovelydialog.LovelySaveStateHandler +import com.yarolegovich.lovelydialog.LovelyStandardDialog +import com.yarolegovich.mp.* +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 +import java.util.* +import javax.inject.Inject + + +@AutoInjector(NextcloudTalkApplication::class) +class ConversationInfoController(args: Bundle) : BaseController(args) { + + @BindView(R.id.notification_settings) + lateinit var materialPreferenceScreen: MaterialPreferenceScreen + @BindView(R.id.progressBar) + lateinit var progressBar: ProgressBar + @BindView(R.id.conversation_info_message_notifications) + lateinit var messageNotificationLevel: MaterialChoicePreference + @BindView(R.id.webinar_settings) + lateinit var conversationInfoWebinar: MaterialPreferenceScreen + @BindView(R.id.conversation_info_lobby) + lateinit var conversationInfoLobby: MaterialSwitchPreference + @BindView(R.id.conversation_info_name) + lateinit var nameCategoryView: MaterialPreferenceCategory + @BindView(R.id.start_time_preferences) + lateinit var startTimeView: MaterialStandardPreference + @BindView(R.id.avatar_image) + lateinit var conversationAvatarImageView: SimpleDraweeView + @BindView(R.id.display_name_text) + lateinit var conversationDisplayName: TextView + @BindView(R.id.participants_list_category) + lateinit var participantsListCategory: MaterialPreferenceCategory + @BindView(R.id.recycler_view) + lateinit var recyclerView: RecyclerView + @BindView(R.id.deleteConversationAction) + lateinit var deleteConversationAction: MaterialStandardPreference + @BindView(R.id.leaveConversationAction) + lateinit var leaveConversationAction: MaterialStandardPreference + @BindView(R.id.ownOptions) + lateinit var ownOptionsCategory: MaterialPreferenceCategory + @BindView(R.id.muteCalls) + lateinit var muteCalls: MaterialSwitchPreference + + @set:Inject + lateinit var ncApi: NcApi + @set:Inject + lateinit var context: Context + + private val conversationToken: String? + private val conversationUser: UserEntity? + private val credentials: String? + private var roomDisposable: Disposable? = null + private var participantsDisposable: Disposable? = null + + private var conversation: Conversation? = null + + private var adapter: FlexibleAdapter>? = null + private var recyclerViewItems: MutableList> = ArrayList() + + private var saveStateHandler: LovelySaveStateHandler? = null + + private val workerData: Data? + get() { + if (!TextUtils.isEmpty(conversationToken) && conversationUser != null) { + val data = Data.Builder() + data.putString(BundleKeys.KEY_ROOM_TOKEN, conversationToken) + data.putLong(BundleKeys.KEY_INTERNAL_USER_ID, conversationUser.id) + return data.build() + } + + return null + } + + init { + setHasOptionsMenu(true) + NextcloudTalkApplication.sharedApplication?.componentApplication?.inject(this) + conversationUser = args.getParcelable(BundleKeys.KEY_USER_ENTITY) + conversationToken = args.getString(BundleKeys.KEY_ROOM_TOKEN) + credentials = ApiUtils.getCredentials(conversationUser!!.username, conversationUser.token) + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + when (item.itemId) { + android.R.id.home -> { + router.popCurrentController() + return true + } + else -> return super.onOptionsItemSelected(item) + } + } + + override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { + return inflater.inflate(R.layout.controller_conversation_info, container, false) + } + + override fun onViewBound(view: View) { + super.onViewBound(view) + + if (saveStateHandler == null) { + saveStateHandler = LovelySaveStateHandler() + } + + val databaseStorageModule = DatabaseStorageModule(conversationUser!!, + conversationToken) + + materialPreferenceScreen.setStorageModule(databaseStorageModule) + conversationInfoWebinar.setStorageModule(databaseStorageModule) + + if (adapter == null) { + fetchRoomInfo() + } else { + loadConversationAvatar() + materialPreferenceScreen.visibility = View.VISIBLE + nameCategoryView.visibility = View.VISIBLE + participantsListCategory.visibility = View.VISIBLE + progressBar.visibility = View.GONE + conversationDisplayName.text = conversation!!.displayName + + setupWebinaryView() + setupAdapter() + } + } + + private fun setupWebinaryView() { + if (conversationUser!!.hasSpreedFeatureCapability("webinary-lobby") && (conversation!!.type + == Conversation.ConversationType.ROOM_GROUP_CALL || conversation!!.type == + Conversation.ConversationType.ROOM_PUBLIC_CALL) && conversation!!.canModerate(conversationUser)) { + conversationInfoWebinar.visibility = View.VISIBLE + + val isLobbyOpenToModeratorsOnly = conversation!!.lobbyState == Conversation.LobbyState.LOBBY_STATE_MODERATORS_ONLY + (conversationInfoLobby.findViewById(R.id.mp_checkable) as SwitchCompat) + .isChecked = isLobbyOpenToModeratorsOnly + + reconfigureLobbyTimerView() + + val currentTimeCalendar = Calendar.getInstance() + if (conversation!!.lobbyTimer != null && conversation!!.lobbyTimer != 0L) { + currentTimeCalendar.set(Calendar.MILLISECOND, (conversation!!.lobbyTimer * 1000).toInt()) + } + + startTimeView.setOnClickListener { + MaterialDialog(activity!!, BottomSheet(WRAP_CONTENT)).show { + dateTimePicker(minDateTime = Calendar.getInstance(), requireFutureDateTime = + true, currentDateTime = currentTimeCalendar, dateTimeCallback = { _, + dateTime -> + reconfigureLobbyTimerView(dateTime) + submitLobbyChanges() + }) + } + } + + (conversationInfoLobby.findViewById(R.id.mp_checkable) as SwitchCompat).setOnCheckedChangeListener { _, _ -> + reconfigureLobbyTimerView() + submitLobbyChanges() + } + } else { + conversationInfoWebinar.visibility = View.GONE + } + } + + fun reconfigureLobbyTimerView(dateTime: Calendar? = null) { + val isChecked = (conversationInfoLobby.findViewById(R.id.mp_checkable) as SwitchCompat).isChecked + + if (dateTime != null && isChecked) { + conversation!!.lobbyTimer = dateTime.timeInMillis / 1000 + } else if (!isChecked) { + conversation!!.lobbyTimer = 0 + } + + conversation!!.lobbyState = if (isChecked) Conversation.LobbyState + .LOBBY_STATE_MODERATORS_ONLY else Conversation.LobbyState.LOBBY_STATE_ALL_PARTICIPANTS + + if (conversation!!.lobbyTimer != null && conversation!!.lobbyTimer != java.lang.Long.MIN_VALUE && conversation!!.lobbyTimer != 0L) { + startTimeView.setSummary(DateUtils.getLocalDateStringFromTimestampForLobby(conversation!!.lobbyTimer)) + } else { + startTimeView.setSummary(R.string.nc_manual) + } + + if (isChecked) { + startTimeView.visibility = View.VISIBLE + } else { + startTimeView.visibility = View.GONE + } + } + + fun submitLobbyChanges() { + val state = if ((conversationInfoLobby.findViewById(R.id + .mp_checkable) as SwitchCompat).isChecked) 1 else 0 + ncApi.setLobbyForConversation(ApiUtils.getCredentials(conversationUser!!.username, + conversationUser.token), ApiUtils.getUrlForLobbyForConversation + (conversationUser.baseUrl, conversation!!.token), state, conversation!!.lobbyTimer) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(object : Observer { + override fun onComplete() { + } + + override fun onSubscribe(d: Disposable) { + } + + override fun onNext(t: GenericOverall) { + } + + override fun onError(e: Throwable) { + } + + }) + } + + private fun showLovelyDialog(dialogId: Int, savedInstanceState: Bundle) { + when (dialogId) { + ID_DELETE_CONVERSATION_DIALOG -> showDeleteConversationDialog(savedInstanceState) + else -> { + } + } + } + + + private fun showDeleteConversationDialog(savedInstanceState: Bundle?) { + if (activity != null) { + LovelyStandardDialog(activity, LovelyStandardDialog.ButtonLayout.HORIZONTAL) + .setTopColorRes(R.color.nc_darkRed) + .setIcon(DisplayUtils.getTintedDrawable(context!!.resources, + R.drawable.ic_delete_black_24dp, R.color.bg_default)) + .setPositiveButtonColor(context!!.resources.getColor(R.color.nc_darkRed)) + .setTitle(R.string.nc_delete_call) + .setMessage(conversation!!.deleteWarningMessage) + .setPositiveButton(R.string.nc_delete) { deleteConversation() } + .setNegativeButton(R.string.nc_cancel, null) + .setInstanceStateHandler(ID_DELETE_CONVERSATION_DIALOG, saveStateHandler!!) + .setSavedInstanceState(savedInstanceState) + .show() + } + } + + override fun onSaveViewState(view: View, outState: Bundle) { + saveStateHandler!!.saveInstanceState(outState) + super.onSaveViewState(view, outState) + } + + override fun onRestoreViewState(view: View, savedViewState: Bundle) { + super.onRestoreViewState(view, savedViewState) + if (LovelySaveStateHandler.wasDialogOnScreen(savedViewState)) { + //Dialog won't be restarted automatically, so we need to call this method. + //Each dialog knows how to restore its state + showLovelyDialog(LovelySaveStateHandler.getSavedDialogId(savedViewState), savedViewState) + } + } + + private fun setupAdapter() { + if (activity != null) { + if (adapter == null) { + adapter = FlexibleAdapter(recyclerViewItems, activity, true) + } + + val layoutManager = SmoothScrollLinearLayoutManager(activity) + recyclerView.layoutManager = layoutManager + recyclerView.setHasFixedSize(true) + recyclerView.adapter = adapter + } + } + + private fun handleParticipants(participants: List) { + var userItem: UserItem + var participant: Participant + + recyclerViewItems = ArrayList() + var ownUserItem: UserItem? = null + + for (i in participants.indices) { + participant = participants[i] + userItem = UserItem(participant, conversationUser, null) + userItem.isEnabled = participant.sessionId != "0" + if (!TextUtils.isEmpty(participant.userId) && participant.userId == conversationUser!!.userId) { + ownUserItem = userItem + userItem.model.sessionId = "-1" + userItem.isEnabled = true + } else { + recyclerViewItems.add(userItem) + } + } + + + if (ownUserItem != null) { + recyclerViewItems.add(0, ownUserItem) + } + + setupAdapter() + + participantsListCategory.visibility = View.VISIBLE + adapter!!.notifyDataSetChanged() + } + + override fun getTitle(): String? { + return resources!!.getString(R.string.nc_conversation_menu_conversation_info) + } + + private fun getListOfParticipants() { + ncApi!!.getPeersForCall(credentials, ApiUtils.getUrlForParticipants(conversationUser!!.baseUrl, conversationToken)) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(object : Observer { + override fun onSubscribe(d: Disposable) { + participantsDisposable = d + } + + override fun onNext(participantsOverall: ParticipantsOverall) { + handleParticipants(participantsOverall.ocs.data) + } + + override fun onError(e: Throwable) { + + } + + override fun onComplete() { + participantsDisposable!!.dispose() + } + }) + + } + + @OnClick(R.id.leaveConversationAction) + internal fun leaveConversation() { + workerData?.let { + WorkManager.getInstance().enqueue(OneTimeWorkRequest.Builder + (LeaveConversationWorker::class + .java).setInputData(it).build() + ) + popTwoLastControllers() + } + } + + private fun deleteConversation() { + workerData?.let { + WorkManager.getInstance().enqueue(OneTimeWorkRequest.Builder + (DeleteConversationWorker::class.java).setInputData(it).build()) + popTwoLastControllers() + } + } + + @OnClick(R.id.deleteConversationAction) + internal fun deleteConversationClick() { + showDeleteConversationDialog(null) + } + + private fun popTwoLastControllers() { + var backstack = router.backstack + backstack = backstack.subList(0, backstack.size - 2) + router.setBackstack(backstack, HorizontalChangeHandler()) + } + + private fun fetchRoomInfo() { + ncApi!!.getRoom(credentials, ApiUtils.getRoom(conversationUser!!.baseUrl, conversationToken)) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(object : Observer { + override fun onSubscribe(d: Disposable) { + roomDisposable = d + } + + override fun onNext(roomOverall: RoomOverall) { + conversation = roomOverall.ocs.data + + if (isAttached && (!isBeingDestroyed || !isDestroyed)) { + ownOptionsCategory.visibility = View.VISIBLE + + setupWebinaryView() + + if (!conversation!!.canLeave(conversationUser)) { + leaveConversationAction.visibility = View.GONE + } else { + leaveConversationAction.visibility = View.VISIBLE + } + + if (!conversation!!.canModerate(conversationUser)) { + deleteConversationAction.visibility = View.GONE + } else { + deleteConversationAction.visibility = View.VISIBLE + } + + if (Conversation.ConversationType.ROOM_SYSTEM == conversation!!.type) { + muteCalls.visibility = View.GONE + } + + getListOfParticipants() + + progressBar.visibility = View.GONE + + nameCategoryView.visibility = View.VISIBLE + + conversationDisplayName.text = conversation!!.displayName + + + loadConversationAvatar() + + if (conversationUser.hasSpreedFeatureCapability("notification-levels")) { + messageNotificationLevel.isEnabled = true + messageNotificationLevel.alpha = 1.0f + + if (conversation!!.notificationLevel != Conversation.NotificationLevel.DEFAULT) { + val stringValue: String = when (EnumNotificationLevelConverter().convertToInt(conversation!!.notificationLevel)) { + 1 -> "always" + 2 -> "mention" + 3 -> "never" + else -> "mention" + } + + messageNotificationLevel.value = stringValue + } else { + setProperNotificationValue(conversation) + } + } else { + messageNotificationLevel.isEnabled = false + messageNotificationLevel.alpha = 0.38f + setProperNotificationValue(conversation) + } + + materialPreferenceScreen.visibility = View.VISIBLE + } + } + + override fun onError(e: Throwable) { + + } + + override fun onComplete() { + roomDisposable!!.dispose() + } + }) + } + + private fun setProperNotificationValue(conversation: Conversation?) { + if (conversation!!.type == Conversation.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL) { + // hack to see if we get mentioned always or just on mention + if (conversationUser!!.hasSpreedFeatureCapability("mention-flag")) { + messageNotificationLevel.value = "always" + } else { + messageNotificationLevel.value = "mention" + } + } else { + messageNotificationLevel.value = "mention" + } + } + + private fun loadConversationAvatar() { + when (conversation!!.type) { + Conversation.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL -> if (!TextUtils.isEmpty + (conversation!!.name)) { + val draweeController = Fresco.newDraweeControllerBuilder() + .setOldController(conversationAvatarImageView.controller) + .setAutoPlayAnimations(true) + .setImageRequest(DisplayUtils.getImageRequestForUrl(ApiUtils.getUrlForAvatarWithName(conversationUser!!.baseUrl, + conversation!!.name, R.dimen.avatar_size_big), null)) + .build() + conversationAvatarImageView.controller = draweeController + } + Conversation.ConversationType.ROOM_GROUP_CALL -> conversationAvatarImageView.hierarchy.setPlaceholderImage(DisplayUtils + .getRoundedBitmapDrawableFromVectorDrawableResource(resources, + R.drawable.ic_people_group_white_24px)) + Conversation.ConversationType.ROOM_PUBLIC_CALL -> conversationAvatarImageView.hierarchy.setPlaceholderImage(DisplayUtils + .getRoundedBitmapDrawableFromVectorDrawableResource(resources, + R.drawable.ic_link_white_24px)) + Conversation.ConversationType.ROOM_SYSTEM -> { + val layers = arrayOfNulls(2) + layers[0] = context!!.getDrawable(R.drawable.ic_launcher_background) + layers[1] = context!!.getDrawable(R.drawable.ic_launcher_foreground) + val layerDrawable = LayerDrawable(layers) + conversationAvatarImageView.hierarchy.setPlaceholderImage(DisplayUtils.getRoundedDrawable(layerDrawable)) + } + + else -> { + } + } + } + + companion object { + + private const val ID_DELETE_CONVERSATION_DIALOG = 0 + } +} diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.java b/app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.java index 97788bacb..cbe252e70 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.java @@ -77,7 +77,7 @@ import com.nextcloud.talk.interfaces.ConversationMenuInterface; import com.nextcloud.talk.jobs.DeleteConversationWorker; import com.nextcloud.talk.models.database.UserEntity; import com.nextcloud.talk.models.json.participants.Participant; -import com.nextcloud.talk.models.json.rooms.Conversation; +import com.nextcloud.talk.models.json.conversations.Conversation; import com.nextcloud.talk.utils.ApiUtils; import com.nextcloud.talk.utils.ConductorRemapping; import com.nextcloud.talk.utils.DisplayUtils; @@ -184,7 +184,7 @@ public class ConversationsListController extends BaseController implements Searc @Override protected void onViewBound(@NonNull View view) { super.onViewBound(view); - NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); + NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); if (getActionBar() != null) { getActionBar().show(); @@ -462,7 +462,7 @@ public class ConversationsListController extends BaseController implements Searc private void showNewConversationsScreen() { Bundle bundle = new Bundle(); - bundle.putBoolean(BundleKeys.KEY_NEW_CONVERSATION, true); + bundle.putBoolean(BundleKeys.INSTANCE.getKEY_NEW_CONVERSATION(), true); getRouter().pushController((RouterTransaction.with(new ContactsController(bundle)) .pushChangeHandler(new HorizontalChangeHandler()) .popChangeHandler(new HorizontalChangeHandler()))); @@ -556,8 +556,8 @@ public class ConversationsListController extends BaseController implements Searc public void onMessageEvent(MoreMenuClickEvent moreMenuClickEvent) { Bundle bundle = new Bundle(); Conversation conversation = moreMenuClickEvent.getConversation(); - bundle.putParcelable(BundleKeys.KEY_ROOM, Parcels.wrap(conversation)); - bundle.putParcelable(BundleKeys.KEY_MENU_TYPE, Parcels.wrap(CallMenuController.MenuType.REGULAR)); + bundle.putParcelable(BundleKeys.INSTANCE.getKEY_ROOM(), Parcels.wrap(conversation)); + bundle.putParcelable(BundleKeys.INSTANCE.getKEY_MENU_TYPE(), Parcels.wrap(CallMenuController.MenuType.REGULAR)); prepareAndShowBottomSheetWithBundle(bundle, true); } @@ -612,20 +612,20 @@ public class ConversationsListController extends BaseController implements Searc Bundle bundle = new Bundle(); - bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, currentUser); - bundle.putString(BundleKeys.KEY_ROOM_TOKEN, conversation.getToken()); - bundle.putString(BundleKeys.KEY_ROOM_ID, conversation.getRoomId()); + bundle.putParcelable(BundleKeys.INSTANCE.getKEY_USER_ENTITY(), currentUser); + bundle.putString(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN(), conversation.getToken()); + bundle.putString(BundleKeys.INSTANCE.getKEY_ROOM_ID(), conversation.getRoomId()); if (conversation.hasPassword && (conversation.participantType.equals(Participant.ParticipantType.GUEST) || conversation.participantType.equals(Participant.ParticipantType.USER_FOLLOWING_LINK))) { - bundle.putInt(BundleKeys.KEY_OPERATION_CODE, 99); + bundle.putInt(BundleKeys.INSTANCE.getKEY_OPERATION_CODE(), 99); prepareAndShowBottomSheetWithBundle(bundle, false); } else { currentUser = userUtils.getCurrentUser(); if (currentUser.hasSpreedFeatureCapability("chat-v2")) { - bundle.putParcelable(BundleKeys.KEY_ACTIVE_CONVERSATION, Parcels.wrap(conversation)); - ConductorRemapping.remapChatController(getRouter(), currentUser.getId(), + bundle.putParcelable(BundleKeys.INSTANCE.getKEY_ACTIVE_CONVERSATION(), Parcels.wrap(conversation)); + ConductorRemapping.INSTANCE.remapChatController(getRouter(), currentUser.getId(), conversation.getToken(), bundle, false); } else { overridePushHandler(new NoOpControllerChangeHandler()); @@ -674,10 +674,10 @@ public class ConversationsListController extends BaseController implements Searc } private void showDeleteConversationDialog(Bundle savedInstanceState) { - if (getActivity() != null && conversationMenuBundle != null && currentUser != null && conversationMenuBundle.getLong(BundleKeys.KEY_INTERNAL_USER_ID) == currentUser.getId()) { + if (getActivity() != null && conversationMenuBundle != null && currentUser != null && conversationMenuBundle.getLong(BundleKeys.INSTANCE.getKEY_INTERNAL_USER_ID()) == currentUser.getId()) { Conversation conversation = - Parcels.unwrap(conversationMenuBundle.getParcelable(BundleKeys.KEY_ROOM)); + Parcels.unwrap(conversationMenuBundle.getParcelable(BundleKeys.INSTANCE.getKEY_ROOM())); if (conversation != null) { new LovelyStandardDialog(getActivity(), LovelyStandardDialog.ButtonLayout.HORIZONTAL) @@ -691,9 +691,9 @@ public class ConversationsListController extends BaseController implements Searc @Override public void onClick(View v) { Data.Builder data = new Data.Builder(); - data.putLong(BundleKeys.KEY_INTERNAL_USER_ID, - conversationMenuBundle.getLong(BundleKeys.KEY_INTERNAL_USER_ID)); - data.putString(BundleKeys.KEY_ROOM_TOKEN, conversation.getToken()); + data.putLong(BundleKeys.INSTANCE.getKEY_INTERNAL_USER_ID(), + conversationMenuBundle.getLong(BundleKeys.INSTANCE.getKEY_INTERNAL_USER_ID())); + data.putString(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN(), conversation.getToken()); conversationMenuBundle = null; deleteConversation(data.build()); } diff --git a/app/src/main/java/com/nextcloud/talk/controllers/LockedController.java b/app/src/main/java/com/nextcloud/talk/controllers/LockedController.java index 883730442..98220d561 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/LockedController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/LockedController.java @@ -63,7 +63,7 @@ public class LockedController extends BaseController { @Override protected void onViewBound(@NonNull View view) { super.onViewBound(view); - NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); + NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); if (getActionBar() != null) { getActionBar().hide(); } diff --git a/app/src/main/java/com/nextcloud/talk/controllers/RingtoneSelectionController.java b/app/src/main/java/com/nextcloud/talk/controllers/RingtoneSelectionController.java index 7a8fdad88..f5edc8cf9 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/RingtoneSelectionController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/RingtoneSelectionController.java @@ -85,7 +85,7 @@ public class RingtoneSelectionController extends BaseController implements Flexi public RingtoneSelectionController(Bundle args) { super(args); setHasOptionsMenu(true); - this.callNotificationSounds = args.getBoolean(BundleKeys.KEY_ARE_CALL_SOUNDS, false); + this.callNotificationSounds = args.getBoolean(BundleKeys.INSTANCE.getKEY_ARE_CALL_SOUNDS(), false); } @Override @@ -96,7 +96,7 @@ public class RingtoneSelectionController extends BaseController implements Flexi @Override protected void onViewBound(@NonNull View view) { super.onViewBound(view); - NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); + NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); if (adapter == null) { adapter = new FlexibleAdapter<>(abstractFlexibleItemList, getActivity(), false); diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ServerSelectionController.java b/app/src/main/java/com/nextcloud/talk/controllers/ServerSelectionController.java index ec0aa3c54..1f71e4101 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ServerSelectionController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/ServerSelectionController.java @@ -111,7 +111,7 @@ public class ServerSelectionController extends BaseController { @Override protected void onViewBound(@NonNull View view) { super.onViewBound(view); - NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); + NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); if (getActivity() != null) { getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); @@ -134,7 +134,7 @@ public class ServerSelectionController extends BaseController { } else { if ((TextUtils.isEmpty(getResources ().getString(R.string.nc_import_account_type)) || - AccountUtils.findAccounts(userUtils.getUsers()).size() == 0) && + AccountUtils.INSTANCE.findAccounts(userUtils.getUsers()).size() == 0) && userUtils.getUsers().size() == 0) { providersTextView.setText(R.string.nc_get_from_provider); @@ -143,20 +143,20 @@ public class ServerSelectionController extends BaseController { .getString(R.string.nc_providers_url))); startActivity(browserIntent); }); - } else if (AccountUtils.findAccounts(userUtils.getUsers()).size() > 0) { - if (!TextUtils.isEmpty(AccountUtils.getAppNameBasedOnPackage(getResources() + } else if (AccountUtils.INSTANCE.findAccounts(userUtils.getUsers()).size() > 0) { + if (!TextUtils.isEmpty(AccountUtils.INSTANCE.getAppNameBasedOnPackage(getResources() .getString(R.string.nc_import_accounts_from)))) { - if (AccountUtils.findAccounts(userUtils.getUsers()).size() > 1) { + if (AccountUtils.INSTANCE.findAccounts(userUtils.getUsers()).size() > 1) { providersTextView.setText(String.format(getResources().getString(R.string - .nc_server_import_accounts), AccountUtils.getAppNameBasedOnPackage(getResources() + .nc_server_import_accounts), AccountUtils.INSTANCE.getAppNameBasedOnPackage(getResources() .getString(R.string.nc_import_accounts_from)))); } else { providersTextView.setText(String.format(getResources().getString(R.string - .nc_server_import_account), AccountUtils.getAppNameBasedOnPackage(getResources() + .nc_server_import_account), AccountUtils.INSTANCE.getAppNameBasedOnPackage(getResources() .getString(R.string.nc_import_accounts_from)))); } } else { - if (AccountUtils.findAccounts(userUtils.getUsers()).size() > 1) { + if (AccountUtils.INSTANCE.findAccounts(userUtils.getUsers()).size() > 1) { providersTextView.setText(getResources().getString(R.string.nc_server_import_accounts_plain)); } else { providersTextView.setText(getResources().getString(R.string @@ -166,7 +166,7 @@ public class ServerSelectionController extends BaseController { providersTextView.setOnClickListener(view13 -> { Bundle bundle = new Bundle(); - bundle.putBoolean(BundleKeys.KEY_IS_ACCOUNT_IMPORT, true); + bundle.putBoolean(BundleKeys.INSTANCE.getKEY_IS_ACCOUNT_IMPORT(), true); getRouter().pushController(RouterTransaction.with( new SwitchAccountController(bundle)) .pushChangeHandler(new HorizontalChangeHandler()) diff --git a/app/src/main/java/com/nextcloud/talk/controllers/SettingsController.java b/app/src/main/java/com/nextcloud/talk/controllers/SettingsController.java index eb625d244..f55438a2b 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/SettingsController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/SettingsController.java @@ -138,8 +138,6 @@ public class SettingsController extends BaseController { @BindView(R.id.message_text) TextView messageText; @Inject - EventBus eventBus; - @Inject AppPreferences appPreferences; @Inject NcApi ncApi; @@ -176,7 +174,7 @@ public class SettingsController extends BaseController { setHasOptionsMenu(true); ViewCompat.setTransitionName(avatarImageView, "userAvatar.transitionTag"); - NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); + NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); getCurrentUser(); @@ -209,7 +207,7 @@ public class SettingsController extends BaseController { licenceButton.setVisibility(View.GONE); } - if (!DoNotDisturbUtils.hasVibrator()) { + if (!DoNotDisturbUtils.INSTANCE.hasVibrator()) { shouldVibrateSwitchPreference.setVisibility(View.GONE); } @@ -251,7 +249,7 @@ public class SettingsController extends BaseController { settingsCallSound.setOnClickListener(v -> { Bundle bundle = new Bundle(); - bundle.putBoolean(BundleKeys.KEY_ARE_CALL_SOUNDS, true); + bundle.putBoolean(BundleKeys.INSTANCE.getKEY_ARE_CALL_SOUNDS(), true); getRouter().pushController(RouterTransaction.with(new RingtoneSelectionController(bundle)) .pushChangeHandler(new HorizontalChangeHandler()) .popChangeHandler(new HorizontalChangeHandler())); @@ -259,7 +257,7 @@ public class SettingsController extends BaseController { settingsMessageSound.setOnClickListener(v -> { Bundle bundle = new Bundle(); - bundle.putBoolean(BundleKeys.KEY_ARE_CALL_SOUNDS, false); + bundle.putBoolean(BundleKeys.INSTANCE.getKEY_ARE_CALL_SOUNDS(), false); getRouter().pushController(RouterTransaction.with(new RingtoneSelectionController(bundle)) .pushChangeHandler(new HorizontalChangeHandler()) .popChangeHandler(new HorizontalChangeHandler())); @@ -325,7 +323,7 @@ public class SettingsController extends BaseController { @OnClick(R.id.settings_version) void sendLogs() { if (getResources().getBoolean(R.bool.nc_is_debug)) { - LoggingUtils.sendMailWithAttachment(context); + LoggingUtils.INSTANCE.sendMailWithAttachment(context); } } @@ -774,7 +772,7 @@ public class SettingsController extends BaseController { private class ThemeChangeListener implements OnPreferenceValueChangedListener { @Override public void onChanged(String newValue) { - NextcloudTalkApplication.setAppTheme(newValue); + NextcloudTalkApplication.Companion.setAppTheme(newValue); } } } diff --git a/app/src/main/java/com/nextcloud/talk/controllers/SwitchAccountController.java b/app/src/main/java/com/nextcloud/talk/controllers/SwitchAccountController.java index 0526322a5..e725ed838 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/SwitchAccountController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/SwitchAccountController.java @@ -137,7 +137,7 @@ public class SwitchAccountController extends BaseController { super(args); setHasOptionsMenu(true); - if (args.containsKey(BundleKeys.KEY_IS_ACCOUNT_IMPORT)) { + if (args.containsKey(BundleKeys.INSTANCE.getKEY_IS_ACCOUNT_IMPORT())) { isAccountImport = true; } } @@ -161,7 +161,7 @@ public class SwitchAccountController extends BaseController { @Override protected void onViewBound(@NonNull View view) { super.onViewBound(view); - NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); + NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); swipeRefreshLayout.setEnabled(false); if (getActionBar() != null) { @@ -198,9 +198,9 @@ public class SwitchAccountController extends BaseController { } else { Account account; ImportAccount importAccount; - for (Object accountObject : AccountUtils.findAccounts(userUtils.getUsers())) { + for (Object accountObject : AccountUtils.INSTANCE.findAccounts(userUtils.getUsers())) { account = (Account) accountObject; - importAccount = AccountUtils.getInformationFromAccount(account); + importAccount = AccountUtils.INSTANCE.getInformationFromAccount(account); participant = new Participant(); participant.setName(importAccount.getUsername()); @@ -230,12 +230,12 @@ public class SwitchAccountController extends BaseController { } private void reauthorizeFromImport(Account account) { - ImportAccount importAccount = AccountUtils.getInformationFromAccount(account); + ImportAccount importAccount = AccountUtils.INSTANCE.getInformationFromAccount(account); Bundle bundle = new Bundle(); - bundle.putString(BundleKeys.KEY_BASE_URL, importAccount.getBaseUrl()); - bundle.putString(BundleKeys.KEY_USERNAME, importAccount.getUsername()); - bundle.putString(BundleKeys.KEY_TOKEN, importAccount.getToken()); - bundle.putBoolean(BundleKeys.KEY_IS_ACCOUNT_IMPORT, true); + bundle.putString(BundleKeys.INSTANCE.getKEY_BASE_URL(), importAccount.getBaseUrl()); + bundle.putString(BundleKeys.INSTANCE.getKEY_USERNAME(), importAccount.getUsername()); + bundle.putString(BundleKeys.INSTANCE.getKEY_TOKEN(), importAccount.getToken()); + bundle.putBoolean(BundleKeys.INSTANCE.getKEY_IS_ACCOUNT_IMPORT(), true); getRouter().pushController(RouterTransaction.with(new AccountVerificationController(bundle)) .pushChangeHandler(new HorizontalChangeHandler()) .popChangeHandler(new HorizontalChangeHandler())); diff --git a/app/src/main/java/com/nextcloud/talk/controllers/WebViewLoginController.java b/app/src/main/java/com/nextcloud/talk/controllers/WebViewLoginController.java index 13ebe692a..874c8aa13 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/WebViewLoginController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/WebViewLoginController.java @@ -149,7 +149,7 @@ public class WebViewLoginController extends BaseController { @Override protected void onViewBound(@NonNull View view) { super.onViewBound(view); - NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); + NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); if (getActivity() != null) { getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); @@ -364,9 +364,9 @@ public class WebViewLoginController extends BaseController { if (!isPasswordUpdate && finalMessageType == null) { Bundle bundle = new Bundle(); - bundle.putString(BundleKeys.KEY_USERNAME, loginData.getUsername()); - bundle.putString(BundleKeys.KEY_TOKEN, loginData.getToken()); - bundle.putString(BundleKeys.KEY_BASE_URL, loginData.getServerUrl()); + bundle.putString(BundleKeys.INSTANCE.getKEY_USERNAME(), loginData.getUsername()); + bundle.putString(BundleKeys.INSTANCE.getKEY_TOKEN(), loginData.getToken()); + bundle.putString(BundleKeys.INSTANCE.getKEY_BASE_URL(), loginData.getServerUrl()); String protocol = ""; if (baseUrl.startsWith("http://")) { @@ -376,7 +376,7 @@ public class WebViewLoginController extends BaseController { } if (!TextUtils.isEmpty(protocol)) { - bundle.putString(BundleKeys.KEY_ORIGINAL_PROTOCOL, protocol); + bundle.putString(BundleKeys.INSTANCE.getKEY_ORIGINAL_PROTOCOL(), protocol); } getRouter().pushController(RouterTransaction.with(new AccountVerificationController diff --git a/app/src/main/java/com/nextcloud/talk/controllers/base/BaseController.java b/app/src/main/java/com/nextcloud/talk/controllers/base/BaseController.java index c2504590c..4fa6fa602 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/base/BaseController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/base/BaseController.java @@ -75,7 +75,7 @@ public abstract class BaseController extends ButterKnifeController { } private void cleanTempCertPreference() { - NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); + NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); List temporaryClassNames = new ArrayList<>(); temporaryClassNames.add(ServerSelectionController.class.getName()); diff --git a/app/src/main/java/com/nextcloud/talk/controllers/bottomsheet/CallMenuController.java b/app/src/main/java/com/nextcloud/talk/controllers/bottomsheet/CallMenuController.java index 69a53e3f7..1925c4d89 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/bottomsheet/CallMenuController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/bottomsheet/CallMenuController.java @@ -49,7 +49,7 @@ import com.nextcloud.talk.events.BottomSheetLockEvent; import com.nextcloud.talk.interfaces.ConversationMenuInterface; import com.nextcloud.talk.jobs.LeaveConversationWorker; import com.nextcloud.talk.models.database.UserEntity; -import com.nextcloud.talk.models.json.rooms.Conversation; +import com.nextcloud.talk.models.json.conversations.Conversation; import com.nextcloud.talk.utils.DisplayUtils; import com.nextcloud.talk.utils.ShareUtils; import com.nextcloud.talk.utils.bundle.BundleKeys; @@ -87,17 +87,17 @@ public class CallMenuController extends BaseController implements FlexibleAdapte public CallMenuController(Bundle args) { super(args); - this.conversation = Parcels.unwrap(args.getParcelable(BundleKeys.KEY_ROOM)); - if (args.containsKey(BundleKeys.KEY_MENU_TYPE)) { - this.menuType = Parcels.unwrap(args.getParcelable(BundleKeys.KEY_MENU_TYPE)); + this.conversation = Parcels.unwrap(args.getParcelable(BundleKeys.INSTANCE.getKEY_ROOM())); + if (args.containsKey(BundleKeys.INSTANCE.getKEY_MENU_TYPE())) { + this.menuType = Parcels.unwrap(args.getParcelable(BundleKeys.INSTANCE.getKEY_MENU_TYPE())); } } public CallMenuController(Bundle args, @Nullable ConversationMenuInterface conversationMenuInterface) { super(args); - this.conversation = Parcels.unwrap(args.getParcelable(BundleKeys.KEY_ROOM)); - if (args.containsKey(BundleKeys.KEY_MENU_TYPE)) { - this.menuType = Parcels.unwrap(args.getParcelable(BundleKeys.KEY_MENU_TYPE)); + this.conversation = Parcels.unwrap(args.getParcelable(BundleKeys.INSTANCE.getKEY_ROOM())); + if (args.containsKey(BundleKeys.INSTANCE.getKEY_MENU_TYPE())) { + this.menuType = Parcels.unwrap(args.getParcelable(BundleKeys.INSTANCE.getKEY_MENU_TYPE())); } this.conversationMenuInterface = conversationMenuInterface; } @@ -110,7 +110,7 @@ public class CallMenuController extends BaseController implements FlexibleAdapte @Override protected void onViewBound(@NonNull View view) { super.onViewBound(view); - NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); + NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); prepareViews(); } @@ -218,7 +218,7 @@ public class CallMenuController extends BaseController implements FlexibleAdapte @Override public boolean onItemClick(View view, int position) { Bundle bundle = new Bundle(); - bundle.putParcelable(BundleKeys.KEY_ROOM, Parcels.wrap(conversation)); + bundle.putParcelable(BundleKeys.INSTANCE.getKEY_ROOM(), Parcels.wrap(conversation)); if (menuType.equals(MenuType.REGULAR)) { MenuItem menuItem = (MenuItem) adapter.getItem(position); @@ -246,7 +246,7 @@ public class CallMenuController extends BaseController implements FlexibleAdapte } eventBus.post(new BottomSheetLockEvent(true, 0, false, true)); } else { - bundle.putInt(BundleKeys.KEY_OPERATION_CODE, tag); + bundle.putInt(BundleKeys.INSTANCE.getKEY_OPERATION_CODE(), tag); if (tag != 2 && tag != 4 && tag != 6 && tag != 7) { eventBus.post(new BottomSheetLockEvent(false, 0, false, false)); getRouter().pushController(RouterTransaction.with(new OperationsMenuController(bundle)) @@ -257,7 +257,7 @@ public class CallMenuController extends BaseController implements FlexibleAdapte .pushChangeHandler(new HorizontalChangeHandler()) .popChangeHandler(new HorizontalChangeHandler())); } else { - bundle.putParcelable(BundleKeys.KEY_MENU_TYPE, Parcels.wrap(MenuType.SHARE)); + bundle.putParcelable(BundleKeys.INSTANCE.getKEY_MENU_TYPE(), Parcels.wrap(MenuType.SHARE)); getRouter().pushController(RouterTransaction.with(new CallMenuController(bundle, null)) .pushChangeHandler(new HorizontalChangeHandler()) .popChangeHandler(new HorizontalChangeHandler())); @@ -277,10 +277,10 @@ public class CallMenuController extends BaseController implements FlexibleAdapte eventBus.post(new BottomSheetLockEvent(true, 0, false, true)); getActivity().startActivity(intent); } else { - bundle.putInt(BundleKeys.KEY_OPERATION_CODE, 7); - bundle.putParcelable(BundleKeys.KEY_SHARE_INTENT, Parcels.wrap(shareIntent)); - bundle.putString(BundleKeys.KEY_APP_ITEM_PACKAGE_NAME, appItem.getPackageName()); - bundle.putString(BundleKeys.KEY_APP_ITEM_NAME, appItem.getName()); + bundle.putInt(BundleKeys.INSTANCE.getKEY_OPERATION_CODE(), 7); + bundle.putParcelable(BundleKeys.INSTANCE.getKEY_SHARE_INTENT(), Parcels.wrap(shareIntent)); + bundle.putString(BundleKeys.INSTANCE.getKEY_APP_ITEM_PACKAGE_NAME(), appItem.getPackageName()); + bundle.putString(BundleKeys.INSTANCE.getKEY_APP_ITEM_NAME(), appItem.getName()); getRouter().pushController(RouterTransaction.with(new EntryMenuController(bundle)) .pushChangeHandler(new HorizontalChangeHandler()) .popChangeHandler(new HorizontalChangeHandler())); @@ -294,8 +294,8 @@ public class CallMenuController extends BaseController implements FlexibleAdapte private Data getWorkerData() { if (!TextUtils.isEmpty(conversation.getToken())) { Data.Builder data = new Data.Builder(); - data.putString(BundleKeys.KEY_ROOM_TOKEN, conversation.getToken()); - data.putLong(BundleKeys.KEY_INTERNAL_USER_ID, currentUser.getId()); + data.putString(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN(), conversation.getToken()); + data.putLong(BundleKeys.INSTANCE.getKEY_INTERNAL_USER_ID(), currentUser.getId()); return data.build(); } @@ -305,8 +305,8 @@ public class CallMenuController extends BaseController implements FlexibleAdapte private Bundle getDeleteConversationBundle() { if (!TextUtils.isEmpty(conversation.getToken())) { Bundle bundle = new Bundle(); - bundle.putLong(BundleKeys.KEY_INTERNAL_USER_ID, currentUser.getId()); - bundle.putParcelable(BundleKeys.KEY_ROOM, Parcels.wrap(conversation)); + bundle.putLong(BundleKeys.INSTANCE.getKEY_INTERNAL_USER_ID(), currentUser.getId()); + bundle.putParcelable(BundleKeys.INSTANCE.getKEY_ROOM(), Parcels.wrap(conversation)); return bundle; } diff --git a/app/src/main/java/com/nextcloud/talk/controllers/bottomsheet/EntryMenuController.java b/app/src/main/java/com/nextcloud/talk/controllers/bottomsheet/EntryMenuController.java index 89db5b5a2..ccce0ab8c 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/bottomsheet/EntryMenuController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/bottomsheet/EntryMenuController.java @@ -44,7 +44,7 @@ import com.nextcloud.talk.R; import com.nextcloud.talk.application.NextcloudTalkApplication; import com.nextcloud.talk.controllers.base.BaseController; import com.nextcloud.talk.events.BottomSheetLockEvent; -import com.nextcloud.talk.models.json.rooms.Conversation; +import com.nextcloud.talk.models.json.conversations.Conversation; import com.nextcloud.talk.utils.ShareUtils; import com.nextcloud.talk.utils.bundle.BundleKeys; import com.nextcloud.talk.utils.database.user.UserUtils; @@ -85,18 +85,18 @@ public class EntryMenuController extends BaseController { super(args); originalBundle = args; - this.operationCode = args.getInt(BundleKeys.KEY_OPERATION_CODE); - if (args.containsKey(BundleKeys.KEY_ROOM)) { - this.conversation = Parcels.unwrap(args.getParcelable(BundleKeys.KEY_ROOM)); + this.operationCode = args.getInt(BundleKeys.INSTANCE.getKEY_OPERATION_CODE()); + if (args.containsKey(BundleKeys.INSTANCE.getKEY_ROOM())) { + this.conversation = Parcels.unwrap(args.getParcelable(BundleKeys.INSTANCE.getKEY_ROOM())); } - if (args.containsKey(BundleKeys.KEY_SHARE_INTENT)) { - this.shareIntent = Parcels.unwrap(args.getParcelable(BundleKeys.KEY_SHARE_INTENT)); + if (args.containsKey(BundleKeys.INSTANCE.getKEY_SHARE_INTENT())) { + this.shareIntent = Parcels.unwrap(args.getParcelable(BundleKeys.INSTANCE.getKEY_SHARE_INTENT())); } - this.name = args.getString(BundleKeys.KEY_APP_ITEM_NAME, ""); - this.packageName = args.getString(BundleKeys.KEY_APP_ITEM_PACKAGE_NAME, ""); - this.callUrl = args.getString(BundleKeys.KEY_CALL_URL, ""); + this.name = args.getString(BundleKeys.INSTANCE.getKEY_APP_ITEM_NAME(), ""); + this.packageName = args.getString(BundleKeys.INSTANCE.getKEY_APP_ITEM_PACKAGE_NAME(), ""); + this.callUrl = args.getString(BundleKeys.INSTANCE.getKEY_CALL_URL(), ""); } @Override @@ -124,12 +124,12 @@ public class EntryMenuController extends BaseController { if (operationCode == 99) { eventBus.post(new BottomSheetLockEvent(false, 0, false, false)); bundle = new Bundle(); - bundle.putParcelable(BundleKeys.KEY_ROOM, Parcels.wrap(conversation)); - bundle.putString(BundleKeys.KEY_CALL_URL, callUrl); - bundle.putString(BundleKeys.KEY_CONVERSATION_PASSWORD, editText.getText().toString()); - bundle.putInt(BundleKeys.KEY_OPERATION_CODE, operationCode); - if (originalBundle.containsKey(BundleKeys.KEY_SERVER_CAPABILITIES)) { - bundle.putParcelable(BundleKeys.KEY_SERVER_CAPABILITIES, originalBundle.getParcelable(BundleKeys.KEY_SERVER_CAPABILITIES)); + bundle.putParcelable(BundleKeys.INSTANCE.getKEY_ROOM(), Parcels.wrap(conversation)); + bundle.putString(BundleKeys.INSTANCE.getKEY_CALL_URL(), callUrl); + bundle.putString(BundleKeys.INSTANCE.getKEY_CONVERSATION_PASSWORD(), editText.getText().toString()); + bundle.putInt(BundleKeys.INSTANCE.getKEY_OPERATION_CODE(), operationCode); + if (originalBundle.containsKey(BundleKeys.INSTANCE.getKEY_SERVER_CAPABILITIES())) { + bundle.putParcelable(BundleKeys.INSTANCE.getKEY_SERVER_CAPABILITIES(), originalBundle.getParcelable(BundleKeys.INSTANCE.getKEY_SERVER_CAPABILITIES())); } getRouter().pushController(RouterTransaction.with(new OperationsMenuController(bundle)) @@ -143,8 +143,8 @@ public class EntryMenuController extends BaseController { } else { conversation.setName(editText.getText().toString()); } - bundle.putParcelable(BundleKeys.KEY_ROOM, Parcels.wrap(conversation)); - bundle.putInt(BundleKeys.KEY_OPERATION_CODE, operationCode); + bundle.putParcelable(BundleKeys.INSTANCE.getKEY_ROOM(), Parcels.wrap(conversation)); + bundle.putInt(BundleKeys.INSTANCE.getKEY_OPERATION_CODE(), operationCode); getRouter().pushController(RouterTransaction.with(new OperationsMenuController(bundle)) .pushChangeHandler(new HorizontalChangeHandler()) .popChangeHandler(new HorizontalChangeHandler())); @@ -161,15 +161,15 @@ public class EntryMenuController extends BaseController { } else if (operationCode != 11) { eventBus.post(new BottomSheetLockEvent(false, 0, false, false)); bundle = new Bundle(); - bundle.putInt(BundleKeys.KEY_OPERATION_CODE, operationCode); - bundle.putString(BundleKeys.KEY_CALL_URL, editText.getText().toString()); + bundle.putInt(BundleKeys.INSTANCE.getKEY_OPERATION_CODE(), operationCode); + bundle.putString(BundleKeys.INSTANCE.getKEY_CALL_URL(), editText.getText().toString()); getRouter().pushController(RouterTransaction.with(new OperationsMenuController(bundle)) .pushChangeHandler(new HorizontalChangeHandler()) .popChangeHandler(new HorizontalChangeHandler())); } else if (operationCode == 11) { eventBus.post(new BottomSheetLockEvent(false, 0, false, false)); - originalBundle.putString(BundleKeys.KEY_CONVERSATION_NAME, editText.getText().toString()); + originalBundle.putString(BundleKeys.INSTANCE.getKEY_CONVERSATION_NAME(), editText.getText().toString()); getRouter().pushController(RouterTransaction.with(new OperationsMenuController(originalBundle)) .pushChangeHandler(new HorizontalChangeHandler()) .popChangeHandler(new HorizontalChangeHandler())); @@ -180,7 +180,7 @@ public class EntryMenuController extends BaseController { @Override protected void onViewBound(@NonNull View view) { super.onViewBound(view); - NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); + NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); if (conversation != null && operationCode == 2) { editText.setText(conversation.getName()); diff --git a/app/src/main/java/com/nextcloud/talk/controllers/bottomsheet/OperationsMenuController.java b/app/src/main/java/com/nextcloud/talk/controllers/bottomsheet/OperationsMenuController.java index 78c7975e8..5f68a6e3d 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/bottomsheet/OperationsMenuController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/bottomsheet/OperationsMenuController.java @@ -56,8 +56,8 @@ import com.nextcloud.talk.models.json.capabilities.Capabilities; import com.nextcloud.talk.models.json.capabilities.CapabilitiesOverall; import com.nextcloud.talk.models.json.generic.GenericOverall; import com.nextcloud.talk.models.json.participants.AddParticipantOverall; -import com.nextcloud.talk.models.json.rooms.Conversation; -import com.nextcloud.talk.models.json.rooms.RoomOverall; +import com.nextcloud.talk.models.json.conversations.Conversation; +import com.nextcloud.talk.models.json.conversations.RoomOverall; import com.nextcloud.talk.utils.ApiUtils; import com.nextcloud.talk.utils.ConductorRemapping; import com.nextcloud.talk.utils.DisplayUtils; @@ -126,31 +126,31 @@ public class OperationsMenuController extends BaseController { public OperationsMenuController(Bundle args) { super(args); - this.operationCode = args.getInt(BundleKeys.KEY_OPERATION_CODE); - if (args.containsKey(BundleKeys.KEY_ROOM)) { - this.conversation = Parcels.unwrap(args.getParcelable(BundleKeys.KEY_ROOM)); + this.operationCode = args.getInt(BundleKeys.INSTANCE.getKEY_OPERATION_CODE()); + if (args.containsKey(BundleKeys.INSTANCE.getKEY_ROOM())) { + this.conversation = Parcels.unwrap(args.getParcelable(BundleKeys.INSTANCE.getKEY_ROOM())); } - this.callPassword = args.getString(BundleKeys.KEY_CONVERSATION_PASSWORD, ""); - this.callUrl = args.getString(BundleKeys.KEY_CALL_URL, ""); + this.callPassword = args.getString(BundleKeys.INSTANCE.getKEY_CONVERSATION_PASSWORD(), ""); + this.callUrl = args.getString(BundleKeys.INSTANCE.getKEY_CALL_URL(), ""); - if (args.containsKey(BundleKeys.KEY_INVITED_PARTICIPANTS)) { - this.invitedUsers = args.getStringArrayList(BundleKeys.KEY_INVITED_PARTICIPANTS); + if (args.containsKey(BundleKeys.INSTANCE.getKEY_INVITED_PARTICIPANTS())) { + this.invitedUsers = args.getStringArrayList(BundleKeys.INSTANCE.getKEY_INVITED_PARTICIPANTS()); } - if (args.containsKey(BundleKeys.KEY_INVITED_GROUP)) { - this.invitedGroups = args.getStringArrayList(BundleKeys.KEY_INVITED_GROUP); + if (args.containsKey(BundleKeys.INSTANCE.getKEY_INVITED_GROUP())) { + this.invitedGroups = args.getStringArrayList(BundleKeys.INSTANCE.getKEY_INVITED_GROUP()); } - if (args.containsKey(BundleKeys.KEY_CONVERSATION_TYPE)) { - this.conversationType = Parcels.unwrap(args.getParcelable(BundleKeys.KEY_CONVERSATION_TYPE)); + if (args.containsKey(BundleKeys.INSTANCE.getKEY_CONVERSATION_TYPE())) { + this.conversationType = Parcels.unwrap(args.getParcelable(BundleKeys.INSTANCE.getKEY_CONVERSATION_TYPE())); } - if (args.containsKey(BundleKeys.KEY_SERVER_CAPABILITIES)) { - this.serverCapabilities = Parcels.unwrap(args.getParcelable(BundleKeys.KEY_SERVER_CAPABILITIES)); + if (args.containsKey(BundleKeys.INSTANCE.getKEY_SERVER_CAPABILITIES())) { + this.serverCapabilities = Parcels.unwrap(args.getParcelable(BundleKeys.INSTANCE.getKEY_SERVER_CAPABILITIES())); } - this.conversationName = args.getString(BundleKeys.KEY_CONVERSATION_NAME, ""); + this.conversationName = args.getString(BundleKeys.INSTANCE.getKEY_CONVERSATION_NAME(), ""); } @@ -162,7 +162,7 @@ public class OperationsMenuController extends BaseController { @Override protected void onViewBound(@NonNull View view) { super.onViewBound(view); - NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); + NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); processOperation(); } @@ -459,11 +459,11 @@ public class OperationsMenuController extends BaseController { eventBus.post(new BottomSheetLockEvent(true, 0, true, false)); Bundle bundle = new Bundle(); - bundle.putParcelable(BundleKeys.KEY_ROOM, Parcels.wrap(conversation)); - bundle.putString(BundleKeys.KEY_CALL_URL, callUrl); - bundle.putParcelable(BundleKeys.KEY_SERVER_CAPABILITIES, + bundle.putParcelable(BundleKeys.INSTANCE.getKEY_ROOM(), Parcels.wrap(conversation)); + bundle.putString(BundleKeys.INSTANCE.getKEY_CALL_URL(), callUrl); + bundle.putParcelable(BundleKeys.INSTANCE.getKEY_SERVER_CAPABILITIES(), Parcels.wrap(capabilitiesOverall.getOcs().getData().getCapabilities())); - bundle.putInt(BundleKeys.KEY_OPERATION_CODE, 99); + bundle.putInt(BundleKeys.INSTANCE.getKEY_OPERATION_CODE(), 99); getRouter().pushController(RouterTransaction.with(new EntryMenuController(bundle)) .pushChangeHandler(new HorizontalChangeHandler()) .popChangeHandler(new HorizontalChangeHandler())); @@ -610,9 +610,9 @@ public class OperationsMenuController extends BaseController { true, true, dismissView)); Intent conversationIntent = new Intent(getActivity(), MagicCallActivity.class); - bundle.putString(BundleKeys.KEY_ROOM_TOKEN, conversation.getToken()); - bundle.putString(BundleKeys.KEY_ROOM_ID, conversation.getRoomId()); - bundle.putString(BundleKeys.KEY_CONVERSATION_NAME, conversation.getDisplayName()); + bundle.putString(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN(), conversation.getToken()); + bundle.putString(BundleKeys.INSTANCE.getKEY_ROOM_ID(), conversation.getRoomId()); + bundle.putString(BundleKeys.INSTANCE.getKEY_CONVERSATION_NAME(), conversation.getDisplayName()); UserEntity conversationUser; if (isGuestUser) { conversationUser = new UserEntity(); @@ -627,14 +627,14 @@ public class OperationsMenuController extends BaseController { conversationUser = currentUser; } - bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, conversationUser); - bundle.putParcelable(BundleKeys.KEY_ACTIVE_CONVERSATION, Parcels.wrap(conversation)); - bundle.putString(BundleKeys.KEY_CONVERSATION_PASSWORD, callPassword); + bundle.putParcelable(BundleKeys.INSTANCE.getKEY_USER_ENTITY(), conversationUser); + bundle.putParcelable(BundleKeys.INSTANCE.getKEY_ACTIVE_CONVERSATION(), Parcels.wrap(conversation)); + bundle.putString(BundleKeys.INSTANCE.getKEY_CONVERSATION_PASSWORD(), callPassword); conversationIntent.putExtras(bundle); if (getParentController() != null) { - ConductorRemapping.remapChatController(getParentController().getRouter(), conversationUser.getId(), + ConductorRemapping.INSTANCE.remapChatController(getParentController().getRouter(), conversationUser.getId(), conversation.getToken(), bundle, true); } } else { @@ -646,12 +646,12 @@ public class OperationsMenuController extends BaseController { private void initiateCall() { eventBus.post(new BottomSheetLockEvent(true, 0, true, true)); Bundle bundle = new Bundle(); - bundle.putString(BundleKeys.KEY_ROOM_TOKEN, conversation.getToken()); - bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, currentUser); + bundle.putString(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN(), conversation.getToken()); + bundle.putParcelable(BundleKeys.INSTANCE.getKEY_USER_ENTITY(), currentUser); if (baseUrl != null && !baseUrl.equals(currentUser.getBaseUrl())) { - bundle.putString(BundleKeys.KEY_MODIFIED_BASE_URL, baseUrl); + bundle.putString(BundleKeys.INSTANCE.getKEY_MODIFIED_BASE_URL(), baseUrl); } - bundle.putParcelable(BundleKeys.KEY_ACTIVE_CONVERSATION, Parcels.wrap(call)); + bundle.putParcelable(BundleKeys.INSTANCE.getKEY_ACTIVE_CONVERSATION(), Parcels.wrap(call)); if (getActivity() != null) { diff --git a/app/src/main/java/com/nextcloud/talk/dagger/modules/RestModule.java b/app/src/main/java/com/nextcloud/talk/dagger/modules/RestModule.java index 69018d48d..de2a058db 100644 --- a/app/src/main/java/com/nextcloud/talk/dagger/modules/RestModule.java +++ b/app/src/main/java/com/nextcloud/talk/dagger/modules/RestModule.java @@ -159,7 +159,7 @@ public class RestModule { Cache provideCache() { int cacheSize = 128 * 1024 * 1024; // 128 MB - return new Cache(NextcloudTalkApplication.getSharedApplication().getCacheDir(), cacheSize); + return new Cache(NextcloudTalkApplication.Companion.getSharedApplication().getCacheDir(), cacheSize); } @Singleton @@ -216,7 +216,7 @@ public class RestModule { } else if (context.getResources().getBoolean(R.bool.nc_is_debug)) { HttpLoggingInterceptor.Logger fileLogger = - s -> LoggingUtils.writeLogEntryToFile(context, s); + s -> LoggingUtils.INSTANCE.writeLogEntryToFile(context, s); HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(fileLogger); loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); loggingInterceptor.redactHeader("Authorization"); diff --git a/app/src/main/java/com/nextcloud/talk/events/MoreMenuClickEvent.java b/app/src/main/java/com/nextcloud/talk/events/MoreMenuClickEvent.java index 28c2b0dc9..bca88d9e4 100644 --- a/app/src/main/java/com/nextcloud/talk/events/MoreMenuClickEvent.java +++ b/app/src/main/java/com/nextcloud/talk/events/MoreMenuClickEvent.java @@ -20,7 +20,7 @@ package com.nextcloud.talk.events; -import com.nextcloud.talk.models.json.rooms.Conversation; +import com.nextcloud.talk.models.json.conversations.Conversation; import lombok.Data; @Data diff --git a/app/src/main/java/com/nextcloud/talk/events/WebSocketCommunicationEvent.java b/app/src/main/java/com/nextcloud/talk/events/WebSocketCommunicationEvent.java index b6190c6c2..c801af4b2 100644 --- a/app/src/main/java/com/nextcloud/talk/events/WebSocketCommunicationEvent.java +++ b/app/src/main/java/com/nextcloud/talk/events/WebSocketCommunicationEvent.java @@ -30,4 +30,4 @@ public class WebSocketCommunicationEvent { public final String type; @Nullable public final HashMap hashMap; -} +} \ No newline at end of file diff --git a/app/src/main/java/com/nextcloud/talk/interfaces/SelectionInterface.java b/app/src/main/java/com/nextcloud/talk/interfaces/ClosedInterface.kt similarity index 82% rename from app/src/main/java/com/nextcloud/talk/interfaces/SelectionInterface.java rename to app/src/main/java/com/nextcloud/talk/interfaces/ClosedInterface.kt index 836b54d59..8e678d5e1 100644 --- a/app/src/main/java/com/nextcloud/talk/interfaces/SelectionInterface.java +++ b/app/src/main/java/com/nextcloud/talk/interfaces/ClosedInterface.kt @@ -18,10 +18,10 @@ * along with this program. If not, see . */ -package com.nextcloud.talk.interfaces; +package com.nextcloud.talk.interfaces -public interface SelectionInterface { - void toggleBrowserItemSelection(String path); +interface ClosedInterface { - boolean isPathSelected(String path); + val isGooglePlayServicesAvailable: Boolean + fun providerInstallerInstallIfNeededAsync() } diff --git a/app/src/main/java/com/nextcloud/talk/interfaces/ConversationMenuInterface.java b/app/src/main/java/com/nextcloud/talk/interfaces/ConversationMenuInterface.kt similarity index 81% rename from app/src/main/java/com/nextcloud/talk/interfaces/ConversationMenuInterface.java rename to app/src/main/java/com/nextcloud/talk/interfaces/ConversationMenuInterface.kt index 8ef3b89a3..9f6afdaf1 100644 --- a/app/src/main/java/com/nextcloud/talk/interfaces/ConversationMenuInterface.java +++ b/app/src/main/java/com/nextcloud/talk/interfaces/ConversationMenuInterface.kt @@ -18,10 +18,10 @@ * along with this program. If not, see . */ -package com.nextcloud.talk.interfaces; +package com.nextcloud.talk.interfaces -import android.os.Bundle; +import android.os.Bundle -public interface ConversationMenuInterface { - void openLovelyDialogWithIdAndBundle(int dialogId, Bundle bundle); +interface ConversationMenuInterface { + fun openLovelyDialogWithIdAndBundle(dialogId: Int, bundle: Bundle) } diff --git a/app/src/main/java/com/nextcloud/talk/interfaces/ClosedInterface.java b/app/src/main/java/com/nextcloud/talk/interfaces/SelectionInterface.kt similarity index 82% rename from app/src/main/java/com/nextcloud/talk/interfaces/ClosedInterface.java rename to app/src/main/java/com/nextcloud/talk/interfaces/SelectionInterface.kt index 445d80652..4766c5534 100644 --- a/app/src/main/java/com/nextcloud/talk/interfaces/ClosedInterface.java +++ b/app/src/main/java/com/nextcloud/talk/interfaces/SelectionInterface.kt @@ -18,10 +18,10 @@ * along with this program. If not, see . */ -package com.nextcloud.talk.interfaces; +package com.nextcloud.talk.interfaces -public interface ClosedInterface { - void providerInstallerInstallIfNeededAsync(); +interface SelectionInterface { + fun toggleBrowserItemSelection(path: String) - boolean isGooglePlayServicesAvailable(); + fun isPathSelected(path: String): Boolean } diff --git a/app/src/main/java/com/nextcloud/talk/jobs/AccountRemovalWorker.java b/app/src/main/java/com/nextcloud/talk/jobs/AccountRemovalWorker.java index 58c044eb9..aec901033 100644 --- a/app/src/main/java/com/nextcloud/talk/jobs/AccountRemovalWorker.java +++ b/app/src/main/java/com/nextcloud/talk/jobs/AccountRemovalWorker.java @@ -79,7 +79,7 @@ public class AccountRemovalWorker extends Worker { @NonNull @Override public Result doWork() { - NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); + NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); PushConfigurationState pushConfigurationState; String credentials; diff --git a/app/src/main/java/com/nextcloud/talk/jobs/CapabilitiesWorker.java b/app/src/main/java/com/nextcloud/talk/jobs/CapabilitiesWorker.java index 3c0dc8675..779a1cf94 100644 --- a/app/src/main/java/com/nextcloud/talk/jobs/CapabilitiesWorker.java +++ b/app/src/main/java/com/nextcloud/talk/jobs/CapabilitiesWorker.java @@ -110,11 +110,11 @@ public class CapabilitiesWorker extends Worker { @NonNull @Override public Result doWork() { - NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); + NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); Data data = getInputData(); - long internalUserId = data.getLong(BundleKeys.KEY_INTERNAL_USER_ID, -1); + long internalUserId = data.getLong(BundleKeys.INSTANCE.getKEY_INTERNAL_USER_ID(), -1); UserEntity userEntity; List userEntityObjectList = new ArrayList(); diff --git a/app/src/main/java/com/nextcloud/talk/jobs/DeleteConversationWorker.java b/app/src/main/java/com/nextcloud/talk/jobs/DeleteConversationWorker.java index e77f90e4e..0bde3e7ac 100644 --- a/app/src/main/java/com/nextcloud/talk/jobs/DeleteConversationWorker.java +++ b/app/src/main/java/com/nextcloud/talk/jobs/DeleteConversationWorker.java @@ -63,15 +63,15 @@ public class DeleteConversationWorker extends Worker { public DeleteConversationWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) { super(context, workerParams); - NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); + NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); } @NonNull @Override public Result doWork() { Data data = getInputData(); - long operationUserId = data.getLong(BundleKeys.KEY_INTERNAL_USER_ID, -1); - String conversationToken = data.getString(BundleKeys.KEY_ROOM_TOKEN); + long operationUserId = data.getLong(BundleKeys.INSTANCE.getKEY_INTERNAL_USER_ID(), -1); + String conversationToken = data.getString(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN()); UserEntity operationUser = userUtils.getUserWithId(operationUserId); if (operationUser != null) { diff --git a/app/src/main/java/com/nextcloud/talk/jobs/LeaveConversationWorker.java b/app/src/main/java/com/nextcloud/talk/jobs/LeaveConversationWorker.java index 849314dce..c1a59096f 100644 --- a/app/src/main/java/com/nextcloud/talk/jobs/LeaveConversationWorker.java +++ b/app/src/main/java/com/nextcloud/talk/jobs/LeaveConversationWorker.java @@ -63,15 +63,15 @@ public class LeaveConversationWorker extends Worker { public LeaveConversationWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) { super(context, workerParams); - NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); + NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); } @NonNull @Override public Result doWork() { Data data = getInputData(); - long operationUserId = data.getLong(BundleKeys.KEY_INTERNAL_USER_ID, -1); - String conversationToken = data.getString(BundleKeys.KEY_ROOM_TOKEN); + long operationUserId = data.getLong(BundleKeys.INSTANCE.getKEY_INTERNAL_USER_ID(), -1); + String conversationToken = data.getString(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN()); UserEntity operationUser = userUtils.getUserWithId(operationUserId); if (operationUser != null) { 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 dc27657f8..84f819129 100644 --- a/app/src/main/java/com/nextcloud/talk/jobs/NotificationWorker.java +++ b/app/src/main/java/com/nextcloud/talk/jobs/NotificationWorker.java @@ -71,8 +71,8 @@ import com.nextcloud.talk.models.json.chat.ChatUtils; import com.nextcloud.talk.models.json.notifications.NotificationOverall; import com.nextcloud.talk.models.json.push.DecryptedPushMessage; import com.nextcloud.talk.models.json.push.NotificationUser; -import com.nextcloud.talk.models.json.rooms.Conversation; -import com.nextcloud.talk.models.json.rooms.RoomOverall; +import com.nextcloud.talk.models.json.conversations.Conversation; +import com.nextcloud.talk.models.json.conversations.RoomOverall; import com.nextcloud.talk.utils.*; import com.nextcloud.talk.utils.bundle.BundleKeys; import com.nextcloud.talk.utils.database.arbitrarystorage.ArbitraryStorageUtils; @@ -132,13 +132,13 @@ public class NotificationWorker extends Worker { boolean muteCalls = false; if ((arbitraryStorageEntity = arbitraryStorageUtils.getStorageSetting(userEntity.getId(), - "mute_calls", intent.getExtras().getString(BundleKeys.KEY_ROOM_TOKEN))) != null) { + "mute_calls", intent.getExtras().getString(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN()))) != null) { muteCalls = Boolean.parseBoolean(arbitraryStorageEntity.getValue()); } if (!muteCalls) { ncApi.getRoom(credentials, ApiUtils.getRoom(userEntity.getBaseUrl(), - intent.getExtras().getString(BundleKeys.KEY_ROOM_TOKEN))) + intent.getExtras().getString(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN()))) .blockingSubscribe(new Observer() { @Override public void onSubscribe(Disposable d) { @@ -149,7 +149,7 @@ public class NotificationWorker extends Worker { public void onNext(RoomOverall roomOverall) { Conversation conversation = roomOverall.getOcs().getData(); - intent.putExtra(BundleKeys.KEY_ROOM, Parcels.wrap(conversation)); + intent.putExtra(BundleKeys.INSTANCE.getKEY_ROOM(), Parcels.wrap(conversation)); if (conversation.getType().equals(Conversation.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL) || (!TextUtils.isEmpty(conversation.getObjectType()) && "share:password".equals (conversation.getObjectType()))) { @@ -308,10 +308,10 @@ public class NotificationWorker extends Worker { } Bundle notificationInfo = new Bundle(); - notificationInfo.putLong(BundleKeys.KEY_INTERNAL_USER_ID, signatureVerification.getUserEntity().getId()); + notificationInfo.putLong(BundleKeys.INSTANCE.getKEY_INTERNAL_USER_ID(), signatureVerification.getUserEntity().getId()); // could be an ID or a TOKEN - notificationInfo.putString(BundleKeys.KEY_ROOM_TOKEN, decryptedPushMessage.getId()); - notificationInfo.putLong(BundleKeys.KEY_NOTIFICATION_ID, decryptedPushMessage.getNotificationId()); + notificationInfo.putString(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN(), decryptedPushMessage.getId()); + notificationInfo.putLong(BundleKeys.INSTANCE.getKEY_NOTIFICATION_ID(), decryptedPushMessage.getNotificationId()); notificationBuilder.setExtras(notificationInfo); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { @@ -462,7 +462,7 @@ public class NotificationWorker extends Worker { } if (soundUri != null & !ApplicationWideCurrentRoomHolder.getInstance().isInCall() && - DoNotDisturbUtils.shouldPlaySound()) { + DoNotDisturbUtils.INSTANCE.shouldPlaySound()) { AudioAttributes.Builder audioAttributesBuilder = new AudioAttributes.Builder().setContentType (AudioAttributes.CONTENT_TYPE_SONIFICATION); @@ -487,7 +487,7 @@ public class NotificationWorker extends Worker { } - if (DoNotDisturbUtils.shouldVibrate(appPreferences.getShouldVibrateSetting())) { + if (DoNotDisturbUtils.INSTANCE.shouldVibrate(appPreferences.getShouldVibrateSetting())) { Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); if (vibrator != null) { @@ -503,12 +503,12 @@ public class NotificationWorker extends Worker { @NonNull @Override public Result doWork() { - NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); + NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); context = getApplicationContext(); Data data = getInputData(); - String subject = data.getString(BundleKeys.KEY_NOTIFICATION_SUBJECT); - String signature = data.getString(BundleKeys.KEY_NOTIFICATION_SIGNATURE); + String subject = data.getString(BundleKeys.INSTANCE.getKEY_NOTIFICATION_SUBJECT()); + String signature = data.getString(BundleKeys.INSTANCE.getKEY_NOTIFICATION_SIGNATURE()); try { byte[] base64DecodedSubject = Base64.decode(subject, Base64.DEFAULT); @@ -560,28 +560,28 @@ public class NotificationWorker extends Worker { if (!signatureVerification.getUserEntity().hasSpreedFeatureCapability ("no-ping")) { - bundle.putString(BundleKeys.KEY_ROOM_ID, decryptedPushMessage.getId()); + bundle.putString(BundleKeys.INSTANCE.getKEY_ROOM_ID(), decryptedPushMessage.getId()); } else { - bundle.putString(BundleKeys.KEY_ROOM_TOKEN, decryptedPushMessage.getId()); + bundle.putString(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN(), decryptedPushMessage.getId()); } - bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, signatureVerification.getUserEntity()); + bundle.putParcelable(BundleKeys.INSTANCE.getKEY_USER_ENTITY(), signatureVerification.getUserEntity()); - bundle.putBoolean(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL, + bundle.putBoolean(BundleKeys.INSTANCE.getKEY_FROM_NOTIFICATION_START_CALL(), startACall); intent.putExtras(bundle); switch (decryptedPushMessage.getType()) { case "call": - if (!bundle.containsKey(BundleKeys.KEY_ROOM_TOKEN)) { + if (!bundle.containsKey(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN())) { context.startActivity(intent); } else { showNotificationForCallWithNoPing(intent); } break; case "room": - if (bundle.containsKey(BundleKeys.KEY_ROOM_TOKEN)) { + if (bundle.containsKey(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN())) { showNotificationForCallWithNoPing(intent); } break; diff --git a/app/src/main/java/com/nextcloud/talk/jobs/ShareOperationWorker.java b/app/src/main/java/com/nextcloud/talk/jobs/ShareOperationWorker.java index 0a4d4373f..908fcebc0 100644 --- a/app/src/main/java/com/nextcloud/talk/jobs/ShareOperationWorker.java +++ b/app/src/main/java/com/nextcloud/talk/jobs/ShareOperationWorker.java @@ -56,11 +56,11 @@ public class ShareOperationWorker extends Worker { public ShareOperationWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) { super(context, workerParams); - NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); + NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); Data data = workerParams.getInputData(); - userId = data.getLong(BundleKeys.KEY_INTERNAL_USER_ID, 0); - roomToken = data.getString(BundleKeys.KEY_ROOM_TOKEN); - Collections.addAll(filesArray, data.getStringArray(BundleKeys.KEY_FILE_PATHS)); + userId = data.getLong(BundleKeys.INSTANCE.getKEY_INTERNAL_USER_ID(), 0); + roomToken = data.getString(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN()); + Collections.addAll(filesArray, data.getStringArray(BundleKeys.INSTANCE.getKEY_FILE_PATHS())); operationsUser = userUtils.getUserWithId(userId); credentials = ApiUtils.getCredentials(operationsUser.getUsername(), operationsUser.getToken()); baseUrl = operationsUser.getBaseUrl(); diff --git a/app/src/main/java/com/nextcloud/talk/jobs/SignalingSettingsWorker.java b/app/src/main/java/com/nextcloud/talk/jobs/SignalingSettingsWorker.java index 475b80c23..7bf50c724 100644 --- a/app/src/main/java/com/nextcloud/talk/jobs/SignalingSettingsWorker.java +++ b/app/src/main/java/com/nextcloud/talk/jobs/SignalingSettingsWorker.java @@ -64,11 +64,11 @@ public class SignalingSettingsWorker extends Worker { @NonNull @Override public Result doWork() { - NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); + NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); Data data = getInputData(); - long internalUserId = data.getLong(BundleKeys.KEY_INTERNAL_USER_ID, -1); + long internalUserId = data.getLong(BundleKeys.INSTANCE.getKEY_INTERNAL_USER_ID(), -1); List userEntityList = new ArrayList<>(); UserEntity userEntity; diff --git a/app/src/main/java/com/nextcloud/talk/jobs/WebsocketConnectionsWorker.java b/app/src/main/java/com/nextcloud/talk/jobs/WebsocketConnectionsWorker.java index 8e17c07ce..82813e537 100644 --- a/app/src/main/java/com/nextcloud/talk/jobs/WebsocketConnectionsWorker.java +++ b/app/src/main/java/com/nextcloud/talk/jobs/WebsocketConnectionsWorker.java @@ -55,7 +55,7 @@ public class WebsocketConnectionsWorker extends Worker { @NonNull @Override public Result doWork() { - NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); + NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); List userEntityList = userUtils.getUsers(); UserEntity userEntity; diff --git a/app/src/main/java/com/nextcloud/talk/models/json/chat/ChatMessage.java b/app/src/main/java/com/nextcloud/talk/models/json/chat/ChatMessage.java index 519000cc5..c863f0111 100644 --- a/app/src/main/java/com/nextcloud/talk/models/json/chat/ChatMessage.java +++ b/app/src/main/java/com/nextcloud/talk/models/json/chat/ChatMessage.java @@ -97,7 +97,7 @@ public class ChatMessage implements IMessage, MessageContentType, MessageContent if (individualHashMap.get("type").equals("file")) { selectedIndividualHashMap = individualHashMap; return (ApiUtils.getUrlForFilePreviewWithFileId(getActiveUser().getBaseUrl(), - individualHashMap.get("id"), NextcloudTalkApplication.getSharedApplication().getResources().getDimensionPixelSize(R.dimen.maximum_file_preview_size))); + individualHashMap.get("id"), NextcloudTalkApplication.Companion.getSharedApplication().getResources().getDimensionPixelSize(R.dimen.maximum_file_preview_size))); } } } @@ -147,45 +147,45 @@ public class ChatMessage implements IMessage, MessageContentType, MessageContent || getMessageType().equals(MessageType.SINGLE_LINK_TENOR_MESSAGE) || getMessageType().equals(MessageType.SINGLE_LINK_GIF_MESSAGE)) { if (getActorId().equals(getActiveUser().getUserId())) { - return (NextcloudTalkApplication.getSharedApplication().getString(R.string.nc_sent_a_gif_you)); + return (NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_sent_a_gif_you)); } else { - return (String.format(NextcloudTalkApplication.getSharedApplication().getResources().getString(R.string.nc_sent_a_gif), - !TextUtils.isEmpty(getActorDisplayName()) ? getActorDisplayName() : NextcloudTalkApplication.getSharedApplication().getString(R.string.nc_guest))); + return (String.format(NextcloudTalkApplication.Companion.getSharedApplication().getResources().getString(R.string.nc_sent_a_gif), + !TextUtils.isEmpty(getActorDisplayName()) ? getActorDisplayName() : NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_guest))); } } else if (getMessageType().equals(MessageType.SINGLE_NC_ATTACHMENT_MESSAGE)) { if (getActorId().equals(getActiveUser().getUserId())) { - return (NextcloudTalkApplication.getSharedApplication().getString(R.string.nc_sent_an_attachment_you)); + return (NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_sent_an_attachment_you)); } else { - return (String.format(NextcloudTalkApplication.getSharedApplication().getResources().getString(R.string.nc_sent_an_attachment), - !TextUtils.isEmpty(getActorDisplayName()) ? getActorDisplayName() : NextcloudTalkApplication.getSharedApplication().getString(R.string.nc_guest))); + return (String.format(NextcloudTalkApplication.Companion.getSharedApplication().getResources().getString(R.string.nc_sent_an_attachment), + !TextUtils.isEmpty(getActorDisplayName()) ? getActorDisplayName() : NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_guest))); } } else if (getMessageType().equals(MessageType.SINGLE_LINK_MESSAGE)) { if (getActorId().equals(getActiveUser().getUserId())) { - return (NextcloudTalkApplication.getSharedApplication().getString(R.string.nc_sent_a_link_you)); + return (NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_sent_a_link_you)); } else { - return (String.format(NextcloudTalkApplication.getSharedApplication().getResources().getString(R.string.nc_sent_a_link), - !TextUtils.isEmpty(getActorDisplayName()) ? getActorDisplayName() : NextcloudTalkApplication.getSharedApplication().getString(R.string.nc_guest))); + return (String.format(NextcloudTalkApplication.Companion.getSharedApplication().getResources().getString(R.string.nc_sent_a_link), + !TextUtils.isEmpty(getActorDisplayName()) ? getActorDisplayName() : NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_guest))); } } else if (getMessageType().equals(MessageType.SINGLE_LINK_AUDIO_MESSAGE)) { if (getActorId().equals(getActiveUser().getUserId())) { - return (NextcloudTalkApplication.getSharedApplication().getString(R.string.nc_sent_an_audio_you)); + return (NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_sent_an_audio_you)); } else { - return (String.format(NextcloudTalkApplication.getSharedApplication().getResources().getString(R.string.nc_sent_an_audio), - !TextUtils.isEmpty(getActorDisplayName()) ? getActorDisplayName() : NextcloudTalkApplication.getSharedApplication().getString(R.string.nc_guest))); + return (String.format(NextcloudTalkApplication.Companion.getSharedApplication().getResources().getString(R.string.nc_sent_an_audio), + !TextUtils.isEmpty(getActorDisplayName()) ? getActorDisplayName() : NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_guest))); } } else if (getMessageType().equals(MessageType.SINGLE_LINK_VIDEO_MESSAGE)) { if (getActorId().equals(getActiveUser().getUserId())) { - return (NextcloudTalkApplication.getSharedApplication().getString(R.string.nc_sent_a_video_you)); + return (NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_sent_a_video_you)); } else { - return (String.format(NextcloudTalkApplication.getSharedApplication().getResources().getString(R.string.nc_sent_a_video), - !TextUtils.isEmpty(getActorDisplayName()) ? getActorDisplayName() : NextcloudTalkApplication.getSharedApplication().getString(R.string.nc_guest))); + return (String.format(NextcloudTalkApplication.Companion.getSharedApplication().getResources().getString(R.string.nc_sent_a_video), + !TextUtils.isEmpty(getActorDisplayName()) ? getActorDisplayName() : NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_guest))); } } else if (getMessageType().equals(MessageType.SINGLE_LINK_IMAGE_MESSAGE)) { if (getActorId().equals(getActiveUser().getUserId())) { - return (NextcloudTalkApplication.getSharedApplication().getString(R.string.nc_sent_an_image_you)); + return (NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_sent_an_image_you)); } else { - return (String.format(NextcloudTalkApplication.getSharedApplication().getResources().getString(R.string.nc_sent_an_image), - !TextUtils.isEmpty(getActorDisplayName()) ? getActorDisplayName() : NextcloudTalkApplication.getSharedApplication().getString(R.string.nc_guest))); + return (String.format(NextcloudTalkApplication.Companion.getSharedApplication().getResources().getString(R.string.nc_sent_an_image), + !TextUtils.isEmpty(getActorDisplayName()) ? getActorDisplayName() : NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_guest))); } } } @@ -257,5 +257,8 @@ public class ChatMessage implements IMessage, MessageContentType, MessageContent MODERATOR_PROMOTED, MODERATOR_DEMOTED, FILE_SHARED, + LOBBY_NONE, + LOBBY_NON_MODERATORS, + LOBBY_OPEN_TO_EVERYONE } } diff --git a/app/src/main/java/com/nextcloud/talk/models/json/rooms/Conversation.java b/app/src/main/java/com/nextcloud/talk/models/json/conversations/Conversation.java similarity index 82% rename from app/src/main/java/com/nextcloud/talk/models/json/rooms/Conversation.java rename to app/src/main/java/com/nextcloud/talk/models/json/conversations/Conversation.java index ad7e49ce4..d05bf2c7b 100644 --- a/app/src/main/java/com/nextcloud/talk/models/json/rooms/Conversation.java +++ b/app/src/main/java/com/nextcloud/talk/models/json/conversations/Conversation.java @@ -18,15 +18,19 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.nextcloud.talk.models.json.rooms; +package com.nextcloud.talk.models.json.conversations; import android.content.res.Resources; + +import androidx.annotation.Nullable; + import com.bluelinelabs.logansquare.annotation.JsonField; import com.bluelinelabs.logansquare.annotation.JsonObject; import com.nextcloud.talk.R; import com.nextcloud.talk.application.NextcloudTalkApplication; import com.nextcloud.talk.models.database.UserEntity; import com.nextcloud.talk.models.json.chat.ChatMessage; +import com.nextcloud.talk.models.json.converters.EnumLobbyStateConverter; import com.nextcloud.talk.models.json.converters.EnumNotificationLevelConverter; import com.nextcloud.talk.models.json.converters.EnumParticipantTypeConverter; import com.nextcloud.talk.models.json.converters.EnumReadOnlyConversationConverter; @@ -79,11 +83,15 @@ public class Conversation { @JsonField(name = "lastMessage") public ChatMessage lastMessage; @JsonField(name = "objectType") - String objectType; + public String objectType; @JsonField(name = "notificationLevel", typeConverter = EnumNotificationLevelConverter.class) - NotificationLevel notificationLevel; + public NotificationLevel notificationLevel; @JsonField(name = "readOnly", typeConverter = EnumReadOnlyConversationConverter.class) - ConversationReadOnlyState conversationReadOnlyState; + public ConversationReadOnlyState conversationReadOnlyState; + @JsonField(name = "lobbyState", typeConverter = EnumLobbyStateConverter.class) + public LobbyState lobbyState; + @JsonField(name = "lobbyTimer") + public Long lobbyTimer; public boolean isPublic() { @@ -97,7 +105,7 @@ public class Conversation { private boolean isLockedOneToOne(UserEntity conversationUser) { - return (getType() == ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL && conversationUser.hasSpreedFeatureCapability("locked-one-to-one-rooms")); + return (getType() == ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL && conversationUser.hasSpreedFeatureCapability("locked-one-to-one-conversations")); } public boolean canModerate(UserEntity conversationUser) { @@ -105,6 +113,13 @@ public class Conversation { || Participant.ParticipantType.MODERATOR.equals(participantType)) && !isLockedOneToOne(conversationUser)); } + public boolean shouldShowLobby(UserEntity conversationUser) { + return getLobbyState().equals(LobbyState.LOBBY_STATE_MODERATORS_ONLY) && !canModerate(conversationUser); + } + + public boolean isLobbyViewApplicable(UserEntity conversationUser) { + return !canModerate(conversationUser) && (getType() == ConversationType.ROOM_GROUP_CALL || getType() == ConversationType.ROOM_PUBLIC_CALL); + } public boolean isNameEditable(UserEntity conversationUser) { return (canModerate(conversationUser) && !ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL.equals(type)); } @@ -115,7 +130,7 @@ public class Conversation { } public String getDeleteWarningMessage() { - Resources resources = NextcloudTalkApplication.getSharedApplication().getResources(); + Resources resources = NextcloudTalkApplication.Companion.getSharedApplication().getResources(); if (getType() == ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL) { return String.format(resources.getString(R.string.nc_delete_conversation_one2one), getDisplayName()); @@ -133,6 +148,11 @@ public class Conversation { NEVER } + public enum LobbyState { + LOBBY_STATE_ALL_PARTICIPANTS, + LOBBY_STATE_MODERATORS_ONLY + } + public enum ConversationReadOnlyState { CONVERSATION_READ_WRITE, CONVERSATION_READ_ONLY diff --git a/app/src/main/java/com/nextcloud/talk/models/json/rooms/RoomOCS.java b/app/src/main/java/com/nextcloud/talk/models/json/conversations/RoomOCS.java similarity index 92% rename from app/src/main/java/com/nextcloud/talk/models/json/rooms/RoomOCS.java rename to app/src/main/java/com/nextcloud/talk/models/json/conversations/RoomOCS.java index ee6741c04..b57698357 100644 --- a/app/src/main/java/com/nextcloud/talk/models/json/rooms/RoomOCS.java +++ b/app/src/main/java/com/nextcloud/talk/models/json/conversations/RoomOCS.java @@ -18,7 +18,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.nextcloud.talk.models.json.rooms; +package com.nextcloud.talk.models.json.conversations; import com.bluelinelabs.logansquare.annotation.JsonField; import com.bluelinelabs.logansquare.annotation.JsonObject; @@ -29,5 +29,5 @@ import lombok.Data; @JsonObject public class RoomOCS extends GenericOCS { @JsonField(name = "data") - Conversation data; + public Conversation data; } diff --git a/app/src/main/java/com/nextcloud/talk/models/json/rooms/RoomOverall.java b/app/src/main/java/com/nextcloud/talk/models/json/conversations/RoomOverall.java similarity index 92% rename from app/src/main/java/com/nextcloud/talk/models/json/rooms/RoomOverall.java rename to app/src/main/java/com/nextcloud/talk/models/json/conversations/RoomOverall.java index 0a158cb15..ef0a0e720 100644 --- a/app/src/main/java/com/nextcloud/talk/models/json/rooms/RoomOverall.java +++ b/app/src/main/java/com/nextcloud/talk/models/json/conversations/RoomOverall.java @@ -18,7 +18,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.nextcloud.talk.models.json.rooms; +package com.nextcloud.talk.models.json.conversations; import com.bluelinelabs.logansquare.annotation.JsonField; import com.bluelinelabs.logansquare.annotation.JsonObject; @@ -28,5 +28,5 @@ import lombok.Data; @JsonObject public class RoomOverall { @JsonField(name = "ocs") - RoomOCS ocs; + public RoomOCS ocs; } diff --git a/app/src/main/java/com/nextcloud/talk/models/json/rooms/RoomsOCS.java b/app/src/main/java/com/nextcloud/talk/models/json/conversations/RoomsOCS.java similarity index 92% rename from app/src/main/java/com/nextcloud/talk/models/json/rooms/RoomsOCS.java rename to app/src/main/java/com/nextcloud/talk/models/json/conversations/RoomsOCS.java index f8d5aa291..2aa2b35a6 100644 --- a/app/src/main/java/com/nextcloud/talk/models/json/rooms/RoomsOCS.java +++ b/app/src/main/java/com/nextcloud/talk/models/json/conversations/RoomsOCS.java @@ -18,7 +18,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.nextcloud.talk.models.json.rooms; +package com.nextcloud.talk.models.json.conversations; import com.bluelinelabs.logansquare.annotation.JsonField; import com.bluelinelabs.logansquare.annotation.JsonObject; @@ -33,5 +33,5 @@ import java.util.List; @JsonObject public class RoomsOCS extends GenericOCS { @JsonField(name = "data") - List data; + public List data; } diff --git a/app/src/main/java/com/nextcloud/talk/models/json/rooms/RoomsOverall.java b/app/src/main/java/com/nextcloud/talk/models/json/conversations/RoomsOverall.java similarity index 92% rename from app/src/main/java/com/nextcloud/talk/models/json/rooms/RoomsOverall.java rename to app/src/main/java/com/nextcloud/talk/models/json/conversations/RoomsOverall.java index 0ef326f14..db70df2f9 100644 --- a/app/src/main/java/com/nextcloud/talk/models/json/rooms/RoomsOverall.java +++ b/app/src/main/java/com/nextcloud/talk/models/json/conversations/RoomsOverall.java @@ -18,7 +18,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.nextcloud.talk.models.json.rooms; +package com.nextcloud.talk.models.json.conversations; import com.bluelinelabs.logansquare.annotation.JsonField; import com.bluelinelabs.logansquare.annotation.JsonObject; @@ -30,5 +30,5 @@ import org.parceler.Parcel; @JsonObject public class RoomsOverall { @JsonField(name = "ocs") - RoomsOCS ocs; + public RoomsOCS ocs; } diff --git a/app/src/main/java/com/nextcloud/talk/models/json/converters/EnumLobbyStateConverter.java b/app/src/main/java/com/nextcloud/talk/models/json/converters/EnumLobbyStateConverter.java new file mode 100644 index 000000000..99eaa4dc5 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/models/json/converters/EnumLobbyStateConverter.java @@ -0,0 +1,50 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017-2019 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.json.converters; + +import com.bluelinelabs.logansquare.typeconverters.IntBasedTypeConverter; +import com.nextcloud.talk.models.json.conversations.Conversation; + +public class EnumLobbyStateConverter extends IntBasedTypeConverter { + @Override + public Conversation.LobbyState getFromInt(int i) { + switch (i) { + case 0: + return Conversation.LobbyState.LOBBY_STATE_ALL_PARTICIPANTS; + case 1: + return Conversation.LobbyState.LOBBY_STATE_MODERATORS_ONLY; + default: + return Conversation.LobbyState.LOBBY_STATE_ALL_PARTICIPANTS; + } + } + + @Override + public int convertToInt(Conversation.LobbyState object) { + switch (object) { + case LOBBY_STATE_ALL_PARTICIPANTS: + return 0; + case LOBBY_STATE_MODERATORS_ONLY: + return 1; + default: + return 0; + } + } +} diff --git a/app/src/main/java/com/nextcloud/talk/models/json/converters/EnumNotificationLevelConverter.java b/app/src/main/java/com/nextcloud/talk/models/json/converters/EnumNotificationLevelConverter.java index 6f41f9bc9..1772b4370 100644 --- a/app/src/main/java/com/nextcloud/talk/models/json/converters/EnumNotificationLevelConverter.java +++ b/app/src/main/java/com/nextcloud/talk/models/json/converters/EnumNotificationLevelConverter.java @@ -21,7 +21,7 @@ package com.nextcloud.talk.models.json.converters; import com.bluelinelabs.logansquare.typeconverters.IntBasedTypeConverter; -import com.nextcloud.talk.models.json.rooms.Conversation; +import com.nextcloud.talk.models.json.conversations.Conversation; public class EnumNotificationLevelConverter extends IntBasedTypeConverter { @Override diff --git a/app/src/main/java/com/nextcloud/talk/models/json/converters/EnumReadOnlyConversationConverter.java b/app/src/main/java/com/nextcloud/talk/models/json/converters/EnumReadOnlyConversationConverter.java index 5c0f097cd..2d4ab61c7 100644 --- a/app/src/main/java/com/nextcloud/talk/models/json/converters/EnumReadOnlyConversationConverter.java +++ b/app/src/main/java/com/nextcloud/talk/models/json/converters/EnumReadOnlyConversationConverter.java @@ -21,7 +21,7 @@ package com.nextcloud.talk.models.json.converters; import com.bluelinelabs.logansquare.typeconverters.IntBasedTypeConverter; -import com.nextcloud.talk.models.json.rooms.Conversation; +import com.nextcloud.talk.models.json.conversations.Conversation; public class EnumReadOnlyConversationConverter extends IntBasedTypeConverter { @Override diff --git a/app/src/main/java/com/nextcloud/talk/models/json/converters/EnumRoomTypeConverter.java b/app/src/main/java/com/nextcloud/talk/models/json/converters/EnumRoomTypeConverter.java index 4aa4df9b9..ed4e02513 100644 --- a/app/src/main/java/com/nextcloud/talk/models/json/converters/EnumRoomTypeConverter.java +++ b/app/src/main/java/com/nextcloud/talk/models/json/converters/EnumRoomTypeConverter.java @@ -21,7 +21,7 @@ package com.nextcloud.talk.models.json.converters; import com.bluelinelabs.logansquare.typeconverters.IntBasedTypeConverter; -import com.nextcloud.talk.models.json.rooms.Conversation; +import com.nextcloud.talk.models.json.conversations.Conversation; public class EnumRoomTypeConverter extends IntBasedTypeConverter { @Override diff --git a/app/src/main/java/com/nextcloud/talk/models/json/converters/EnumSystemMessageTypeConverter.java b/app/src/main/java/com/nextcloud/talk/models/json/converters/EnumSystemMessageTypeConverter.java deleted file mode 100644 index 59e1855f7..000000000 --- a/app/src/main/java/com/nextcloud/talk/models/json/converters/EnumSystemMessageTypeConverter.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * 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.json.converters; - -import com.bluelinelabs.logansquare.typeconverters.StringBasedTypeConverter; -import com.nextcloud.talk.models.json.chat.ChatMessage; - -import static com.nextcloud.talk.models.json.chat.ChatMessage.SystemMessageType.*; - -/* - - conversation_created - {actor} created the conversation - conversation_renamed - {actor} renamed the conversation from "foo" to "bar" - call_joined - {actor} joined the call - call_left - {actor} left the call - call_ended - Call with {user1}, {user2}, {user3}, {user4} and {user5} (Duration 30:23) - guests_allowed - {actor} allowed guests in the conversation - guests_disallowed - {actor} disallowed guests in the conversation - password_set - {actor} set a password for the conversation - password_removed - {actor} removed the password for the conversation - user_added - {actor} added {user} to the conversation - user_removed - {actor} removed {user} from the conversation - moderator_promoted - {actor} promoted {user} to moderator - moderator_demoted - {actor} demoted {user} from moderator - - */ -public class EnumSystemMessageTypeConverter extends StringBasedTypeConverter { - @Override - public ChatMessage.SystemMessageType getFromString(String string) { - switch (string) { - case "conversation_created": - return CONVERSATION_CREATED; - case "conversation_renamed": - return CONVERSATION_RENAMED; - case "call_started": - return CALL_STARTED; - case "call_joined": - return CALL_JOINED; - case "call_left": - return CALL_LEFT; - case "call_ended": - return CALL_ENDED; - case "guests_allowed": - return GUESTS_ALLOWED; - case "guests_disallowed": - return GUESTS_DISALLOWED; - case "password_set": - return PASSWORD_SET; - case "password_removed": - return PASSWORD_REMOVED; - case "user_added": - return USER_ADDED; - case "user_removed": - return USER_REMOVED; - case "moderator_promoted": - return MODERATOR_PROMOTED; - case "moderator_demoted": - return MODERATOR_DEMOTED; - case "file_shared": - return FILE_SHARED; - default: - return DUMMY; - } - } - - @Override - public String convertToString(ChatMessage.SystemMessageType object) { - - if (object == null) { - return ""; - } - - switch (object) { - case CONVERSATION_CREATED: - return "conversation_created"; - case CONVERSATION_RENAMED: - return "conversation_renamed"; - case CALL_STARTED: - return "call_started"; - case CALL_JOINED: - return "call_joined"; - case CALL_LEFT: - return "call_left"; - case CALL_ENDED: - return "call_ended"; - case GUESTS_ALLOWED: - return "guests_allowed"; - case GUESTS_DISALLOWED: - return "guests_disallowed"; - case PASSWORD_SET: - return "password_set"; - case PASSWORD_REMOVED: - return "password_removed"; - case USER_ADDED: - return "user_added"; - case USER_REMOVED: - return "user_removed"; - case MODERATOR_PROMOTED: - return "moderator_promoted"; - case MODERATOR_DEMOTED: - return "moderator_demoted"; - case FILE_SHARED: - return "file_shared"; - default: - return ""; - } - } -} diff --git a/app/src/main/java/com/nextcloud/talk/models/json/converters/EnumSystemMessageTypeConverter.kt b/app/src/main/java/com/nextcloud/talk/models/json/converters/EnumSystemMessageTypeConverter.kt new file mode 100644 index 000000000..48205eff3 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/models/json/converters/EnumSystemMessageTypeConverter.kt @@ -0,0 +1,98 @@ +/* + * 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.json.converters + +import com.bluelinelabs.logansquare.typeconverters.StringBasedTypeConverter +import com.nextcloud.talk.models.json.chat.ChatMessage + +import com.nextcloud.talk.models.json.chat.ChatMessage.SystemMessageType.* + +/* + + conversation_created - {actor} created the conversation + conversation_renamed - {actor} renamed the conversation from "foo" to "bar" + call_joined - {actor} joined the call + call_left - {actor} left the call + call_ended - Call with {user1}, {user2}, {user3}, {user4} and {user5} (Duration 30:23) + guests_allowed - {actor} allowed guests in the conversation + guests_disallowed - {actor} disallowed guests in the conversation + password_set - {actor} set a password for the conversation + password_removed - {actor} removed the password for the conversation + user_added - {actor} added {user} to the conversation + user_removed - {actor} removed {user} from the conversation + moderator_promoted - {actor} promoted {user} to moderator + moderator_demoted - {actor} demoted {user} from moderator + + */ +class EnumSystemMessageTypeConverter : StringBasedTypeConverter() { + override fun getFromString(string: String): ChatMessage.SystemMessageType { + when (string) { + "conversation_created" -> return CONVERSATION_CREATED + "conversation_renamed" -> return CONVERSATION_RENAMED + "call_started" -> return CALL_STARTED + "call_joined" -> return CALL_JOINED + "call_left" -> return CALL_LEFT + "call_ended" -> return CALL_ENDED + "guests_allowed" -> return GUESTS_ALLOWED + "guests_disallowed" -> return GUESTS_DISALLOWED + "password_set" -> return PASSWORD_SET + "password_removed" -> return PASSWORD_REMOVED + "user_added" -> return USER_ADDED + "user_removed" -> return USER_REMOVED + "moderator_promoted" -> return MODERATOR_PROMOTED + "moderator_demoted" -> return MODERATOR_DEMOTED + "file_shared" -> return FILE_SHARED + "lobby_none" -> return LOBBY_NONE + "lobby_non_moderators" -> return LOBBY_NON_MODERATORS + "lobby_timer_reached" -> return LOBBY_OPEN_TO_EVERYONE + else -> return DUMMY + } + } + + override fun convertToString(`object`: ChatMessage.SystemMessageType?): String { + + if (`object` == null) { + return "" + } + + when (`object`) { + CONVERSATION_CREATED -> return "conversation_created" + CONVERSATION_RENAMED -> return "conversation_renamed" + CALL_STARTED -> return "call_started" + CALL_JOINED -> return "call_joined" + CALL_LEFT -> return "call_left" + CALL_ENDED -> return "call_ended" + GUESTS_ALLOWED -> return "guests_allowed" + GUESTS_DISALLOWED -> return "guests_disallowed" + PASSWORD_SET -> return "password_set" + PASSWORD_REMOVED -> return "password_removed" + USER_ADDED -> return "user_added" + USER_REMOVED -> return "user_removed" + MODERATOR_PROMOTED -> return "moderator_promoted" + MODERATOR_DEMOTED -> return "moderator_demoted" + FILE_SHARED -> return "file_shared" + LOBBY_NONE -> return "lobby_none" + LOBBY_NON_MODERATORS -> return "lobby_non_moderators" + LOBBY_OPEN_TO_EVERYONE -> return "lobby_timer_reached" + else -> return "" + } + } +} diff --git a/app/src/main/java/com/nextcloud/talk/models/json/generic/GenericMeta.java b/app/src/main/java/com/nextcloud/talk/models/json/generic/GenericMeta.java index d977c9edc..490bf7acc 100644 --- a/app/src/main/java/com/nextcloud/talk/models/json/generic/GenericMeta.java +++ b/app/src/main/java/com/nextcloud/talk/models/json/generic/GenericMeta.java @@ -30,11 +30,11 @@ import org.parceler.Parcel; @JsonObject(serializeNullObjects = true) public class GenericMeta { @JsonField(name = "status") - String status; + public String status; @JsonField(name = "statuscode") - int statusCode; + public int statusCode; @JsonField(name = "message") - String message; + public String message; } diff --git a/app/src/main/java/com/nextcloud/talk/models/json/generic/GenericOCS.java b/app/src/main/java/com/nextcloud/talk/models/json/generic/GenericOCS.java index 920a1bae1..335ed52cf 100644 --- a/app/src/main/java/com/nextcloud/talk/models/json/generic/GenericOCS.java +++ b/app/src/main/java/com/nextcloud/talk/models/json/generic/GenericOCS.java @@ -30,5 +30,5 @@ import org.parceler.Parcel; @JsonObject public class GenericOCS { @JsonField(name = "meta") - GenericMeta meta; + public GenericMeta meta; } diff --git a/app/src/main/java/com/nextcloud/talk/models/json/generic/GenericOverall.java b/app/src/main/java/com/nextcloud/talk/models/json/generic/GenericOverall.java index e8b9043c9..d750a6255 100644 --- a/app/src/main/java/com/nextcloud/talk/models/json/generic/GenericOverall.java +++ b/app/src/main/java/com/nextcloud/talk/models/json/generic/GenericOverall.java @@ -30,5 +30,5 @@ import org.parceler.Parcel; @JsonObject public class GenericOverall { @JsonField(name = "ocs") - GenericOCS ocs; + public GenericOCS ocs; } diff --git a/app/src/main/java/com/nextcloud/talk/models/json/participants/AddParticipantOCS.java b/app/src/main/java/com/nextcloud/talk/models/json/participants/AddParticipantOCS.java index 15df7101d..443abdc0d 100644 --- a/app/src/main/java/com/nextcloud/talk/models/json/participants/AddParticipantOCS.java +++ b/app/src/main/java/com/nextcloud/talk/models/json/participants/AddParticipantOCS.java @@ -23,7 +23,7 @@ package com.nextcloud.talk.models.json.participants; 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.rooms.Conversation; +import com.nextcloud.talk.models.json.conversations.Conversation; @JsonObject public class AddParticipantOCS extends GenericOCS { diff --git a/app/src/main/java/com/nextcloud/talk/models/json/participants/AddParticipantOverall.java b/app/src/main/java/com/nextcloud/talk/models/json/participants/AddParticipantOverall.java index 696d31422..d7bb38b7d 100644 --- a/app/src/main/java/com/nextcloud/talk/models/json/participants/AddParticipantOverall.java +++ b/app/src/main/java/com/nextcloud/talk/models/json/participants/AddParticipantOverall.java @@ -22,7 +22,7 @@ package com.nextcloud.talk.models.json.participants; import com.bluelinelabs.logansquare.annotation.JsonField; import com.bluelinelabs.logansquare.annotation.JsonObject; -import com.nextcloud.talk.models.json.rooms.RoomsOCS; +import com.nextcloud.talk.models.json.conversations.RoomsOCS; import lombok.Data; @Data diff --git a/app/src/main/java/com/nextcloud/talk/models/json/participants/Participant.java b/app/src/main/java/com/nextcloud/talk/models/json/participants/Participant.java index 5d72f7992..4d49f4dc3 100644 --- a/app/src/main/java/com/nextcloud/talk/models/json/participants/Participant.java +++ b/app/src/main/java/com/nextcloud/talk/models/json/participants/Participant.java @@ -33,32 +33,32 @@ import org.parceler.ParcelPropertyConverter; @JsonObject public class Participant { @JsonField(name = "userId") - String userId; + public String userId; @JsonField(name = {"type", "participantType"}, typeConverter = EnumParticipantTypeConverter.class) - ParticipantType type; + public ParticipantType type; @JsonField(name = "name") - String name; + public String name; @JsonField(name = "displayName") - String displayName; + public String displayName; @JsonField(name = "lastPing") - long lastPing; + public long lastPing; @JsonField(name = "sessionId") - String sessionId; + public String sessionId; @JsonField(name = "roomId") - long roomId; + public long roomId; @ParcelPropertyConverter(ObjectParcelConverter.class) @JsonField(name = "inCall") - Object inCall; - String source; + public Object inCall; + public String source; - boolean selected; + public boolean selected; public ParticipantFlags getParticipantFlags() { diff --git a/app/src/main/java/com/nextcloud/talk/models/json/participants/ParticipantsOCS.java b/app/src/main/java/com/nextcloud/talk/models/json/participants/ParticipantsOCS.java index 26c336a9f..b27fdd088 100644 --- a/app/src/main/java/com/nextcloud/talk/models/json/participants/ParticipantsOCS.java +++ b/app/src/main/java/com/nextcloud/talk/models/json/participants/ParticipantsOCS.java @@ -33,5 +33,5 @@ import java.util.List; @JsonObject public class ParticipantsOCS extends GenericOCS { @JsonField(name = "data") - List data; + public List data; } diff --git a/app/src/main/java/com/nextcloud/talk/models/json/participants/ParticipantsOverall.java b/app/src/main/java/com/nextcloud/talk/models/json/participants/ParticipantsOverall.java index 6a0bcc1d3..6ab2b97a5 100644 --- a/app/src/main/java/com/nextcloud/talk/models/json/participants/ParticipantsOverall.java +++ b/app/src/main/java/com/nextcloud/talk/models/json/participants/ParticipantsOverall.java @@ -30,5 +30,5 @@ import org.parceler.Parcel; @JsonObject public class ParticipantsOverall { @JsonField(name = "ocs") - ParticipantsOCS ocs; + public ParticipantsOCS ocs; } diff --git a/app/src/main/java/com/nextcloud/talk/models/json/websocket/RoomPropertiesWebSocketMessage.java b/app/src/main/java/com/nextcloud/talk/models/json/websocket/RoomPropertiesWebSocketMessage.java index 5c0b2489c..7e4372a11 100644 --- a/app/src/main/java/com/nextcloud/talk/models/json/websocket/RoomPropertiesWebSocketMessage.java +++ b/app/src/main/java/com/nextcloud/talk/models/json/websocket/RoomPropertiesWebSocketMessage.java @@ -23,7 +23,7 @@ package com.nextcloud.talk.models.json.websocket; import com.bluelinelabs.logansquare.annotation.JsonField; import com.bluelinelabs.logansquare.annotation.JsonObject; import com.nextcloud.talk.models.json.converters.EnumRoomTypeConverter; -import com.nextcloud.talk.models.json.rooms.Conversation; +import com.nextcloud.talk.models.json.conversations.Conversation; import lombok.Data; import org.parceler.Parcel; diff --git a/app/src/main/java/com/nextcloud/talk/presenters/MentionAutocompletePresenter.java b/app/src/main/java/com/nextcloud/talk/presenters/MentionAutocompletePresenter.java index ebfb6f922..22d18e705 100644 --- a/app/src/main/java/com/nextcloud/talk/presenters/MentionAutocompletePresenter.java +++ b/app/src/main/java/com/nextcloud/talk/presenters/MentionAutocompletePresenter.java @@ -62,7 +62,7 @@ public class MentionAutocompletePresenter extends RecyclerViewPresenter public MentionAutocompletePresenter(Context context) { super(context); this.context = context; - NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); + NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); currentUser = userUtils.getCurrentUser(); } @@ -70,7 +70,7 @@ public class MentionAutocompletePresenter extends RecyclerViewPresenter super(context); this.roomToken = roomToken; this.context = context; - NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); + NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); currentUser = userUtils.getCurrentUser(); } diff --git a/app/src/main/java/com/nextcloud/talk/receivers/PackageReplacedReceiver.java b/app/src/main/java/com/nextcloud/talk/receivers/PackageReplacedReceiver.java index 93c89b1d8..28fba9729 100644 --- a/app/src/main/java/com/nextcloud/talk/receivers/PackageReplacedReceiver.java +++ b/app/src/main/java/com/nextcloud/talk/receivers/PackageReplacedReceiver.java @@ -49,7 +49,7 @@ public class PackageReplacedReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { - NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); + NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); if (intent != null && intent.getAction() != null && intent.getAction().equals("android.intent.action.MY_PACKAGE_REPLACED")) { diff --git a/app/src/main/java/com/nextcloud/talk/utils/AccountUtils.java b/app/src/main/java/com/nextcloud/talk/utils/AccountUtils.java deleted file mode 100644 index 5257316d2..000000000 --- a/app/src/main/java/com/nextcloud/talk/utils/AccountUtils.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Nextcloud Talk application - * - * @author Mario Danic - * Copyright (C) 2017 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 . - * - * Parts related to account import were either copied from or inspired by the great work done by David Luhmer at: - * https://github.com/nextcloud/ownCloud-Account-Importer - */ - -package com.nextcloud.talk.utils; - -import android.accounts.Account; -import android.accounts.AccountManager; -import android.content.Context; -import android.content.pm.PackageInfo; -import android.content.pm.PackageManager; -import android.content.pm.Signature; -import android.util.Log; -import com.nextcloud.talk.R; -import com.nextcloud.talk.application.NextcloudTalkApplication; -import com.nextcloud.talk.models.ImportAccount; -import com.nextcloud.talk.models.database.UserEntity; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public class AccountUtils { - - private static final String TAG = "AccountUtils"; - - public static List findAccounts(List userEntitiesList) { - Context context = NextcloudTalkApplication.getSharedApplication().getApplicationContext(); - final AccountManager accMgr = AccountManager.get(context); - final Account[] accounts = accMgr.getAccountsByType(context.getString(R.string.nc_import_account_type)); - - List accountsAvailable = new ArrayList<>(); - ImportAccount importAccount; - UserEntity internalUserEntity; - boolean accountFound; - for (Account account : accounts) { - accountFound = false; - - for (int i = 0; i < userEntitiesList.size(); i++) { - internalUserEntity = userEntitiesList.get(i); - importAccount = getInformationFromAccount(account); - if (importAccount.getToken() != null) { - if (importAccount.getBaseUrl().startsWith("http://") || - importAccount.getBaseUrl().startsWith("https://")) { - if (internalUserEntity.getUsername().equals(importAccount.getUsername()) && - internalUserEntity.getBaseUrl().equals(importAccount.getBaseUrl())) { - accountFound = true; - break; - } - } else { - if (internalUserEntity.getUsername().equals(importAccount.getUsername()) && - (internalUserEntity.getBaseUrl().equals("http://" + importAccount.getBaseUrl()) || - internalUserEntity.getBaseUrl().equals("https://" + - importAccount.getBaseUrl()))) { - accountFound = true; - break; - } - - } - } else { - accountFound = true; - break; - } - } - - if (!accountFound) { - accountsAvailable.add(account); - } - } - - return accountsAvailable; - } - - public static String getAppNameBasedOnPackage(String packageName) { - Context context = NextcloudTalkApplication.getSharedApplication().getApplicationContext(); - PackageManager packageManager = context.getPackageManager(); - String appName = ""; - try { - appName = (String) packageManager.getApplicationLabel(packageManager.getApplicationInfo(packageName, - PackageManager.GET_META_DATA)); - } catch (PackageManager.NameNotFoundException e) { - Log.e(TAG, "Failed to get app name based on package"); - } - - return appName; - } - - public static boolean canWeOpenFilesApp(Context context, String accountName) { - PackageManager pm = context.getPackageManager(); - try { - PackageInfo packageInfo = - pm.getPackageInfo(context.getString(R.string.nc_import_accounts_from), 0); - if (packageInfo.versionCode >= 30060151) { - Signature[] ownSignatures = pm.getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES).signatures; - Signature[] filesAppSignatures = pm.getPackageInfo(context.getString(R.string.nc_import_accounts_from), PackageManager.GET_SIGNATURES).signatures; - - if (Arrays.equals(ownSignatures, filesAppSignatures)) { - final AccountManager accMgr = AccountManager.get(context); - final Account[] accounts = accMgr.getAccountsByType(context.getString(R.string.nc_import_account_type)); - for (Account account : accounts) { - if (account.name.equals(accountName)) { - return true; - } - } - } else { - return true; - } - } - } catch (PackageManager.NameNotFoundException appNotFoundException) { - - } - return false; - } - - public static ImportAccount getInformationFromAccount(Account account) { - int lastAtPos = account.name.lastIndexOf("@"); - String urlString = account.name.substring(lastAtPos + 1); - String username = account.name.substring(0, lastAtPos); - - Context context = NextcloudTalkApplication.getSharedApplication().getApplicationContext(); - final AccountManager accMgr = AccountManager.get(context); - - String password = null; - try { - password = accMgr.getPassword(account); - } catch (Exception exception) { - Log.e(TAG, "Failed to import account"); - } - - if (urlString.endsWith("/")) { - urlString = urlString.substring(0, urlString.length() - 1); - } - - return new ImportAccount(username, password, urlString); - } -} - diff --git a/app/src/main/java/com/nextcloud/talk/utils/AccountUtils.kt b/app/src/main/java/com/nextcloud/talk/utils/AccountUtils.kt new file mode 100644 index 000000000..83e12c9df --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/utils/AccountUtils.kt @@ -0,0 +1,149 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 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 . + * + * Parts related to account import were either copied from or inspired by the great work done by David Luhmer at: + * https://github.com/nextcloud/ownCloud-Account-Importer + */ + +package com.nextcloud.talk.utils + +import android.accounts.Account +import android.accounts.AccountManager +import android.content.Context +import android.content.pm.PackageManager +import android.util.Log +import com.nextcloud.talk.R +import com.nextcloud.talk.application.NextcloudTalkApplication +import com.nextcloud.talk.models.ImportAccount +import com.nextcloud.talk.models.database.UserEntity +import java.util.* + +object AccountUtils { + + private val TAG = "AccountUtils" + + fun findAccounts(userEntitiesList: List): List { + val context = NextcloudTalkApplication.sharedApplication!!.applicationContext + val accMgr = AccountManager.get(context) + val accounts = accMgr.getAccountsByType(context.getString(R.string.nc_import_account_type)) + + val accountsAvailable = ArrayList() + var importAccount: ImportAccount + var internalUserEntity: UserEntity + var accountFound: Boolean + for (account in accounts) { + accountFound = false + + for (i in userEntitiesList.indices) { + internalUserEntity = userEntitiesList[i] + importAccount = getInformationFromAccount(account) + if (importAccount.token != null) { + if (importAccount.baseUrl.startsWith("http://") || importAccount.baseUrl.startsWith("https://")) { + if (internalUserEntity.username == importAccount.username && internalUserEntity.baseUrl == importAccount.baseUrl) { + accountFound = true + break + } + } else { + if (internalUserEntity.username == importAccount.username && (internalUserEntity + .baseUrl == "http://" + importAccount.baseUrl || + internalUserEntity.baseUrl == "https://" + importAccount + .baseUrl)) { + accountFound = true + break + } + + } + } else { + accountFound = true + break + } + } + + if (!accountFound) { + accountsAvailable.add(account) + } + } + + return accountsAvailable + } + + fun getAppNameBasedOnPackage(packageName: String): String { + val context = NextcloudTalkApplication.sharedApplication!!.applicationContext + val packageManager = context.packageManager + var appName = "" + try { + appName = packageManager.getApplicationLabel(packageManager.getApplicationInfo(packageName, + PackageManager.GET_META_DATA)) as String + } catch (e: PackageManager.NameNotFoundException) { + Log.e(TAG, "Failed to get app name based on package") + } + + return appName + } + + fun canWeOpenFilesApp(context: Context, accountName: String): Boolean { + val pm = context.packageManager + try { + val packageInfo = pm.getPackageInfo(context.getString(R.string.nc_import_accounts_from), 0) + if (packageInfo.versionCode >= 30060151) { + val ownSignatures = pm.getPackageInfo(context.packageName, PackageManager.GET_SIGNATURES).signatures + val filesAppSignatures = pm.getPackageInfo(context.getString(R.string.nc_import_accounts_from), PackageManager.GET_SIGNATURES).signatures + + if (Arrays.equals(ownSignatures, filesAppSignatures)) { + val accMgr = AccountManager.get(context) + val accounts = accMgr.getAccountsByType(context.getString(R.string.nc_import_account_type)) + for (account in accounts) { + if (account.name == accountName) { + return true + } + } + } else { + return true + } + } + } catch (appNotFoundException: PackageManager.NameNotFoundException) { + + } + + return false + } + + fun getInformationFromAccount(account: Account): ImportAccount { + val lastAtPos = account.name.lastIndexOf("@") + var urlString = account.name.substring(lastAtPos + 1) + val username = account.name.substring(0, lastAtPos) + + val context = NextcloudTalkApplication.sharedApplication!!.applicationContext + val accMgr = AccountManager.get(context) + + var password: String? = null + try { + password = accMgr.getPassword(account) + } catch (exception: Exception) { + Log.e(TAG, "Failed to import account") + } + + if (urlString.endsWith("/")) { + urlString = urlString.substring(0, urlString.length - 1) + } + + return ImportAccount(username, password, urlString) + } +} + diff --git a/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java b/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java index ddc548457..1d9d3a814 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java +++ b/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java @@ -42,6 +42,10 @@ public class ApiUtils { return userAgent + BuildConfig.VERSION_NAME; } + public static String getUrlForLobbyForConversation(String baseUrl, String token) { + return getRoom(baseUrl, token) + "/webinary/lobby"; + } + public static RetrofitBucket getRetrofitBucketForContactsSearch(String baseUrl, @Nullable String searchQuery) { RetrofitBucket retrofitBucket = new RetrofitBucket(); retrofitBucket.setUrl(baseUrl + ocsApiVersion + "/apps/files_sharing/api/v1/sharees"); @@ -215,7 +219,7 @@ public class ApiUtils { public static String getUrlForAvatarWithName(String baseUrl, String name, @DimenRes int avatarSize) { avatarSize = Math.round(NextcloudTalkApplication - .getSharedApplication().getResources().getDimension(avatarSize)); + .Companion.getSharedApplication().getResources().getDimension(avatarSize)); return baseUrl + "/index.php/avatar/" + Uri.encode(name) + "/" + avatarSize; } @@ -236,7 +240,7 @@ public class ApiUtils { } public static String getUrlPushProxy() { - return NextcloudTalkApplication.getSharedApplication(). + return NextcloudTalkApplication.Companion.getSharedApplication(). getApplicationContext().getResources().getString(R.string.nc_push_server_url) + "/devices"; } diff --git a/app/src/main/java/com/nextcloud/talk/utils/BottomNavigationUtils.java b/app/src/main/java/com/nextcloud/talk/utils/BottomNavigationUtils.java deleted file mode 100644 index a02230a71..000000000 --- a/app/src/main/java/com/nextcloud/talk/utils/BottomNavigationUtils.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Nextcloud Talk application - * - * @author Mario Danic - * Copyright (C) 2017 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 . - * - * The bottom navigation was taken from a PR to Conductor by Chris6647@gmail.com - * https://github.com/bluelinelabs/Conductor/pull/316 and https://github.com/chris6647/Conductor/pull/1/files - * and of course modified by yours truly. - */ - -package com.nextcloud.talk.utils; - -public class BottomNavigationUtils { - - /** - * Copy/paste from {@link java.util.Objects#equals(Object, Object)} to support lower API version - * - * @param a - * @param b - * @return - */ - public static boolean equals(Object a, Object b) { - return (a == b) || (a != null && a.equals(b)); - } -} diff --git a/app/src/main/java/com/nextcloud/talk/utils/ConductorRemapping.java b/app/src/main/java/com/nextcloud/talk/utils/ConductorRemapping.java deleted file mode 100644 index 91c64f66b..000000000 --- a/app/src/main/java/com/nextcloud/talk/utils/ConductorRemapping.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Nextcloud Talk application - * - * @author Mario Danic - * Copyright (C) 2017-2019 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; - -import android.os.Bundle; -import com.bluelinelabs.conductor.Router; -import com.bluelinelabs.conductor.RouterTransaction; -import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler; -import com.nextcloud.talk.controllers.ChatController; - -import java.util.List; - -public class ConductorRemapping { - public static void remapChatController(Router router, long internalUserId, String roomTokenOrId, Bundle bundle, boolean replaceTop) { - String tag = internalUserId + "@" + roomTokenOrId; - if (router.getControllerWithTag(tag) != null) { - List backstack = router.getBackstack(); - RouterTransaction routerTransaction = null; - for (int i = 0; i < router.getBackstackSize(); i++) { - if (tag.equals(backstack.get(i).tag())) { - routerTransaction = backstack.get(i); - backstack.remove(routerTransaction); - break; - } - } - - backstack.add(routerTransaction); - router.setBackstack(backstack, new HorizontalChangeHandler()); - } else { - if (!replaceTop) { - router.pushController(RouterTransaction.with(new ChatController(bundle)) - .pushChangeHandler(new HorizontalChangeHandler()) - .popChangeHandler(new HorizontalChangeHandler()).tag(tag)); - } else { - router.replaceTopController(RouterTransaction.with(new ChatController(bundle)) - .pushChangeHandler(new HorizontalChangeHandler()) - .popChangeHandler(new HorizontalChangeHandler()).tag(tag)); - } - } - } -} diff --git a/app/src/main/java/com/nextcloud/talk/utils/ConductorRemapping.kt b/app/src/main/java/com/nextcloud/talk/utils/ConductorRemapping.kt new file mode 100644 index 000000000..e2845a0b7 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/utils/ConductorRemapping.kt @@ -0,0 +1,57 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017-2019 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 + +import android.os.Bundle +import com.bluelinelabs.conductor.Router +import com.bluelinelabs.conductor.RouterTransaction +import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler +import com.nextcloud.talk.controllers.ChatController + +object ConductorRemapping { + fun remapChatController(router: Router, internalUserId: Long, roomTokenOrId: String, bundle: Bundle, replaceTop: Boolean) { + val tag = "$internalUserId@$roomTokenOrId" + if (router.getControllerWithTag(tag) != null) { + val backstack = router.backstack + var routerTransaction: RouterTransaction? = null + for (i in 0 until router.backstackSize) { + if (tag == backstack[i].tag()) { + routerTransaction = backstack[i] + backstack.remove(routerTransaction) + break + } + } + + backstack.add(routerTransaction) + router.setBackstack(backstack, HorizontalChangeHandler()) + } else { + if (!replaceTop) { + router.pushController(RouterTransaction.with(ChatController(bundle)) + .pushChangeHandler(HorizontalChangeHandler()) + .popChangeHandler(HorizontalChangeHandler()).tag(tag)) + } else { + router.replaceTopController(RouterTransaction.with(ChatController(bundle)) + .pushChangeHandler(HorizontalChangeHandler()) + .popChangeHandler(HorizontalChangeHandler()).tag(tag)) + } + } + } +} diff --git a/app/src/main/java/com/nextcloud/talk/utils/DateUtils.java b/app/src/main/java/com/nextcloud/talk/utils/DateUtils.kt similarity index 55% rename from app/src/main/java/com/nextcloud/talk/utils/DateUtils.java rename to app/src/main/java/com/nextcloud/talk/utils/DateUtils.kt index 76f3fd92f..cb2e66979 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/DateUtils.java +++ b/app/src/main/java/com/nextcloud/talk/utils/DateUtils.kt @@ -18,26 +18,26 @@ * along with this program. If not, see . */ -package com.nextcloud.talk.utils; +package com.nextcloud.talk.utils -import android.content.Context; +import java.text.DateFormat +import java.util.* -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; -import java.util.Locale; -import java.util.TimeZone; -public class DateUtils { - public static String getLocalDateTimeStringFromTimestamp(Context context, long timestamp) { - Calendar cal = Calendar.getInstance(); - TimeZone tz = cal.getTimeZone(); +object DateUtils { + fun getLocalDateTimeStringFromTimestamp(timestamp: Long): String { + val cal = Calendar.getInstance() + val tz = cal.timeZone /* date formatter in local timezone */ - Locale currentLocale = context.getResources().getConfiguration().locale; - SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss", currentLocale); - sdf.setTimeZone(tz); + val format = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.MEDIUM, Locale + .getDefault()) + format.timeZone = tz - return sdf.format(new Date(timestamp)); + return format.format(Date(timestamp)) + } + + fun getLocalDateStringFromTimestampForLobby(timestamp: Long): String { + return getLocalDateTimeStringFromTimestamp(timestamp * 1000); } } diff --git a/app/src/main/java/com/nextcloud/talk/utils/DeviceUtils.java b/app/src/main/java/com/nextcloud/talk/utils/DeviceUtils.java index 8d56bd091..e53149078 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/DeviceUtils.java +++ b/app/src/main/java/com/nextcloud/talk/utils/DeviceUtils.java @@ -42,7 +42,7 @@ public class DeviceUtils { Method setApplicationAutoStartMethod = appOpsUtilsClass.getMethod("setApplicationAutoStart", Context .class, String.class, Boolean.TYPE); if (setApplicationAutoStartMethod != null) { - Context applicationContext = NextcloudTalkApplication.getSharedApplication().getApplicationContext(); + Context applicationContext = NextcloudTalkApplication.Companion.getSharedApplication().getApplicationContext(); setApplicationAutoStartMethod.invoke(appOpsUtilsClass, applicationContext, applicationContext .getPackageName(), Boolean.TRUE); } @@ -61,7 +61,7 @@ public class DeviceUtils { @SuppressLint("PrivateApi") Class protectAppControlClass = Class.forName("com.huawei.systemmanager.optimize.process" + ".ProtectAppControl"); if (protectAppControlClass != null) { - Context applicationContext = NextcloudTalkApplication.getSharedApplication().getApplicationContext(); + Context applicationContext = NextcloudTalkApplication.Companion.getSharedApplication().getApplicationContext(); Method getInstanceMethod = protectAppControlClass.getMethod("getInstance", Context.class); // ProtectAppControl instance diff --git a/app/src/main/java/com/nextcloud/talk/utils/DisplayUtils.java b/app/src/main/java/com/nextcloud/talk/utils/DisplayUtils.java index 46e96e8b5..410635394 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/DisplayUtils.java +++ b/app/src/main/java/com/nextcloud/talk/utils/DisplayUtils.java @@ -96,7 +96,7 @@ public class DisplayUtils { public void onClick(@Nonnull View widget) { Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); browserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - NextcloudTalkApplication.getSharedApplication().getApplicationContext().startActivity(browserIntent); + NextcloudTalkApplication.Companion.getSharedApplication().getApplicationContext().startActivity(browserIntent); } @Override @@ -344,7 +344,7 @@ public class DisplayUtils { .matcher(spannableString); - int textSize = NextcloudTalkApplication.getSharedApplication().getResources().getDimensionPixelSize(R.dimen + int textSize = NextcloudTalkApplication.Companion.getSharedApplication().getResources().getDimensionPixelSize(R.dimen .chat_text_size); int lastStartIndex = -1; @@ -364,7 +364,7 @@ public class DisplayUtils { public static Drawable getMessageSelector(@ColorInt int normalColor, @ColorInt int selectedColor, @ColorInt int pressedColor, @DrawableRes int shape) { - Drawable vectorDrawable = ContextCompat.getDrawable(NextcloudTalkApplication.getSharedApplication() + Drawable vectorDrawable = ContextCompat.getDrawable(NextcloudTalkApplication.Companion.getSharedApplication() .getApplicationContext(), shape); Drawable drawable = DrawableCompat.wrap(vectorDrawable).mutate(); diff --git a/app/src/main/java/com/nextcloud/talk/utils/DoNotDisturbUtils.java b/app/src/main/java/com/nextcloud/talk/utils/DoNotDisturbUtils.java deleted file mode 100644 index 1cd6bcae8..000000000 --- a/app/src/main/java/com/nextcloud/talk/utils/DoNotDisturbUtils.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * 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; - -import android.app.NotificationManager; -import android.content.Context; -import android.media.AudioManager; -import android.os.Build; -import android.os.Vibrator; -import com.nextcloud.talk.application.NextcloudTalkApplication; - -public class DoNotDisturbUtils { - private static final String TAG = "DoNotDisturbUtils"; - - public static boolean shouldPlaySound() { - Context context = NextcloudTalkApplication.getSharedApplication().getApplicationContext(); - - NotificationManager notificationManager = - (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); - AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); - - boolean shouldPlaySound = true; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && notificationManager != null) { - if (notificationManager.getCurrentInterruptionFilter() != NotificationManager.INTERRUPTION_FILTER_ALL) { - shouldPlaySound = false; - } - } - - if (audioManager != null && shouldPlaySound) { - if (audioManager.getRingerMode() != AudioManager.RINGER_MODE_NORMAL) { - shouldPlaySound = false; - } - } - - return shouldPlaySound; - } - - public static boolean hasVibrator() { - Context context = NextcloudTalkApplication.getSharedApplication().getApplicationContext(); - Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); - return (vibrator != null && vibrator.hasVibrator()); - } - - public static boolean shouldVibrate(boolean vibrate) { - - if (hasVibrator()) { - Context context = NextcloudTalkApplication.getSharedApplication().getApplicationContext(); - AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); - - if (audioManager != null) { - if (vibrate) { - return (audioManager.getRingerMode() != AudioManager.RINGER_MODE_SILENT); - } else { - return (audioManager.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE); - } - } - } - - return false; - } -} diff --git a/app/src/main/java/com/nextcloud/talk/utils/DoNotDisturbUtils.kt b/app/src/main/java/com/nextcloud/talk/utils/DoNotDisturbUtils.kt new file mode 100644 index 000000000..e7140d06b --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/utils/DoNotDisturbUtils.kt @@ -0,0 +1,74 @@ +/* + * 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 + +import android.app.NotificationManager +import android.content.Context +import android.media.AudioManager +import android.os.Build +import android.os.Vibrator +import com.nextcloud.talk.application.NextcloudTalkApplication + +object DoNotDisturbUtils { + fun shouldPlaySound(): Boolean { + val context = NextcloudTalkApplication.sharedApplication?.applicationContext + + val notificationManager = context?.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager + val audioManager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager + + var shouldPlaySound = true + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + if (notificationManager.currentInterruptionFilter != NotificationManager.INTERRUPTION_FILTER_ALL) { + shouldPlaySound = false + } + } + + if (shouldPlaySound) { + if (audioManager.ringerMode != AudioManager.RINGER_MODE_NORMAL) { + shouldPlaySound = false + } + } + + return shouldPlaySound + } + + fun hasVibrator(): Boolean { + val context = NextcloudTalkApplication.sharedApplication?.applicationContext + val vibrator = context?.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator + return vibrator.hasVibrator() + } + + fun shouldVibrate(vibrate: Boolean): Boolean { + + if (hasVibrator()) { + val context = NextcloudTalkApplication.sharedApplication?.applicationContext + val audioManager = context?.getSystemService(Context.AUDIO_SERVICE) as AudioManager + + return if (vibrate) { + audioManager.ringerMode != AudioManager.RINGER_MODE_SILENT + } else { + audioManager.ringerMode == AudioManager.RINGER_MODE_VIBRATE + } + } + + return false + } +} diff --git a/app/src/main/java/com/nextcloud/talk/utils/DrawableUtils.java b/app/src/main/java/com/nextcloud/talk/utils/DrawableUtils.java deleted file mode 100644 index 368e5914e..000000000 --- a/app/src/main/java/com/nextcloud/talk/utils/DrawableUtils.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * 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; - -import com.nextcloud.talk.R; - -import java.util.HashMap; -import java.util.Map; - -public class DrawableUtils { - - - public static int getDrawableResourceIdForMimeType(String mimetype) { - Map drawableMap = new HashMap<>(); - - // Initial list of mimetypes was acquired from https://github.com/nextcloud/server/blob/694ba5435b2963e201f6a6d2c775836bde07aaef/core/js/mimetypelist.js - drawableMap.put("application/coreldraw", R.drawable.ic_mimetype_image); - drawableMap.put("application/epub+zip", R.drawable.ic_mimetype_text); - drawableMap.put("application/font-sfnt", R.drawable.ic_mimetype_image); - drawableMap.put("application/font-woff", R.drawable.ic_mimetype_image); - drawableMap.put("application/gpx+xml", R.drawable.ic_mimetype_location); - drawableMap.put("application/illustrator", R.drawable.ic_mimetype_image); - drawableMap.put("application/javascript", R.drawable.ic_mimetype_text_code); - drawableMap.put("application/json", R.drawable.ic_mimetype_text_code); - drawableMap.put("application/msaccess", R.drawable.ic_mimetype_file); - drawableMap.put("application/msexcel", R.drawable.ic_mimetype_x_office_spreadsheet); - drawableMap.put("application/msonenote", R.drawable.ic_mimetype_x_office_document); - drawableMap.put("application/mspowerpoint", R.drawable.ic_mimetype_x_office_presentation); - drawableMap.put("application/msword", R.drawable.ic_mimetype_x_office_document); - drawableMap.put("application/octet-stream", R.drawable.ic_mimetype_file); - drawableMap.put("application/postscript", R.drawable.ic_mimetype_image); - drawableMap.put("application/rss+xml", R.drawable.ic_mimetype_text_code); - drawableMap.put("application/vnd.android.package-archive", R.drawable.ic_mimetype_package_x_generic); - drawableMap.put("application/vnd.lotus-wordpro", R.drawable.ic_mimetype_x_office_document); - drawableMap.put("application/vnd.garmin.tcx+xml", R.drawable.ic_mimetype_location); - drawableMap.put("application/vnd.google-earth.kml+xml", R.drawable.ic_mimetype_location); - drawableMap.put("application/vnd.google-earth.kmz", R.drawable.ic_mimetype_location); - drawableMap.put("application/vnd.ms-excel", R.drawable.ic_mimetype_x_office_spreadsheet); - drawableMap.put("application/vnd.ms-excel.addin.macroEnabled.12", R.drawable.ic_mimetype_x_office_spreadsheet); - drawableMap.put("application/vnd.ms-excel.sheet.binary.macroEnabled.12", R.drawable.ic_mimetype_x_office_spreadsheet); - drawableMap.put("application/vnd.ms-excel.sheet.macroEnabled.12", R.drawable.ic_mimetype_x_office_spreadsheet); - drawableMap.put("application/vnd.ms-excel.template.macroEnabled.12", R.drawable.ic_mimetype_x_office_spreadsheet); - drawableMap.put("application/vnd.ms-fontobject", R.drawable.ic_mimetype_image); - drawableMap.put("application/vnd.ms-powerpoint", R.drawable.ic_mimetype_x_office_presentation); - drawableMap.put("application/vnd.ms-powerpoint.addin.macroEnabled.12", R.drawable.ic_mimetype_x_office_presentation); - drawableMap.put("application/vnd.ms-powerpoint.presentation.macroEnabled.12", R.drawable.ic_mimetype_x_office_presentation); - drawableMap.put("application/vnd.ms-powerpoint.slideshow.macroEnabled.12", R.drawable.ic_mimetype_x_office_presentation); - drawableMap.put("application/vnd.ms-powerpoint.template.macroEnabled.12", R.drawable.ic_mimetype_x_office_presentation); - drawableMap.put("application/vnd.ms-visio.drawing.macroEnabled.12", R.drawable.ic_mimetype_x_office_document); - drawableMap.put("application/vnd.ms-visio.drawing", R.drawable.ic_mimetype_x_office_document); - drawableMap.put("application/vnd.ms-visio.stencil.macroEnabled.12", R.drawable.ic_mimetype_x_office_document); - drawableMap.put("application/vnd.ms-visio.stencil", R.drawable.ic_mimetype_x_office_document); - drawableMap.put("application/vnd.ms-visio.template.macroEnabled.12", R.drawable.ic_mimetype_x_office_document); - drawableMap.put("application/vnd.ms-visio.template", R.drawable.ic_mimetype_x_office_document); - drawableMap.put("application/vnd.ms-word.template.macroEnabled.12", R.drawable.ic_mimetype_x_office_document); - drawableMap.put("application/vnd.oasis.opendocument.presentation", R.drawable.ic_mimetype_x_office_presentation); - drawableMap.put("application/vnd.oasis.opendocument.presentation-template", R.drawable.ic_mimetype_x_office_presentation); - drawableMap.put("application/vnd.oasis.opendocument.spreadsheet", R.drawable.ic_mimetype_x_office_spreadsheet); - drawableMap.put("application/vnd.oasis.opendocument.spreadsheet-template", R.drawable.ic_mimetype_x_office_spreadsheet); - drawableMap.put("application/vnd.oasis.opendocument.text", R.drawable.ic_mimetype_x_office_document); - drawableMap.put("application/vnd.oasis.opendocument.text-master", R.drawable.ic_mimetype_x_office_document); - drawableMap.put("application/vnd.oasis.opendocument.text-template", R.drawable.ic_mimetype_x_office_document); - drawableMap.put("application/vnd.oasis.opendocument.text-web", R.drawable.ic_mimetype_x_office_document); - drawableMap.put("application/vnd.openxmlformats-officedocument.presentationml.presentation", R.drawable.ic_mimetype_x_office_presentation); - drawableMap.put("application/vnd.openxmlformats-officedocument.presentationml.slideshow", R.drawable.ic_mimetype_x_office_presentation); - drawableMap.put("application/vnd.openxmlformats-officedocument.presentationml.template", R.drawable.ic_mimetype_x_office_presentation); - drawableMap.put("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", R.drawable.ic_mimetype_x_office_spreadsheet); - drawableMap.put("application/vnd.openxmlformats-officedocument.spreadsheetml.template", R.drawable.ic_mimetype_x_office_spreadsheet); - drawableMap.put("application/vnd.openxmlformats-officedocument.wordprocessingml.document", R.drawable.ic_mimetype_x_office_document); - drawableMap.put("application/vnd.openxmlformats-officedocument.wordprocessingml.template", R.drawable.ic_mimetype_x_office_document); - drawableMap.put("application/vnd.visio", R.drawable.ic_mimetype_x_office_document); - drawableMap.put("application/vnd.wordperfect", R.drawable.ic_mimetype_x_office_document); - drawableMap.put("application/x-7z-compressed", R.drawable.ic_mimetype_package_x_generic); - drawableMap.put("application/x-bzip2", R.drawable.ic_mimetype_package_x_generic); - drawableMap.put("application/x-cbr", R.drawable.ic_mimetype_text); - drawableMap.put("application/x-compressed", R.drawable.ic_mimetype_package_x_generic); - drawableMap.put("application/x-dcraw", R.drawable.ic_mimetype_image); - drawableMap.put("application/x-deb", R.drawable.ic_mimetype_package_x_generic); - drawableMap.put("application/x-fictionbook+xml", R.drawable.ic_mimetype_text); - drawableMap.put("application/x-font", R.drawable.ic_mimetype_image); - drawableMap.put("application/x-gimp", R.drawable.ic_mimetype_image); - drawableMap.put("application/x-gzip", R.drawable.ic_mimetype_package_x_generic); - drawableMap.put("application/x-iwork-keynote-sffkey", R.drawable.ic_mimetype_x_office_presentation); - drawableMap.put("application/x-iwork-numbers-sffnumbers", R.drawable.ic_mimetype_x_office_spreadsheet); - drawableMap.put("application/x-iwork-pages-sffpages", R.drawable.ic_mimetype_x_office_document); - drawableMap.put("application/x-mobipocket-ebook", R.drawable.ic_mimetype_text); - drawableMap.put("application/x-perl", R.drawable.ic_mimetype_text_code); - drawableMap.put("application/x-photoshop", R.drawable.ic_mimetype_image); - drawableMap.put("application/x-php", R.drawable.ic_mimetype_text_code); - drawableMap.put("application/x-rar-compressed", R.drawable.ic_mimetype_package_x_generic); - drawableMap.put("application/x-tar", R.drawable.ic_mimetype_package_x_generic); - drawableMap.put("application/x-tex", R.drawable.ic_mimetype_text); - drawableMap.put("application/xml", R.drawable.ic_mimetype_text_code); - drawableMap.put("application/yaml", R.drawable.ic_mimetype_text_code); - drawableMap.put("application/zip", R.drawable.ic_mimetype_package_x_generic); - drawableMap.put("database", R.drawable.ic_mimetype_file); - drawableMap.put("httpd/unix-directory", R.drawable.ic_mimetype_folder); - drawableMap.put("text/css", R.drawable.ic_mimetype_text_code); - drawableMap.put("text/csv", R.drawable.ic_mimetype_x_office_spreadsheet); - drawableMap.put("text/html", R.drawable.ic_mimetype_text_code); - drawableMap.put("text/x-c", R.drawable.ic_mimetype_text_code); - drawableMap.put("text/x-c++src", R.drawable.ic_mimetype_text_code); - drawableMap.put("text/x-h", R.drawable.ic_mimetype_text_code); - drawableMap.put("text/x-java-source", R.drawable.ic_mimetype_text_code); - drawableMap.put("text/x-ldif", R.drawable.ic_mimetype_text_code); - drawableMap.put("text/x-python", R.drawable.ic_mimetype_text_code); - drawableMap.put("text/x-shellscript", R.drawable.ic_mimetype_text_code); - drawableMap.put("web", R.drawable.ic_mimetype_text_code); - drawableMap.put("application/internet-shortcut", R.drawable.ic_mimetype_link); - - drawableMap.put("inode/directory", R.drawable.ic_mimetype_folder); - drawableMap.put("unknown", R.drawable.ic_mimetype_file); - drawableMap.put("application/pdf", R.drawable.ic_mimetype_application_pdf); - - if ("DIR".equals(mimetype)) { - mimetype = "inode/directory"; - return drawableMap.get(mimetype); - } - - if (drawableMap.containsKey(mimetype)) { - return drawableMap.get(mimetype); - } - - if (mimetype.startsWith("image/")) { - return R.drawable.ic_mimetype_image; - } - - if (mimetype.startsWith("video/")) { - return R.drawable.ic_mimetype_video; - } - - if (mimetype.startsWith("text/")) { - return R.drawable.ic_mimetype_text; - } - - if (mimetype.startsWith("audio")) { - return R.drawable.ic_mimetype_audio; - } - - return drawableMap.get("unknown"); - } - -} diff --git a/app/src/main/java/com/nextcloud/talk/utils/DrawableUtils.kt b/app/src/main/java/com/nextcloud/talk/utils/DrawableUtils.kt new file mode 100644 index 000000000..14afd4298 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/utils/DrawableUtils.kt @@ -0,0 +1,158 @@ +/* + * 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 + +import com.nextcloud.talk.R + +import java.util.HashMap + +object DrawableUtils { + + + fun getDrawableResourceIdForMimeType(mimetype: String): Int { + var localMimetype = mimetype + val drawableMap = HashMap() + + // Initial list of mimetypes was acquired from https://github.com/nextcloud/server/blob/694ba5435b2963e201f6a6d2c775836bde07aaef/core/js/mimetypelist.js + drawableMap["application/coreldraw"] = R.drawable.ic_mimetype_image + drawableMap["application/epub+zip"] = R.drawable.ic_mimetype_text + drawableMap["application/font-sfnt"] = R.drawable.ic_mimetype_image + drawableMap["application/font-woff"] = R.drawable.ic_mimetype_image + drawableMap["application/gpx+xml"] = R.drawable.ic_mimetype_location + drawableMap["application/illustrator"] = R.drawable.ic_mimetype_image + drawableMap["application/javascript"] = R.drawable.ic_mimetype_text_code + drawableMap["application/json"] = R.drawable.ic_mimetype_text_code + drawableMap["application/msaccess"] = R.drawable.ic_mimetype_file + drawableMap["application/msexcel"] = R.drawable.ic_mimetype_x_office_spreadsheet + drawableMap["application/msonenote"] = R.drawable.ic_mimetype_x_office_document + drawableMap["application/mspowerpoint"] = R.drawable.ic_mimetype_x_office_presentation + drawableMap["application/msword"] = R.drawable.ic_mimetype_x_office_document + drawableMap["application/octet-stream"] = R.drawable.ic_mimetype_file + drawableMap["application/postscript"] = R.drawable.ic_mimetype_image + drawableMap["application/rss+xml"] = R.drawable.ic_mimetype_text_code + drawableMap["application/vnd.android.package-archive"] = R.drawable.ic_mimetype_package_x_generic + drawableMap["application/vnd.lotus-wordpro"] = R.drawable.ic_mimetype_x_office_document + drawableMap["application/vnd.garmin.tcx+xml"] = R.drawable.ic_mimetype_location + drawableMap["application/vnd.google-earth.kml+xml"] = R.drawable.ic_mimetype_location + drawableMap["application/vnd.google-earth.kmz"] = R.drawable.ic_mimetype_location + drawableMap["application/vnd.ms-excel"] = R.drawable.ic_mimetype_x_office_spreadsheet + drawableMap["application/vnd.ms-excel.addin.macroEnabled.12"] = R.drawable.ic_mimetype_x_office_spreadsheet + drawableMap["application/vnd.ms-excel.sheet.binary.macroEnabled.12"] = R.drawable.ic_mimetype_x_office_spreadsheet + drawableMap["application/vnd.ms-excel.sheet.macroEnabled.12"] = R.drawable.ic_mimetype_x_office_spreadsheet + drawableMap["application/vnd.ms-excel.template.macroEnabled.12"] = R.drawable.ic_mimetype_x_office_spreadsheet + drawableMap["application/vnd.ms-fontobject"] = R.drawable.ic_mimetype_image + drawableMap["application/vnd.ms-powerpoint"] = R.drawable.ic_mimetype_x_office_presentation + drawableMap["application/vnd.ms-powerpoint.addin.macroEnabled.12"] = R.drawable.ic_mimetype_x_office_presentation + drawableMap["application/vnd.ms-powerpoint.presentation.macroEnabled.12"] = R.drawable.ic_mimetype_x_office_presentation + drawableMap["application/vnd.ms-powerpoint.slideshow.macroEnabled.12"] = R.drawable.ic_mimetype_x_office_presentation + drawableMap["application/vnd.ms-powerpoint.template.macroEnabled.12"] = R.drawable.ic_mimetype_x_office_presentation + drawableMap["application/vnd.ms-visio.drawing.macroEnabled.12"] = R.drawable.ic_mimetype_x_office_document + drawableMap["application/vnd.ms-visio.drawing"] = R.drawable.ic_mimetype_x_office_document + drawableMap["application/vnd.ms-visio.stencil.macroEnabled.12"] = R.drawable.ic_mimetype_x_office_document + drawableMap["application/vnd.ms-visio.stencil"] = R.drawable.ic_mimetype_x_office_document + drawableMap["application/vnd.ms-visio.template.macroEnabled.12"] = R.drawable.ic_mimetype_x_office_document + drawableMap["application/vnd.ms-visio.template"] = R.drawable.ic_mimetype_x_office_document + drawableMap["application/vnd.ms-word.template.macroEnabled.12"] = R.drawable.ic_mimetype_x_office_document + drawableMap["application/vnd.oasis.opendocument.presentation"] = R.drawable.ic_mimetype_x_office_presentation + drawableMap["application/vnd.oasis.opendocument.presentation-template"] = R.drawable.ic_mimetype_x_office_presentation + drawableMap["application/vnd.oasis.opendocument.spreadsheet"] = R.drawable.ic_mimetype_x_office_spreadsheet + drawableMap["application/vnd.oasis.opendocument.spreadsheet-template"] = R.drawable.ic_mimetype_x_office_spreadsheet + drawableMap["application/vnd.oasis.opendocument.text"] = R.drawable.ic_mimetype_x_office_document + drawableMap["application/vnd.oasis.opendocument.text-master"] = R.drawable.ic_mimetype_x_office_document + drawableMap["application/vnd.oasis.opendocument.text-template"] = R.drawable.ic_mimetype_x_office_document + drawableMap["application/vnd.oasis.opendocument.text-web"] = R.drawable.ic_mimetype_x_office_document + drawableMap["application/vnd.openxmlformats-officedocument.presentationml.presentation"] = R.drawable.ic_mimetype_x_office_presentation + drawableMap["application/vnd.openxmlformats-officedocument.presentationml.slideshow"] = R.drawable.ic_mimetype_x_office_presentation + drawableMap["application/vnd.openxmlformats-officedocument.presentationml.template"] = R.drawable.ic_mimetype_x_office_presentation + drawableMap["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"] = R.drawable.ic_mimetype_x_office_spreadsheet + drawableMap["application/vnd.openxmlformats-officedocument.spreadsheetml.template"] = R.drawable.ic_mimetype_x_office_spreadsheet + drawableMap["application/vnd.openxmlformats-officedocument.wordprocessingml.document"] = R.drawable.ic_mimetype_x_office_document + drawableMap["application/vnd.openxmlformats-officedocument.wordprocessingml.template"] = R.drawable.ic_mimetype_x_office_document + drawableMap["application/vnd.visio"] = R.drawable.ic_mimetype_x_office_document + drawableMap["application/vnd.wordperfect"] = R.drawable.ic_mimetype_x_office_document + drawableMap["application/x-7z-compressed"] = R.drawable.ic_mimetype_package_x_generic + drawableMap["application/x-bzip2"] = R.drawable.ic_mimetype_package_x_generic + drawableMap["application/x-cbr"] = R.drawable.ic_mimetype_text + drawableMap["application/x-compressed"] = R.drawable.ic_mimetype_package_x_generic + drawableMap["application/x-dcraw"] = R.drawable.ic_mimetype_image + drawableMap["application/x-deb"] = R.drawable.ic_mimetype_package_x_generic + drawableMap["application/x-fictionbook+xml"] = R.drawable.ic_mimetype_text + drawableMap["application/x-font"] = R.drawable.ic_mimetype_image + drawableMap["application/x-gimp"] = R.drawable.ic_mimetype_image + drawableMap["application/x-gzip"] = R.drawable.ic_mimetype_package_x_generic + drawableMap["application/x-iwork-keynote-sffkey"] = R.drawable.ic_mimetype_x_office_presentation + drawableMap["application/x-iwork-numbers-sffnumbers"] = R.drawable.ic_mimetype_x_office_spreadsheet + drawableMap["application/x-iwork-pages-sffpages"] = R.drawable.ic_mimetype_x_office_document + drawableMap["application/x-mobipocket-ebook"] = R.drawable.ic_mimetype_text + drawableMap["application/x-perl"] = R.drawable.ic_mimetype_text_code + drawableMap["application/x-photoshop"] = R.drawable.ic_mimetype_image + drawableMap["application/x-php"] = R.drawable.ic_mimetype_text_code + drawableMap["application/x-rar-compressed"] = R.drawable.ic_mimetype_package_x_generic + drawableMap["application/x-tar"] = R.drawable.ic_mimetype_package_x_generic + drawableMap["application/x-tex"] = R.drawable.ic_mimetype_text + drawableMap["application/xml"] = R.drawable.ic_mimetype_text_code + drawableMap["application/yaml"] = R.drawable.ic_mimetype_text_code + drawableMap["application/zip"] = R.drawable.ic_mimetype_package_x_generic + drawableMap["database"] = R.drawable.ic_mimetype_file + drawableMap["httpd/unix-directory"] = R.drawable.ic_mimetype_folder + drawableMap["text/css"] = R.drawable.ic_mimetype_text_code + drawableMap["text/csv"] = R.drawable.ic_mimetype_x_office_spreadsheet + drawableMap["text/html"] = R.drawable.ic_mimetype_text_code + drawableMap["text/x-c"] = R.drawable.ic_mimetype_text_code + drawableMap["text/x-c++src"] = R.drawable.ic_mimetype_text_code + drawableMap["text/x-h"] = R.drawable.ic_mimetype_text_code + drawableMap["text/x-java-source"] = R.drawable.ic_mimetype_text_code + drawableMap["text/x-ldif"] = R.drawable.ic_mimetype_text_code + drawableMap["text/x-python"] = R.drawable.ic_mimetype_text_code + drawableMap["text/x-shellscript"] = R.drawable.ic_mimetype_text_code + drawableMap["web"] = R.drawable.ic_mimetype_text_code + drawableMap["application/internet-shortcut"] = R.drawable.ic_mimetype_link + + drawableMap["inode/directory"] = R.drawable.ic_mimetype_folder + drawableMap["unknown"] = R.drawable.ic_mimetype_file + drawableMap["application/pdf"] = R.drawable.ic_mimetype_application_pdf + + if ("DIR" == localMimetype) { + localMimetype = "inode/directory" + return drawableMap[localMimetype]!! + } + + if (drawableMap.containsKey(localMimetype)) { + return drawableMap[localMimetype]!! + } + + if (localMimetype.startsWith("image/")) { + return R.drawable.ic_mimetype_image + } + + if (localMimetype.startsWith("video/")) { + return R.drawable.ic_mimetype_video + } + + if (localMimetype.startsWith("text/")) { + return R.drawable.ic_mimetype_text + } + + return if (localMimetype.startsWith("audio")) { + R.drawable.ic_mimetype_audio + } else drawableMap["unknown"]!! + } +} diff --git a/app/src/main/java/com/nextcloud/talk/utils/LoggingUtils.java b/app/src/main/java/com/nextcloud/talk/utils/LoggingUtils.java deleted file mode 100644 index 19490710e..000000000 --- a/app/src/main/java/com/nextcloud/talk/utils/LoggingUtils.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Nextcloud Talk application - * - * @author Mario Danic - * Copyright (C) 2017-2019 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; - -import android.content.Context; -import android.content.Intent; -import android.net.Uri; -import android.os.Build; -import androidx.core.content.FileProvider; -import com.nextcloud.talk.BuildConfig; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; - -public class LoggingUtils { - public static void writeLogEntryToFile(Context context, String logEntry) { - DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); - Date date = new Date(); - String logEntryWithDateTime = dateFormat.format(date) + ": " + logEntry + "\n"; - - try { - FileOutputStream outputStream = context.openFileOutput("nc_log.txt", - Context.MODE_PRIVATE | Context.MODE_APPEND); - outputStream.write(logEntryWithDateTime.getBytes()); - outputStream.flush(); - outputStream.close(); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - public static void sendMailWithAttachment(Context context) { - File logFile = context.getFileStreamPath("nc_log.txt"); - Intent emailIntent = new Intent(Intent.ACTION_SEND); - String mailto = "mario@nextcloud.com"; - emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{mailto}); - emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Talk logs"); - emailIntent.setType("text/plain"); - emailIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); - Uri uri; - - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { - uri = Uri.fromFile(logFile); - } else { - uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID, logFile); - } - - emailIntent.putExtra(Intent.EXTRA_STREAM, uri); - emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - context.startActivity(emailIntent); - } -} diff --git a/app/src/main/java/com/nextcloud/talk/utils/LoggingUtils.kt b/app/src/main/java/com/nextcloud/talk/utils/LoggingUtils.kt new file mode 100644 index 000000000..051eac362 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/utils/LoggingUtils.kt @@ -0,0 +1,78 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017-2019 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 + +import android.content.Context +import android.content.Intent +import android.net.Uri +import android.os.Build +import androidx.core.content.FileProvider +import com.nextcloud.talk.BuildConfig + +import java.io.File +import java.io.FileNotFoundException +import java.io.FileOutputStream +import java.io.IOException +import java.text.DateFormat +import java.text.SimpleDateFormat +import java.util.Date + +object LoggingUtils { + fun writeLogEntryToFile(context: Context, logEntry: String) { + val dateFormat = SimpleDateFormat("yyyy/MM/dd HH:mm:ss") + val date = Date() + val logEntryWithDateTime = dateFormat.format(date) + ": " + logEntry + "\n" + + try { + val outputStream = context.openFileOutput("nc_log.txt", + Context.MODE_PRIVATE or Context.MODE_APPEND) + outputStream.write(logEntryWithDateTime.toByteArray()) + outputStream.flush() + outputStream.close() + } catch (e: FileNotFoundException) { + e.printStackTrace() + } catch (e: IOException) { + e.printStackTrace() + } + + } + + fun sendMailWithAttachment(context: Context) { + val logFile = context.getFileStreamPath("nc_log.txt") + val emailIntent = Intent(Intent.ACTION_SEND) + val mailto = "mario@nextcloud.com" + emailIntent.putExtra(Intent.EXTRA_EMAIL, arrayOf(mailto)) + emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Talk logs") + emailIntent.type = "text/plain" + emailIntent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION + val uri: Uri + + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { + uri = Uri.fromFile(logFile) + } else { + uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID, logFile) + } + + emailIntent.putExtra(Intent.EXTRA_STREAM, uri) + emailIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK + context.startActivity(emailIntent) + } +} diff --git a/app/src/main/java/com/nextcloud/talk/utils/MagicMap.java b/app/src/main/java/com/nextcloud/talk/utils/MagicMap.kt similarity index 72% rename from app/src/main/java/com/nextcloud/talk/utils/MagicMap.java rename to app/src/main/java/com/nextcloud/talk/utils/MagicMap.kt index 0ae3d82c6..b0ae58039 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/MagicMap.java +++ b/app/src/main/java/com/nextcloud/talk/utils/MagicMap.kt @@ -18,14 +18,14 @@ * along with this program. If not, see . */ -package com.nextcloud.talk.utils; +package com.nextcloud.talk.utils -import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentHashMap -public class MagicMap extends ConcurrentHashMap { - public int add(Object element) { - int key = System.identityHashCode(element); - super.put(key, element); - return key; +class MagicMap : ConcurrentHashMap() { + fun add(element: Any): Int { + val key = System.identityHashCode(element) + super.put(key, element) + return key } } diff --git a/app/src/main/java/com/nextcloud/talk/utils/NotificationUtils.java b/app/src/main/java/com/nextcloud/talk/utils/NotificationUtils.java index d6baa6ca2..9f679fd3d 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/NotificationUtils.java +++ b/app/src/main/java/com/nextcloud/talk/utils/NotificationUtils.java @@ -96,7 +96,7 @@ public class NotificationUtils { notification = statusBarNotification.getNotification(); if (notification != null && !notification.extras.isEmpty()) { - if (conversationUser.getId() == notification.extras.getLong(BundleKeys.KEY_INTERNAL_USER_ID)) { + if (conversationUser.getId() == notification.extras.getLong(BundleKeys.INSTANCE.getKEY_INTERNAL_USER_ID())) { notificationManager.cancel(statusBarNotification.getId()); } } @@ -120,8 +120,8 @@ public class NotificationUtils { notification = statusBarNotification.getNotification(); if (notification != null && !notification.extras.isEmpty()) { - if (conversationUser.getId() == notification.extras.getLong(BundleKeys.KEY_INTERNAL_USER_ID) && - notificationId == notification.extras.getLong(BundleKeys.KEY_NOTIFICATION_ID)) { + if (conversationUser.getId() == notification.extras.getLong(BundleKeys.INSTANCE.getKEY_INTERNAL_USER_ID()) && + notificationId == notification.extras.getLong(BundleKeys.INSTANCE.getKEY_NOTIFICATION_ID())) { notificationManager.cancel(statusBarNotification.getId()); } } @@ -146,8 +146,8 @@ public class NotificationUtils { notification = statusBarNotification.getNotification(); if (notification != null && !notification.extras.isEmpty()) { - if (conversationUser.getId() == notification.extras.getLong(BundleKeys.KEY_INTERNAL_USER_ID) && - roomTokenOrId.equals(statusBarNotification.getNotification().extras.getString(BundleKeys.KEY_ROOM_TOKEN))) { + if (conversationUser.getId() == notification.extras.getLong(BundleKeys.INSTANCE.getKEY_INTERNAL_USER_ID()) && + roomTokenOrId.equals(statusBarNotification.getNotification().extras.getString(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN()))) { return statusBarNotification; } } @@ -173,8 +173,8 @@ public class NotificationUtils { notification = statusBarNotification.getNotification(); if (notification != null && !notification.extras.isEmpty()) { - if (conversationUser.getId() == notification.extras.getLong(BundleKeys.KEY_INTERNAL_USER_ID) && - roomTokenOrId.equals(statusBarNotification.getNotification().extras.getString(BundleKeys.KEY_ROOM_TOKEN))) { + if (conversationUser.getId() == notification.extras.getLong(BundleKeys.INSTANCE.getKEY_INTERNAL_USER_ID()) && + roomTokenOrId.equals(statusBarNotification.getNotification().extras.getString(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN()))) { notificationManager.cancel(statusBarNotification.getId()); } } diff --git a/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java b/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java index 17736077a..65a72f8d9 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java +++ b/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java @@ -74,15 +74,15 @@ public class PushUtils { private String proxyServer; public PushUtils() { - NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); + NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); - keysFile = NextcloudTalkApplication.getSharedApplication().getDir("PushKeyStore", Context.MODE_PRIVATE); + keysFile = NextcloudTalkApplication.Companion.getSharedApplication().getDir("PushKeyStore", Context.MODE_PRIVATE); - publicKeyFile = new File(NextcloudTalkApplication.getSharedApplication().getDir("PushKeystore", + publicKeyFile = new File(NextcloudTalkApplication.Companion.getSharedApplication().getDir("PushKeystore", Context.MODE_PRIVATE), "push_key.pub"); - privateKeyFile = new File(NextcloudTalkApplication.getSharedApplication().getDir("PushKeystore", + privateKeyFile = new File(NextcloudTalkApplication.Companion.getSharedApplication().getDir("PushKeystore", Context.MODE_PRIVATE), "push_key.priv"); - proxyServer = NextcloudTalkApplication.getSharedApplication().getResources(). + proxyServer = NextcloudTalkApplication.Companion.getSharedApplication().getResources(). getString(R.string.nc_push_server_url); } diff --git a/app/src/main/java/com/nextcloud/talk/utils/SecurityUtils.java b/app/src/main/java/com/nextcloud/talk/utils/SecurityUtils.java index 6af7e7967..2542086d6 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/SecurityUtils.java +++ b/app/src/main/java/com/nextcloud/talk/utils/SecurityUtils.java @@ -112,7 +112,7 @@ public class SecurityUtils { } private static int getIntegerFromStringTimeout(String validity) { - Resources resources = NextcloudTalkApplication.getSharedApplication().getResources(); + Resources resources = NextcloudTalkApplication.Companion.getSharedApplication().getResources(); List entryValues = Arrays.asList(resources.getStringArray(R.array.screen_lock_timeout_entry_values)); int[] entryIntValues = resources.getIntArray(R.array.screen_lock_timeout_entry_int_values); int indexOfValidity = entryValues.indexOf(validity); diff --git a/app/src/main/java/com/nextcloud/talk/utils/ShareUtils.java b/app/src/main/java/com/nextcloud/talk/utils/ShareUtils.java index 1eabb54fe..815f26cd3 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/ShareUtils.java +++ b/app/src/main/java/com/nextcloud/talk/utils/ShareUtils.java @@ -33,7 +33,7 @@ import androidx.annotation.Nullable; import com.kennyc.bottomsheet.adapters.AppAdapter; import com.nextcloud.talk.R; import com.nextcloud.talk.models.database.UserEntity; -import com.nextcloud.talk.models.json.rooms.Conversation; +import com.nextcloud.talk.models.json.conversations.Conversation; import com.nextcloud.talk.utils.database.user.UserUtils; import java.util.ArrayList; diff --git a/app/src/main/java/com/nextcloud/talk/utils/bundle/BundleBuilder.java b/app/src/main/java/com/nextcloud/talk/utils/bundle/BundleBuilder.java deleted file mode 100644 index d0f8edce6..000000000 --- a/app/src/main/java/com/nextcloud/talk/utils/bundle/BundleBuilder.java +++ /dev/null @@ -1,191 +0,0 @@ -/* - * Nextcloud Talk application - * - * @author Mario Danic - * Copyright (C) 2017 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.bundle; - -import android.os.Bundle; -import android.os.Parcelable; -import android.util.SparseArray; - -import java.io.Serializable; -import java.util.ArrayList; - -public class BundleBuilder { - - private final Bundle bundle; - - public BundleBuilder(Bundle bundle) { - this.bundle = bundle; - } - - public BundleBuilder putAll(Bundle bundle) { - this.bundle.putAll(bundle); - return this; - } - - public BundleBuilder putBoolean(String key, boolean value) { - bundle.putBoolean(key, value); - return this; - } - - public BundleBuilder putBooleanArray(String key, boolean[] value) { - bundle.putBooleanArray(key, value); - return this; - } - - public BundleBuilder putDouble(String key, double value) { - bundle.putDouble(key, value); - return this; - } - - public BundleBuilder putDoubleArray(String key, double[] value) { - bundle.putDoubleArray(key, value); - return this; - } - - public BundleBuilder putLong(String key, long value) { - bundle.putLong(key, value); - return this; - } - - public BundleBuilder putLongArray(String key, long[] value) { - bundle.putLongArray(key, value); - return this; - } - - public BundleBuilder putString(String key, String value) { - bundle.putString(key, value); - return this; - } - - public BundleBuilder putStringArray(String key, String[] value) { - bundle.putStringArray(key, value); - return this; - } - - public BundleBuilder putBundle(String key, Bundle value) { - bundle.putBundle(key, value); - return this; - } - - public BundleBuilder putByte(String key, byte value) { - bundle.putByte(key, value); - return this; - } - - public BundleBuilder putByteArray(String key, byte[] value) { - bundle.putByteArray(key, value); - return this; - } - - public BundleBuilder putChar(String key, char value) { - bundle.putChar(key, value); - return this; - } - - public BundleBuilder putCharArray(String key, char[] value) { - bundle.putCharArray(key, value); - return this; - } - - public BundleBuilder putCharSequence(String key, CharSequence value) { - bundle.putCharSequence(key, value); - return this; - } - - public BundleBuilder putCharSequenceArray(String key, CharSequence[] value) { - bundle.putCharSequenceArray(key, value); - return this; - } - - public BundleBuilder putCharSequenceArrayList(String key, ArrayList value) { - bundle.putCharSequenceArrayList(key, value); - return this; - } - - public BundleBuilder putInt(String key, int value) { - bundle.putInt(key, value); - return this; - } - - public BundleBuilder putIntArray(String key, int[] value) { - bundle.putIntArray(key, value); - return this; - } - - public BundleBuilder putFloat(String key, float value) { - bundle.putFloat(key, value); - return this; - } - - public BundleBuilder putFloatArray(String key, float[] value) { - bundle.putFloatArray(key, value); - return this; - } - - public BundleBuilder putIntegerArrayList(String key, ArrayList value) { - bundle.putIntegerArrayList(key, value); - return this; - } - - public BundleBuilder putParcelable(String key, Parcelable value) { - bundle.putParcelable(key, value); - return this; - } - - public BundleBuilder putParcelableArray(String key, Parcelable[] value) { - bundle.putParcelableArray(key, value); - return this; - } - - public BundleBuilder putParcelableArrayList(String key, ArrayList value) { - bundle.putParcelableArrayList(key, value); - return this; - } - - public BundleBuilder putSerializable(String key, Serializable value) { - bundle.putSerializable(key, value); - return this; - } - - public BundleBuilder putShort(String key, short value) { - bundle.putShort(key, value); - return this; - } - - public BundleBuilder putShortArray(String key, short[] value) { - bundle.putShortArray(key, value); - return this; - } - - public BundleBuilder putSparseParcelableArray(String key, SparseArray value) { - bundle.putSparseParcelableArray(key, value); - return this; - } - - public BundleBuilder putStringArrayList(String key, ArrayList value) { - bundle.putStringArrayList(key, value); - return this; - } - - public Bundle build() { - return bundle; - } - -} diff --git a/app/src/main/java/com/nextcloud/talk/utils/bundle/BundleKeys.java b/app/src/main/java/com/nextcloud/talk/utils/bundle/BundleKeys.java deleted file mode 100644 index faef6f195..000000000 --- a/app/src/main/java/com/nextcloud/talk/utils/bundle/BundleKeys.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Nextcloud Talk application - * - * @author Mario Danic - * Copyright (C) 2017 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.bundle; - -public class BundleKeys { - public static final String KEY_USERNAME = "KEY_USERNAME"; - public static final String KEY_TOKEN = "KEY_TOKEN"; - public static final String KEY_BASE_URL = "KEY_BASE_URL"; - public static final String KEY_IS_ACCOUNT_IMPORT = "KEY_IS_ACCOUNT_IMPORT"; - public static final String KEY_ORIGINAL_PROTOCOL = "KEY_ORIGINAL_PROTOCOL"; - public static final String KEY_ROOM = "KEY_CONVERSATION"; - public static final String KEY_OPERATION_CODE = "KEY_OPERATION_CODE"; - public static final String KEY_MENU_TYPE = "KEY_MENU_TYPE"; - public static final String KEY_SHARE_INTENT = "KEY_SHARE_INTENT"; - public static final String KEY_APP_ITEM_PACKAGE_NAME = "KEY_APP_ITEM_PACKAGE_NAME"; - public static final String KEY_APP_ITEM_NAME = "KEY_APP_ITEM_NAME"; - public static final String KEY_CONVERSATION_PASSWORD = "KEY_CONVERSATION_PASSWORD"; - public static final String KEY_ROOM_TOKEN = "KEY_ROOM_TOKEN"; - public static final String KEY_USER_ENTITY = "KEY_USER_ENTITY"; - public static final String KEY_NEW_CONVERSATION = "KEY_NEW_CONVERSATION"; - public static final String KEY_CALL_URL = "KEY_CALL_URL"; - public static final String KEY_MODIFIED_BASE_URL = "KEY_MODIFIED_BASE_URL"; - public static final String KEY_NOTIFICATION_SUBJECT = "KEY_NOTIFICATION_SUBJECT"; - public static final String KEY_NOTIFICATION_SIGNATURE = "KEY_NOTIFICATION_SIGNATURE"; - public static final String KEY_INTERNAL_USER_ID = "KEY_INTERNAL_USER_ID"; - public static final String KEY_CONVERSATION_TYPE = "KEY_CONVERSATION_TYPE"; - public static final String KEY_INVITED_PARTICIPANTS = "KEY_INVITED_PARTICIPANTS"; - public static final String KEY_INVITED_GROUP = "KEY_INVITED_GROUP"; - public static final String KEY_CONVERSATION_NAME = "KEY_CONVERSATION_NAME"; - public static final String KEY_CALL_VOICE_ONLY = "KEY_CALL_VOICE_ONLY"; - public static final String KEY_ACTIVE_CONVERSATION = "KEY_ACTIVE_CONVERSATION"; - public static final String KEY_SERVER_CAPABILITIES = "KEY_SERVER_CAPABILITIES"; - public static final String KEY_FROM_NOTIFICATION_START_CALL = "KEY_FROM_NOTIFICATION_START_CALL"; - public static final String KEY_ROOM_ID = "KEY_ROOM_ID"; - public static final String KEY_ARE_CALL_SOUNDS = "KEY_ARE_CALL_SOUNDS"; - public static final String KEY_BROWSER_TYPE = "KEY_BROWSER_TYPE"; - public static final String KEY_FILE_PATHS = "KEY_FILE_PATHS"; - public static final String KEY_ACCOUNT = "KEY_ACCOUNT"; - public static final String KEY_FILE_ID = "KEY_FILE_ID"; - public static final String KEY_NOTIFICATION_ID = "KEY_NOTIFICATION_ID"; -} diff --git a/app/src/main/java/com/nextcloud/talk/utils/bundle/BundleKeys.kt b/app/src/main/java/com/nextcloud/talk/utils/bundle/BundleKeys.kt new file mode 100644 index 000000000..85cec858b --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/utils/bundle/BundleKeys.kt @@ -0,0 +1,59 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 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.bundle + +object BundleKeys { + val KEY_USERNAME = "KEY_USERNAME" + val KEY_TOKEN = "KEY_TOKEN" + val KEY_BASE_URL = "KEY_BASE_URL" + val KEY_IS_ACCOUNT_IMPORT = "KEY_IS_ACCOUNT_IMPORT" + val KEY_ORIGINAL_PROTOCOL = "KEY_ORIGINAL_PROTOCOL" + val KEY_ROOM = "KEY_CONVERSATION" + val KEY_OPERATION_CODE = "KEY_OPERATION_CODE" + val KEY_MENU_TYPE = "KEY_MENU_TYPE" + val KEY_SHARE_INTENT = "KEY_SHARE_INTENT" + val KEY_APP_ITEM_PACKAGE_NAME = "KEY_APP_ITEM_PACKAGE_NAME" + val KEY_APP_ITEM_NAME = "KEY_APP_ITEM_NAME" + val KEY_CONVERSATION_PASSWORD = "KEY_CONVERSATION_PASSWORD" + val KEY_ROOM_TOKEN = "KEY_ROOM_TOKEN" + val KEY_USER_ENTITY = "KEY_USER_ENTITY" + val KEY_NEW_CONVERSATION = "KEY_NEW_CONVERSATION" + val KEY_CALL_URL = "KEY_CALL_URL" + val KEY_MODIFIED_BASE_URL = "KEY_MODIFIED_BASE_URL" + val KEY_NOTIFICATION_SUBJECT = "KEY_NOTIFICATION_SUBJECT" + val KEY_NOTIFICATION_SIGNATURE = "KEY_NOTIFICATION_SIGNATURE" + val KEY_INTERNAL_USER_ID = "KEY_INTERNAL_USER_ID" + val KEY_CONVERSATION_TYPE = "KEY_CONVERSATION_TYPE" + val KEY_INVITED_PARTICIPANTS = "KEY_INVITED_PARTICIPANTS" + val KEY_INVITED_GROUP = "KEY_INVITED_GROUP" + val KEY_CONVERSATION_NAME = "KEY_CONVERSATION_NAME" + val KEY_CALL_VOICE_ONLY = "KEY_CALL_VOICE_ONLY" + val KEY_ACTIVE_CONVERSATION = "KEY_ACTIVE_CONVERSATION" + val KEY_SERVER_CAPABILITIES = "KEY_SERVER_CAPABILITIES" + val KEY_FROM_NOTIFICATION_START_CALL = "KEY_FROM_NOTIFICATION_START_CALL" + val KEY_ROOM_ID = "KEY_ROOM_ID" + val KEY_ARE_CALL_SOUNDS = "KEY_ARE_CALL_SOUNDS" + val KEY_BROWSER_TYPE = "KEY_BROWSER_TYPE" + val KEY_FILE_PATHS = "KEY_FILE_PATHS" + val KEY_ACCOUNT = "KEY_ACCOUNT" + val KEY_FILE_ID = "KEY_FILE_ID" + val KEY_NOTIFICATION_ID = "KEY_NOTIFICATION_ID" +} diff --git a/app/src/main/java/com/nextcloud/talk/utils/power/PowerManagerUtils.java b/app/src/main/java/com/nextcloud/talk/utils/power/PowerManagerUtils.java index c374f3d04..b01d87884 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/power/PowerManagerUtils.java +++ b/app/src/main/java/com/nextcloud/talk/utils/power/PowerManagerUtils.java @@ -51,7 +51,7 @@ public class PowerManagerUtils { private int orientation; public PowerManagerUtils() { - NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); + NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); fullLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "nctalk:fullwakelock"); diff --git a/app/src/main/java/com/nextcloud/talk/utils/preferences/MagicUserInputModule.java b/app/src/main/java/com/nextcloud/talk/utils/preferences/MagicUserInputModule.java index 292c9ab02..d33dd52c5 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/preferences/MagicUserInputModule.java +++ b/app/src/main/java/com/nextcloud/talk/utils/preferences/MagicUserInputModule.java @@ -48,12 +48,12 @@ public class MagicUserInputModule extends StandardUserInputModule { public MagicUserInputModule(Context context) { super(context); - NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); + NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); } public MagicUserInputModule(Context context, List keysWithIntegerInput) { super(context); - NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); + NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); this.keysWithIntegerInput = keysWithIntegerInput; } diff --git a/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.java b/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.java index 05a1f4cd6..61f127a95 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.java +++ b/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.java @@ -50,9 +50,11 @@ public class DatabaseStorageModule implements StorageModule { private String conversationToken; private long accountIdentifier; + private boolean lobbyValue; + private String messageNotificationLevel; public DatabaseStorageModule(UserEntity conversationUser, String conversationToken) { - NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); + NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); this.conversationUser = conversationUser; this.accountIdentifier = conversationUser.getId(); @@ -61,7 +63,11 @@ public class DatabaseStorageModule implements StorageModule { @Override public void saveBoolean(String key, boolean value) { - arbitraryStorageUtils.storeStorageSetting(accountIdentifier, key, Boolean.toString(value), conversationToken); + if (!key.equals("conversation_lobby")) { + arbitraryStorageUtils.storeStorageSetting(accountIdentifier, key, Boolean.toString(value), conversationToken); + } else { + lobbyValue = value; + } } @Override @@ -129,11 +135,15 @@ public class DatabaseStorageModule implements StorageModule { @Override public boolean getBoolean(String key, boolean defaultVal) { - ArbitraryStorageEntity valueFromDb = arbitraryStorageUtils.getStorageSetting(accountIdentifier, key, conversationToken); - if (valueFromDb == null) { - return defaultVal; + if (key.equals("conversation_lobby")) { + return lobbyValue; } else { - return Boolean.parseBoolean(valueFromDb.getValue()); + ArbitraryStorageEntity valueFromDb = arbitraryStorageUtils.getStorageSetting(accountIdentifier, key, conversationToken); + if (valueFromDb == null) { + return defaultVal; + } else { + return Boolean.parseBoolean(valueFromDb.getValue()); + } } } diff --git a/app/src/main/java/com/nextcloud/talk/utils/ssl/MagicKeyManager.java b/app/src/main/java/com/nextcloud/talk/utils/ssl/MagicKeyManager.java index 488338a28..ec05763ff 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/ssl/MagicKeyManager.java +++ b/app/src/main/java/com/nextcloud/talk/utils/ssl/MagicKeyManager.java @@ -51,7 +51,7 @@ public class MagicKeyManager implements X509KeyManager { this.userUtils = userUtils; this.appPreferences = appPreferences; - context = NextcloudTalkApplication.getSharedApplication().getApplicationContext(); + context = NextcloudTalkApplication.Companion.getSharedApplication().getApplicationContext(); } @Override diff --git a/app/src/main/java/com/nextcloud/talk/utils/ssl/MagicTrustManager.java b/app/src/main/java/com/nextcloud/talk/utils/ssl/MagicTrustManager.java index c24c4049c..74484d0df 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/ssl/MagicTrustManager.java +++ b/app/src/main/java/com/nextcloud/talk/utils/ssl/MagicTrustManager.java @@ -46,7 +46,7 @@ public class MagicTrustManager implements X509TrustManager { private KeyStore trustedKeyStore = null; public MagicTrustManager() { - keystoreFile = new File(NextcloudTalkApplication.getSharedApplication().getDir("CertsKeystore", + keystoreFile = new File(NextcloudTalkApplication.Companion.getSharedApplication().getDir("CertsKeystore", Context.MODE_PRIVATE), "keystore.bks"); try { diff --git a/app/src/main/java/com/nextcloud/talk/webrtc/MagicPeerConnectionWrapper.java b/app/src/main/java/com/nextcloud/talk/webrtc/MagicPeerConnectionWrapper.java index f8421980a..a63e92695 100644 --- a/app/src/main/java/com/nextcloud/talk/webrtc/MagicPeerConnectionWrapper.java +++ b/app/src/main/java/com/nextcloud/talk/webrtc/MagicPeerConnectionWrapper.java @@ -81,7 +81,7 @@ public class MagicPeerConnectionWrapper { String sessionId, String localSession, @Nullable MediaStream mediaStream, boolean isMCUPublisher, boolean hasMCU, String videoStreamType) { - NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); + NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); this.localMediaStream = mediaStream; this.videoStreamType = videoStreamType; @@ -205,7 +205,7 @@ public class MagicPeerConnectionWrapper { if (!TextUtils.isEmpty(nick)) { return nick; } else { - return NextcloudTalkApplication.getSharedApplication().getString(R.string.nc_nick_guest); + return NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_nick_guest); } } @@ -260,7 +260,7 @@ public class MagicPeerConnectionWrapper { data.get(bytes); String strData = new String(bytes); Log.d(TAG, "Got msg: " + strData + " over " + TAG + " " + sessionId); - LoggingUtils.writeLogEntryToFile(context, + LoggingUtils.INSTANCE.writeLogEntryToFile(context, "Got msg: " + strData + " over " + peerConnection.hashCode() + " " + sessionId); try { @@ -336,7 +336,7 @@ public class MagicPeerConnectionWrapper { @Override public void onIceConnectionChange(PeerConnection.IceConnectionState iceConnectionState) { peerIceConnectionState = iceConnectionState; - LoggingUtils.writeLogEntryToFile(context, + LoggingUtils.INSTANCE.writeLogEntryToFile(context, "iceConnectionChangeTo: " + iceConnectionState.name() + " over " + peerConnection.hashCode() + " " + sessionId); Log.d("iceConnectionChangeTo: ", iceConnectionState.name() + " over " + peerConnection.hashCode() + " " + sessionId); @@ -428,7 +428,7 @@ public class MagicPeerConnectionWrapper { @Override public void onCreateFailure(String s) { Log.d(TAG, s); - LoggingUtils.writeLogEntryToFile(context, + LoggingUtils.INSTANCE.writeLogEntryToFile(context, "SDPObserver createFailure: " + s + " over " + peerConnection.hashCode() + " " + sessionId); } @@ -436,7 +436,7 @@ public class MagicPeerConnectionWrapper { @Override public void onSetFailure(String s) { Log.d(TAG, s); - LoggingUtils.writeLogEntryToFile(context, + LoggingUtils.INSTANCE.writeLogEntryToFile(context, "SDPObserver setFailure: " + s + " over " + peerConnection.hashCode() + " " + sessionId); } diff --git a/app/src/main/java/com/nextcloud/talk/webrtc/MagicWebSocketInstance.java b/app/src/main/java/com/nextcloud/talk/webrtc/MagicWebSocketInstance.java index d8c66160d..7c2b83a15 100644 --- a/app/src/main/java/com/nextcloud/talk/webrtc/MagicWebSocketInstance.java +++ b/app/src/main/java/com/nextcloud/talk/webrtc/MagicWebSocketInstance.java @@ -84,7 +84,7 @@ public class MagicWebSocketInstance extends WebSocketListener { private List messagesQueue = new ArrayList<>(); MagicWebSocketInstance(UserEntity conversationUser, String connectionUrl, String webSocketTicket) { - NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); + NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); this.connectionUrl = connectionUrl; this.conversationUser = conversationUser; @@ -145,7 +145,7 @@ public class MagicWebSocketInstance extends WebSocketListener { public void onMessage(WebSocket webSocket, String text) { if (webSocket == internalWebSocket) { Log.d(TAG, "Receiving : " + webSocket.toString() + " " + text); - LoggingUtils.writeLogEntryToFile(context, + LoggingUtils.INSTANCE.writeLogEntryToFile(context, "WebSocket " + webSocket.hashCode() + " receiving: " + text); try { @@ -182,7 +182,7 @@ public class MagicWebSocketInstance extends WebSocketListener { case "error": ErrorOverallWebSocketMessage errorOverallWebSocketMessage = LoganSquare.parse(text, ErrorOverallWebSocketMessage.class); if (("no_such_session").equals(errorOverallWebSocketMessage.getErrorWebSocketMessage().getCode())) { - LoggingUtils.writeLogEntryToFile(context, + LoggingUtils.INSTANCE.writeLogEntryToFile(context, "WebSocket " + webSocket.hashCode() + " resumeID " + resumeId + " expired"); resumeId = ""; currentRoomToken = ""; @@ -218,8 +218,8 @@ public class MagicWebSocketInstance extends WebSocketListener { shouldRefreshChat = (boolean) chatMap.get("refresh"); if (shouldRefreshChat) { HashMap refreshChatHashMap = new HashMap<>(); - refreshChatHashMap.put(BundleKeys.KEY_ROOM_TOKEN, (String) messageHashMap.get("roomid")); - refreshChatHashMap.put(BundleKeys.KEY_INTERNAL_USER_ID, Long.toString(conversationUser.getId())); + refreshChatHashMap.put(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN(), (String) messageHashMap.get("roomid")); + refreshChatHashMap.put(BundleKeys.INSTANCE.getKEY_INTERNAL_USER_ID(), Long.toString(conversationUser.getId())); eventBus.post(new WebSocketCommunicationEvent("refreshChat", refreshChatHashMap)); } } @@ -271,7 +271,7 @@ public class MagicWebSocketInstance extends WebSocketListener { break; } } catch (IOException e) { - LoggingUtils.writeLogEntryToFile(context, + LoggingUtils.INSTANCE.writeLogEntryToFile(context, "WebSocket " + webSocket.hashCode() + " IOException: " + e.getMessage()); Log.e(TAG, "Failed to recognize WebSocket message"); } @@ -292,14 +292,14 @@ public class MagicWebSocketInstance extends WebSocketListener { @Override public void onClosing(WebSocket webSocket, int code, String reason) { Log.d(TAG, "Closing : " + code + " / " + reason); - LoggingUtils.writeLogEntryToFile(context, + LoggingUtils.INSTANCE.writeLogEntryToFile(context, "WebSocket " + webSocket.hashCode() + " Closing: " + reason); } @Override public void onFailure(WebSocket webSocket, Throwable t, Response response) { Log.d(TAG, "Error : " + t.getMessage()); - LoggingUtils.writeLogEntryToFile(context, + LoggingUtils.INSTANCE.writeLogEntryToFile(context, "WebSocket " + webSocket.hashCode() + " onFailure: " + t.getMessage()); closeWebSocket(webSocket); } @@ -338,7 +338,7 @@ public class MagicWebSocketInstance extends WebSocketListener { internalWebSocket.send(message); } } catch (IOException e) { - LoggingUtils.writeLogEntryToFile(context, + LoggingUtils.INSTANCE.writeLogEntryToFile(context, "WebSocket sendCalLMessage: " + e.getMessage() + "\n" + ncMessageWrapper.toString()); Log.e(TAG, "Failed to serialize signaling message"); } @@ -359,7 +359,7 @@ public class MagicWebSocketInstance extends WebSocketListener { internalWebSocket.send(message); } } catch (IOException e) { - LoggingUtils.writeLogEntryToFile(context, + LoggingUtils.INSTANCE.writeLogEntryToFile(context, "WebSocket requestOfferForSessionIdWithType: " + e.getMessage() + "\n" + sessionIdParam + " " + roomType); Log.e(TAG, "Failed to offer request"); } @@ -387,7 +387,7 @@ public class MagicWebSocketInstance extends WebSocketListener { return usersHashMap.get(session).getDisplayName(); } - return NextcloudTalkApplication.getSharedApplication().getString(R.string.nc_nick_guest); + return NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_nick_guest); } public String getSessionForUserId(String userId) { diff --git a/app/src/main/java/com/nextcloud/talk/webrtc/WebSocketConnectionHelper.java b/app/src/main/java/com/nextcloud/talk/webrtc/WebSocketConnectionHelper.java index b8a049e1c..40f8d0ee7 100644 --- a/app/src/main/java/com/nextcloud/talk/webrtc/WebSocketConnectionHelper.java +++ b/app/src/main/java/com/nextcloud/talk/webrtc/WebSocketConnectionHelper.java @@ -41,7 +41,7 @@ public class WebSocketConnectionHelper { public WebSocketConnectionHelper() { - NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); + NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); } public static synchronized MagicWebSocketInstance getMagicWebSocketInstanceForUserId(long userId) { diff --git a/app/src/main/res/drawable/ic_mimetype_application.xml b/app/src/main/res/drawable/ic_mimetype_application.xml index c00d93fc9..8b339a3f3 100755 --- a/app/src/main/res/drawable/ic_mimetype_application.xml +++ b/app/src/main/res/drawable/ic_mimetype_application.xml @@ -1,4 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ~ + ~ 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 . + --> + + + + diff --git a/app/src/main/res/drawable/ic_timer_black_24dp.xml b/app/src/main/res/drawable/ic_timer_black_24dp.xml new file mode 100644 index 000000000..afe6738e6 --- /dev/null +++ b/app/src/main/res/drawable/ic_timer_black_24dp.xml @@ -0,0 +1,25 @@ + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 56f47a903..fb873faff 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -25,6 +25,12 @@ android:layout_height="match_parent" tools:context=".activities.MainActivity"> + + @@ -36,14 +42,8 @@ android:theme="@style/ThemeOverlay.MaterialComponents.Dark.ActionBar" app:contentInsetStart="24dp" app:contentInsetStartWithNavigation="0dp" - app:titleMarginStart="0dp" - app:popupTheme="@style/appActionBarPopupMenu" /> + app:popupTheme="@style/appActionBarPopupMenu" + app:titleMarginStart="0dp" /> - - diff --git a/app/src/main/res/layout/call_item.xml b/app/src/main/res/layout/call_item.xml index 443001d88..2ab2db2d2 100644 --- a/app/src/main/res/layout/call_item.xml +++ b/app/src/main/res/layout/call_item.xml @@ -26,30 +26,6 @@ android:layout_weight="1" android:orientation="vertical"> - - - - - - + + + + + + diff --git a/app/src/main/res/layout/call_states.xml b/app/src/main/res/layout/call_states.xml index 6e46a77fd..91851db9a 100644 --- a/app/src/main/res/layout/call_states.xml +++ b/app/src/main/res/layout/call_states.xml @@ -24,6 +24,15 @@ android:layout_height="match_parent" android:background="@color/grey950"> + + - - - - + + - - + + + + + + + - - - - - - - - - + app:placeholderImage="@drawable/ic_mic_off_white_24px" + app:roundAsCircle="true" /> + android:alpha="0.7" + app:backgroundImage="@color/colorPrimary" + app:placeholderImage="@drawable/ic_videocam_white_24px" + app:roundAsCircle="true" /> + android:visibility="gone" + app:backgroundImage="@color/colorPrimary" + app:placeholderImage="@drawable/ic_volume_mute_white_24dp" + app:roundAsCircle="true" /> + + + + diff --git a/app/src/main/res/layout/controller_call_notification.xml b/app/src/main/res/layout/controller_call_notification.xml index 72c427197..ee7c6dc8f 100644 --- a/app/src/main/res/layout/controller_call_notification.xml +++ b/app/src/main/res/layout/controller_call_notification.xml @@ -31,6 +31,44 @@ android:src="@color/grey950" tools:srcCompat="@tools:sample/backgrounds/scenic" /> + + + + + + + + + - - - - - - - - - diff --git a/app/src/main/res/layout/controller_chat.xml b/app/src/main/res/layout/controller_chat.xml index 4c6a317cd..fd9fb353a 100644 --- a/app/src/main/res/layout/controller_chat.xml +++ b/app/src/main/res/layout/controller_chat.xml @@ -21,7 +21,11 @@ + android:layout_height="match_parent" + android:keepScreenOn="true"> + + + + + + - - - - diff --git a/app/src/main/res/layout/controller_conversation_info.xml b/app/src/main/res/layout/controller_conversation_info.xml index c5bb311a9..b7ab29542 100644 --- a/app/src/main/res/layout/controller_conversation_info.xml +++ b/app/src/main/res/layout/controller_conversation_info.xml @@ -58,13 +58,6 @@ android:layout_width="match_parent" android:layout_height="wrap_content"> - - + + @@ -85,7 +85,7 @@ android:visibility="gone"> - - + + + + diff --git a/app/src/main/res/layout/controller_conversations_rv.xml b/app/src/main/res/layout/controller_conversations_rv.xml index 63989ce3e..869ce232e 100644 --- a/app/src/main/res/layout/controller_conversations_rv.xml +++ b/app/src/main/res/layout/controller_conversations_rv.xml @@ -84,8 +84,6 @@ - - + + diff --git a/app/src/main/res/layout/controller_entry_menu.xml b/app/src/main/res/layout/controller_entry_menu.xml index ca9da07b8..6e6a3ddd5 100644 --- a/app/src/main/res/layout/controller_entry_menu.xml +++ b/app/src/main/res/layout/controller_entry_menu.xml @@ -24,15 +24,31 @@ android:layout_height="wrap_content" android:background="@color/bg_bottom_sheet"> + + + app:passwordToggleTint="@color/grey_600"> - - diff --git a/app/src/main/res/layout/controller_locked.xml b/app/src/main/res/layout/controller_locked.xml index 5df9f7ea1..933709361 100644 --- a/app/src/main/res/layout/controller_locked.xml +++ b/app/src/main/res/layout/controller_locked.xml @@ -40,13 +40,13 @@ android:src="@drawable/ic_lock_white_24px" /> diff --git a/app/src/main/res/layout/controller_operations_menu.xml b/app/src/main/res/layout/controller_operations_menu.xml index 4d516d8c5..f825fdacb 100644 --- a/app/src/main/res/layout/controller_operations_menu.xml +++ b/app/src/main/res/layout/controller_operations_menu.xml @@ -23,18 +23,6 @@ android:layout_height="wrap_content" android:background="@color/nc_white_color"> - - + + - - - - - - + + + + + + diff --git a/app/src/main/res/layout/controller_settings.xml b/app/src/main/res/layout/controller_settings.xml index f406ef09c..5e7399961 100644 --- a/app/src/main/res/layout/controller_settings.xml +++ b/app/src/main/res/layout/controller_settings.xml @@ -46,14 +46,6 @@ android:layout_width="match_parent" android:layout_height="wrap_content"> - - + + + apc:mp_title="@string/nc_settings_theme_title" /> @@ -173,6 +172,17 @@ apc:mpc_title="@string/nc_settings_privacy" apc:mpc_title_color="@color/colorPrimary"> + + - - - - - - + + + + - + + + + + + + + + + + - - - - - - - - - - - + \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_standard_vertical.xml b/app/src/main/res/layout/dialog_standard_vertical.xml index 4fb8c4edf..01700ffd7 100644 --- a/app/src/main/res/layout/dialog_standard_vertical.xml +++ b/app/src/main/res/layout/dialog_standard_vertical.xml @@ -27,8 +27,6 @@ android:layout_height="match_parent" android:orientation="vertical"> - - - - + android:layout_height="12dp" /> + - + android:layout_height="wrap_content" + android:layout_gravity="end" + android:gravity="end|center_vertical" + android:paddingLeft="@dimen/ld_side_margin" + android:paddingRight="@dimen/ld_side_margin" + android:visibility="gone" /> + + \ No newline at end of file diff --git a/app/src/main/res/layout/emoji_view.xml b/app/src/main/res/layout/emoji_view.xml index 49818ee22..f1e87f047 100644 --- a/app/src/main/res/layout/emoji_view.xml +++ b/app/src/main/res/layout/emoji_view.xml @@ -22,11 +22,12 @@ android:layout_width="match_parent" android:layout_height="wrap_content"> - + android:layout_height="36dp" + android:layout_alignParentBottom="true" + android:orientation="horizontal" /> - + android:layout_height="wrap_content" + android:layout_above="@+id/emojiViewDivider" /> diff --git a/app/src/main/res/layout/item_custom_incoming_preview_message.xml b/app/src/main/res/layout/item_custom_incoming_preview_message.xml index 498eb04d2..30ccae42a 100644 --- a/app/src/main/res/layout/item_custom_incoming_preview_message.xml +++ b/app/src/main/res/layout/item_custom_incoming_preview_message.xml @@ -20,7 +20,6 @@ - - + app:actualImageScaleType="fitCenter" /> + + diff --git a/app/src/main/res/layout/item_custom_incoming_text_message.xml b/app/src/main/res/layout/item_custom_incoming_text_message.xml index 30085d294..a6072ce06 100644 --- a/app/src/main/res/layout/item_custom_incoming_text_message.xml +++ b/app/src/main/res/layout/item_custom_incoming_text_message.xml @@ -51,16 +51,16 @@ android:id="@+id/messageAuthor" android:layout_width="match_parent" android:layout_height="wrap_content" - android:textColor="@color/colorPrimary" android:layout_marginBottom="4dp" + android:textColor="@color/colorPrimary" android:textSize="12sp" /> diff --git a/app/src/main/res/layout/item_custom_outcoming_preview_message.xml b/app/src/main/res/layout/item_custom_outcoming_preview_message.xml index 4737997f6..44baedcf3 100644 --- a/app/src/main/res/layout/item_custom_outcoming_preview_message.xml +++ b/app/src/main/res/layout/item_custom_outcoming_preview_message.xml @@ -20,7 +20,6 @@ + app:actualImageScaleType="fitCenter" /> - - + + - - + + diff --git a/app/src/main/res/layout/lobby_view.xml b/app/src/main/res/layout/lobby_view.xml new file mode 100644 index 000000000..315aae698 --- /dev/null +++ b/app/src/main/res/layout/lobby_view.xml @@ -0,0 +1,47 @@ + + + + + + + + + \ 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 834d03818..b653d7873 100644 --- a/app/src/main/res/layout/notification_settings_item.xml +++ b/app/src/main/res/layout/notification_settings_item.xml @@ -43,10 +43,10 @@ apc:mp_title="@string/nc_plain_old_messages"> diff --git a/app/src/main/res/layout/rv_item_browser_file.xml b/app/src/main/res/layout/rv_item_browser_file.xml index e2053a12f..dc454c227 100644 --- a/app/src/main/res/layout/rv_item_browser_file.xml +++ b/app/src/main/res/layout/rv_item_browser_file.xml @@ -25,45 +25,33 @@ android:layout_margin="@dimen/double_margin_between_elements" android:background="@color/bg_default"> - - - + android:clickable="true" + android:focusable="true" + android:longClickable="false" + android:visibility="visible" /> + android:layout_alignEnd="@id/file_icon" + android:src="@drawable/ic_star_black_24dp" + android:tint="@color/grey_600" /> - + - + + + android:layout_marginEnd="8dp" + app:actualImageScaleType="fitCenter" + app:placeholderImageScaleType="fitCenter" /> diff --git a/app/src/main/res/layout/rv_item_contact.xml b/app/src/main/res/layout/rv_item_contact.xml index fa8a4cf22..cde98f001 100644 --- a/app/src/main/res/layout/rv_item_contact.xml +++ b/app/src/main/res/layout/rv_item_contact.xml @@ -28,6 +28,27 @@ android:layout_margin="@dimen/margin_between_elements" android:orientation="vertical"> + + + + - - - - diff --git a/app/src/main/res/layout/rv_item_conversation.xml b/app/src/main/res/layout/rv_item_conversation.xml index 44c26580a..4cf1ce7fc 100644 --- a/app/src/main/res/layout/rv_item_conversation.xml +++ b/app/src/main/res/layout/rv_item_conversation.xml @@ -34,13 +34,6 @@ android:layout_centerVertical="true" android:layout_marginEnd="@dimen/margin_between_elements"> - - + + + + - - diff --git a/app/src/main/res/layout/rv_item_conversation_info_participant.xml b/app/src/main/res/layout/rv_item_conversation_info_participant.xml index 8757d73a6..36a25574b 100644 --- a/app/src/main/res/layout/rv_item_conversation_info_participant.xml +++ b/app/src/main/res/layout/rv_item_conversation_info_participant.xml @@ -32,12 +32,6 @@ android:layout_centerVertical="true" android:layout_marginStart="@dimen/activity_horizontal_margin"> - - + + - + + + + + + + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 79fe11b6c..c419a786b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -282,4 +282,16 @@ Refresh %1$s | Last modified: %2$s + + + Webinar + Lobby + Start time + You are currently waiting in a lobby. + You are currently waiting in a lobby.\n This + meeting is scheduled for %1$s. + Manual + at + + diff --git a/app/src/test/java/com/nextcloud/talk/utils/DoNotDisturbUtilsTest.java b/app/src/test/java/com/nextcloud/talk/utils/DoNotDisturbUtilsTest.java index 9db5618f4..96398d70b 100644 --- a/app/src/test/java/com/nextcloud/talk/utils/DoNotDisturbUtilsTest.java +++ b/app/src/test/java/com/nextcloud/talk/utils/DoNotDisturbUtilsTest.java @@ -1,3 +1,23 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017-2019 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; import android.app.NotificationManager; @@ -74,7 +94,7 @@ public class DoNotDisturbUtilsTest { when(audioManager.getRingerMode()).thenReturn(AudioManager.RINGER_MODE_NORMAL); assertFalse("shouldPlaySound incorrectly returned true", - DoNotDisturbUtils.shouldPlaySound()); + DoNotDisturbUtils.INSTANCE.shouldPlaySound()); } @Test @@ -83,7 +103,7 @@ public class DoNotDisturbUtilsTest { when(audioManager.getRingerMode()).thenReturn(AudioManager.RINGER_MODE_VIBRATE); assertFalse("shouldPlaySound incorrectly returned true", - DoNotDisturbUtils.shouldPlaySound()); + DoNotDisturbUtils.INSTANCE.shouldPlaySound()); } @Test @@ -91,7 +111,7 @@ public class DoNotDisturbUtilsTest { when(vibrator.hasVibrator()).thenReturn(false); assertFalse("shouldVibrate returned true despite no vibrator", - DoNotDisturbUtils.shouldVibrate(true)); + DoNotDisturbUtils.INSTANCE.shouldVibrate(true)); } @Test @@ -101,7 +121,7 @@ public class DoNotDisturbUtilsTest { when(audioManager.getRingerMode()).thenReturn(AudioManager.RINGER_MODE_NORMAL); assertTrue("shouldVibrate incorrectly returned false", - DoNotDisturbUtils.shouldVibrate(true)); + DoNotDisturbUtils.INSTANCE.shouldVibrate(true)); } @Test @@ -111,6 +131,6 @@ public class DoNotDisturbUtilsTest { when(audioManager.getRingerMode()).thenReturn(AudioManager.RINGER_MODE_SILENT); assertFalse("shouldVibrate returned true despite ringer mode set to silent", - DoNotDisturbUtils.shouldVibrate(true)); + DoNotDisturbUtils.INSTANCE.shouldVibrate(true)); } } diff --git a/app/src/test/java/com/nextcloud/talk/utils/ShareUtilsTest.java b/app/src/test/java/com/nextcloud/talk/utils/ShareUtilsTest.java index ea3b7b4e5..ef71397db 100644 --- a/app/src/test/java/com/nextcloud/talk/utils/ShareUtilsTest.java +++ b/app/src/test/java/com/nextcloud/talk/utils/ShareUtilsTest.java @@ -1,3 +1,23 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017-2019 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; import android.content.Context; @@ -6,7 +26,7 @@ import android.text.TextUtils; import com.nextcloud.talk.R; import com.nextcloud.talk.models.database.UserEntity; -import com.nextcloud.talk.models.json.rooms.Conversation; +import com.nextcloud.talk.models.json.conversations.Conversation; import com.nextcloud.talk.utils.database.user.UserUtils; import org.junit.Before; diff --git a/app/src/test/java/com/nextcloud/talk/utils/TextMatchersTest.java b/app/src/test/java/com/nextcloud/talk/utils/TextMatchersTest.java index 38de718b2..28c8c6de8 100644 --- a/app/src/test/java/com/nextcloud/talk/utils/TextMatchersTest.java +++ b/app/src/test/java/com/nextcloud/talk/utils/TextMatchersTest.java @@ -1,3 +1,23 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017-2019 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; import com.nextcloud.talk.models.json.chat.ChatMessage; diff --git a/build.gradle b/build.gradle index 1bbbca4a3..4d2b35033 100644 --- a/build.gradle +++ b/build.gradle @@ -1,3 +1,23 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017-2019 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 . + */ + // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { diff --git a/findbugs-filter.xml b/findbugs-filter.xml index e5f385eee..585711f9f 100644 --- a/findbugs-filter.xml +++ b/findbugs-filter.xml @@ -1,6 +1,26 @@ + + diff --git a/gradle.properties b/gradle.properties index a3094e3fa..804dca367 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,23 @@ +# +# Nextcloud Talk application +# +# @author Mario Danic +# Copyright (C) 2017-2019 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 . +# + # Project-wide Gradle settings. # IDE (e.g. Android Studio) users: diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 0bd0124c3..74524f662 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,3 +1,23 @@ +# +# Nextcloud Talk application +# +# @author Mario Danic +# Copyright (C) 2017-2019 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 . +# + #Thu Aug 22 11:56:51 CEST 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists diff --git a/settings.gradle b/settings.gradle index e7b4def49..ba06f867c 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1,21 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017-2019 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 . + */ + include ':app'