Skip to content

Commit

Permalink
Merge pull request #64 from 3Dpass/dev
Browse files Browse the repository at this point in the history
FEATURE: None rotation mode. Version: 2.13.0
  • Loading branch information
L3odr0id authored Mar 16, 2024
2 parents 17b93e4 + 66190e8 commit 47fc41c
Show file tree
Hide file tree
Showing 89 changed files with 2,706 additions and 1,008 deletions.
10 changes: 9 additions & 1 deletion assets/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -353,5 +353,13 @@
"contact_name_exists": "Du hast bereits einen Kontakt mit diesem Namen angelegt. Bitte verwende einen anderen.",
"no_contacts": "Du hast noch keine Kontakte angelegt.",
"delete_contact_confirm_title": "Kontakt {} löschen?",
"delete_contact_confirm_text": "Sind Sie sich sicher, dass sie den Kontakt {} mit der Adresse {} löschen möchten?"
"delete_contact_confirm_text": "Sind Sie sich sicher, dass sie den Kontakt {} mit der Adresse {} löschen möchten?",

"edit_action": "Bearbeiten {} (id: {})",
"edit_action_submit": "Bearbeiten",
"max_value": "Max Value",
"textfield_not_empty": "Das Textfeld {} darf nicht leer sein.",
"max_value_multiplier": "Max Value muss ein Multiplikator von 10 sein.",
"input_exceeds_limit": "Max Value muss weniger als 10^8 sein.",
"input_not_a_number": "Max Value muss eine Zahl sein."
}
25 changes: 23 additions & 2 deletions assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@
"other": "{} objects"
},
"reset_objects_cache_plural": "{} cached",
"objects_list_appbar_title": "{} in storage",
"objects_list_appbar_title": "{} on the storage",
"no_objects": "No cached objects",
"bad_address": "Wrong address format",
"delete_snapshots_dialog_title": "Delete snapshots",
Expand All @@ -410,5 +410,26 @@
"uploaded_object_id": "id: ",
"uploaded_object_status": "Status: ",
"uploaded_object_owner": "Owner: ",
"uploaded_object_hashes": "Object's hashes: "
"uploaded_object_hashes": "Object's hashes: ",

"@2.13.0":{
},
"rename_object_button_label": "Rename object",
"rename_object_dialog_title": "Rename object",
"rename_object_dialog_action": "Apply",
"scan_one_more_time_button_label": "Scan one more time",

"edit_action": "Edit {} (id: {})",
"edit_action_submit": "Edit",
"max_value": "Max Value",
"textfield_not_empty": "The text field must not be empty.",
"max_value_multiplier": "Max Value must be a multiplier of 10.",
"input_exceeds_limit": "Max Value must be less than 10^8.",
"input_not_a_number": "Max Value must be a number.",

"trans_bytes_none": "None",
"trans_bytes_random": "Random",
"trans_bytes_specific": "Specific",

"trans_bytes_mode_help": "Set rotation bytes mode to None to upload an object"
}
1 change: 1 addition & 0 deletions lib/core/persistence/hive_setup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Future<void> hiveSetup() async {
Hive.registerAdapter<PreviewSettings>(PreviewSettingsAdapter());
Hive.registerAdapter<AppSettings>(AppSettingsAdapter());
Hive.registerAdapter<Contact>(ContactAdapter());
Hive.registerAdapter<TransBytesMode>(TransBytesModeAdapter());
// poScan objects
Hive.registerAdapter<UploadedObject>(UploadedObjectAdapter());

Expand Down
6 changes: 6 additions & 0 deletions lib/core/utils/m_app_install_date.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import 'package:threedpass/setup.dart';

class MAppInstallDate {
static const String instanceName = 'app_install_date';
static DateTime? get() => getIt<DateTime>(instanceName: instanceName);
}
12 changes: 11 additions & 1 deletion lib/core/widgets/buttons/elevated_button.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
import 'package:threedpass/core/theme/d3p_colors.dart';
import 'package:threedpass/core/theme/d3p_special_styles.dart';
import 'package:threedpass/core/theme/d3p_theme.dart';

Expand Down Expand Up @@ -74,7 +75,16 @@ class D3pElevatedButton extends StatelessWidget {
style: ButtonStyle(
foregroundColor: foregroundColor != null
? MaterialStateProperty.all(foregroundColor)
: null,
: MaterialStateProperty.resolveWith(
(final states) {
if (states.contains(MaterialState.disabled)) {
return D3pColors
.disabled; // Theme.of(context).colorScheme.onSurface;
} else {
return Colors.white;
}
},
),
backgroundColor: backgroundColor != null && onPressed != null
? MaterialStateProperty.all(backgroundColor)
: null,
Expand Down
23 changes: 23 additions & 0 deletions lib/core/widgets/buttons/enum_buttons_list.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'package:flutter/material.dart';
import 'package:threedpass/core/widgets/buttons/enum_button.dart';

class EnumButtonsList extends StatelessWidget {
final int length;
final EnumButton Function(BuildContext, int) itemBuilder;

const EnumButtonsList({
required this.length,
required this.itemBuilder,
super.key,
});

@override
Widget build(final BuildContext context) {
return ListView.builder(
shrinkWrap: true,
itemCount: length,
physics: const NeverScrollableScrollPhysics(),
itemBuilder: itemBuilder,
);
}
}
2 changes: 1 addition & 1 deletion lib/core/widgets/screen_lock/d3p_screen_lock_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class D3pScreenLockTheme {
buttonStyle: OutlinedButton.styleFrom(
foregroundColor: colors.themeOpposite,
backgroundColor: colors.pinButtonBGColor,
shape: RoundedRectangleBorder(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(
D3pCardTheme.radius,
),
Expand Down
14 changes: 11 additions & 3 deletions lib/core/widgets/utc_time.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,31 @@ import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:threedpass/core/theme/d3p_colors.dart';
import 'package:threedpass/core/theme/d3p_special_styles.dart';
import 'package:threedpass/core/widgets/text/d3p_body_medium_text.dart';

class UTCTime extends StatelessWidget {
const UTCTime({required this.dateTime, required this.formatter, super.key});

final DateTime dateTime;
final DateTime? dateTime;
final DateFormat formatter;

@override
Widget build(BuildContext context) {
Widget build(final BuildContext context) {
if (dateTime == null) {
return const D3pBodyMediumText(
'null',
translate: false,
);
}

final medium = Theme.of(context).customTextStyles.d3pBodyMedium;
final small = Theme.of(context).customTextStyles.d3pBodySmall;

return RichText(
text: TextSpan(
children: [
TextSpan(
text: formatter.format(dateTime),
text: formatter.format(dateTime!),
style: medium,
),
WidgetSpan(
Expand Down
2 changes: 1 addition & 1 deletion lib/features/app/presentation/global_states_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class GlobalStatesProvider extends StatelessWidget {
lazy: false,
),
BlocProvider<NotificationsBloc>(
create: (_) => di_setup.getIt<NotificationsBloc>(),
create: (final _) => di_setup.getIt<NotificationsBloc>(),
),
],
child: PlatformProvider(
Expand Down
25 changes: 24 additions & 1 deletion lib/features/hashes_list/bloc/hashes_list_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import 'dart:io';
import 'package:bloc/bloc.dart';
import 'package:flutter/material.dart';
import 'package:logger/logger.dart';
import 'package:super_core/super_core.dart';
import 'package:threedpass/core/polkawallet/utils/log.dart';
import 'package:threedpass/features/hashes_list/domain/entities/hash_object.dart';
import 'package:threedpass/features/hashes_list/domain/entities/objects_directory.dart';
import 'package:threedpass/features/hashes_list/domain/entities/snapshot.dart';
Expand All @@ -24,6 +26,7 @@ class HashesListBloc extends Bloc<HashesListEvent, HashesListState> {
on<ReplaceSnapshot>(_replaceSnapshot);
on<_LoadHashesList>(_loadList);
on<UnmarkNewSnap>(_unmarkNewSnap);
on<ReplaceObject>(_replaceObject);
}

final HashesRepository hashesRepository;
Expand Down Expand Up @@ -235,17 +238,37 @@ class HashesListBloc extends Bloc<HashesListEvent, HashesListState> {
// replace it with new one
if (oldSnapIndex != -1) {
obj.snapshots[oldSnapIndex] = event.snap.copyWith(isNew: false);
emit(
HashesListLoaded(
objects: list,
globalKeyMap: buildMap(list),
),
);
} else {
getIt<Logger>().e(
'Not found a snapshot in object ${obj.name}. Snapshot name=${event.snap.name}',
);
}
}
}

Future<void> _replaceObject(
final ReplaceObject event,
final Emitter<HashesListState> emit,
) async {
if (state is HashesListLoaded) {
final stateLL = state as HashesListLoaded;
final list = stateLL.objects;
list.replace(event.oldObj, event.newObj);
emit(
HashesListLoaded(
objects: list,
globalKeyMap: buildMap(list),
globalKeyMap: stateLL.globalKeyMap,
),
);
} else {
logE('Replace object is called, but state is not HashesListLoaded');
return;
}
}
}
10 changes: 10 additions & 0 deletions lib/features/hashes_list/bloc/hashes_list_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ class ReplaceSnapshot extends HashesListEvent {
final HashObject object;
}

class ReplaceObject extends HashesListEvent {
const ReplaceObject({
required this.oldObj,
required this.newObj,
});

final HashObject newObj;
final HashObject oldObj;
}

class AddObject extends HashesListEvent {
const AddObject({
required this.object,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class SnapshotFileFactory {
filePath: filePath,
transBytes: transBytes,
algorithm: algo,
// updateIsolateListener: scanIsolateCubit.setData,
sendNone: settings.transBytesMode == TransBytesMode.none,
);

return calculator.calcHashes(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ class _TransBytes {
});

Future<String> calc() async {
final String userTransBytes = scanSettings.transBytes;

if (userTransBytes.isNotEmpty) {
return userTransBytes;
switch (scanSettings.transBytesMode) {
case TransBytesMode.none:
return '';
case TransBytesMode.random:
return RandomHex.generate(8);
case TransBytesMode.specific:
return scanSettings.transBytes;
}

final randomTransBytes = RandomHex.generate(8);
return randomTransBytes;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:threedpass/features/hashes_list/bloc/hashes_list_bloc.dart';
import 'package:threedpass/features/hashes_list/domain/entities/hash_object.dart';
import 'package:threedpass/features/hashes_list/domain/entities/snapshot.dart';

extension FindHashObjectBySnapshot on HashesListLoaded {
HashObject? findBySnapshot(final Snapshot snapshot) {
for (final hashObject in this.objects) {
if (hashObject.snapshots.contains(snapshot)) {
return hashObject;
}
}

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ class PoscanObjectsCubit extends Cubit<PoscanObjectsState> {
logE("Could not load objects count from poscan. $e");
},
right: (final objLen) async {
if (objLen != state.objects.length) {
emit(state.copyWith(storageCount: objLen));
}
await load(from: 0, till: objLen);
},
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:hive/hive.dart';
import 'package:threedpass/core/polkawallet/utils/log.dart';

part 'uploaded_object.g.dart';

Expand All @@ -22,21 +23,29 @@ class UploadedObject {
const UploadedObject({
required this.id,
required this.raw,
// required this.owner,
// required this.hashes,
// required this.status,
required this.cacheDate,
// required this.statusDateUTC,
});

DateTime get statusDateUTC {
final d1 =
(raw['state'] as Map).values.first.toString().replaceAll(',', '');
final d2 = int.parse(d1);
final initialDate = DateTime(2022, DateTime.august, 30, 21, 36);
final realStatus = initialDate.add(Duration(minutes: d2));

return realStatus;
DateTime? get statusDateUTC {
try {
final dynamic values =
(raw['state'] as Map).values.first; // Can be 685,523 or [793,188, 0]
String rawDate = '';
if (values is String) {
rawDate = values;
} else if (values is List<dynamic>) {
rawDate = values.first.toString();
}
final d1 = rawDate.replaceAll(',', '');
final d2 = int.parse(d1);
final initialDate = DateTime(2022, DateTime.august, 30, 21, 36);
final realStatus = initialDate.add(Duration(minutes: d2));

return realStatus;
} on Object catch (e) {
logE('UploadedObject statusDateUTC ' + e.toString() + ' $raw');
return null;
}
}

String get owner => raw['owner'] as String;
Expand Down
Loading

0 comments on commit 47fc41c

Please sign in to comment.