Skip to content
This repository has been archived by the owner on Sep 23, 2021. It is now read-only.

Commit

Permalink
update 0.1.0 version
Browse files Browse the repository at this point in the history
  • Loading branch information
CaiJingLong committed Oct 11, 2018
1 parent c043f51 commit 412e5b7
Show file tree
Hide file tree
Showing 14 changed files with 71 additions and 59 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# CHANGELOG

## [0.1.0] support video
API incompatibility

ImageXXX rename AssetXXX

## [0.0.8] fix bug
DefaultCheckBoxBuilderDelegate params checkColor not valid bug

Expand Down
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@ if you want to build custom ui, you just need api to make custom ui. to use [pho

![image](https://github.com/CaiJingLong/some_asset/blob/master/image_picker1.gif)

## API incompatibility
API incompatibility

because support video, so the ImagePathEntity and ImageEntity rename to AssetPathEntity and AssetEntity.

so PhotoPicker.pickImage return type will change to List<AssetEntity>

## install

```yaml
dependencies:
photo: ^0.0.8
photo: ^0.1.0
```
## import
Expand All @@ -31,7 +38,7 @@ import 'package:photo_manager/photo_manager.dart';

```dart
void _pickImage() async {
List<ImageEntity> imgList = await PhotoPicker.pickImage(
List<AssetEntity> imgList = await PhotoPicker.pickImage(
context: context, // BuildContext requied
/// The following are optional parameters.
Expand Down
2 changes: 1 addition & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class _MyHomePageState extends State<MyHomePage> {
String currentSelected = "";

void _pickImage() async {
List<ImageEntity> imgList = await PhotoPicker.pickImage(
List<AssetEntity> imgList = await PhotoPicker.pickImage(
context: context, // BuildContext requied

/// The following are optional parameters.
Expand Down
10 changes: 5 additions & 5 deletions lib/photo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class PhotoPicker {
///
/// 当用户给予权限后
///
/// 当用户确定时,返回一个图片[ImageEntity]列表
/// 当用户确定时,返回一个图片[AssetEntity]列表
///
/// 当用户取消时
///
Expand All @@ -44,10 +44,10 @@ class PhotoPicker {
///
/// when user give permission.
///
/// when user sure , return a [ImageEntity] of [List]
/// when user sure , return a [AssetEntity] of [List]
///
/// when user cancel selected,result is empty list
static Future<List<ImageEntity>> pickImage({
static Future<List<AssetEntity>> pickImage({
@required BuildContext context,
int rowCount = 4,
int maxSelected = 9,
Expand Down Expand Up @@ -94,7 +94,7 @@ class PhotoPicker {
);
}

Future<List<ImageEntity>> _pickImage(
Future<List<AssetEntity>> _pickImage(
BuildContext context,
Options options,
I18nProvider provider,
Expand All @@ -116,7 +116,7 @@ class PhotoPicker {
return _openGalleryContentPage(context, options, provider);
}

Future<List<ImageEntity>> _openGalleryContentPage(
Future<List<AssetEntity>> _openGalleryContentPage(
BuildContext context, Options options, I18nProvider provider) async {
return Navigator.of(context).push(
MaterialPageRoute(
Expand Down
16 changes: 8 additions & 8 deletions lib/src/delegate/sort_delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:photo_manager/photo_manager.dart';
abstract class SortDelegate {
const SortDelegate();

void sort(List<ImagePathEntity> list);
void sort(List<AssetPathEntity> list);

static const none = DefaultSortDelegate();

Expand All @@ -14,20 +14,20 @@ class DefaultSortDelegate extends SortDelegate {
const DefaultSortDelegate();

@override
void sort(List<ImagePathEntity> list) {}
void sort(List<AssetPathEntity> list) {}
}

class CommonSortDelegate extends SortDelegate {
const CommonSortDelegate();

@override
void sort(List<ImagePathEntity> list) {
void sort(List<AssetPathEntity> list) {
list.sort((path1, path2) {
if (path1 == ImagePathEntity.all) {
if (path1 == AssetPathEntity.all) {
return -1;
}

if (path2 == ImagePathEntity.all) {
if (path2 == AssetPathEntity.all) {
return 1;
}

Expand All @@ -51,15 +51,15 @@ class CommonSortDelegate extends SortDelegate {
});
}

int otherSort(ImagePathEntity path1, ImagePathEntity path2) {
int otherSort(AssetPathEntity path1, AssetPathEntity path2) {
return path1.name.compareTo(path2.name);
}

bool _isCamera(ImagePathEntity entity) {
bool _isCamera(AssetPathEntity entity) {
return entity.name.toUpperCase() == "camera".toUpperCase();
}

bool _isScreenShot(ImagePathEntity entity) {
bool _isScreenShot(AssetPathEntity entity) {
return entity.name.toUpperCase() == "screenshots".toUpperCase() ||
entity.name.toUpperCase() == "screenshot".toUpperCase();
}
Expand Down
6 changes: 3 additions & 3 deletions lib/src/engine/lru_cache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import 'package:photo_manager/photo_manager.dart';
class ImageLruCache {
static LRUMap<_ImageCacheEntity, Uint8List> _map = LRUMap(500);

static Uint8List getData(ImageEntity entity, [int size = 64]) {
static Uint8List getData(AssetEntity entity, [int size = 64]) {
return _map.get(_ImageCacheEntity(entity, size));
}

static void setData(ImageEntity entity, int size, Uint8List list) {
static void setData(AssetEntity entity, int size, Uint8List list) {
_map.put(_ImageCacheEntity(entity, size), list);
}
}

class _ImageCacheEntity {
ImageEntity entity;
AssetEntity entity;
int size;

_ImageCacheEntity(this.entity, this.size);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/provider/gallery_list_provider.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:photo_manager/photo_manager.dart';

abstract class GalleryListProvider {
List<ImagePathEntity> galleryPathList = [];
List<AssetPathEntity> galleryPathList = [];
}
12 changes: 6 additions & 6 deletions lib/src/provider/selected_provider.dart
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import 'package:photo_manager/photo_manager.dart';

abstract class SelectedProvider {
List<ImageEntity> selectedList = [];
List<AssetEntity> selectedList = [];

int get selectedCount => selectedList.length;

bool containsEntity(ImageEntity entity) {
bool containsEntity(AssetEntity entity) {
return selectedList.contains(entity);
}

int indexOfSelected(ImageEntity entity) {
int indexOfSelected(AssetEntity entity) {
return selectedList.indexOf(entity);
}

bool isUpperLimit();

bool addSelectEntity(ImageEntity entity) {
bool addSelectEntity(AssetEntity entity) {
if (containsEntity(entity)) {
return false;
}
Expand All @@ -26,11 +26,11 @@ abstract class SelectedProvider {
return true;
}

bool removeSelectEntity(ImageEntity entity) {
bool removeSelectEntity(AssetEntity entity) {
return selectedList.remove(entity);
}

void compareAndRemoveEntities(List<ImageEntity> previewSelectedList) {
void compareAndRemoveEntities(List<AssetEntity> previewSelectedList) {
var srcList = List.of(selectedList);
selectedList.clear();
srcList.forEach((entity) {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/ui/dialog/change_gallery_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
import 'package:photo_manager/photo_manager.dart';

class ChangeGalleryDialog extends StatefulWidget {
final List<ImagePathEntity> galleryList;
final List<AssetPathEntity> galleryList;

const ChangeGalleryDialog({Key key, this.galleryList}) : super(key: key);

Expand Down
34 changes: 17 additions & 17 deletions lib/src/ui/page/photo_main_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import 'package:photo/src/ui/page/photo_preview_page.dart';
import 'package:photo_manager/photo_manager.dart';

class PhotoMainPage extends StatefulWidget {
final ValueChanged<List<ImageEntity>> onClose;
final ValueChanged<List<AssetEntity>> onClose;

const PhotoMainPage({
Key key,
Expand All @@ -29,22 +29,22 @@ class _PhotoMainPageState extends State<PhotoMainPage>

I18nProvider get i18nProvider => ConfigProvider.of(context).provider;

List<ImageEntity> list = [];
List<AssetEntity> list = [];

Color get themeColor => options.themeColor;

ImagePathEntity _currentPath = ImagePathEntity.all;
AssetPathEntity _currentPath = AssetPathEntity.all;

bool _isInit = false;

ImagePathEntity get currentPath {
AssetPathEntity get currentPath {
if (_currentPath == null) {
return null;
}
return _currentPath;
}

set currentPath(ImagePathEntity value) {
set currentPath(AssetPathEntity value) {
_currentPath = value;
}

Expand Down Expand Up @@ -151,14 +151,14 @@ class _PhotoMainPageState extends State<PhotoMainPage>
}

void _refreshList() async {
var pathList = await PhotoManager.getImagePathList();
var pathList = await PhotoManager.getAssetPathList();

options.sortDelegate.sort(pathList);

galleryPathList.clear();
galleryPathList.addAll(pathList);

var imageList = await currentPath.imageList;
var imageList = await currentPath.assetList;
this.list.clear();
this.list.addAll(imageList);
setState(() {
Expand Down Expand Up @@ -214,7 +214,7 @@ class _PhotoMainPageState extends State<PhotoMainPage>
);
}

Widget _buildSelected(ImageEntity entity) {
Widget _buildSelected(AssetEntity entity) {
var currentSelected = containsEntity(entity);
return Positioned(
right: 0.0,
Expand All @@ -230,7 +230,7 @@ class _PhotoMainPageState extends State<PhotoMainPage>
);
}

Widget _buildText(ImageEntity entity) {
Widget _buildText(AssetEntity entity) {
var isSelected = containsEntity(entity);
Widget child;
BoxDecoration decoration;
Expand Down Expand Up @@ -263,7 +263,7 @@ class _PhotoMainPageState extends State<PhotoMainPage>
);
}

void changeCheck(bool value, ImageEntity entity) {
void changeCheck(bool value, AssetEntity entity) {
if (value) {
addSelectEntity(entity);
} else {
Expand All @@ -272,18 +272,18 @@ class _PhotoMainPageState extends State<PhotoMainPage>
setState(() {});
}

void _onGalleryChange(ImagePathEntity value) {
void _onGalleryChange(AssetPathEntity value) {
_currentPath = value;

_currentPath.imageList.then((v) {
_currentPath.assetList.then((v) {
list.clear();
list.addAll(v);
scrollController.jumpTo(0.0);
setState(() {});
});
}

void _onItemClick(ImageEntity data, int index) {
void _onItemClick(AssetEntity data, int index) {
var result = new PhotoPreviewResult();
isPushed = true;
Navigator.of(context).push(
Expand Down Expand Up @@ -343,11 +343,11 @@ class _PhotoMainPageState extends State<PhotoMainPage>
);
}

bool handlePreviewResult(List<ImageEntity> v) {
bool handlePreviewResult(List<AssetEntity> v) {
if (v == null) {
return false;
}
if (v is List<ImageEntity>) {
if (v is List<AssetEntity>) {
return true;
}
return false;
Expand Down Expand Up @@ -383,7 +383,7 @@ class _PhotoMainPageState extends State<PhotoMainPage>
}

class _BottomWidget extends StatefulWidget {
final ValueChanged<ImagePathEntity> onGalleryChange;
final ValueChanged<AssetPathEntity> onGalleryChange;

final Options options;

Expand Down Expand Up @@ -481,7 +481,7 @@ class __BottomWidgetState extends State<_BottomWidget> {
}

class ImageItem extends StatelessWidget {
final ImageEntity entity;
final AssetEntity entity;

final Color themeColor;

Expand Down
Loading

0 comments on commit 412e5b7

Please sign in to comment.