parent
76b32e69ff
commit
49bc2bdd16
@ -0,0 +1,32 @@
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
|
||||
import 'package:smartfit_app_mobile/modele/helper.dart';
|
||||
|
||||
class ActivitySaver {
|
||||
String saveDirectory = "activities";
|
||||
late final Directory applicationDocumentsDir;
|
||||
|
||||
ActivitySaver._create(this.applicationDocumentsDir);
|
||||
|
||||
static Future<ActivitySaver> create() async {
|
||||
final appDir = await getApplicationDocumentsDirectory();
|
||||
return ActivitySaver._create(appDir);
|
||||
}
|
||||
|
||||
Future<void> saveActivity(Uint8List activityFile, String filename) async {
|
||||
final file = await File(
|
||||
p.join(applicationDocumentsDir.path, saveDirectory, filename))
|
||||
.create(recursive: true); // To create dir if not exists
|
||||
file.writeAsBytesSync(activityFile);
|
||||
}
|
||||
|
||||
File getActivity(String filename) {
|
||||
final file =
|
||||
File(p.join(applicationDocumentsDir.path, saveDirectory, filename));
|
||||
return file;
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
class Helper {
|
||||
static bool isPlatformWeb() {
|
||||
if (kIsWeb) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
import 'dart:convert';
|
||||
import 'package:smartfit_app_mobile/modele/api/i_data_strategy.dart';
|
||||
import 'package:smartfit_app_mobile/modele/local_db/model.dart';
|
||||
import 'package:tuple/tuple.dart';
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
import 'package:smartfit_app_mobile/main.dart';
|
||||
|
||||
class RequestLocal implements IDataStrategy {
|
||||
@override
|
||||
Future<Tuple2> getInfoUser(String token) async {
|
||||
final User user = localDB.userBox.get(1);
|
||||
Map<String, String> json = {"email": user.email, "username": user.username};
|
||||
return Tuple2(true, jsonEncode(json));
|
||||
}
|
||||
|
||||
// need to save file on request_api.upload() beforehand.
|
||||
@override
|
||||
Future<Tuple2> getFile(String token, String fileUuid) async {
|
||||
return const Tuple2(true, "to implement");
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Tuple2> getFiles(String token) async {
|
||||
final List<dynamic> activities = localDB.activityBox.getAll();
|
||||
List<Map<String, dynamic>> jsonList = List.empty(growable: true);
|
||||
|
||||
for (Activity act in activities) {
|
||||
Map<String, dynamic> json = {
|
||||
"uuid": act.uuid,
|
||||
"filename": act.filename,
|
||||
"category": act.category,
|
||||
"creation_date": act.date,
|
||||
"info": act.info
|
||||
};
|
||||
jsonList.add(json);
|
||||
}
|
||||
|
||||
return Tuple2(true, jsonEncode(activities));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Tuple2<bool, String>> modifAttribut(
|
||||
String token, String nameAttribut, String newValue) async {
|
||||
return const Tuple2(false, "not implemented");
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Tuple2<bool, String>> postUser(
|
||||
String email, String hash, String username) async {
|
||||
return const Tuple2(false, "not implemented");
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Tuple2<bool, String>> deleteUser(String token) async {
|
||||
return const Tuple2(false, "not implemented");
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Tuple2<bool, String>> connexion(String email, String hash) async {
|
||||
return const Tuple2(false, "not implemented");
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Tuple2<bool, String>> uploadFile(String token, File file) async {
|
||||
return const Tuple2(false, "not implemented");
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Tuple2<bool, String>> uploadFileByte(
|
||||
String token,
|
||||
Uint8List contentFile,
|
||||
String nameFile,
|
||||
String category,
|
||||
String date) async {
|
||||
return const Tuple2(false, "not implemented");
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> deleteFile(String token, String fileUuid) async {
|
||||
throw Exception("Not Implemented");
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
import 'package:smartfit_app_mobile/modele/api/i_data_strategy.dart';
|
||||
import 'package:smartfit_app_mobile/modele/api/request_api.dart';
|
||||
|
||||
class ProfileUtil {
|
||||
final IDataStrategy _dataStrategy = RequestApi();
|
||||
|
||||
void modifyDataUser(String token, String attribut, String newUsername) {
|
||||
_dataStrategy.modifAttribut(token, attribut, newUsername);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue