Commit 90b5b8f5 authored by 郑智刚's avatar 郑智刚

消息模块 通知页面

parent 45af5021
...@@ -4,12 +4,14 @@ ...@@ -4,12 +4,14 @@
// RouterCenterGenerator // RouterCenterGenerator
// ************************************************************************** // **************************************************************************
//NewMessageRouterImpl is resign : true
//PrestigeImpl is resign : true //PrestigeImpl is resign : true
//BuriedImpl is resign : true //BuriedImpl is resign : true
//AlbumRouterImpl is resign : true //AlbumRouterImpl is resign : true
//ActivityReportRouterImpl is resign : true //ActivityReportRouterImpl is resign : true
//MessageRouterImpl is resign : true //MessageRouterImpl is resign : true
//UserRouterImpl is resign : true //UserRouterImpl is resign : true
import "package:gmalpha_flutter/NewMessageModel/NewMessageRouterImpl.dart"; import "package:gmalpha_flutter/NewMessageModel/NewMessageRouterImpl.dart";
import "package:gmalpha_flutter/NewMessageModel/NewMessageRouter.dart"; import "package:gmalpha_flutter/NewMessageModel/NewMessageRouter.dart";
import "package:gmalpha_flutter/PrestigeModel/PrestigeImpl.dart"; import "package:gmalpha_flutter/PrestigeModel/PrestigeImpl.dart";
......
...@@ -7,5 +7,5 @@ import 'package:gmalpha_flutter/NewMessageModel/NewMessageRouterImpl.dart'; ...@@ -7,5 +7,5 @@ import 'package:gmalpha_flutter/NewMessageModel/NewMessageRouterImpl.dart';
abstract class NewMessageRouter implements RouterBaser { abstract class NewMessageRouter implements RouterBaser {
Widget getMessagePage(); Widget getMessagePage();
Widget getAttentionPage(); Widget getAttentionPage(String fromPage);
} }
\ No newline at end of file
...@@ -11,7 +11,7 @@ class NewMessageRouterImpl implements NewMessageRouter { ...@@ -11,7 +11,7 @@ class NewMessageRouterImpl implements NewMessageRouter {
} }
@override @override
Widget getAttentionPage() { Widget getAttentionPage(String fromPage) {
return AttentionPage(); return AttentionPage(fromPage);
} }
} }
\ No newline at end of file
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/AttentionEntity.dart'; import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/AttentionEntity.dart';
import 'package:gmalpha_flutter/commonModel/ui/ALColors.dart'; import 'package:gmalpha_flutter/commonModel/ui/ALColors.dart';
import 'package:gmalpha_flutter/NewMessageModel/page/message_date.dart';
class AttentionListItem extends StatelessWidget { class AttentionListItem extends StatelessWidget {
var item; final Data item;
AttentionListItem(this.item); AttentionListItem(this.item);
Text myText(
String text,
Color color,
double size,
{int maxLines = 1, bool weight = false}
) {
return Text(
text,
softWrap: true,
maxLines: maxLines,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: size,
color: color,
height: 1.38,
fontWeight: weight ? FontWeight.bold : FontWeight.normal
),
);
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return SizedBox( return SizedBox(
child: Card( child: Card(
elevation: 0.0, elevation: 0.0,
child: Row( child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[ children: <Widget>[
Padding( Padding(
padding: const EdgeInsets.only(left: 16.0, right: 10.0), padding: const EdgeInsets.only(top: 5.0, left: 16.0, right: 10.0),
child: CircleAvatar( child: CircleAvatar(
radius: 21.0, radius: 21.0,
backgroundImage: NetworkImage(item.icon), backgroundImage: NetworkImage(item.icon),
...@@ -24,37 +47,21 @@ class AttentionListItem extends StatelessWidget { ...@@ -24,37 +47,21 @@ class AttentionListItem extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[ children: <Widget>[
Container( Container(
child: Text( child: myText('${item.title}', ALColors.Color464646, 13.0, weight: true),
'${item.title}',
style: TextStyle(
color: ALColors.Color323232,
fontSize: 13.0
),
),
), ),
Container( Padding(
child: Text( padding: const EdgeInsets.only(top: 4.0),
'${item.content}', child: myText('${item.content}', ALColors.Color666666, 13.0, maxLines: 2),
style: TextStyle(
color: ALColors.Color323232,
fontSize: 13.0
),
),
), ),
Container( Padding(
child: Text( padding: const EdgeInsets.only(top: 3.0),
'${item.pushTime}', child: myText(MessageDate(item.pushTime).diffTime(), ALColors.Color999999, 10.0)
style: TextStyle(
color: ALColors.Color8E8E8E,
fontSize: 10.0
),
),
) )
], ],
), ),
), ),
Padding( Padding(
padding: const EdgeInsets.only(left: 12.0, right: 16.0), padding: const EdgeInsets.only(top: 4.0, left: 12.0, right: 16.0),
child: Container( child: Container(
width: 54.0, width: 54.0,
height: 29.0, height: 29.0,
...@@ -65,15 +72,9 @@ class AttentionListItem extends StatelessWidget { ...@@ -65,15 +72,9 @@ class AttentionListItem extends StatelessWidget {
), ),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.zero), shape: RoundedRectangleBorder(borderRadius: BorderRadius.zero),
onPressed: () { onPressed: () {
// TODO 跳转到详情页面 // todo 跳转到原生页面 详情页面
}, },
child: Text( child: myText('详情', ALColors.Color323232, 13.0)
'详情',
style: TextStyle(
color: ALColors.Color323232,
fontSize: 13.0
),
),
), ),
) )
) )
......
/*
* @author zzg
* @date 2019-09-16
**/
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/AttentionEntity.dart'; import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/AttentionEntity.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/MessageRepository.dart'; import 'package:gmalpha_flutter/NewMessageModel/service/MessageRepository.dart';
...@@ -11,16 +7,30 @@ import 'package:gmalpha_flutter/commonModel/toast/toast.dart'; ...@@ -11,16 +7,30 @@ import 'package:gmalpha_flutter/commonModel/toast/toast.dart';
class AttentionModel extends BaseModel { class AttentionModel extends BaseModel {
LiveData<AttentionEntity> zzgLive = new LiveData(); LiveData<AttentionEntity> zzgLive = new LiveData();
List<Data> _newList = [];
int page; int page;
int count; final int count = 10;
final String fromPage;
AttentionModel(this.page, this.count); AttentionModel(this.page, this.fromPage);
init(BuildContext context) { init(BuildContext context) {
page = 1; // 初始化或者刷新的时候增加一项无用项,用来渲染列表title
if (page == 1) {
Data firstData = Data();
_newList.add(firstData);
}
MessageRepository.getInstance().getAttentionList(page, count).listen((value) { MessageRepository.getInstance().getAttentionList(page, count).listen((value) {
if (value != null) { if (value != null) {
// 增加一个字段,用来判断是否还有数据
if (value.data.length == 0) {
value.noData = true;
} else {
value.noData = false;
}
_newList.addAll(value.data);
value.data = _newList;
zzgLive.notifyView(value); zzgLive.notifyView(value);
} }
}).onError((error) { }).onError((error) {
...@@ -29,7 +39,13 @@ class AttentionModel extends BaseModel { ...@@ -29,7 +39,13 @@ class AttentionModel extends BaseModel {
}); });
} }
more (BuildContext context) { refresh(BuildContext context) {
page = 1;
_newList = [];
init(context);
}
more(BuildContext context) {
page++; page++;
init(context); init(context);
} }
......
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_boost/flutter_boost.dart'; import 'package:flutter_svg/flutter_svg.dart';
// import 'package:flutter_svg/flutter_svg.dart';
import 'package:gmalpha_flutter/NewMessageModel/page/AttentionModel.dart'; import 'package:gmalpha_flutter/NewMessageModel/page/AttentionModel.dart';
import 'package:gmalpha_flutter/NewMessageModel/page/AttentionListItem.dart'; import 'package:gmalpha_flutter/NewMessageModel/page/AttentionListItem.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/AttentionEntity.dart'; import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/AttentionEntity.dart';
import 'package:gmalpha_flutter/commonModel/base/BasePage.dart';
import 'package:gmalpha_flutter/commonModel/ui/ALColors.dart';
class AttentionPage extends StatefulWidget { class AttentionPage extends StatefulWidget {
AttentionModel _model; final AttentionModel _model;
AttentionPage() { AttentionPage(String fromPage) : _model = AttentionModel(1, fromPage);
_model = AttentionModel(1, 10);
}
@override @override
_AttentionPageState createState() => _AttentionPageState(_model); _AttentionPageState createState() => _AttentionPageState(_model);
} }
class _AttentionPageState extends State<AttentionPage> { class _AttentionPageState extends BasePage<AttentionPage> {
List _noticeLists = []; List<Data> _noticeLists = [];
List _newList = []; bool noData = false;
AttentionModel _model; AttentionModel _model;
_AttentionPageState(this._model); _AttentionPageState(this._model);
ScrollController _scrollController = ScrollController(); ScrollController _scrollController = ScrollController();
bool isPerformingRequest = false; bool isPerformingRequest = false;
// 热更新代码
@override @override
void reassemble() { void reassemble() {
super.reassemble(); super.reassemble();
_model.init(context); _noticeLists = [];
setState(() { _scrollController.jumpTo(0);
_noticeLists = []; _model.refresh(context);
});
} }
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_model.init(context); _model.init(context);
// 监听ListView滚动,滚动到底部的时候加载更多
_scrollController.addListener(() { _scrollController.addListener(() {
if (_scrollController.position.pixels == _scrollController.position.maxScrollExtent) { if (noData == false
&& _scrollController.position.pixels
== _scrollController.position.maxScrollExtent) {
_model.more(context); _model.more(context);
} }
}); });
} }
@override
String pageName() {
return 'notice_list';
}
@override
String referrer() {
return _model.fromPage;
}
Widget buildNoticeitem(BuildContext context, int index) { Widget buildNoticeitem(BuildContext context, int index) {
if (index == _noticeLists.length && _newList.length == 0) { if (index == 0) {
// 第一项是没有用的数据,用来渲染裂变的title-通知
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 16.0, left: 16.0, right: 16.0, bottom: 10.0),
child: Text(
'通知',
style: TextStyle(fontSize: 20.0, color: ALColors.Color323232),
),
),
Divider(
color: ALColors.ColorE4E4E4,
),
],
);
}
// 最后一项是没有用的数据,用来渲染加载更多UI和暂无更多数据
if (index == _noticeLists.length && noData == true) {
return Padding( return Padding(
padding: const EdgeInsets.all(10.0), padding: const EdgeInsets.all(10.0),
child: Center( child: Center(
...@@ -62,22 +93,33 @@ class _AttentionPageState extends State<AttentionPage> { ...@@ -62,22 +93,33 @@ class _AttentionPageState extends State<AttentionPage> {
} }
Widget _buildProgressIndicator() { Widget _buildProgressIndicator() {
return Padding( return Container(
padding: const EdgeInsets.all(8.0), color: Color(0xFFF4F3F8),
child: Row( child: Padding(
mainAxisAlignment: MainAxisAlignment.center, padding: const EdgeInsets.all(20.0),
children: <Widget>[ child: Row(
Container( mainAxisAlignment: MainAxisAlignment.center,
width: 15.0, crossAxisAlignment: CrossAxisAlignment.center,
height: 15.0, children: <Widget>[
child: CircularProgressIndicator(strokeWidth: 2.0), Container(
), width: 15.0,
Padding( height: 15.0,
padding: const EdgeInsets.only(left: 5.0), child: CircularProgressIndicator(strokeWidth: 2.0),
child: Text('加载中...'), ),
) Padding(
], padding: const EdgeInsets.only(left: 6.0),
) child: Text(
'加载中...',
style: TextStyle(
color: ALColors.Color999999,
fontSize: 14.0,
height: 1.07
),
),
)
],
)
),
); );
} }
...@@ -86,26 +128,28 @@ class _AttentionPageState extends State<AttentionPage> { ...@@ -86,26 +128,28 @@ class _AttentionPageState extends State<AttentionPage> {
return Scaffold( return Scaffold(
backgroundColor: Colors.white, backgroundColor: Colors.white,
appBar: AppBar( appBar: AppBar(
centerTitle: true, elevation: 0.0,
leading: GestureDetector( leading: GestureDetector(
onTap: () { onTap: () {
FlutterBoost.singleton.closePageForContext(context); Navigator.pop(context);
}, },
child: Center( child: Padding(
// child: SvgPicture.asset("images/left_arrow.svg", color: Color(0xff323232)), padding: const EdgeInsets.only(top: 10.0, right: 10.0, bottom: 10.0),
), child: Center(
child: SvgPicture.asset("images/left_arrow.svg", color: Color(0xff323232)),
),
)
), ),
), ),
body: StreamBuilder<AttentionEntity>( body: StreamBuilder<AttentionEntity>(
stream: _model.zzgLive.stream, stream: _model.zzgLive.stream,
initialData: _model.zzgLive.data, initialData: _model.zzgLive.data,
builder: (context, data) { builder: (context, data) {
_newList = data.data.data; noData = data.data.noData;
for (var item in data.data.data) { _noticeLists = data.data.data;
_noticeLists.add(item);
}
isPerformingRequest = false; isPerformingRequest = false;
return ListView.builder( return ListView.builder(
shrinkWrap: true,
controller: _scrollController, controller: _scrollController,
itemCount: _noticeLists.length + 1, itemCount: _noticeLists.length + 1,
itemBuilder: buildNoticeitem itemBuilder: buildNoticeitem
...@@ -118,5 +162,6 @@ class _AttentionPageState extends State<AttentionPage> { ...@@ -118,5 +162,6 @@ class _AttentionPageState extends State<AttentionPage> {
@override @override
void dispose() { void dispose() {
super.dispose(); super.dispose();
_model.dispose();
} }
} }
\ No newline at end of file
class MessageDate {
final double time;
int _currentDate;
MessageDate(this.time);
String diffTime () {
var date = DateTime.now();
int serverTime = (time * 1000).toInt();
_currentDate = date.millisecondsSinceEpoch;
int minuteDifference = ((_currentDate - serverTime) / 1000 / 60).floor();
int hourDifference = ((_currentDate - serverTime) / 1000 / 60 / 60).ceil();
int dayDifference = ((_currentDate - serverTime) / 1000 / 60 / 60 / 24).ceil();
if (hourDifference < 24) {
if (minuteDifference < 1) {
return '刚刚';
} else if (minuteDifference < 60) {
return '$minuteDifference分钟前';
}
return '$hourDifference小时前';
} else if (hourDifference > 24 && hourDifference < 48) {
return '昨天前';
} else {
int currentYear = DateTime.fromMillisecondsSinceEpoch(serverTime).year;
int currentDay = DateTime.fromMillisecondsSinceEpoch(serverTime).day;
int currentMonth = DateTime.fromMillisecondsSinceEpoch(serverTime).month;
String currentDay2 = currentDay < 10 ? '0$currentDay' : '$currentDay';
String currentMonth2 = currentMonth < 10 ? '0$currentMonth' : '$currentMonth';
if (dayDifference < 365) {
return '$currentMonth2-$currentDay2';
} else {
return '$currentYear-$currentMonth2-$currentDay2';
}
}
}
}
\ No newline at end of file
class AttentionEntity { class AttentionEntity {
String message; String message;
int error; int error;
bool noData;
List<Data> data; List<Data> data;
AttentionEntity({this.message, this.error, this.data}); AttentionEntity({this.message, this.error, this.noData, this.data});
AttentionEntity.fromJson(Map<String, dynamic> json) { AttentionEntity.fromJson(Map<String, dynamic> json) {
message = json['message']; message = json['message'];
error = json['error']; error = json['error'];
noData = json['noData'];
if (json['data'] != null) { if (json['data'] != null) {
data = new List<Data>(); data = new List<Data>();
json['data'].forEach((v) { json['data'].forEach((v) {
...@@ -20,6 +22,7 @@ class AttentionEntity { ...@@ -20,6 +22,7 @@ class AttentionEntity {
final Map<String, dynamic> data = new Map<String, dynamic>(); final Map<String, dynamic> data = new Map<String, dynamic>();
data['message'] = this.message; data['message'] = this.message;
data['error'] = this.error; data['error'] = this.error;
data['noData'] = this.noData;
if (this.data != null) { if (this.data != null) {
data['data'] = this.data.map((v) => v.toJson()).toList(); data['data'] = this.data.map((v) => v.toJson()).toList();
} }
......
...@@ -27,6 +27,7 @@ class TestPage extends StatelessWidget { ...@@ -27,6 +27,7 @@ class TestPage extends StatelessWidget {
presigePage(context), presigePage(context),
albumPage(context), albumPage(context),
userSettingPage(context), userSettingPage(context),
attentionPage(context)
], ],
), ),
...@@ -83,4 +84,12 @@ class TestPage extends StatelessWidget { ...@@ -83,4 +84,12 @@ class TestPage extends StatelessWidget {
?.getUserSettingPage("241765327", "NULL"), ?.getUserSettingPage("241765327", "NULL"),
"设置页面"); "设置页面");
} }
attentionPage(BuildContext context) {
return base(
context,
RouterCenterImpl()
.findNewMessageRouter()?.getAttentionPage('message_home'),
"通知页面");
}
} }
...@@ -23,4 +23,5 @@ class ALColors { ...@@ -23,4 +23,5 @@ class ALColors {
static const Color ColorF4F3F8 = Color(0xFFf4f3f8); static const Color ColorF4F3F8 = Color(0xFFf4f3f8);
static const Color Color282828 = Color(0xFF282828); static const Color Color282828 = Color(0xFF282828);
static const Color ColorE5E5E5 = Color(0xFFe5e5e5); static const Color ColorE5E5E5 = Color(0xFFe5e5e5);
static const Color Color666666 = Color(0xFF666666);
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment