Update timeline "refresh" to reset the timeline, after prompting for confirmation.

main
Hank Grabowski 2023-11-27 09:39:38 -05:00
rodzic 251f408c98
commit b13b66ec48
3 zmienionych plików z 20 dodań i 18 usunięć

Wyświetl plik

@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:logging/logging.dart';
import 'package:provider/provider.dart';
import 'package:relatica/globals.dart';
import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';
import '../../models/TimelineIdentifiers.dart';
@ -15,16 +16,15 @@ class TimelinePanel extends StatelessWidget {
TimelinePanel({super.key, required this.timeline});
Future<void> update(TimelineManager manager) async {
await manager.updateTimeline(
timeline,
TimelineRefreshType.refresh,
);
await manager.updateTimeline(
timeline,
TimelineRefreshType.loadNewer,
);
Future<void> update(BuildContext context, TimelineManager manager) async {
final confirm =
await showYesNoDialog(context, 'Reload timeline from scratch?');
if (confirm == true) {
await manager.updateTimeline(
timeline,
TimelineRefreshType.refresh,
);
}
}
void scrollToTop() {
@ -41,7 +41,7 @@ class TimelinePanel extends StatelessWidget {
final items = manager.getTimeline(timeline);
return RefreshIndicator(
onRefresh: () async {
update(manager);
update(context, manager);
return;
},
child: items.isEmpty

Wyświetl plik

@ -1,12 +1,15 @@
import 'TimelineIdentifiers.dart';
import 'entry_tree_item.dart';
const defaultLowestId = 9223372036854775807;
const defaultHighestId = 0;
class Timeline {
final TimelineIdentifiers id;
final List<EntryTreeItem> _posts = [];
final Map<String, EntryTreeItem> _postsById = {};
int _lowestStatusId = 9223372036854775807;
int _highestStatusId = 0;
int _lowestStatusId = defaultLowestId;
int _highestStatusId = defaultHighestId;
int get highestStatusId => _highestStatusId;
@ -72,8 +75,8 @@ class Timeline {
void clear() {
_posts.clear();
_postsById.clear();
_lowestStatusId = 0;
_highestStatusId = 0;
_lowestStatusId = defaultLowestId;
_highestStatusId = defaultHighestId;
}
@override

Wyświetl plik

@ -192,9 +192,8 @@ class TimelineManager extends ChangeNotifier {
late final int highestId;
switch (refreshType) {
case TimelineRefreshType.refresh:
lowestId = timeline.highestStatusId == 0
? timeline.highestStatusId
: timeline.highestStatusId + 1;
timeline.clear();
lowestId = 0;
highestId = 0;
break;
case TimelineRefreshType.loadOlder: