Skip to content

Commit

Permalink
Add predictive back animation for all fragments
Browse files Browse the repository at this point in the history
  • Loading branch information
brahmkshatriya committed Dec 10, 2024
1 parent 016505f commit 23f1da8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 51 deletions.
20 changes: 9 additions & 11 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,25 @@ dependencies {

implementation("androidx.appcompat:appcompat:1.7.0")

implementation("androidx.constraintlayout:constraintlayout:2.1.4")
implementation("androidx.constraintlayout:constraintlayout:2.2.0")
implementation("androidx.recyclerview:recyclerview:1.3.2")
implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.1.0")

implementation("androidx.fragment:fragment-ktx:1.6.2")
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.6")
implementation("androidx.paging:paging-common-ktx:3.3.2")
implementation("androidx.paging:paging-runtime-ktx:3.3.2")
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.7")
implementation("androidx.paging:paging-common-ktx:3.3.4")
implementation("androidx.paging:paging-runtime-ktx:3.3.4")
implementation("androidx.preference:preference-ktx:1.2.1")

implementation("androidx.room:room-runtime:2.6.1")
implementation("androidx.room:room-ktx:2.6.1")
ksp("androidx.room:room-compiler:2.6.1")

implementation("androidx.media3:media3-exoplayer:1.4.1")
implementation("androidx.media3:media3-session:1.4.1")
implementation("androidx.media3:media3-ui:1.4.1")
implementation("androidx.media3:media3-exoplayer-dash:1.4.1")
implementation("androidx.media3:media3-exoplayer-hls:1.4.1")
implementation("androidx.media3:media3-exoplayer:1.5.0")
implementation("androidx.media3:media3-session:1.5.0")
implementation("androidx.media3:media3-ui:1.5.0")
implementation("androidx.media3:media3-exoplayer-dash:1.5.0")
implementation("androidx.media3:media3-exoplayer-hls:1.5.0")

implementation("androidx.core:core-splashscreen:1.0.1")
implementation("androidx.palette:palette-ktx:1.0.0")
Expand All @@ -86,8 +86,6 @@ dependencies {
implementation("com.flaviofaria:kenburnsview:1.0.7")
implementation("com.github.paramsen:noise:2.0.0")

implementation("com.github.Kyant0:taglib:1.0.0-alpha22")

testImplementation("org.jetbrains.kotlin:kotlin-reflect:1.9.24")
testImplementation("junit:junit:4.13.2")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,17 @@ import android.app.DownloadManager
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.graphics.Bitmap
import android.media.MediaScannerConnection
import android.net.Uri
import android.os.ParcelFileDescriptor
import android.webkit.MimeTypeMap
import com.kyant.taglib.Metadata
import com.kyant.taglib.Picture
import com.kyant.taglib.PropertyMap
import com.kyant.taglib.TagLib
import dagger.hilt.android.AndroidEntryPoint
import dev.brahmkshatriya.echo.EchoDatabase
import dev.brahmkshatriya.echo.common.models.Track
import dev.brahmkshatriya.echo.db.DownloadDao
import dev.brahmkshatriya.echo.utils.getFromCache
import dev.brahmkshatriya.echo.utils.loadBitmap
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import java.io.ByteArrayOutputStream
import java.io.File
import javax.inject.Inject

Expand Down Expand Up @@ -58,7 +50,6 @@ class DownloadReceiver : BroadcastReceiver() {
val file = File(Uri.parse(fileUri).path!!)
val newFile = File("${file.absolutePath}.$extension")
file.renameTo(newFile)
context.applyTags(newFile, track)
MediaScannerConnection.scanFile(
context, arrayOf(newFile.toString()), null, null
)
Expand All @@ -70,35 +61,4 @@ class DownloadReceiver : BroadcastReceiver() {
}
}
}

companion object {
fun Context.applyTags(
newFile: File, track
: Track
) {
val fd = ParcelFileDescriptor.open(
newFile, ParcelFileDescriptor.MODE_READ_WRITE
)

val metadata = TagLib.getMetadata(fd = fd.dup().detachFd(), readPictures = true)
?: Metadata(PropertyMap(), arrayOf())
val artwork = runBlocking { track.cover.loadBitmap(this@applyTags) }?.let {
val stream = ByteArrayOutputStream()
it.compress(Bitmap.CompressFormat.PNG, 100, stream)
Picture(stream.toByteArray(), "Back Cover", "Back Cover", "image/png")
}

artwork?.let { TagLib.savePictures(fd.dup().detachFd(), arrayOf(it)) }
val props = metadata.propertyMap.apply {
set("TITLE", arrayOf(track.title))
set("ARTIST", arrayOf(track.artists.joinToString(", ") { it.name }))
track.album?.run {
set("ALBUM", arrayOf(title))
set("ALBUMARTIST", arrayOf(artists.joinToString(", ") { it.name }))
releaseDate?.let { set("DATE", arrayOf(it)) }
}
}
TagLib.savePropertyMap(fd.dup().detachFd(), props)
}
}
}

0 comments on commit 23f1da8

Please sign in to comment.