show posts on main page

This commit is contained in:
Jan 2022-12-30 00:27:35 +01:00
parent a2a2928ebc
commit e610286d69
Signed by: Lea
GPG key ID: 1BAFFE8347019C42
4 changed files with 76 additions and 4 deletions

View file

@ -27,7 +27,7 @@ class Feed {
title = json['title']; title = json['title'];
url = json['url']; url = json['url'];
siteUrl = json['site_url']; siteUrl = json['site_url'];
isSpark = json['isSpark'] == '1'; isSpark = json['isSpark'] == 1;
lastUpdatedOnTime = DateTime.fromMillisecondsSinceEpoch(toInt(json['last_updated_on_time']) * 1000); lastUpdatedOnTime = DateTime.fromMillisecondsSinceEpoch(toInt(json['last_updated_on_time']) * 1000);
} }

View file

@ -32,8 +32,8 @@ class Item {
author = json['author']; author = json['author'];
html = json['html']; html = json['html'];
url = json['url']; url = json['url'];
isSaved = json['is_saved'] == '1'; isSaved = json['is_saved'] == 1;
isRead = json['is_read'] == '1'; isRead = json['is_read'] == 1;
createdOnTime = DateTime.fromMillisecondsSinceEpoch(toInt(json['created_on_time']) * 1000); createdOnTime = DateTime.fromMillisecondsSinceEpoch(toInt(json['created_on_time']) * 1000);
} }

View file

@ -1,5 +1,6 @@
import 'dart:async'; import 'dart:async';
import 'package:feet/widgets/homepage_post.dart';
import 'package:feet/widgets/login_prompt.dart'; import 'package:feet/widgets/login_prompt.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:dynamic_color/dynamic_color.dart'; import 'package:dynamic_color/dynamic_color.dart';
@ -88,9 +89,28 @@ class _MyHomePageState extends State<MyHomePage> {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text(widget.title), title: Text(widget.title),
actions: [
IconButton(
onPressed: () {
widget.api.request()
.withFeeds()
.withGroups()
.withItems()
.execute()
.then((_) { setState(() {}); });
},
icon: const Icon(Icons.replay_outlined),
),
],
), ),
body: loggedIn body: loggedIn
? const Center(child: Text('Meep')) ? 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)), : Center(child: LoginPrompt(api: widget.api)),
); );
} }

View file

@ -0,0 +1,52 @@
import 'package:flutter/material.dart';
import '../api/api.dart';
// TODO use some localization library
String formatDate(DateTime date) {
return '${date.day}.${date.month}.${date.year}, ${date.hour}:${date.minute < 10 ? '0${date.minute}' : date.minute}';
}
class HomepagePost extends StatelessWidget {
final Item post;
const HomepagePost({ super.key, required this.post });
@override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.symmetric(vertical: 6.0, horizontal: 8.0),
decoration: BoxDecoration(
border: Border.all(
color: Theme.of(context).colorScheme.secondaryContainer,
),
borderRadius: const BorderRadius.all(Radius.circular(15)),
color: post.isRead
? null
: Theme.of(context).colorScheme.secondaryContainer.withAlpha(150),
),
child: InkWell(
onTap: () {
showDialog(context: context, builder: (context) => SimpleDialog(title: Text(post.title)));
},
borderRadius: const BorderRadius.all(Radius.circular(15)),
child: Container(
margin: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(post.title, style: Theme.of(context).textTheme.titleMedium, overflow: TextOverflow.ellipsis),
Row(
children: [
post.author.isNotEmpty
? Text(post.author)
: const Text('Unknown author', style: TextStyle(fontStyle: FontStyle.italic)),
const Text(' \u2022 '),
Text(formatDate(post.createdOnTime)),
],
),
],
),
)
),
);
}
}