pikapika/lib/screens/ProScreen.dart

264 lines
7.4 KiB
Dart
Raw Normal View History

2023-04-12 07:53:37 +00:00
import 'dart:convert';
2022-07-09 07:11:26 +00:00
import 'package:flutter/material.dart';
2023-04-12 07:53:37 +00:00
import 'package:intl/intl.dart';
2022-07-09 07:11:26 +00:00
import 'package:pikapika/basic/Common.dart';
import 'package:pikapika/basic/Method.dart';
2023-04-12 07:53:37 +00:00
import 'package:pikapika/screens/AccessKeyReplaceScreen.dart';
2022-07-09 07:11:26 +00:00
2023-04-12 07:53:37 +00:00
import '../basic/config/IconLoading.dart';
2022-07-09 07:11:26 +00:00
import '../basic/config/IsPro.dart';
2023-05-08 09:57:28 +00:00
import 'components/ListView.dart';
2022-07-09 07:11:26 +00:00
class ProScreen extends StatefulWidget {
const ProScreen({Key? key}) : super(key: key);
@override
State<StatefulWidget> createState() => _ProScreenState();
}
class _ProScreenState extends State<ProScreen> {
String _username = "";
@override
void initState() {
method.getUsername().then((value) {
setState(() {
_username = value;
});
});
2023-04-12 07:53:37 +00:00
proEvent.subscribe(_setState);
2022-07-09 07:11:26 +00:00
super.initState();
}
2023-04-12 07:53:37 +00:00
@override
void dispose() {
proEvent.unsubscribe(_setState);
super.dispose();
}
_setState(_) {
setState(() {});
}
2022-07-09 07:11:26 +00:00
@override
Widget build(BuildContext context) {
var size = MediaQuery.of(context).size;
var min = size.width < size.height ? size.width : size.height;
return Scaffold(
appBar: AppBar(
title: const Text("发电中心"),
),
2023-05-08 09:57:28 +00:00
body: PikaListView(
2022-07-09 07:11:26 +00:00
children: [
SizedBox(
width: min / 2,
height: min / 2,
child: Center(
child: Icon(
isPro ? Icons.offline_bolt : Icons.offline_bolt_outlined,
size: min / 3,
color: Colors.grey.shade500,
),
),
),
Center(child: Text(_username)),
Container(height: 20),
const Divider(),
const Padding(
padding: EdgeInsets.all(20),
child: Text(
2023-04-12 09:48:48 +00:00
"\"关于\"界面找到维护地址可获得发电指引\n"
"\n \"我曾经发过电\"可同步相应发电状态"
"\n \"我刚才发了电\"兑换神秘代码"
"\n\n发电小功能: 多线程下载 / 批量导入导出下载",
2022-07-12 07:28:47 +00:00
),
),
const Divider(),
2022-07-09 07:11:26 +00:00
ListTile(
2023-04-12 07:53:37 +00:00
title: const Text("签到/游戏/兑换"),
2022-07-09 07:11:26 +00:00
subtitle: Text(
proInfoAf.isPro
? "发电中 (${DateTime.fromMillisecondsSinceEpoch(1000 * proInfoAf.expire).toString()})"
2022-07-09 07:11:26 +00:00
: "未发电",
),
),
const Divider(),
ListTile(
title: const Text("我曾经发过电"),
onTap: () async {
try {
await method.reloadPro();
defaultToast(context, "SUCCESS");
} catch (e, s) {
defaultToast(context, "FAIL");
}
await reloadIsPro();
setState(() {});
},
),
const Divider(),
ListTile(
title: const Text("我刚才发了电"),
onTap: () async {
2023-05-08 09:57:28 +00:00
var code = await inputString(context, "输入代码");
if (code != null) {
code = code.trim();
if (code.isNotEmpty) {
try {
await method.inputCdKey(code);
defaultToast(context, "SUCCESS");
} catch (e, s) {
defaultToast(context, "FAIL");
}
2022-07-09 07:11:26 +00:00
}
}
await reloadIsPro();
setState(() {});
},
),
const Divider(),
2023-04-12 07:53:37 +00:00
...patPro(),
const Divider(),
const Divider(),
2022-07-09 07:11:26 +00:00
],
),
);
}
2023-04-12 07:53:37 +00:00
List<Widget> patPro() {
List<Widget> widgets = [];
if (proInfoPat.accessKey.isNotEmpty) {
var text = "密钥 : 已录入";
if (proInfoPat.patId.isNotEmpty) {
text += "\nPAT账号 : ${proInfoPat.patId}";
}
if (proInfoPat.bindUid.isNotEmpty) {
text += "\n绑定PIKA账号 : ${proInfoPat.bindUid}";
}
if (proInfoPat.requestDelete > 0) {
DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(
proInfoPat.requestDelete * 1000,
isUtc: true,
);
String formattedDate =
DateFormat('yyyy-MM-dd HH:mm:ss').format(dateTime.toLocal());
text += "\n绑定账号时间 : $formattedDate";
}
if (proInfoPat.reBind > 0) {
DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(
proInfoPat.reBind * 1000,
isUtc: true,
);
String formattedDate =
DateFormat('yyyy-MM-dd HH:mm:ss').format(dateTime.toLocal());
text += "\n可以换绑时间 : $formattedDate";
}
List<TextSpan> append = [];
if (proInfoPat.bindUid == "") {
append.add(const TextSpan(
text: "\n(请点击这里绑定到当前账号发电)",
style: TextStyle(color: Colors.blue),
));
} else if (proInfoPat.bindUid != _username) {
append.add(const TextSpan(
text: "\n(请点换绑到当前账号发电)",
style: TextStyle(color: Colors.red),
));
} else if (proInfoPat.isPro == false) {
append.add(const TextSpan(
text: "\n(未检测到入会, 请到下载页入会)",
style: TextStyle(color: Colors.orange),
));
} else {
append.add(const TextSpan(
text: "\n(PAT正常)",
style: TextStyle(color: Colors.green),
));
}
widgets.add(ListTile(
onTap: () async {
print(jsonEncode(proInfoPat));
var choose = await chooseMapDialog<int>(
context,
{
"更新PAT发电状态": 2,
"绑定到此账号": 3,
"更换PAT密钥": 1,
"清除PAT信息": 4,
},
"请选择",
);
switch (choose) {
case 1:
addPatAccount();
break;
case 2:
reloadPatAccount();
break;
case 3:
bindThisAccount();
break;
case 4:
clearPat();
break;
}
},
title: const Text("PAT入会"),
subtitle: Text.rich(TextSpan(children: [
TextSpan(text: text),
...append,
])),
));
} else {
widgets.add(ListTile(
onTap: () {
addPatAccount();
},
title: const Text("PAT入会"),
subtitle: const Text("点击绑定"),
));
}
return widgets;
}
void addPatAccount() async {
print(jsonEncode(proInfoPat));
String? key = await inputString(context, "请输入授权代码");
if (key != null) {
await Navigator.of(context)
.push(mixRoute(builder: (BuildContext context) {
return AccessKeyReplaceScreen(accessKey: key);
}));
}
}
reloadPatAccount() async {
defaultToast(context, "请稍后");
try {
await method.reloadPatAccount();
await reloadIsPro();
defaultToast(context, "SUCCESS");
} catch (e) {
defaultToast(context, "FAIL : $e");
} finally {}
}
bindThisAccount() async {
defaultToast(context, "请稍后");
try {
await method.bindThisAccount();
await reloadIsPro();
defaultToast(context, "SUCCESS");
} catch (e) {
defaultToast(context, "FAIL : $e");
} finally {}
}
clearPat() async {
await method.clearPat();
await reloadIsPro();
defaultToast(context, "Success");
}
2022-07-09 07:11:26 +00:00
}