From 12ea09b27b55626fb1b290071e6e56e4aa622f6c Mon Sep 17 00:00:00 2001 From: sruusk <57395313+sruusk@users.noreply.github.com> Date: Fri, 13 Dec 2024 10:14:59 +0200 Subject: [PATCH] Add medium widget layout --- README.md | 1 + .../com/sruusk/sahkohinta/WidgetProvider.kt | 14 ++- .../app/src/main/res/layout/widget_medium.xml | 87 +++++++++++++++++++ .../app/src/main/res/layout/widget_wide.xml | 2 +- android/app/src/main/res/xml/widget.xml | 2 +- lib/main.dart | 2 - lib/utils/api.dart | 5 +- pubspec.lock | 8 -- pubspec.yaml | 2 - 9 files changed, 105 insertions(+), 18 deletions(-) create mode 100644 android/app/src/main/res/layout/widget_medium.xml diff --git a/README.md b/README.md index b01e518..00bf931 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ Sähkön tuntihinnat Suomessa. - [ ] Laske hintaan ALV ja myyjän marginaali ## Ympäristömuuttujat +Voit asettaa ympäristömuuttujat ajaessa flutter run/build komentoja käyttämällä `--dart-define key=value` parametria. - `ENTSOE_TOKEN` - ENTSO-E Web API Security Token ## Kuvakaappaus diff --git a/android/app/src/main/kotlin/com/sruusk/sahkohinta/WidgetProvider.kt b/android/app/src/main/kotlin/com/sruusk/sahkohinta/WidgetProvider.kt index 6b0538e..80501ef 100644 --- a/android/app/src/main/kotlin/com/sruusk/sahkohinta/WidgetProvider.kt +++ b/android/app/src/main/kotlin/com/sruusk/sahkohinta/WidgetProvider.kt @@ -26,6 +26,17 @@ class WidgetProvider : HomeWidgetProvider() { setTextViewText(R.id.text_time, time) } + val mediumView = RemoteViews(context.packageName, R.layout.widget_medium).apply { + val prices = Array(3) { i -> widgetData.getString("price$i", "0.00").toString() } + val time = widgetData.getString("time", "12.12.").toString() + val times = Array(3) { i -> widgetData.getString("time$i", "25-26").toString() } + setTextViewText(R.id.text_price1, prices[0]) + setTextViewText(R.id.text_price2, prices[1]) + setTextViewText(R.id.text_time, time.split(" ")[0]) // Only date + setTextViewText(R.id.text_time1, times[0]) + setTextViewText(R.id.text_time2, times[1]) + } + val wideView = RemoteViews(context.packageName, R.layout.widget_wide).apply { val prices = Array(3) { i -> widgetData.getString("price$i", "0.00").toString() } val time = widgetData.getString("time", "12.12.").toString() @@ -41,7 +52,8 @@ class WidgetProvider : HomeWidgetProvider() { val viewMapping: Map = mapOf( SizeF(40f, 100f) to narrowView, - SizeF(100f, 100f) to wideView + SizeF(120f, 100f) to mediumView, + SizeF(180f, 100f) to wideView ) val remoteViews = RemoteViews(viewMapping) diff --git a/android/app/src/main/res/layout/widget_medium.xml b/android/app/src/main/res/layout/widget_medium.xml new file mode 100644 index 0000000..ee5ba4f --- /dev/null +++ b/android/app/src/main/res/layout/widget_medium.xml @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + diff --git a/android/app/src/main/res/layout/widget_wide.xml b/android/app/src/main/res/layout/widget_wide.xml index 9b4dc78..5550672 100644 --- a/android/app/src/main/res/layout/widget_wide.xml +++ b/android/app/src/main/res/layout/widget_wide.xml @@ -22,7 +22,7 @@ android:textColor="#E8E8E8" android:layout_gravity="bottom"/> prices = []; final document = XmlDocument.parse(response.body); diff --git a/pubspec.lock b/pubspec.lock index fe92f40..9a7234e 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -94,14 +94,6 @@ packages: description: flutter source: sdk version: "0.0.0" - flutter_dotenv: - dependency: "direct main" - description: - name: flutter_dotenv - sha256: b7c7be5cd9f6ef7a78429cabd2774d3c4af50e79cb2b7593e3d5d763ef95c61b - url: "https://pub.dev" - source: hosted - version: "5.2.1" flutter_lints: dependency: "direct dev" description: diff --git a/pubspec.yaml b/pubspec.yaml index d67da3b..f89e1b7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -41,7 +41,6 @@ dependencies: mrx_charts: ^0.1.3 home_widget: ^0.7.0 android_alarm_manager_plus: ^4.0.4 - flutter_dotenv: ^5.2.1 dev_dependencies: flutter_test: @@ -68,7 +67,6 @@ flutter: # To add assets to your application, add an assets section, like this: assets: - assets/lang/ - - .env # An image asset can refer to one or more resolution-specific "variants", see # https://flutter.dev/to/resolution-aware-images