widgets implementation

This commit is contained in:
ezyyeah 2022-12-06 23:08:52 +01:00
parent e32d2483d3
commit 0de763a297
7 changed files with 113 additions and 17 deletions

View File

@ -27,6 +27,7 @@
<action android:name="list_widget.ACTION_WIDGET_CLICK_NAV_RIGHT" /> <action android:name="list_widget.ACTION_WIDGET_CLICK_NAV_RIGHT" />
<action android:name="list_widget.ACTION_WIDGET_CLICK_NAV_TODAY" /> <action android:name="list_widget.ACTION_WIDGET_CLICK_NAV_TODAY" />
<action android:name="list_widget.ACTION_WIDGET_CLICK_NAV_REFRESH" /> <action android:name="list_widget.ACTION_WIDGET_CLICK_NAV_REFRESH" />
<action android:name="list_widget.ACTION_WIDGET_CLICK_BUY_PREMIUM" />
</intent-filter> </intent-filter>
<meta-data <meta-data

Binary file not shown.

After

Width:  |  Height:  |  Size: 528 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 156 KiB

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape android:shape="rectangle">
<solid android:color="#ffE0CCEC"></solid>
<corners android:radius="10dp" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<gradient android:endColor="#ffE0CCEC" android:startColor="#C9ABDC" />
<corners android:radius="10dp" />
</shape>
</item>
</selector>

View File

@ -5,16 +5,6 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_margin="@dimen/widget_margin"> android:layout_margin="@dimen/widget_margin">
<TextView
android:id="@+id/empty_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Empty"
android:gravity="center"
android:textColor="@color/text"
android:textSize="20sp"
android:textStyle="bold" />
<RelativeLayout <RelativeLayout
android:id="@+id/tt_grid_cont" android:id="@+id/tt_grid_cont"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -23,6 +13,17 @@
android:background="@drawable/card_layout_bg" android:background="@drawable/card_layout_bg"
android:orientation="vertical"> android:orientation="vertical">
<TextView
android:id="@+id/empty_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Empty"
android:textColor="@color/text"
android:textSize="20sp"
android:textStyle="bold" />
<ListView <ListView
android:id="@+id/widget_list" android:id="@+id/widget_list"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -83,17 +84,73 @@
android:id="@+id/nav_current" android:id="@+id/nav_current"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_marginLeft="20sp" android:layout_marginLeft="20sp"
android:layout_toLeftOf="@id/nav_refresh"
android:fontFamily="@font/montserrat_medium"
android:gravity="center_vertical" android:gravity="center_vertical"
android:maxLines="1" android:maxLines="1"
android:text="Unknown" android:text="Timetable"
android:fontFamily="@font/montserrat_medium"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@id/nav_refresh"
android:textColor="@color/text" android:textColor="@color/text"
android:textSize="24sp" android:textSize="24sp"
android:textStyle="bold" /> android:textStyle="bold" />
</RelativeLayout> </RelativeLayout>
</RelativeLayout> </RelativeLayout>
<LinearLayout
android:visibility="gone"
android:id="@+id/need_login"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:background="@drawable/card_layout_bg"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/montserrat_medium"
android:gravity="center"
android:text="A Widget használatához, bejelentkezés szükséges."
android:textColor="@color/green"
android:textSize="24sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:visibility="gone"
android:id="@+id/need_premium"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:backgroundTint="#ffF4F4F4"
android:background="@drawable/card_layout_bg"
android:orientation="vertical" >
<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true"
android:paddingHorizontal="10dp"
android:paddingTop="5dp"
android:src="@drawable/tinta_widget" />
<Button
android:id="@+id/buy_premium"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="@drawable/btn_shape"
android:gravity="center"
android:text="Vigyél oda!"
android:padding="0dp"
android:layout_margin="0dp"
android:textColor="#ff691A9B"
android:fontFamily="@font/montserrat_medium"
android:textSize="16dp"
android:textStyle="bold"/>
</LinearLayout>
</RelativeLayout> </RelativeLayout>

View File

@ -71,6 +71,7 @@ Future<void> syncAll(BuildContext context) {
Future<bool?> updateWidget() async { Future<bool?> updateWidget() async {
try { try {
print("FILC | Widget updated from sync");
return HomeWidget.updateWidget(name: 'widget_timetable.WidgetTimetable'); return HomeWidget.updateWidget(name: 'widget_timetable.WidgetTimetable');
} on PlatformException catch (exception) { } on PlatformException catch (exception) {
debugPrint('Error Updating Widget. $exception'); debugPrint('Error Updating Widget. $exception');

View File

@ -2,6 +2,8 @@ import 'package:filcnaplo/models/settings.dart';
import 'package:filcnaplo/models/user.dart'; import 'package:filcnaplo/models/user.dart';
import 'package:filcnaplo_kreta_api/models/student.dart'; import 'package:filcnaplo_kreta_api/models/student.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:home_widget/home_widget.dart';
import 'package:flutter/services.dart';
class UserProvider with ChangeNotifier { class UserProvider with ChangeNotifier {
final Map<String, User> _users = {}; final Map<String, User> _users = {};
@ -26,9 +28,20 @@ class UserProvider with ChangeNotifier {
void setUser(String userId) { void setUser(String userId) {
_selectedUserId = userId; _selectedUserId = userId;
_settings.update(lastAccountId: userId); _settings.update(lastAccountId: userId);
updateWidget();
notifyListeners(); notifyListeners();
} }
Future<bool?> updateWidget() async {
try {
print("FILC | Widget updated from users");
return HomeWidget.updateWidget(name: 'widget_timetable.WidgetTimetable');
} on PlatformException catch (exception) {
print('Error Updating Widget After setUser. $exception');
}
return false;
}
void addUser(User user) { void addUser(User user) {
_users[user.id] = user; _users[user.id] = user;
if (kDebugMode) { if (kDebugMode) {
@ -36,9 +49,15 @@ class UserProvider with ChangeNotifier {
} }
} }
void removeUser(String userId) { void removeUser(String userId) async {
_users.removeWhere((key, value) => key == userId); _users.removeWhere((key, value) => key == userId);
if (_users.isNotEmpty) _selectedUserId = _users.keys.first; if (_users.isNotEmpty) {
setUser(_users.keys.first);
} else {
print("FILC | Setting last account id to null");
await _settings.update(lastAccountId: "");
}
updateWidget();
notifyListeners(); notifyListeners();
} }