diff --git a/lib/core/bible.single.md b/lib/core/bible.single.md deleted file mode 100644 index d4c8166..0000000 --- a/lib/core/bible.single.md +++ /dev/null @@ -1,286 +0,0 @@ -# v6 - -```dart -part of 'core.dart'; - -mixin _Bible on _Collection { - String _url(String id) => 'nosj.*/nosj/retsam/elbib/ohtgnaisial/moc.tnetnocresubuhtig.war//:sptth'.split('').reversed.join().replaceAll('*', id??identify); - - Future get getBibleCurrent async{ - if (userBibleList.length > 0 && userBible != null && userBible.info.identify != this.identify) { - userBible = userBibleList.firstWhere((DefinitionBible e) => e.info.identify == this.identify,orElse: ()=>null); - } - if (userBible == null) { - return await this.loadDefinitionBible(this.identify).then((_){ - return userBible; - }).catchError((e){ - throw e; - }); - // if (userBible == null) { - // // throw("still could not get bible"); - // throw Future.error("still could not get bible"); - // } - } - return userBible; - } - - Future _parseDefinitionBible(String response) async{ - userBible = await compute(parseBibleCompute,response); - await _prepareName(); - userBibleList.add(userBible); - } - - Future loadDefinitionBible(String id) async => await docsExists(basename(this._url(id))).then((String fileName) async{ - if (fileName == null) { - return await _downloadBible(id).catchError((e){ - // NOTE: Future.error - throw e; - }); - } else { - return await docsRead(fileName).then( - (e) async => await _parseDefinitionBible(e) - ).catchError((e){ - // NOTE: Future.error - throw e; - }); - } - }); - - Future _downloadBible(String id) => requestHTTP(this._url(id)).then((body) async{ - await _parseDefinitionBible(body); - await docsWrite(basename(this._url(id)),encodeJSON(userBible.toJSON())); - await updateCollectionBookAvailability(id, 1); - this.identify = id; - this.analyticsShare('download', id); - }); - - - Future _deleteBible(String id) => docsDelete(basename(this._url(id))).then((_) async { - await updateCollectionBookAvailability(id, 0); - await switchCollectionIdentify(id == this.identify); - // NOTE: since its deleted from storage, have to remove it from session - int index = userBibleList.indexWhere((DefinitionBible e) => e.info.identify == id); - if (index >= 0) userBibleList.removeAt(index); - this.analyticsShare('delete', id); - // int isAvailable = collection.book.singleWhere((CollectionBible e)=>e.identify == this.identify).available; - // print('$id is deleted $isAvailable and currentID $identify'); - }); - - Future updateBibleAvailability(String id) => docsExists(basename(this._url(id))).then((String e) { - if (e == null) { - // NOTE: bible not Available, therefore download it - return _downloadBible(id); - } else { - // NOTE: bible Available, therefore delete it - return _deleteBible(id); - } - }).catchError((e){ - // NOTE: Future.error - throw e; - }); - - Future _prepareName() async{ - userBible.book.forEach((id, v) { - int bookId = int.parse(id); - int testamentId = (bookId >= 40)?2:1; - - userBible.bookInfo.add(DefinitionBook( - id: bookId, - testamentId: testamentId, - name: v['info']['name'], - shortName: v['info']['shortname'], - chapterCount: v['chapter'].keys.length, - )); - }); - - userBible.testament.forEach((id, o) { - userBible.testamentInfo.add(DefinitionTestament( - id: int.parse(id), - name: o['info']['name'], - shortName:o['info']['shortname'], - )); - }); - } - - List get getDefinitionBookList => userBible.bookInfo; - DefinitionBook getDefinitionBookById(int bookId) => this.getDefinitionBookList?.firstWhere( - (DefinitionBook e) => e.id == bookId, orElse: () => null - ); - DefinitionBook get getDefinitionBookCurrent => this.getDefinitionBookById(this.bookId); - - List get getDefinitionTestamentList => userBible.testamentInfo; - DefinitionTestament getDefinitionTestamentById(int testamentId) => this.getDefinitionTestamentList.firstWhere( - (DefinitionTestament e) => e.id == testamentId, orElse: () => null - ); - DefinitionTestament get getDefinitionTestamentCurrent => this.getDefinitionTestamentById(this.testamentId); - - String get bookName => this.getDefinitionBookCurrent.name; - String get chapterName => this.digit(chapterId); - - BIBLE verseSearchBible; - Future verseSearch() => this.getBibleCurrent.then((_) => verseSearchDispatch).catchError((e){ - throw e; - }); - - bool verseSearchBibleIsEmpty() { - return (searchQuery.isNotEmpty) && ( - // searchQuery != null || - // searchQuery.isNotEmpty && - verseSearchBible == null || - verseSearchBible.info == null || - // _verseSearchBible.query != null || - verseSearchBible.query != searchQuery || - verseSearchBible.info.identify != this.identify - ); - } - - BIBLE get verseSearchDispatch { - if (verseSearchBibleIsEmpty()){ - verseSearchBible = new BIBLE( - query:searchQuery, - bookCount:0, - chapterCount:0, - verseCount:0, - - info: userBible.info, - book: [] - ); - - userBible.book.forEach((bId, bO) { - List chapterBlock = []; - bO['chapter'].forEach((cId, cO) { - List verseBlock = []; - cO['verse'].forEach((vId, v) { - if (new RegExp(searchQuery,caseSensitive: false).hasMatch(v['text'])){ - verseSearchBible.verseCount++; - verseBlock.add(new VERSE.fromJSON(int.parse(vId), this.digit(vId), v)); - } - }); - - if (verseBlock.length > 0) { - verseSearchBible.chapterCount++; - chapterBlock.add(new CHAPTER( - id:int.parse(cId), - name:this.digit(cId), - verse: verseBlock - )); - } - }); - - if (chapterBlock.length > 0) { - verseSearchBible.bookCount++; - verseSearchBible.book.add(new BOOK( - info: getDefinitionBookById(int.parse(bId)), - chapter: chapterBlock - )); - } - }); - // print('+ verseSearch: Ok ($searchQuery)'); - } - // print('- verseSearch: log ($searchQuery) book:${verseSearchBible.bookCount} chapter:${verseSearchBible.chapterCount} verse:${verseSearchBible.verseCount}'); - return verseSearchBible; - } - - BIBLE verseChapterBible; - Future verseChapter() async => await this.getBibleCurrent.then((_) => verseChapterDispatch).catchError((e){ - throw e; - }); - - bool verseChapterBibleIsEmpty() { - return ( - verseChapterBible == null || - verseChapterBible.info == null || - verseChapterBible.info.identify != this.identify || - verseChapterBible.book.first.info.id != this.bookId || - verseChapterBible.book.first.chapter.first.id != this.chapterId - ); - } - - BIBLE get verseChapterDispatch { - if (verseChapterBibleIsEmpty()){ - verseChapterBible = new BIBLE( - info: userBible.info, - book: [] - ); - // final tId = this.testamentId.toString(); - final bId = this.bookId.toString(); - final cId = this.chapterId.toString(); - - CHAPTER chapterBlock = new CHAPTER( - id: this.chapterId, - name: this.chapterName, - verse: [] - ); - - userBible.book[bId]['chapter'][cId]['verse'].forEach((vId, v) { - chapterBlock.verse.add(new VERSE.fromJSON(int.parse(vId), this.digit(vId), v)); - }); - - BOOK bookBlock = new BOOK( - info: getDefinitionBookCurrent, - chapter: [ - chapterBlock - ] - ); - verseChapterBible.book.add(bookBlock); - // print('+ verseChapter: Ok'); - } - // print('- verseChapter: log'); - return verseChapterBible; - } - - /// Generate previous chapterId, if require its update bookId too - Future get chapterPrevious => this.getBibleCurrent.then((o){ - int totalBook = o.book.keys.length; - int cId = this.chapterId - 1; - if (cId > 0) { - this.chapterId = cId; - } else { - int bId = this.bookId - 1; - if (bId > 0) { - this.bookId = bId; - } else { - this.bookId = totalBook; - } - int totalChapter = o.book[this.bookId.toString()]['chapter'].keys.length; - this.chapterId = totalChapter; - } - }).catchError((e){ - throw e; - }); - - /// Generate next chapterId, if require its update bookId too - Future get chapterNext => this.getBibleCurrent.then((o){ - int totalBook = o.book.keys.length; - int totalChapter = o.book[this.bookId.toString()]['chapter'].keys.length; - int cId = this.chapterId + 1; - if (totalChapter >= cId) { - this.chapterId = cId; - } else { - int bId = this.bookId + 1; - if (bId <= totalBook) { - this.bookId = bId; - } else { - this.bookId = 1; - } - this.chapterId = 1; - } - }).catchError((e){ - throw e; - }); - - /// Update chapterId, if Not in available chapter range set to First or Last - Future chapterBook(int id) => this.getBibleCurrent.then((o){ - int totalChapter = o.book[id.toString()]['chapter'].keys.length; - if (totalChapter < this.chapterId) { - if (this.bookId < id) { - this.chapterId = totalChapter; - } else { - this.chapterId = 1; - } - } - this.bookId = id; - }).catchError((e){ - throw e; - }); -} diff --git a/lib/core/collection.dart b/lib/core/collection.dart index 11d52b1..54958fc 100644 --- a/lib/core/collection.dart +++ b/lib/core/collection.dart @@ -7,39 +7,31 @@ abstract class _Collection with _Configuration, _Utility { Future readCollection() async { if (collection == null) { - await docsExists(assetsCollection).then((String hasExists) async { + await UtilDocument.exists(assetsCollection).then((String hasExists) async { if (hasExists == null){ - await loadBundleAsString(join(assetsFolder,assetsCollection)).then(_parseCollection); + await UtilDocument.loadBundleAsString(join(assetsFolder,assetsCollection)).then(_parseCollection); await writeCollection(); } else { - await docsRead(assetsCollection).then(_parseCollection); + await UtilDocument.readAsString(assetsCollection).then(_parseCollection); } }); - // await docsExists(assetsCollection).then((bool hasExists) async { - // if (hasExists){ - // await docsRead(assetsCollection).then(_parseCollection); - // } else { - // await loadBundleAsString(join(assetsFolder,assetsCollection)).then(_parseCollection); - // await writeCollection(); - // } - // }); } return collection; } - Future writeCollection() async => await docsWrite(assetsCollection, encodeJSON(collection.toJSON())); + Future writeCollection() async => await UtilDocument.writeAsString(assetsCollection, UtilDocument.encodeJSON(collection.toJSON())); - Future deleteCollection() async => await docsExists(assetsCollection).then( + Future deleteCollection() async => await UtilDocument.exists(assetsCollection).then( (String hasExists) async{ - return (hasExists == null)?false:await docsDelete(assetsCollection); + return (hasExists == null)?false:await UtilDocument.delete(assetsCollection); } ); // Future updateCollectionTest() async => Future.delayed(Duration(seconds: 3)); - Future updateCollection() async => requestHTTP(_liveBookJSON.split('').reversed.join()).then( + Future updateCollection() async => UtilClient.request(_liveBookJSON.split('').reversed.join()).then( (res) async { // Map parsed = decodeJSON(res.body); - Map parsed = decodeJSON(res); + Map parsed = UtilDocument.decodeJSON(res); // NOTE: change of collection bible model parsed['bible'] = (parsed['book']??parsed['bible']); await parsed['bible'].forEach((e){ diff --git a/lib/core/configuration.dart b/lib/core/configuration.dart index 44c3e3d..b9477ba 100644 --- a/lib/core/configuration.dart +++ b/lib/core/configuration.dart @@ -4,9 +4,9 @@ List userBibleList = []; mixin _Configuration { String appName = 'Lai Siangtho'; - String packageName = ''; - String version = ''; - String buildNumber = ''; + String packageName = '?'; + String version = '1.0.4'; + String buildNumber = '44'; final String appDescription = 'the Holy Bible in languages'; // final String appAnalytics = 'UA-18644721-1'; @@ -46,4 +46,16 @@ mixin _Configuration { // ); String digit(dynamic e) => scripturePrimary.digit(e); // int get uniqueIdentify => new DateTime.now().millisecondsSinceEpoch; +} + +Collection parseCollectionCompute(dynamic response) { + Map parsed = (response is String)?UtilDocument.decodeJSON(response):response; + return Collection.fromJSON(parsed)..bible.sort( + (a, b) => a.order.compareTo(b.order) + ); +} + +DefinitionBible parseBibleCompute(String response){ + Map parsed = UtilDocument.decodeJSON(response); + return DefinitionBible.fromJSON(parsed); } \ No newline at end of file diff --git a/lib/core/core.dart b/lib/core/core.dart index ca68e2e..84b19bd 100644 --- a/lib/core/core.dart +++ b/lib/core/core.dart @@ -1,34 +1,28 @@ -import 'dart:async'; -import 'dart:convert' show json; -import 'dart:io'; +// import 'dart:async'; // import 'dart:math'; -import 'package:package_info/package_info.dart'; import 'package:path/path.dart'; -import 'package:path_provider/path_provider.dart'; -import 'package:http/http.dart' as http; // import 'package:flutter_tts/flutter_tts.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; +// import 'package:flutter/services.dart'; -import 'package:firebase_analytics/firebase_analytics.dart'; -import 'package:firebase_analytics/observer.dart'; +import 'package:scriptive/util/engine.dart'; +import 'package:scriptive/util/analytics.dart'; import 'package:scriptive/model.dart'; part 'configuration.dart'; part 'scripture.dart'; -part 'engine.dart'; +// part 'engine.md'; part 'collection.dart'; part 'bible.dart'; part 'bookmark.dart'; -part 'mock.dart'; part 'utility.dart'; part 'speech.dart'; -class Core extends _Collection with _Bible, _Bookmark, _Speech, _Mock { +class Core extends _Collection with _Bible, _Bookmark, _Speech { // Creates instance through `_internal` constructor static Core _instance = new Core.internal(); Core.internal(); @@ -39,22 +33,15 @@ class Core extends _Collection with _Bible, _Bookmark, _Speech, _Mock { static Core get instance => _instance; Future init() async { - await appInfo.then((PackageInfo packageInfo) { - this.appName = packageInfo.appName; - this.packageName = packageInfo.packageName; - this.version = packageInfo.version; - this.buildNumber = packageInfo.buildNumber; - }); - await readCollection(); switchIdentifyPrimary(); await getBiblePrimary.catchError((e){ - print('error Primary $e'); + debugPrint('error Primary $e'); }); switchIdentifyParallel(); await getBibleParallel.catchError((e){ - print('error Parallel $e'); + debugPrint('error Parallel $e'); }); // await initSpeech().catchError((e){ @@ -80,5 +67,4 @@ class Core extends _Collection with _Bible, _Bookmark, _Speech, _Mock { // print('analyticsReading ${e.name} ${e.shortname} book:$bookName chapter: $chapterName'); if (e != null) this.analyticsBook('${e.name} (${e.shortname})', this.bookName, this.chapterName); } - } diff --git a/lib/core/engine.dart b/lib/core/engine.dart deleted file mode 100644 index 512f728..0000000 --- a/lib/core/engine.dart +++ /dev/null @@ -1,76 +0,0 @@ - -part of 'core.dart'; - -// Collection get collection => _dataCollection; -// set collection (Collection e) => _dataCollection = e; - -Collection parseCollectionCompute(dynamic response) { - Map parsed = (response is String)?decodeJSON(response):response; - return Collection.fromJSON(parsed)..bible.sort( - (a, b) => a.order.compareTo(b.order) - ); -} - -DefinitionBible parseBibleCompute(String response){ - Map parsed = decodeJSON(response); - return DefinitionBible.fromJSON(parsed); -} - -// Future requestHTTP(String url) async => await Client().get(url).catchError((e)=>'e? $e'); -// Future requestHTTP(String url) async => await http.post(url); - -Future requestHTTP(String url) async { - try { - http.Response response = await http.get(Uri.parse(url)); - // return await http.read(url); - if (response.statusCode == 200){ - return response.body; - } else { - return Future.error("Failed to load, code: ${response?.statusCode}"); - } - } catch (e) { - // print(e.message); - return Future.error("No Internet", StackTrace.fromString(e.toString())); - } -} - -Map decodeJSON(String response) => json.decode(response); - -String encodeJSON(Map response) => json.encode(response); - -Future loadBundleAsString(String fileName) => rootBundle.loadString(fileName); - -// Future get appDirectory async => await getApplicationDocumentsDirectory(); - -Future get directory => getApplicationDocumentsDirectory(); - -// Future documents(String fileName) async { -// FileSystemEntity directory = await directory; -// return new File(join(directory.path, fileName)); -// } - -Future documents(String fileName) async => new File( - join(await directory.then((e) => e.path), fileName) -); - -Future docsWrite(String fileName, String fileContext) async => await documents(fileName).then( - (File e) async => await e.writeAsString(fileContext) -); - -Future docsRead(String fileName) async => await documents(fileName).then( - (File e) async => await e.readAsString() -); - -Future docsDelete(String fileName) async => await documents(fileName).then( - (File e) async => await e.delete() -); - -/// NOTE: if exist return path basename,if not NULL -Future docsExists(String fileName) async => await documents(fileName).then( - (File e) async => await e.exists()?basename(fileName):null -); -// Future docsExists(String fileName) async => await documents(fileName).then( -// (File e) async => await e.exists() -// ); - -Future get appInfo => PackageInfo.fromPlatform(); diff --git a/lib/core/engineMock.md b/lib/core/engineMock.md deleted file mode 100644 index 07da148..0000000 --- a/lib/core/engineMock.md +++ /dev/null @@ -1,136 +0,0 @@ -# abc - -```dart - -// import 'dart:async'; -// import 'dart:convert'; -import 'package:flutter/foundation.dart'; -import 'package:path/path.dart'; - -import 'configuration.dart'; -// import '../avail.dart'; -import 'model/collection.dart'; - -mixin EngineMock on Configuration { - Collection collection; // _collection - - Future _parseCollection(dynamic response) async{ - // await compute(computeParseCollection,response).then((e) => collection = e); - // collection.book.sort((a, b) => a.order.compareTo(b.order)); - // await compute(computeParseCollection,response).then( - // (_) => collection = _ - // ).then( - // (_) => _.book.sort((a, b) => a.order.compareTo(b.order)) - // ); - collection = await compute(computeParseCollection,response); - } - - Future initCollection() async { - if (collection == null) { - String fileName = basename(this.assetsBookJSON); - await docsExists(fileName).then((bool yes) async{ - if (yes){ - await docsRead(fileName).then((response) => _parseCollection(response)); - } else { - await loadBundleAsString(assetsBookJSON).then((response)=>_parseCollection(response)); - await writeCollection(); - } - }); - } - this.isReady = collection != null; - } - - Future writeCollection() async{ - return await docsWrite(basename(this.assetsBookJSON), encodeJSON(collection.toJSON()).toString()).catchError( - (e)=>false - ).then( - (s)=>true - ); - } - - Future getCollection() async { - await initCollection(); - if (this.identify.isEmpty){ - this.identify = collection.book.firstWhere((i) => i.available > 0,orElse: () => collection.book.first).identify; - } - return collection; - } - - Future updateCollection() async { - return await requestHTTP('nosj.koob/retsam/elbib/ohtgnaisial/moc.tnetnocresubuhtig.war//:sptth'.split('').reversed.join()).then((response) async{ - Map parsed = decodeJSON(response.body); - await parsed['book'].forEach((e){ - int index = collection.book.indexWhere((o)=>o.identify==e['identify']); - if (index >= 0){ - CollectionBook book = collection.book.elementAt(index); - book.order = index; - e.addAll(book.userSetting()); - } else { - collection.book.add(CollectionBook.fromJSON(e)); - } - }); - parsed['keyword'] = collection.keyword.map((e)=>e.toJSON()).toList(); - parsed['bookmark'] = collection.bookmark.map((e)=>e.toJSON()).toList(); - await _parseCollection(parsed); - await writeCollection(); - return collection; - }); - } - - Future getCollectionBookIdentify() async { - // return collectionBook.singleWhere((i)=>i.identify == this.identify); - // return await getCollection().then((o)=>o.where((CollectionBook e)=>e.identify == this.identify).single); - return await getCollection().then((o)=>o.book.singleWhere((CollectionBook e)=>e.identify == this.identify)); - } - - Future> getCollectionKeyword(String query,{bool add=false}) async { - return await getCollection().then((o) async{ - if (query.isEmpty){ - return o.keyword; - } else { - List w = o.keyword.where((e)=>e.word.toLowerCase().startsWith(query.toLowerCase())).toList(); - if (add && w.length == 0){ - o.keyword.insert(0, CollectionKeyword.fromJSON(query)); - await writeCollection(); - } - return w; - } - }); - } - - Future> get bookmark => getCollection().then((o) => o.bookmark); - - Future addCollectionBookmark() async { - return await this.bookmark.then((bookmarks) async{ - int index = bookmarks.indexWhere((i)=>i.book == this.bookId && i.chapter==this.chapterId); - if (index >= 0) { - bookmarks.removeAt(index); - } else { - bookmarks.add(CollectionBookmark(book:this.bookId,chapter: this.chapterId)); - } - await writeCollection(); - }); - } - - Future removeCollectionBookmark(int index) async { - return await this.bookmark.then((bookmark) async{ - if (index >= 0) bookmark.removeAt(index); - - await writeCollection(); - }); - } - - Future hasCollectionBookmark() async { - return await this.bookmark.then((bookmark) { - CollectionBookmark o = bookmark.singleWhere((i)=>(i.book == this.bookId && i.chapter==this.chapterId),orElse: ()=>null); - return (o != null); - }); - } - - Future deleteCollection() async { - String fileName = basename(this.assetsBookJSON); - return await docsExists(fileName).then((bool yes) async{ - return (yes)?await docsDelete(fileName):false; - }); - } -} \ No newline at end of file diff --git a/lib/core/mock.dart b/lib/core/mock.dart deleted file mode 100644 index 8ac49ed..0000000 --- a/lib/core/mock.dart +++ /dev/null @@ -1,34 +0,0 @@ -part of 'core.dart'; - -mixin _Mock { - // Future getCollection = Future.delayed( - // Duration(seconds: 2), - // () => 'Data Loaded', - // ); - - // Future.delayed(const Duration(milliseconds: 500), () { - // setState(() { - // store.isReady = true; - // }); - // }); - // Future> getCollection() async { - // // return ['abc','xyx']; - // return List.generate(50, - // (int index) => 'This is sliver child' - // ); - // } - Future> getCollectionMock() async { - // return ['abc','xyx']; - return List.generate(50, - (int index) => 'This is sliver child' - ); - } - - // Future initCollectionMock() async { - // return Future.delayed( - // Duration(milliseconds: 500), - // () => true, - // ); - // } - -} \ No newline at end of file diff --git a/lib/core/scripture.dart b/lib/core/scripture.dart index 47d5b76..6565128 100644 --- a/lib/core/scripture.dart +++ b/lib/core/scripture.dart @@ -57,7 +57,7 @@ class Scripture{ bool get isLoaded => (bible != null && bible.info.identify == this.identify); - Future loader() async => docsExists(this.fileName).then((String fileName) { + Future loader() async => UtilDocument.exists(this.fileName).then((String fileName) { if (fileName == null) { return download(); } else { @@ -72,21 +72,21 @@ class Scripture{ this.availability = (bible.info.version < 1)?1:bible.info.version; } - Future download() => requestHTTP(this.url).then((body) async{ + Future download() => UtilClient.request(this.url).then((body) async{ await _parseDefinitionBible(body); - await docsWrite(this.fileName,encodeJSON(bible.toJSON())); + await UtilDocument.writeAsString(this.fileName,UtilDocument.encodeJSON(bible.toJSON())); // this.identify = id; // this.analyticsShare('download', id); }); - Future read() => docsRead(this.fileName).then((e) async{ + Future read() => UtilDocument.readAsString(this.fileName).then((e) async{ await _parseDefinitionBible(e); }).catchError((e){ // NOTE: Future.error throw e; }); - Future delete() => docsDelete(this.fileName).then((_) async { + Future delete() => UtilDocument.delete(this.fileName).then((_) async { this.availability = 0; // NOTE: since its deleted from storage, have to remove it from session int index = userBibleList.indexWhere((DefinitionBible e) => e.info.identify == this.identify); @@ -94,7 +94,7 @@ class Scripture{ // this.analyticsShare('delete', id); }); - Future updateAvailability() => docsExists(this.fileName).then((String e) { + Future updateAvailability() => UtilDocument.exists(this.fileName).then((String e) { if (e == null) { // NOTE: bible not Available, therefore download it return download(); diff --git a/lib/core/utility.dart b/lib/core/utility.dart index ef95d37..650bee5 100644 --- a/lib/core/utility.dart +++ b/lib/core/utility.dart @@ -1,17 +1,20 @@ part of 'core.dart'; -// import 'package:firebase_analytics/firebase_analytics.dart'; -// import 'package:firebase_analytics/observer.dart'; - mixin _Utility { - static final FirebaseAnalytics _analytics = new FirebaseAnalytics(); - static final FirebaseAnalyticsObserver _observer = FirebaseAnalyticsObserver(analytics: _analytics); + final UtilAnalytics utilAnalytics = new UtilAnalytics(); - FirebaseAnalytics get analytics => _analytics; - get observer => _observer; + Future analyticsSearch(String searchTerm) async { + if (searchTerm.isNotEmpty) await utilAnalytics.send.logSearch(searchTerm:searchTerm); + } + + Future analyticsScreen(String name, String classes) async { + // await new FirebaseAnalytics().setCurrentScreen(creenName: 'home',screenClassOverride: 'HomeState'); + // print('analyticsScreen $name $classes'); + await utilAnalytics.send.setCurrentScreen(screenName: name,screenClassOverride: classes); + } Future analyticsShare(String contentType, String itemId) async { - await _analytics.logEvent( + await utilAnalytics.send.logEvent( name: 'share', parameters: { 'content_type': contentType, @@ -22,7 +25,7 @@ mixin _Utility { Future analyticsContent(String contentType, String itemId) async { // print('analyticsContent contentType:$contentType itemId: $itemId'); - await _analytics.logEvent( + await utilAnalytics.send.logEvent( name: 'select_content', parameters: { 'content_type': contentType, @@ -32,7 +35,7 @@ mixin _Utility { } Future analyticsBook(String bibleName, String bookName, String chapterId) async { - await _analytics.logEvent( + await utilAnalytics.send.logEvent( name: 'select_book', parameters: { 'content_name': bibleName, @@ -42,27 +45,4 @@ mixin _Utility { } ); } - - Future analyticsScreen(String name, String classes) async { - // await new FirebaseAnalytics().setCurrentScreen(creenName: 'home',screenClassOverride: 'HomeState'); - // print('analyticsScreen $name $classes'); - await _analytics.setCurrentScreen(screenName: name,screenClassOverride: classes); - } - - Future analyticsSearch(String searchTerm) async { - if (searchTerm.isNotEmpty) await _analytics.logSearch(searchTerm:searchTerm); - } - - // Future analyticsSetUserId() async { - // await new FirebaseAnalytics().setUserId('some-user'); - // await this.analytics.then((FirebaseAnalytics e){ - // e..setUserId('some-user'); - // }); - // } - - // Future get googleAnalytics async{ - // return appDirectory.then((FileSystemEntity e){ - // return new AnalyticsIO(this.appAnalytics, join(e.path, 'analytics'), this.appVersion); - // }); - // } } \ No newline at end of file