Skip to content

Commit

Permalink
add code information
Browse files Browse the repository at this point in the history
  • Loading branch information
kidozh committed Dec 2, 2024
1 parent 547bc58 commit 384c402
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 93 deletions.
3 changes: 3 additions & 0 deletions lib/app/MainApp.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class MyApp extends StatelessWidget {
DynamicSchemeVariant dynamicSchemeVariant =
await UserPreferencesUtils.getInterfaceDynamicSchemeVariantPreference();
String adExemptHost = await UserPreferencesUtils.getAdExemptDiscuzHostPreference();
bool ignoreCustomFontStyle = await UserPreferencesUtils.getDisableFontCustomizationPreference();

Provider.of<ThemeNotifierProvider>(context, listen: false)
.setTheme(colorName);
Expand All @@ -95,6 +96,8 @@ class MyApp extends StatelessWidget {
.setDynamicSchemeVariant(dynamicSchemeVariant);
Provider.of<TypeSettingNotifierProvider>(context, listen: false)
.setScalingParameter(scale);
Provider.of<TypeSettingNotifierProvider>(context, listen: false)
.ignoreCustomFontStyle = ignoreCustomFontStyle;
Provider.of<ThemeNotifierProvider>(context, listen: false)
.setBrightness(brightness);
Provider.of<ThemeNotifierProvider>(context, listen: false)
Expand Down
1 change: 1 addition & 0 deletions lib/page/ChooseTypography.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class _ChooseTypeSettingScaleState extends State<ChooseTypeSettingScalePage> {
setState(() {
ignoreCustomFontStyle = value;
});
Provider.of<TypeSettingNotifierProvider>(context, listen: false).ignoreCustomFontStyle = value;
}, initialValue: ignoreCustomFontStyle,
),
SettingsTile.switchTile(
Expand Down
171 changes: 105 additions & 66 deletions lib/page/FullImagePage.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


import 'dart:io';
import 'dart:typed_data';

Expand All @@ -13,92 +11,133 @@ import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
import 'package:image_gallery_saver/image_gallery_saver.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:photo_view/photo_view.dart';
import 'package:photo_view/photo_view_gallery.dart';

import '../utility/AppPlatformIcons.dart';

class FullImagePage extends StatelessWidget{


class FullImagePage extends StatefulWidget {
String imageUrl;
FullImagePage(this.imageUrl);
late BuildContext _context;
List<String> imageUrlList = [];

FullImagePage(this.imageUrl, this.imageUrlList);

@override
State<StatefulWidget> createState() {
// TODO: implement createState
return FullImagePageState(imageUrl, imageUrlList);
}



}


class FullImagePageState extends State<FullImagePage>{
String imageUrl;
List<String> imageUrlList = [];

late PageController pageController;

int currentPage = 0;
FullImagePageState(this.imageUrl, this.imageUrlList){
currentPage = initialPage;
pageController = PageController(initialPage: initialPage);

}

@override
Widget build(BuildContext context) {
_context = context;


return PlatformScaffold(
appBar: PlatformAppBar(
title: Text(imageUrl.split("/").last,
maxLines: 1,
appBar: PlatformAppBar(
title: Text(
"${currentPage + 1} / ${imageUrlList.length}",
maxLines: 1,
),
trailingActions: [
IconButton(
icon: Icon(AppPlatformIcons(context).saveOutline),
onPressed: () {
VibrationUtils.vibrateWithClickIfPossible();
_save(context);
},
)
],
),
trailingActions: [
IconButton(
icon: Icon(AppPlatformIcons(context).saveOutline),
onPressed: (){
VibrationUtils.vibrateWithClickIfPossible();
_save();
},
)
],
),
body: Container(
child: Column(
children: [
Expanded(
child: PhotoView(
imageProvider: CachedNetworkImageProvider(
imageUrl,

),
)

),

// ElevatedButton.icon(
// icon: Icon(Icons.save),
// onPressed: (){
// _save();
// },
// label: Text(S.of(context).savePictureToDevice)
// )
],
)
)
);

body: Container(
child: Column(
children: [
Expanded(
child: photoViewGalleryListBuilder,
)
],
)));
}

Future<void> _saveFigureInDevice() async{
var response = await Dio().get(imageUrl,
options: Options(responseType: ResponseType.bytes)
);
ImageGallerySaver.saveImage(Uint8List.fromList(response.data), quality: 100);
int get initialPage => imageUrlList.indexOf(imageUrl);

Widget get photoViewGalleryListBuilder => PhotoViewGallery.builder(
itemCount: imageUrlList.length,
scrollPhysics: const BouncingScrollPhysics(),
builder: (BuildContext context, int index) {
return PhotoViewGalleryPageOptions(
imageProvider: CachedNetworkImageProvider(imageUrlList[index]),
initialScale: PhotoViewComputedScale.contained * 0.8,
heroAttributes: PhotoViewHeroAttributes(tag: index),
);
},
pageController: pageController,
onPageChanged: (value){
setState(() {
currentPage = value;
});

},
loadingBuilder: (context, event) => Center(
child: Container(
width: 48,
height: 48,
child: PlatformCircularProgressIndicator(
material: (context, platform) => MaterialProgressIndicatorData(
value: (event == null || event.expectedTotalBytes == null)? 0: event.cumulativeBytesLoaded / event.expectedTotalBytes!
),
),
),
),

);

Future<void> _saveFigureInDevice() async {
if(currentPage < imageUrlList.length){
var response = await Dio()
.get(imageUrlList[currentPage], options: Options(responseType: ResponseType.bytes));
ImageGallerySaver.saveImage(Uint8List.fromList(response.data),
quality: 100);
EasyLoading.showSuccess(S.of(context).saveImageSuccessfully);
}
}

_save() async {
if(Platform.isIOS || Platform.isAndroid){
_save(BuildContext context) async {
if (Platform.isIOS || Platform.isAndroid) {
print(imageUrl);
var status = await Permission.storage.status;
print(status);
if(status.isGranted){
if (status.isGranted) {
await _saveFigureInDevice();
}
else if(status.isPermanentlyDenied){
EasyLoading.showError(S.of(_context).writeStorageDenied);
}
else if(status.isDenied){
} else if (status.isPermanentlyDenied) {
EasyLoading.showError(S.of(context).writeStorageDenied);
} else if (status.isDenied) {
PermissionStatus statusResult = await Permission.storage.request();
if(statusResult.isGranted){
if (statusResult.isGranted) {
// save it
await _saveFigureInDevice();
} else {
EasyLoading.showError(S.of(context).writeStorageDenied);
}
else{
EasyLoading.showError(S.of(_context).writeStorageDenied);
}

}


}

}
}
}
13 changes: 13 additions & 0 deletions lib/provider/TypeSettingNotifierProvider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,19 @@ class TypeSettingNotifierProvider with ChangeNotifier{

bool get useCompactParagraph => _useCompactParagraph;

bool _ignoreCustomFontStyle = true;

bool get ignoreCustomFontStyle => _ignoreCustomFontStyle;

set ignoreCustomFontStyle(bool value){
this._ignoreCustomFontStyle = value;
notifyListeners();
}

void setIgnoreCustomFontStyle(bool value){
this._ignoreCustomFontStyle = value;
notifyListeners();
}


}
36 changes: 18 additions & 18 deletions lib/utility/PostTextFieldUtils.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import 'dart:convert';
import 'dart:developer';
import 'dart:io' show Platform;
import "dart:convert";
import "dart:developer";
import "dart:io" show Platform;

import 'package:device_info_plus/device_info_plus.dart';
import 'package:discuz_flutter/entity/Smiley.dart';
import 'package:flutter/widgets.dart';
import 'package:ios_utsname_ext/extension.dart';
import "package:device_info_plus/device_info_plus.dart";
import "package:discuz_flutter/entity/Smiley.dart";
import "package:flutter/widgets.dart";
import "package:ios_utsname_ext/extension.dart";

import '../generated/l10n.dart';
import "../generated/l10n.dart";

class PostTextFieldUtils {
static String getPostMessage(String message) {
Expand Down Expand Up @@ -84,7 +84,7 @@ class PostTextFieldUtils {
static const String NO_SIGNATURE = "";

static const String EXAMPLE_HTML_LONG_DATA = r"""
<p id='top'><a href='#bottom'>Scroll to bottom</a></p>
<p id="top"><a href="#bottom">Scroll to bottom</a></p>
<h1>Header 1</h1>
<h2>Header 2</h2>
<h3>Header 3</h3>
Expand All @@ -93,11 +93,11 @@ class PostTextFieldUtils {
<h6>Header 6</h6>
<h2>Inline Styles:</h2>
<p>The should be <span style='color: blue;'>BLUE style='color: blue;'</span></p>
<p>The should be <span style='color: red;'>RED style='color: red;'</span></p>
<p>The should be <span style='color: rgba(0, 0, 0, 0.10);'>BLACK with 10% alpha style='color: rgba(0, 0, 0, 0.10);</span></p>
<p>The should be <span style='color: rgb(0, 97, 0);'>GREEN style='color: rgb(0, 97, 0);</span></p>
<p>The should be <span style='background-color: red; color: rgb(0, 97, 0);'>GREEN style='color: rgb(0, 97, 0);</span></p>
<p>The should be <span style="color: blue;">BLUE style="color: blue;"</span></p>
<p>The should be <span style="color: red;">RED style="color: red;"</span></p>
<p>The should be <span style="color: rgba(0, 0, 0, 0.10);">BLACK with 10% alpha style="color: rgba(0, 0, 0, 0.10);</span></p>
<p>The should be <span style="color: rgb(0, 97, 0);">GREEN style="color: rgb(0, 97, 0);</span></p>
<p>The should be <span style="background-color: red; color: rgb(0, 97, 0);">GREEN style="color: rgb(0, 97, 0);</span></p>
<h2>Text Alignment</h2>
<p style="text-align: center;"><span style="color: rgba(0, 0, 0, 0.95);">Center Aligned Text</span></p>
Expand All @@ -122,16 +122,16 @@ class PostTextFieldUtils {
<h2>Link support:</h2>
<p>
Linking to <a href='https://github.com'>websites</a> has never been easier.
Linking to <a href="https://github.com">websites</a> has never been easier.
</p>
<h2 id='middle'>SVG support:</h2>
<svg id='svg1' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'>
<h2 id="middle">SVG support:</h2>
<svg id="svg1" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
<circle r="32" cx="35" cy="65" fill="#F00" opacity="0.5"/>
<circle r="32" cx="65" cy="65" fill="#0F0" opacity="0.5"/>
<circle r="32" cx="50" cy="35" fill="#00F" opacity="0.5"/>
</svg>
<p id='bottom'><a href='#top'>Scroll to top</a></p>
<p id="bottom"><a href="#top">Scroll to top</a></p>
""";
}
9 changes: 8 additions & 1 deletion lib/utility/PostTextUtils.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@



import 'dart:developer';

class PostTextUtils{
static String replaceCollapseTag(String string){
//log("Recv html $string");
Expand Down Expand Up @@ -67,8 +69,10 @@ class PostTextUtils{
decodedString = replaceMediaTag(decodedString);
decodedString = decodedString;
if(useCompactParagraph){
decodedString = decodedString.replaceAll(RegExp(r"<br.*?/>\s+<br.*?/>"), r"<br />");
decodedString = decodedString.replaceAll(RegExp(r"<br\s+?/>\s+<br\s+?/>"), r"<br />");
}


// if(useCompactParagraph){
// decodedString = decodedString.replaceAll(RegExp(r"<br.*?/>"), "");
// }
Expand All @@ -77,6 +81,9 @@ class PostTextUtils{
}

static String decodePostMessage(String message){
message = message.replaceAll(RegExp(r'style=".*?"'), "");
message = message.replaceAll(RegExp(r'color=".*?"'), "");
log("Get decoded remove style message ${message}");
return message

;
Expand Down
10 changes: 8 additions & 2 deletions lib/widget/AttachmentWidget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ class AttachmentWidget extends StatelessWidget{

Navigator.push(
context,
platformPageRoute(context:context, builder: (context) => FullImagePage(URLUtils.getAttachmentURLWithAidEncode(discuz, _attachment.aidEncode)))
platformPageRoute(context:context, builder: (context) => FullImagePage(
URLUtils.getAttachmentURLWithAidEncode(discuz, _attachment.aidEncode),
[URLUtils.getAttachmentURLWithAidEncode(discuz, _attachment.aidEncode)]
))
);
},
);
Expand Down Expand Up @@ -174,7 +177,10 @@ class AttachmentWidget extends StatelessWidget{
VibrationUtils.vibrateWithClickIfPossible();
Navigator.push(
context,
platformPageRoute(context:context, builder: (context) => FullImagePage(URLUtils.getAttachmentURLWithAidEncode(discuz, _attachment.aidEncode)))
platformPageRoute(context:context, builder: (context) => FullImagePage(
URLUtils.getAttachmentURLWithAidEncode(discuz, _attachment.aidEncode),
[URLUtils.getAttachmentURLWithAidEncode(discuz, _attachment.aidEncode)]
))
);
}, label: Text(S.of(context).watchPictureInFullScreen))
],
Expand Down
Loading

0 comments on commit 384c402

Please sign in to comment.