Skip to content

Commit

Permalink
Merge pull request #394 from project-violet/adv-table-ui
Browse files Browse the repository at this point in the history
Advance tablet ui 2
  • Loading branch information
violet-dev committed Feb 9, 2024
2 parents 58f8700 + 3100155 commit 7917e7b
Show file tree
Hide file tree
Showing 16 changed files with 117 additions and 58 deletions.
1 change: 1 addition & 0 deletions assets/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@
"changedthread": "Number of Threads have changed!",
"exportlog": "Export Log Record",
"thumbnailslidersize": "Thumbnail Slider Size",
"verylarge": "Very Large",
"large": "Large",
"middle": "Middle",
"small": "Small",
Expand Down
1 change: 1 addition & 0 deletions assets/locale/eo.json
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@
"changedthread": "Number of Threads have changed!",
"exportlog": "Export Log Record",
"thumbnailslidersize": "Thumbnail Slider Size",
"verylarge": "Very Large",
"large": "Large",
"middle": "Middle",
"small": "Small",
Expand Down
1 change: 1 addition & 0 deletions assets/locale/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@
"changedthread": "Number of Threads have changed!",
"exportlog": "Export Log Record",
"thumbnailslidersize": "Thumbnail Slider Size",
"verylarge": "Very Large",
"large": "Large",
"middle": "Middle",
"small": "Small",
Expand Down
1 change: 1 addition & 0 deletions assets/locale/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@
"changedthread": "Number of Threads have changed!",
"exportlog": "Export Log Record",
"thumbnailslidersize": "Thumbnail Slider Size",
"verylarge": "Very Large",
"large": "Large",
"middle": "Middle",
"small": "Small",
Expand Down
1 change: 1 addition & 0 deletions assets/locale/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@
"changedthread": "스레드 개수를 변경했습니다!",
"exportlog": "로그 기록 내보내기",
"thumbnailslidersize": "썸네일 슬라이드 크기",
"verylarge": "매우 크게",
"large": "크게",
"middle": "중간",
"small": "작게",
Expand Down
1 change: 1 addition & 0 deletions assets/locale/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@
"changedthread": "O número de processos mudou!",
"exportlog": "Exportar registro de log",
"thumbnailslidersize": "Tamanho da miniatura do controle deslizante",
"verylarge": "Venti",
"large": "Grande",
"middle": "Médio",
"small": "Pequeno",
Expand Down
1 change: 1 addition & 0 deletions assets/locale/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@
"changedthread": "Number of Threads have changed!",
"exportlog": "Export Log Record",
"thumbnailslidersize": "Thumbnail Slider Size",
"verylarge": "Very Large",
"large": "Large",
"middle": "Middle",
"small": "Small",
Expand Down
1 change: 1 addition & 0 deletions assets/locale/zh_Hans.json
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@
"changedthread": "Number of Threads have changed!",
"exportlog": "Export Log Record",
"thumbnailslidersize": "Thumbnail Slider Size",
"verylarge": "Very Large",
"large": "Large",
"middle": "Middle",
"small": "Small",
Expand Down
1 change: 1 addition & 0 deletions assets/locale/zh_Hant.json
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@
"changedthread": "Number of Threads have changed!",
"exportlog": "Export Log Record",
"thumbnailslidersize": "Thumbnail Slider Size",
"verylarge": "Very Large",
"large": "Large",
"middle": "Middle",
"small": "Small",
Expand Down
12 changes: 8 additions & 4 deletions lib/pages/artist_info/artist_info_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -463,14 +463,16 @@ class _ArtistInfoPageState extends State<ArtistInfoPage> {

Widget queryResult() {
final width = MediaQuery.of(context).size.width;
var axis1 = charts.AxisSpec<String>(
final maxItemCount =
MediaQuery.of(context).orientation == Orientation.landscape ? 8 : 6;
final axis1 = charts.AxisSpec<String>(
renderSpec: charts.GridlineRendererSpec(
labelStyle: charts.TextStyleSpec(
fontSize: isExpanded ? 10 : 14,
color: charts.MaterialPalette.white),
lineStyle: const charts.LineStyleSpec(
color: charts.MaterialPalette.transparent)));
var axis2 = const charts.NumericAxisSpec(
const axis2 = charts.NumericAxisSpec(
renderSpec: charts.GridlineRendererSpec(
labelStyle: charts.TextStyleSpec(
fontSize: 10, color: charts.MaterialPalette.white),
Expand Down Expand Up @@ -566,7 +568,7 @@ class _ArtistInfoPageState extends State<ArtistInfoPage> {
expanded: Column(children: <Widget>[
articleArea(),
Visibility(
visible: cc.length > 6,
visible: cc.length > maxItemCount,
child: more(() => ArticleListPage(
cc: cc,
name: (widget.isGroup
Expand Down Expand Up @@ -713,14 +715,16 @@ class _ArtistInfoPageState extends State<ArtistInfoPage> {
final windowWidth = MediaQuery.of(context).size.width;
final columnCount =
MediaQuery.of(context).orientation == Orientation.landscape ? 4 : 3;
final maxItemCount =
MediaQuery.of(context).orientation == Orientation.landscape ? 8 : 6;
return LiveGrid(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
padding: const EdgeInsets.fromLTRB(16, 8, 16, 16),
showItemInterval: const Duration(milliseconds: 50),
showItemDuration: const Duration(milliseconds: 150),
visibleFraction: 0.001,
itemCount: min(cc.length, 6),
itemCount: min(cc.length, maxItemCount),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: columnCount,
crossAxisSpacing: 8,
Expand Down
121 changes: 81 additions & 40 deletions lib/pages/download/download_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:intl/intl.dart';
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
import 'package:path_provider/path_provider.dart';
import 'package:permission_handler/permission_handler.dart';
Expand Down Expand Up @@ -285,7 +286,16 @@ class _DownloadPageState extends ThemeSwitchableState<DownloadPage>

if (Settings.downloadResultType == 0 || Settings.downloadResultType == 1) {
if (Settings.downloadAlignType != 0 && Settings.downloadResultType == 0) {
return _panelGroupBy();
return FutureBuilder(
future: getGroupBy(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return const SliverToBoxAdapter(child: SizedBox.shrink());
}

return _panelGroupBy(snapshot.data!);
},
);
}

var mm = Settings.downloadResultType == 0 ? 3 : 2;
Expand Down Expand Up @@ -405,7 +415,29 @@ class _DownloadPageState extends ThemeSwitchableState<DownloadPage>
throw Exception('unreachable');
}

List<(String, List<DownloadItemModel>)> getGroupBy() {
Future<List<(String, List<DownloadItemModel>)>> getGroupBy() async {
final user = await User.getInstance();
final userlog = await user.getUserLog();
final articlereadlog = <int, DateTime>{};

for (var element in userlog) {
final id = int.tryParse(element.articleId());
if (id == null) {
Logger.warning(
'[download-_applyFilter] articleId is not int type: ${element.articleId()}');
continue;
}
if (!articlereadlog.containsKey(id)) {
final dt = DateTime.tryParse(element.datetimeStart());
if (dt != null) {
articlereadlog[id] = dt;
} else {
Logger.warning(
'[download-_applyFilter] datetimeStart is not DateTime type: ${element.datetimeStart()}');
}
}
}

final groups = filterResult.groupListsBy((e) {
final qr = queryResults[int.tryParse(e.url()) ?? -1];
if (qr == null) return 'none';
Expand All @@ -424,17 +456,30 @@ class _DownloadPageState extends ThemeSwitchableState<DownloadPage>
return getFirst(qr.groups());

case 3: // page
final pageGroup = e.filesWithoutThumbnail().length ~/ 10;
return '${pageGroup * 10} ~ ${(pageGroup + 1) * 10} Page';

case 4: // datetime recent
return getFirst(qr.groups());
if (!articlereadlog.containsKey(qr.id())) {
final downoadDateTime = DateTime.parse(e.dateTime()!);
return DateFormat('yyyy.MM.dd').format(downoadDateTime);
}
return DateFormat('yyyy.MM.dd').format(articlereadlog[qr.id()]!);

default:
throw Exception('unrechable');
}
});

final groupsSorted = groups.entries.map((e) => (e.key, e.value)).toList()
var groupsSorted = groups.entries.map((e) => (e.key, e.value)).toList()
..sortBy((e) => e.$1);

final reverseOrder =
Settings.downloadAlignType == 3 || Settings.downloadAlignType == 4;
if (reverseOrder) {
groupsSorted = groupsSorted.reversed.toList();
}

return groupsSorted;
}

Expand Down Expand Up @@ -475,13 +520,13 @@ class _DownloadPageState extends ThemeSwitchableState<DownloadPage>
// updateHeights();
}

void _indexChanged() {
Future<void> _indexChanged() async {
final details = indexBarDragListener.dragDetails.value;
if (details.action == IndexBarDragDetails.actionDown ||
details.action == IndexBarDragDetails.actionUpdate) {
final tag = details.tag!;

final groupBy = getGroupBy();
final groupBy = await getGroupBy();

// TODO: More optimize
final headerCount =
Expand Down Expand Up @@ -515,46 +560,42 @@ class _DownloadPageState extends ThemeSwitchableState<DownloadPage>
Widget indexBar() {
return Align(
alignment: Alignment.centerRight,
child: IndexBar(
// data: widget.indexBarData,
data: getGroupBy().map((e) => e.$1[0].toUpperCase()).toSet().toList(),
// options: const IndexBarOptions(
// needRebuild: true,
// color: Colors.transparent,
// ),
indexBarDragListener: indexBarDragListener,
// height: widget.indexBarHeight,
// itemHeight: widget.indexBarItemHeight,
// margin: widget.indexBarMargin,
// indexHintBuilder: widget.indexHintBuilder,
// indexBarDragListener: dragListener,
// options: widget.indexBarOptions,
// controller: indexBarController,
options: const IndexBarOptions(
needRebuild: true,
selectTextStyle: TextStyle(
fontSize: 12, color: Colors.white, fontWeight: FontWeight.w500),
selectItemDecoration:
BoxDecoration(shape: BoxShape.circle, color: Color(0xFF333333)),
// indexHintWidth: 96,
// indexHintHeight: 97,
// indexHintAlignment: Alignment.centerRight,
// indexHintTextStyle:
// TextStyle(fontSize: 24.0, color: Colors.black87),
// indexHintOffset: Offset(-30, 0),
),
child: FutureBuilder(
future: getGroupBy(),
builder: (context, snapshot) {
if (!snapshot.hasData) return Container();

return IndexBar(
data: snapshot.data!
.map((e) => e.$1[0].toUpperCase())
.toSet()
.toList(),
indexBarDragListener: indexBarDragListener,
options: const IndexBarOptions(
needRebuild: true,
selectTextStyle: TextStyle(
fontSize: 12,
color: Colors.white,
fontWeight: FontWeight.w500),
selectItemDecoration: BoxDecoration(
shape: BoxShape.circle, color: Color(0xFF333333)),
),
);
},
),
);
}

Widget _panelGroupBy() {
var windowWidth = lastWindowWidth = MediaQuery.of(context).size.width;
var mm = Settings.downloadResultType == 0 ? 3 : 2;
Widget _panelGroupBy(List<(String, List<DownloadItemModel>)> groupBy) {
final windowWidth = lastWindowWidth = MediaQuery.of(context).size.width;
final columnCount = Settings.downloadResultType == 0 ? 3 : 2;
final effectiveColumnCount =
Settings.useTabletMode ? columnCount * 2 : columnCount;

heightRefHeader = null;
heightRefArticle = null;

final groupsWidget = getGroupBy().map((e) {
final groupsWidget = groupBy.map((e) {
final title = Container(
key: heightRefHeader == null ? heightRefHeader ??= GlobalKey() : null,
padding: const EdgeInsets.fromLTRB(8, 8, 8, 8),
Expand Down Expand Up @@ -614,7 +655,7 @@ class _DownloadPageState extends ThemeSwitchableState<DownloadPage>
padding: const EdgeInsets.fromLTRB(8, 4, 8, 16),
shrinkWrap: true,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: Settings.useTabletMode ? mm * 2 : mm,
crossAxisCount: effectiveColumnCount,
crossAxisSpacing: 8,
mainAxisSpacing: 8,
childAspectRatio: 3 / 4,
Expand All @@ -633,7 +674,7 @@ class _DownloadPageState extends ThemeSwitchableState<DownloadPage>
initialStyle: DownloadListItem(
showDetail: false,
addBottomPadding: false,
width: (windowWidth - 4.0) / mm,
width: (windowWidth - 4.0) / effectiveColumnCount,
),
item: e,
download: e.download,
Expand Down
12 changes: 5 additions & 7 deletions lib/pages/search/search_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -571,18 +571,20 @@ class ResultPanelWidget extends StatelessWidget {

@override
Widget build(BuildContext context) {
final mm = Settings.searchResultType == 0 ? 3 : 2;
final columnCount = Settings.searchResultType == 0 ? 3 : 2;
final windowWidth = MediaQuery.of(context).size.width;

switch (Settings.searchResultType) {
case 0:
case 1:
final simpleModeColumnCount =
Settings.useTabletMode ? columnCount * 2 : columnCount;
return SliverPadding(
padding: const EdgeInsets.fromLTRB(8, 0, 8, 16),
sliver: SliverGrid(
key: sliverKey,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: Settings.useTabletMode ? mm * 2 : mm,
crossAxisCount: simpleModeColumnCount,
crossAxisSpacing: 8,
mainAxisSpacing: 8,
childAspectRatio: 3 / 4,
Expand All @@ -591,9 +593,8 @@ class ResultPanelWidget extends StatelessWidget {
(BuildContext context, int index) {
return articleItem(
index,
mm,
windowWidth,
(windowWidth - 4.0) / mm,
(windowWidth - 4.0) / simpleModeColumnCount,
alignment: Alignment.bottomCenter,
);
},
Expand Down Expand Up @@ -631,7 +632,6 @@ class ResultPanelWidget extends StatelessWidget {
itemBuilder: (context, index, animation) {
return articleItem(
index,
mm,
windowWidth,
(windowWidth - 4.0) / kDetailModeColumnCount,
showDetail: Settings.searchResultType >= 3,
Expand All @@ -648,7 +648,6 @@ class ResultPanelWidget extends StatelessWidget {
(BuildContext context, int index) {
return articleItem(
index,
mm,
windowWidth,
windowWidth - 4.0,
showDetail: Settings.searchResultType >= 3,
Expand All @@ -669,7 +668,6 @@ class ResultPanelWidget extends StatelessWidget {

articleItem(
int index,
int mm,
double windowWidth,
double width, {
bool showDetail = false,
Expand Down
9 changes: 7 additions & 2 deletions lib/pages/viewer/horizontal_viewer_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,14 @@ class _HorizontalViewerPageState extends State<HorizontalViewerPage> {
}
if (c.provider.useProvider) {
if (c.onTwoPage.value) {
var indexPad = 0;
if (c.secondPageToSecondPage.value) {
indexPad = 1;
}

const evict = [-4, -3, 4, 5];
for (final i in evict) {
final target = c.page.value + i;
final target = c.page.value + i - indexPad;

if (target < 0 || c.maxPage <= target || c.urlCache[target] == null) {
continue;
Expand All @@ -199,7 +204,7 @@ class _HorizontalViewerPageState extends State<HorizontalViewerPage> {

const precache = [-2, -1, 2, 3];
for (final i in precache) {
final target = c.page.value + i;
final target = c.page.value + i - indexPad;

if (target < 0 || c.maxPage <= target || c.urlCache[target] == null) {
continue;
Expand Down

0 comments on commit 7917e7b

Please sign in to comment.