Skip to content

Commit

Permalink
Release of 2.5.0
Browse files Browse the repository at this point in the history
* All:
Add `artwork` to genres. (✔️|✔️|✔️)
Add `sortType`, `orderType` and `ignoreCase` to `queryAudiosFrom`. (✔️|✔️|✔️)

* Dart:
Add `frameBuilder` and `errorBuilder` to `[QueryArtworkWidget].` (✔️)
Remove deprecated methods. (✔️)
Update DEPRECATED. (✔️)

* Web
Add `path` parameter to `querySongs`. (✔️)

* Android:
Downgrade kotlin and gradle version. (✔️)
Fix null album_id on Android 9 or below. (✔️)
Re-Add the `path` parameter to `querySongs`. (✔️)
Fix empty `Uint8List` when using `queryArtwork` on Android 7. (✔️)
  • Loading branch information
LucJosin authored Oct 16, 2021
2 parents f4549f9 + a2043ac commit cffc616
Show file tree
Hide file tree
Showing 39 changed files with 516 additions and 167 deletions.
20 changes: 17 additions & 3 deletions 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.4.1
on_audio_query: ^2.5.0
```
### Request Permission:
Expand Down Expand Up @@ -135,7 +135,7 @@ All types of methods on this plugin:
| [`queryArtists`](#queryartists) | `(SortType, OrderType, UriType, RequestPermission)` | `List<ArtistModel>` | <br>
| [`queryPlaylists`](#queryplaylists) | `(SortType, OrderType, UriType, RequestPermission)` | `List<PlaylistModel>` | <br>
| [`queryGenres`](#querygenres) | `(SortType, OrderType, UriType, RequestPermission)` | `List<GenreModel>` | <br>
| [`queryAudiosFrom`]() | `(Type, Where, RequestPermission)` | `List<SongModel>` | <br>
| [`queryAudiosFrom`](#queryaudiosfrom) | `(Type, Where, RequestPermission)` | `List<SongModel>` | <br>
| [`queryWithFilters`](#querywithfilters) | `(ArgsVal, WithFiltersType, Args, RequestPermission)` | `List<dynamic>` | <br>
| [`queryArtwork`](#queryArtwork) | `(Id, Type, Format, Size, RequestPermission)` | `Uint8List?` | <br>

Expand Down Expand Up @@ -247,7 +247,21 @@ All types of methods on this plugin:
```

Or you can use a basic and custom Widget.
**See example [QueryArtworkWidget](#artworkwidget)**
**See example [QueryArtworkWidget](#artwork-widget)**

#### queryAudiosFrom
You can use this method to 'query' the songs from any section(Album, Artist, Playlist or Genre).
```dart
someName() async {
List<SongModel> something = await _audioQuery.queryAudiosFrom(
AudiosFromType.ALBUM_ID,
albumId,
// You can also define a sortType
sortType: SongSortType.TITLE, // Default
orderType: OrderType.ASC_OR_SMALLER, // Default
);
}
```

#### queryWithFilters
```dart
Expand Down
45 changes: 45 additions & 0 deletions on_audio_query/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,48 @@
## [2.5.0] - [10.15.2021]
### Release
- `[2.0.0]` release.

### Features
#### Dart
- **[Added]** `errorBuilder` and `frameBuilder` to `[QueryArtworkWidget]`.

### Fixes
#### Web
- **[Fixed]** empty result when using `[queryArtwork]`.
- **[Fixed]** error when decoding some images.

See all development [changes](https://github.com/LucasPJS/on_audio_query/blob/main/on_audio_query/CHANGELOG.md):
- [2.5.0-alpha.0](#250-alpha0---10152021)

## [2.5.0-alpha.0] - [10.15.2021]
### Features
#### All platforms
- **[Added]** `artwork` to genres. - [#41](https://github.com/LucasPJS/on_audio_query/issues/41)
- **[Added]** `sortType`, `orderType` and `ignoreCase` to `[queryAudiosFrom]`.

#### Android
- Re-**[Added]** `path` parameter to `[querySongs]`. - [#48](https://github.com/LucasPJS/on_audio_query/issues/48)

#### Web
- **[Added]** `path` parameter to `[querySongs]`.

### Fixes
#### Android
- **[Fixed]** empty `Uint8List` when using `[queryArtwork]` on Android 7. - [#47](https://github.com/LucasPJS/on_audio_query/issues/47)
- **[Fixed]** null `albumId` when using Android 9 or below. - [#53](https://github.com/LucasPJS/on_audio_query/issues/53)

### Documentation
- Updated `README` documentation. New `[queryAudiosFrom]` section.
- Updated `DEPRECATED` documentation.

### Changes
- Downgraded `Kotlin` and `Gradle` version. - [#51](https://github.com/LucasPJS/on_audio_query/issues/51)

### ⚠ Important Changes
#### @Deprecated
- `[albumId]` from `[AlbumModel]`.
- Use `[id]` instead.

## [2.4.2] - [10.01.2021]
### Fixes
#### IOS
Expand Down
9 changes: 7 additions & 2 deletions on_audio_query/DEPRECATED.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
## [2.3.0] - [09.25.2021] -> [X.X.X] - [XX.XX.2021]
## [2.5.0] - [10.15.2021] -> [X.X.X] - [XX.XX.XXXX]
### Deprecated
- `[albumId]` from `[AlbumModel]`.
- Use `[id]` instead.

## [2.3.0] - [09.25.2021] -> [2.5.0] - [10.15.2021]
### Deprecated
- `[DEFAULT]` from `[SongSortType]`.
- Use `[TITLE]` instead.
Expand All @@ -22,7 +27,7 @@
- `[DATA_ADDED]` from `[PlaylistSortType]`.
- Use `[DATE_ADDED]` instead.

## [2.0.0] - [06.23.2021] -> [2.3.0] - [09.23.2021]
## [2.0.0] - [06.23.2021] -> [2.3.0] - [09.25.2021]
### Deprecated
- `[albumName]` from `[AlbumModel]`.
- Use `[album]` instead.
Expand Down
20 changes: 17 additions & 3 deletions 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.4.2
on_audio_query: ^2.5.0
```
### Request Permission:
Expand Down Expand Up @@ -135,7 +135,7 @@ All types of methods on this plugin:
| [`queryArtists`](#queryartists) | `(SortType, OrderType, UriType, RequestPermission)` | `List<ArtistModel>` | <br>
| [`queryPlaylists`](#queryplaylists) | `(SortType, OrderType, UriType, RequestPermission)` | `List<PlaylistModel>` | <br>
| [`queryGenres`](#querygenres) | `(SortType, OrderType, UriType, RequestPermission)` | `List<GenreModel>` | <br>
| [`queryAudiosFrom`]() | `(Type, Where, RequestPermission)` | `List<SongModel>` | <br>
| [`queryAudiosFrom`](#queryaudiosfrom) | `(Type, Where, RequestPermission)` | `List<SongModel>` | <br>
| [`queryWithFilters`](#querywithfilters) | `(ArgsVal, WithFiltersType, Args, RequestPermission)` | `List<dynamic>` | <br>
| [`queryArtwork`](#queryArtwork) | `(Id, Type, Format, Size, RequestPermission)` | `Uint8List?` | <br>

Expand Down Expand Up @@ -247,7 +247,21 @@ All types of methods on this plugin:
```

Or you can use a basic and custom Widget.
**See example [QueryArtworkWidget](#artworkwidget)**
**See example [QueryArtworkWidget](#artwork-widget)**

#### queryAudiosFrom
You can use this method to 'query' the songs from any section(Album, Artist, Playlist or Genre).
```dart
someName() async {
List<SongModel> something = await _audioQuery.queryAudiosFrom(
AudiosFromType.ALBUM_ID,
albumId,
// You can also define a sortType
sortType: SongSortType.TITLE, // Default
orderType: OrderType.ASC_OR_SMALLER, // Default
);
}
```

#### queryWithFilters
```dart
Expand Down
20 changes: 17 additions & 3 deletions 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.4.2
on_audio_query: ^2.5.0
```
#### Solicitar Permissões:
Expand Down Expand Up @@ -136,7 +136,7 @@ Todos os tipos de métodos nesse plugin:
| [`queryArtists`](#queryartists) | `(SortType, OrderType, UriType, RequestPermission)` | `List<ArtistModel>` | <br>
| [`queryPlaylists`](#queryplaylists) | `(SortType, OrderType, UriType, RequestPermission)` | `List<PlaylistModel>` | <br>
| [`queryGenres`](#querygenres) | `(SortType, OrderType, UriType, RequestPermission)` | `List<GenreModel>` | <br>
| [`queryAudiosFrom`]() | `(Type, Where, RequestPermission)` | `List<SongModel>` | <br>
| [`queryAudiosFrom`](#queryaudiosfrom) | `(Type, Where, RequestPermission)` | `List<SongModel>` | <br>
| [`queryWithFilters`](#queryWithFilters) | `(ArgsVal, WithFiltersType, Args, RequestPermission)` | `List<dynamic>` | <br>
| [`queryArtwork`](#queryArtwork) | `(Id, Type, Format, Size, RequestPermission)` | `Uint8List?` | <br>

Expand Down Expand Up @@ -248,7 +248,21 @@ Todos os tipos de métodos nesse plugin:
```

Ou você pode usar um Widget básico e customizável.
**Veja o exemplo [QueryArtworkWidget](#queryartworkwidget)**
**Veja o exemplo [QueryArtworkWidget](#artwork-widget)**

#### queryAudiosFrom
Você pode usar esse método para 'pegar' as músicas de qualquer seção(Album, Artista, Playlist or Gênero).
```dart
someName() async {
List<SongModel> something = await _audioQuery.queryAudiosFrom(
AudiosFromType.ALBUM_ID,
albumId,
// Você pode também definir um tipo de classificação.
sortType: SongSortType.TITLE, // Default
orderType: OrderType.ASC_OR_SMALLER, // Default
);
}
```

#### queryWithFilters
```dart
Expand Down
4 changes: 2 additions & 2 deletions on_audio_query/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ group 'com.lucasjosino.on_audio_query'
version '1.0-SNAPSHOT'

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

dependencies {
classpath 'com.android.tools.build:gradle:7.0.2'
classpath 'com.android.tools.build:gradle:4.1.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class OnArtworksQuery : ViewModel() {
// * [1]: Album.
// * [2]: Playlist.
// * [3]: Artist.
// * [4]: Genre.
uri = checkArtworkType(call.argument<Int>("type")!!)
// Define the [type]:
type = call.argument<Int>("type")!!
Expand All @@ -81,7 +82,12 @@ class OnArtworksQuery : ViewModel() {
resultArtList = loadArt()
}

//Flutter UI will start, but, information still loading
// Sometimes android will extract a 'wrong' or 'empty' artwork. Just set as null.
if (resultArtList != null && resultArtList.isEmpty()) {
resultArtList = null
}

// Flutter UI will start, but, information still loading
result.success(resultArtList)
}
}
Expand All @@ -101,16 +107,17 @@ class OnArtworksQuery : ViewModel() {
if (Build.VERSION.SDK_INT >= 29) {
// Try / Catch to avoid problems.
try {
// If [type] is 2 or 3, we need to 'get' the first item from playlist or artist.
// If [type] is 2, 3 or 4, we need to 'get' the first item from playlist or artist.
// We'll use the first artist song to 'simulate' the artwork.
//
// Type:
// * [3]: Artist.
// * [2]: Playlist.
// * [3]: Artist.
// * [4]: Genre.
//
// Due old problems with [MethodChannel] the [id] is defined as [Number].
// Here we convert to [Long]
val query = if (type == 2 || type == 3) {
val query = if (type == 2 || type == 3 || type == 4) {
val item = helper.loadFirstItem(type, id, resolver) ?: return@withContext null
ContentUris.withAppendedId(uri, item.toLong())
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.lifecycle.viewModelScope
import com.lucasjosino.on_audio_query.OnAudioQueryPlugin
import com.lucasjosino.on_audio_query.query.helper.OnAudioHelper
import com.lucasjosino.on_audio_query.types.checkAudiosFromType
import com.lucasjosino.on_audio_query.types.sorttypes.checkSongSortType
import com.lucasjosino.on_audio_query.utils.songProjection
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
Expand All @@ -32,6 +33,7 @@ class OnAudiosFromQuery : ViewModel() {
private lateinit var context: Context
private lateinit var where: String
private lateinit var whereVal: String
private lateinit var sortType: String
private lateinit var resolver: ContentResolver

/**
Expand All @@ -54,6 +56,13 @@ class OnAudiosFromQuery : ViewModel() {
// * [5]: Genre Id
// * [6]: Playlist
val type = call.argument<Int>("type")!!
// Sort: Type and Order.
// TODO
sortType = checkSongSortType(
call.argument<Int>("sortType"),
call.argument<Int>("orderType")!!,
call.argument<Boolean>("ignoreCase")!!
)

// TODO: Add a better way to handle this query
// This will fix (for now) the problem between Android < 30 && Android > 30
Expand Down Expand Up @@ -100,7 +109,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), sortType)
// Empty list.
val songsFromList: ArrayList<MutableMap<String, Any?>> = ArrayList()

Expand Down Expand Up @@ -168,7 +177,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, sortType)
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 @@ -22,6 +22,7 @@ class OnAudiosQuery : ViewModel() {

// Main parameters
private val helper = OnAudioHelper()
private var selection: String? = null

// None of this methods can be null.
private lateinit var uri: Uri
Expand All @@ -31,6 +32,7 @@ class OnAudiosQuery : ViewModel() {
@SuppressLint("StaticFieldLeak")
private lateinit var context: Context


/**
* Method to "query" all songs.
*
Expand All @@ -39,6 +41,8 @@ class OnAudiosQuery : ViewModel() {
* * [result]
* * [call]
*/
// Ignore the [Data] deprecation because this plugin support older versions.
@Suppress("DEPRECATION")
fun querySongs(
context: Context,
result: MethodChannel.Result,
Expand All @@ -56,6 +60,11 @@ class OnAudiosQuery : ViewModel() {
// * [0]: External.
// * [1]: Internal.
uri = checkAudiosUriType(call.argument<Int>("uri")!!)
// Here we provide a custom 'path'.
if (call.argument<String>("path") != null) {
val projection = songProjection()
selection = projection[0] + " like " + "'%" + call.argument<String>("path") + "/%'"
}

// Query everything in background for a better performance.
viewModelScope.launch {
Expand All @@ -80,7 +89,7 @@ class OnAudiosQuery : ViewModel() {
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(), selection, null, sortType)
// Empty list.
val songList: ArrayList<MutableMap<String, Any?>> = ArrayList()

Expand Down
Loading

0 comments on commit cffc616

Please sign in to comment.