unread posts tab
This commit is contained in:
parent
72f61ea804
commit
3b44a0f535
138
lib/main.dart
138
lib/main.dart
|
@ -1,5 +1,6 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:feet/widgets/centered_page_hint.dart';
|
||||
import 'package:feet/widgets/homepage_post.dart';
|
||||
import 'package:feet/widgets/login_prompt.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
@ -20,8 +21,7 @@ class MyApp extends StatelessWidget {
|
|||
Future<bool> _loadPrefs() async {
|
||||
var prefs = await SharedPreferences.getInstance();
|
||||
this.prefs = prefs;
|
||||
var apiKey = prefs.getString('apiKey'),
|
||||
apiUrl = prefs.getString('apiUrl');
|
||||
var apiKey = prefs.getString('apiKey'), apiUrl = prefs.getString('apiUrl');
|
||||
|
||||
if (apiUrl != null && apiKey != null) {
|
||||
api.apiUrl = apiUrl;
|
||||
|
@ -36,26 +36,28 @@ class MyApp extends StatelessWidget {
|
|||
Widget build(BuildContext context) {
|
||||
return DynamicColorBuilder(
|
||||
builder: ((lightDynamic, darkDynamic) => MaterialApp(
|
||||
title: 'Feet',
|
||||
theme: ThemeData(
|
||||
brightness: Brightness.light,
|
||||
useMaterial3: true,
|
||||
colorScheme: lightDynamic,
|
||||
),
|
||||
darkTheme: ThemeData(
|
||||
brightness: Brightness.dark,
|
||||
useMaterial3: true,
|
||||
colorScheme: darkDynamic,
|
||||
),
|
||||
themeMode: ThemeMode.system,
|
||||
home: FutureBuilder<bool>(
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData && prefs != null) return MyHomePage(title: 'Feet', api: api, prefs: prefs!);
|
||||
return const SizedBox();
|
||||
},
|
||||
future: _loadPrefs(),
|
||||
),
|
||||
)),
|
||||
title: 'Feet',
|
||||
theme: ThemeData(
|
||||
brightness: Brightness.light,
|
||||
useMaterial3: true,
|
||||
colorScheme: lightDynamic,
|
||||
),
|
||||
darkTheme: ThemeData(
|
||||
brightness: Brightness.dark,
|
||||
useMaterial3: true,
|
||||
colorScheme: darkDynamic,
|
||||
),
|
||||
themeMode: ThemeMode.system,
|
||||
home: FutureBuilder<bool>(
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData && prefs != null) {
|
||||
return MyHomePage(title: 'Feet', api: api, prefs: prefs!);
|
||||
}
|
||||
return const SizedBox();
|
||||
},
|
||||
future: _loadPrefs(),
|
||||
),
|
||||
)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -64,16 +66,62 @@ class MyHomePage extends StatefulWidget {
|
|||
final String title;
|
||||
final FeverAPI api;
|
||||
final SharedPreferences prefs;
|
||||
const MyHomePage({ super.key, required this.title, required this.api, required this.prefs });
|
||||
const MyHomePage(
|
||||
{super.key, required this.title, required this.api, required this.prefs});
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage> {
|
||||
var _index = 0;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var loggedIn = widget.api.loggedIn();
|
||||
var posts = widget.api.cache.items.getAll().values;
|
||||
var savedPosts = posts.where((element) => element.isSaved);
|
||||
var unreadPosts = posts.where((element) => !element.isRead);
|
||||
|
||||
final pages = [
|
||||
/* Posts list */
|
||||
posts.isNotEmpty
|
||||
? ListView(
|
||||
children: posts.map((value) => HomepagePost(post: value)).toList()
|
||||
..sort((a, b) => b.post.createdOnTime.millisecondsSinceEpoch
|
||||
.compareTo(a.post.createdOnTime.millisecondsSinceEpoch)),
|
||||
)
|
||||
: const CenteredPageHint(
|
||||
icon: Icons.coffee,
|
||||
text: "Your feed is currently empty."
|
||||
),
|
||||
/* Unread */
|
||||
unreadPosts.isNotEmpty
|
||||
? ListView(
|
||||
children: unreadPosts
|
||||
.map((value) => HomepagePost(post: value))
|
||||
.toList()
|
||||
..sort((a, b) => b.post.createdOnTime.millisecondsSinceEpoch
|
||||
.compareTo(a.post.createdOnTime.millisecondsSinceEpoch)),
|
||||
)
|
||||
: const CenteredPageHint(
|
||||
icon: Icons.check,
|
||||
text: "Nothing new here!"
|
||||
),
|
||||
/* Saved posts */
|
||||
savedPosts.isNotEmpty
|
||||
? ListView(
|
||||
children: savedPosts
|
||||
.map((value) => HomepagePost(post: value))
|
||||
.toList()
|
||||
..sort((a, b) => b.post.createdOnTime.millisecondsSinceEpoch
|
||||
.compareTo(a.post.createdOnTime.millisecondsSinceEpoch)),
|
||||
)
|
||||
: const CenteredPageHint(
|
||||
icon: Icons.bookmarks_outlined,
|
||||
text: "Nothing here yet. Try saving some posts!"
|
||||
),
|
||||
];
|
||||
|
||||
// I'm aware that this is stupid, but I'm sick and tired and really don't care as long as it works
|
||||
if (!loggedIn) {
|
||||
|
@ -92,26 +140,42 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||
actions: [
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
widget.api.request()
|
||||
.withFeeds()
|
||||
.withGroups()
|
||||
.withItems()
|
||||
.execute()
|
||||
.then((_) { setState(() {}); });
|
||||
widget.api
|
||||
.request()
|
||||
.withFeeds()
|
||||
.withGroups()
|
||||
.withItems()
|
||||
.execute()
|
||||
.then((_) {
|
||||
setState(() {});
|
||||
});
|
||||
},
|
||||
icon: const Icon(Icons.replay_outlined),
|
||||
),
|
||||
],
|
||||
),
|
||||
bottomNavigationBar: BottomNavigationBar(
|
||||
currentIndex: _index,
|
||||
onTap: (value) => setState(() => _index = value),
|
||||
items: const [
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.list),
|
||||
label: 'Feed',
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.lens_blur),
|
||||
label: 'Unread',
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.bookmark_outline),
|
||||
activeIcon: Icon(Icons.bookmark),
|
||||
label: 'Saved',
|
||||
),
|
||||
],
|
||||
),
|
||||
body: loggedIn
|
||||
? ListView(
|
||||
children: widget.api.cache.items.getAll()
|
||||
.values
|
||||
.map((value) => HomepagePost(post: value))
|
||||
.toList()
|
||||
..sort((a, b) => b.post.createdOnTime.millisecondsSinceEpoch.compareTo(a.post.createdOnTime.millisecondsSinceEpoch)),
|
||||
)
|
||||
: Center(child: LoginPrompt(api: widget.api)),
|
||||
? pages[_index]
|
||||
: Center(child: LoginPrompt(api: widget.api)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
23
lib/widgets/centered_page_hint.dart
Normal file
23
lib/widgets/centered_page_hint.dart
Normal file
|
@ -0,0 +1,23 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
class CenteredPageHint extends StatelessWidget {
|
||||
final IconData icon;
|
||||
final String text;
|
||||
const CenteredPageHint({super.key, required this.icon, required this.text});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(12.0),
|
||||
child: Icon(icon, size: 48),
|
||||
),
|
||||
Text(text),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue