Skip to content

Commit

Permalink
lint checks solved
Browse files Browse the repository at this point in the history
Signed-off-by: parneet-guraya <[email protected]>
  • Loading branch information
parneet-guraya committed Sep 3, 2024
1 parent 40f2d87 commit bc4ddf4
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 28 deletions.
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,8 @@
<service
android:name="com.nextcloud.client.media.BackgroundPlayerService"
android:foregroundServiceType="mediaPlayback"
android:exported="true">
android:exported="true"
tools:ignore="ExportedService">
<intent-filter>
<action android:name="androidx.media3.session.MediaSessionService"/>
</intent-filter>
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/nextcloud/client/di/AppComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -483,6 +485,7 @@ abstract class ComponentsModule {
abstract InternalTwoWaySyncActivity internalTwoWaySyncActivity();


@OptIn(markerClass = UnstableApi.class)
@ContributesAndroidInjector
abstract BackgroundPlayerService backgroundPlayerService();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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))
}

Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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))
}
}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -111,6 +110,7 @@ import javax.inject.Inject
* instantiation too.
*/
@Suppress("TooManyFunctions")
@OptIn(UnstableApi::class)
class PreviewMediaActivity :
FileActivity(),
FileFragment.ContainerActivity,
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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()
Expand All @@ -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")
}
}
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")
}
}
}
Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -208,7 +209,6 @@ class PreviewMediaFragment : FileFragment(), OnTouchListener, Injectable {
autoplay = exoPlayer?.isPlaying ?: false
putLong(EXTRA_PLAY_POSITION, savedPlaybackPosition)
putBoolean(EXTRA_PLAYING, autoplay)

}
}

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -545,7 +548,6 @@ class PreviewMediaFragment : FileFragment(), OnTouchListener, Injectable {
* Opens the previewed file with an external application.
*/
private fun openFile() {

containerActivity.fileOperationsHelper.openFile(file)
}

Expand Down

0 comments on commit bc4ddf4

Please sign in to comment.