forked from hardcoresushi/DroidFS
Remove some deprecation warnings
This commit is contained in:
parent
d3f0d059f8
commit
65ecdd19ca
@ -1,5 +1,5 @@
|
|||||||
package sushi.hardcore.droidfs.file_operations
|
package sushi.hardcore.droidfs.file_operations
|
||||||
|
|
||||||
import android.app.Notification
|
import androidx.core.app.NotificationCompat
|
||||||
|
|
||||||
class FileOperationNotification(val notificationBuilder: Notification.Builder, val notificationId: Int)
|
class FileOperationNotification(val notificationBuilder: NotificationCompat.Builder, val notificationId: Int)
|
@ -1,11 +1,11 @@
|
|||||||
package sushi.hardcore.droidfs.file_operations
|
package sushi.hardcore.droidfs.file_operations
|
||||||
|
|
||||||
import android.app.*
|
import android.app.*
|
||||||
import android.content.Context
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.graphics.drawable.Icon
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.*
|
import android.os.*
|
||||||
|
import androidx.core.app.NotificationCompat
|
||||||
|
import androidx.core.app.NotificationManagerCompat
|
||||||
import androidx.documentfile.provider.DocumentFile
|
import androidx.documentfile.provider.DocumentFile
|
||||||
import sushi.hardcore.droidfs.GocryptfsVolume
|
import sushi.hardcore.droidfs.GocryptfsVolume
|
||||||
import sushi.hardcore.droidfs.R
|
import sushi.hardcore.droidfs.R
|
||||||
@ -23,7 +23,7 @@ class FileOperationService : Service() {
|
|||||||
|
|
||||||
private val binder = LocalBinder()
|
private val binder = LocalBinder()
|
||||||
private lateinit var gocryptfsVolume: GocryptfsVolume
|
private lateinit var gocryptfsVolume: GocryptfsVolume
|
||||||
private lateinit var notificationManager: NotificationManager
|
private lateinit var notificationManager: NotificationManagerCompat
|
||||||
private var notifications = HashMap<Int, Boolean>()
|
private var notifications = HashMap<Int, Boolean>()
|
||||||
private var lastNotificationId = 0
|
private var lastNotificationId = 0
|
||||||
|
|
||||||
@ -41,41 +41,38 @@ class FileOperationService : Service() {
|
|||||||
private fun showNotification(message: Int, total: Int?): FileOperationNotification {
|
private fun showNotification(message: Int, total: Int?): FileOperationNotification {
|
||||||
++lastNotificationId
|
++lastNotificationId
|
||||||
if (!::notificationManager.isInitialized){
|
if (!::notificationManager.isInitialized){
|
||||||
notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
notificationManager = NotificationManagerCompat.from(this)
|
||||||
}
|
}
|
||||||
val notificationBuilder = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
val channel = NotificationChannel(NOTIFICATION_CHANNEL_ID, getString(R.string.file_operations), NotificationManager.IMPORTANCE_LOW)
|
notificationManager.createNotificationChannel(
|
||||||
notificationManager.createNotificationChannel(channel)
|
NotificationChannel(
|
||||||
Notification.Builder(this, NOTIFICATION_CHANNEL_ID)
|
NOTIFICATION_CHANNEL_ID,
|
||||||
} else {
|
getString(R.string.file_operations),
|
||||||
Notification.Builder(this)
|
NotificationManager.IMPORTANCE_LOW
|
||||||
}
|
)
|
||||||
val cancelIntent = Intent(this, NotificationBroadcastReceiver::class.java).apply {
|
|
||||||
val bundle = Bundle()
|
|
||||||
bundle.putBinder("binder", LocalBinder())
|
|
||||||
bundle.putInt("notificationId", lastNotificationId)
|
|
||||||
putExtra("bundle", bundle)
|
|
||||||
action = ACTION_CANCEL
|
|
||||||
}
|
|
||||||
val cancelPendingIntent = PendingIntent.getBroadcast(this, 0, cancelIntent, PendingIntent.FLAG_UPDATE_CURRENT)
|
|
||||||
val notificationAction = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
||||||
Notification.Action.Builder(
|
|
||||||
Icon.createWithResource(this, R.drawable.icon_close),
|
|
||||||
getString(R.string.cancel),
|
|
||||||
cancelPendingIntent
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
Notification.Action.Builder(
|
|
||||||
R.drawable.icon_close,
|
|
||||||
getString(R.string.cancel),
|
|
||||||
cancelPendingIntent
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
val notificationBuilder = NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
|
||||||
notificationBuilder
|
notificationBuilder
|
||||||
.setContentTitle(getString(message))
|
.setContentTitle(getString(message))
|
||||||
.setSmallIcon(R.mipmap.icon_launcher)
|
.setSmallIcon(R.mipmap.icon_launcher)
|
||||||
.setOngoing(true)
|
.setOngoing(true)
|
||||||
.addAction(notificationAction.build())
|
.addAction(NotificationCompat.Action(
|
||||||
|
R.drawable.icon_close,
|
||||||
|
getString(R.string.cancel),
|
||||||
|
PendingIntent.getBroadcast(
|
||||||
|
this,
|
||||||
|
0,
|
||||||
|
Intent(this, NotificationBroadcastReceiver::class.java).apply {
|
||||||
|
val bundle = Bundle()
|
||||||
|
bundle.putBinder("binder", LocalBinder())
|
||||||
|
bundle.putInt("notificationId", lastNotificationId)
|
||||||
|
putExtra("bundle", bundle)
|
||||||
|
action = ACTION_CANCEL
|
||||||
|
},
|
||||||
|
PendingIntent.FLAG_UPDATE_CURRENT
|
||||||
|
)
|
||||||
|
))
|
||||||
if (total != null) {
|
if (total != null) {
|
||||||
notificationBuilder
|
notificationBuilder
|
||||||
.setContentText("0/$total")
|
.setContentText("0/$total")
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package sushi.hardcore.droidfs.file_viewers
|
package sushi.hardcore.droidfs.file_viewers
|
||||||
|
|
||||||
import com.google.android.exoplayer2.SimpleExoPlayer
|
import com.google.android.exoplayer2.ExoPlayer
|
||||||
import sushi.hardcore.droidfs.databinding.ActivityAudioPlayerBinding
|
import sushi.hardcore.droidfs.databinding.ActivityAudioPlayerBinding
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ class AudioPlayer: MediaPlayer(){
|
|||||||
return "audio"
|
return "audio"
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun bindPlayer(player: SimpleExoPlayer) {
|
override fun bindPlayer(player: ExoPlayer) {
|
||||||
binding.audioController.player = player
|
binding.audioController.player = player
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,13 +10,13 @@ import sushi.hardcore.droidfs.R
|
|||||||
import sushi.hardcore.droidfs.widgets.CustomAlertDialogBuilder
|
import sushi.hardcore.droidfs.widgets.CustomAlertDialogBuilder
|
||||||
|
|
||||||
abstract class MediaPlayer: FileViewerActivity() {
|
abstract class MediaPlayer: FileViewerActivity() {
|
||||||
private lateinit var player: SimpleExoPlayer
|
private lateinit var player: ExoPlayer
|
||||||
|
|
||||||
override fun viewFile() {
|
override fun viewFile() {
|
||||||
initializePlayer()
|
initializePlayer()
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract fun bindPlayer(player: SimpleExoPlayer)
|
abstract fun bindPlayer(player: ExoPlayer)
|
||||||
protected open fun onPlaylistIndexChanged() {}
|
protected open fun onPlaylistIndexChanged() {}
|
||||||
protected open fun onPlayerReady() {}
|
protected open fun onPlayerReady() {}
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ abstract class MediaPlayer: FileViewerActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun initializePlayer(){
|
private fun initializePlayer(){
|
||||||
player = SimpleExoPlayer.Builder(this).build()
|
player = ExoPlayer.Builder(this).build()
|
||||||
bindPlayer(player)
|
bindPlayer(player)
|
||||||
createPlaylist()
|
createPlaylist()
|
||||||
for (e in mappedPlaylist) {
|
for (e in mappedPlaylist) {
|
||||||
@ -58,8 +58,8 @@ abstract class MediaPlayer: FileViewerActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
override fun onPositionDiscontinuity(reason: Int) {
|
override fun onPositionDiscontinuity(reason: Int) {
|
||||||
if (player.currentWindowIndex != currentPlaylistIndex) {
|
if (player.currentMediaItemIndex != currentPlaylistIndex) {
|
||||||
playlistNext(player.currentWindowIndex == (currentPlaylistIndex+1)%mappedPlaylist.size)
|
playlistNext(player.currentMediaItemIndex == (currentPlaylistIndex+1) % mappedPlaylist.size)
|
||||||
onPlaylistIndexChanged()
|
onPlaylistIndexChanged()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package sushi.hardcore.droidfs.file_viewers
|
package sushi.hardcore.droidfs.file_viewers
|
||||||
|
|
||||||
import android.content.pm.ActivityInfo
|
import android.content.pm.ActivityInfo
|
||||||
import com.google.android.exoplayer2.SimpleExoPlayer
|
import com.google.android.exoplayer2.ExoPlayer
|
||||||
import sushi.hardcore.droidfs.databinding.ActivityVideoPlayerBinding
|
import sushi.hardcore.droidfs.databinding.ActivityVideoPlayerBinding
|
||||||
|
|
||||||
class VideoPlayer: MediaPlayer() {
|
class VideoPlayer: MediaPlayer() {
|
||||||
@ -17,7 +17,7 @@ class VideoPlayer: MediaPlayer() {
|
|||||||
super.viewFile()
|
super.viewFile()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun bindPlayer(player: SimpleExoPlayer) {
|
override fun bindPlayer(player: ExoPlayer) {
|
||||||
binding.videoPlayer.player = player
|
binding.videoPlayer.player = player
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user