Fix some issues
This commit is contained in:
parent
7f3ab5894b
commit
80655c61d9
7 changed files with 55 additions and 36 deletions
|
@ -95,12 +95,14 @@ class DatabaseHelper {
|
|||
.update(table, row, where: '$columnHash = ?', whereArgs: [hash]);
|
||||
}
|
||||
|
||||
Future<bool> containsPath(String path) async {
|
||||
Future<Photo> getPhotoByUrl(String url) async {
|
||||
Database db = await instance.database;
|
||||
return (await db
|
||||
.query(table, where: '$columnLocalPath =?', whereArgs: [path]))
|
||||
.length >
|
||||
0;
|
||||
var rows = await db.query(table, where: '$columnUrl =?', whereArgs: [url]);
|
||||
if (rows.length > 0) {
|
||||
return Photo.fromRow(rows[0]);
|
||||
} else {
|
||||
throw ("No cached photo");
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> containsPhotoHash(String hash) async {
|
||||
|
|
|
@ -20,10 +20,13 @@ void main() async {
|
|||
runApp(MyApp());
|
||||
await provider.refreshGalleryList();
|
||||
|
||||
provider.list[0].assetList.then((assets) {
|
||||
var photoSyncManager = PhotoSyncManager(assets);
|
||||
photoSyncManager.init();
|
||||
});
|
||||
if (provider.list.length > 0) {
|
||||
provider.list[0].assetList.then((assets) {
|
||||
init(assets);
|
||||
});
|
||||
} else {
|
||||
init(List<AssetEntity>());
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> init(List<AssetEntity> assets) async {
|
||||
|
|
|
@ -34,10 +34,10 @@ class Photo {
|
|||
var file = (await asset.originFile);
|
||||
photo.localPath = file.path;
|
||||
photo.hash = getHash(file);
|
||||
return setThumbnail(photo).then((value) => photo);
|
||||
return setThumbnail(photo);
|
||||
}
|
||||
|
||||
static Future<void> setThumbnail(Photo photo) async {
|
||||
static Future<Photo> setThumbnail(Photo photo) async {
|
||||
var externalPath = (await getApplicationDocumentsDirectory()).path;
|
||||
var thumbnailPath =
|
||||
externalPath + "/photos/thumbnails/" + photo.hash + ".thumbnail";
|
||||
|
|
|
@ -115,7 +115,7 @@ class PhotoSyncManager {
|
|||
.download(Constants.ENDPOINT + photo.url, localPath)
|
||||
.catchError(_onError);
|
||||
photo.localPath = localPath;
|
||||
Photo.setThumbnail(photo);
|
||||
await Photo.setThumbnail(photo);
|
||||
await DatabaseHelper.instance.insertPhoto(photo);
|
||||
PhotoLoader.instance.reloadPhotos();
|
||||
}
|
||||
|
|
|
@ -5,17 +5,11 @@ import 'package:myapp/core/lru_map.dart';
|
|||
import 'package:myapp/models/photo.dart';
|
||||
import 'package:share_extend/share_extend.dart';
|
||||
|
||||
class DetailPage extends StatefulWidget {
|
||||
class DetailPage extends StatelessWidget {
|
||||
final Photo photo;
|
||||
final String url;
|
||||
|
||||
const DetailPage({Key key, this.photo, this.url}) : super(key: key);
|
||||
const DetailPage(this.photo, {Key key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_DetailPageState createState() => _DetailPageState();
|
||||
}
|
||||
|
||||
class _DetailPageState extends State<DetailPage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
|
@ -25,7 +19,7 @@ class _DetailPageState extends State<DetailPage> {
|
|||
IconButton(
|
||||
icon: Icon(Icons.share),
|
||||
onPressed: () {
|
||||
ShareExtend.share(widget.photo.localPath, "image");
|
||||
ShareExtend.share(photo.localPath, "image");
|
||||
},
|
||||
)
|
||||
],
|
||||
|
@ -43,12 +37,12 @@ class _DetailPageState extends State<DetailPage> {
|
|||
onVerticalDragUpdate: (details) {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: ImageLruCache.getData(widget.photo.localPath) == null
|
||||
child: ImageLruCache.getData(photo.localPath) == null
|
||||
? Image.file(
|
||||
File(widget.photo.localPath),
|
||||
File(photo.localPath),
|
||||
filterQuality: FilterQuality.low,
|
||||
)
|
||||
: ImageLruCache.getData(widget.photo.localPath),
|
||||
: ImageLruCache.getData(photo.localPath),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,9 +2,11 @@ import 'package:flutter/material.dart';
|
|||
import 'package:myapp/db/db_helper.dart';
|
||||
import 'package:myapp/face_search_manager.dart';
|
||||
import 'package:myapp/models/face.dart';
|
||||
import 'package:myapp/models/photo.dart';
|
||||
import 'package:myapp/models/search_result.dart';
|
||||
import 'package:myapp/ui/circular_network_image_widget.dart';
|
||||
import 'package:myapp/core/constants.dart' as Constants;
|
||||
import 'package:myapp/ui/image_widget.dart';
|
||||
import 'package:myapp/ui/network_image_detail_page.dart';
|
||||
|
||||
import 'detail_page.dart';
|
||||
|
@ -42,8 +44,8 @@ class FaceSearchResultsPage extends StatelessWidget {
|
|||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
return GridView.builder(
|
||||
itemBuilder: (_, index) => _buildItem(
|
||||
context, Constants.ENDPOINT + snapshot.data[index].url),
|
||||
itemBuilder: (_, index) =>
|
||||
_buildItem(context, snapshot.data[index].url),
|
||||
itemCount: snapshot.data.length,
|
||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 4,
|
||||
|
@ -57,18 +59,38 @@ class FaceSearchResultsPage extends StatelessWidget {
|
|||
|
||||
Widget _buildItem(BuildContext context, String url) {
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
onTap: () async {
|
||||
_routeToDetailPage(url, context);
|
||||
},
|
||||
child: Container(
|
||||
margin: EdgeInsets.all(2),
|
||||
child: Image.network(url, height: 124, width: 124, fit: BoxFit.cover),
|
||||
),
|
||||
child: _getImage(url),
|
||||
);
|
||||
}
|
||||
|
||||
void _routeToDetailPage(String url, BuildContext context) {
|
||||
final page = NetworkImageDetailPage(url);
|
||||
Widget _getImage(String url) {
|
||||
return FutureBuilder<Photo>(
|
||||
future: DatabaseHelper.instance.getPhotoByUrl(url),
|
||||
builder: (_, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
return ImageWidget(path: snapshot.data.thumbnailPath);
|
||||
} else if (snapshot.hasError) {
|
||||
return Container(
|
||||
margin: EdgeInsets.all(2),
|
||||
child: Image.network(Constants.ENDPOINT + url,
|
||||
height: 124, width: 124, fit: BoxFit.cover),
|
||||
);
|
||||
} else {
|
||||
return Text("Loading...");
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void _routeToDetailPage(String url, BuildContext context) async {
|
||||
Widget page = NetworkImageDetailPage(url);
|
||||
var photo = await DatabaseHelper.instance.getPhotoByUrl(url);
|
||||
if (photo != null) {
|
||||
page = DetailPage(photo);
|
||||
}
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (BuildContext context) {
|
||||
|
|
|
@ -74,9 +74,7 @@ class _GalleryState extends State<Gallery> {
|
|||
}
|
||||
|
||||
void routeToDetailPage(Photo photo, BuildContext context) {
|
||||
final page = DetailPage(
|
||||
photo: photo,
|
||||
);
|
||||
final page = DetailPage(photo);
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (BuildContext context) {
|
||||
|
|
Loading…
Reference in a new issue