Skip to content

Commit

Permalink
支持在画廊上传者更新画廊后,手动更新本地已下载的旧画廊至最新版本
Browse files Browse the repository at this point in the history
Support upgrade local downloaded gallery to the latest version after gallery uploader uploading a new version
  • Loading branch information
jiangtian616 committed Apr 28, 2022
1 parent ad7600e commit 8ae9514
Show file tree
Hide file tree
Showing 12 changed files with 365 additions and 101 deletions.
139 changes: 122 additions & 17 deletions lib/src/database/database.g.dart

Large diffs are not rendered by default.

41 changes: 25 additions & 16 deletions lib/src/database/gallery_downloaded.drift
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
CREATE TABLE gallery_downloaded
(
gid INT NOT NULL PRIMARY KEY,
token TEXT NOT NULL,
title TEXT NOT NULL,
category TEXT NOT NULL,
pageCount INT NOT NULL,
galleryUrl TEXT NOT NULL,
uploader TEXT,
publishTime TEXT NOT NULL,
downloadStatusIndex INT NOT NULL,
insertTime TEXT
gid INT NOT NULL PRIMARY KEY,
token TEXT NOT NULL,
title TEXT NOT NULL,
category TEXT NOT NULL,
pageCount INT NOT NULL,
galleryUrl TEXT NOT NULL,
oldVersionGalleryUrl TEXT,
uploader TEXT,
publishTime TEXT NOT NULL,
downloadStatusIndex INT NOT NULL,
insertTime TEXT
);

CREATE TABLE image
(
url TEXT NOT NULL PRIMARY KEY,
url TEXT NOT NULL,
serialNo INT NOT NULL,
gid INT NOT NULL REFERENCES gallery_downloaded (gid),
height REAL NOT NULL,
width REAL NOT NULL,
path TEXT NOT NULL,
downloadStatusIndex INT NOT NULL
imageHash TEXT NOT NULL,
downloadStatusIndex INT NOT NULL,
PRIMARY KEY (url, gid)

);

selectGallerysWithImages:
Expand All @@ -30,6 +34,7 @@ SELECT g.gid,
category,
pageCount,
galleryUrl,
oldVersionGalleryUrl,
uploader,
publishTime,
g.downloadStatusIndex as galleryDownloadStatusIndex,
Expand All @@ -39,6 +44,7 @@ SELECT g.gid,
height,
width,
path,
imageHash,
i.downloadStatusIndex as imageDownloadStatusIndex
FROM gallery_downloaded g
left join image i on g.gid = i.gid
Expand All @@ -51,7 +57,8 @@ ORDER BY insertTime DESC;

insertGallery:
insert into gallery_downloaded
values (:gid, :token, :title, :category, :pageCount, :galleryUrl, :uploader, :publishTime, :downloadStatusIndex, :insertTime);
values (:gid, :token, :title, :category, :pageCount, :galleryUrl, :oldVersionGalleryUrl, :uploader, :publishTime,
:downloadStatusIndex, :insertTime);

deleteGallery:
delete
Expand All @@ -72,17 +79,19 @@ where gid = :gid;

insertImage:
insert into image
values (:url, :serialNo, :gid, :height, :width, :path, :downloadStatusIndex);
values (:url, :serialNo, :gid, :height, :width, :path, :imageHash, :downloadStatusIndex);

updateImage:
update image
set downloadStatusIndex = :downloadStatusIndex
where url = :url;
where gid = :gid
AND url = :url;

deleteImage:
delete
from image
where url = :url;
where gid = :gid
AND url = :url;

deleteImagesWithGid:
delete
Expand Down
4 changes: 4 additions & 0 deletions lib/src/l18n/en_US.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class en_US {
'resume': "Resume",
'pause': 'Pause',
'finished': 'Finished',
'update': 'Update',
'submit': 'Submit',
'chooseFavorite': 'Choose Favorite',
'uploader': 'Uploader',
Expand Down Expand Up @@ -114,6 +115,9 @@ class en_US {
'resample': 'Resample',
'beginToDownloadArchive': 'Begin to Download Archive',
'beginToDownloadArchiveHint': 'You can check progress at Download -> Archive',
'updateGalleryError': 'Update Gallery Error',
'thisGalleryHasANewVersion': 'This gallery has a new version',
'hasUpdated': 'Has updated',

/// comment page
'newComment': 'New Comment',
Expand Down
5 changes: 5 additions & 0 deletions lib/src/l18n/zh_CN.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class zh_CN {
'resume': "继续下载",
'pause': '暂停',
'finished': '已完成',
'update': '更新',
'submit': '提交',
'chooseFavorite': '选择收藏夹',
'uploader': '上传者',
Expand Down Expand Up @@ -114,6 +115,9 @@ class zh_CN {
'resample': '压缩',
'beginToDownloadArchive': '开始下载归档',
'beginToDownloadArchiveHint': '可在 下载 -> 归档 确认进度',
'updateGalleryError': '更新画廊失败',
'thisGalleryHasANewVersion': '该画廊有新版本',
'hasUpdated': '已更新',

/// comment page
'newComment': '新评论',
Expand Down Expand Up @@ -301,6 +305,7 @@ class zh_CN {
'restoreDownloadTasksHint': '通过下载元数据来恢复下载记录',
'restoreDownloadTasksSuccess': '恢复下载任务成功',
'restoredCount': '恢复任务数',
'removeOldGalleryAfterUpdate': '更新画廊后删除旧画廊',

/// tag namespace
'language': '语言',
Expand Down
2 changes: 2 additions & 0 deletions lib/src/model/gallery_detail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class GalleryDetail {
String torrentCount;
String torrentPageUrl;
String archivePageUrl;
String? newVersionGalleryUrl;
LinkedHashMap<String, List<GalleryTag>> fullTags;
List<GalleryComment> comments;
List<GalleryThumbnail> thumbnails;
Expand All @@ -30,6 +31,7 @@ class GalleryDetail {
required this.torrentCount,
required this.torrentPageUrl,
required this.archivePageUrl,
this.newVersionGalleryUrl,
required this.fullTags,
required this.comments,
required this.thumbnails,
Expand Down
24 changes: 23 additions & 1 deletion lib/src/model/gallery_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ class GalleryImage {
double width;

String? path;
String? imageHash;
DownloadStatus downloadStatus;

GalleryImage({
required this.url,
required this.height,
required this.width,
this.imageHash,
this.path,
this.downloadStatus = DownloadStatus.none,
});
Expand All @@ -28,6 +30,7 @@ class GalleryImage {
"url": this.url,
"height": this.height,
"width": this.width,
"imageHash": this.imageHash,
"path": this.path,
"downloadStatus": this.downloadStatus.index,
};
Expand All @@ -38,13 +41,32 @@ class GalleryImage {
url: json["url"],
height: json["height"],
width: json["width"],
imageHash: json["imageHash"],
path: json["path"],
downloadStatus: DownloadStatus.values[json["downloadStatus"]],
);
}

GalleryImage copyWith({
String? url,
double? height,
double? width,
String? imageHash,
String? path,
DownloadStatus? downloadStatus,
}) {
return GalleryImage(
url: url ?? this.url,
height: height ?? this.height,
width: width ?? this.width,
imageHash: imageHash ?? this.imageHash,
path: path ?? this.path,
downloadStatus: downloadStatus ?? this.downloadStatus,
);
}

@override
String toString() {
return 'GalleryImage{url: $url, height: $height, width: $width, path: $path, downloadStatus: $downloadStatus}';
return 'GalleryImage{url: $url, height: $height, width: $width, imageHash: $imageHash, path: $path, downloadStatus: $downloadStatus}';
}
}
2 changes: 1 addition & 1 deletion lib/src/network/eh_request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class EHRequest {

static Future<void> init() async {
_dio = Dio(BaseOptions(
connectTimeout: 5000,
connectTimeout: 6000,
receiveTimeout: 6000,
));

Expand Down
39 changes: 32 additions & 7 deletions lib/src/pages/details/details_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ class DetailsPage extends StatelessWidget {
CupertinoSliverRefreshControl(onRefresh: detailsPageLogic.handleRefresh),
_buildHeader(gallery, detailsPageState.galleryDetails, context),
_buildDetails(gallery, detailsPageState.galleryDetails),
if (detailsPageState.galleryDetails?.newVersionGalleryUrl != null)
_buildNewVersionHint(detailsPageState.galleryDetails!.newVersionGalleryUrl!),
_buildActions(gallery, detailsPageState.galleryDetails, context),
if (detailsPageState.galleryDetails?.fullTags.isNotEmpty ?? false)
_buildTags(detailsPageState.galleryDetails!.fullTags),
Expand Down Expand Up @@ -293,6 +295,26 @@ class DetailsPage extends StatelessWidget {
);
}

Widget _buildNewVersionHint(String parentGalleryUrl) {
return SliverPadding(
padding: const EdgeInsets.only(top: 24),
sliver: SliverToBoxAdapter(
child: SizedBox(
height: 50,
child: TextButton(
child: Text('thisGalleryHasANewVersion'.tr),
onPressed: () => toNamed(
Routes.details,
arguments: parentGalleryUrl,
offAllBefore: false,
preventDuplicates: false,
),
),
),
),
);
}

Widget _buildActions(Gallery gallery, GalleryDetail? galleryDetails, BuildContext context) {
int readIndexRecord = storageService.read('readIndexRecord::${detailsPageState.gallery!.gid}') ?? 0;

Expand Down Expand Up @@ -329,9 +351,11 @@ class DetailsPage extends StatelessWidget {
? 'download'.tr
: downloadProgress.downloadStatus == DownloadStatus.paused
? 'resume'.tr
: downloadProgress.downloadStatus == DownloadStatus.downloaded
? 'finished'.tr
: 'pause'.tr,
: downloadProgress.downloadStatus == DownloadStatus.downloading
? 'pause'.tr
: detailsPageState.galleryDetails?.newVersionGalleryUrl == null
? 'finished'.tr
: 'update'.tr,
style: TextStyle(fontSize: 12, color: Get.theme.appBarTheme.titleTextStyle?.color),
);
},
Expand Down Expand Up @@ -379,8 +403,9 @@ class DetailsPage extends StatelessWidget {
loadingState: detailsPageState.ratingState,
idleWidget: IconTextButton(
iconData:
gallery.hasRated && detailsPageState.galleryDetails != null ? Icons.star : Icons.star_border,
iconColor: gallery.hasRated && detailsPageState.galleryDetails != null ? Colors.red.shade700 : null,
gallery.hasRated && detailsPageState.galleryDetails != null ? Icons.star : Icons.star_border,
iconColor:
gallery.hasRated && detailsPageState.galleryDetails != null ? Colors.red.shade700 : null,
iconSize: 28,
text: Text(
gallery.hasRated ? gallery.rating.toString() : 'rating'.tr,
Expand All @@ -392,8 +417,8 @@ class DetailsPage extends StatelessWidget {
onPressed: detailsPageState.galleryDetails == null
? null
: UserSetting.hasLoggedIn()
? detailsPageLogic.handleTapRating
: detailsPageLogic.showLoginSnack,
? detailsPageLogic.handleTapRating
: detailsPageLogic.showLoginSnack,
),
errorWidgetSameWithIdle: true,
);
Expand Down
4 changes: 4 additions & 0 deletions lib/src/pages/details/details_page_logic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,10 @@ class DetailsPageLogic extends GetxController {
} else if (downloadProgress.downloadStatus == DownloadStatus.downloading) {
downloadService.pauseDownloadGallery(gallery.toGalleryDownloadedData());
toast('${'pause'.tr}${gallery.gid}', isCenter: false);
} else if (downloadProgress.downloadStatus == DownloadStatus.downloaded &&
state.galleryDetails?.newVersionGalleryUrl != null) {
downloadService.updateGallery(gallery.toGalleryDownloadedData(), state.galleryDetails!.newVersionGalleryUrl!);
toast('${'update'.tr}${gallery.gid}', isCenter: false);
}
}

Expand Down

0 comments on commit 8ae9514

Please sign in to comment.