Add three area controller

This commit is contained in:
niuhuan 2021-11-29 11:26:30 +08:00
parent 13b79f65f5
commit caef949f32
9 changed files with 85 additions and 80 deletions

View File

@ -24,7 +24,13 @@ var (
tmpDir string tmpDir string
) )
var initFlag bool
func InitPlugin(_remoteDir string, _downloadDir string, _tmpDir string) { func InitPlugin(_remoteDir string, _downloadDir string, _tmpDir string) {
if initFlag {
return
}
initFlag = true
remoteDir = _remoteDir remoteDir = _remoteDir
downloadDir = _downloadDir downloadDir = _downloadDir
tmpDir = _tmpDir tmpDir = _tmpDir

View File

@ -8,11 +8,13 @@ import '../Method.dart';
enum FullScreenAction { enum FullScreenAction {
CONTROLLER, CONTROLLER,
TOUCH_ONCE, TOUCH_ONCE,
THREE_AREA,
} }
Map<String, FullScreenAction> _fullScreenActionMap = { Map<String, FullScreenAction> _fullScreenActionMap = {
"使用控制器": FullScreenAction.CONTROLLER, "使用控制器": FullScreenAction.CONTROLLER,
"点击屏幕一次": FullScreenAction.TOUCH_ONCE, "点击屏幕一次": FullScreenAction.TOUCH_ONCE,
"将屏幕划分成三个区域": FullScreenAction.THREE_AREA,
}; };
const _propertyName = "fullScreenAction"; const _propertyName = "fullScreenAction";

View File

@ -1,42 +0,0 @@
///
import 'package:flutter/material.dart';
import '../Common.dart';
import '../Method.dart';
const _propertyName = "guiAnimation";
late bool _guiAnimation;
Future<void> initGuiAnimation() async {
_guiAnimation = (await method.loadProperty(_propertyName, "true")) == "true";
}
bool currentGuiAnimation() {
return _guiAnimation;
}
Future<void> _chooseGuiAnimation(BuildContext context) async {
String? result =
await chooseListDialog<String>(context, "开启软件界面动画", ["", ""]);
if (result != null) {
var target = result == "";
await method.saveProperty(_propertyName, "$target");
_guiAnimation = target;
}
}
Widget guiAnimationSetting() {
return StatefulBuilder(
builder: (BuildContext context, void Function(void Function()) setState) {
return ListTile(
title: Text("软件界面动画"),
subtitle: Text(_guiAnimation ? "" : ""),
onTap: () async {
await _chooseGuiAnimation(context);
setState(() {});
},
);
},
);
}

View File

@ -1,5 +1,4 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:pikapika/basic/config/GuiAnimation.dart';
import 'package:pikapika/basic/config/Version.dart'; import 'package:pikapika/basic/config/Version.dart';
import 'package:pikapika/screens/components/Badge.dart'; import 'package:pikapika/screens/components/Badge.dart';
@ -31,39 +30,25 @@ class _AppScreenState extends State<AppScreen> {
setState(() {}); setState(() {});
} }
static List<Widget> _widgetOptions = <Widget>[ static const List<Widget> _widgetOptions = <Widget>[
CategoriesScreen(), const CategoriesScreen(),
SpaceScreen(), const SpaceScreen(),
]; ];
late int _selectedIndex = 0; late int _selectedIndex = 0;
PageController _pageController = PageController(initialPage: 0);
void _onItemTapped(int index) { void _onItemTapped(int index) {
if (currentGuiAnimation()) {
_pageController.animateToPage(
index,
duration: Duration(milliseconds: 200),
curve: Curves.ease,
);
} else {
_pageController.jumpToPage(index);
}
}
void _onPageChanged(int index) {
setState(() { setState(() {
this._selectedIndex = index; _selectedIndex = index;
}); });
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
body: PageView( body: IndexedStack(
controller: _pageController, index: _selectedIndex,
children: _widgetOptions, children: _widgetOptions,
onPageChanged: _onPageChanged,
), ),
bottomNavigationBar: BottomNavigationBar( bottomNavigationBar: BottomNavigationBar(
items: <BottomNavigationBarItem>[ items: <BottomNavigationBarItem>[

View File

@ -24,12 +24,7 @@ class CategoriesScreen extends StatefulWidget {
State<StatefulWidget> createState() => _CategoriesScreenState(); State<StatefulWidget> createState() => _CategoriesScreenState();
} }
class _CategoriesScreenState extends State<CategoriesScreen> class _CategoriesScreenState extends State<CategoriesScreen> {
with AutomaticKeepAliveClientMixin {
@override
bool get wantKeepAlive => true;
late SearchBar _searchBar = SearchBar( late SearchBar _searchBar = SearchBar(
hintText: '搜索', hintText: '搜索',
inBar: false, inBar: false,
@ -92,7 +87,6 @@ class _CategoriesScreenState extends State<CategoriesScreen>
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
super.build(context);
var theme = Theme.of(context); var theme = Theme.of(context);
var themeBackground = theme.scaffoldBackgroundColor; var themeBackground = theme.scaffoldBackgroundColor;
var shadeBackground = Color.fromARGB( var shadeBackground = Color.fromARGB(

View File

@ -11,7 +11,6 @@ import 'package:pikapika/basic/config/DownloadAndExportPath.dart';
import 'package:pikapika/basic/config/DownloadThreadCount.dart'; import 'package:pikapika/basic/config/DownloadThreadCount.dart';
import 'package:pikapika/basic/config/FullScreenAction.dart'; import 'package:pikapika/basic/config/FullScreenAction.dart';
import 'package:pikapika/basic/config/FullScreenUI.dart'; import 'package:pikapika/basic/config/FullScreenUI.dart';
import 'package:pikapika/basic/config/GuiAnimation.dart';
import 'package:pikapika/basic/config/KeyboardController.dart'; import 'package:pikapika/basic/config/KeyboardController.dart';
import 'package:pikapika/basic/config/NoAnimation.dart'; import 'package:pikapika/basic/config/NoAnimation.dart';
import 'package:pikapika/basic/config/PagerAction.dart'; import 'package:pikapika/basic/config/PagerAction.dart';
@ -77,7 +76,6 @@ class _InitScreenState extends State<InitScreen> {
await initNoAnimation(); await initNoAnimation();
await initVersion(); await initVersion();
autoCheckNewVersion(); autoCheckNewVersion();
await initGuiAnimation();
// , token失效重新登录, 1 // , token失效重新登录, 1
if (await method.preLogin()) { if (await method.preLogin()) {
// token或username+password有效则直接进入登录好的界面 // token或username+password有效则直接进入登录好的界面

View File

@ -13,7 +13,6 @@ import 'package:pikapika/basic/config/DownloadAndExportPath.dart';
import 'package:pikapika/basic/config/DownloadThreadCount.dart'; import 'package:pikapika/basic/config/DownloadThreadCount.dart';
import 'package:pikapika/basic/config/FullScreenAction.dart'; import 'package:pikapika/basic/config/FullScreenAction.dart';
import 'package:pikapika/basic/config/FullScreenUI.dart'; import 'package:pikapika/basic/config/FullScreenUI.dart';
import 'package:pikapika/basic/config/GuiAnimation.dart';
import 'package:pikapika/basic/config/KeyboardController.dart'; import 'package:pikapika/basic/config/KeyboardController.dart';
import 'package:pikapika/basic/config/NoAnimation.dart'; import 'package:pikapika/basic/config/NoAnimation.dart';
import 'package:pikapika/basic/config/PagerAction.dart'; import 'package:pikapika/basic/config/PagerAction.dart';
@ -44,12 +43,11 @@ class SettingsScreen extends StatelessWidget {
convertToPNGSetting(), convertToPNGSetting(),
readerTypeSetting(), readerTypeSetting(),
readerDirectionSetting(), readerDirectionSetting(),
noAnimationSetting(),
autoFullScreenSetting(), autoFullScreenSetting(),
fullScreenActionSetting(), fullScreenActionSetting(),
volumeControllerSetting(), volumeControllerSetting(),
keyboardControllerSetting(), keyboardControllerSetting(),
guiAnimationSetting(), noAnimationSetting(),
Divider(), Divider(),
shadowCategoriesModeSetting(), shadowCategoriesModeSetting(),
shadowCategoriesSetting(), shadowCategoriesSetting(),

View File

@ -21,10 +21,7 @@ class SpaceScreen extends StatefulWidget {
State<StatefulWidget> createState() => _SpaceScreenState(); State<StatefulWidget> createState() => _SpaceScreenState();
} }
class _SpaceScreenState extends State<SpaceScreen> class _SpaceScreenState extends State<SpaceScreen> {
with AutomaticKeepAliveClientMixin {
@override
bool get wantKeepAlive => true;
@override @override
void initState() { void initState() {
@ -44,7 +41,6 @@ class _SpaceScreenState extends State<SpaceScreen>
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
super.build(context);
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text('我的'), title: Text('我的'),

View File

@ -167,6 +167,74 @@ class ImageReader extends StatelessWidget {
child: reader, child: reader,
); );
break; break;
case FullScreenAction.THREE_AREA:
reader = Stack(
children: [
reader,
LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
var up = Expanded(
child: GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () {
_readerControllerEvent
.broadcast(_ReaderControllerEventArgs("UP"));
},
child: Container(),
),
);
var down = Expanded(
child: GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () {
_readerControllerEvent
.broadcast(_ReaderControllerEventArgs("DOWN"));
},
child: Container(
),
),
);
var fullScreen = Expanded(
child: GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () => struct.onFullScreenChange(!struct.fullScreen),
child: Container(),
),
);
late Widget child;
switch (struct.pagerDirection) {
case ReaderDirection.TOP_TO_BOTTOM:
child = Column(children: [
up,
fullScreen,
down,
]);
break;
case ReaderDirection.LEFT_TO_RIGHT:
child = Row(children: [
up,
fullScreen,
down,
]);
break;
case ReaderDirection.RIGHT_TO_LEFT:
child = Row(children: [
down,
fullScreen,
up,
]);
break;
}
return Container(
width: constraints.maxWidth,
height: constraints.maxHeight,
child: child,
);
},
),
],
);
break;
} }
// //
return reader; return reader;