-
Notifications
You must be signed in to change notification settings - Fork 736
Conversation
There was a problem hiding this 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:
- proper error handling using Arrow (https://github.com/Ivy-Apps/ivy-wallet/blob/deprecated-ivywallet-rewrite-2223/drive/google-drive/src/main/java/com/ivy/drive/google_drive/GoogleDriveServiceImpl.kt)
- Don't suppress Detekt errors in your module - fix them.
- Add Unit tests using Mockk for all classes
- Ideally, it should look like the implementation which we did last year:
https://github.com/Ivy-Apps/ivy-wallet/tree/deprecated-ivywallet-rewrite-2223/drive/google-drive/src/main/java/com/ivy/drive/google_drive
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 🙏
.idea/codeStyles/Project.xml
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove + add to .gitignore
.idea/codeStyles/codeStyleConfig.xml
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove + add to .gitignore
.idea/deploymentTargetDropDown.xml
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove + add to .gitignore
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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" | ||
|
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's very bad! Throwing exceptions leads to unexpected crash. Please use Arrow's Either
like we did in https://github.com/Ivy-Apps/ivy-wallet/blob/deprecated-ivywallet-rewrite-2223/drive/google-drive/src/main/java/com/ivy/drive/google_drive/GoogleDriveServiceImpl.kt
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is n
? 😄
There was a problem hiding this comment.
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.
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. |
Did you watch the attached video 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" |
okay i will work on it |
I added a green text in the same option |
Remove the ✔️ and use only "Enabled" with 1dp border radius green. Other than that looks good! |
Pull Request (PR) Checklist
Please check if your pull request fulfills the following requirements:
main
branch.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.
Risk Factors
What may go wrong if we merge your PR?
In what cases your code won't work?
Does this PR closes any GitHub Issues?
Check Ivy Wallet Issues.
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:
If the Detekt errors are caused by a legacy code, you can suppress them using a basline.
Detekt baseline (not recommended)
Lint
We use the standard Android Lint plus Slack's compose-lints as an addition to enforce proper Compose usage.
To run Lint locally:
If the Lint errors are caused by a legacy code, you can suppress them using a basline.
Lint baseline (not recommended)
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: