Переглянути джерело

Vibrate and show info when call recording starts

...or when entering a call where recording is in progress.

+ extract vibration handling to util

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
Marcel Hibbe 2 роки тому
батько
коміт
bcf9f25596

+ 3 - 0
app/src/main/java/com/nextcloud/talk/activities/CallActivity.java

@@ -94,6 +94,7 @@ import com.nextcloud.talk.users.UserManager;
 import com.nextcloud.talk.utils.ApiUtils;
 import com.nextcloud.talk.utils.DisplayUtils;
 import com.nextcloud.talk.utils.NotificationUtils;
+import com.nextcloud.talk.utils.VibrationUtils;
 import com.nextcloud.talk.utils.animations.PulseAnimation;
 import com.nextcloud.talk.utils.database.user.CapabilitiesUtilNew;
 import com.nextcloud.talk.utils.permissions.PlatformPermissionUtil;
@@ -396,6 +397,8 @@ public class CallActivity extends CallBaseActivity {
         callRecordingViewModel.getViewState().observe(this, viewState -> {
             if (viewState instanceof CallRecordingViewModel.RecordingStartedState) {
                 binding.callRecordingIndicator.setVisibility(View.VISIBLE);
+                VibrationUtils.INSTANCE.vibrateShort(context);
+                Toast.makeText(context, context.getResources().getString(R.string.record_active_info), Toast.LENGTH_LONG).show();
             } else if (viewState instanceof CallRecordingViewModel.RecordingConfirmStopState) {
                 MaterialAlertDialogBuilder dialogBuilder = new MaterialAlertDialogBuilder(this)
                     .setTitle(R.string.record_stop_confirm_title)

+ 4 - 16
app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt

@@ -44,13 +44,10 @@ import android.media.MediaPlayer
 import android.media.MediaRecorder
 import android.net.Uri
 import android.os.Build
-import android.os.Build.VERSION_CODES.O
 import android.os.Bundle
 import android.os.Handler
 import android.os.Parcelable
 import android.os.SystemClock
-import android.os.VibrationEffect
-import android.os.Vibrator
 import android.provider.ContactsContract
 import android.provider.MediaStore
 import android.text.Editable
@@ -169,6 +166,7 @@ import com.nextcloud.talk.utils.ImageEmojiEditText
 import com.nextcloud.talk.utils.MagicCharPolicy
 import com.nextcloud.talk.utils.NotificationUtils
 import com.nextcloud.talk.utils.ParticipantPermissions
+import com.nextcloud.talk.utils.VibrationUtils
 import com.nextcloud.talk.utils.bundle.BundleKeys
 import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ACTIVE_CONVERSATION
 import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_CONVERSATION_NAME
@@ -1175,7 +1173,7 @@ class ChatController(args: Bundle) :
                 Log.e(TAG, "start for audio recording failed")
             }
 
-            vibrate()
+            VibrationUtils.vibrateShort(context)
         }
     }
 
@@ -1208,7 +1206,7 @@ class ChatController(args: Bundle) :
                     Log.w(TAG, "error while stopping recorder!")
                 }
 
-                vibrate()
+                VibrationUtils.vibrateShort(context)
             }
             recorder = null
         } else {
@@ -1216,15 +1214,6 @@ class ChatController(args: Bundle) :
         }
     }
 
-    private fun vibrate() {
-        val vibrator = context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
-        if (Build.VERSION.SDK_INT >= O) {
-            vibrator.vibrate(VibrationEffect.createOneShot(SHORT_VIBRATE, VibrationEffect.DEFAULT_AMPLITUDE))
-        } else {
-            vibrator.vibrate(SHORT_VIBRATE)
-        }
-    }
-
     private fun requestRecordAudioPermissions() {
         requestPermissions(
             arrayOf(
@@ -2771,7 +2760,7 @@ class ChatController(args: Bundle) :
     }
 
     override fun onClickReaction(chatMessage: ChatMessage, emoji: String) {
-        vibrate()
+        VibrationUtils.vibrateShort(context)
         if (chatMessage.reactionsSelf?.contains(emoji) == true) {
             reactionsRepository.deleteReaction(currentConversation!!, chatMessage, emoji)
                 .subscribeOn(Schedulers.io())
@@ -3427,7 +3416,6 @@ class ChatController(args: Bundle) :
         private const val VOICE_MESSAGE_CHANNELS = 1
         private const val FILE_DATE_PATTERN = "yyyy-MM-dd HH-mm-ss"
         private const val VIDEO_SUFFIX = ".mp4"
-        private const val SHORT_VIBRATE: Long = 20
         private const val FULLY_OPAQUE_INT: Int = 255
         private const val SEMI_TRANSPARENT_INT: Int = 99
         private const val VOICE_MESSAGE_SEEKBAR_BASE: Int = 1000

+ 38 - 0
app/src/main/java/com/nextcloud/talk/utils/VibrationUtils.kt

@@ -0,0 +1,38 @@
+/*
+ * Nextcloud Talk application
+ *
+ * @author Marcel Hibbe
+ * Copyright (C) 2023 Marcel Hibbe <dev@mhibbe.de>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package com.nextcloud.talk.utils
+
+import android.content.Context
+import android.os.Build
+import android.os.VibrationEffect
+import android.os.Vibrator
+
+object VibrationUtils {
+    private const val SHORT_VIBRATE: Long = 20
+
+    fun vibrateShort(context: Context) {
+        val vibrator = context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+            vibrator.vibrate(VibrationEffect.createOneShot(SHORT_VIBRATE, VibrationEffect.DEFAULT_AMPLITUDE))
+        } else {
+            vibrator.vibrate(SHORT_VIBRATE)
+        }
+    }
+}

+ 1 - 1
app/src/main/res/values/strings.xml

@@ -568,7 +568,7 @@
     <string name="record_stop_loading">stopping…</string>
     <string name="record_stop_confirm_title">Stop Call recording</string>
     <string name="record_stop_confirm_message">"Do you really want to stop the recording?"</string>
-    <string name="record_active_info">"This call is being recorded"</string>
+    <string name="record_active_info">"The call is being recorded"</string>
 
     <!-- Shared items -->
     <string name="shared_items_media">Media</string>