changed everything from filcnaplo to refilc finally

This commit is contained in:
Kima
2024-02-24 20:12:25 +01:00
parent 0d1c7b7143
commit 1171e3aaaf
655 changed files with 38728 additions and 44967 deletions

View File

@@ -0,0 +1,66 @@
import 'dart:math';
import 'package:refilc/theme/colors/colors.dart';
import 'package:refilc_mobile_ui/common/empty.dart';
import 'package:refilc_mobile_ui/common/panel/panel.dart';
import 'package:refilc_mobile_ui/screens/news/news_tile.dart';
import 'package:refilc/models/news.dart';
import 'package:refilc_mobile_ui/screens/news/news_view.dart';
import 'package:refilc_mobile_ui/screens/settings/settings_screen.i18n.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:refilc/api/providers/news_provider.dart';
class NewsScreen extends StatelessWidget {
const NewsScreen({super.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".i18n,
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:refilc/models/news.dart';
import 'package:refilc/utils/format.dart';
class NewsTile extends StatelessWidget {
const NewsTile(this.news, {super.key, this.onTap});
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,137 @@
import 'dart:io';
import 'package:refilc/models/settings.dart';
import 'package:refilc_mobile_ui/common/dialog_button.dart';
import 'package:flutter/material.dart';
import 'package:refilc/models/news.dart';
import 'package:refilc/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:refilc_mobile_ui/screens/settings/settings_screen.i18n.dart';
class NewsView extends StatelessWidget {
const NewsView(this.news, {super.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 == 'all' || 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;
case "all":
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);
}
}
}