Skip to content
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@ app.*.map.json
/android/key.properties
*.keystore
.env

google-services.json
21 changes: 18 additions & 3 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ plugins {
id "dev.flutter.flutter-gradle-plugin"
}

def keyProperties = new Properties()
keyProperties.load(new FileInputStream(file('key.properties')))

def debugStoreFile = keyProperties.getProperty('DEBUG_STORE_FILE')
def debugStorePassword = keyProperties.getProperty('DEBUG_STORE_PASSWORD')
def debugKeyAlias = keyProperties.getProperty('DEBUG_KEY_ALIAS')
def debugKeyPassword = keyProperties.getProperty('DEBUG_KEY_PASSWORD')

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
Expand Down Expand Up @@ -41,14 +49,21 @@ android {
}

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.omedacore.notelytask"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}

signingConfigs {
debug {
storeFile file(debugStoreFile)
storePassword debugStorePassword
keyAlias debugKeyAlias
keyPassword debugKeyPassword
}
}

buildTypes {
Expand Down
2 changes: 1 addition & 1 deletion android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pluginManagement {
plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "7.3.0" apply false
id "org.jetbrains.kotlin.android" version "1.7.10" apply false
id "org.jetbrains.kotlin.android" version "1.9.23" apply false
}

include ":app"
Binary file added assets/google_drive.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 29 additions & 28 deletions lib/cubit/github_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class GithubCubit extends HydratedCubit<GithubState> {
Future<GetNotesResult> getRemoteNotes({
required BuildContext context,
String? encryptionKey,
String? redirectNoteId,
}) async {
final accessToken = state.accessToken;
final ownerRepo = state.ownerRepo;
Expand Down Expand Up @@ -89,7 +88,7 @@ class GithubCubit extends HydratedCubit<GithubState> {
final accessToken = state.accessToken;
if (accessToken == null) {
reset(shouldError: true);
return RemoteConnectionResult();
return const RemoteConnectionResult();
}
emit(state.copyWith(loading: true, error: false));

Expand All @@ -98,30 +97,31 @@ class GithubCubit extends HydratedCubit<GithubState> {
accessToken,
);

final content = existingFile?.content;

if (keepLocal || existingFile?.sha == null || content == null) {
return const RemoteConnectionResult(shouldCreateRemote: true);
}

emit(
state.copyWith(
ownerRepo: ownerRepo,
sha: existingFile?.sha,
),
);
final content = existingFile?.content;

if (keepLocal || existingFile?.sha == null || content == null) {
return RemoteConnectionResult(shouldCreateRemote: true);
}

final isEncryptedString = isEncrypted(content);
if (isEncryptedString) {
final encryptionKey = await enterEncryptionKeyDialog();
if (encryptionKey == null) {
reset(shouldError: true);
return RemoteConnectionResult();
return const RemoteConnectionResult();
}

final decrypted = decrypt(content, encryptionKey);
if (decrypted == null) {
reset(shouldError: true);
return RemoteConnectionResult();
return const RemoteConnectionResult();
}

emit(state.copyWith(loading: false));
Expand All @@ -132,12 +132,6 @@ class GithubCubit extends HydratedCubit<GithubState> {
return RemoteConnectionResult(content: content);
}

bool isLoggedIn() {
final ownerRepo = state.ownerRepo;
final accessToken = state.accessToken;
return ownerRepo != null && accessToken != null;
}

Future<FileData?> uploadNewFile(
String safeFileName,
Uint8List data,
Expand All @@ -149,7 +143,7 @@ class GithubCubit extends HydratedCubit<GithubState> {
}
emit(state.copyWith(loading: true));

var newFile = await githubRepository.createNewFile(
final newFile = await githubRepository.createNewFile(
ownerRepo,
accessToken,
data,
Expand All @@ -163,7 +157,7 @@ class GithubCubit extends HydratedCubit<GithubState> {
}

emit(state.copyWith(loading: false));
return FileData(name: safeFileName, sha: sha);
return FileData(name: safeFileName, id: sha);
}

Future<bool> deleteFile(FileData fileData) async {
Expand All @@ -177,7 +171,7 @@ class GithubCubit extends HydratedCubit<GithubState> {
bool isDeleted = await githubRepository.deleteFile(
ownerRepo,
accessToken,
fileData.sha,
fileData.id,
fileData.name,
);

Expand All @@ -193,7 +187,7 @@ class GithubCubit extends HydratedCubit<GithubState> {
final ownerRepo = state.ownerRepo;
final sha = state.sha;
final accessToken = state.accessToken;
if (!isLoggedIn() || ownerRepo == null || accessToken == null) {
if (!state.isLoggedIn() || ownerRepo == null || accessToken == null) {
return;
}
emit(state.copyWith(loading: true));
Expand All @@ -203,7 +197,7 @@ class GithubCubit extends HydratedCubit<GithubState> {
? stringifiedContent
: encrypt(stringifiedContent, encryptionKey);

var newNote = await githubRepository.createOrUpdateNotesFile(
final newNote = await githubRepository.createOrUpdateNotesFile(
ownerRepo,
accessToken,
finalizedStringContent,
Expand All @@ -222,21 +216,28 @@ class GithubCubit extends HydratedCubit<GithubState> {
}

void reset({bool shouldError = false}) {
emit(const GithubState());
emit(state.copyWith(
loading: false,
ownerRepo: null,
error: shouldError,
accessToken: null,
));
emit(
const GithubState().copyWith(
loading: false,
ownerRepo: null,
error: shouldError,
accessToken: null,
),
);
}

void invalidateError() {
emit(state.copyWith(error: false));
}

Future<void> launchLogin() async {
var loginResult = await githubRepository.initialLogin();
reset();
final loginResult = await githubRepository.initialLogin();
if (loginResult == null) {
reset(shouldError: true);
return;
}

emit(
state.copyWith(
deviceCode: loginResult.deviceCode,
Expand Down
Loading