Skip to content

Commit

Permalink
Merge pull request #595 from project-violet/windows-ui
Browse files Browse the repository at this point in the history
Phase 1. Adopt ui for windows - article simple info
  • Loading branch information
violet-dev authored Dec 29, 2024
2 parents 261942d + d9697a9 commit 2611cf3
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 109 deletions.
19 changes: 15 additions & 4 deletions violet/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_downloader/flutter_downloader.dart'; // @dependent: android
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:fullscreen_window/fullscreen_window.dart';
import 'package:get/get.dart';
import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';
import 'package:shared_preferences/shared_preferences.dart';
Expand Down Expand Up @@ -248,11 +249,14 @@ class CustomScrollBehavior extends MaterialScrollBehavior {
}

// A widget to listen for the Escape key, XButton1 and raise the WillPopScope event
// ignore: must_be_immutable
class EscapeKeyListener extends StatelessWidget {
final Widget child;
final GlobalKey<NavigatorState> navigatorKey;

const EscapeKeyListener({
bool toggleFullScreen = false;

EscapeKeyListener({
super.key,
required this.navigatorKey,
required this.child,
Expand All @@ -264,9 +268,16 @@ class EscapeKeyListener extends StatelessWidget {
autofocus: true,
focusNode: FocusNode(),
onKeyEvent: (KeyEvent event) {
if (event is KeyDownEvent &&
event.logicalKey == LogicalKeyboardKey.escape) {
navigatorPop();
if (event is KeyDownEvent) {
switch (event.logicalKey) {
case LogicalKeyboardKey.escape:
navigatorPop();
break;
case LogicalKeyboardKey.f11:
toggleFullScreen = !toggleFullScreen;
FullScreenWindow.setFullScreen(toggleFullScreen);
break;
}
}
},
// https://github.com/flutter/flutter/issues/115641#issuecomment-2267579790
Expand Down
117 changes: 54 additions & 63 deletions violet/lib/pages/article_info/article_info_page.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// This source code is a part of Project Violet.
// Copyright (C) 2020-2024. violet-team. Licensed under the Apache-2.0 License.

import 'dart:io';
import 'dart:math';

import 'package:auto_animated/auto_animated.dart';
Expand Down Expand Up @@ -73,8 +74,6 @@ class ArticleInfoPage extends StatelessWidget {
width: width - 16,
height: Variables.articleInfoHeight,
child: Container(
// width: width,
// height: height,
color: Settings.themeWhat
? Colors.black.withOpacity(0.9)
: Colors.white.withOpacity(0.97),
Expand All @@ -83,49 +82,13 @@ class ArticleInfoPage extends StatelessWidget {
children: [
Container(
width: width,
height: 4 * 50.0 + 16,
height: simpleInfoHeight(),
color: Settings.themeWhat
? Colors.grey.shade900.withOpacity(0.6)
: Colors.white.withOpacity(0.2),
child: SimpleInfoWidget(),
),
// _functionButtons(width, context, data),
Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Settings.majorColor.withAlpha(230),
),
onPressed: () async =>
await _downloadButtonEvent(context, data),
child: SizedBox(
width: (width - 32 - 64 - 32) / 2,
child: Text(
Translations.instance!.trans('download'),
textAlign: TextAlign.center,
),
),
),
const SizedBox(width: 4.0),
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Settings.majorColor,
),
onPressed: data.lockRead
? null
: () async => await _readButtonEvent(context, data),
child: SizedBox(
width: (width - 32 - 64 - 32) / 2,
child: Text(
Translations.instance!.trans('read'),
textAlign: TextAlign.center,
),
),
),
],
),
buttonArea(context),
TagInfoAreaWidget(queryResult: data.queryResult),
const DividerWidget(),
_CommentArea(
Expand All @@ -152,7 +115,7 @@ class ArticleInfoPage extends StatelessWidget {
expanded: PreviewAreaWidget(
queryResult: data.queryResult,
onPageTapped: (page) async =>
await _readButtonEvent(context, data, page),
await readButtonEvent(context, data, page),
),
collapsed: Container(),
),
Expand Down Expand Up @@ -196,45 +159,73 @@ class ArticleInfoPage extends StatelessWidget {
);
}

/*_functionButtons(width, context, data) {
double simpleInfoHeight() {
const bottomPadding = 16;
final height = Platform.isWindows ? 4 * 100.0 : 4 * 50.0;
return height + bottomPadding;
}

Row buttonArea(BuildContext context) {
final width = MediaQuery.of(context).size.width;
final buttonWidth = (width - 32 - 64 - 32) / 2;
final buttonHeight = Platform.isWindows ? 36.0 : null;
final iconSize = Platform.isWindows ? 20.0 : null;
final data = Provider.of<ArticleInfo>(context);

SizedBox buttonInner(IconData icon, String text) {
return SizedBox(
width: buttonWidth,
height: buttonHeight,
child: Align(
alignment: Alignment.center,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(icon, size: iconSize),
const SizedBox(width: 6.0),
Text(
text,
textAlign: TextAlign.center,
style: const TextStyle(fontWeight: FontWeight.bold),
),
],
),
),
);
}

return Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
child: Container(
width: (width - 32 - 64 - 32) / 2,
child: Text(
Translations.instance!.trans('download'),
textAlign: TextAlign.center,
),
),
style: ElevatedButton.styleFrom(
primary: Settings.majorColor.withAlpha(230),
backgroundColor: Settings.majorColor.withAlpha(230),
),
onPressed: () async => await downloadButtonEvent(context, data),
child: buttonInner(
MdiIcons.download,
Translations.instance!.trans('download'),
),
onPressed: () async => await _downloadButtonEvent(context, data),
),
const SizedBox(width: 4.0),
ElevatedButton(
child: Container(
width: (width - 32 - 64 - 32) / 2,
child: Text(
Translations.instance!.trans('read'),
textAlign: TextAlign.center,
),
),
style: ElevatedButton.styleFrom(
primary: Settings.majorColor,
backgroundColor: Settings.majorColor,
),
onPressed: data.lockRead
? null
: () async => await _readButtonEvent(context, data),
: () async => await readButtonEvent(context, data),
child: buttonInner(
MdiIcons.bookOpenPageVariant,
Translations.instance!.trans('read'),
),
),
],
);
}*/
}

_downloadButtonEvent(context, data) async {
downloadButtonEvent(context, data) async {
if (!Settings.useInnerStorage &&
!await Permission.manageExternalStorage.isGranted) {
if (await Permission.manageExternalStorage.request() ==
Expand Down Expand Up @@ -273,7 +264,7 @@ class ArticleInfoPage extends StatelessWidget {
Navigator.pop(context);
}

_readButtonEvent(BuildContext context, ArticleInfo data, [int? page]) async {
readButtonEvent(BuildContext context, ArticleInfo data, [int? page]) async {
if (Settings.useVioletServer) {
Future.delayed(const Duration(milliseconds: 100)).then((value) async {
await VioletServer.view(data.queryResult.id());
Expand Down
Loading

0 comments on commit 2611cf3

Please sign in to comment.