diff --git a/lib/JsonResult/PrivateMessagePortalResult.dart b/lib/JsonResult/PrivateMessagePortalResult.dart index 0974651..ba4c72e 100644 --- a/lib/JsonResult/PrivateMessagePortalResult.dart +++ b/lib/JsonResult/PrivateMessagePortalResult.dart @@ -17,6 +17,7 @@ class PrivateMessagePortalResult extends BaseResult{ PrivateMessagePortalResult(){} factory PrivateMessagePortalResult.fromJson(Map json) => _$PrivateMessagePortalResultFromJson(json); + Map toJson() => _$PrivateMessagePortalResultToJson(this); } @JsonSerializable() @@ -33,7 +34,7 @@ class PrivateMessagePortalVariables extends BaseVariableResult{ PrivateMessagePortalVariables(){} factory PrivateMessagePortalVariables.fromJson(Map json) => _$PrivateMessagePortalVariablesFromJson(json); - + Map toJson() => _$PrivateMessagePortalVariablesToJson(this); } @JsonSerializable() @@ -67,5 +68,6 @@ class PrivateMessagePortal{ PrivateMessagePortal(); factory PrivateMessagePortal.fromJson(Map json) => _$PrivateMessagePortalFromJson(json); + Map toJson() => _$PrivateMessagePortalToJson(this); } diff --git a/lib/page/PrivateMessageDetailPage.dart b/lib/page/PrivateMessageDetailPage.dart index d0f0667..e541666 100644 --- a/lib/page/PrivateMessageDetailPage.dart +++ b/lib/page/PrivateMessageDetailPage.dart @@ -21,6 +21,7 @@ import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_platform_widgets/flutter_platform_widgets.dart'; import 'package:provider/provider.dart'; +import '../utility/AppPlatformIcons.dart'; import '../utility/EasyRefreshUtils.dart'; import 'UserProfilePage.dart'; @@ -71,7 +72,6 @@ class _PrivateMessageDetailState @override void initState() { - // TODO: implement initState super.initState(); _controller = EasyRefreshController(controlFinishLoad: true, controlFinishRefresh: true); @@ -219,8 +219,8 @@ class _PrivateMessageDetailState appBar: PlatformAppBar( title: Text(toUsername), trailingActions: [ - PlatformIconButton( - icon: Icon(PlatformIcons(context).ellipsis), + IconButton( + icon: Icon(AppPlatformIcons(context).userProfileSolid, size: 28,), onPressed: () { Navigator.push( context, diff --git a/lib/screen/PrivateMessagePortalScreen.dart b/lib/screen/PrivateMessagePortalScreen.dart index 5297fc5..7e508ff 100644 --- a/lib/screen/PrivateMessagePortalScreen.dart +++ b/lib/screen/PrivateMessagePortalScreen.dart @@ -1,3 +1,4 @@ +import 'dart:convert'; import 'dart:developer'; import 'package:dio/dio.dart'; @@ -20,13 +21,13 @@ import 'package:provider/provider.dart'; import '../provider/DiscuzNotificationProvider.dart'; import '../utility/EasyRefreshUtils.dart'; +import '../utility/UserPreferencesUtils.dart'; class PrivateMessagePortalScreen extends StatelessWidget { PrivateMessagePortalScreen(); @override Widget build(BuildContext context) { - // TODO: implement build return PrivateMessagePortalStatefulWidget(); } } @@ -54,10 +55,35 @@ class _PrivateMessagePortalState @override void initState() { - // TODO: implement initState super.initState(); + _loadPrivateMessageCache(); _controller = EasyRefreshController(controlFinishLoad: true, controlFinishRefresh: true); + } + + Future _loadPrivateMessageCache() async{ + log("Load private message cache"); + Discuz? discuz = + Provider.of(context, listen: false).discuz; + User? user = + Provider.of(context, listen: false).user; + if(discuz!= null && user!= null){ + String jsonString = await UserPreferencesUtils.getDiscuzPrivateMessageResultCacheJson(discuz, user!); + try{ + PrivateMessagePortalResult cacheResult = PrivateMessagePortalResult.fromJson(jsonDecode(jsonString)); + log("Set state ->"); + setState(() { + result = cacheResult; + _pmList = cacheResult.variables.pmList; + }); + } + catch(e,s){ + log(e.toString()); + } + log("Load private message string -> ${jsonString}"); + + } + } Future _invalidateHotThreadContent(Discuz discuz) async { @@ -78,12 +104,18 @@ class _PrivateMessagePortalState // // }); Provider.of(context, listen: false).setNotificationCount(result.variables.noticeCount); - if(result.variables.count != 0 && _pmList.length >= result.variables.count){ - _controller.finishLoad(IndicatorResult.noMore); - return IndicatorResult.noMore; + // if(result.variables.count != 0 && _pmList.length >= result.variables.count){ + // _controller.finishLoad(IndicatorResult.noMore); + // return IndicatorResult.noMore; + // } + + if(user == null){ + return IndicatorResult.fail; } - return await _client.privateMessagePortalResult(_page).then((value) { + return await _client.privateMessagePortalResult(_page).then((value) async{ + String cacheString = jsonEncode(value.toJson()); + await UserPreferencesUtils.putDiscuzPrivateMessageResultCacheJson(discuz, user!, cacheString); setState(() { result = value; _error = null; @@ -93,11 +125,13 @@ class _PrivateMessagePortalState _pmList.addAll(value.variables.pmList); } }); + _page += 1; _controller.finishRefresh(); + // check for loaded all? - log("Get HotThread ${_pmList.length} ${value.variables.count}"); + log("Get pm list ${_pmList.length} ${value.variables.count}"); _controller.finishLoad(_pmList.length >= value.variables.count ? IndicatorResult.noMore : IndicatorResult.success); diff --git a/lib/utility/AppPlatformIcons.dart b/lib/utility/AppPlatformIcons.dart index 35e158c..6114503 100644 --- a/lib/utility/AppPlatformIcons.dart +++ b/lib/utility/AppPlatformIcons.dart @@ -158,4 +158,6 @@ class AppPlatformIcons{ IconData get userIncognitoSolid => isMaterial(context)? Icons.airplanemode_active : CupertinoIcons.eyeglasses; IconData get discuzSolid => isMaterial(context)? Icons.amp_stories : Icons.amp_stories; + + IconData get userProfileSolid => isMaterial(context)? Icons.person_outline : CupertinoIcons.person_crop_circle; } \ No newline at end of file diff --git a/lib/utility/UserPreferencesUtils.dart b/lib/utility/UserPreferencesUtils.dart index 96f0733..0cb6a9a 100644 --- a/lib/utility/UserPreferencesUtils.dart +++ b/lib/utility/UserPreferencesUtils.dart @@ -7,6 +7,8 @@ import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; import 'package:shared_preferences/shared_preferences.dart'; +import '../entity/User.dart'; + class UserPreferencesUtils{ static final String recordHistoryKey = "recordHistoryKey"; @@ -611,5 +613,17 @@ class UserPreferencesUtils{ await prefs.setString(discuzSmileyCacheJsonKey, value); } + static Future getDiscuzPrivateMessageResultCacheJson(Discuz discuz, User user) async { + String discuzSmileyCacheJsonKey = "discuz_private_message_caches_${discuz.baseURL}_${user.uid}"; + SharedPreferences prefs = await SharedPreferences.getInstance(); + var string = prefs.getString(discuzSmileyCacheJsonKey); + return string == null? "": string; + } + + static Future putDiscuzPrivateMessageResultCacheJson(Discuz discuz, User user,String value) async{ + String discuzSmileyCacheJsonKey = "discuz_private_message_caches_${discuz.baseURL}_${user.uid}"; + SharedPreferences prefs = await SharedPreferences.getInstance(); + await prefs.setString(discuzSmileyCacheJsonKey, value); + } } \ No newline at end of file diff --git a/lib/widget/PrivateMessagePortalWidget.dart b/lib/widget/PrivateMessagePortalWidget.dart index 6e90073..3780881 100644 --- a/lib/widget/PrivateMessagePortalWidget.dart +++ b/lib/widget/PrivateMessagePortalWidget.dart @@ -38,7 +38,7 @@ class PrivateMessagePortalWidget extends StatelessWidget{ elevation: 4.0, color: Theme.of(context).brightness == Brightness.light? Colors.white: Colors.white10, surfaceTintColor: Theme.of(context).brightness == Brightness.light? Colors.white: Colors.white10, - child: Padding(padding: EdgeInsets.all(4.0), + child: Padding(padding: EdgeInsets.zero, child: child, ), ), @@ -52,16 +52,22 @@ class PrivateMessagePortalWidget extends StatelessWidget{ ], ), - child: ListTile( - leading: UserAvatar(_discuz, _privateMessagePortal.toUid, _privateMessagePortal.toUserName, size: 36,), + child: PlatformListTile( + leading: UserAvatar(_discuz, _privateMessagePortal.toUid, _privateMessagePortal.toUserName, size: 48,), title: Text(_privateMessagePortal.subject, overflow: TextOverflow.ellipsis, - maxLines: 2, + style: TextStyle( + fontWeight: FontWeight.bold + ), + maxLines: 1, ), subtitle: Text( "${_privateMessagePortal.msgFromName}: ${_privateMessagePortal.message}", overflow: TextOverflow.ellipsis, + style: TextStyle( + fontWeight: FontWeight.w300 + ), maxLines: 1, ),