Skip to content

Commit

Permalink
developed sharing feature & solved issue #36
Browse files Browse the repository at this point in the history
  • Loading branch information
matteo-convertino committed Apr 10, 2024
1 parent 89bdd65 commit cfe7a33
Show file tree
Hide file tree
Showing 68 changed files with 2,257 additions and 1,175 deletions.
16 changes: 11 additions & 5 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
plugins {
id "com.android.application"
id "kotlin-android"
id "dev.flutter.flutter-gradle-plugin"
}

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
Expand All @@ -14,10 +20,10 @@ if (credentialsPropertiesFile.exists()) {
}
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
/*def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
}*/

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
Expand All @@ -29,9 +35,9 @@ if (flutterVersionName == null) {
flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
/*apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"*/

android {
compileSdkVersion 34
Expand Down Expand Up @@ -97,5 +103,5 @@ flutter {
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.9.10"
}
13 changes: 0 additions & 13 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
buildscript {
ext.kotlin_version = '1.9.10'
repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:7.2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

allprojects {
repositories {
google()
Expand Down
30 changes: 22 additions & 8 deletions android/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
include ':app'
pluginManagement {
def flutterSdkPath = {
def properties = new Properties()
file("local.properties").withInputStream { properties.load(it) }
def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
return flutterSdkPath
}()

def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
def properties = new Properties()
includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")

assert localPropertiesFile.exists()
localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}

def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"
plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "7.2.0" apply false
id "org.jetbrains.kotlin.android" version "1.9.10" apply false
}

include ":app"
File renamed without changes
Binary file added assets/images/no_results.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 19 additions & 16 deletions lib/bloc/account_details/account_details_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,39 +1,42 @@
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:otp_manager/bloc/account_details/account_details_event.dart';
import 'package:otp_manager/bloc/account_details/account_details_state.dart';
import 'package:otp_manager/models/account.dart';
import 'package:otp_manager/repository/local_repository.dart';
import 'package:otp_manager/repository/interface/account_repository.dart';
import 'package:otp_manager/repository/interface/shared_account_repository.dart';
import 'package:otp_manager/repository/interface/user_repository.dart';
import 'package:otp_manager/routing/constants.dart';

import '../../domain/account_service.dart';
import '../../routing/navigation_service.dart';

class AccountDetailsBloc
extends Bloc<AccountDetailsEvent, AccountDetailsState> {
final LocalRepositoryImpl localRepositoryImpl;
final Account account;
final UserRepository userRepository;
final AccountRepository accountRepository;
final AccountService accountService;
final SharedAccountRepository sharedAccountRepository;
final dynamic account; // Account | SharedAccount

final NavigationService _navigationService = NavigationService();

AccountDetailsBloc({
required this.localRepositoryImpl,
required this.userRepository,
required this.accountRepository,
required this.accountService,
required this.sharedAccountRepository,
required this.account,
}) : super(
AccountDetailsState.initial(account, localRepositoryImpl.getUser()!),
AccountDetailsState.initial(account, userRepository.get()!),
) {
on<DeleteAccount>(_onDeleteAccount);
}

void _onDeleteAccount(
DeleteAccount event, Emitter<AccountDetailsState> emit) {
if (localRepositoryImpl.setAccountAsDeleted(state.account.id)) {
emit(state.copyWith(
accountDeleted:
"${state.account.type == "totp" ? "TOTP" : "HOTP"} has been removed"));
_navigationService.resetToScreen(homeRoute);
} else {
emit(state.copyWith(
accountDeleted: "There was an error while deleting the account"));
_navigationService.goBack();
}
accountService.setAsDeleted(state.account);

emit(state.copyWith(
message: "${state.account.type.toUpperCase()} has been removed"));
_navigationService.resetToScreen(homeRoute);
}
}
22 changes: 12 additions & 10 deletions lib/bloc/account_details/account_details_state.dart
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
import 'package:equatable/equatable.dart';
import 'package:otp_manager/models/user.dart';

import '../../models/account.dart';

class AccountDetailsState extends Equatable {
final Account account;
final String accountDeleted;
final dynamic account; // Account | ShareAccount
final String message;
final String password;
final String serverUrl;

const AccountDetailsState({
required this.account,
required this.accountDeleted,
required this.message,
required this.password,
required this.serverUrl,
});

AccountDetailsState.initial(this.account, User user)
: accountDeleted = "",
password = user.password ?? "";
: message = "",
password = user.password!,
serverUrl = user.url;

AccountDetailsState copyWith({String? accountDeleted}) {
AccountDetailsState copyWith({String? message}) {
return AccountDetailsState(
account: account,
accountDeleted: accountDeleted ?? this.accountDeleted,
message: message ?? this.message,
password: password,
serverUrl: serverUrl,
);
}

@override
List<Object> get props => [accountDeleted];
List<Object> get props => [message];
}
21 changes: 8 additions & 13 deletions lib/bloc/auth/auth_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,31 @@ import 'package:crypto/crypto.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:otp_manager/bloc/auth/auth_event.dart';
import 'package:otp_manager/bloc/auth/auth_state.dart';
import 'package:otp_manager/repository/local_repository.dart';
import 'package:otp_manager/repository/interface/user_repository.dart';
import 'package:otp_manager/routing/constants.dart';

import '../../domain/nextcloud_service.dart';
import '../../models/user.dart';
import '../../routing/navigation_service.dart';

class AuthBloc extends Bloc<AuthEvent, AuthState> {
final LocalRepositoryImpl localRepositoryImpl;
final UserRepository userRepository;
final NextcloudService nextcloudService;
late User user = localRepositoryImpl.getUser()!;
late User user = userRepository.get()!;

final NavigationService _navigationService = NavigationService();

AuthBloc({
required this.localRepositoryImpl,
required this.userRepository,
required this.nextcloudService,
}) : super(
AuthState.initial(localRepositoryImpl.getUser()!),
) {
}) : super(const AuthState.initial()) {
on<Authenticated>(_onAuthenticated);
on<PasswordSubmit>(_onPasswordSubmit);
on<PasswordChanged>(_onPasswordChanged);
on<ResetAttempts>(_onResetAttempts);
on<ShowFingerAuth>(_onShowFingerAuth);

if (state.password != "") {
if (user.password != null) {
add(ShowFingerAuth());
}
}
Expand All @@ -51,7 +49,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
DateTime.now().add(const Duration(minutes: 5));
}

localRepositoryImpl.updateUser(user);
userRepository.update(user);
}

void _onResetAttempts(ResetAttempts event, Emitter<AuthState> emit) {
Expand All @@ -75,9 +73,6 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
if (state.attempts == 0) {
emit(state.copyWith(attempts: 3));
}

emit(state.copyWith(isError: false));
emit(state.copyWith(isError: true));
}

void _onAuthenticated(Authenticated event, Emitter<AuthState> emit) {
Expand All @@ -100,7 +95,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
user.password = password;
user.iv = iv;

localRepositoryImpl.updateUser(user);
userRepository.update(user);
} else {
_error(emit, result["error"]!);
return;
Expand Down
13 changes: 3 additions & 10 deletions lib/bloc/auth/auth_state.dart
Original file line number Diff line number Diff line change
@@ -1,45 +1,38 @@
import 'package:equatable/equatable.dart';
import 'package:otp_manager/models/user.dart';

class AuthState extends Equatable {
final int attempts;
final String password;
final String message;
final bool isError;
final bool canShowFingerAuth;

const AuthState({
required this.attempts,
required this.password,
required this.message,
required this.isError,
required this.canShowFingerAuth,
});

AuthState.initial(User user)
const AuthState.initial()
: attempts = 3,
password = user.password ?? "",
password = "",
message = "",
isError = false,
canShowFingerAuth = false;

AuthState copyWith({
int? attempts,
String? password,
String? message,
bool? isError,
bool? canShowFingerAuth,
}) {
return AuthState(
attempts: attempts ?? this.attempts,
password: password ?? this.password,
message: message ?? this.message,
isError: isError ?? this.isError,
canShowFingerAuth: canShowFingerAuth ?? this.canShowFingerAuth,
);
}

@override
List<Object> get props =>
[attempts, password, message, isError, canShowFingerAuth];
List<Object> get props => [attempts, password, message, canShowFingerAuth];
}
Loading

0 comments on commit cfe7a33

Please sign in to comment.