-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Permission Manager created #9
Conversation
@@ -29,8 +32,8 @@ class MainActivity : ComponentActivity() { | |||
SmartStorageSample( | |||
onStoreTap = { | |||
smartStorage.store( | |||
location = SmartDirectory.CUSTOM, | |||
fileName = "interstellar", | |||
location = SmartDirectory.DOWNLOADS, |
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.
Place appropriate file name and add some comments about SmartDirectory enum usage.
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.
Done as per suggestion.
} | ||
|
||
PermissionStatus.REDIRECT_TO_SETTINGS -> { | ||
//Redirection |
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.
Complete redirection code here
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.
Redirect to manage all files permission in settings done.
if(fileDetails != null){ | ||
if(fileDetails!!.location == SmartDirectory.CUSTOM){ | ||
PermissionStatus.DENIED -> { | ||
Toast.makeText(activity, "Permission Denied", Toast.LENGTH_SHORT).show() |
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.
Define string resource and use it here. Don't use hard coded strings.
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.
Hard-coded strings removed
val uri: Uri? = result.data?.data | ||
if (uri != null) { | ||
baseDocumentTreeUri = uri | ||
if (fileDetails != null) { |
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.
FileDetails null check can be handled as follows. That way we can eliminate !! usage. :
fileDetails?.let { writeFileToDocumentTree( baseDocumentTreeUri, it.name, it.fileData, ) }
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.
Used lateinit to prevent null checks all over.
@@ -118,18 +103,26 @@ class SmartStorage(private val activity: ComponentActivity) { | |||
if (!fileName.isNullOrEmpty()) "$fileName.$fileType" else "smartStorage.${fileType.name}" |
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.
In case on null file name we can use timestamp or random alphanumeric character sequence to give name to file
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.
Done as per suggestion
@@ -118,18 +103,26 @@ class SmartStorage(private val activity: ComponentActivity) { | |||
if (!fileName.isNullOrEmpty()) "$fileName.$fileType" else "smartStorage.${fileType.name}" |
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.
Be cautious while using "!" operator in if condition. If you do have option without using it you can check your logic please do that.
Reason behind this is Unnecessary Condition Negation operation will be performed and it'll impact time complexity.
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.
Done as per suggestion
|
||
|
||
private fun callFileDetails() { | ||
if (fileDetails != null) { |
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.
Please do null check as above mentioned in comment.
@@ -166,7 +165,8 @@ class SmartStorage(private val activity: ComponentActivity) { | |||
private fun handleFileCreation(location: String, context: Context): File? { | |||
return when (location) { | |||
SmartDirectory.INTERNAL -> context.filesDir | |||
SmartDirectory.EXTERNAL_APP -> context.getExternalFilesDir(null) | |||
SmartDirectory.EXTERNAL_PUBLIC -> Environment.getExternalStoragePublicDirectory("SmartStorage") |
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.
External public directory name should be App Name which uses our library.
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.
Done as per suggestion
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.
Added some review comments, otherwise LGTM
…o refactor/permission-manager
Closing this PR as this is not required now |
What type of PR is this? (check all applicable)
Description
Created PermissionManager class for code modularizaation.
Instructions, Screenshots, Recordings
Not Applicable as of now.
Checks