Skip to content

Commit

Permalink
add private interface update
Browse files Browse the repository at this point in the history
  • Loading branch information
kidozh committed Aug 13, 2024
1 parent 25594bd commit bf66049
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 15 deletions.
4 changes: 3 additions & 1 deletion lib/JsonResult/PrivateMessagePortalResult.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class PrivateMessagePortalResult extends BaseResult{
PrivateMessagePortalResult(){}

factory PrivateMessagePortalResult.fromJson(Map<String, dynamic> json) => _$PrivateMessagePortalResultFromJson(json);
Map<String, dynamic> toJson() => _$PrivateMessagePortalResultToJson(this);
}

@JsonSerializable()
Expand All @@ -33,7 +34,7 @@ class PrivateMessagePortalVariables extends BaseVariableResult{

PrivateMessagePortalVariables(){}
factory PrivateMessagePortalVariables.fromJson(Map<String, dynamic> json) => _$PrivateMessagePortalVariablesFromJson(json);

Map<String, dynamic> toJson() => _$PrivateMessagePortalVariablesToJson(this);
}

@JsonSerializable()
Expand Down Expand Up @@ -67,5 +68,6 @@ class PrivateMessagePortal{
PrivateMessagePortal();

factory PrivateMessagePortal.fromJson(Map<String, dynamic> json) => _$PrivateMessagePortalFromJson(json);
Map<String, dynamic> toJson() => _$PrivateMessagePortalToJson(this);
}

6 changes: 3 additions & 3 deletions lib/page/PrivateMessageDetailPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -71,7 +72,6 @@ class _PrivateMessageDetailState

@override
void initState() {
// TODO: implement initState
super.initState();
_controller = EasyRefreshController(controlFinishLoad: true, controlFinishRefresh: true);

Expand Down Expand Up @@ -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,
Expand Down
48 changes: 41 additions & 7 deletions lib/screen/PrivateMessagePortalScreen.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:convert';
import 'dart:developer';

import 'package:dio/dio.dart';
Expand All @@ -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();
}
}
Expand Down Expand Up @@ -54,10 +55,35 @@ class _PrivateMessagePortalState

@override
void initState() {
// TODO: implement initState
super.initState();
_loadPrivateMessageCache();
_controller = EasyRefreshController(controlFinishLoad: true, controlFinishRefresh: true);
}

Future<void> _loadPrivateMessageCache() async{
log("Load private message cache");
Discuz? discuz =
Provider.of<DiscuzAndUserNotifier>(context, listen: false).discuz;
User? user =
Provider.of<DiscuzAndUserNotifier>(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<IndicatorResult> _invalidateHotThreadContent(Discuz discuz) async {
Expand All @@ -78,12 +104,18 @@ class _PrivateMessagePortalState
//
// });
Provider.of<DiscuzNotificationProvider>(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;
Expand All @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions lib/utility/AppPlatformIcons.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
14 changes: 14 additions & 0 deletions lib/utility/UserPreferencesUtils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -611,5 +613,17 @@ class UserPreferencesUtils{
await prefs.setString(discuzSmileyCacheJsonKey, value);
}

static Future<String> 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<void> 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);
}

}
14 changes: 10 additions & 4 deletions lib/widget/PrivateMessagePortalWidget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
),
Expand All @@ -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,
),

Expand Down

0 comments on commit bf66049

Please sign in to comment.