Skip to content

Commit

Permalink
halt network condition if no user is provided
Browse files Browse the repository at this point in the history
  • Loading branch information
kidozh committed Oct 26, 2024
1 parent 234576b commit 5d4ccc6
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 72 deletions.
40 changes: 24 additions & 16 deletions lib/page/DisplayForumSliverPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ class _DisplayForumSliverState extends State<DisplayForumSliverStatefulWidget> {
DateTime.now(),
discuz)
);
if(Provider.of<DiscuzAndUserNotifier>(context, listen: false).user == null) {
return;
}
client.favoriteForumActionResult(_displayForumResult.discuzIndexVariables.formHash, fid).then((value){
if(value.errorResult!= null && value.errorResult!.key == "do_success"){
EasyLoading.showSuccess(S.of(context).discuzOperationMessage(value.errorResult!.key, value.errorResult!.content));
Expand All @@ -176,6 +179,9 @@ class _DisplayForumSliverState extends State<DisplayForumSliverStatefulWidget> {
FavoriteForumInDatabase? favoriteForumInDatabase = favoriteForumDao.getFavoriteForumByFid(fid, discuz);
if(favoriteForumInDatabase!= null){
favoriteForumDao.removeFavoriteForum(favoriteForumInDatabase);
if(Provider.of<DiscuzAndUserNotifier>(context, listen: false).user == null) {
return;
}
client.unfavoriteThreadActionResult(_displayForumResult.discuzIndexVariables.formHash, favoriteForumInDatabase.favid).then((value){
if(value.errorResult!= null && value.errorResult!.key == "do_success"){
EasyLoading.showSuccess(S.of(context).discuzOperationMessage(value.errorResult!.key, value.errorResult!.content));
Expand Down Expand Up @@ -401,23 +407,25 @@ class _DisplayForumSliverState extends State<DisplayForumSliverStatefulWidget> {
}
},
),
if(user != null)
IconButton(
icon: Icon(AppPlatformIcons(context).publishPostOutlined,size: 24),
onPressed: () {
if(_displayForumResult.discuzIndexVariables.forum.fid != 0){
VibrationUtils.vibrateWithClickIfPossible();
Navigator.push(
context,
platformPageRoute(
context: context,
builder: (context) => PostThreadPage(discuz,_displayForumResult.discuzIndexVariables.forum.fid, 0)));
}
else{
EasyLoading.showInfo(S.of(context).loading);
}
Consumer<DiscuzAndUserNotifier>(
builder: (context, discuzAndUser, child) => discuzAndUser.user!= null? IconButton(
icon: Icon(AppPlatformIcons(context).publishPostOutlined,size: 24),
onPressed: () {
if(_displayForumResult.discuzIndexVariables.forum.fid != 0){
VibrationUtils.vibrateWithClickIfPossible();
Navigator.push(
context,
platformPageRoute(
context: context,
builder: (context) => PostThreadPage(discuz,_displayForumResult.discuzIndexVariables.forum.fid, 0)));
}
else{
EasyLoading.showInfo(S.of(context).loading);
}

}): Container(),
),

}),
PlatformPopupMenu(
icon: Icon(PlatformIcons(context).ellipsis, size: 24,),
options: [
Expand Down
80 changes: 36 additions & 44 deletions lib/page/PostThreadPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class PostThreadState extends State<PostThreadStatefulWidget> {
title: Text(S.of(context).pushThreadTitle),
trailingActions: [
PlatformIconButton(
icon: Icon(AppPlatformIcons(context).postThreadSolid),
icon: Icon(AppPlatformIcons(context).postThreadSolid, size: 24,),
onPressed: () async {
VibrationUtils.vibrateWithClickIfPossible();
await _launchCaptchaDialog(context);
Expand Down Expand Up @@ -229,9 +229,9 @@ class PostThreadState extends State<PostThreadStatefulWidget> {
));
},
),
PlatformIconButton(
icon: Icon(Icons.settings_backup_restore),
),
// PlatformIconButton(
// icon: Icon(Icons.settings_backup_restore),
// ),
],
),
],
Expand Down Expand Up @@ -389,50 +389,42 @@ class PostThreadState extends State<PostThreadStatefulWidget> {
Dio dio = await NetworkUtils.getDioWithPersistCookieJar(user);
// MobileApiClient client = MobileApiClient(dio, baseUrl: discuz.baseURL);

showDialog(
showPlatformDialog(
context: context,
builder: (context) {
return SimpleDialog(
return PlatformAlertDialog(
title: Text(S.of(context).pushThreadTitle),
children: [
Padding(padding: EdgeInsets.symmetric(vertical: 8.0, horizontal: 8.0),
child: Column(
children: [
CaptchaWidget(
dio,
discuz,
user,
"post",
captchaController: captchaController,
showProgress: true,
),
SizedBox(
height: 16.0,
),
Row(
mainAxisSize: MainAxisSize.max,
children: [
Expanded(
child: PlatformElevatedButton(
color: Theme.of(context).primaryColor,
child: Text(
S.of(context).send,
style: TextStyle(
color:
Theme.of(context).primaryTextTheme.labelLarge?.color),
),
onPressed: () {
VibrationUtils.vibrateWithClickIfPossible();
postThread();
Navigator.of(context).pop();
},
)),
],
)
],
),
content: Padding(padding: EdgeInsets.symmetric(vertical: 8.0, horizontal: 8.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
CaptchaWidget(
dio,
discuz,
user,
"post",
captchaController: captchaController,
showProgress: true,
),
],
),
),
actions: [
PlatformDialogAction(
child: Text(S.of(context).send),
onPressed: () {
VibrationUtils.vibrateWithClickIfPossible();
postThread();
Navigator.of(context).pop();
},
),
PlatformDialogAction(
child: Text(S.of(context).cancel),
onPressed: () {
VibrationUtils.vibrateWithClickIfPossible();
Navigator.of(context).pop();
},
)

],
);
});
Expand Down
6 changes: 6 additions & 0 deletions lib/page/ViewThreadSliverPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,9 @@ class _ViewThreadSliverState extends State<ViewThreadStatefulSliverWidget> {
_viewThreadResult.threadVariables.threadInfo.replies,
DateTime.now(),
discuz));
if(Provider.of<DiscuzAndUserNotifier>(context, listen: false).user == null) {
return;
}
client
.favoriteThreadActionResult(
_viewThreadResult.threadVariables.formHash, tid)
Expand All @@ -543,6 +546,9 @@ class _ViewThreadSliverState extends State<ViewThreadStatefulSliverWidget> {
favoriteThreadDao.getFavoriteThreadByTid(tid, discuz);
if (favoriteThreadInDatabase != null) {
favoriteThreadDao.removeFavoriteThread(favoriteThreadInDatabase);
if(Provider.of<DiscuzAndUserNotifier>(context, listen: false).user == null) {
return;
}
client
.unfavoriteThreadActionResult(
_viewThreadResult.threadVariables.formHash,
Expand Down
22 changes: 11 additions & 11 deletions lib/screen/ExtraFuncInThreadScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import 'package:discuz_flutter/utility/NetworkUtils.dart';
import 'package:discuz_flutter/utility/VibrationUtils.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:flutter_image_compress/flutter_image_compress.dart';
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
import 'package:image_picker/image_picker.dart';
Expand Down Expand Up @@ -141,17 +142,16 @@ class ExtraFuncInThreadState extends State<ExtraFuncInThreadScreen>{
),
if(!file_not_exceeding_size)
Container(
child: PlatformListTile(
// title: Text(S.of(context).attachmentUploadExceedingSizeTitle,
// style: TextStyle(
// color: Theme.of(context).colorScheme.onPrimary,
// fontSize: FontSize.small.value
// ),
//
// ),
title: Text(S.of(context).attachmentUploadExceedingSizeDescription,
style: TextStyle(
color: Theme.of(context).colorScheme.onPrimary,
child: Container(

color: Theme.of(context).colorScheme.primary,
child: SizedBox(
width: double.infinity,
child: Text(S.of(context).attachmentUploadExceedingSizeDescription,
style: TextStyle(
color: Theme.of(context).colorScheme.onPrimary,
fontSize: FontSize.medium.value
),
),
),
),
Expand Down
2 changes: 1 addition & 1 deletion lib/utility/AppPlatformIcons.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class AppPlatformIcons{

IconData get goToSolid => isMaterial(context)? Icons.arrow_forward : CupertinoIcons.arrow_right;

IconData get postThreadSolid => isMaterial(context)? Icons.send : CupertinoIcons.arrowshape_turn_up_right_fill;
IconData get postThreadSolid => isMaterial(context)? Icons.send : CupertinoIcons.arrow_up_right_diamond_fill;

IconData get checkCircleSolid => isMaterial(context)? Icons.check_circle : CupertinoIcons.check_mark_circled_solid;

Expand Down

0 comments on commit 5d4ccc6

Please sign in to comment.