Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.0.1 #43

Merged
merged 11 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/ISSUE_TEMPLATE/bug-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
name: Bug report
about: Create a report to help us improve
title: "[BUG] <title>"
labels: bug, in triage
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Version [e.g. 22]

**Additional context**
Add any other context about the problem here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea
title: ''
labels: feature, in triage
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,8 @@ app.*.symbols
**/*key.json
**/*.p8
**/*.p12
.ipa
.aab
release/


91 changes: 91 additions & 0 deletions build_release
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/bin/bash

#######################################
# Flutter Version Increment and Build Script
#######################################

# Script Usage:
# - This script must be executed from the root of the Flutter project.
# - It increments the build number in the Flutter project's pubspec.yaml file.
# - It provides options to increment the MAJOR, MINOR, or PATCH version components in
# addition to the build number.
# - Release builds for iOS and Android can be disabled using the --no-build option.
# - The appBundle and ipa file are copied to the ./release directory.

# Usage:
# ./build_release [OPTIONS]

# Available Options:
# --major Increment the MAJOR version component.
# --minor Increment the MINOR version component.
# --patch Increment the PATCH version component.
# => only one of the options above can be used at a time.
#
# --no-build Disable release builds for iOS and Android.

ios_release_build() {
# Build ipa
flutter build ipa --release

# Copy IPA file to release directory
cp build/ios/ipa/*.ipa ./release
}

android_release_build() {
# Build appBundle
flutter build appbundle --release

# Copy App Bundle file to release directory
cp build/app/outputs/bundle/release/*.aab ./release
}

# Function to execute Flutter release builds for iOS and Android
execute_flutter_release_builds() {
# Ensure release directory exists; create if not present
mkdir -p ./release

ios_release_build
android_release_build
}

# Function to increment version components in pubspec.yaml
increment_flutter_version() {
PUBSPEC_FILE="pubspec.yaml"
CURRENT_VERSION=$(awk '/version:/ {print $2}' "$PUBSPEC_FILE" | tr -d "'")
MAJOR=$(echo "$CURRENT_VERSION" | cut -d. -f1)
MINOR=$(echo "$CURRENT_VERSION" | cut -d. -f2)
PATCH=$(echo "$CURRENT_VERSION" | cut -d. -f3 | cut -d+ -f1)
BUILD=$(echo "$CURRENT_VERSION" | cut -d+ -f2)

if [ "$1" == "--major" ]; then
NEW_VERSION="$((MAJOR + 1)).0.0+$((BUILD + 1))"
elif [ "$1" == "--minor" ]; then
NEW_VERSION="$MAJOR.$((MINOR + 1)).0+$((BUILD + 1))"
elif [ "$1" == "--patch" ]; then
NEW_VERSION="$MAJOR.$MINOR.$((PATCH + 1))+$((BUILD + 1))"
else
NEW_VERSION="$MAJOR.$MINOR.$PATCH+$((BUILD + 1))"
fi

awk -v current_version="$CURRENT_VERSION" -v new_version="$NEW_VERSION" \
'$1 == "version:" && $2 == current_version { $2 = new_version } { print }' \
"$PUBSPEC_FILE" > temp && mv temp "$PUBSPEC_FILE"

echo "Flutter version incremented to $NEW_VERSION"
}

# Increment version based on provided options
if [ "$1" == "--major" ] || [ "$1" == "--minor" ] || [ "$1" == "--patch" ]; then
increment_flutter_version "$1"
elif [ "$2" == "--major" ] || [ "$2" == "--minor" ] || [ "$2" == "--patch" ]; then
increment_flutter_version "$2"
else
increment_flutter_version
fi

# Check for --no-build option to disable release builds
if [[ "$1" == "--no-build" || "$2" == "--no-build" ]]; then
echo "Release builds disabled."
else
execute_flutter_release_builds
fi
9 changes: 7 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ import 'package:engelsburg_planer/src/services/firebase/firebase_config.dart';
import 'package:engelsburg_planer/src/utils/extensions.dart';
import 'package:engelsburg_planer/src/services/data_service.dart';
import 'package:engelsburg_planer/src/services/isolated_worker.dart';
import 'package:engelsburg_planer/src/utils/logger.dart';
import 'package:flutter/material.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:logging/logging.dart';
import 'package:provider/provider.dart';

/// Initialize and run app
void main() async {
Logger.rootLevel = Level.debug;
Logger.forType<EngelsburgPlaner>().info("Starting app...");

WidgetsFlutterBinding.ensureInitialized();

await InitializingPriority.instant.initialize();
Expand Down Expand Up @@ -69,6 +72,8 @@ extension InitializingPriorityUtils on InitializingPriority{
Future initialize() {
return toInitialize.entries.where((entry) => entry.value == this).asyncMap(
(entry) async => await Future.value(entry.key.call()),
);
).then((value) {
Logger.forType<EngelsburgPlaner>().info("Initialized '$name' priority");
});
}
}
4 changes: 2 additions & 2 deletions lib/src/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import 'package:engelsburg_planer/main.dart';
import 'package:engelsburg_planer/src/backend/database/state/app_state.dart';
import 'package:engelsburg_planer/src/backend/database/state/theme_state.dart';
import 'package:engelsburg_planer/src/services/firebase/analytics.dart';
import 'package:engelsburg_planer/src/services/firebase/crashlytics.dart';
import 'package:engelsburg_planer/src/utils/extensions.dart';
import 'package:engelsburg_planer/src/utils/global_context.dart';
import 'package:engelsburg_planer/src/utils/logger.dart';
import 'package:engelsburg_planer/src/view/routing/route_generator.dart';
import 'package:engelsburg_planer/src/view/widgets/util/util_widgets.dart';
import 'package:flutter/material.dart' hide Router;
Expand All @@ -30,8 +30,8 @@ class EngelsburgPlaner extends StatelessWidget {
return Consumer2<ThemeState, AppConfigState>(
builder: (context, theme, config, _) {
var router = AppRouter.router(context);
Logger.forType<EngelsburgPlaner>().info("Start building app...");

Crashlytics.log("Start building app..");
return MaterialApp.router(
builder: NoOverScrollEffect.get,
debugShowCheckedModeBanner: false,
Expand Down
26 changes: 17 additions & 9 deletions lib/src/backend/api/request_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ class RequestService {
var prepareTime = stopwatch.elapsedMilliseconds;

//Execute request
return _request(request).timeout(timeout, onTimeout: () {
//On timeout return response with status = 999
return http.Response("", 999);

//TODO? create retry service? (callback?), exponential backoff?
}).then((response) {
//TODO? create retry service? (callback?), exponential backoff?
//On timeout or error return response with status = 999
return _request(request)
.onError((error, stackTrace) => http.Response("", 999))
.timeout(timeout, onTimeout: () => http.Response("", 999))
.then((response) {
stopwatch.stop();

RequestAnalysis analysis;
Expand Down Expand Up @@ -125,7 +125,15 @@ class RequestAnalysis {
final int? responseSize;
final bool timedOut;

const RequestAnalysis({required this.prepareTime, required this.responseTime, required this.responseSize, required this.timedOut,}) : assert(timedOut || responseTime != null);

const RequestAnalysis.timedOut(this.prepareTime) : timedOut = true, responseTime = null, responseSize = null;
const RequestAnalysis({
required this.prepareTime,
required this.responseTime,
required this.responseSize,
required this.timedOut,
}) : assert(timedOut || responseTime != null);

const RequestAnalysis.timedOut(this.prepareTime)
: timedOut = true,
responseTime = null,
responseSize = null;
}
4 changes: 2 additions & 2 deletions lib/src/backend/database/nosql/base/collection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class Collection<T> extends CollectionReference<T> {

//TODO docs
Future<List<Document<T>>> documents() async {
var cached = _storage.state.getCachedCollection(this);
if (cached != null) return cached.map((e) => e.storage(_storage)).toList();
var cached = _storage.state.getCachedCollection<T>(this);
if (cached != null) return cached.cast<DocumentReference<T>>().map((e) => e.storage(_storage)).cast<Document<T>>().toList();

var collectionData = await _storage.getCollection(path);
_storage.state.cacheCollection(this, collectionData);
Expand Down
3 changes: 0 additions & 3 deletions lib/src/backend/database/nosql/base/document.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,4 @@ class Document<T> extends DocumentReference<T> {
/// the operation was successful.
Future<bool> copyTo(Storage target) async =>
target.setDocument(path, tryParseTypedData(await load()));

@override
String toString() => 'Document{path: ${super.path}, data: $data}';
}
13 changes: 12 additions & 1 deletion lib/src/backend/database/nosql/base/references.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* Copyright (c) Paul Huerkamp 2023. All rights reserved.
*/

import 'dart:ui';

import 'package:engelsburg_planer/src/backend/database/nosql/base/collection.dart';
import 'package:engelsburg_planer/src/backend/database/nosql/base/document.dart';
import 'package:engelsburg_planer/src/backend/database/nosql/storage/storage.dart';
Expand All @@ -26,13 +28,16 @@ abstract class Reference<T> {
String get id => path.split("/").last;

@override
String toString() => 'Reference{path: $path}';
@keepToString
String toString() => path;

@override
bool operator ==(Object other) => other is Reference && path == other.path;

@override
int get hashCode => path.hashCode;

Reference<D> cast<D>(Parser<D> parser);
}

/// Same as Reference<T>, but only to documents.
Expand All @@ -55,6 +60,9 @@ class DocumentReference<T> extends Reference<T> {
);
}

@override
DocumentReference<D> cast<D>(Parser<D> parser) => DocumentReference<D>(path, parser);

/// Makes the reference concrete, links a storage to the reference.
@nonVirtual
Document<T> storage(Storage storage) => Document<T>.ref(storage, this);
Expand All @@ -76,6 +84,9 @@ class CollectionReference<T> extends Reference<T> {
parser,
);

@override
CollectionReference<D> cast<D>(Parser<D> parser) => CollectionReference<D>(path, parser);

/// Makes the reference concrete, links a storage to the reference.
@nonVirtual
Collection<T> storage(Storage storage) => Collection<T>.ref(storage, this);
Expand Down
8 changes: 6 additions & 2 deletions lib/src/backend/database/nosql/local_nosql_database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ class LocalNosqlDatabase {
);

//Save new stream and return
latest.then((value) => newController.add(value));
latest.then((value) {
if (!newController.isClosed) newController.add(value);
});
return (_documentSnapshots[path] = newController).stream;
}

Expand All @@ -124,7 +126,9 @@ class LocalNosqlDatabase {
);

//Save new stream and return
latest.then((value) => newController.add(value));
latest.then((value) {
if (!newController.isClosed) newController.add(value);
});
return (_collectionSnapshots[path] = newController).stream;
}
}
Expand Down
24 changes: 12 additions & 12 deletions lib/src/backend/database/nosql/storage/storage_cache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
import 'package:engelsburg_planer/src/backend/database/nosql/base/references.dart';
import 'package:engelsburg_planer/src/backend/database/nosql/storage/storage.dart';
import 'package:engelsburg_planer/src/utils/extensions.dart';
import 'package:flutter/foundation.dart';
import 'package:engelsburg_planer/src/utils/logger.dart';

//TODO docs
class StorageCache {
class StorageCache with Logs<Storage> {
final Map<DocumentReference, Map<String, dynamic>> _documentCache = {};
final Map<CollectionReference, Set<DocumentReference>> _collectionCache = {};

/// Writes the data of the document to the cache and also references the
/// document in the collection cache if possible.
void setDocument(DocumentReference document, Map<String, dynamic> data) {
debugPrint("[${document.id}] updating cached document: $data");
void setDocument<T>(DocumentReference<T> document, Map<String, dynamic> data) {
logger.trace("Updating cached document: $document");
//Update document cache
_documentCache[document] = data;

Expand All @@ -33,14 +33,14 @@ class StorageCache {
//TODO docs
Map<String, dynamic>? getDocument(DocumentReference document) {
var data = _documentCache[document];
if (data != null) debugPrint("[${document.id}] getting cached document: $data");
if (data != null) logger.trace("getting cached document: $document");

return data;
}

//TODO docs
void removeDocument(DocumentReference document) {
debugPrint("[${document.id}] removing cached document");
logger.trace("removing cached document: $document");
_documentCache.remove(document);

//Update parent collection
Expand All @@ -60,12 +60,12 @@ class StorageCache {
}

//TODO docs
void setCollection(CollectionReference collection, CollectionData collectionData) {
debugPrint("[${collection.id}] setting cached collection: $collectionData");
void setCollection<T>(CollectionReference<T> collection, CollectionData collectionData) {
logger.trace("setting cached collection: $collection");

//Map collection data to document references
var documents = collectionData.mapToList((key, value) {
var document = DocumentReference(key, collection.parser);
var document = DocumentReference<T>(key, collection.parser);

//Update each document
setDocument(document, value);
Expand All @@ -78,11 +78,11 @@ class StorageCache {

//TODO docs
List<DocumentReference<T>>? getCollection<T>(CollectionReference<T> collection) {
debugPrint("[${collection.id}] getting cached collection");
logger.trace("getting cached collection: $collection");

var refs = _collectionCache[collection]?.toList() ?? [];
var refs = _collectionCache[collection];

return refs.cast<DocumentReference<T>>();
return refs?.map((e) => e.cast(collection.parser)).toList() ?? [];
}

/// Returns if the data to the given reference, document or collection,
Expand Down
Loading