Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Feature google drive #2787

Closed

Conversation

mohammednawas8
Copy link
Contributor

Pull Request (PR) Checklist

Please check if your pull request fulfills the following requirements:

  • The PR is submitted to the main branch.
  • I've read the Contribution Guidelines and my PR doesn't break the "Contributing Rules".
  • I've read the Architecture Guidelines.
  • I confirm that I've run the code locally and everything works as expected.
  • 🎬 I've attached a screen recoding of the changes.

Tip: drag & drop the video to the PR description.
https://github.com/Ivy-Apps/ivy-wallet/assets/78867217/5a972c68-ffbe-423d-b292-c20ce548f15a

What's changed?

Describe with a few bullets what's new:
a Adding new option in the settings screen which is Google Drive backup
b Ability to link a google drive account to backup the user's data each 12 hours
c Ability to delete/change the drive account.

💡 Tip: Please, attach screenshots and screen recordings. It helps a lot!

Risk Factors

What may go wrong if we merge your PR?

  • a
  • b
  • c

In what cases your code won't work?

  • a
  • b
  • c

Does this PR closes any GitHub Issues?

Check Ivy Wallet Issues.

Replace ISSUE_NUMBER with your issue number (for example Closes #1234). If you've done that correctly, you'll see the issue title linked when previewing your PR description.

Troubleshooting CI failures

If you see any of the PR checks failing (❌) go to Actions and find it there. Or simply click "Details" next to the failed check and explore the logs to see why it has failed.

Detekt

Detekt is a static code analyzer for Kotlin that we use to enforce code readibility and good practices.

To run Detekt locally:

./gradlew detekt

If the Detekt errors are caused by a legacy code, you can suppress them using a basline.

Detekt baseline (not recommended)

./scripts/detektBaseline.sh

Lint

We use the standard Android Lint plus Slack's compose-lints as an addition to enforce proper Compose usage.

To run Lint locally:

./scripts/lint.sh

If the Lint errors are caused by a legacy code, you can suppress them using a basline.

Lint baseline (not recommended)

./scripts/lintBaseline.sh

Unit tests

If this job is failing this means that your changes break an existing unit test. You must identify the failing tests and fix your code.

To run the Unit tests locally:

./gradlew testDebugUnitTest

Copy link
Collaborator

@ILIYANGERMANOV ILIYANGERMANOV left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @mohammednawas8 thank you for your hard work! 🎉 Your code seems working but it we need to make some changes to make it mergeable.

You need to address:

I've pasted in the issue for reference because it features solid error handling + good type-safety.

No rush, man. If you're near the situation in Israel, please stay safe. Hope this ends soon 🙏

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove + add to .gitignore

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove + add to .gitignore

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove + add to .gitignore

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove + add to .gitignore


// This solves Could not instantiat worker issue
class CustomWorkerFactory @Inject constructor(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a better solution to this? This seems like a hack that'll become tech debt in the future

backupFile,
"${IVY_BACKUP_FILE_NAME}-${Date()}",
DriveMimeType.JSON,
5
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic Number, Detekt raised a valid error

// The reason of why i did not use hilt to inject this repo in the constructor is because i want to get the drive instance during
// The runtime, if we use hilt to inject this in the constructor the drive instance will be null when the user links his google account
// For the first time.
private fun getDriveBackRepository(context: Context): DriveBackupRepository {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use @Provides + dagger.Lazy like Lazy<DriveBackupRepository - let's use Hilt for that

internal const val IVY_FOLDER_NAME = "Ivy"
const val IVY_BACKUP_FILE_NAME = "Ivy-backup"
const val WORKER_TAG = "Ivy-Backup-Worker"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needless blank lines, Detekt has caught that too

* @param n is The capacity of the Backup folder,
* if the capacity is full then the oldest file will get deleted and get replaced by the new file.
* */
@Throws(Exception::class)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I catch the exceptions using try and catch

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @mohammednawas8 that works but the problem is that Exceptions are prone to errors and runtime crashes. We work with typed errors:
https://arrow-kt.io/learn/typed-errors/working-with-typed-errors/

TL;DR;

  • If a function is expected to fail, e.g. Network request (it happens often) we model its return type explicitly with Either
  • We throw Exceptions only for exceptional cases - situations which we don't expect to happen. For example, save to DB failing because the device is out of storage or some IO error.

Does that make sense?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i will take a look at that

file: File,
fileName: String,
mimeType: DriveMimeType,
n: Int
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is n? 😄

Copy link
Contributor Author

@mohammednawas8 mohammednawas8 Oct 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is the backup folder capacity, you mentioned it in the requirements

  • It should make up to N backup files
  • When N is reached the oldest backup is deleted.
    but anyways i changed its name to be clearer, there is a documentation in the DriveBackRepository interface that explains thethisattribute.

@ILIYANGERMANOV
Copy link
Collaborator

Hey @mohammednawas8 we also need to indicate whether Google Drive backups are enabled in Settings or not. Maybe a Switch? Or... some UI telling the user whether backups are enabled.

@mohammednawas8
Copy link
Contributor Author

Did you watch the attached video
https://github-production-user-asset-6210df.s3.amazonaws.com/78867217/274605831-5a972c68-ffbe-423d-b292-c20ce548f15a.mp4

as you can notice if the user has already linked his drive account with the app and tried to click on the google drive backup option again, a dialog will show up that shows the back up email and the ability to delete the account.

@ILIYANGERMANOV
Copy link
Collaborator

Did you watch the attached video https://github-production-user-asset-6210df.s3.amazonaws.com/78867217/274605831-5a972c68-ffbe-423d-b292-c20ce548f15a.mp4

as you can notice if the user has already linked his drive account with the app and tried to click on the google drive backup option again, a dialog will show up that shows the back up email and the ability to delete the account.

the user must be able to notice that w/o having to click. Like having different UI states on the button. If enabled for example a green pill saying "Enabled"

@mohammednawas8
Copy link
Contributor Author

okay i will work on it

@mohammednawas8
Copy link
Contributor Author

I added a green text in the same option
https://github.com/Ivy-Apps/ivy-wallet/assets/78867217/695408f3-daba-4e53-a46e-8a2b0d97191d

@ILIYANGERMANOV
Copy link
Collaborator

ILIYANGERMANOV commented Oct 12, 2023

I added a green text in the same option https://github.com/Ivy-Apps/ivy-wallet/assets/78867217/695408f3-daba-4e53-a46e-8a2b0d97191d

Screenshot_20231012_222438_Chrome

Remove the ✔️ and use only "Enabled" with 1dp border radius green. Other than that looks good!

@mohammednawas8
Copy link
Contributor Author

Like this
enable flag

@ILIYANGERMANOV
Copy link
Collaborator

Like this enable flag

It's a perfect! Just do

  • vertical padding 4.dp or 8.dp
  • horizontal 16.dp

@github-actions github-actions bot added the Stale No activity, will be automatically closed soon. label Oct 15, 2023
@github-actions github-actions bot closed this Oct 16, 2023
@github-actions github-actions bot added Stale No activity, will be automatically closed soon. and removed Stale No activity, will be automatically closed soon. labels Oct 19, 2023
@github-actions github-actions bot closed this Oct 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Stale No activity, will be automatically closed soon.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Google Drive auto-backups Example issue
2 participants