Skip to content

Commit

Permalink
Merge pull request #71 from Meatysoda/master
Browse files Browse the repository at this point in the history
Feat: add history record page
  • Loading branch information
Jackiu1997 authored May 16, 2023
2 parents 7808a00 + fc087b9 commit 0e7b485
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 3 deletions.
3 changes: 3 additions & 0 deletions lib/common/l10n/generated/intl/messages_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ class MessageLookup extends MessageLookupByLibrary {
"Please follow live rooms first"),
"empty_favorite_title":
MessageLookupByLibrary.simpleMessage("No Favorites"),
"empty_history":
MessageLookupByLibrary.simpleMessage("No history here"),
"empty_live_subtitle": MessageLookupByLibrary.simpleMessage(
"Click the button below\nto switch platform"),
"empty_live_title":
Expand Down Expand Up @@ -154,6 +156,7 @@ class MessageLookup extends MessageLookupByLibrary {
"help": MessageLookupByLibrary.simpleMessage("Help"),
"hide_offline_rooms":
MessageLookupByLibrary.simpleMessage("Hide Offline Rooms"),
"history": MessageLookupByLibrary.simpleMessage("History"),
"info_is_offline": m0,
"info_is_replay": m1,
"issue_feedback":
Expand Down
2 changes: 2 additions & 0 deletions lib/common/l10n/generated/intl/messages_zh_CN.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class MessageLookup extends MessageLookupByLibrary {
"empty_favorite_subtitle":
MessageLookupByLibrary.simpleMessage("请先关注其他直播间"),
"empty_favorite_title": MessageLookupByLibrary.simpleMessage("无关注直播"),
"empty_history": MessageLookupByLibrary.simpleMessage("无观看历史记录"),
"empty_live_subtitle":
MessageLookupByLibrary.simpleMessage("请点击下方按钮切换平台"),
"empty_live_title": MessageLookupByLibrary.simpleMessage("未发现直播"),
Expand Down Expand Up @@ -132,6 +133,7 @@ class MessageLookup extends MessageLookupByLibrary {
"github": MessageLookupByLibrary.simpleMessage("Github"),
"help": MessageLookupByLibrary.simpleMessage("帮助"),
"hide_offline_rooms": MessageLookupByLibrary.simpleMessage("隐藏未直播的直播间"),
"history": MessageLookupByLibrary.simpleMessage("历史记录"),
"info_is_offline": m0,
"info_is_replay": m1,
"issue_feedback": MessageLookupByLibrary.simpleMessage("问题反馈"),
Expand Down
20 changes: 20 additions & 0 deletions lib/common/l10n/generated/l10n.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion lib/common/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,9 @@

"play_video_failed": "Play Video Failed",
"retry": "Retry",
"replay": "REPLAY"
"replay": "REPLAY",


"history": "History",
"empty_history": "No history here"
}
6 changes: 5 additions & 1 deletion lib/common/l10n/intl_zh_CN.arb
Original file line number Diff line number Diff line change
Expand Up @@ -152,5 +152,9 @@

"play_video_failed": "无法播放直播",
"retry": "重试",
"replay": "录播"
"replay": "录播",


"history": "历史记录",
"empty_history": "无观看历史记录"
}
35 changes: 35 additions & 0 deletions lib/common/services/settings_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ class SettingsService extends GetxController {
favoriteAreas.map<String>((e) => jsonEncode(e.toJson())).toList());
});

historyRooms.listen((rooms) {
PrefUtil.setStringList('historyRooms',
historyRooms.map<String>((e) => jsonEncode(e.toJson())).toList());
});

backupDirectory.listen((String value) {
backupDirectory.value = value;
PrefUtil.setString('backupDirectory', value);
Expand All @@ -52,7 +57,9 @@ class SettingsService extends GetxController {
"Light": ThemeMode.light,
};
final themeModeName = (PrefUtil.getString('themeMode') ?? "System").obs;

get themeMode => SettingsService.themeModes[themeModeName.value]!;

void changeThemeMode(String mode) {
themeModeName.value = mode;
PrefUtil.setString('themeMode', mode);
Expand All @@ -73,7 +80,9 @@ class SettingsService extends GetxController {
"Orchid": const Color.fromARGB(255, 218, 112, 214),
};
final themeColorName = (PrefUtil.getString('themeColor') ?? "Blue").obs;

get themeColor => SettingsService.themeColors[themeColorName.value]!;

void changeThemeColor(String color) {
themeColorName.value = color;
PrefUtil.setString('themeColor', color);
Expand All @@ -84,7 +93,9 @@ class SettingsService extends GetxController {
"简体中文": const Locale.fromSubtags(languageCode: 'zh', countryCode: 'CN'),
};
final languageName = (PrefUtil.getString('language') ?? "简体中文").obs;

get language => SettingsService.languages[languageName.value]!;

void changeLanguage(String value) {
languageName.value = value;
PrefUtil.setString('language', value);
Expand Down Expand Up @@ -115,6 +126,7 @@ class SettingsService extends GetxController {
static const List<String> resolutions = ['原画', '蓝光8M', '蓝光4M', '超清', '流畅'];
final preferResolution =
(PrefUtil.getString('preferResolution') ?? resolutions[0]).obs;

void changePreferResolution(String name) {
if (resolutions.indexWhere((e) => e == name) != -1) {
preferResolution.value = name;
Expand All @@ -125,6 +137,7 @@ class SettingsService extends GetxController {
static const List<String> platforms = ['bilibili', 'douyu', 'huya'];
final preferPlatform =
(PrefUtil.getString('preferPlatform') ?? platforms[0]).obs;

void changePreferPlatform(String name) {
if (platforms.indexWhere((e) => e == name) != -1) {
preferPlatform.value = name;
Expand All @@ -139,6 +152,11 @@ class SettingsService extends GetxController {
.toList())
.obs;

final historyRooms = ((PrefUtil.getStringList('historyRooms') ?? [])
.map((e) => LiveRoom.fromJson(jsonDecode(e)))
.toList())
.obs;

bool isFavorite(LiveRoom room) {
return favoriteRooms.contains(room);
}
Expand All @@ -162,6 +180,23 @@ class SettingsService extends GetxController {
return true;
}

bool updateRoomInHistory(LiveRoom room) {
int idx = historyRooms.indexOf(room);
if (idx == -1) return false;
historyRooms[idx] = room;
return true;
}
void addRoomToHistory(LiveRoom room) {
if (historyRooms.contains(room)) {
historyRooms.remove(room);
}
//默认只记录20条,够用了
if (historyRooms.length > 19) {
historyRooms.removeRange(0, historyRooms.length - 19);
}
historyRooms.add(room);
}

// Favorite areas storage
final favoriteAreas = ((PrefUtil.getStringList('favoriteAreas') ?? [])
.map((e) => LiveArea.fromJson(jsonDecode(e)))
Expand Down
8 changes: 8 additions & 0 deletions lib/common/widgets/menu_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class MenuButton extends StatelessWidget {
AppPages.settings,
AppPages.about,
AppPages.contact,
AppPages.history,
];

@override
Expand Down Expand Up @@ -47,6 +48,13 @@ class MenuButton extends StatelessWidget {
leading: const Icon(Icons.contact_support),
text: S.of(context).contact,
),
),PopupMenuItem(
value: 3,
padding: const EdgeInsets.symmetric(horizontal: 12),
child: MenuListTile(
leading: const Icon(Icons.history),
text: S.of(context).history,
),
),
],
);
Expand Down
76 changes: 76 additions & 0 deletions lib/modules/history/history_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:get/get.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:pure_live/common/index.dart';

class HistoryPage extends GetView {
HistoryPage({Key? key}) : super(key: key);

final refreshController = RefreshController();

Future onRefresh() async {
bool result = true;
final SettingsService settings = Get.find<SettingsService>();

for (final room in settings.historyRooms) {
try {
var newRoom = await Sites.of(room.platform).liveSite.getRoomInfo(room);
settings.updateRoomInHistory(newRoom);
} catch (e) {
result = false;
}
}

if (result) {
refreshController.refreshCompleted();
} else {
refreshController.refreshFailed();
}
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: true,
scrolledUnderElevation: 0,
title: Text('${S.of(context).history}(20)'),
),
body: Obx(() {
final SettingsService settings = Get.find<SettingsService>();
const dense = true;
final rooms = settings.historyRooms.reversed.toList();
return LayoutBuilder(builder: (context, constraint) {
final width = constraint.maxWidth;
int crossAxisCount =
width > 1280 ? 4 : (width > 960 ? 3 : (width > 640 ? 2 : 1));
if (dense) {
crossAxisCount =
width > 1280 ? 5 : (width > 960 ? 4 : (width > 640 ? 3 : 2));
}
return SmartRefresher(
enablePullDown: true,
physics: const BouncingScrollPhysics(),
header: const WaterDropHeader(),
controller: refreshController,
onRefresh: onRefresh,
child: rooms.isEmpty
? EmptyView(
icon: Icons.history_rounded,
title: S.of(context).empty_history,
subtitle: '',
)
: MasonryGridView.count(
padding: const EdgeInsets.all(5),
controller: ScrollController(),
crossAxisCount: crossAxisCount,
itemCount: rooms.length,
itemBuilder: (context, index) =>
RoomCard(room: rooms[index], dense: dense),
),
);
});
}),
);
}
}
2 changes: 1 addition & 1 deletion lib/modules/live_play/live_play_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class LivePlayController extends GetxController {
);
success.value = true;
});
});
}).then((value) => settings.addRoomToHistory(room));

// start danmaku server
liveDanmaku.start(int.parse(
Expand Down
7 changes: 7 additions & 0 deletions lib/routes/app_pages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import 'package:pure_live/modules/settings/settings_binding.dart';
import 'package:pure_live/modules/settings/settings_page.dart';
import 'package:pure_live/modules/search/search_binding.dart';
import 'package:pure_live/modules/search/search_page.dart';
import 'package:pure_live/modules/history/history_page.dart';


class AppPages {
AppPages._();
Expand All @@ -33,6 +35,7 @@ class AppPages {
static const contact = '/contact';
static const backup = '/backup';
static const about = '/about';
static const history = '/history';
static const donate = '/donate';

static toAreaRooms(LiveArea area) {
Expand Down Expand Up @@ -65,6 +68,10 @@ class AppPages {
page: SettingsPage.new,
binding: SettingsBinding(),
),
GetPage(
name: history,
page: HistoryPage.new,
),
GetPage(
name: search,
page: SearchPage.new,
Expand Down

0 comments on commit 0e7b485

Please sign in to comment.