-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feature] Initial support for basic media library functions
- Loading branch information
Showing
48 changed files
with
2,651 additions
and
550 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
app/src/main/java/com/skyd/anivu/model/bean/MediaGroupBean.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.skyd.anivu.model.bean | ||
|
||
import com.skyd.anivu.R | ||
import com.skyd.anivu.appContext | ||
import com.skyd.anivu.base.BaseBean | ||
|
||
open class MediaGroupBean( | ||
open val name: String, | ||
) : BaseBean { | ||
override fun equals(other: Any?): Boolean { | ||
if (this === other) return true | ||
if (other !is MediaGroupBean) return false | ||
if (this === DefaultMediaGroup || other === DefaultMediaGroup) return false | ||
return name == other.name | ||
} | ||
|
||
override fun hashCode(): Int { | ||
var result = name.hashCode() | ||
result = 31 * result + (this === DefaultMediaGroup).hashCode() | ||
return result | ||
} | ||
|
||
object DefaultMediaGroup : | ||
MediaGroupBean(appContext.getString(R.string.default_media_group)) { | ||
private fun readResolve(): Any = DefaultMediaGroup | ||
override val name: String | ||
get() = appContext.getString(R.string.default_media_group) | ||
} | ||
|
||
companion object { | ||
fun MediaGroupBean.isDefaultGroup(): Boolean = this === DefaultMediaGroup | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,18 @@ | ||
package com.skyd.anivu.model.bean | ||
|
||
import android.content.Context | ||
import android.os.Parcelable | ||
import com.skyd.anivu.base.BaseBean | ||
import com.skyd.anivu.ext.toUri | ||
import kotlinx.parcelize.IgnoredOnParcel | ||
import kotlinx.parcelize.Parcelize | ||
import com.skyd.anivu.ext.getMimeType | ||
import java.io.File | ||
|
||
@Parcelize | ||
data class VideoBean( | ||
val displayName: String? = null, | ||
val file: File, | ||
) : BaseBean, Parcelable { | ||
fun isMedia(context: Context): Boolean = context.contentResolver | ||
.getType(file.toUri(context))?.startsWith("video/") == true | ||
|
||
@IgnoredOnParcel | ||
val name: String = file.name.orEmpty() | ||
|
||
@IgnoredOnParcel | ||
val size: Long = file.length() | ||
|
||
@IgnoredOnParcel | ||
val date: Long = file.lastModified() | ||
|
||
@IgnoredOnParcel | ||
) : BaseBean { | ||
var name: String = file.name | ||
var mimetype: String = file.getMimeType() ?: "*/*" | ||
var size: Long = file.length() | ||
var date: Long = file.lastModified() | ||
val isMedia: Boolean = mimetype.startsWith("video/") || mimetype.startsWith("audio/") | ||
val isDir: Boolean = file.isDirectory | ||
val isFile: Boolean = file.isFile | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
app/src/main/java/com/skyd/anivu/model/preference/data/FilePickerLocationPreference.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.skyd.anivu.model.preference.data | ||
|
||
import android.content.Context | ||
import android.os.Environment | ||
import androidx.datastore.preferences.core.Preferences | ||
import androidx.datastore.preferences.core.stringPreferencesKey | ||
import com.skyd.anivu.base.BasePreference | ||
import com.skyd.anivu.ext.dataStore | ||
import com.skyd.anivu.ext.put | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
|
||
object FilePickerLocationPreference : BasePreference<String> { | ||
private const val FILE_PICKER_LOCATION = "filePickerLocation" | ||
|
||
override val default: String = Environment.getExternalStorageDirectory().absolutePath | ||
|
||
val key = stringPreferencesKey(FILE_PICKER_LOCATION) | ||
|
||
fun put(context: Context, scope: CoroutineScope, value: String) { | ||
scope.launch(Dispatchers.IO) { | ||
context.dataStore.put(key, value) | ||
} | ||
} | ||
|
||
override fun fromPreferences(preferences: Preferences): String = preferences[key] ?: default | ||
} |
File renamed without changes.
Oops, something went wrong.