From 4cd5fb759a4b5e6529f9e6b6f2c12ea2896673e7 Mon Sep 17 00:00:00 2001 From: Harald Rudell Date: Sat, 15 Jul 2023 19:23:29 -0700 Subject: [PATCH 01/10] version 0.9.33-230715, use kotlin-parcelize instead of unsupported kotlin-android-extensions --- app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index f10c3e75..e6881720 100755 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,6 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' -apply plugin: 'kotlin-android-extensions' +apply plugin: 'kotlin-parcelize' apply plugin: 'kotlin-kapt' //apply plugin: 'com.google.firebase.crashlytics' //apply plugin: 'com.google.gms.google-services' @@ -13,7 +13,7 @@ android { minSdkVersion 21 targetSdkVersion 33 versionCode 933 - versionName "0.9.33" + versionName "0.9.33-230715" } buildFeatures { From 7606ffca3d71e1e9e000af908d5aae942c3d71cf Mon Sep 17 00:00:00 2001 From: Harald Rudell Date: Sat, 15 Jul 2023 20:08:50 -0700 Subject: [PATCH 02/10] PendingIntent.FLAG_IMMUTABLE required for Android12+ --- .../com/dimowner/audiorecorder/AppConstants.java | 12 ++++++++++++ .../com/dimowner/audiorecorder/app/DecodeService.kt | 7 +++++-- .../dimowner/audiorecorder/app/DownloadService.java | 5 ++++- .../dimowner/audiorecorder/app/PlaybackService.java | 5 ++++- .../dimowner/audiorecorder/app/RecordingService.java | 4 +++- .../app/moverecords/MoveRecordsService.kt | 5 ++++- 6 files changed, 32 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/dimowner/audiorecorder/AppConstants.java b/app/src/main/java/com/dimowner/audiorecorder/AppConstants.java index b26e41ff..7ca6ebff 100755 --- a/app/src/main/java/com/dimowner/audiorecorder/AppConstants.java +++ b/app/src/main/java/com/dimowner/audiorecorder/AppConstants.java @@ -16,12 +16,24 @@ package com.dimowner.audiorecorder; +import android.app.PendingIntent; +import android.os.Build; + /** * AppConstants that may be used in multiple classes. */ public class AppConstants { private AppConstants() {} + static { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + PENDING_INTENT_FLAGS = PendingIntent.FLAG_IMMUTABLE; + } else { + PENDING_INTENT_FLAGS = 0; + } + } + + public static final int PENDING_INTENT_FLAGS; public static final String REQUESTS_RECEIVER = "dmitriy.ponomarenko.ua@gmail.com"; diff --git a/app/src/main/java/com/dimowner/audiorecorder/app/DecodeService.kt b/app/src/main/java/com/dimowner/audiorecorder/app/DecodeService.kt index 439bfb55..80977855 100644 --- a/app/src/main/java/com/dimowner/audiorecorder/app/DecodeService.kt +++ b/app/src/main/java/com/dimowner/audiorecorder/app/DecodeService.kt @@ -16,6 +16,7 @@ package com.dimowner.audiorecorder.app +import android.annotation.SuppressLint import android.app.* import android.content.BroadcastReceiver import android.content.Context @@ -31,6 +32,7 @@ import androidx.core.app.NotificationCompat import androidx.core.app.NotificationManagerCompat import androidx.core.content.ContextCompat import com.dimowner.audiorecorder.* +import com.dimowner.audiorecorder.AppConstants.* import com.dimowner.audiorecorder.app.main.MainActivity import com.dimowner.audiorecorder.audio.AudioDecodingListener import com.dimowner.audiorecorder.audio.AudioWaveformVisualization @@ -115,7 +117,7 @@ class DecodeService : Service() { processingTasks.postRunnable { var prevTime: Long = 0 val rec = localRepository.getRecord(id) - if (rec != null && rec.duration / 1000 < AppConstants.DECODE_DURATION) { + if (rec != null && rec.duration / 1000 < DECODE_DURATION) { waveformVisualization.decodeRecordWaveform(rec.path, object : AudioDecodingListener { override fun isCanceled(): Boolean { return isCancel @@ -178,6 +180,7 @@ class DecodeService : Service() { } } + @SuppressLint("WrongConstant") private fun startNotification() { notificationManager = NotificationManagerCompat.from(this) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { @@ -201,7 +204,7 @@ class DecodeService : Service() { // Create notification default intent. val intent = Intent(applicationContext, MainActivity::class.java) intent.flags = Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP - contentPendingIntent = PendingIntent.getActivity(applicationContext, 0, intent, 0) + contentPendingIntent = PendingIntent.getActivity(applicationContext, 0, intent, PENDING_INTENT_FLAGS) startForeground(NOTIF_ID, buildNotification()) } diff --git a/app/src/main/java/com/dimowner/audiorecorder/app/DownloadService.java b/app/src/main/java/com/dimowner/audiorecorder/app/DownloadService.java index d5abf173..d88d2a49 100644 --- a/app/src/main/java/com/dimowner/audiorecorder/app/DownloadService.java +++ b/app/src/main/java/com/dimowner/audiorecorder/app/DownloadService.java @@ -16,6 +16,7 @@ package com.dimowner.audiorecorder.app; +import android.annotation.SuppressLint; import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; @@ -33,6 +34,7 @@ import android.widget.Toast; import com.dimowner.audiorecorder.ARApplication; +import com.dimowner.audiorecorder.AppConstants; import com.dimowner.audiorecorder.BackgroundQueue; import com.dimowner.audiorecorder.ColorMap; import com.dimowner.audiorecorder.R; @@ -190,6 +192,7 @@ public void onError(String message) { }); } + @SuppressLint("WrongConstant") private void startNotification() { notificationManager = NotificationManagerCompat.from(this); @@ -205,7 +208,7 @@ private void startNotification() { // Create notification default intent. Intent intent = new Intent(getApplicationContext(), MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP); - contentPendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0); + contentPendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, AppConstants.PENDING_INTENT_FLAGS); startForeground(NOTIF_ID, buildNotification()); } diff --git a/app/src/main/java/com/dimowner/audiorecorder/app/PlaybackService.java b/app/src/main/java/com/dimowner/audiorecorder/app/PlaybackService.java index 72022777..86e1c059 100644 --- a/app/src/main/java/com/dimowner/audiorecorder/app/PlaybackService.java +++ b/app/src/main/java/com/dimowner/audiorecorder/app/PlaybackService.java @@ -16,6 +16,7 @@ package com.dimowner.audiorecorder.app; +import android.annotation.SuppressLint; import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; @@ -32,6 +33,7 @@ import android.widget.RemoteViews; import com.dimowner.audiorecorder.ARApplication; +import com.dimowner.audiorecorder.AppConstants; import com.dimowner.audiorecorder.ColorMap; import com.dimowner.audiorecorder.R; import com.dimowner.audiorecorder.app.main.MainActivity; @@ -142,6 +144,7 @@ public int onStartCommand(Intent intent, int flags, int startId) { return super.onStartCommand(intent, flags, startId); } + @SuppressLint("WrongConstant") private void startForegroundService() { notificationManager = NotificationManagerCompat.from(this); @@ -164,7 +167,7 @@ private void startForegroundService() { // Create notification default intent. Intent intent = new Intent(getApplicationContext(), MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP); - contentPendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0); + contentPendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, AppConstants.PENDING_INTENT_FLAGS); startForeground(NOTIF_ID, buildNotification()); started = true; } diff --git a/app/src/main/java/com/dimowner/audiorecorder/app/RecordingService.java b/app/src/main/java/com/dimowner/audiorecorder/app/RecordingService.java index 804e9b23..a718884c 100644 --- a/app/src/main/java/com/dimowner/audiorecorder/app/RecordingService.java +++ b/app/src/main/java/com/dimowner/audiorecorder/app/RecordingService.java @@ -16,6 +16,7 @@ package com.dimowner.audiorecorder.app; +import android.annotation.SuppressLint; import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; @@ -266,11 +267,12 @@ private Notification buildNotification() { return builder.build(); } + @SuppressLint("WrongConstant") private PendingIntent createContentIntent() { // Create notification default intent. Intent intent = new Intent(getApplicationContext(), MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP); - return PendingIntent.getActivity(getApplicationContext(), 0, intent, 0); + return PendingIntent.getActivity(getApplicationContext(), 0, intent, AppConstants.PENDING_INTENT_FLAGS); } private void stopForegroundService() { diff --git a/app/src/main/java/com/dimowner/audiorecorder/app/moverecords/MoveRecordsService.kt b/app/src/main/java/com/dimowner/audiorecorder/app/moverecords/MoveRecordsService.kt index 2b011067..b8f156cd 100644 --- a/app/src/main/java/com/dimowner/audiorecorder/app/moverecords/MoveRecordsService.kt +++ b/app/src/main/java/com/dimowner/audiorecorder/app/moverecords/MoveRecordsService.kt @@ -1,5 +1,6 @@ package com.dimowner.audiorecorder.app.moverecords +import android.annotation.SuppressLint import android.app.NotificationChannel import android.app.NotificationManager import android.app.PendingIntent @@ -17,6 +18,7 @@ import androidx.annotation.RequiresApi import androidx.core.app.NotificationCompat import androidx.core.app.NotificationManagerCompat import com.dimowner.audiorecorder.ARApplication +import com.dimowner.audiorecorder.AppConstants import com.dimowner.audiorecorder.BackgroundQueue import com.dimowner.audiorecorder.ColorMap import com.dimowner.audiorecorder.R @@ -208,6 +210,7 @@ class MoveRecordsService : Service() { } } + @SuppressLint("WrongConstant") private fun startNotification() { notificationManager = NotificationManagerCompat.from(this) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { @@ -230,7 +233,7 @@ class MoveRecordsService : Service() { // Create notification default intent. val intent = Intent(applicationContext, MainActivity::class.java) intent.flags = Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP - val pendingIntent = PendingIntent.getActivity(applicationContext, 0, intent, 0) + val pendingIntent = PendingIntent.getActivity(applicationContext, 0, intent, AppConstants.PENDING_INTENT_FLAGS) // Create notification builder. builder = NotificationCompat.Builder(this, CHANNEL_ID) From 982785483975e114b030d18c0e120a8dbd9c1c52 Mon Sep 17 00:00:00 2001 From: Harald Rudell Date: Sat, 15 Jul 2023 20:22:29 -0700 Subject: [PATCH 03/10] versionName 0.9.33-230715 versionCode 934 --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index e6881720..69f0883b 100755 --- a/app/build.gradle +++ b/app/build.gradle @@ -12,7 +12,7 @@ android { applicationId "com.dimowner.audiorecorder" minSdkVersion 21 targetSdkVersion 33 - versionCode 933 + versionCode 934 versionName "0.9.33-230715" } From 3504e4f929c5bfc28b9d216a19f8717530c795bc Mon Sep 17 00:00:00 2001 From: Harald Rudell Date: Sat, 15 Jul 2023 21:38:28 -0700 Subject: [PATCH 04/10] Timber version 5.0.1 --- .../dimowner/audiorecorder/ARApplication.java | 142 ------------------ .../dimowner/audiorecorder/ARApplication.kt | 128 ++++++++++++++++ .../audiorecorder/app/DecodeService.kt | 10 +- .../app/TransparentRecordingActivity.kt | 4 +- .../app/moverecords/MoveRecordsActivity.kt | 6 +- .../app/moverecords/MoveRecordsService.kt | 12 +- 6 files changed, 144 insertions(+), 158 deletions(-) delete mode 100644 app/src/main/java/com/dimowner/audiorecorder/ARApplication.java create mode 100644 app/src/main/java/com/dimowner/audiorecorder/ARApplication.kt diff --git a/app/src/main/java/com/dimowner/audiorecorder/ARApplication.java b/app/src/main/java/com/dimowner/audiorecorder/ARApplication.java deleted file mode 100644 index 139bae9b..00000000 --- a/app/src/main/java/com/dimowner/audiorecorder/ARApplication.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright 2018 Dmytro Ponomarenko - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.dimowner.audiorecorder; - -import android.app.Application; -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; -import android.os.Handler; -import android.telephony.PhoneStateListener; -import android.telephony.TelephonyManager; - -import com.dimowner.audiorecorder.audio.player.PlayerContractNew; -import com.dimowner.audiorecorder.data.Prefs; -import com.dimowner.audiorecorder.util.AndroidUtils; -//import com.google.firebase.FirebaseApp; - -import timber.log.Timber; - -public class ARApplication extends Application { - - final static String AUDIO_BECOMING_NOISY = "android.media.AUDIO_BECOMING_NOISY"; - private AudioOutputChangeReceiver audioOutputChangeReceiver; - - private static String PACKAGE_NAME ; - public static volatile Handler applicationHandler; - - /** Screen width in dp */ - private static float screenWidthDp = 0; - - public static Injector injector; - - public static Injector getInjector() { - return injector; - } - - public static String appPackage() { - return PACKAGE_NAME; - } - - /** - * Calculate density pixels per second for record duration. - * Used for visualisation waveform in view. - * @param durationSec record duration in seconds - */ - public static float getDpPerSecond(float durationSec) { - if (durationSec > AppConstants.LONG_RECORD_THRESHOLD_SECONDS) { - return AppConstants.WAVEFORM_WIDTH * screenWidthDp / durationSec; - } else { - return AppConstants.SHORT_RECORD_DP_PER_SECOND; - } - } - - public static int getLongWaveformSampleCount() { - return (int)(AppConstants.WAVEFORM_WIDTH * screenWidthDp); - } - - @Override - public void onCreate() { - if (BuildConfig.DEBUG) { - //Timber initialization - Timber.plant(new Timber.DebugTree() { - @Override - protected String createStackElementTag(StackTraceElement element) { - return "AR-AR " + super.createStackElementTag(element) + ":" + element.getLineNumber(); - } - }); - } - super.onCreate(); - - PACKAGE_NAME = getApplicationContext().getPackageName(); - applicationHandler = new Handler(getApplicationContext().getMainLooper()); - screenWidthDp = AndroidUtils.pxToDp(AndroidUtils.getScreenWidth(getApplicationContext())); - injector = new Injector(getApplicationContext()); - Prefs prefs = injector.providePrefs(); - if (!prefs.isMigratedSettings()) { - prefs.migrateSettings(); - } - - IntentFilter intentFilter = new IntentFilter(); - intentFilter.addAction(AUDIO_BECOMING_NOISY); - audioOutputChangeReceiver = new AudioOutputChangeReceiver(); - registerReceiver(audioOutputChangeReceiver, intentFilter); - - try { - TelephonyManager mTelephonyMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); - mTelephonyMgr.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); - } catch (Exception e) { - Timber.e(e); - } -// FirebaseApp.initializeApp(this); - } - - @Override - public void onTerminate() { - super.onTerminate(); - //This method is never called on real Android devices - injector.releaseMainPresenter(); - injector.closeTasks(); - - unregisterReceiver(audioOutputChangeReceiver); - } - - private static class AudioOutputChangeReceiver extends BroadcastReceiver { - @Override - public void onReceive(Context context, Intent intent) { - String actionOfIntent = intent.getAction(); - if (actionOfIntent != null && actionOfIntent.equals(AUDIO_BECOMING_NOISY)){ - PlayerContractNew.Player player = injector.provideAudioPlayer(); - player.pause(); - } - } - } - - private PhoneStateListener mPhoneStateListener = new PhoneStateListener() { - @Override - public void onCallStateChanged(int state, String incomingNumber) { - if ((state == TelephonyManager.CALL_STATE_RINGING) - || (state == TelephonyManager.CALL_STATE_OFFHOOK)) { - //Pause playback when incoming call or on hold - PlayerContractNew.Player player = injector.provideAudioPlayer(); - player.pause(); - } - super.onCallStateChanged(state, incomingNumber); - } - }; -} diff --git a/app/src/main/java/com/dimowner/audiorecorder/ARApplication.kt b/app/src/main/java/com/dimowner/audiorecorder/ARApplication.kt new file mode 100644 index 00000000..27717018 --- /dev/null +++ b/app/src/main/java/com/dimowner/audiorecorder/ARApplication.kt @@ -0,0 +1,128 @@ +/* + * Copyright 2018 Dmytro Ponomarenko + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.dimowner.audiorecorder + +import android.app.Application +import android.content.BroadcastReceiver +import android.content.Context +import android.content.Intent +import android.content.IntentFilter +import android.os.Handler +import android.telephony.PhoneStateListener +import android.telephony.TelephonyManager +import com.dimowner.audiorecorder.util.AndroidUtils +import timber.log.Timber +import timber.log.Timber.DebugTree + +//import com.google.firebase.FirebaseApp; +class ARApplication : Application() { + private var audioOutputChangeReceiver: AudioOutputChangeReceiver? = null + override fun onCreate() { + if (BuildConfig.DEBUG) { + //Timber initialization + Timber.plant(DebugTree()) + } + super.onCreate() + PACKAGE_NAME = applicationContext.packageName + applicationHandler = Handler(applicationContext.mainLooper) + screenWidthDp = AndroidUtils.pxToDp( + AndroidUtils.getScreenWidth( + applicationContext + ) + ) + injector = Injector(applicationContext) + val prefs = injector!!.providePrefs() + if (!prefs.isMigratedSettings) { + prefs.migrateSettings() + } + val intentFilter = IntentFilter() + intentFilter.addAction(AUDIO_BECOMING_NOISY) + audioOutputChangeReceiver = AudioOutputChangeReceiver() + registerReceiver(audioOutputChangeReceiver, intentFilter) + try { + val mTelephonyMgr = getSystemService(TELEPHONY_SERVICE) as TelephonyManager + mTelephonyMgr.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE) + } catch (e: Exception) { + Timber.e(e) + } + // FirebaseApp.initializeApp(this); + } + + override fun onTerminate() { + super.onTerminate() + //This method is never called on real Android devices + injector!!.releaseMainPresenter() + injector!!.closeTasks() + unregisterReceiver(audioOutputChangeReceiver) + } + + private class AudioOutputChangeReceiver : BroadcastReceiver() { + override fun onReceive(context: Context, intent: Intent) { + val actionOfIntent = intent.action + if (actionOfIntent != null && actionOfIntent == AUDIO_BECOMING_NOISY) { + val player = injector!!.provideAudioPlayer() + player.pause() + } + } + } + + private val mPhoneStateListener: PhoneStateListener = object : PhoneStateListener() { + override fun onCallStateChanged(state: Int, incomingNumber: String) { + if (state == TelephonyManager.CALL_STATE_RINGING || state == TelephonyManager.CALL_STATE_OFFHOOK) { + //Pause playback when incoming call or on hold + val player = injector!!.provideAudioPlayer() + player.pause() + } + super.onCallStateChanged(state, incomingNumber) + } + } + + companion object { + const val AUDIO_BECOMING_NOISY = "android.media.AUDIO_BECOMING_NOISY" + private var PACKAGE_NAME: String? = null + + @JvmField + @Volatile + var applicationHandler: Handler? = null + + /** Screen width in dp */ + private var screenWidthDp = 0f + @JvmStatic + var injector: Injector? = null + @JvmStatic + fun appPackage(): String? { + return PACKAGE_NAME + } + + /** + * Calculate density pixels per second for record duration. + * Used for visualisation waveform in view. + * @param durationSec record duration in seconds + */ + @JvmStatic + fun getDpPerSecond(durationSec: Float): Float { + return if (durationSec > AppConstants.LONG_RECORD_THRESHOLD_SECONDS) { + AppConstants.WAVEFORM_WIDTH * screenWidthDp / durationSec + } else { + AppConstants.SHORT_RECORD_DP_PER_SECOND.toFloat() + } + } + + @JvmStatic + val longWaveformSampleCount: Int + get() = (AppConstants.WAVEFORM_WIDTH * screenWidthDp).toInt() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/dimowner/audiorecorder/app/DecodeService.kt b/app/src/main/java/com/dimowner/audiorecorder/app/DecodeService.kt index 80977855..8f03de6d 100644 --- a/app/src/main/java/com/dimowner/audiorecorder/app/DecodeService.kt +++ b/app/src/main/java/com/dimowner/audiorecorder/app/DecodeService.kt @@ -82,11 +82,11 @@ class DecodeService : Service() { override fun onCreate() { super.onCreate() - colorMap = ARApplication.getInjector().provideColorMap() - processingTasks = ARApplication.getInjector().provideProcessingTasksQueue() - recordingsTasks = ARApplication.getInjector().provideRecordingTasksQueue() - localRepository = ARApplication.getInjector().provideLocalRepository() - waveformVisualization = ARApplication.getInjector().provideAudioWaveformVisualization() + colorMap = ARApplication.injector.provideColorMap() + processingTasks = ARApplication.injector.provideProcessingTasksQueue() + recordingsTasks = ARApplication.injector.provideRecordingTasksQueue() + localRepository = ARApplication.injector.provideLocalRepository() + waveformVisualization = ARApplication.injector.provideAudioWaveformVisualization() } override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { diff --git a/app/src/main/java/com/dimowner/audiorecorder/app/TransparentRecordingActivity.kt b/app/src/main/java/com/dimowner/audiorecorder/app/TransparentRecordingActivity.kt index 0b5b979f..25014100 100644 --- a/app/src/main/java/com/dimowner/audiorecorder/app/TransparentRecordingActivity.kt +++ b/app/src/main/java/com/dimowner/audiorecorder/app/TransparentRecordingActivity.kt @@ -41,8 +41,8 @@ class TransparentRecordingActivity : Activity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - prefs = ARApplication.getInjector().providePrefs() - fileRepository = ARApplication.getInjector().provideFileRepository() + prefs = ARApplication.injector.providePrefs() + fileRepository = ARApplication.injector.provideFileRepository() if (checkRecordPermission2()) { if (checkStoragePermission2()) { diff --git a/app/src/main/java/com/dimowner/audiorecorder/app/moverecords/MoveRecordsActivity.kt b/app/src/main/java/com/dimowner/audiorecorder/app/moverecords/MoveRecordsActivity.kt index 3b182e3a..1ac2b7ba 100644 --- a/app/src/main/java/com/dimowner/audiorecorder/app/moverecords/MoveRecordsActivity.kt +++ b/app/src/main/java/com/dimowner/audiorecorder/app/moverecords/MoveRecordsActivity.kt @@ -86,14 +86,14 @@ class MoveRecordsActivity : Activity() { } override fun onCreate(savedInstanceState: Bundle?) { - val colorMap = ARApplication.getInjector().provideColorMap() + val colorMap = ARApplication.injector.provideColorMap() setTheme(colorMap.appThemeResource) super.onCreate(savedInstanceState) binding = ActivityMoveRecordsBinding.inflate(layoutInflater) val view = binding.root setContentView(view) - viewModel = ARApplication.getInjector().provideMoveRecordsViewModel() + viewModel = ARApplication.injector.provideMoveRecordsViewModel() binding.recyclerView.layoutManager = LinearLayoutManager(applicationContext) binding.recyclerView.adapter = adapter @@ -381,7 +381,7 @@ class MoveRecordsActivity : Activity() { } private fun clear() { - ARApplication.getInjector().releaseMoveRecordsViewModel() + ARApplication.injector.releaseMoveRecordsViewModel() scope.cancel() } diff --git a/app/src/main/java/com/dimowner/audiorecorder/app/moverecords/MoveRecordsService.kt b/app/src/main/java/com/dimowner/audiorecorder/app/moverecords/MoveRecordsService.kt index b8f156cd..5b0b6ccf 100644 --- a/app/src/main/java/com/dimowner/audiorecorder/app/moverecords/MoveRecordsService.kt +++ b/app/src/main/java/com/dimowner/audiorecorder/app/moverecords/MoveRecordsService.kt @@ -85,12 +85,12 @@ class MoveRecordsService : Service() { override fun onCreate() { super.onCreate() - colorMap = ARApplication.getInjector().provideColorMap() - prefs = ARApplication.getInjector().providePrefs() - copyTasks = ARApplication.getInjector().provideCopyTasksQueue() - loadingTasks = ARApplication.getInjector().provideLoadingTasksQueue() - fileRepository = ARApplication.getInjector().provideFileRepository() - localRepository = ARApplication.getInjector().provideLocalRepository() + colorMap = ARApplication.injector.provideColorMap() + prefs = ARApplication.injector.providePrefs() + copyTasks = ARApplication.injector.provideCopyTasksQueue() + loadingTasks = ARApplication.injector.provideLoadingTasksQueue() + fileRepository = ARApplication.injector.provideFileRepository() + localRepository = ARApplication.injector.provideLocalRepository() } override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { From e08f63e09eab79fd6b112063f3c49f26dd5ba36c Mon Sep 17 00:00:00 2001 From: Harald Rudell Date: Sun, 16 Jul 2023 00:25:38 -0700 Subject: [PATCH 05/10] No static storing of ApplicationContext --- .../dimowner/audiorecorder/ARApplication.kt | 4 +- .../com/dimowner/audiorecorder/Injector.java | 88 +++++++++---------- .../audiorecorder/app/DecodeService.kt | 13 +-- .../audiorecorder/app/DownloadService.java | 2 +- .../audiorecorder/app/PlaybackService.java | 2 +- .../audiorecorder/app/RecordingService.java | 13 +-- .../app/TransparentRecordingActivity.kt | 4 +- .../app/browser/FileBrowserActivity.java | 6 +- .../app/info/ActivityInformation.java | 4 +- .../app/lostrecords/LostRecordsActivity.java | 4 +- .../audiorecorder/app/main/MainActivity.java | 8 +- .../app/moverecords/MoveRecordsActivity.kt | 6 +- .../app/moverecords/MoveRecordsService.kt | 15 ++-- .../app/records/RecordsActivity.java | 6 +- .../app/settings/SettingsActivity.java | 4 +- .../app/setup/SetupActivity.java | 4 +- .../app/trash/TrashActivity.java | 4 +- .../app/welcome/WelcomeActivity.java | 2 +- 18 files changed, 93 insertions(+), 96 deletions(-) diff --git a/app/src/main/java/com/dimowner/audiorecorder/ARApplication.kt b/app/src/main/java/com/dimowner/audiorecorder/ARApplication.kt index 27717018..a228207e 100644 --- a/app/src/main/java/com/dimowner/audiorecorder/ARApplication.kt +++ b/app/src/main/java/com/dimowner/audiorecorder/ARApplication.kt @@ -43,8 +43,8 @@ class ARApplication : Application() { applicationContext ) ) - injector = Injector(applicationContext) - val prefs = injector!!.providePrefs() + injector = Injector() + val prefs = injector!!.providePrefs(applicationContext) if (!prefs.isMigratedSettings) { prefs.migrateSettings() } diff --git a/app/src/main/java/com/dimowner/audiorecorder/Injector.java b/app/src/main/java/com/dimowner/audiorecorder/Injector.java index b41f16f4..3f0a00f2 100644 --- a/app/src/main/java/com/dimowner/audiorecorder/Injector.java +++ b/app/src/main/java/com/dimowner/audiorecorder/Injector.java @@ -54,8 +54,6 @@ public class Injector { - private final Context context; - private BackgroundQueue loadingTasks; private BackgroundQueue recordingTasks; private BackgroundQueue importTasks; @@ -74,33 +72,29 @@ public class Injector { private AudioPlayerNew audioPlayer = null; - public Injector(Context context) { - this.context = context; - } - - public Prefs providePrefs() { + public Prefs providePrefs(Context context) { return PrefsImpl.getInstance(context); } - public RecordsDataSource provideRecordsDataSource() { + public RecordsDataSource provideRecordsDataSource(Context context) { return RecordsDataSource.getInstance(context); } - public TrashDataSource provideTrashDataSource() { + public TrashDataSource provideTrashDataSource(Context context) { return TrashDataSource.getInstance(context); } - public FileRepository provideFileRepository() { - return FileRepositoryImpl.getInstance(context, providePrefs()); + public FileRepository provideFileRepository(Context context) { + return FileRepositoryImpl.getInstance(context, providePrefs(context)); } - public LocalRepository provideLocalRepository() { - return LocalRepositoryImpl.getInstance(provideRecordsDataSource(), provideTrashDataSource(), provideFileRepository(), providePrefs()); + public LocalRepository provideLocalRepository(Context context) { + return LocalRepositoryImpl.getInstance(provideRecordsDataSource(context), provideTrashDataSource(context), provideFileRepository(context), providePrefs(context)); } - public AppRecorder provideAppRecorder() { - return AppRecorderImpl.getInstance(provideAudioRecorder(), provideLocalRepository(), - provideLoadingTasksQueue(), providePrefs()); + public AppRecorder provideAppRecorder(Context context) { + return AppRecorderImpl.getInstance(provideAudioRecorder(context), provideLocalRepository(context), + provideLoadingTasksQueue(), providePrefs(context)); } public AudioWaveformVisualization provideAudioWaveformVisualization() { @@ -142,11 +136,11 @@ public BackgroundQueue provideCopyTasksQueue() { return copyTasks; } - public ColorMap provideColorMap() { - return ColorMap.getInstance(providePrefs()); + public ColorMap provideColorMap(Context context) { + return ColorMap.getInstance(providePrefs(context)); } - public SettingsMapper provideSettingsMapper() { + public SettingsMapper provideSettingsMapper(Context context) { return SettingsMapper.getInstance(context); } @@ -161,8 +155,8 @@ public PlayerContractNew.Player provideAudioPlayer() { return audioPlayer; } - public RecorderContract.Recorder provideAudioRecorder() { - switch (providePrefs().getSettingRecordingFormat()) { + public RecorderContract.Recorder provideAudioRecorder(Context context) { + switch (providePrefs(context).getSettingRecordingFormat()) { default: case AppConstants.FORMAT_M4A: return AudioRecorder.getInstance(); @@ -173,77 +167,77 @@ public RecorderContract.Recorder provideAudioRecorder() { } } - public MainContract.UserActionsListener provideMainPresenter() { + public MainContract.UserActionsListener provideMainPresenter(Context context) { if (mainPresenter == null) { - mainPresenter = new MainPresenter(providePrefs(), provideFileRepository(), - provideLocalRepository(), provideAudioPlayer(), provideAppRecorder(), + mainPresenter = new MainPresenter(providePrefs(context), provideFileRepository(context), + provideLocalRepository(context), provideAudioPlayer(), provideAppRecorder(context), provideRecordingTasksQueue(), provideLoadingTasksQueue(), provideProcessingTasksQueue(), - provideImportTasksQueue(), provideSettingsMapper()); + provideImportTasksQueue(), provideSettingsMapper(context)); } return mainPresenter; } - public RecordsContract.UserActionsListener provideRecordsPresenter() { + public RecordsContract.UserActionsListener provideRecordsPresenter(Context context) { if (recordsPresenter == null) { - recordsPresenter = new RecordsPresenter(provideLocalRepository(), provideFileRepository(), + recordsPresenter = new RecordsPresenter(provideLocalRepository(context), provideFileRepository(context), provideLoadingTasksQueue(), provideRecordingTasksQueue(), - provideAudioPlayer(), provideAppRecorder(), providePrefs()); + provideAudioPlayer(), provideAppRecorder(context), providePrefs(context)); } return recordsPresenter; } - public SettingsContract.UserActionsListener provideSettingsPresenter() { + public SettingsContract.UserActionsListener provideSettingsPresenter(Context context) { if (settingsPresenter == null) { - settingsPresenter = new SettingsPresenter(provideLocalRepository(), provideFileRepository(), - provideRecordingTasksQueue(), provideLoadingTasksQueue(), providePrefs(), - provideSettingsMapper(), provideAppRecorder()); + settingsPresenter = new SettingsPresenter(provideLocalRepository(context), provideFileRepository(context), + provideRecordingTasksQueue(), provideLoadingTasksQueue(), providePrefs(context), + provideSettingsMapper(context), provideAppRecorder(context)); } return settingsPresenter; } - public TrashContract.UserActionsListener provideTrashPresenter() { + public TrashContract.UserActionsListener provideTrashPresenter(Context context) { if (trashPresenter == null) { trashPresenter = new TrashPresenter(provideLoadingTasksQueue(), provideRecordingTasksQueue(), - provideFileRepository(), provideLocalRepository()); + provideFileRepository(context), provideLocalRepository(context)); } return trashPresenter; } - public SetupContract.UserActionsListener provideSetupPresenter() { + public SetupContract.UserActionsListener provideSetupPresenter(Context context) { if (setupPresenter == null) { - setupPresenter = new SetupPresenter(providePrefs()); + setupPresenter = new SetupPresenter(providePrefs(context)); } return setupPresenter; } - public MoveRecordsViewModel provideMoveRecordsViewModel() { + public MoveRecordsViewModel provideMoveRecordsViewModel(Context context) { if (moveRecordsViewModel == null) { moveRecordsViewModel = new MoveRecordsViewModel( provideLoadingTasksQueue(), - provideLocalRepository(), - provideFileRepository(), - provideSettingsMapper(), + provideLocalRepository(context), + provideFileRepository(context), + provideSettingsMapper(context), provideAudioPlayer(), - provideAppRecorder(), - providePrefs() + provideAppRecorder(context), + providePrefs(context) ); } return moveRecordsViewModel; } - public LostRecordsContract.UserActionsListener provideLostRecordsPresenter() { + public LostRecordsContract.UserActionsListener provideLostRecordsPresenter(Context context) { if (lostRecordsPresenter == null) { lostRecordsPresenter = new LostRecordsPresenter(provideLoadingTasksQueue(), provideRecordingTasksQueue(), - provideLocalRepository(), providePrefs()); + provideLocalRepository(context), providePrefs(context)); } return lostRecordsPresenter; } - public FileBrowserContract.UserActionsListener provideFileBrowserPresenter() { + public FileBrowserContract.UserActionsListener provideFileBrowserPresenter(Context context) { if (fileBrowserPresenter == null) { - fileBrowserPresenter = new FileBrowserPresenter(providePrefs(), provideAppRecorder(), provideImportTasksQueue(), + fileBrowserPresenter = new FileBrowserPresenter(providePrefs(context), provideAppRecorder(context), provideImportTasksQueue(), provideLoadingTasksQueue(), provideRecordingTasksQueue(), - provideLocalRepository(), provideFileRepository()); + provideLocalRepository(context), provideFileRepository(context)); } return fileBrowserPresenter; } diff --git a/app/src/main/java/com/dimowner/audiorecorder/app/DecodeService.kt b/app/src/main/java/com/dimowner/audiorecorder/app/DecodeService.kt index 8f03de6d..f04cfc1e 100644 --- a/app/src/main/java/com/dimowner/audiorecorder/app/DecodeService.kt +++ b/app/src/main/java/com/dimowner/audiorecorder/app/DecodeService.kt @@ -82,11 +82,11 @@ class DecodeService : Service() { override fun onCreate() { super.onCreate() - colorMap = ARApplication.injector.provideColorMap() - processingTasks = ARApplication.injector.provideProcessingTasksQueue() - recordingsTasks = ARApplication.injector.provideRecordingTasksQueue() - localRepository = ARApplication.injector.provideLocalRepository() - waveformVisualization = ARApplication.injector.provideAudioWaveformVisualization() + colorMap = ARApplication.injector!!.provideColorMap(applicationContext) + processingTasks = ARApplication.injector!!.provideProcessingTasksQueue() + recordingsTasks = ARApplication.injector!!.provideRecordingTasksQueue() + localRepository = ARApplication.injector!!.provideLocalRepository(applicationContext) + waveformVisualization = ARApplication.injector!!.provideAudioWaveformVisualization() } override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { @@ -234,10 +234,11 @@ class DecodeService : Service() { stopSelf() } + @SuppressLint("WrongConstant") private fun getCancelDecodePendingIntent(context: Context): PendingIntent { val intent = Intent(context, StopDecodeReceiver::class.java) intent.action = ACTION_CANCEL_DECODE - return PendingIntent.getBroadcast(context, 15, intent, 0) + return PendingIntent.getBroadcast(context, 15, intent, AppConstants.PENDING_INTENT_FLAGS) } @RequiresApi(Build.VERSION_CODES.O) diff --git a/app/src/main/java/com/dimowner/audiorecorder/app/DownloadService.java b/app/src/main/java/com/dimowner/audiorecorder/app/DownloadService.java index d88d2a49..727368a4 100644 --- a/app/src/main/java/com/dimowner/audiorecorder/app/DownloadService.java +++ b/app/src/main/java/com/dimowner/audiorecorder/app/DownloadService.java @@ -99,7 +99,7 @@ public IBinder onBind(Intent intent) { public void onCreate() { super.onCreate(); - colorMap = ARApplication.getInjector().provideColorMap(); + colorMap = ARApplication.getInjector().provideColorMap(getApplicationContext()); copyTasks = ARApplication.getInjector().provideCopyTasksQueue(); } diff --git a/app/src/main/java/com/dimowner/audiorecorder/app/PlaybackService.java b/app/src/main/java/com/dimowner/audiorecorder/app/PlaybackService.java index 86e1c059..aeaaa01e 100644 --- a/app/src/main/java/com/dimowner/audiorecorder/app/PlaybackService.java +++ b/app/src/main/java/com/dimowner/audiorecorder/app/PlaybackService.java @@ -91,7 +91,7 @@ public void onCreate() { super.onCreate(); audioPlayer = ARApplication.getInjector().provideAudioPlayer(); - colorMap = ARApplication.getInjector().provideColorMap(); + colorMap = ARApplication.getInjector().provideColorMap(getApplicationContext()); if (playerCallback == null) { playerCallback = new PlayerContractNew.PlayerCallback() { diff --git a/app/src/main/java/com/dimowner/audiorecorder/app/RecordingService.java b/app/src/main/java/com/dimowner/audiorecorder/app/RecordingService.java index a718884c..bf29d73c 100644 --- a/app/src/main/java/com/dimowner/audiorecorder/app/RecordingService.java +++ b/app/src/main/java/com/dimowner/audiorecorder/app/RecordingService.java @@ -102,15 +102,16 @@ public IBinder onBind(Intent intent) { @Override public void onCreate() { super.onCreate(); - appRecorder = ARApplication.getInjector().provideAppRecorder(); + getApplicationContext(); + appRecorder = ARApplication.getInjector().provideAppRecorder(getApplicationContext()); audioPlayer = ARApplication.getInjector().provideAudioPlayer(); recordingsTasks = ARApplication.getInjector().provideRecordingTasksQueue(); - localRepository = ARApplication.getInjector().provideLocalRepository(); - prefs = ARApplication.getInjector().providePrefs(); - recorder = ARApplication.getInjector().provideAudioRecorder(); + localRepository = ARApplication.getInjector().provideLocalRepository(getApplicationContext()); + prefs = ARApplication.getInjector().providePrefs(getApplicationContext()); + recorder = ARApplication.getInjector().provideAudioRecorder(getApplicationContext()); - colorMap = ARApplication.getInjector().provideColorMap(); - fileRepository = ARApplication.getInjector().provideFileRepository(); + colorMap = ARApplication.getInjector().provideColorMap(getApplicationContext()); + fileRepository = ARApplication.getInjector().provideFileRepository(getApplicationContext()); appRecorderCallback = new AppRecorderCallback() { boolean checkHasSpace = true; diff --git a/app/src/main/java/com/dimowner/audiorecorder/app/TransparentRecordingActivity.kt b/app/src/main/java/com/dimowner/audiorecorder/app/TransparentRecordingActivity.kt index 25014100..dbaeee3b 100644 --- a/app/src/main/java/com/dimowner/audiorecorder/app/TransparentRecordingActivity.kt +++ b/app/src/main/java/com/dimowner/audiorecorder/app/TransparentRecordingActivity.kt @@ -41,8 +41,8 @@ class TransparentRecordingActivity : Activity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - prefs = ARApplication.injector.providePrefs() - fileRepository = ARApplication.injector.provideFileRepository() + prefs = ARApplication.injector!!.providePrefs(applicationContext) + fileRepository = ARApplication.injector!!.provideFileRepository(applicationContext) if (checkRecordPermission2()) { if (checkStoragePermission2()) { diff --git a/app/src/main/java/com/dimowner/audiorecorder/app/browser/FileBrowserActivity.java b/app/src/main/java/com/dimowner/audiorecorder/app/browser/FileBrowserActivity.java index f2e81021..ef1caec9 100644 --- a/app/src/main/java/com/dimowner/audiorecorder/app/browser/FileBrowserActivity.java +++ b/app/src/main/java/com/dimowner/audiorecorder/app/browser/FileBrowserActivity.java @@ -73,7 +73,7 @@ public static Intent getStartIntent(Context context) { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { - setTheme(ARApplication.getInjector().provideColorMap().getAppThemeResource()); + setTheme(ARApplication.getInjector().provideColorMap(getApplicationContext()).getAppThemeResource()); super.onCreate(savedInstanceState); setContentView(R.layout.activity_file_browser); @@ -97,7 +97,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { RecyclerView recyclerView = findViewById(R.id.recycler_view); recyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext())); - adapter = new FileBrowserAdapter(getApplicationContext(), ARApplication.getInjector().provideSettingsMapper()); + adapter = new FileBrowserAdapter(getApplicationContext(), ARApplication.getInjector().provideSettingsMapper(getApplicationContext())); adapter.setOnItemClickListener(new FileBrowserAdapter.OnItemClickListener() { @Override public void onItemClick(RecordInfo record) { @@ -132,7 +132,7 @@ public void onRemoveItemClick(final RecordInfo record) { } }); recyclerView.setAdapter(adapter); - presenter = ARApplication.getInjector().provideFileBrowserPresenter(); + presenter = ARApplication.getInjector().provideFileBrowserPresenter(getApplicationContext()); } @Override diff --git a/app/src/main/java/com/dimowner/audiorecorder/app/info/ActivityInformation.java b/app/src/main/java/com/dimowner/audiorecorder/app/info/ActivityInformation.java index b5f57f0e..492a8063 100644 --- a/app/src/main/java/com/dimowner/audiorecorder/app/info/ActivityInformation.java +++ b/app/src/main/java/com/dimowner/audiorecorder/app/info/ActivityInformation.java @@ -41,7 +41,7 @@ public static Intent getStartIntent(Context context, RecordInfo info) { @Override protected void onCreate(Bundle savedInstanceState) { - ColorMap colorMap = ARApplication.getInjector().provideColorMap(); + ColorMap colorMap = ARApplication.getInjector().provideColorMap(getApplicationContext()); setTheme(colorMap.getAppThemeResource()); super.onCreate(savedInstanceState); setContentView(R.layout.activity_info); @@ -65,7 +65,7 @@ protected void onCreate(Bundle savedInstanceState) { txtName.setText(info.getName()); txtFormat.setText(info.getFormat()); txtDuration.setText(TimeUtils.formatTimeIntervalHourMinSec2(info.getDuration()/1000)); - txtSize.setText(ARApplication.getInjector().provideSettingsMapper().formatSize(info.getSize())); + txtSize.setText(ARApplication.getInjector().provideSettingsMapper(getApplicationContext()).formatSize(info.getSize())); txtLocation.setText(info.getLocation()); txtCreated.setText(TimeUtils.formatDateTimeLocale(info.getCreated())); txtSampleRate.setText(getString(R.string.value_hz, info.getSampleRate())); diff --git a/app/src/main/java/com/dimowner/audiorecorder/app/lostrecords/LostRecordsActivity.java b/app/src/main/java/com/dimowner/audiorecorder/app/lostrecords/LostRecordsActivity.java index 95f512d8..a89763c9 100644 --- a/app/src/main/java/com/dimowner/audiorecorder/app/lostrecords/LostRecordsActivity.java +++ b/app/src/main/java/com/dimowner/audiorecorder/app/lostrecords/LostRecordsActivity.java @@ -60,7 +60,7 @@ public static Intent getStartIntent(Context context, ArrayList data) @Override protected void onCreate(@Nullable Bundle savedInstanceState) { - setTheme(ARApplication.getInjector().provideColorMap().getAppThemeResource()); + setTheme(ARApplication.getInjector().provideColorMap(getApplicationContext()).getAppThemeResource()); super.onCreate(savedInstanceState); setContentView(R.layout.activity_lost_records); @@ -108,7 +108,7 @@ public void onRemoveItemClick(final RecordItem record) { } } - presenter = ARApplication.getInjector().provideLostRecordsPresenter(); + presenter = ARApplication.getInjector().provideLostRecordsPresenter(getApplicationContext()); } @Override diff --git a/app/src/main/java/com/dimowner/audiorecorder/app/main/MainActivity.java b/app/src/main/java/com/dimowner/audiorecorder/app/main/MainActivity.java index 1ad0b508..65720ca2 100644 --- a/app/src/main/java/com/dimowner/audiorecorder/app/main/MainActivity.java +++ b/app/src/main/java/com/dimowner/audiorecorder/app/main/MainActivity.java @@ -155,7 +155,7 @@ public static Intent getStartIntent(Context context) { @Override protected void onCreate(Bundle savedInstanceState) { - colorMap = ARApplication.getInjector().provideColorMap(); + colorMap = ARApplication.getInjector().provideColorMap(getApplicationContext()); setTheme(colorMap.getAppThemeResource()); super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); @@ -222,8 +222,8 @@ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { } }); - presenter = ARApplication.getInjector().provideMainPresenter(); - fileRepository = ARApplication.getInjector().provideFileRepository(); + presenter = ARApplication.getInjector().provideMainPresenter(getApplicationContext()); + fileRepository = ARApplication.getInjector().provideFileRepository(getApplicationContext()); waveformView.setOnSeekListener(new WaveformViewNew.OnSeekListener() { @Override @@ -279,7 +279,7 @@ protected void onStart() { // presenter.checkPublicStorageRecords(); } presenter.checkFirstRun(); - presenter.setAudioRecorder(ARApplication.getInjector().provideAudioRecorder()); + presenter.setAudioRecorder(ARApplication.getInjector().provideAudioRecorder(getApplicationContext())); presenter.updateRecordingDir(getApplicationContext()); presenter.loadActiveRecord(); diff --git a/app/src/main/java/com/dimowner/audiorecorder/app/moverecords/MoveRecordsActivity.kt b/app/src/main/java/com/dimowner/audiorecorder/app/moverecords/MoveRecordsActivity.kt index 1ac2b7ba..523a36c0 100644 --- a/app/src/main/java/com/dimowner/audiorecorder/app/moverecords/MoveRecordsActivity.kt +++ b/app/src/main/java/com/dimowner/audiorecorder/app/moverecords/MoveRecordsActivity.kt @@ -86,14 +86,14 @@ class MoveRecordsActivity : Activity() { } override fun onCreate(savedInstanceState: Bundle?) { - val colorMap = ARApplication.injector.provideColorMap() + val colorMap = ARApplication.injector!!.provideColorMap(applicationContext) setTheme(colorMap.appThemeResource) super.onCreate(savedInstanceState) binding = ActivityMoveRecordsBinding.inflate(layoutInflater) val view = binding.root setContentView(view) - viewModel = ARApplication.injector.provideMoveRecordsViewModel() + viewModel = ARApplication.injector!!.provideMoveRecordsViewModel(applicationContext) binding.recyclerView.layoutManager = LinearLayoutManager(applicationContext) binding.recyclerView.adapter = adapter @@ -381,7 +381,7 @@ class MoveRecordsActivity : Activity() { } private fun clear() { - ARApplication.injector.releaseMoveRecordsViewModel() + ARApplication.injector!!.releaseMoveRecordsViewModel() scope.cancel() } diff --git a/app/src/main/java/com/dimowner/audiorecorder/app/moverecords/MoveRecordsService.kt b/app/src/main/java/com/dimowner/audiorecorder/app/moverecords/MoveRecordsService.kt index 5b0b6ccf..eb5ee381 100644 --- a/app/src/main/java/com/dimowner/audiorecorder/app/moverecords/MoveRecordsService.kt +++ b/app/src/main/java/com/dimowner/audiorecorder/app/moverecords/MoveRecordsService.kt @@ -85,12 +85,12 @@ class MoveRecordsService : Service() { override fun onCreate() { super.onCreate() - colorMap = ARApplication.injector.provideColorMap() - prefs = ARApplication.injector.providePrefs() - copyTasks = ARApplication.injector.provideCopyTasksQueue() - loadingTasks = ARApplication.injector.provideLoadingTasksQueue() - fileRepository = ARApplication.injector.provideFileRepository() - localRepository = ARApplication.injector.provideLocalRepository() + colorMap = ARApplication.injector!!.provideColorMap(applicationContext) + prefs = ARApplication.injector!!.providePrefs(applicationContext) + copyTasks = ARApplication.injector!!.provideCopyTasksQueue() + loadingTasks = ARApplication.injector!!.provideLoadingTasksQueue() + fileRepository = ARApplication.injector!!.provideFileRepository(applicationContext) + localRepository = ARApplication.injector!!.provideLocalRepository(applicationContext) } override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { @@ -260,10 +260,11 @@ class MoveRecordsService : Service() { stopSelf() } + @SuppressLint("WrongConstant") private fun getCancelMovePendingIntent(context: Context): PendingIntent { val intent = Intent(context, StopMoveRecordsReceiver::class.java) intent.action = ACTION_CANCEL_MOVE_RECORDS - return PendingIntent.getBroadcast(context, 318, intent, 0) + return PendingIntent.getBroadcast(context, 318, intent, AppConstants.PENDING_INTENT_FLAGS) } @RequiresApi(Build.VERSION_CODES.O) diff --git a/app/src/main/java/com/dimowner/audiorecorder/app/records/RecordsActivity.java b/app/src/main/java/com/dimowner/audiorecorder/app/records/RecordsActivity.java index b9eeb118..973ea84d 100644 --- a/app/src/main/java/com/dimowner/audiorecorder/app/records/RecordsActivity.java +++ b/app/src/main/java/com/dimowner/audiorecorder/app/records/RecordsActivity.java @@ -111,7 +111,7 @@ public static Intent getStartIntent(Context context) { @Override protected void onCreate(Bundle savedInstanceState) { - colorMap = ARApplication.getInjector().provideColorMap(); + colorMap = ARApplication.getInjector().provideColorMap(getApplicationContext()); SimpleWaveformView.setWaveformColorRes(colorMap.getPrimaryColorRes()); setTheme(colorMap.getAppThemeResource()); super.onCreate(savedInstanceState); @@ -237,7 +237,7 @@ public void onScrolled(@NonNull RecyclerView rv, int dx, int dy) { } }); - adapter = new RecordsAdapter(ARApplication.getInjector().provideSettingsMapper()); + adapter = new RecordsAdapter(ARApplication.getInjector().provideSettingsMapper(getApplicationContext())); adapter.setItemClickListener((view, id, path, position) -> presenter.setActiveRecord(id, new RecordsContract.Callback() { @Override public void onSuccess() { presenter.stopPlayback(); @@ -313,7 +313,7 @@ public void onSelectDeselect(int selectedCount) { }); recyclerView.setAdapter(adapter); - presenter = ARApplication.getInjector().provideRecordsPresenter(); + presenter = ARApplication.getInjector().provideRecordsPresenter(getApplicationContext()); waveformView.setOnSeekListener(new WaveformViewNew.OnSeekListener() { @Override diff --git a/app/src/main/java/com/dimowner/audiorecorder/app/settings/SettingsActivity.java b/app/src/main/java/com/dimowner/audiorecorder/app/settings/SettingsActivity.java index 323810f4..08299436 100644 --- a/app/src/main/java/com/dimowner/audiorecorder/app/settings/SettingsActivity.java +++ b/app/src/main/java/com/dimowner/audiorecorder/app/settings/SettingsActivity.java @@ -114,7 +114,7 @@ public static Intent getStartIntent(Context context) { @Override protected void onCreate(Bundle savedInstanceState) { - colorMap = ARApplication.getInjector().provideColorMap(); + colorMap = ARApplication.getInjector().provideColorMap(getApplicationContext()); setTheme(colorMap.getAppThemeResource()); super.onCreate(savedInstanceState); setContentView(R.layout.activity_settings); @@ -211,7 +211,7 @@ protected void onCreate(Bundle savedInstanceState) { channelsSetting.setTitle(R.string.channels); channelsSetting.setOnInfoClickListener(v -> AndroidUtils.showInfoDialog(SettingsActivity.this, R.string.info_channels)); - presenter = ARApplication.getInjector().provideSettingsPresenter(); + presenter = ARApplication.getInjector().provideSettingsPresenter(getApplicationContext()); LinearLayout pnlInfo = findViewById(R.id.info_panel); pnlInfo.setBackground( diff --git a/app/src/main/java/com/dimowner/audiorecorder/app/setup/SetupActivity.java b/app/src/main/java/com/dimowner/audiorecorder/app/setup/SetupActivity.java index af98e783..6f4e753d 100644 --- a/app/src/main/java/com/dimowner/audiorecorder/app/setup/SetupActivity.java +++ b/app/src/main/java/com/dimowner/audiorecorder/app/setup/SetupActivity.java @@ -64,7 +64,7 @@ public static Intent getStartIntent(Context context) { @Override protected void onCreate(Bundle savedInstanceState) { - colorMap = ARApplication.getInjector().provideColorMap(); + colorMap = ARApplication.getInjector().provideColorMap(getApplicationContext()); setTheme(colorMap.getAppThemeResource()); super.onCreate(savedInstanceState); setContentView(R.layout.activity_setup); @@ -142,7 +142,7 @@ protected void onCreate(Bundle savedInstanceState) { channelsSetting.setTitle(R.string.channels); channelsSetting.setOnInfoClickListener(v -> AndroidUtils.showInfoDialog(SetupActivity.this, R.string.info_channels)); - presenter = ARApplication.getInjector().provideSetupPresenter(); + presenter = ARApplication.getInjector().provideSetupPresenter(getApplicationContext()); initThemeColorSelector(); initNameFormatSelector(); diff --git a/app/src/main/java/com/dimowner/audiorecorder/app/trash/TrashActivity.java b/app/src/main/java/com/dimowner/audiorecorder/app/trash/TrashActivity.java index 4f48e654..9a9ff6df 100644 --- a/app/src/main/java/com/dimowner/audiorecorder/app/trash/TrashActivity.java +++ b/app/src/main/java/com/dimowner/audiorecorder/app/trash/TrashActivity.java @@ -59,7 +59,7 @@ public static Intent getStartIntent(Context context) { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { - setTheme(ARApplication.getInjector().provideColorMap().getAppThemeResource()); + setTheme(ARApplication.getInjector().provideColorMap(getApplicationContext()).getAppThemeResource()); super.onCreate(savedInstanceState); setContentView(R.layout.activity_trash); @@ -117,7 +117,7 @@ public void onRestoreItemClick(final RecordItem record) { } }); recyclerView.setAdapter(adapter); - presenter = ARApplication.getInjector().provideTrashPresenter(); + presenter = ARApplication.getInjector().provideTrashPresenter(getApplicationContext()); } @Override diff --git a/app/src/main/java/com/dimowner/audiorecorder/app/welcome/WelcomeActivity.java b/app/src/main/java/com/dimowner/audiorecorder/app/welcome/WelcomeActivity.java index c58080fc..2ef7f197 100644 --- a/app/src/main/java/com/dimowner/audiorecorder/app/welcome/WelcomeActivity.java +++ b/app/src/main/java/com/dimowner/audiorecorder/app/welcome/WelcomeActivity.java @@ -57,7 +57,7 @@ public static Intent getStartIntent(Context context) { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { - setTheme(ARApplication.getInjector().provideColorMap().getAppThemeResource()); + setTheme(ARApplication.getInjector().provideColorMap(getApplicationContext()).getAppThemeResource()); super.onCreate(savedInstanceState); setContentView(R.layout.activity_welcome); From 57ecb4f3c08bf4c122d6a1e6454585782d7205ed Mon Sep 17 00:00:00 2001 From: Harald Rudell Date: Sun, 16 Jul 2023 00:54:16 -0700 Subject: [PATCH 06/10] android.permission.POST_NOTIFICATIONS for Android13+ --- app/src/main/AndroidManifest.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index bb3434c7..93ea6c38 100755 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,6 +1,7 @@ + From dd0011e28fa8cef9dd7499622db2c481127413ae Mon Sep 17 00:00:00 2001 From: Harald Rudell Date: Sun, 16 Jul 2023 02:09:27 -0700 Subject: [PATCH 07/10] Android 12+ telephony support --- .../dimowner/audiorecorder/ARApplication.kt | 61 +++++++++++++++++-- .../audiorecorder/app/RecordingService.java | 3 +- 2 files changed, 57 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/dimowner/audiorecorder/ARApplication.kt b/app/src/main/java/com/dimowner/audiorecorder/ARApplication.kt index a228207e..2dbcac0e 100644 --- a/app/src/main/java/com/dimowner/audiorecorder/ARApplication.kt +++ b/app/src/main/java/com/dimowner/audiorecorder/ARApplication.kt @@ -13,20 +13,29 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +@file:Suppress("DEPRECATION") + package com.dimowner.audiorecorder +import android.Manifest import android.app.Application import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import android.content.IntentFilter +import android.content.pm.PackageManager +import android.os.Build import android.os.Handler import android.telephony.PhoneStateListener +import android.telephony.TelephonyCallback import android.telephony.TelephonyManager +import androidx.annotation.RequiresApi +import androidx.core.content.ContextCompat import com.dimowner.audiorecorder.util.AndroidUtils import timber.log.Timber import timber.log.Timber.DebugTree + //import com.google.firebase.FirebaseApp; class ARApplication : Application() { private var audioOutputChangeReceiver: AudioOutputChangeReceiver? = null @@ -52,9 +61,15 @@ class ARApplication : Application() { intentFilter.addAction(AUDIO_BECOMING_NOISY) audioOutputChangeReceiver = AudioOutputChangeReceiver() registerReceiver(audioOutputChangeReceiver, intentFilter) + + // feature: pause when phone functions ringing or off-hook try { - val mTelephonyMgr = getSystemService(TELEPHONY_SERVICE) as TelephonyManager - mTelephonyMgr.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE) + val telephonyMgr = getSystemService(TELEPHONY_SERVICE) as TelephonyManager + if (Build.VERSION.SDK_INT= Build.VERSION_CODES.S) object : CallStateListener() { + override fun onCallStateChanged(state: Int) { + if (state == TelephonyManager.CALL_STATE_OFFHOOK || + state == TelephonyManager.CALL_STATE_RINGING) { + pausePlayback() + } + } + } else null + private class AudioOutputChangeReceiver : BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { val actionOfIntent = intent.action @@ -79,12 +124,16 @@ class ARApplication : Application() { } } - private val mPhoneStateListener: PhoneStateListener = object : PhoneStateListener() { + @Suppress("DEPRECATION") + fun telephonyPreAndroid12(telephonyMgr: TelephonyManager) { + telephonyMgr.listen(mPhoneStateListenerPreAndroid12, PhoneStateListener.LISTEN_CALL_STATE) + } + + private val mPhoneStateListenerPreAndroid12: PhoneStateListener = object : PhoneStateListener() { + @Deprecated("Deprecated in Java") override fun onCallStateChanged(state: Int, incomingNumber: String) { if (state == TelephonyManager.CALL_STATE_RINGING || state == TelephonyManager.CALL_STATE_OFFHOOK) { - //Pause playback when incoming call or on hold - val player = injector!!.provideAudioPlayer() - player.pause() + pausePlayback() } super.onCallStateChanged(state, incomingNumber) } diff --git a/app/src/main/java/com/dimowner/audiorecorder/app/RecordingService.java b/app/src/main/java/com/dimowner/audiorecorder/app/RecordingService.java index bf29d73c..bca827e6 100644 --- a/app/src/main/java/com/dimowner/audiorecorder/app/RecordingService.java +++ b/app/src/main/java/com/dimowner/audiorecorder/app/RecordingService.java @@ -283,10 +283,11 @@ private void stopForegroundService() { started = false; } + @SuppressLint("WrongConstant") protected PendingIntent getPendingSelfIntent(Context context, String action) { Intent intent = new Intent(context, StopRecordingReceiver.class); intent.setAction(action); - return PendingIntent.getBroadcast(context, 10, intent, 0); + return PendingIntent.getBroadcast(context, 10, intent, AppConstants.PENDING_INTENT_FLAGS); } @RequiresApi(Build.VERSION_CODES.O) From c01f13e477e8a1e74302f7758d730f0dd0144753 Mon Sep 17 00:00:00 2001 From: Harald Rudell Date: Sun, 16 Jul 2023 06:10:56 -0700 Subject: [PATCH 08/10] deprecations --- .../com/dimowner/audiorecorder/ARApplication.kt | 13 ++++++------- .../dimowner/audiorecorder/app/DecodeService.kt | 17 +++++++++++------ .../app/settings/SettingsActivity.java | 10 ++++------ 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/com/dimowner/audiorecorder/ARApplication.kt b/app/src/main/java/com/dimowner/audiorecorder/ARApplication.kt index 2dbcac0e..e942b1ea 100644 --- a/app/src/main/java/com/dimowner/audiorecorder/ARApplication.kt +++ b/app/src/main/java/com/dimowner/audiorecorder/ARApplication.kt @@ -52,8 +52,7 @@ class ARApplication : Application() { applicationContext ) ) - injector = Injector() - val prefs = injector!!.providePrefs(applicationContext) + val prefs = injector.providePrefs(applicationContext) if (!prefs.isMigratedSettings) { prefs.migrateSettings() } @@ -79,14 +78,14 @@ class ARApplication : Application() { override fun onTerminate() { super.onTerminate() //This method is never called on real Android devices - injector!!.releaseMainPresenter() - injector!!.closeTasks() + injector.releaseMainPresenter() + injector.closeTasks() unregisterReceiver(audioOutputChangeReceiver) } fun pausePlayback() { //Pause playback when incoming call or on hold - val player = injector!!.provideAudioPlayer() + val player = injector.provideAudioPlayer() player.pause() } @@ -118,7 +117,7 @@ class ARApplication : Application() { override fun onReceive(context: Context, intent: Intent) { val actionOfIntent = intent.action if (actionOfIntent != null && actionOfIntent == AUDIO_BECOMING_NOISY) { - val player = injector!!.provideAudioPlayer() + val player = injector.provideAudioPlayer() player.pause() } } @@ -150,7 +149,7 @@ class ARApplication : Application() { /** Screen width in dp */ private var screenWidthDp = 0f @JvmStatic - var injector: Injector? = null + var injector = Injector() @JvmStatic fun appPackage(): String? { return PACKAGE_NAME diff --git a/app/src/main/java/com/dimowner/audiorecorder/app/DecodeService.kt b/app/src/main/java/com/dimowner/audiorecorder/app/DecodeService.kt index f04cfc1e..1a3cb92e 100644 --- a/app/src/main/java/com/dimowner/audiorecorder/app/DecodeService.kt +++ b/app/src/main/java/com/dimowner/audiorecorder/app/DecodeService.kt @@ -82,11 +82,11 @@ class DecodeService : Service() { override fun onCreate() { super.onCreate() - colorMap = ARApplication.injector!!.provideColorMap(applicationContext) - processingTasks = ARApplication.injector!!.provideProcessingTasksQueue() - recordingsTasks = ARApplication.injector!!.provideRecordingTasksQueue() - localRepository = ARApplication.injector!!.provideLocalRepository(applicationContext) - waveformVisualization = ARApplication.injector!!.provideAudioWaveformVisualization() + colorMap = ARApplication.injector.provideColorMap(applicationContext) + processingTasks = ARApplication.injector.provideProcessingTasksQueue() + recordingsTasks = ARApplication.injector.provideRecordingTasksQueue() + localRepository = ARApplication.injector.provideLocalRepository(applicationContext) + waveformVisualization = ARApplication.injector.provideAudioWaveformVisualization() } override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { @@ -230,7 +230,12 @@ class DecodeService : Service() { } fun stopService() { - stopForeground(true) + if (Build.VERSION.SDK_INT>Build.VERSION_CODES.S_V2) { + stopForeground(STOP_FOREGROUND_REMOVE) + }else { + @Suppress("DEPRECATION") + stopForeground(true) + } stopSelf() } diff --git a/app/src/main/java/com/dimowner/audiorecorder/app/settings/SettingsActivity.java b/app/src/main/java/com/dimowner/audiorecorder/app/settings/SettingsActivity.java index 08299436..d9719355 100644 --- a/app/src/main/java/com/dimowner/audiorecorder/app/settings/SettingsActivity.java +++ b/app/src/main/java/com/dimowner/audiorecorder/app/settings/SettingsActivity.java @@ -16,6 +16,7 @@ package com.dimowner.audiorecorder.app.settings; +import android.annotation.SuppressLint; import android.app.Activity; import android.content.ActivityNotFoundException; import android.content.Context; @@ -281,8 +282,8 @@ private void initNameFormatSelector() { values[2] = getResources().getString(R.string.naming) + " " + FileUtil.generateRecordNameDateUS() + ".m4a"; values[3] = getResources().getString(R.string.naming) + " " + FileUtil.generateRecordNameDateISO8601() + ".m4a"; values[4] = getResources().getString(R.string.naming) + " " + FileUtil.generateRecordNameMills() + ".m4a"; - for (int i = 0; i < values.length; i++) { - items.add(new AppSpinnerAdapter.ThemeItem(values[i], + for (String value : values) { + items.add(new AppSpinnerAdapter.ThemeItem(value, getApplicationContext().getResources().getColor(colorMap.getPrimaryColorRes()))); } AppSpinnerAdapter adapter = new AppSpinnerAdapter(SettingsActivity.this, @@ -323,6 +324,7 @@ protected void onDestroy() { colorMap.removeOnThemeColorChangeListener(onThemeColorChangeListener); } + @SuppressLint("UnsafeOptInUsageWarning") @Override public void onClick(View v) { int id = v.getId(); @@ -384,11 +386,7 @@ private void requestFeature() { private Intent rateIntentForUrl(String url) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(String.format("%s?id=%s", url, getApplicationContext().getPackageName()))); int flags = Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_MULTIPLE_TASK; - if (Build.VERSION.SDK_INT >= 21) { flags |= Intent.FLAG_ACTIVITY_NEW_DOCUMENT; - } else { - flags |= Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET; - } intent.addFlags(flags); return intent; } From 52db65dded183bc6d465735b01995b448fa9ff6e Mon Sep 17 00:00:00 2001 From: Harald Rudell Date: Sun, 16 Jul 2023 06:37:20 -0700 Subject: [PATCH 09/10] warnings --- app/build.gradle | 2 +- .../com/dimowner/audiorecorder/Injector.java | 3 +++ .../dimowner/audiorecorder/RecordingWidget.kt | 4 ++- .../audiorecorder/app/DownloadService.java | 3 ++- .../audiorecorder/app/PlaybackService.java | 3 ++- .../app/TransparentRecordingActivity.kt | 6 ++--- .../app/moverecords/MoveRecordsActivity.kt | 6 ++--- .../app/moverecords/MoveRecordsService.kt | 26 +++++++++++-------- 8 files changed, 32 insertions(+), 21 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 69f0883b..eddab7c2 100755 --- a/app/build.gradle +++ b/app/build.gradle @@ -92,7 +92,7 @@ android.variantFilter { variant -> dependencies { def androidX = "1.3.0" - def coroutines = "1.6.1" + def coroutines = "1.6.4" def timber = "5.0.1" //Kotlin diff --git a/app/src/main/java/com/dimowner/audiorecorder/Injector.java b/app/src/main/java/com/dimowner/audiorecorder/Injector.java index 3f0a00f2..e14f5c32 100644 --- a/app/src/main/java/com/dimowner/audiorecorder/Injector.java +++ b/app/src/main/java/com/dimowner/audiorecorder/Injector.java @@ -16,6 +16,7 @@ package com.dimowner.audiorecorder; +import android.annotation.SuppressLint; import android.content.Context; import com.dimowner.audiorecorder.app.AppRecorder; @@ -210,6 +211,7 @@ public SetupContract.UserActionsListener provideSetupPresenter(Context context) return setupPresenter; } + @SuppressLint("UnsafeOptInUsageWarning") public MoveRecordsViewModel provideMoveRecordsViewModel(Context context) { if (moveRecordsViewModel == null) { moveRecordsViewModel = new MoveRecordsViewModel( @@ -291,6 +293,7 @@ public void releaseSetupPresenter() { } } + @SuppressLint("UnsafeOptInUsageWarning") public void releaseMoveRecordsViewModel() { if (moveRecordsViewModel != null) { moveRecordsViewModel.clear(); diff --git a/app/src/main/java/com/dimowner/audiorecorder/RecordingWidget.kt b/app/src/main/java/com/dimowner/audiorecorder/RecordingWidget.kt index 831bab01..0340264c 100644 --- a/app/src/main/java/com/dimowner/audiorecorder/RecordingWidget.kt +++ b/app/src/main/java/com/dimowner/audiorecorder/RecordingWidget.kt @@ -1,5 +1,6 @@ package com.dimowner.audiorecorder +import android.annotation.SuppressLint import android.app.PendingIntent import android.appwidget.AppWidgetManager import android.appwidget.AppWidgetProvider @@ -43,9 +44,10 @@ internal fun updateAppWidget( appWidgetManager.updateAppWidget(appWidgetId, views) } +@SuppressLint("WrongConstant") private fun getRecordingPendingIntent(context: Context): PendingIntent { val intent = Intent(context, WidgetReceiver::class.java) - return PendingIntent.getBroadcast(context, 11, intent, 0) + return PendingIntent.getBroadcast(context, 11, intent, AppConstants.PENDING_INTENT_FLAGS) } class WidgetReceiver : BroadcastReceiver() { diff --git a/app/src/main/java/com/dimowner/audiorecorder/app/DownloadService.java b/app/src/main/java/com/dimowner/audiorecorder/app/DownloadService.java index 727368a4..53ecb28d 100644 --- a/app/src/main/java/com/dimowner/audiorecorder/app/DownloadService.java +++ b/app/src/main/java/com/dimowner/audiorecorder/app/DownloadService.java @@ -239,10 +239,11 @@ public void stopService() { stopSelf(); } + @SuppressLint("WrongConstant") protected PendingIntent getPendingSelfIntent(Context context, String action) { Intent intent = new Intent(context, StopDownloadReceiver.class); intent.setAction(action); - return PendingIntent.getBroadcast(context, 10, intent, 0); + return PendingIntent.getBroadcast(context, 10, intent, AppConstants.PENDING_INTENT_FLAGS); } @RequiresApi(Build.VERSION_CODES.O) diff --git a/app/src/main/java/com/dimowner/audiorecorder/app/PlaybackService.java b/app/src/main/java/com/dimowner/audiorecorder/app/PlaybackService.java index aeaaa01e..ff35bb21 100644 --- a/app/src/main/java/com/dimowner/audiorecorder/app/PlaybackService.java +++ b/app/src/main/java/com/dimowner/audiorecorder/app/PlaybackService.java @@ -202,10 +202,11 @@ public void stopForegroundService() { started = false; } + @SuppressLint("WrongConstant") protected PendingIntent getPendingSelfIntent(Context context, String action) { Intent intent = new Intent(context, StopPlaybackReceiver.class); intent.setAction(action); - return PendingIntent.getBroadcast(context, 10, intent, 0); + return PendingIntent.getBroadcast(context, 10, intent, AppConstants.PENDING_INTENT_FLAGS); } @RequiresApi(Build.VERSION_CODES.O) diff --git a/app/src/main/java/com/dimowner/audiorecorder/app/TransparentRecordingActivity.kt b/app/src/main/java/com/dimowner/audiorecorder/app/TransparentRecordingActivity.kt index dbaeee3b..ba5d4377 100644 --- a/app/src/main/java/com/dimowner/audiorecorder/app/TransparentRecordingActivity.kt +++ b/app/src/main/java/com/dimowner/audiorecorder/app/TransparentRecordingActivity.kt @@ -41,8 +41,8 @@ class TransparentRecordingActivity : Activity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - prefs = ARApplication.injector!!.providePrefs(applicationContext) - fileRepository = ARApplication.injector!!.provideFileRepository(applicationContext) + prefs = ARApplication.injector.providePrefs(applicationContext) + fileRepository = ARApplication.injector.provideFileRepository(applicationContext) if (checkRecordPermission2()) { if (checkStoragePermission2()) { @@ -116,7 +116,7 @@ class TransparentRecordingActivity : Activity() { if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { AndroidUtils.showDialog( this, R.string.warning, R.string.need_write_permission, - { v -> + { _ -> requestPermissions( arrayOf( Manifest.permission.WRITE_EXTERNAL_STORAGE, diff --git a/app/src/main/java/com/dimowner/audiorecorder/app/moverecords/MoveRecordsActivity.kt b/app/src/main/java/com/dimowner/audiorecorder/app/moverecords/MoveRecordsActivity.kt index 523a36c0..cdb0f20b 100644 --- a/app/src/main/java/com/dimowner/audiorecorder/app/moverecords/MoveRecordsActivity.kt +++ b/app/src/main/java/com/dimowner/audiorecorder/app/moverecords/MoveRecordsActivity.kt @@ -86,14 +86,14 @@ class MoveRecordsActivity : Activity() { } override fun onCreate(savedInstanceState: Bundle?) { - val colorMap = ARApplication.injector!!.provideColorMap(applicationContext) + val colorMap = ARApplication.injector.provideColorMap(applicationContext) setTheme(colorMap.appThemeResource) super.onCreate(savedInstanceState) binding = ActivityMoveRecordsBinding.inflate(layoutInflater) val view = binding.root setContentView(view) - viewModel = ARApplication.injector!!.provideMoveRecordsViewModel(applicationContext) + viewModel = ARApplication.injector.provideMoveRecordsViewModel(applicationContext) binding.recyclerView.layoutManager = LinearLayoutManager(applicationContext) binding.recyclerView.adapter = adapter @@ -381,7 +381,7 @@ class MoveRecordsActivity : Activity() { } private fun clear() { - ARApplication.injector!!.releaseMoveRecordsViewModel() + ARApplication.injector.releaseMoveRecordsViewModel() scope.cancel() } diff --git a/app/src/main/java/com/dimowner/audiorecorder/app/moverecords/MoveRecordsService.kt b/app/src/main/java/com/dimowner/audiorecorder/app/moverecords/MoveRecordsService.kt index eb5ee381..914d2053 100644 --- a/app/src/main/java/com/dimowner/audiorecorder/app/moverecords/MoveRecordsService.kt +++ b/app/src/main/java/com/dimowner/audiorecorder/app/moverecords/MoveRecordsService.kt @@ -17,6 +17,7 @@ import android.widget.Toast import androidx.annotation.RequiresApi import androidx.core.app.NotificationCompat import androidx.core.app.NotificationManagerCompat +import androidx.core.content.ContextCompat import com.dimowner.audiorecorder.ARApplication import com.dimowner.audiorecorder.AppConstants import com.dimowner.audiorecorder.BackgroundQueue @@ -85,12 +86,12 @@ class MoveRecordsService : Service() { override fun onCreate() { super.onCreate() - colorMap = ARApplication.injector!!.provideColorMap(applicationContext) - prefs = ARApplication.injector!!.providePrefs(applicationContext) - copyTasks = ARApplication.injector!!.provideCopyTasksQueue() - loadingTasks = ARApplication.injector!!.provideLoadingTasksQueue() - fileRepository = ARApplication.injector!!.provideFileRepository(applicationContext) - localRepository = ARApplication.injector!!.provideLocalRepository(applicationContext) + colorMap = ARApplication.injector.provideColorMap(applicationContext) + prefs = ARApplication.injector.providePrefs(applicationContext) + copyTasks = ARApplication.injector.provideCopyTasksQueue() + loadingTasks = ARApplication.injector.provideLoadingTasksQueue() + fileRepository = ARApplication.injector.provideFileRepository(applicationContext) + localRepository = ARApplication.injector.provideLocalRepository(applicationContext) } override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { @@ -225,10 +226,8 @@ class MoveRecordsService : Service() { resources.getString(R.string.moving_record, downloadingRecordName) ) remoteViewsSmall.setInt( - R.id.container, "setBackgroundColor", this.resources.getColor( - colorMap.primaryColorRes - ) - ) + R.id.container, "setBackgroundColor", + ContextCompat.getColor(applicationContext, colorMap.primaryColorRes)) // Create notification default intent. val intent = Intent(applicationContext, MainActivity::class.java) @@ -256,7 +255,12 @@ class MoveRecordsService : Service() { } fun stopService() { - stopForeground(true) + if (Build.VERSION.SDK_INT>Build.VERSION_CODES.S_V2) { + stopForeground(STOP_FOREGROUND_REMOVE) + }else { + @Suppress("DEPRECATION") + stopForeground(true) + } stopSelf() } From bfb60234d8e47feace6ae694551bffdda2d7301e Mon Sep 17 00:00:00 2001 From: Harald Rudell Date: Sun, 16 Jul 2023 07:31:09 -0700 Subject: [PATCH 10/10] comments --- .../audiorecorder/app/moverecords/MoveRecordsActivity.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/dimowner/audiorecorder/app/moverecords/MoveRecordsActivity.kt b/app/src/main/java/com/dimowner/audiorecorder/app/moverecords/MoveRecordsActivity.kt index cdb0f20b..5dda2565 100644 --- a/app/src/main/java/com/dimowner/audiorecorder/app/moverecords/MoveRecordsActivity.kt +++ b/app/src/main/java/com/dimowner/audiorecorder/app/moverecords/MoveRecordsActivity.kt @@ -43,7 +43,6 @@ import com.dimowner.audiorecorder.util.RippleUtils import com.dimowner.audiorecorder.util.TimeUtils import com.dimowner.audiorecorder.util.isVisible import kotlinx.coroutines.* -import kotlinx.coroutines.flow.collect import timber.log.Timber import java.io.File @@ -359,6 +358,12 @@ class MoveRecordsActivity : Activity() { clear() } + // 230716 should be uopgraded for Android 13… + // in AndroidManifest.xml, Application tag, add property android:enableOnBackInvokedCallback="true" + // make Activity AppCompatActivity + // in onCreate: onBackPressedDispatcher.addCallback(this,onBackPressedCallback) + // write the callback + // does not seem to work right yet, unless Activity 1.6+ is used override fun onBackPressed() { super.onBackPressed() clear()