-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
No longer support automatically creating Profile, change to select th…
…e Profile to be used in the application by yourself 不再支持自动创建Profile,改为自行选择要在应用内使用的Profile
- Loading branch information
1 parent
78fb059
commit d0887b1
Showing
12 changed files
with
207 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class Profile { | ||
int number; | ||
|
||
String name; | ||
|
||
bool selected; | ||
|
||
Profile({required this.number, required this.name, required this.selected}); | ||
} |
111 changes: 111 additions & 0 deletions
111
lib/src/pages/setting/eh/profile/setting_eh_profile_page.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:dio/dio.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:get/get.dart'; | ||
import 'package:jhentai/src/extension/widget_extension.dart'; | ||
import 'package:jhentai/src/widget/loading_state_indicator.dart'; | ||
import 'package:retry/retry.dart'; | ||
|
||
import '../../../../exception/eh_exception.dart'; | ||
import '../../../../model/profile.dart'; | ||
import '../../../../network/eh_cookie_manager.dart'; | ||
import '../../../../network/eh_request.dart'; | ||
import '../../../../setting/site_setting.dart'; | ||
import '../../../../utils/eh_spider_parser.dart'; | ||
import '../../../../utils/log.dart'; | ||
|
||
class SettingEHProfilePage extends StatefulWidget { | ||
const SettingEHProfilePage({super.key}); | ||
|
||
@override | ||
State<SettingEHProfilePage> createState() => _SettingEHProfilePageState(); | ||
} | ||
|
||
class _SettingEHProfilePageState extends State<SettingEHProfilePage> { | ||
LoadingState loadingState = LoadingState.idle; | ||
late List<Profile> profiles; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
_loadProfile(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar(centerTitle: true, title: Text('profileSetting'.tr)), | ||
body: _buildProfile(), | ||
); | ||
} | ||
|
||
Widget _buildProfile() { | ||
if (loadingState != LoadingState.success) { | ||
return LoadingStateIndicator(loadingState: loadingState, errorTapCallback: _loadProfile); | ||
} | ||
|
||
int number = profiles.firstWhere((p) => p.selected).number; | ||
return SafeArea( | ||
child: ListView( | ||
padding: const EdgeInsets.only(top: 16), | ||
children: [ | ||
ListTile( | ||
title: Text('selectedProfile'.tr), | ||
trailing: DropdownButton<int>( | ||
value: number, | ||
elevation: 4, | ||
alignment: AlignmentDirectional.centerEnd, | ||
onChanged: (int? newValue) { | ||
Get.find<EHCookieManager>().storeEhCookiesForAllUri([Cookie('sp', newValue?.toString() ?? '1')]); | ||
setState(() { | ||
for (Profile value in profiles) { | ||
value.selected = value.number == newValue; | ||
} | ||
}); | ||
}, | ||
items: profiles | ||
.map( | ||
(p) => DropdownMenuItem(child: Text(p.name), value: p.number), | ||
) | ||
.toList(), | ||
), | ||
) | ||
], | ||
).withListTileTheme(context), | ||
); | ||
} | ||
|
||
Future<void> _loadProfile() async { | ||
if (loadingState == LoadingState.loading) { | ||
return; | ||
} | ||
|
||
loadingState = LoadingState.loading; | ||
({List<Profile> profiles, FrontPageDisplayType frontPageDisplayType, bool isLargeThumbnail, int thumbnailRows}) settings; | ||
try { | ||
settings = await retry( | ||
() => EHRequest.requestSettingPage(EHSpiderParser.settingPage2SiteSetting), | ||
retryIf: (e) => e is DioError, | ||
maxAttempts: 3, | ||
); | ||
} on DioError catch (e) { | ||
Log.error('Load profile fail', e.message); | ||
setState(() { | ||
loadingState = LoadingState.error; | ||
}); | ||
return; | ||
} on EHException catch (e) { | ||
Log.error('Load profile fail', e.message); | ||
setState(() { | ||
loadingState = LoadingState.error; | ||
}); | ||
return; | ||
} | ||
|
||
setState(() { | ||
profiles = settings.profiles; | ||
loadingState = LoadingState.success; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.