Save and sort sheets by last access time
This commit is contained in:
@@ -1,22 +1,36 @@
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
|
||||
enum StorageKey { url, jwt, email, password }
|
||||
enum SecureStorageKey { url, jwt, email, password }
|
||||
|
||||
class StorageHelper {
|
||||
final sheetAccessTimesBox = "sheetAccessTimes";
|
||||
|
||||
late FlutterSecureStorage secureStorage;
|
||||
|
||||
StorageHelper() {
|
||||
AndroidOptions getAndroidOptions() => const AndroidOptions(
|
||||
encryptedSharedPreferences: true,
|
||||
);
|
||||
AndroidOptions getAndroidOptions() =>
|
||||
const AndroidOptions(encryptedSharedPreferences: true);
|
||||
secureStorage = FlutterSecureStorage(aOptions: getAndroidOptions());
|
||||
}
|
||||
|
||||
Future<String?> read(StorageKey key) {
|
||||
Future<String?> readSecure(SecureStorageKey key) {
|
||||
return secureStorage.read(key: key.name);
|
||||
}
|
||||
|
||||
Future<void> write(StorageKey key, String value) {
|
||||
Future<void> writeSecure(SecureStorageKey key, String value) {
|
||||
return secureStorage.write(key: key.name, value: value);
|
||||
}
|
||||
|
||||
Future<Map<String, DateTime>> readSheetAccessTimes() async {
|
||||
final box = await Hive.openBox(sheetAccessTimesBox);
|
||||
return box.toMap().map(
|
||||
(k, v) => MapEntry(k as String, DateTime.parse(v as String)),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> writeSheetAccessTime(String uuid, DateTime datetime) async {
|
||||
final box = await Hive.openBox(sheetAccessTimesBox);
|
||||
await box.put(uuid, datetime.toIso8601String());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user