Commit 1ec44043 authored by 何碧荣's avatar 何碧荣

增加like页

parent 670eabe0
......@@ -4,18 +4,18 @@
// RouterCenterGenerator
// **************************************************************************
import "package:gmalpha_flutter/NewMessageModel/NewMessageRouterImpl.dart";
import "package:gmalpha_flutter/NewMessageModel/NewMessageRouter.dart";
import "package:gmalpha_flutter/PrestigeModel/PrestigeImpl.dart";
import "package:gmalpha_flutter/PrestigeModel/PrestigeRouter.dart";
import "package:gmalpha_flutter/BuriedLib/BuriedImpl.dart";
import "package:gmalpha_flutter/BuriedLib/BuriedRouter.dart";
import "package:gmalpha_flutter/AlbumModel/AlbumRouterImpl.dart";
import "package:gmalpha_flutter/AlbumModel/AlbumRouter.dart";
import "package:gmalpha_flutter/ActivityReportModel/ActivityReportRouterImpl.dart";
import "package:gmalpha_flutter/ActivityReportModel/ActivityReportRouter.dart";
import "package:gmalpha_flutter/BuriedLib/BuriedImpl.dart";
import "package:gmalpha_flutter/BuriedLib/BuriedRouter.dart";
import "package:gmalpha_flutter/messageModel/MessageRouterImpl.dart";
import "package:gmalpha_flutter/messageModel/MessageRouter.dart";
import "package:gmalpha_flutter/NewMessageModel/NewMessageRouterImpl.dart";
import "package:gmalpha_flutter/NewMessageModel/NewMessageRouter.dart";
import "package:gmalpha_flutter/PrestigeModel/PrestigeImpl.dart";
import "package:gmalpha_flutter/PrestigeModel/PrestigeRouter.dart";
import "package:gmalpha_flutter/userModel/UserRouterImpl.dart";
import "package:gmalpha_flutter/userModel/UserRouter.dart";
......@@ -46,12 +46,12 @@ class RouterCenterImpl {
}
void init() {
map.putIfAbsent("NewMessageModel", () => NewMessageRouterImpl());
map.putIfAbsent("prestigeModel", () => PrestigeImpl());
map.putIfAbsent("buried_router", () => BuriedImpl());
map.putIfAbsent("albumModel", () => AlbumRouterImpl());
map.putIfAbsent("ActivityReportModel", () => ActivityReportRouterImpl());
map.putIfAbsent("buried_router", () => BuriedImpl());
map.putIfAbsent("messageModel", () => MessageRouterImpl());
map.putIfAbsent("NewMessageModel", () => NewMessageRouterImpl());
map.putIfAbsent("prestigeModel", () => PrestigeImpl());
map.putIfAbsent("userModel", () => UserRouterImpl());
}
......@@ -59,18 +59,18 @@ class RouterCenterImpl {
return map[modelName];
}
NewMessageRouter findNewMessageRouter() {
if (map["NewMessageModel"] == null) {
AlbumRouter findAlbumRouter() {
if (map["albumModel"] == null) {
return null;
}
return map["NewMessageModel"] as NewMessageRouter;
return map["albumModel"] as AlbumRouter;
}
PrestigeRouter findPrestigeRouter() {
if (map["prestigeModel"] == null) {
ActivityReportRouter findActivityReportRouter() {
if (map["ActivityReportModel"] == null) {
return null;
}
return map["prestigeModel"] as PrestigeRouter;
return map["ActivityReportModel"] as ActivityReportRouter;
}
BuriedRouter findBuriedRouter() {
......@@ -80,25 +80,25 @@ class RouterCenterImpl {
return map["buried_router"] as BuriedRouter;
}
AlbumRouter findAlbumRouter() {
if (map["albumModel"] == null) {
MessageRouter findMessageRouter() {
if (map["messageModel"] == null) {
return null;
}
return map["albumModel"] as AlbumRouter;
return map["messageModel"] as MessageRouter;
}
ActivityReportRouter findActivityReportRouter() {
if (map["ActivityReportModel"] == null) {
NewMessageRouter findNewMessageRouter() {
if (map["NewMessageModel"] == null) {
return null;
}
return map["ActivityReportModel"] as ActivityReportRouter;
return map["NewMessageModel"] as NewMessageRouter;
}
MessageRouter findMessageRouter() {
if (map["messageModel"] == null) {
PrestigeRouter findPrestigeRouter() {
if (map["prestigeModel"] == null) {
return null;
}
return map["messageModel"] as MessageRouter;
return map["prestigeModel"] as PrestigeRouter;
}
UserRouter findUserRouter() {
......
......@@ -6,4 +6,5 @@ import 'package:gmalpha_flutter/NewMessageModel/NewMessageRouterImpl.dart';
@Router("NewMessageModel", NewMessageRouterImpl)
abstract class NewMessageRouter implements RouterBaser {
Widget getMessagePage();
Widget getLikePage(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/likePage/LikePage.dart';
import 'package:gmalpha_flutter/newMessageModel/page/MessagePage.dart';
......@@ -8,4 +9,9 @@ class NewMessageRouterImpl implements NewMessageRouter {
Widget getMessagePage() {
return MessagePage();
}
@override
Widget getLikePage(String fromPage) {
return LikePage(fromPage);
}
}
\ No newline at end of file
import 'package:flutter/material.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/MessageRepository.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/LikePageEntity.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 LikeModel extends BaseModel()
\ No newline at end of file
class LikeModel extends BaseModel{
LiveData<LikePageEntity> likeLive = LiveData();
List<Data> _newList = [];
int page;
final int count = 10;
final String fromPage;
LikeModel(this.page, this.fromPage);
@override
void dispose() {
likeLive.dispost();
}
void init(BuildContext context,{Function callback}){
// 初始化或者刷新的时候增加一项无用项,用来渲染列表title
if (page == 1) {
Data firstData = Data();
_newList.add(firstData);
}
MessageRepository.getInstance()
.getLikePage(page, count)
.listen((value) {
if (value != null) {
likeLive.notifyView(value);
}
if (value != null) {
// 增加一个字段,用来判断是否还有数据
if (value.data.length == 0) {
value.noData = true;
} else {
value.noData = false;
}
_newList.addAll(value.data);
value.data = _newList;
likeLive.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);
}
}
import 'package:flutter/material.dart';
import 'package:gmalpha_flutter/NewMessageModel/page/likePage/LikeModel.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/LikePageEntity.dart';
import 'package:gmalpha_flutter/commonModel/base/BasePage.dart';
import 'package:gmalpha_flutter/commonModel/ui/ALColors.dart';
enum LoadStatus {
// 正在加载
LOADING,
// 加载完成
COMPLETE,
// 初始状态
INITIAL
}
class LikePage extends StatefulWidget {
LikePage({Key key}) : super(key: key);
final LikeModel _model;
LikePage(String fromPage) : _model = LikeModel(1, fromPage);
_LikePageState createState() => _LikePageState();
@override
_LikePageState createState() => _LikePageState(_model);
}
class _LikePageState extends State<LikePage> {
class _LikePageState extends BasePage<LikePage> {
LoadStatus loadStatus = LoadStatus.INITIAL;
List<Data> _likeLists = [];
bool noData = false;
LikeModel _model;
_LikePageState(this._model);
ScrollController _scrollController = ScrollController();
bool isPerformingRequest = false;
// 热更新代码
@override
void reassemble() {
super.reassemble();
_likeLists = [];
_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 'like_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: 5.0, left: 16.0, right: 16.0, bottom: 29.0),
child: Text(
'Like',
style: TextStyle(fontSize: 20.0, color: ALColors.Color323232),
),
),
Container(
margin: const EdgeInsets.only(left: 15.0, right: 15.0),
child: Divider(
height: 1.0,
color: ALColors.ColorE4E4E4,
),
)
],
);
}
// 最后一项是没有用的数据,用来渲染加载更多UI和暂无更多数据
if (index == _likeLists.length && noData == true) {
return Padding(
padding: const EdgeInsets.all(10.0),
child: Center(
child: Text('暂时无更多数据'),
),
);
}
if (index == _likeLists.length) {
return _buildProgressIndicator();
}
return Padding(
padding: const EdgeInsets.only(bottom: 16.0, top: 16.0, left: 15.0, right: 15.0),
child: AttentionListItem(_likeLists[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(
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
title: Text('like')
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: Column(),
body: StreamBuilder<LikePageEntity>(
stream: _model.likeLive.stream,
initialData: _model.likeLive.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;
_likeLists = data.data.data;
isPerformingRequest = false;
return ListView.builder(
shrinkWrap: true,
controller: _scrollController,
itemCount: _likeLists.length + 1,
itemBuilder: buildNoticeitem
);
},
)
);
}
}
\ No newline at end of file
@override
void dispose() {
super.dispose();
_model.dispose();
}
}
import 'package:gmalpha_flutter/NewMessageModel/service/local/MessageLocal.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/MessageRemote.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/LatestMessageEntity.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/LikePageEntity.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';
......@@ -46,4 +47,12 @@ class MessageRepository {
return value;
});
}
Observable<LikePageEntity> getLikePage(int page, int count) {
return _remote.getLikePage(page, count).map((value) {
if (value != null) {
}
return value;
});
}
}
\ No newline at end of file
import 'package:gmalpha_flutter/NewMessageModel/service/remote/api/MessageApi.serv.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/LatestMessageEntity.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/LikePageEntity.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';
......@@ -27,4 +28,8 @@ class MessageRemote {
Observable<LatestMessageEntity> getLatestMessage() {
return MessageApiImpl().getLatestMessage();
}
Observable<LikePageEntity> getLikePage(int page, int count) {
return MessageApiImpl().getLikePage(page, count);
}
}
......@@ -2,9 +2,10 @@
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/LatestMessageEntity.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/LikePageEntity.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 +18,7 @@ abstract class MessageApi{
@Get('api/v1/push/newest/info')
LatestMessageEntity getLatestMessage();
@Get("api/v1/message/like")
LikePageEntity getLikePage(@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/LikePageEntity.dart';
import 'package:gmalpha_flutter/commonModel/net/DioUtil.dart';
class MessageApiImpl {
......@@ -58,4 +61,14 @@ class MessageApiImpl {
}
});
}
Observable<LikePageEntity> getLikePage(int page, int count) {
return Observable.fromFuture(DioUtil().get('api/v1/message/like',
data: {'page': page, 'count': count})).map((value) {
if (value != null && value.statusCode == 200) {
Map map = json.decode(value.toString());
return LikePageEntity.fromJson(map);
}
});
}
}
class LikePageEntity {
int error;
String message;
Null extra;
List<Data> data;
LikePageEntity({this.error, this.message, this.extra, this.data});
LikePageEntity.fromJson(Map<String, dynamic> json) {
error = json['error'];
message = json['message'];
extra = json['extra'];
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['error'] = this.error;
data['message'] = this.message;
data['extra'] = this.extra;
if (this.data != null) {
data['data'] = this.data.map((v) => v.toJson()).toList();
}
return data;
}
}
class Data {
int type;
int id;
String content;
int userId;
String icon;
bool unread;
String name;
double time;
LikeContent likeContent;
Data(
{this.type,
this.id,
this.content,
this.userId,
this.icon,
this.unread,
this.name,
this.time,
this.likeContent});
Data.fromJson(Map<String, dynamic> json) {
type = json['type'];
id = json['id'];
content = json['content'];
userId = json['user_id'];
icon = json['icon'];
unread = json['unread'];
name = json['name'];
time = json['time'];
likeContent = json['like_content'] != null
? new LikeContent.fromJson(json['like_content'])
: null;
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['type'] = this.type;
data['id'] = this.id;
data['content'] = this.content;
data['user_id'] = this.userId;
data['icon'] = this.icon;
data['unread'] = this.unread;
data['name'] = this.name;
data['time'] = this.time;
if (this.likeContent != null) {
data['like_content'] = this.likeContent.toJson();
}
return data;
}
}
class LikeContent {
int type;
int id;
int contentType;
String content;
LikeContent({this.type, this.id, this.contentType, this.content});
LikeContent.fromJson(Map<String, dynamic> json) {
type = json['type'];
id = json['id'];
contentType = json['content_type'];
content = json['content'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['type'] = this.type;
data['id'] = this.id;
data['content_type'] = this.contentType;
data['content'] = this.content;
return data;
}
}
\ No newline at end of file
......@@ -98,10 +98,10 @@ class _MyAppState extends State<MyApp> {
// return RouterCenterImpl()
// .findActivityReportRouter()
// ?.getActivityReportPage(279, 1, '');
return RouterCenterImpl()
.findAlbumRouter()
.getAlbumPage("com.example.gengmei_flutter_plugin_example",true, 2, null);
//return RouterCenterImpl().findNewMessageRouter().getMessagePage();
// return RouterCenterImpl()
// .findAlbumRouter()
// .getAlbumPage("com.example.gengmei_flutter_plugin_example",true, 2, null);
return RouterCenterImpl().findNewMessageRouter()?.getLikePage('1');
},
},
......
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