remelem mukszik

This commit is contained in:
ReinerRego
2023-05-26 21:51:21 +02:00
parent baec76c29f
commit 0ece9382af
170 changed files with 15575 additions and 0 deletions

View File

@@ -0,0 +1,61 @@
import 'dart:math';
import 'package:filcnaplo/theme/colors/colors.dart';
import 'package:filcnaplo_mobile_ui/common/empty.dart';
import 'package:filcnaplo_mobile_ui/common/panel/panel.dart';
import 'package:filcnaplo_mobile_ui/screens/news/news_tile.dart';
import 'package:filcnaplo/models/news.dart';
import 'package:filcnaplo_mobile_ui/screens/news/news_view.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:filcnaplo/api/providers/news_provider.dart';
class NewsScreen extends StatelessWidget {
const NewsScreen({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
var newsProvider = Provider.of<NewsProvider>(context);
List<News> news = [];
news = newsProvider.news.where((e) => e.title != "").toList();
return Scaffold(
appBar: AppBar(
surfaceTintColor: Theme.of(context).scaffoldBackgroundColor,
leading: BackButton(color: AppColors.of(context).text),
title: Text("News", style: TextStyle(color: AppColors.of(context).text)),
),
body: SafeArea(
child: RefreshIndicator(
onRefresh: () => newsProvider.fetch(),
child: ListView.builder(
physics: const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()),
itemCount: max(news.length, 1),
itemBuilder: (context, index) {
if (news.isNotEmpty) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 24.0, vertical: 12.0),
child: Panel(
child: Material(
type: MaterialType.transparency,
child: NewsTile(
news[index],
onTap: () => NewsView.show(news[index], context: context, force: true),
),
),
),
);
} else {
return const Padding(
padding: EdgeInsets.only(top: 24.0),
child: Empty(subtitle: "Nothing to see here"),
);
}
},
),
),
),
);
}
}

View File

@@ -0,0 +1,30 @@
import 'package:flutter/material.dart';
import 'package:filcnaplo/models/news.dart';
import 'package:filcnaplo/utils/format.dart';
class NewsTile extends StatelessWidget {
const NewsTile(this.news, {Key? key, this.onTap}) : super(key: key);
final News news;
final Function()? onTap;
@override
Widget build(BuildContext context) {
return ListTile(
title: Text(
news.title,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(fontWeight: FontWeight.w600),
),
subtitle: Text(
news.content.escapeHtml().replaceAll("\n", " "),
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: const TextStyle(fontWeight: FontWeight.w500),
),
onTap: onTap,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12.0)),
);
}
}

View File

@@ -0,0 +1,116 @@
import 'dart:io';
import 'package:filcnaplo/models/settings.dart';
import 'package:filcnaplo_mobile_ui/common/dialog_button.dart';
import 'package:flutter/material.dart';
import 'package:filcnaplo/models/news.dart';
import 'package:filcnaplo/utils/format.dart';
import 'package:flutter_custom_tabs/flutter_custom_tabs.dart';
import 'package:flutter_linkify/flutter_linkify.dart';
import 'package:provider/provider.dart';
import 'package:filcnaplo_mobile_ui/screens/settings/settings_screen.i18n.dart';
class NewsView extends StatelessWidget {
const NewsView(this.news, {Key? key}) : super(key: key);
final News news;
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 100.0, horizontal: 32.0),
child: Material(
borderRadius: BorderRadius.circular(12.0),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 12.0, vertical: 4.0),
child: Column(
children: [
// Content
Expanded(
child: ListView(
physics: const BouncingScrollPhysics(),
children: [
Padding(
padding: const EdgeInsets.only(left: 8.0, right: 6.0, top: 14.0, bottom: 8.0),
child: Text(
news.title,
maxLines: 3,
style: const TextStyle(fontWeight: FontWeight.w600, fontSize: 18.0),
),
),
SelectableLinkify(
text: news.content.escapeHtml(),
options: const LinkifyOptions(looseUrl: true, removeWww: true),
onOpen: (link) {
launch(
link.url,
customTabsOption: CustomTabsOption(showPageTitle: true, toolbarColor: Theme.of(context).scaffoldBackgroundColor),
);
},
style: const TextStyle(fontWeight: FontWeight.w500, fontSize: 14.0),
),
],
),
),
// Actions
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
if (news.link != "")
DialogButton(
label: news.openLabel != "" ? news.openLabel : "open".i18n.toUpperCase(),
onTap: () => launch(
news.link,
customTabsOption: CustomTabsOption(showPageTitle: true, toolbarColor: Theme.of(context).scaffoldBackgroundColor),
),
),
DialogButton(
label: "done".i18n,
onTap: () => Navigator.of(context).maybePop(),
),
],
),
],
),
),
),
);
}
static Future<T?> show<T>(News news, {required BuildContext context, bool force = false}) {
if (news.title == "") return Future<T?>.value(null);
bool popup = news.platform == '' || force;
if (Provider.of<SettingsProvider>(context, listen: false).newsEnabled || news.emergency || force) {
switch (news.platform.trim().toLowerCase()) {
case "android":
if (Platform.isAndroid) popup = true;
break;
case "ios":
if (Platform.isIOS) popup = true;
break;
case "linux":
if (Platform.isLinux) popup = true;
break;
case "windows":
if (Platform.isWindows) popup = true;
break;
case "macos":
if (Platform.isMacOS) popup = true;
break;
default:
popup = true;
}
} else {
popup = false;
}
if (popup) {
return showDialog<T?>(context: context, builder: (context) => NewsView(news), barrierDismissible: true);
} else {
return Future<T?>.value(null);
}
}
}