From 1adf4877823d960956691d9681c93b99c746a1b6 Mon Sep 17 00:00:00 2001 From: Varakh Date: Thu, 4 Feb 2021 01:07:03 +0100 Subject: [PATCH] Automatic refresh history if something has been uploaded and add fastlane alpha and debug --- CHANGELOG.md | 3 ++ android/fastlane/Fastfile | 11 +++++++ android/fastlane/README.md | 10 ++++++ lib/app.dart | 43 ++++++++++++++------------ lib/core/enums/refresh_event.dart | 1 + lib/core/services/refresh_service.dart | 13 ++++++++ lib/core/viewmodels/history_model.dart | 23 ++++++++++++-- lib/core/viewmodels/upload_model.dart | 4 +++ lib/locator.dart | 2 ++ lib/ui/views/history_view.dart | 21 +++++++------ pubspec.yaml | 2 +- 11 files changed, 102 insertions(+), 31 deletions(-) create mode 100644 lib/core/enums/refresh_event.dart create mode 100644 lib/core/services/refresh_service.dart diff --git a/CHANGELOG.md b/CHANGELOG.md index c595851..d3af263 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ # CHANGELOG +## 1.0.0+2 +* Automatic refresh history if something has been uploaded + ## 1.0.0+1 * Initial release \ No newline at end of file diff --git a/android/fastlane/Fastfile b/android/fastlane/Fastfile index 2b94403..66b19c7 100644 --- a/android/fastlane/Fastfile +++ b/android/fastlane/Fastfile @@ -1,11 +1,22 @@ default_platform(:android) platform :android do + desc "Build Debug" + lane :build_debug do + sh("#{ENV['PWD']}/fastlane/buildAndroidDebug.sh") + end + desc "Build" lane :build do sh("#{ENV['PWD']}/fastlane/buildAndroid.sh") end + desc "Deploy a new version to the Google Play as Alpha" + lane :alpha do + build + upload_to_play_store(track: 'alpha', aab: '../build/app/outputs/bundle/release/app-release.aab') + end + desc "Deploy a new version to the Google Play as Beta" lane :beta do build diff --git a/android/fastlane/README.md b/android/fastlane/README.md index 8ea746c..0eb400f 100644 --- a/android/fastlane/README.md +++ b/android/fastlane/README.md @@ -16,11 +16,21 @@ or alternatively using `brew install fastlane` # Available Actions ## Android +### android build_debug +``` +fastlane android build_debug +``` +Build Debug ### android build ``` fastlane android build ``` Build +### android alpha +``` +fastlane android alpha +``` +Deploy a new version to the Google Play as Alpha ### android beta ``` fastlane android beta diff --git a/lib/app.dart b/lib/app.dart index f57cc34..3a7ccb6 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -4,11 +4,13 @@ import 'package:flutter_translate/localization_provider.dart'; import 'package:flutter_translate/localized_app.dart'; import 'package:provider/provider.dart'; +import 'core/enums/refresh_event.dart'; import 'core/manager/dialog_manager.dart'; import 'core/manager/lifecycle_manager.dart'; import 'core/models/session.dart'; import 'core/services/dialog_service.dart'; import 'core/services/navigation_service.dart'; +import 'core/services/refresh_service.dart'; import 'core/services/session_service.dart'; import 'locator.dart'; import 'ui/app_router.dart'; @@ -22,24 +24,27 @@ class MyApp extends StatelessWidget { return LocalizationProvider( state: LocalizationProvider.of(context).state, - child: StreamProvider( - initialData: Session.initial(), - create: (context) => locator().sessionController.stream, - child: LifeCycleManager( - child: MaterialApp( - title: translate('app.title'), - builder: (context, child) => Navigator( - key: locator().dialogNavigationKey, - onGenerateRoute: (settings) => MaterialPageRoute(builder: (context) => DialogManager(child: child)), - ), - theme: ThemeData( - brightness: Brightness.light, primarySwatch: primaryAccentColor, primaryColor: primaryAccentColor), - onGenerateRoute: AppRouter.generateRoute, - navigatorKey: locator().navigationKey, - home: StartUpView(), - supportedLocales: localizationDelegate.supportedLocales, - locale: localizationDelegate.currentLocale, - )), - )); + child: StreamProvider( + initialData: null, + create: (context) => locator().refreshHistoryController.stream, + child: StreamProvider( + initialData: Session.initial(), + create: (context) => locator().sessionController.stream, + child: LifeCycleManager( + child: MaterialApp( + title: translate('app.title'), + builder: (context, child) => Navigator( + key: locator().dialogNavigationKey, + onGenerateRoute: (settings) => MaterialPageRoute(builder: (context) => DialogManager(child: child)), + ), + theme: ThemeData( + brightness: Brightness.light, primarySwatch: primaryAccentColor, primaryColor: primaryAccentColor), + onGenerateRoute: AppRouter.generateRoute, + navigatorKey: locator().navigationKey, + home: StartUpView(), + supportedLocales: localizationDelegate.supportedLocales, + locale: localizationDelegate.currentLocale, + )), + ))); } } diff --git a/lib/core/enums/refresh_event.dart b/lib/core/enums/refresh_event.dart new file mode 100644 index 0000000..914dba5 --- /dev/null +++ b/lib/core/enums/refresh_event.dart @@ -0,0 +1 @@ +enum RefreshEvent { RefreshHistory } diff --git a/lib/core/services/refresh_service.dart b/lib/core/services/refresh_service.dart new file mode 100644 index 0000000..13abb15 --- /dev/null +++ b/lib/core/services/refresh_service.dart @@ -0,0 +1,13 @@ +import 'dart:async'; + +import '../enums/refresh_event.dart'; + +class RefreshService { + StreamController refreshHistoryController = StreamController(); + + void addEvent(RefreshEvent event) { + if (refreshHistoryController.hasListener) { + refreshHistoryController.add(event); + } + } +} diff --git a/lib/core/viewmodels/history_model.dart b/lib/core/viewmodels/history_model.dart index 220c06e..27f553a 100644 --- a/lib/core/viewmodels/history_model.dart +++ b/lib/core/viewmodels/history_model.dart @@ -1,3 +1,4 @@ +import 'dart:async'; import 'dart:io'; import 'package:flutter_translate/flutter_translate.dart'; @@ -6,6 +7,7 @@ import 'package:logger/logger.dart'; import '../../locator.dart'; import '../datamodels/dialog_response.dart'; import '../enums/error_code.dart'; +import '../enums/refresh_event.dart'; import '../enums/viewstate.dart'; import '../error/rest_service_exception.dart'; import '../error/service_exception.dart'; @@ -15,18 +17,30 @@ import '../models/uploaded_paste.dart'; import '../services/dialog_service.dart'; import '../services/file_service.dart'; import '../services/link_service.dart'; +import '../services/refresh_service.dart'; import '../util/logger.dart'; import 'base_model.dart'; class HistoryModel extends BaseModel { final Logger _logger = getLogger(); final FileService _fileService = locator(); + final RefreshService _refreshService = locator(); final LinkService _linkService = locator(); final DialogService _dialogService = locator(); - String errorMessage; + StreamSubscription _refreshTriggerSubscription; List pastes = []; + String errorMessage; + + void init() { + this._refreshTriggerSubscription = _refreshService.refreshHistoryController.stream.listen((event) { + if (event == RefreshEvent.RefreshHistory) { + _logger.d('History needs a refresh'); + getHistory(); + } + }); + } Future getHistory() async { setState(ViewState.Busy); @@ -64,7 +78,6 @@ class HistoryModel extends BaseModel { } pastes.sort((a, b) => a.date.compareTo(b.date)); - errorMessage = null; } catch (e) { if (e is RestServiceException) { @@ -148,4 +161,10 @@ class HistoryModel extends BaseModel { void openLink(String link) { _linkService.open(link); } + + @override + void dispose() { + _refreshTriggerSubscription.cancel(); + super.dispose(); + } } diff --git a/lib/core/viewmodels/upload_model.dart b/lib/core/viewmodels/upload_model.dart index b34fcd1..ed5845f 100644 --- a/lib/core/viewmodels/upload_model.dart +++ b/lib/core/viewmodels/upload_model.dart @@ -11,6 +11,7 @@ import 'package:receive_sharing_intent/receive_sharing_intent.dart'; import '../../locator.dart'; import '../enums/error_code.dart'; +import '../enums/refresh_event.dart'; import '../enums/viewstate.dart'; import '../error/rest_service_exception.dart'; import '../error/service_exception.dart'; @@ -19,6 +20,7 @@ import '../models/rest/uploaded_multi_response.dart'; import '../models/rest/uploaded_response.dart'; import '../services/file_service.dart'; import '../services/link_service.dart'; +import '../services/refresh_service.dart'; import '../util/logger.dart'; import 'base_model.dart'; @@ -26,6 +28,7 @@ class UploadModel extends BaseModel { final Logger _logger = getLogger(); final FileService _fileService = locator(); final LinkService _linkService = locator(); + final RefreshService _refreshService = locator(); TextEditingController _pasteTextController = TextEditingController(); StreamSubscription _intentDataStreamSubscription; @@ -171,6 +174,7 @@ class UploadModel extends BaseModel { clearCachedFiles(); _pasteTextController.clear(); + _refreshService.addEvent(RefreshEvent.RefreshHistory); errorMessage = null; return uploadedPasteIds; } catch (e) { diff --git a/lib/locator.dart b/lib/locator.dart index 9306122..732ae92 100644 --- a/lib/locator.dart +++ b/lib/locator.dart @@ -7,6 +7,7 @@ import 'core/services/file_service.dart'; import 'core/services/link_service.dart'; import 'core/services/navigation_service.dart'; import 'core/services/permission_service.dart'; +import 'core/services/refresh_service.dart'; import 'core/services/session_service.dart'; import 'core/services/storage_service.dart'; import 'core/viewmodels/about_model.dart'; @@ -35,6 +36,7 @@ void setupLocator() { locator.registerLazySingleton(() => FileService()); locator.registerLazySingleton(() => LinkService()); locator.registerLazySingleton(() => PermissionService()); + locator.registerLazySingleton(() => RefreshService()); /// view models locator.registerFactory(() => StartUpViewModel()); diff --git a/lib/ui/views/history_view.dart b/lib/ui/views/history_view.dart index 8bb95e8..52a11c3 100644 --- a/lib/ui/views/history_view.dart +++ b/lib/ui/views/history_view.dart @@ -21,7 +21,10 @@ class HistoryView extends StatelessWidget { var url = Provider.of(context).url; return BaseView( - onModelReady: (model) => model.getHistory(), + onModelReady: (model) { + model.init(); + return model.getHistory(); + }, builder: (context, model, child) => Scaffold( appBar: MyAppBar(title: Text(translate('titles.history'))), backgroundColor: backgroundColor, @@ -40,14 +43,6 @@ class HistoryView extends StatelessWidget { ); } - Widget _renderOpenInBrowser(HistoryModel model, String url) { - return IconButton( - icon: Icon(Icons.open_in_new, color: Colors.blue, textDirection: TextDirection.ltr), - onPressed: () { - return model.openLink(url); - }); - } - Widget _render(HistoryModel model, String url) { List cards = List(); @@ -163,4 +158,12 @@ class HistoryView extends StatelessWidget { physics: AlwaysScrollableScrollPhysics(), ); } + + Widget _renderOpenInBrowser(HistoryModel model, String url) { + return IconButton( + icon: Icon(Icons.open_in_new, color: Colors.blue, textDirection: TextDirection.ltr), + onPressed: () { + return model.openLink(url); + }); + } } diff --git a/pubspec.yaml b/pubspec.yaml index 42159bf..fe7264c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,7 +11,7 @@ description: A mobile client for FileBin. # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 1.0.0+1 +version: 1.0.0+2 environment: sdk: ">=2.7.0 <3.0.0"