From bc4ddf46fbcb73bddacc0528e671021a303c43d6 Mon Sep 17 00:00:00 2001 From: parneet-guraya Date: Wed, 4 Sep 2024 04:32:07 +0530 Subject: [PATCH] lint checks solved Signed-off-by: parneet-guraya --- app/src/main/AndroidManifest.xml | 3 ++- .../com/nextcloud/client/di/AppComponent.java | 4 ++++ .../nextcloud/client/di/ComponentsModule.java | 3 +++ .../client/media/BackgroundPlayerService.kt | 18 ++++++++++++------ .../android/media/MediaControlView.kt | 9 ++------- .../ui/preview/PreviewMediaActivity.kt | 19 +++++++++---------- .../ui/preview/PreviewMediaFragment.kt | 10 ++++++---- 7 files changed, 38 insertions(+), 28 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f71a4ac29fb8..61b602496481 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -350,7 +350,8 @@ + android:exported="true" + tools:ignore="ExportedService"> diff --git a/app/src/main/java/com/nextcloud/client/di/AppComponent.java b/app/src/main/java/com/nextcloud/client/di/AppComponent.java index 0a136b19ce22..27e69184437c 100644 --- a/app/src/main/java/com/nextcloud/client/di/AppComponent.java +++ b/app/src/main/java/com/nextcloud/client/di/AppComponent.java @@ -28,6 +28,8 @@ import javax.inject.Singleton; +import androidx.annotation.OptIn; +import androidx.media3.common.util.UnstableApi; import dagger.BindsInstance; import dagger.Component; import dagger.android.support.AndroidSupportInjectionModule; @@ -55,6 +57,8 @@ public interface AppComponent { void inject(MainApp app); void inject(MediaControlView mediaControlView); + + @OptIn(markerClass = UnstableApi.class) void inject(BackgroundPlayerService backgroundPlayerService); void inject(ThemeableSwitchPreference switchPreference); diff --git a/app/src/main/java/com/nextcloud/client/di/ComponentsModule.java b/app/src/main/java/com/nextcloud/client/di/ComponentsModule.java index cd0040476e11..32c9344b7f65 100644 --- a/app/src/main/java/com/nextcloud/client/di/ComponentsModule.java +++ b/app/src/main/java/com/nextcloud/client/di/ComponentsModule.java @@ -123,6 +123,8 @@ import com.owncloud.android.ui.preview.pdf.PreviewPdfFragment; import com.owncloud.android.ui.trashbin.TrashbinActivity; +import androidx.annotation.OptIn; +import androidx.media3.common.util.UnstableApi; import dagger.Module; import dagger.android.ContributesAndroidInjector; @@ -483,6 +485,7 @@ abstract class ComponentsModule { abstract InternalTwoWaySyncActivity internalTwoWaySyncActivity(); + @OptIn(markerClass = UnstableApi.class) @ContributesAndroidInjector abstract BackgroundPlayerService backgroundPlayerService(); diff --git a/app/src/main/java/com/nextcloud/client/media/BackgroundPlayerService.kt b/app/src/main/java/com/nextcloud/client/media/BackgroundPlayerService.kt index 64dfbd633975..f49e32515f45 100644 --- a/app/src/main/java/com/nextcloud/client/media/BackgroundPlayerService.kt +++ b/app/src/main/java/com/nextcloud/client/media/BackgroundPlayerService.kt @@ -78,7 +78,7 @@ class BackgroundPlayerService : MediaSessionService(), Injectable { private val stopReceiver = object : BroadcastReceiver() { override fun onReceive(context: Context?, intent: Intent?) { - when(intent?.action){ + when (intent?.action) { RELEASE_MEDIA_SESSION_BROADCAST_ACTION -> release() STOP_MEDIA_SESSION_BROADCAST_ACTION -> exoPlayer.stop() } @@ -110,7 +110,15 @@ class BackgroundPlayerService : MediaSessionService(), Injectable { val playPauseButton = CommandButton.Builder() .setDisplayName("PlayPause") - .setIconResId(CommandButton.getIconResIdForIconConstant(if (mediaSession?.player?.isPlaying!!) CommandButton.ICON_PAUSE else CommandButton.ICON_PLAY)) + .setIconResId( + CommandButton.getIconResIdForIconConstant( + if (mediaSession?.player?.isPlaying!!) { + CommandButton.ICON_PAUSE + } else { + CommandButton.ICON_PLAY + } + ) + ) .setPlayerCommand(COMMAND_PLAY_PAUSE) .setExtras(Bundle().apply { putInt(COMMAND_KEY_COMPACT_VIEW_INDEX, 1) }) .build() @@ -161,10 +169,7 @@ class BackgroundPlayerService : MediaSessionService(), Injectable { .build() } - override fun onPostConnect( - session: MediaSession, - controller: MediaSession.ControllerInfo - ) { + override fun onPostConnect(session: MediaSession, controller: MediaSession.ControllerInfo) { session.setCustomLayout(listOf(seekBackward, seekForward)) } @@ -219,6 +224,7 @@ class BackgroundPlayerService : MediaSessionService(), Injectable { // that sometimes onTaskRemove() doesn't get called immediately // eventually gets called so the service stops but the notification doesn't clear out. // [WORKAROUND] So, explicitly removing the notification here. + // TODO: revisit after bug solved! val nm = getSystemService(NOTIFICATION_SERVICE) as NotificationManager nm.cancel(DefaultMediaNotificationProvider.DEFAULT_NOTIFICATION_ID) stopSelf() diff --git a/app/src/main/java/com/owncloud/android/media/MediaControlView.kt b/app/src/main/java/com/owncloud/android/media/MediaControlView.kt index 87b5d12375c6..3b1fae062701 100644 --- a/app/src/main/java/com/owncloud/android/media/MediaControlView.kt +++ b/app/src/main/java/com/owncloud/android/media/MediaControlView.kt @@ -72,10 +72,6 @@ class MediaControlView(context: Context, attrs: AttributeSet?) : }, 100) } - fun stopMediaPlayerMessages() { - handler.removeMessages(SHOW_PROGRESS) - } - @Suppress("MagicNumber") private fun initControllerView() { binding.playBtn.requestFocus() @@ -131,7 +127,7 @@ class MediaControlView(context: Context, attrs: AttributeSet?) : val pos = setProgress() if (!isDragging) { - sendMessageDelayed(obtainMessage(SHOW_PROGRESS), (1000 - pos % 1000).toLong()) + sendMessageDelayed(obtainMessage(SHOW_PROGRESS), (1000 - pos % 1000)) } } } @@ -274,7 +270,6 @@ class MediaControlView(context: Context, attrs: AttributeSet?) : @Suppress("MagicNumber") override fun onClick(v: View) { - playerControl?.let { playerControl -> val playing = playerControl.playWhenReady val id = v.id @@ -316,7 +311,7 @@ class MediaControlView(context: Context, attrs: AttributeSet?) : } playerControl?.let { playerControl -> - val duration = playerControl.duration.toLong() + val duration = playerControl.duration val newPosition = duration * progress / 1000L playerControl.seekTo(newPosition) binding.currentTimeText.text = formatTime(newPosition) diff --git a/app/src/main/java/com/owncloud/android/ui/preview/PreviewMediaActivity.kt b/app/src/main/java/com/owncloud/android/ui/preview/PreviewMediaActivity.kt index d92db7ea21a4..0176556f7f31 100644 --- a/app/src/main/java/com/owncloud/android/ui/preview/PreviewMediaActivity.kt +++ b/app/src/main/java/com/owncloud/android/ui/preview/PreviewMediaActivity.kt @@ -64,7 +64,6 @@ import com.nextcloud.client.jobs.download.FileDownloadHelper import com.nextcloud.client.media.BackgroundPlayerService import com.nextcloud.client.media.ErrorFormat import com.nextcloud.client.media.ExoplayerListener -import com.nextcloud.client.media.ExoplayerListener.Companion import com.nextcloud.client.media.NextcloudExoPlayer.createNextcloudExoplayer import com.nextcloud.client.network.ClientFactory import com.nextcloud.client.network.ClientFactory.CreationException @@ -111,6 +110,7 @@ import javax.inject.Inject * instantiation too. */ @Suppress("TooManyFunctions") +@OptIn(UnstableApi::class) class PreviewMediaActivity : FileActivity(), FileFragment.ContainerActivity, @@ -144,7 +144,6 @@ class PreviewMediaActivity : override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.O) { setTheme(R.style.Theme_ownCloud_Toolbar) } @@ -157,10 +156,10 @@ class PreviewMediaActivity : applyWindowInsets() initArguments(savedInstanceState) - if(MimeTypeUtil.isVideo(file)){ + if (MimeTypeUtil.isVideo(file)) { // release any background media session if exists sendAudioSessionReleaseBroadcast() - }else if(MimeTypeUtil.isAudio(file)){ + } else if (MimeTypeUtil.isAudio(file)) { val stopPlayer = Intent(BackgroundPlayerService.STOP_MEDIA_SESSION_BROADCAST_ACTION).apply { setPackage(packageName) } @@ -344,7 +343,7 @@ class PreviewMediaActivity : nextcloudClient?.let { client -> handler.post { videoPlayer = createNextcloudExoplayer(this, client) - videoMediaSession = MediaSession.Builder(this,videoPlayer as Player).build() + videoMediaSession = MediaSession.Builder(this, videoPlayer as Player).build() videoPlayer?.let { player -> player.addListener( @@ -386,7 +385,7 @@ class PreviewMediaActivity : playAudio() binding.audioControllerView.setMediaPlayer(audioMediaController) } catch (e: Exception) { - Log_OC.e(TAG,"exception raised while getting the media controller ${e.message}") + Log_OC.e(TAG, "exception raised while getting the media controller ${e.message}") } }, MoreExecutors.directExecutor() @@ -400,7 +399,7 @@ class PreviewMediaActivity : try { LoadStreamUrl(this, user, clientFactory).execute(file.localId) } catch (e: Exception) { - Log_OC.e(TAG, "Loading stream url not possible: $e") + Log_OC.e(TAG, "Loading stream url for Audio not possible: $e") } } } @@ -434,7 +433,7 @@ class PreviewMediaActivity : MaterialAlertDialogBuilder(this@PreviewMediaActivity) .setMessage(message) .setPositiveButton(R.string.common_ok) { _: DialogInterface?, _: Int -> - audioPlayer.seekToDefaultPosition() + audioPlayer.seekToDefaultPosition() audioPlayer.pause() } .setCancelable(false) @@ -692,7 +691,7 @@ class PreviewMediaActivity : try { LoadStreamUrl(this, user, clientFactory).execute(file.localId) } catch (e: Exception) { - Log_OC.e(TAG, "Loading stream url not possible: $e") + Log_OC.e(TAG, "Loading stream url for Video not possible: $e") } } } @@ -770,7 +769,7 @@ class PreviewMediaActivity : } override fun onDestroy() { - mediaControllerFuture?.let {MediaController.releaseFuture(it)} + mediaControllerFuture?.let { MediaController.releaseFuture(it) } super.onDestroy() Log_OC.v(TAG, "onDestroy") diff --git a/app/src/main/java/com/owncloud/android/ui/preview/PreviewMediaFragment.kt b/app/src/main/java/com/owncloud/android/ui/preview/PreviewMediaFragment.kt index 52c6ee60c4f8..4785d2d728a9 100644 --- a/app/src/main/java/com/owncloud/android/ui/preview/PreviewMediaFragment.kt +++ b/app/src/main/java/com/owncloud/android/ui/preview/PreviewMediaFragment.kt @@ -120,11 +120,12 @@ class PreviewMediaFragment : FileFragment(), OnTouchListener, Injectable { private var mediaSession: MediaSession? = null private var nextcloudClient: NextcloudClient? = null + @OptIn(UnstableApi::class) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) // release any background media session if exists - val intent = Intent(BackgroundPlayerService.STOP_MEDIA_SESSION_BROADCAST_ACTION).apply { + val intent = Intent(BackgroundPlayerService.RELEASE_MEDIA_SESSION_BROADCAST_ACTION).apply { setPackage(requireActivity().packageName) } requireActivity().sendBroadcast(intent) @@ -208,7 +209,6 @@ class PreviewMediaFragment : FileFragment(), OnTouchListener, Injectable { autoplay = exoPlayer?.isPlaying ?: false putLong(EXTRA_PLAY_POSITION, savedPlaybackPosition) putBoolean(EXTRA_PLAYING, autoplay) - } } @@ -254,7 +254,10 @@ class PreviewMediaFragment : FileFragment(), OnTouchListener, Injectable { it.addListener(listener) } // session id needs to be unique since this fragment is used in viewpager multiple fragments can exist at a time - mediaSession = MediaSession.Builder(requireContext(),exoPlayer as Player).setId(System.currentTimeMillis().toString()).build() + mediaSession = MediaSession.Builder( + requireContext(), + exoPlayer as Player + ).setId(System.currentTimeMillis().toString()).build() } private fun releaseVideoPlayer() { @@ -545,7 +548,6 @@ class PreviewMediaFragment : FileFragment(), OnTouchListener, Injectable { * Opens the previewed file with an external application. */ private fun openFile() { - containerActivity.fileOperationsHelper.openFile(file) }