Commit c7849c50 authored by 杜欣's avatar 杜欣

Merge branch 'dx/message' of git.wanmeizhensuo.com:mobile/gmalpha_flutter into dx/message

# Conflicts:
#	lib/TestPage.dart
parents fc9ce87f acb5d115
......@@ -4,12 +4,14 @@
// RouterCenterGenerator
// **************************************************************************
//NewMessageRouterImpl is resign : true
//PrestigeImpl is resign : true
//BuriedImpl is resign : true
//AlbumRouterImpl is resign : true
//ActivityReportRouterImpl is resign : true
//MessageRouterImpl is resign : true
//UserRouterImpl is resign : true
import "package:gmalpha_flutter/NewMessageModel/NewMessageRouterImpl.dart";
import "package:gmalpha_flutter/NewMessageModel/NewMessageRouter.dart";
import "package:gmalpha_flutter/PrestigeModel/PrestigeImpl.dart";
......
......@@ -5,5 +5,6 @@ import 'package:gmalpha_flutter/NewMessageModel/NewMessageRouterImpl.dart';
@Router("NewMessageModel", NewMessageRouterImpl, true)
abstract class NewMessageRouter implements RouterBaser {
Widget getAttentionPage(String fromPage);
Widget getMessagePage(String fromPage);
}
\ No newline at end of file
import 'package:flutter/widgets.dart';
import 'package:gmalpha_flutter/NewMessageModel/NewMessageRouter.dart';
import 'package:gmalpha_flutter/newMessageModel/page/MessagePage.dart';
import 'package:gmalpha_flutter/NewMessageModel/page/AttentionPage.dart';
class NewMessageRouterImpl implements NewMessageRouter {
......@@ -8,4 +9,9 @@ class NewMessageRouterImpl implements NewMessageRouter {
Widget getMessagePage(String fromPage) {
return MessagePage(fromPage);
}
@override
Widget getAttentionPage(String fromPage) {
return AttentionPage(fromPage);
}
}
\ No newline at end of file
import 'package:flutter/material.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/AttentionEntity.dart';
import 'package:gmalpha_flutter/commonModel/ui/ALColors.dart';
import 'package:gmalpha_flutter/NewMessageModel/page/message_date.dart';
class AttentionListItem extends StatelessWidget {
final Data 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
Widget build(BuildContext context) {
return SizedBox(
child: Card(
elevation: 0.0,
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 5.0, left: 16.0, right: 10.0),
child: CircleAvatar(
radius: 21.0,
backgroundImage: NetworkImage(item.icon),
),
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
child: myText('${item.title}', ALColors.Color464646, 13.0, weight: true),
),
Padding(
padding: const EdgeInsets.only(top: 4.0),
child: myText('${item.content}', ALColors.Color666666, 13.0, maxLines: 2),
),
Padding(
padding: const EdgeInsets.only(top: 3.0),
child: myText(MessageDate(item.pushTime).diffTime(), ALColors.Color999999, 10.0)
)
],
),
),
Padding(
padding: const EdgeInsets.only(top: 4.0, left: 12.0, right: 16.0),
child: Container(
width: 54.0,
height: 29.0,
child: OutlineButton(
padding: const EdgeInsets.only(left: 0.0, right: 0.0,),
borderSide: BorderSide(
color: ALColors.Color323232
),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.zero),
onPressed: () {
// todo 跳转到原生页面 详情页面
},
child: myText('详情', ALColors.Color323232, 13.0)
),
)
)
],
),
),
);
}
}
import 'package:flutter/material.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/AttentionEntity.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/MessageRepository.dart';
import 'package:gmalpha_flutter/commonModel/live/BaseModel.dart';
import 'package:gmalpha_flutter/commonModel/live/LiveData.dart';
import 'package:gmalpha_flutter/commonModel/toast/toast.dart';
class AttentionModel extends BaseModel {
LiveData<AttentionEntity> zzgLive = new LiveData();
List<Data> _newList = [];
int page;
final int count = 10;
final String fromPage;
AttentionModel(this.page, this.fromPage);
init(BuildContext context, {Function callback}) {
// 初始化或者刷新的时候增加一项无用项,用来渲染列表title
if (page == 1) {
Data firstData = Data();
_newList.add(firstData);
}
MessageRepository.getInstance().getAttentionList(page, count).listen((value) {
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);
if (callback is Function) {
callback();
}
}
}).onError((error) {
Toast.show(context, "${error.toString()}");
print(error);
});
}
refresh(BuildContext context) {
page = 1;
_newList = [];
init(context);
}
more(BuildContext context, Function fun) {
page++;
init(context, callback: fun);
}
@override
void dispose() {
zzgLive.dispost();
}
}
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:gmalpha_flutter/NewMessageModel/page/AttentionModel.dart';
import 'package:gmalpha_flutter/NewMessageModel/page/AttentionListItem.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';
enum LoadStatus {
// 正在加载
LOADING,
// 加载完成
COMPLETE,
// 初始状态
INITIAL
}
class AttentionPage extends StatefulWidget {
final AttentionModel _model;
AttentionPage(String fromPage) : _model = AttentionModel(1, fromPage);
@override
_AttentionPageState createState() => _AttentionPageState(_model);
}
class _AttentionPageState extends BasePage<AttentionPage> {
LoadStatus loadStatus = LoadStatus.INITIAL;
List<Data> _noticeLists = [];
bool noData = false;
AttentionModel _model;
_AttentionPageState(this._model);
ScrollController _scrollController = ScrollController();
bool isPerformingRequest = false;
// 热更新代码
@override
void reassemble() {
super.reassemble();
_noticeLists = [];
_scrollController.jumpTo(0);
_model.refresh(context);
loadStatus = LoadStatus.INITIAL;
}
@override
void initState() {
super.initState();
_model.init(context);
// 监听ListView滚动,滚动到底部的时候加载更多
_scrollController.addListener(() {
if (noData == false
&& _scrollController.position.pixels
== _scrollController.position.maxScrollExtent) {
setState(() {
loadStatus = LoadStatus.LOADING;
});
_model.more(context, loadComplete);
}
});
}
void loadComplete() {
setState(() {
loadStatus = LoadStatus.COMPLETE;
});
}
@override
String pageName() {
return 'notice_list';
}
@override
String referrer() {
return _model.fromPage;
}
Widget buildNoticeitem(BuildContext context, int index) {
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(
padding: const EdgeInsets.all(10.0),
child: Center(
child: Text('暂时无更多数据'),
),
);
}
if (index == _noticeLists.length) {
return _buildProgressIndicator();
}
return Padding(
padding: const EdgeInsets.only(bottom: 21.0),
child: AttentionListItem(_noticeLists[index]),
);
}
Widget _buildProgressIndicator() {
return Opacity(
opacity: loadStatus == LoadStatus.LOADING ? 1.0 : 0.0,
child: Container(
color: Color(0xFFF4F3F8),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
width: 15.0,
height: 15.0,
child: CircularProgressIndicator(strokeWidth: 2.0),
),
Padding(
padding: const EdgeInsets.only(left: 6.0, top: 20.0, bottom: 20.0),
child: Text(
'加载中...',
style: TextStyle(
color: ALColors.Color999999,
fontSize: 14.0,
height: 1.07
),
),
)
],
)
),
);
}
Widget loadingItem() {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
CircularProgressIndicator(),
Padding(
padding: const EdgeInsets.all(10.0),
child: Text('加载中...'),
)
],
),
);
}
Widget errorItem(String reason) {
return Center(
child: Text("$reason"),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
elevation: 0.0,
leading: GestureDetector(
onTap: () {
Navigator.pop(context);
},
child: Padding(
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>(
stream: _model.zzgLive.stream,
initialData: _model.zzgLive.data,
builder: (context, data) {
if (data.data == null) {
return loadingItem();
}
if (data.data.error != 0 || data.data.data == null) {
return errorItem(data.data.message);
}
noData = data.data.noData;
_noticeLists = data.data.data;
isPerformingRequest = false;
return ListView.builder(
shrinkWrap: true,
controller: _scrollController,
itemCount: _noticeLists.length + 1,
itemBuilder: buildNoticeitem
);
},
)
);
}
@override
void 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
......@@ -3,6 +3,7 @@ import 'package:gmalpha_flutter/NewMessageModel/service/remote/MessageRemote.dar
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/LatestMessageEntity.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/MyMessageEntity.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/UnreadMessageEntity.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/AttentionEntity.dart';
import 'package:rxdart/rxdart.dart';
class MessageRepository {
......@@ -46,4 +47,12 @@ class MessageRepository {
return value;
});
}
Observable<AttentionEntity> getAttentionList(int page, int count) {
return _remote.getAttentionList(page, count).map((value) {
if (value != null) {
}
return value;
});
}
}
\ No newline at end of file
......@@ -2,6 +2,7 @@ import 'package:gmalpha_flutter/NewMessageModel/service/remote/api/MessageApi.se
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/LatestMessageEntity.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/MyMessageEntity.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/UnreadMessageEntity.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/AttentionEntity.dart';
import 'package:rxdart/rxdart.dart';
class MessageRemote {
......@@ -27,4 +28,8 @@ class MessageRemote {
Observable<LatestMessageEntity> getLatestMessage() {
return MessageApiImpl().getLatestMessage();
}
Observable<AttentionEntity> getAttentionList(int page, int count) {
return MessageApiImpl().getAttentionList(page, count);
}
}
......@@ -2,9 +2,11 @@
import 'package:gmalpha_flutter/Annotations/anno/Get.dart';
import 'package:gmalpha_flutter/Annotations/anno/Query.dart';
import 'package:gmalpha_flutter/Annotations/anno/ServiceCenter.dart';
import 'package:gmalpha_flutter/newMessageModel/service/remote/entity/LatestMessageEntity.dart';
import 'package:gmalpha_flutter/newMessageModel/service/remote/entity/MyMessageEntity.dart';
import 'package:gmalpha_flutter/newMessageModel/service/remote/entity/UnreadMessageEntity.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/AttentionEntity.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/LatestMessageEntity.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/MyMessageEntity.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/UnreadMessageEntity.dart';
@ServiceCenter()
abstract class MessageApi{
......@@ -17,4 +19,7 @@ abstract class MessageApi{
@Get('api/v1/push/newest/info')
LatestMessageEntity getLatestMessage();
@Get('api/v1/message/notice')
AttentionEntity getAttentionList(@Query('page') int page, @Query('count') int count);
}
\ No newline at end of file
......@@ -8,10 +8,13 @@ import 'dart:convert';
import 'dart:io';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/LatestMessageEntity.dart';
import 'package:rxdart/rxdart.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/MyMessageEntity.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/UnreadMessageEntity.dart';
import 'package:rxdart/rxdart.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/LatestMessageEntity.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/AttentionEntity.dart';
import 'package:gmalpha_flutter/commonModel/net/DioUtil.dart';
class MessageApiImpl {
......@@ -58,4 +61,14 @@ class MessageApiImpl {
}
});
}
Observable<AttentionEntity> getAttentionList(int page, int count) {
return Observable.fromFuture(DioUtil().get('api/v1/message/notice',
data: {'page': page, 'count': count})).map((value) {
if (value != null && value.statusCode == 200) {
Map map = json.decode(value.toString());
return AttentionEntity.fromJson(map);
}
});
}
}
class AttentionEntity {
String message;
int error;
bool noData;
List<Data> data;
AttentionEntity({this.message, this.error, this.noData, this.data});
AttentionEntity.fromJson(Map<String, dynamic> json) {
message = json['message'];
error = json['error'];
noData = json['noData'];
if (json['data'] != null) {
data = new List<Data>();
json['data'].forEach((v) {
data.add(new Data.fromJson(v));
});
}
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['message'] = this.message;
data['error'] = this.error;
data['noData'] = this.noData;
if (this.data != null) {
data['data'] = this.data.map((v) => v.toJson()).toList();
}
return data;
}
}
class Data {
int id;
String title;
String content;
String url;
String icon;
double pushTime;
Data({this.id, this.title, this.content, this.url, this.icon, this.pushTime});
Data.fromJson(Map<String, dynamic> json) {
id = json['id'];
title = json['title'];
content = json['content'];
url = json['url'];
icon = json['icon'];
pushTime = json['push_time'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['id'] = this.id;
data['title'] = this.title;
data['content'] = this.content;
data['url'] = this.url;
data['icon'] = this.icon;
data['push_time'] = this.pushTime;
return data;
}
}
\ No newline at end of file
......@@ -28,6 +28,7 @@ class TestPage extends StatelessWidget {
presigePage(context),
albumPage(context),
userSettingPage(context),
attentionPage(context),
testMessagePage(context),
],
),
......@@ -47,10 +48,10 @@ class TestPage extends StatelessWidget {
testMessagePage(BuildContext context) {
return base(context, () {
Navigator.push(
context,
new CustomRoute(RouterCenterImpl()
.findNewMessageRouter()
?.getMessagePage('')));
context,
new CustomRoute(RouterCenterImpl()
.findNewMessageRouter()?.getMessagePage(''))
);
}, "消息页面");
}
......@@ -92,4 +93,14 @@ class TestPage extends StatelessWidget {
?.getUserSettingPage("241765462", "NULL")));
}, "设置页面");
}
attentionPage(BuildContext context) {
return base(context, () {
Navigator.push(
context,
new CustomRoute(RouterCenterImpl()
.findNewMessageRouter()?.getAttentionPage('message_home'))
);
}, "通知页面");
}
}
......@@ -23,4 +23,5 @@ class ALColors {
static const Color ColorF4F3F8 = Color(0xFFf4f3f8);
static const Color Color282828 = Color(0xFF282828);
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