Skip to content

Commit

Permalink
Update 2.3.1
Browse files Browse the repository at this point in the history
Fix error related to android song projection. (✔️) 
Fix error when trying to build using Android. (✔️)
Updated kotlin and dependences versions. (✔️)
Move from jCenter to MavenCentral. (✔️)
Added ignoreCase to querySongs, queryAlbums, queryPlaylists, queryArtists and queryGenres(Android/Web). (✔️)
  • Loading branch information
LucJosin authored Sep 27, 2021
2 parents 0265015 + 574ec99 commit dda1662
Show file tree
Hide file tree
Showing 37 changed files with 314 additions and 176 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ NOTE: Feel free to help with readme translations
Add the following code to your `pubspec.yaml`:
```yaml
dependencies:
on_audio_query: ^2.3.0
on_audio_query: ^2.3.1
```
### Request Permission:
Expand Down
24 changes: 24 additions & 0 deletions on_audio_query/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
## [2.3.1] - [09.27.2021]
### Features
#### Android/Web
- **[Added]** `[ignoreCase]` to:
- `[querySongs]`.
- `[queryAlbums]`.
- `[queryArtists]`.
- `[queryPlaylists]`.
- `[queryGenres]`.

### Fixes
#### Android
- **[Fixed]** `error` when trying to build using `Android`. - [#32](https://github.com/LucasPJS/on_audio_query/issues/32) & [#33](https://github.com/LucasPJS/on_audio_query/issues/33)
- **[Fixed]** `error` related to android song projection. - [#31](https://github.com/LucasPJS/on_audio_query/issues/31)
- **[Fixed]** `'bug'` when using `SongSortType.TITLE`. This is now a `'feature'` and can be controlled using `[ignoreCase]`. - [#29](https://github.com/LucasPJS/on_audio_query/issues/29)

### Documentation
- Updated `README` documentation.

### Changes
#### Android
- Updated `[Kotlin]` and `[Dependencies]` versions.
- Moved from `[JCenter]` to `[MavenCentral]`.

## [2.3.0] - [09.25.2021]
### Features
#### Android/IOS/Web
Expand Down
2 changes: 1 addition & 1 deletion on_audio_query/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ NOTE: Feel free to help with readme translations
Add the following code to your `pubspec.yaml`:
```yaml
dependencies:
on_audio_query: ^2.3.0
on_audio_query: ^2.3.1
```
### Request Permission:
Expand Down
2 changes: 1 addition & 1 deletion on_audio_query/README.pt-BR.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ NOTE: Fique à vontade para ajudar nas traduções
Adicione o seguinte codigo para seu `pubspec.yaml`:
```yaml
dependencies:
on_audio_query: ^2.3.0
on_audio_query: ^2.3.1
```
#### Solicitar Permissões:
Expand Down
13 changes: 6 additions & 7 deletions on_audio_query/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ group 'com.lucasjosino.on_audio_query'
version '1.0-SNAPSHOT'

buildscript {
ext.kotlin_version = '1.4.32'
ext.kotlin_version = '1.5.31'
repositories {
google()
jcenter()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:4.1.3'
classpath 'com.android.tools.build:gradle:7.0.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

rootProject.allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}

Expand All @@ -37,8 +37,7 @@ android {

dependencies {
def lifecycle_version = "2.3.1"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2-native-mt'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2-native-mt'
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Mon Sep 27 10:16:16 BRT 2021
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
zipStoreBase=GRADLE_USER_HOME
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.lucasjosino.on_audio_query.controller

import android.content.Context
import android.util.Log
import com.lucasjosino.on_audio_query.query.*
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ class OnAlbumsQuery : ViewModel() {

// Sort: Type and Order.
sortType = checkAlbumSortType(
call.argument<Int>("sortType")!!,
call.argument<Int>("orderType")!!
call.argument<Int>("sortType"),
call.argument<Int>("orderType")!!,
call.argument<Boolean>("ignoreCase")!!
)
// Check uri:
// * [0]: External.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ class OnArtistsQuery : ViewModel() {

// Sort: Type and Order
sortType = checkArtistSortType(
call.argument<Int>("sortType")!!,
call.argument<Int>("orderType")!!
call.argument<Int>("sortType"),
call.argument<Int>("orderType")!!,
call.argument<Boolean>("ignoreCase")!!
)
// Check uri:
// * [0]: External.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class OnAudiosFromQuery : ViewModel() {
withContext(Dispatchers.IO) {
// TODO: Add a [sortType].
// Setup the cursor with [uri], [projection], [selection](where) and [values](whereVal).
val cursor = resolver.query(uri, songProjection, where, arrayOf(whereVal), null)
val cursor = resolver.query(uri, songProjection(), where, arrayOf(whereVal), null)
// Empty list.
val songsFromList: ArrayList<MutableMap<String, Any?>> = ArrayList()

Expand Down Expand Up @@ -168,7 +168,7 @@ class OnAudiosFromQuery : ViewModel() {
withContext(Dispatchers.IO) {

val songsFrom: ArrayList<MutableMap<String, Any?>> = ArrayList()
val cursor = resolver.query(pUri, songProjection, null, null, null)
val cursor = resolver.query(pUri, songProjection(), null, null, null)
while (cursor != null && cursor.moveToNext()) {
val tempData: MutableMap<String, Any?> = HashMap()
for (media in cursor.columnNames) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ class OnAudiosQuery : ViewModel() {

// Sort: Type and Order.
sortType = checkSongSortType(
call.argument<Int>("sortType")!!,
call.argument<Int>("orderType")!!
call.argument<Int>("sortType"),
call.argument<Int>("orderType")!!,
call.argument<Boolean>("ignoreCase")!!
)
// Check uri:
// * [0]: External.
Expand Down Expand Up @@ -77,8 +78,9 @@ class OnAudiosQuery : ViewModel() {
//Loading in Background
private suspend fun loadSongs(): ArrayList<MutableMap<String, Any?>> =
withContext(Dispatchers.IO) {

// Setup the cursor with [uri], [projection] and [sortType].
val cursor = resolver.query(uri, songProjection, null, null, sortType)
val cursor = resolver.query(uri, songProjection(), null, null, sortType)
// Empty list.
val songList: ArrayList<MutableMap<String, Any?>> = ArrayList()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ class OnGenresQuery : ViewModel() {

// Sort: Type and Order.
sortType = checkGenreSortType(
call.argument<Int>("sortType")!!,
call.argument<Int>("orderType")!!
call.argument<Int>("sortType"),
call.argument<Int>("orderType")!!,
call.argument<Boolean>("ignoreCase")!!
)
// Check uri:
// * [0]: External.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ class OnPlaylistQuery : ViewModel() {

// Sort: Type and Order.
sortType = checkGenreSortType(
call.argument<Int>("sortType")!!,
call.argument<Int>("orderType")!!
call.argument<Int>("sortType"),
call.argument<Int>("orderType")!!,
call.argument<Boolean>("ignoreCase")!!
)
// Check uri:
// * [0]: External.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ fun checkWithFiltersType(sortType: Int): Uri {

fun checkProjection(withType: Uri): Array<String>? {
return when (withType) {
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI -> songProjection
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI -> songProjection()
// [Album] projection is null because we need all items.
MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI -> null
MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI -> playlistProjection
MediaStore.Audio.Artists.EXTERNAL_CONTENT_URI -> artistProjection
MediaStore.Audio.Genres.EXTERNAL_CONTENT_URI -> genreProjection
else -> songProjection
else -> songProjection()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ package com.lucasjosino.on_audio_query.types.sorttypes

import android.provider.MediaStore

fun checkAlbumSortType(sortType: Int, order: Int): String {
fun checkAlbumSortType(sortType: Int?, order: Int, ignoreCase: Boolean): String {
//[ASC] = Ascending Order
//[DESC] = Descending Order
//TODO: **Review this code later**
val pOrder: String = if (order == 0) " ASC" else " DESC"
val orderAndCase: String = if (ignoreCase) {
if (order == 0) " COLLATE NOCASE ASC" else " COLLATE NOCASE DESC"
} else {
if (order == 0) " ASC" else " DESC"
}
return when (sortType) {
0 -> MediaStore.Audio.Albums.ALBUM + pOrder
1 -> MediaStore.Audio.Albums.ARTIST + pOrder
2 -> MediaStore.Audio.Albums.NUMBER_OF_SONGS + pOrder
else -> MediaStore.Audio.Albums.ALBUM //
0 -> MediaStore.Audio.Albums.ALBUM + orderAndCase
1 -> MediaStore.Audio.Albums.ARTIST + orderAndCase
2 -> MediaStore.Audio.Albums.NUMBER_OF_SONGS + orderAndCase
else -> MediaStore.Audio.Albums.DEFAULT_SORT_ORDER + orderAndCase
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ package com.lucasjosino.on_audio_query.types.sorttypes

import android.provider.MediaStore

fun checkArtistSortType(sortType: Int, order: Int): String {
fun checkArtistSortType(sortType: Int?, order: Int, ignoreCase: Boolean): String {
//[ASC] = Ascending Order
//[DESC] = Descending Order
//TODO: **Review this code later**
val pOrder: String = if (order == 0) " ASC" else " DESC"
val orderAndCase: String = if (ignoreCase) {
if (order == 0) " COLLATE NOCASE ASC" else " COLLATE NOCASE DESC"
} else {
if (order == 0) " ASC" else " DESC"
}
return when (sortType) {
0 -> MediaStore.Audio.Artists.ARTIST + pOrder
1 -> MediaStore.Audio.Artists.NUMBER_OF_TRACKS + pOrder
2 -> MediaStore.Audio.Artists.NUMBER_OF_ALBUMS + pOrder
else -> MediaStore.Audio.Artists.ARTIST //
0 -> MediaStore.Audio.Artists.ARTIST + orderAndCase
1 -> MediaStore.Audio.Artists.NUMBER_OF_TRACKS + orderAndCase
2 -> MediaStore.Audio.Artists.NUMBER_OF_ALBUMS + orderAndCase
else -> MediaStore.Audio.Artists.DEFAULT_SORT_ORDER + orderAndCase
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ package com.lucasjosino.on_audio_query.types.sorttypes

import android.provider.MediaStore

fun checkGenreSortType(sortType: Int, order: Int): String {
fun checkGenreSortType(sortType: Int?, order: Int, ignoreCase: Boolean): String {
//[ASC] = Ascending Order
//[DESC] = Descending Order
//TODO: **Review this code later**
val pOrder: String = if (order == 0) " ASC" else " DESC"
val orderAndCase: String = if (ignoreCase) {
if (order == 0) " COLLATE NOCASE ASC" else " COLLATE NOCASE DESC"
} else {
if (order == 0) " ASC" else " DESC"
}
return when (sortType) {
0 -> MediaStore.Audio.Genres.NAME + pOrder
else -> MediaStore.Audio.Genres.NAME //
0 -> MediaStore.Audio.Genres.NAME + orderAndCase
else -> MediaStore.Audio.Genres.DEFAULT_SORT_ORDER + orderAndCase
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ package com.lucasjosino.on_audio_query.types.sorttypes

import android.provider.MediaStore

fun checkPlaylistSortType(sortType: Int, order: Int): String {
fun checkPlaylistSortType(sortType: Int?, order: Int, ignoreCase: Boolean): String {
//[ASC] = Ascending Order
//[DESC] = Descending Order
//TODO: **Review this code later**
val pOrder: String = if (order == 0) " ASC" else " DESC"
val orderAndCase: String = if (ignoreCase) {
if (order == 0) " COLLATE NOCASE ASC" else " COLLATE NOCASE DESC"
} else {
if (order == 0) " ASC" else " DESC"
}
return when (sortType) {
0 -> MediaStore.Audio.Playlists.NAME + pOrder
1 -> MediaStore.Audio.Playlists.DATE_ADDED + pOrder
else -> MediaStore.Audio.Playlists.NAME //
0 -> MediaStore.Audio.Playlists.NAME + orderAndCase
1 -> MediaStore.Audio.Playlists.DATE_ADDED + orderAndCase
else -> MediaStore.Audio.Playlists.DEFAULT_SORT_ORDER + orderAndCase
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,23 @@ import android.annotation.SuppressLint
import android.provider.MediaStore

@SuppressLint("InlinedApi")
fun checkSongSortType(sortType: Int, order: Int): String {
fun checkSongSortType(sortType: Int?, order: Int, ignoreCase: Boolean): String {
//[ASC] = Ascending Order
//[DESC] = Descending Order
//TODO: **Review this code later**
val pOrder: String = if (order == 0) " ASC" else " DESC"
val orderAndCase: String = if (ignoreCase) {
if (order == 0) " COLLATE NOCASE ASC" else " COLLATE NOCASE DESC"
} else {
if (order == 0) " ASC" else " DESC"
}
return when (sortType) {
0 -> MediaStore.Audio.Media.TITLE + pOrder
1 -> MediaStore.Audio.Media.ARTIST + pOrder
2 -> MediaStore.Audio.Media.ALBUM + pOrder
3 -> MediaStore.Audio.Media.DURATION + pOrder
4 -> MediaStore.Audio.Media.DATE_ADDED + pOrder
5 -> MediaStore.Audio.Media.SIZE + pOrder
6 -> MediaStore.Audio.Media.DISPLAY_NAME + pOrder
else -> MediaStore.Audio.Media.TITLE //
0 -> MediaStore.Audio.Media.TITLE + orderAndCase
1 -> MediaStore.Audio.Media.ARTIST + orderAndCase
2 -> MediaStore.Audio.Media.ALBUM + orderAndCase
3 -> MediaStore.Audio.Media.DURATION + orderAndCase
4 -> MediaStore.Audio.Media.DATE_ADDED + orderAndCase
5 -> MediaStore.Audio.Media.SIZE + orderAndCase
6 -> MediaStore.Audio.Media.DISPLAY_NAME + orderAndCase
else -> MediaStore.Audio.Media.DEFAULT_SORT_ORDER + orderAndCase
}
}
Loading

0 comments on commit dda1662

Please sign in to comment.