-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- use object box as cache provider - store all item actions in cache - use virtual markers to distinct between saved and intermediate state
- Loading branch information
Showing
33 changed files
with
713 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
part of '../converters.dart'; | ||
|
||
extension CampaignActionParsing on CampaignAction { | ||
PosterCreateModel getSerializedAsPosterCreate() { | ||
var data = jsonDecode(serialized!) as Map<String, dynamic>; | ||
if (data['photo'] != null) { | ||
data['photo'] = (data['photo'] as List<dynamic>).cast<int>(); | ||
} | ||
data['location'] = (data['location'] as List<dynamic>).cast<double>(); | ||
|
||
var model = PosterCreateModel.fromJson(data); | ||
return model; | ||
} | ||
|
||
PosterUpdateModel getSerializedAsPosterUpdate() { | ||
var data = jsonDecode(serialized!) as Map<String, dynamic>; | ||
if (data['photo'] != null) { | ||
data['photo'] = (data['photo'] as List<dynamic>).cast<int>(); | ||
} | ||
data['location'] = (data['location'] as List<dynamic>).cast<double>(); | ||
|
||
var model = PosterUpdateModel.fromJson(data); | ||
return model; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
part of '../converters.dart'; | ||
|
||
extension DateTimeParsing on DateTime { | ||
String getDateTimeAsString() { | ||
DateTime datetime = this; | ||
final dateString = DateFormat(t.campaigns.poster.date_format).format(datetime); | ||
final timeString = DateFormat(t.campaigns.poster.time_format).format(datetime); | ||
return t.campaigns.poster.datetime_display_template | ||
.replaceAll('{date}', dateString) | ||
.replaceAll('{time}', timeString); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
lib/app/services/converters/poster_create_model_parsing.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
part of '../converters.dart'; | ||
|
||
extension PosterCreateModelParsing on PosterCreateModel { | ||
MarkerItemModel transformToVirtualMarkerItem(int temporaryId) { | ||
return MarkerItemModel.virtual( | ||
id: temporaryId, | ||
status: PoiServiceType.poster.getAsMarkerItemStatus(PosterStatus.ok), | ||
location: location, | ||
); | ||
} | ||
|
||
PosterDetailModel transformToPosterDetailModel(int temporaryId) { | ||
return PosterDetailModel( | ||
id: temporaryId.toString(), | ||
status: PosterStatus.ok, | ||
address: address, | ||
thumbnailUrl: null, | ||
imageUrl: null, | ||
location: location, | ||
comment: '', | ||
createdAt: '${DateTime.now().getDateTimeAsString()}*', // should mark this as preliminary | ||
isCached: true, | ||
); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
lib/app/services/converters/poster_update_model_parsing.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
part of '../converters.dart'; | ||
|
||
extension PosterUpdateModelParsing on PosterUpdateModel { | ||
MarkerItemModel transformToVirtualMarkerItem() { | ||
return MarkerItemModel.virtual( | ||
id: int.parse(id), | ||
status: PoiServiceType.poster.getAsMarkerItemStatus(status), | ||
location: location, | ||
); | ||
} | ||
|
||
PosterDetailModel transformToPosterDetailModel(int temporaryId) { | ||
return PosterDetailModel( | ||
id: temporaryId.toString(), | ||
status: status, | ||
address: address, | ||
thumbnailUrl: null, | ||
imageUrl: null, | ||
location: location, | ||
comment: comment, | ||
createdAt: '${DateTime.now().getDateTimeAsString()}*', // should mark this as preliminary | ||
isCached: true, | ||
); | ||
} | ||
|
||
PosterUpdateModel mergeWith(PosterUpdateModel newPosterUpdate) { | ||
var oldPosterUdpate = this; | ||
|
||
return newPosterUpdate.copyWith( | ||
removePreviousPhotos: newPosterUpdate.removePreviousPhotos || oldPosterUdpate.removePreviousPhotos, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:gruene_app/objectbox_generated_code/objectbox.g.dart'; | ||
import 'package:path/path.dart' as p; | ||
import 'package:path_provider/path_provider.dart'; | ||
|
||
class ObjectBox { | ||
static ObjectBox? _instance; | ||
|
||
// ObjectBox._(); | ||
|
||
factory ObjectBox() => _instance!; | ||
|
||
/// The Store of this app. | ||
late final Store store; | ||
|
||
ObjectBox._create(this.store) { | ||
// Add any additional setup code, e.g. build queries. | ||
} | ||
|
||
/// Create an instance of ObjectBox to use throughout the app. | ||
static Future<void> init() async { | ||
final docsDir = await getApplicationDocumentsDirectory(); | ||
final store = await openStore(directory: p.join(docsDir.path, 'wk-cache')); | ||
_instance = ObjectBox._create(store); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.