My Library

A description of what my library does.

License

License

GroupId

GroupId

com.github.xyz-fly
ArtifactId

ArtifactId

core
Last Version

Last Version

0.9.0
Release Date

Release Date

Type

Type

aar
Description

Description

My Library
A description of what my library does.
Project URL

Project URL

https://github.com/xyz-fly/AlbumCore/
Source Code Management

Source Code Management

https://github.com/xyz-fly/AlbumCore/

Download core

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.xyz-fly/core/ -->
<dependency>
    <groupId>com.github.xyz-fly</groupId>
    <artifactId>core</artifactId>
    <version>0.9.0</version>
    <type>aar</type>
</dependency>
// https://jarcasting.com/artifacts/com.github.xyz-fly/core/
implementation 'com.github.xyz-fly:core:0.9.0'
// https://jarcasting.com/artifacts/com.github.xyz-fly/core/
implementation ("com.github.xyz-fly:core:0.9.0")
'com.github.xyz-fly:core:aar:0.9.0'
<dependency org="com.github.xyz-fly" name="core" rev="0.9.0">
  <artifact name="core" type="aar" />
</dependency>
@Grapes(
@Grab(group='com.github.xyz-fly', module='core', version='0.9.0')
)
libraryDependencies += "com.github.xyz-fly" % "core" % "0.9.0"
[com.github.xyz-fly/core "0.9.0"]

Dependencies

runtime (5)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-android-extensions-runtime jar 1.3.72
org.jetbrains.kotlin : kotlin-stdlib-jdk7 jar 1.3.72
androidx.core » core-ktx jar 1.2.0
androidx.appcompat » appcompat jar 1.1.0
androidx.paging » paging-runtime-ktx jar 2.1.2

Project Modules

There are no modules declared in this project.

Build Status Maven Central GitHub license MinSdk

AlbumCore

A fast media loader library depend on androidx-paging without UI widget for Android.

AlbumCore AlbumCore

Download

So just add the dependency to your project build.gradle file:

dependencies {
    implementation 'com.github.xyz-fly:albumcore:0.9.8'
    // it need depend on androidx-paging for new features
    implementation 'androidx.paging:paging-runtime-ktx:3.0.0-alpha07'
}

Sample usage

A sample project which provide runnable code examples

Permission

Add the permission to your project manifests, and request permissions in your activity:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

Get Media of Directory

Create a loader by loadmanager and set DirectoryCallback as callback like this:

// For a simple directory list
LoaderManager.getInstance(this).initLoader(0, null, object : DirectoryCallback(
    this,
    MediaTypeSelection.Builder().image().video().create()
) {
    override fun onLoadComplete(
        loader: Loader<Cursor>,
        list: List<AlbumDirectory>
    ) {
        // show list to view
    }
})

Get media

  • 1: Create RecyclerView and PagingDataAdapter.
  • 2: Create a Pager by AlbumFactory, then create a flow to submit list data
  • 3: Get media data by directory-id (get all of media when directory-id is 0). Simple use cases will look something like this:
// For a simple image list

private val clearListCh = Channel<Unit>(Channel.CONFLATED)
private val albumMediaId = MutableLiveData<Long>()

private val posts = flowOf(
    clearListCh.receiveAsFlow().map { PagingData.empty<AlbumMedia>() },
    albumMediaId.asFlow().flatMapLatest {
        Pager(config) {
            AlbumFactory.getAlbumPagingSource(
                this,
                MediaTypeSelection.Builder().setBucketId(it).image().video().create()
            )
        }.flow.onStart {
            // let clearListCh emit empty-list first
            delay(1L)
        }
    }
).flattenMerge(2)

//
lifecycleScope.launchWhenCreated {
    posts.collectLatest {
        adapter.submitData(it)
    }
}

Filter media format

Filters items by an Array, or Ignore items by an Array

MediaTypeSelection.Builder()
    .setBucketId(id)
    .image(filter = arrayOf(MimeType.IMAGE_JPG, MimeType.IMAGE_PNG, MimeType.IMAGE_WEBP))
    .video(ignore = arrayOf(MimeType.VIDEO_AVI))
    .create()

Use selection and args

Use selection as query media parameter

val selection = "${MediaStore.Video.Media.DURATION} >= ?"
val selectionArgs = arrayOf(
    TimeUnit.MILLISECONDS.convert(5, TimeUnit.MINUTES).toString()
)

MediaTypeSelection.Builder()
    .selection(selection, selectionArgs)
    .create()

License

Copyright 2020 xyz-fly

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Versions

Version
0.9.0