Skip to content

Commit

Permalink
Merge pull request #225 from CaiJingLong/filter-option-change
Browse files Browse the repository at this point in the history
Filter option change
  • Loading branch information
CaiJingLong authored Mar 23, 2020
2 parents 7117d21 + b1a749e commit 3a06b2d
Show file tree
Hide file tree
Showing 20 changed files with 485 additions and 322 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ Feature:
- Add `orientation` for `AssetEntity`.
- Add `onlyAll` for `getAssetPathList`.
- Support audio type(Only android, iOS Photos have no audio)
- **Breaking change**, Add date condition to filter datetime
- Add class `DateTimeCond`
- Add `dateTimeCond` to `FilterOptionGroup`
- Remove `fetchDateTime` from `getAssetPathList`
- Remove param `dt` from `AssetPathEntity.refreshPathProperties`, and add `refreshPathProperties` params to the method.

Update

Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ A flutter api for photo, you can get image/video from ios or android.

If you just need a picture selector, you can choose to use [photo](https://pub.dartlang.org/packages/photo) library , a multi image picker. All UI create by flutter.

- [photo_manager](#photo_manager)
- [photo_manager](#photomanager)
- [install](#install)
- [Add to pubspec](#add-to-pubspec)
- [import in dart code](#import-in-dart-code)
Expand Down Expand Up @@ -78,12 +78,11 @@ if (result) {
List<AssetPathEntity> list = await PhotoManager.getAssetPathList();
```

| name | description |
| ------------- | --------------------------------------------------------------------------------------------- |
| hasAll | Is there an album containing "all" |
| type | image/video/all , default all. |
| fetchDateTime | Only include resources older than that time.(Will be included in filterOption in the future.) |
| fliterOption | See FilterOption. |
| name | description |
| ------------ | ---------------------------------- |
| hasAll | Is there an album containing "all" |
| type | image/video/all , default all. |
| fliterOption | See FilterOption. |

#### FilterOption

Expand All @@ -92,6 +91,7 @@ List<AssetPathEntity> list = await PhotoManager.getAssetPathList();
| needTitle | The title attribute of the picture must be included in android (even if it is false), it is more performance-consuming in iOS, please consider whether you need it. The default is false. |
| sizeConstraint | Constraints on resource size. |
| durationConstraint | Constraints of time, pictures will ignore this constraint. |
| dateTimeCond | Includes date filtering and date sorting |

Example see [filter_option_page.dart](https://github.com/CaiJingLong/flutter_photo_manager/blob/filter-option/example/lib/page/filter_option_page.dart).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,57 +6,61 @@ import top.kikt.imagescanner.AssetType
import top.kikt.imagescanner.core.utils.ConvertUtils

class FilterOption(map: Map<*, *>) {

val videoOption = ConvertUtils.getOptionFromType(map, AssetType.Video)
val imageOption = ConvertUtils.getOptionFromType(map, AssetType.Image)
val audioOption = ConvertUtils.getOptionFromType(map, AssetType.Audio)

val dateCond = ConvertUtils.convertToDateCond(map["date"] as Map<*, *>)
}

class FilterCond {
var isShowTitle = false
lateinit var sizeConstraint: SizeConstraint
lateinit var durationConstraint: DurationConstraint

companion object {
private const val widthKey = MediaStore.Files.FileColumns.WIDTH
private const val heightKey = MediaStore.Files.FileColumns.HEIGHT
@SuppressLint("InlinedApi")
private const val durationKey = MediaStore.Video.VideoColumns.DURATION
}

fun sizeCond(): String {

return "$widthKey >= ? AND $widthKey <= ? AND $heightKey >= ? AND $heightKey <=?"
}

fun sizeArgs(): Array<String> {
return arrayOf(sizeConstraint.minWidth, sizeConstraint.maxWidth, sizeConstraint.minHeight, sizeConstraint.maxHeight).toList().map {
it.toString()
}.toTypedArray()
}

fun durationCond(): String {
return "$durationKey >=? AND $durationKey <=?"
}

fun durationArgs(): Array<String> {
return arrayOf(durationConstraint.min, durationConstraint.max).toList().map {
it.toString()
}.toTypedArray()
}

class SizeConstraint {
var minWidth = 0
var maxWidth = 0
var minHeight = 0
var maxHeight = 0

}

class DurationConstraint {
var min: Long = 0
var max: Long = 0

}
}
}

data class DateCond(
val minMs: Long, val maxMs: Long, val asc: Boolean
)
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ object AndroidQDBUtils : IDBUtils {
val args = ArrayList<String>()
val typeSelection: String = getCondFromType(requestType, option, args)

val dateSelection = "AND ${MediaStore.MediaColumns.DATE_ADDED} <= ?"
args.add(timeStamp.toString())
val dateSelection = getDateCond(args, timeStamp, option)

val sizeWhere = sizeWhere(requestType)

Expand Down Expand Up @@ -87,8 +86,7 @@ object AndroidQDBUtils : IDBUtils {
val args = ArrayList<String>()
val typeSelection: String = getCondFromType(requestType, option, args)

val dateSelection = "AND ${MediaStore.MediaColumns.DATE_ADDED} <= ?"
args.add(timeStamp.toString())
val dateSelection = getDateCond(args, timeStamp, option)

val sizeWhere = sizeWhere(requestType)

Expand Down Expand Up @@ -123,8 +121,7 @@ object AndroidQDBUtils : IDBUtils {

val sizeWhere = sizeWhere(requestType)

val dateSelection = "AND ${MediaStore.Images.Media.DATE_ADDED} <= ?"
args.add(timeStamp.toString())
val dateSelection = getDateCond(args, timeStamp, option)

val keys = (IDBUtils.storeImageKeys + IDBUtils.storeVideoKeys + IDBUtils.typeKeys).distinct().toTypedArray()
val selection = if (isAll) {
Expand All @@ -133,7 +130,7 @@ object AndroidQDBUtils : IDBUtils {
"${MediaStore.Images.ImageColumns.BUCKET_ID} = ? $typeSelection $dateSelection $sizeWhere"
}

val sortOrder = "${MediaStore.Images.Media.DATE_TAKEN} DESC LIMIT $pageSize OFFSET ${page * pageSize}"
val sortOrder = getSortOrder(page * pageSize, pageSize, option)
val cursor = context.contentResolver.query(uri, keys, selection, args.toTypedArray(), sortOrder)
?: return emptyList()

Expand Down Expand Up @@ -165,8 +162,7 @@ object AndroidQDBUtils : IDBUtils {

val sizeWhere = sizeWhere(requestType)

val dateSelection = "AND ${MediaStore.Images.Media.DATE_ADDED} <= ?"
args.add(timestamp.toString())
val dateSelection = getDateCond(args, timestamp, option)

val keys = (IDBUtils.storeImageKeys + IDBUtils.storeVideoKeys + IDBUtils.typeKeys).distinct().toTypedArray()
val selection = if (isAll) {
Expand All @@ -177,7 +173,7 @@ object AndroidQDBUtils : IDBUtils {

val pageSize = end - start

val sortOrder = "${MediaStore.Images.Media.DATE_TAKEN} DESC LIMIT $pageSize OFFSET $start"
val sortOrder = getSortOrder(start, pageSize, option)
val cursor = context.contentResolver.query(uri, keys, selection, args.toTypedArray(), sortOrder)
?: return emptyList()

Expand Down Expand Up @@ -246,8 +242,7 @@ object AndroidQDBUtils : IDBUtils {
val args = ArrayList<String>()
val typeSelection: String = getCondFromType(type, option, args)

val dateSelection = "AND ${MediaStore.MediaColumns.DATE_ADDED} <= ?"
args.add(timeStamp.toString())
val dateSelection = getDateCond(args, timeStamp, option)

val idSelection: String
if (isAll) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package top.kikt.imagescanner.core.utils

import top.kikt.imagescanner.AssetType
import top.kikt.imagescanner.core.entity.AssetEntity
import top.kikt.imagescanner.core.entity.FilterCond
import top.kikt.imagescanner.core.entity.FilterOption
import top.kikt.imagescanner.core.entity.GalleryEntity
import top.kikt.imagescanner.core.entity.*

/// create 2019-09-05 by cai
Expand Down Expand Up @@ -118,6 +115,12 @@ object ConvertUtils {
return filterOptions
}

fun convertToDateCond(map: Map<*, *>): DateCond {
val min = map["min"].toString().toLong()
val max = map["max"].toString().toLong()
val asc = map["asc"].toString().toBoolean()
return DateCond(min, max, asc)
}

fun convertFilterOptionsFromMap(map: Map<*, *>): FilterOption {
return FilterOption(map)
Expand Down
Loading

0 comments on commit 3a06b2d

Please sign in to comment.