Skip to content

Commit

Permalink
Choose cdn , op full screen
Browse files Browse the repository at this point in the history
  • Loading branch information
niuhuan committed Jan 7, 2022
1 parent 7020432 commit 96ad8e9
Show file tree
Hide file tree
Showing 12 changed files with 414 additions and 107 deletions.
3 changes: 2 additions & 1 deletion android/app/src/main/res/values-night/styles.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is on -->
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
Expand All @@ -14,5 +14,6 @@
This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
<item name="android:windowLayoutInDisplayCutoutMode" tools:ignore="NewApi">shortEdges</item>
</style>
</resources>
3 changes: 2 additions & 1 deletion android/app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is off -->
<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
Expand All @@ -14,5 +14,6 @@
This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
<item name="android:windowLayoutInDisplayCutoutMode" tools:ignore="NewApi">shortEdges</item>
</style>
</resources>
120 changes: 120 additions & 0 deletions lib/basic/entities.dart
Original file line number Diff line number Diff line change
Expand Up @@ -567,3 +567,123 @@ class CommentPage extends Page<Comment> {
total = json['total'];
}
}

class PreLoginResponse {
PreLoginResponse({
required this.preSet,
required this.preLogin,
required this.selfInfo,
});

late final bool preSet;
late final bool preLogin;
late final SelfInfo? selfInfo;

PreLoginResponse.fromJson(Map<String, dynamic> json) {
preSet = json['pre_set'];
preLogin = json['pre_login'];
if (json['self_info'] != null) {
selfInfo = SelfInfo.fromJson(json['self_info']);
} else {
selfInfo = null;
}
}

Map<String, dynamic> toJson() {
final _data = <String, dynamic>{};
_data['pre_set'] = preSet;
_data['pre_login'] = preLogin;
_data['self_info'] = selfInfo?.toJson();
return _data;
}
}

class SelfInfo {
SelfInfo({
required this.uid,
required this.username,
required this.email,
required this.emailverified,
required this.photo,
required this.fname,
required this.gender,
required this.message,
required this.coin,
required this.albumFavorites,
required this.s,
required this.favoriteList,
required this.levelName,
required this.level,
required this.nextLevelExp,
required this.exp,
required this.expPercent,
required this.badges,
required this.albumFavoritesMax,
});

late final String uid;
late final String username;
late final String email;
late final String emailverified;
late final String photo;
late final String fname;
late final String gender;
late final String message;
late final String coin;
late final int albumFavorites;
late final String s;
late final List<dynamic> favoriteList;
late final String levelName;
late final int level;
late final int nextLevelExp;
late final String exp;
late final double expPercent;
late final List<dynamic> badges;
late final int albumFavoritesMax;

SelfInfo.fromJson(Map<String, dynamic> json) {
uid = json['uid'];
username = json['username'];
email = json['email'];
emailverified = json['emailverified'];
photo = json['photo'];
fname = json['fname'];
gender = json['gender'];
message = json['message'];
coin = json['coin'];
albumFavorites = json['album_favorites'];
s = json['s'];
favoriteList = List.castFrom<dynamic, dynamic>(json['favorite_list']);
levelName = json['level_name'];
level = json['level'];
nextLevelExp = json['nextLevelExp'];
exp = json['exp'];
expPercent = json['expPercent'];
badges = List.castFrom<dynamic, dynamic>(json['badges']);
albumFavoritesMax = json['album_favorites_max'];
}

Map<String, dynamic> toJson() {
final _data = <String, dynamic>{};
_data['uid'] = uid;
_data['username'] = username;
_data['email'] = email;
_data['emailverified'] = emailverified;
_data['photo'] = photo;
_data['fname'] = fname;
_data['gender'] = gender;
_data['message'] = message;
_data['coin'] = coin;
_data['album_favorites'] = albumFavorites;
_data['s'] = s;
_data['favorite_list'] = favoriteList;
_data['level_name'] = levelName;
_data['level'] = level;
_data['nextLevelExp'] = nextLevelExp;
_data['exp'] = exp;
_data['expPercent'] = expPercent;
_data['badges'] = badges;
_data['album_favorites_max'] = albumFavoritesMax;
return _data;
}
}
6 changes: 6 additions & 0 deletions lib/basic/methods.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ class Methods {
Future saveCdnHost(String choose) {
return _invoke("save_cdn_host", choose);
}

Future<PreLoginResponse> preLogin() async {
return PreLoginResponse.fromJson(
jsonDecode(await _invoke("pre_login", "")),
);
}
}

class _Response {
Expand Down
17 changes: 9 additions & 8 deletions lib/configs/configs.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'package:jasmine/configs/network_api_host.dart';
import 'package:jasmine/configs/network_cdn_host.dart';
import 'package:jasmine/configs/reader_controller_type.dart';
import 'package:jasmine/configs/reader_direction.dart';
import 'package:jasmine/configs/reader_slider_position.dart';
import 'package:jasmine/configs/reader_type.dart';
import 'package:jasmine/configs/versions.dart';

import 'network_api_host.dart';
import 'network_cdn_host.dart';
import 'reader_controller_type.dart';
import 'reader_direction.dart';
import 'reader_slider_position.dart';
import 'reader_type.dart';
import 'versions.dart';
import 'login.dart';
import 'pager_controller_mode.dart';
import 'pager_view_mode.dart';

Expand All @@ -20,4 +20,5 @@ Future initConfigs() async {
await initReaderDirection();
await initReaderControllerType();
await initReaderSliderPosition();
initLogin();
}
42 changes: 42 additions & 0 deletions lib/configs/login.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import 'package:event/event.dart';
import 'package:jasmine/basic/methods.dart';

enum LoginStatus {
notSet,
logging,
loginField,
loginSuccess,
}

late SelfInfo _selfInfo;
LoginStatus _status = LoginStatus.notSet;
final Event _event = Event();

SelfInfo get selfInfo => _selfInfo;

Event get loginEvent => _event;

LoginStatus get loginStatus => _status;

set _loginState(LoginStatus value) {
_status = value;
_event.broadcast();
}

Future initLogin() async {
try {
_loginState = LoginStatus.logging;
final preLogin = await methods.preLogin();
if (!preLogin.preSet) {
_loginState = LoginStatus.notSet;
} else if (preLogin.preLogin) {
_selfInfo = preLogin.selfInfo!;
_loginState = LoginStatus.loginSuccess;
} else {
_loginState = LoginStatus.loginField;
}
} catch (e, st) {
print("$e\n$st");
_loginState = LoginStatus.loginField;
}
}
28 changes: 17 additions & 11 deletions lib/configs/network_api_host.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,40 @@ const _apiHostMap = {
"分流3": "\"www.jmapibranch3.cc\"",
};

late String _apiHost;

String _apiHostName(String value) {
if (value == "") {
value = "null";
}
return _apiHostMap.map((key, value) => MapEntry(value, key))[value] ?? "";
}

late String _apiHost;
String get currentApiHostName => _apiHostName(_apiHost);

Future<void> initApiHost() async {
_apiHost = await methods.loadApiHost();
}

Future chooseApiHost(BuildContext context) async {
final choose = await chooseMapDialog(
context,
title: "API分流",
values: _apiHostMap,
);
if (choose != null) {
await methods.saveApiHost(choose);
_apiHost = choose;
}
}

Widget apiHostSetting() {
return StatefulBuilder(
builder: (BuildContext context, void Function(void Function()) setState) {
return ListTile(
onTap: () async {
final choose = await chooseMapDialog(
context,
title: "API分流",
values: _apiHostMap,
);
if (choose != null) {
await methods.saveApiHost(choose);
_apiHost = choose;
setState(() {});
}
await chooseApiHost(context);
setState(() {});
},
title: const Text("API分流"),
subtitle: Text(_apiHostName(_apiHost)),
Expand Down
28 changes: 17 additions & 11 deletions lib/configs/network_cdn_host.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,40 @@ const _cdnHostMap = {
"分流2": "\"cdn-msp.jmcdnproxy2.cc\"",
};

late String _cdnHost;

String _cdnHostName(String value) {
if (value == "") {
value = "null";
}
return _cdnHostMap.map((key, value) => MapEntry(value, key))[value] ?? "";
}

late String _cdnHost;
String get currentCdnHostName => _cdnHostName(_cdnHost);

Future<void> initCdnHost() async {
_cdnHost = await methods.loadCdnHost();
}

Future chooseCdnHost(BuildContext context) async {
final choose = await chooseMapDialog(
context,
title: "API分流",
values: _cdnHostMap,
);
if (choose != null) {
await methods.saveCdnHost(choose);
_cdnHost = choose;
}
}

Widget cdnHostSetting() {
return StatefulBuilder(
builder: (BuildContext context, void Function(void Function()) setState) {
return ListTile(
onTap: () async {
final choose = await chooseMapDialog(
context,
title: "API分流",
values: _cdnHostMap,
);
if (choose != null) {
await methods.saveCdnHost(choose);
_cdnHost = choose;
setState(() {});
}
await chooseCdnHost(context);
setState(() {});
},
title: const Text("图片分流"),
subtitle: Text(_cdnHostName(_cdnHost)),
Expand Down
Loading

0 comments on commit 96ad8e9

Please sign in to comment.