Skip to content
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

Closed
wants to merge 16 commits into from

Conversation

DhruviChotai
Copy link
Collaborator

What type of PR is this? (check all applicable)

  • Feature
  • Bug Fix
  • Optimization

Description

Created PermissionManager class for code modularizaation.

Instructions, Screenshots, Recordings

Not Applicable as of now.

Checks

  • SonarLint
  • Locally Tested

@DhruviChotai DhruviChotai added the enhancement New feature or request label Apr 23, 2024
@@ -29,8 +32,8 @@ class MainActivity : ComponentActivity() {
SmartStorageSample(
onStoreTap = {
smartStorage.store(
location = SmartDirectory.CUSTOM,
fileName = "interstellar",
location = SmartDirectory.DOWNLOADS,
Copy link
Collaborator

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.

Copy link
Collaborator

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
Copy link
Collaborator

Choose a reason for hiding this comment

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

Complete redirection code here

Copy link
Collaborator

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()
Copy link
Collaborator

@amitsid1408 amitsid1408 Apr 25, 2024

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.

Copy link
Collaborator

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) {
Copy link
Collaborator

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, ) }

Copy link
Collaborator

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}"
Copy link
Collaborator

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

Copy link
Collaborator

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}"
Copy link
Collaborator

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.

Copy link
Collaborator

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) {
Copy link
Collaborator

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")
Copy link
Collaborator

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.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Done as per suggestion

Copy link
Collaborator

@amitsid1408 amitsid1408 left a 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

@amitsid1408
Copy link
Collaborator

Closing this PR as this is not required now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants