From 1100ce2ab84f0906c504c5afd9c638ed7d0b6b3e Mon Sep 17 00:00:00 2001 From: hmalik144 Date: Tue, 11 Oct 2022 22:24:52 +0100 Subject: [PATCH] - mid commit --- android/app/build.gradle | 1 + android/app/src/main/AndroidManifest.xml | 29 +++- .../h_mal/easycc/AppWidgetProvider.kt | 45 +++++ .../CurrencyAppWidgetConfigureActivity.kt | 110 ++++++++++++ .../h_mal/easycc/CustomDialogClass.kt | 57 +++++++ .../h_mal/easycc/WidgetSubmitDialog.kt | 37 ++++ .../appttude/h_mal/easycc/WidgetViewModel.kt | 57 +++++++ .../src/main/res/drawable/ic_background.xml | 24 +++ .../res/drawable/ic_refresh_white_24dp.xml | 10 ++ .../src/main/res/layout/confirm_dialog.xml | 64 +++++++ .../main/res/layout/currency_app_widget.xml | 65 +++++++ .../layout/currency_app_widget_configure.xml | 69 ++++++++ .../app/src/main/res/layout/custom_dialog.xml | 39 +++++ .../app/src/main/res/values-night/colors.xml | 8 + android/app/src/main/res/values/colors.xml | 8 + android/app/src/main/res/values/strings.xml | 161 ++++++++++++++++++ android/app/src/main/res/values/styles.xml | 8 + android/build.gradle | 2 +- lib/main.dart | 22 +++ pubspec.lock | 7 + pubspec.yaml | 1 + 21 files changed, 821 insertions(+), 3 deletions(-) create mode 100644 android/app/src/main/kotlin/com/appttude/h_mal/easycc/AppWidgetProvider.kt create mode 100644 android/app/src/main/kotlin/com/appttude/h_mal/easycc/CurrencyAppWidgetConfigureActivity.kt create mode 100644 android/app/src/main/kotlin/com/appttude/h_mal/easycc/CustomDialogClass.kt create mode 100644 android/app/src/main/kotlin/com/appttude/h_mal/easycc/WidgetSubmitDialog.kt create mode 100644 android/app/src/main/kotlin/com/appttude/h_mal/easycc/WidgetViewModel.kt create mode 100644 android/app/src/main/res/drawable/ic_background.xml create mode 100644 android/app/src/main/res/drawable/ic_refresh_white_24dp.xml create mode 100644 android/app/src/main/res/layout/confirm_dialog.xml create mode 100644 android/app/src/main/res/layout/currency_app_widget.xml create mode 100644 android/app/src/main/res/layout/currency_app_widget_configure.xml create mode 100644 android/app/src/main/res/layout/custom_dialog.xml create mode 100644 android/app/src/main/res/values-night/colors.xml create mode 100644 android/app/src/main/res/values/colors.xml create mode 100644 android/app/src/main/res/values/strings.xml diff --git a/android/app/build.gradle b/android/app/build.gradle index 6486bd4..c44b2e2 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -68,4 +68,5 @@ flutter { dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'androidx.cardview:cardview:1.0.0' } diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index e317dea..581ca1d 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -25,8 +25,33 @@ - + + + + + + + + + + + + + + + + + + + + + + + diff --git a/android/app/src/main/kotlin/com/appttude/h_mal/easycc/AppWidgetProvider.kt b/android/app/src/main/kotlin/com/appttude/h_mal/easycc/AppWidgetProvider.kt new file mode 100644 index 0000000..093f328 --- /dev/null +++ b/android/app/src/main/kotlin/com/appttude/h_mal/easycc/AppWidgetProvider.kt @@ -0,0 +1,45 @@ +package com.appttude.h_mal.easycc + +import android.appwidget.AppWidgetManager +import android.content.Context +import android.content.SharedPreferences +import android.net.Uri +import android.widget.RemoteViews +import es.antonborri.home_widget.HomeWidgetBackgroundIntent +import es.antonborri.home_widget.HomeWidgetLaunchIntent +import es.antonborri.home_widget.HomeWidgetProvider + +class AppWidgetProvider : HomeWidgetProvider(){ + override fun onUpdate( + context: Context, + appWidgetManager: AppWidgetManager, + appWidgetIds: IntArray, + widgetData: SharedPreferences + ) { + appWidgetIds.forEach { widgetId -> + val views = RemoteViews(context.packageName, R.layout.currency_app_widget).apply { + // Data from background operation received + val from: String? = widgetData.getString("from", null) + val to: String? = widgetData.getString("to", null) + val rate: String? = widgetData.getString("rate", null) + + val titleString = "${from}${to}" + setTextViewText(R.id.exchangeName, titleString) + setTextViewText(R.id.exchangeRate, rate.toString()) + + val uri = Uri.parse("myAppWidget://update") + uri.buildUpon().query(widgetId.toString()).build() + + setImageViewResource(R.id.refresh_icon, R.drawable.ic_refresh_white_24dp) + val backgroundIntent = HomeWidgetBackgroundIntent.getBroadcast(context, uri) + setOnClickPendingIntent(R.id.refresh_icon, backgroundIntent) + + val pendingIntent = HomeWidgetLaunchIntent.getActivity(context, + MainActivity::class.java) + + setOnClickPendingIntent(R.id.widget_view, pendingIntent) + } + appWidgetManager.updateAppWidget(widgetId, views) + } + } +} \ No newline at end of file diff --git a/android/app/src/main/kotlin/com/appttude/h_mal/easycc/CurrencyAppWidgetConfigureActivity.kt b/android/app/src/main/kotlin/com/appttude/h_mal/easycc/CurrencyAppWidgetConfigureActivity.kt new file mode 100644 index 0000000..3ed4817 --- /dev/null +++ b/android/app/src/main/kotlin/com/appttude/h_mal/easycc/CurrencyAppWidgetConfigureActivity.kt @@ -0,0 +1,110 @@ +package com.appttude.h_mal.easycc + +import android.app.Activity +import android.app.PendingIntent +import android.appwidget.AppWidgetManager +import android.content.Intent +import android.net.Uri +import android.os.Build +import android.os.Bundle +import android.view.View +import android.widget.TextView +import androidx.activity.viewModels +import com.appttude.h_mal.easycc.databinding.CurrencyAppWidgetConfigureBinding +import com.appttude.h_mal.easycc.ui.BaseActivity +import com.appttude.h_mal.easycc.ui.main.CustomDialogClass +import com.appttude.h_mal.easycc.utils.transformIntToArray +import com.appttude.h_mal.easycc.widget.CurrencyAppWidgetKotlin +import dagger.hilt.android.AndroidEntryPoint +import es.antonborri.home_widget.HomeWidgetBackgroundIntent +import es.antonborri.home_widget.HomeWidgetBackgroundReceiver +import es.antonborri.home_widget.HomeWidgetPlugin + +/** + * The configuration screen for the [CurrencyAppWidgetKotlin] AppWidget. + */ +class CurrencyAppWidgetConfigureActivity : Activity(), + View.OnClickListener { + + private var mAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID + + public override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.currency_app_widget_configure) + + // Set the result to CANCELED. This will cause the widget host to cancel + // out of the widget placement if the user presses the back button. + setResult(RESULT_CANCELED) + + // Find the widget id from the intent. + val extras = intent.extras + if (extras != null) { + mAppWidgetId = extras.getInt( + AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID + ) + } + + // If this activity was started with an intent without an app widget ID, finish with an error. + if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) { + finish() + return + } + setupClickListener() + } + + private fun setupClickListener() { + findViewById(R.id.submitWidget).setOnClickListener(this) + findViewById(R.id.currencyOne).setOnClickListener(this) + findViewById(R.id.currencyTwo).setOnClickListener(this) + } + + override fun onClick(view: View?) { + when (view?.tag.toString()) { + "top", "bottom" -> showCustomDialog(view) + "submit" -> viewModel.submitSelectionOnClick() + else -> { + return + } + } + } + + private fun displaySubmitDialog() { + val message = viewModel.getSubmitDialogMessage() + WidgetSubmitDialog(this, message, object : DialogSubmit { + override fun onSubmit() { + sendUpdateIntent() + finishCurrencyWidgetActivity() + } + }).show() + } + + + private fun showCustomDialog(view: View?) { + CustomDialogClass(this) { + (view as TextView).text = it + viewModel.setCurrencyName(view.tag, it) + }.show() + } + + fun finishCurrencyWidgetActivity() { + // Make sure we pass back the original appWidgetId + val resultValue = intent + resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId) + setResult(RESULT_OK, resultValue) + finish() + } + + fun sendUpdateIntent(from: String, to: String) { + // It is the responsibility of the configuration activity to update the app widget + // Send update broadcast to widget app class + val uri = Uri.parse("myAppWidget://createWidget").buildUpon() + .appendQueryParameter("id", mAppWidgetId.toString()) + .appendQueryParameter("from", from) + .appendQueryParameter("to", to) + .build() + + val backgroundIntent = HomeWidgetBackgroundIntent.getBroadcast(this, uri) + backgroundIntent.send() + } + +} diff --git a/android/app/src/main/kotlin/com/appttude/h_mal/easycc/CustomDialogClass.kt b/android/app/src/main/kotlin/com/appttude/h_mal/easycc/CustomDialogClass.kt new file mode 100644 index 0000000..bc38a66 --- /dev/null +++ b/android/app/src/main/kotlin/com/appttude/h_mal/easycc/CustomDialogClass.kt @@ -0,0 +1,57 @@ +package com.appttude.h_mal.easycc + +import android.app.Dialog +import android.content.Context +import android.os.Bundle +import android.text.Editable +import android.text.TextWatcher +import android.view.WindowManager +import android.widget.ArrayAdapter +import android.widget.ListView +import android.widget.TextView +import com.appttude.h_mal.easycc.R + +/** + * Custom dialog when selecting currencies from list with filter + */ +@Suppress("DEPRECATION") +class CustomDialogClass( + context: Context, + private val onSelect: (String) -> Unit +) : Dialog(context) { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.custom_dialog) + + // Transparent background + window!!.setBackgroundDrawableResource(android.R.color.transparent) + // Keyboard not to overlap dialog + window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE) + + val arrayAdapter = + ArrayAdapter.createFromResource( + context, R.array.currency_arrays, + android.R.layout.simple_list_item_1 + ) + + val list_view = findViewById(R.id.list_view) + list_view.adapter = arrayAdapter + + // Edit text to filter @arrayAdapter + findViewById(R.id.search_text).addTextChangedListener(object : TextWatcher { + override fun beforeTextChanged(charSequence: CharSequence, i: Int, i1: Int, i2: Int) {} + override fun onTextChanged(charSequence: CharSequence, i: Int, i1: Int, i2: Int) { + arrayAdapter.filter.filter(charSequence) + } + + override fun afterTextChanged(editable: Editable) {} + }) + + // interface selection back to calling activity + list_view.setOnItemClickListener { adapterView, _, i, _ -> + onSelect.invoke(adapterView.getItemAtPosition(i).toString()) + dismiss() + } + } +} \ No newline at end of file diff --git a/android/app/src/main/kotlin/com/appttude/h_mal/easycc/WidgetSubmitDialog.kt b/android/app/src/main/kotlin/com/appttude/h_mal/easycc/WidgetSubmitDialog.kt new file mode 100644 index 0000000..408b652 --- /dev/null +++ b/android/app/src/main/kotlin/com/appttude/h_mal/easycc/WidgetSubmitDialog.kt @@ -0,0 +1,37 @@ +package com.appttude.h_mal.easycc + +import android.app.Dialog +import android.content.Context +import android.os.Bundle +import android.widget.TextView + + +/** + * Dialog created when submitting the completed selections + * in [CurrencyAppWidgetConfigureActivity] + */ +class WidgetSubmitDialog( + context: Context, + private val messageString: String, + private val dialogInterface: DialogSubmit +) : Dialog(context) { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.confirm_dialog) + // layer behind dialog to be transparent + window!!.setBackgroundDrawableResource(android.R.color.transparent) + // Dialog cannot be cancelled by clicking away + setCancelable(false) + + findViewById(R.id.confirmText).text = messageString + + // handle dialog buttons + findViewById(R.id.confirmYes).setOnClickListener { dialogInterface.onSubmit() } + findViewById(R.id.confirmNo).setOnClickListener { dismiss() } + } +} + +interface DialogSubmit { + fun onSubmit() +} \ No newline at end of file diff --git a/android/app/src/main/kotlin/com/appttude/h_mal/easycc/WidgetViewModel.kt b/android/app/src/main/kotlin/com/appttude/h_mal/easycc/WidgetViewModel.kt new file mode 100644 index 0000000..068eee4 --- /dev/null +++ b/android/app/src/main/kotlin/com/appttude/h_mal/easycc/WidgetViewModel.kt @@ -0,0 +1,57 @@ +package com.appttude.h_mal.easycc + +import androidx.lifecycle.ViewModel +import com.appttude.h_mal.easycc.data.repository.Repository +import com.appttude.h_mal.easycc.ui.BaseViewModel +import com.appttude.h_mal.easycc.utils.trimToThree +import dagger.hilt.android.lifecycle.HiltViewModel +import javax.inject.Inject + +class WidgetViewModel: ViewModel() { + + var appWidgetId: Int? = null + + var rateIdFrom: String? = null + var rateIdTo: String? = null + + // Setup viewmodel app widget ID + // Set default values for text views + fun initiate(appId: Int) { + appWidgetId = appId + } + + // Retrieve name for submit dialog (eg. AUDGBP) + fun getSubmitDialogMessage(): String { + val widgetName = getWidgetStringName() + return StringBuilder().append("Create widget for ") + .append(widgetName) + .append("?").toString() + } + + fun submitSelectionOnClick() { + if (rateIdTo == null || rateIdFrom == null) { + onError("Selections incomplete") + return + } + if (rateIdFrom == rateIdTo) { + onError("Selected rates cannot be the same") + return + } + onSuccess(Unit) + } + + fun setWidgetStored() { + + } + + // Start operation based on dialog selection + fun setCurrencyName(tag: Any?, currencyName: String) { + when (tag.toString()) { + "top" -> rateIdFrom = currencyName + "bottom" -> rateIdTo = currencyName + } + } + + private fun getWidgetStringName() = "${rateIdFrom!!.substring(0, 3)}${rateIdTo!!.substring(0, 3)}" + +} \ No newline at end of file diff --git a/android/app/src/main/res/drawable/ic_background.xml b/android/app/src/main/res/drawable/ic_background.xml new file mode 100644 index 0000000..21d6752 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_background.xml @@ -0,0 +1,24 @@ + + + + + + + + + + \ No newline at end of file diff --git a/android/app/src/main/res/drawable/ic_refresh_white_24dp.xml b/android/app/src/main/res/drawable/ic_refresh_white_24dp.xml new file mode 100644 index 0000000..a27ba3c --- /dev/null +++ b/android/app/src/main/res/drawable/ic_refresh_white_24dp.xml @@ -0,0 +1,10 @@ + + + diff --git a/android/app/src/main/res/layout/confirm_dialog.xml b/android/app/src/main/res/layout/confirm_dialog.xml new file mode 100644 index 0000000..339dcb0 --- /dev/null +++ b/android/app/src/main/res/layout/confirm_dialog.xml @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/android/app/src/main/res/layout/currency_app_widget.xml b/android/app/src/main/res/layout/currency_app_widget.xml new file mode 100644 index 0000000..8d9d1b1 --- /dev/null +++ b/android/app/src/main/res/layout/currency_app_widget.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/android/app/src/main/res/layout/currency_app_widget_configure.xml b/android/app/src/main/res/layout/currency_app_widget_configure.xml new file mode 100644 index 0000000..19460db --- /dev/null +++ b/android/app/src/main/res/layout/currency_app_widget_configure.xml @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/android/app/src/main/res/layout/custom_dialog.xml b/android/app/src/main/res/layout/custom_dialog.xml new file mode 100644 index 0000000..7b6354b --- /dev/null +++ b/android/app/src/main/res/layout/custom_dialog.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/android/app/src/main/res/values-night/colors.xml b/android/app/src/main/res/values-night/colors.xml new file mode 100644 index 0000000..d74b2f1 --- /dev/null +++ b/android/app/src/main/res/values-night/colors.xml @@ -0,0 +1,8 @@ + + + #253031 + #315659 + #2978A0 + #8549ff + #C6E0FF + diff --git a/android/app/src/main/res/values/colors.xml b/android/app/src/main/res/values/colors.xml new file mode 100644 index 0000000..a72e604 --- /dev/null +++ b/android/app/src/main/res/values/colors.xml @@ -0,0 +1,8 @@ + + + #253031 + #315659 + #2978A0 + #8549ff + #C6E0FF + \ No newline at end of file diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..4d866f8 --- /dev/null +++ b/android/app/src/main/res/values/strings.xml @@ -0,0 +1,161 @@ + + + + + ALL - Albanian Lek + AFN - Afghan Afghani + DZD - Algerian Dinar + AOA - Angolan Kwanza + ARS - Argentine Peso + AMD - Armenian Dram + AWG - Aruban Florin + AUD - Australian Dollar + AZN - Azerbaijani Manat + BSD - Bahamian Dollar + BHD - Bahraini Dinar + BDT - Bangladeshi Taka + BBD - Barbadian Dollar + BYR - Belarusian Ruble + BZD - Belize Dollar + BTN - Bhutanese Ngultrum + BTC - Bitcoin + BOB - Bolivian Boliviano + BAM - Bosnia And Herzegovina Konvertibilna Marka + BWP - Botswana Pula + BRL - Brazilian Real + GBP - British Pound + BND - Brunei Dollar + BGN - Bulgarian Lev + BIF - Burundi Franc + KHR - Cambodian Riel + CAD - Canadian Dollar + CVE - Cape Verdean Escudo + KYD - Cayman Islands Dollar + XAF - Central African CFA Franc + XPF - CFP Franc + CLP - Chilean Peso + CNY - Chinese Yuan + COP - Colombian Peso + KMF - Comorian Franc + CDF - Congolese Franc + CRC - Costa Rican Colon + HRK - Croatian Kuna + CUP - Cuban Peso + CZK - Czech Koruna + DKK - Danish Krone + DJF - Djiboutian Franc + DOP - Dominican Peso + XCD - East Caribbean Dollar + EGP - Egyptian Pound + ERN - Eritrean Nakfa + ETB - Ethiopian Birr + EUR - Euro + FKP - Falkland Islands Pound + FJD - Fijian Dollar + GMD - Gambian Dalasi + GEL - Georgian Lari + GHS - Ghanaian Cedi + GIP - Gibraltar Pound + GTQ - Guatemalan Quetzal + GNF - Guinean Franc + GYD - Guyanese Dollar + HTG - Haitian Gourde + HNL - Honduran Lempira + HKD - Hong Kong Dollar + HUF - Hungarian Forint + ISK - Icelandic Kr\u00f3na + INR - Indian Rupee + IDR - Indonesian Rupiah + IRR - Iranian Rial + IQD - Iraqi Dinar + ILS - Israeli New Sheqel + JMD - Jamaican Dollar + JPY - Japanese Yen + JOD - Jordanian Dinar + KZT - Kazakhstani Tenge + KES - Kenyan Shilling + KWD - Kuwaiti Dinar + KGS - Kyrgyzstani Som + LAK - Lao Kip + LVL - Latvian Lats + LBP - Lebanese Lira + LSL - Lesotho Loti + LRD - Liberian Dollar + LYD - Libyan Dinar + MOP - Macanese Pataca + MKD - Macedonian Denar + MGA - Malagasy Ariary + MWK - Malawian Kwacha + MYR - Malaysian Ringgit + MVR - Maldivian Rufiyaa + MRO - Mauritanian Ouguiya + MUR - Mauritian Rupee + MXN - Mexican Peso + MDL - Moldovan Leu + MNT - Mongolian Tugrik + MAD - Moroccan Dirham + MZN - Mozambican Metical + MMK - Myanma Kyat + NAD - Namibian Dollar + NPR - Nepalese Rupee + ANG - Netherlands Antillean Gulden + TWD - New Taiwan Dollar + NZD - New Zealand Dollar + NIO - Nicaraguan Cordoba + NGN - Nigerian Naira + KPW - North Korean Won + NOK - Norwegian Krone + OMR - Omani Rial + TOP - Paanga + PKR - Pakistani Rupee + PAB - Panamanian Balboa + PGK - Papua New Guinean Kina + PYG - Paraguayan Guarani + PEN - Peruvian Nuevo Sol + PHP - Philippine Peso + PLN - Polish Zloty + QAR - Qatari Riyal + RON - Romanian Leu + RUB - Russian Ruble + RWF - Rwandan Franc + SHP - Saint Helena Pound + WST - Samoan Tala + STD - Sao Tome And Principe Dobra + SAR - Saudi Riyal + RSD - Serbian Dinar + SCR - Seychellois Rupee + SLL - Sierra Leonean Leone + SGD - Singapore Dollar + SBD - Solomon Islands Dollar + SOS - Somali Shilling + ZAR - South African Rand + KRW - South Korean Won + XDR - Special Drawing Rights + LKR - Sri Lankan Rupee + SDG - Sudanese Pound + SRD - Surinamese Dollar + SZL - Swazi Lilangeni + SEK - Swedish Krona + CHF - Swiss Franc + SYP - Syrian Pound + TJS - Tajikistani Somoni + TZS - Tanzanian Shilling + THB - Thai Baht + TTD - Trinidad and Tobago Dollar + TND - Tunisian Dinar + TRY - Turkish New Lira + TMT - Turkmenistan Manat + AED - UAE Dirham + UGX - Ugandan Shilling + UAH - Ukrainian Hryvnia + USD - United States Dollar + UYU - Uruguayan Peso + UZS - Uzbekistani Som + VUV - Vanuatu Vatu + VEF - Venezuelan Bolivar + VND - Vietnamese Dong + XOF - West African CFA Franc + YER - Yemeni Rial + ZMW - Zambian Kwacha + + \ No newline at end of file diff --git a/android/app/src/main/res/values/styles.xml b/android/app/src/main/res/values/styles.xml index cb1ef88..1ffd453 100644 --- a/android/app/src/main/res/values/styles.xml +++ b/android/app/src/main/res/values/styles.xml @@ -15,4 +15,12 @@ + + diff --git a/android/build.gradle b/android/build.gradle index 58a8c74..6b21153 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -6,7 +6,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:7.2.0' + classpath 'com.android.tools.build:gradle:4.1.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } diff --git a/lib/main.dart b/lib/main.dart index 1b24838..15af659 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:home_widget/home_widget.dart'; import 'package:logger/logger.dart'; import 'data/prefs/preference_provider.dart'; @@ -16,6 +17,27 @@ void main() async { runApp(const MyApp()); } +Future backgroundCallback(Uri? uri) async { + if (uri?.host == 'updatecounter') { + Map? querys = uri?.queryParameters; + + int _counter = 0; + await HomeWidget.getWidgetData('_counter', defaultValue: 0).then((int? value) { + _counter = value ?? 0; + _counter++; + }); + await HomeWidget.saveWidgetData('_counter', _counter); + await HomeWidget.updateWidget(name: 'AppWidgetProvider', iOSName: 'AppWidgetProvider'); + } else if (uri?.host == 'createWidget') { + Map? querys = uri?.queryParameters; + String? id = querys?["id"]; + String? from = querys?["from"]; + String? to = querys?["to"]; + + + } +} + class MyApp extends StatelessWidget { const MyApp({super.key}); diff --git a/pubspec.lock b/pubspec.lock index 719248f..83f4454 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -282,6 +282,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.0" + home_widget: + dependency: "direct main" + description: + name: home_widget + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.6" http_multi_server: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index b107407..5fa8453 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -49,6 +49,7 @@ dependencies: mockito: ^5.3.2 json_annotation: ^4.7.0 flutter_launcher_icons: ^0.10.0 + home_widget: ^0.1.6 dev_dependencies: flutter_test: