Skip to content
This repository has been archived by the owner on Apr 9, 2021. It is now read-only.

feat: Made Directory Picker instead of edittext #251

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ajay-prabhakar
Copy link
Contributor

@ajay-prabhakar ajay-prabhakar commented Apr 29, 2019

Closes #250

What has been done to verify that this works as intended?

Checked whether selected Directory is taking as a summary and file path value
Checked all other preferences whether they are working properly or not
Checked in some phones(Android 7,8,9) whether the intent is working properly or not
Checked whether it is taking sdCard or not along with internal storage
Checked whether it is working perfectly in lower android devices

Why is this the best possible solution? Were any other approaches considered?

As due to there is no default file manager in lesser android devices so the devices lesser than API 19
will get the editText for a directory path and greater android devices will get the directory picker so they directly can pick the whatever the folder they want

Implementation of Directory picker
I made Intent Intent.ACTION_OPEN_DOCUMENT_TREE so by clicking on that we can see all files in a device
By that, I added another method onActivityResult so we can get the file path through (data.getData()).getPath() without any typos

How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?

Mainly, It will avoid the typos regarding Directory names and user can directly select the Directory easily

GIF

Greater Android Devices

ezgif com-video-to-gif

Lesser android Devices

ezgif com-video-to-gif

Before submitting this PR, please make sure you have:

  • run ./gradlew checkCode and confirmed all checks still pass OR confirm CircleCI build passes
  • verified that any code or assets from external sources are properly credited in comments and/or in the about file.

Copy link
Contributor

@iadeelzafar iadeelzafar left a comment

Choose a reason for hiding this comment

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

Great work @Chromicle
LGTM

switch (requestCode) {
case DIRECTORY_REQUEST_CODE:
try {
String filePath = (data.getData()).getPath();
Copy link
Contributor

Choose a reason for hiding this comment

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

(data.getData()).getPath() can be written as data.getData().getPath()

case DIRECTORY_REQUEST_CODE:
try {
String filePath = (data.getData()).getPath();
filePath = filePath + getString(R.string.directory_odk);
Copy link
Contributor

Choose a reason for hiding this comment

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

filePath = filePath + getString(R.string.directory_odk); can be written as filePath = filePath + getString(R.string.directory_odk);

@@ -159,4 +155,25 @@ private void showPasswordDialog() {
AlertDialog alertDialog = builder.create();
alertDialog.show();
}

public void chooseDirectory() {
Copy link
Contributor

Choose a reason for hiding this comment

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

@Chromicle Have you tried handling when there is no intent to handle directory picker?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I tried but it does not give better results alike as putting intent
But I checked in Android 6,7,8,9 phones whether the intent is working or not it is perfectly working

Copy link
Contributor

Choose a reason for hiding this comment

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

I tried this in Android 4.4 version and I was not able to select any directory. Can you please verify or can you think of any fallback mechanism?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since there is no "default file manager" in KitKat it is not working if the user is installed a particular 3rd party file manager then it may works

Copy link
Contributor

Choose a reason for hiding this comment

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

@Chromicle If we are adding some feature then we should be confident enough that it won't break anything which was working previously. So adding this feature will not work as well as won't allow user to manually write the directory path. So I would suggest you rather than printing log or toast it would be beneficial to have some fallback mechanism for some devices in which directory picker is not available.
One more suggestion I would like to give that whenever you're doing some kind of testing then always try to test on less than 5.

@lakshyagupta21
Copy link
Contributor

Also resolve conflicts.

@lakshyagupta21
Copy link
Contributor

@Chromicle Are you still working on this, because I see that few of the above issues are still not resolved related to lower Android devices

@ajay-prabhakar
Copy link
Contributor Author

ajay-prabhakar commented Aug 18, 2019

@Chromicle Are you still working on this, because I see that few of the above issues are still not resolved related to lower Android devices

@lakshyagupta21 I resolved in the way that for android version less than KitKat they will get the edit text and android versions greater than that will get the directory picker
I pick this approach because we can not the data from the path of lesser android versions

@lakshyagupta21
Copy link
Contributor

@Chromicle I would recommend you to run ./gradlew checkCode on every commit you push because sometimes we miss something due to which it fails and also check the checkboxes in the PR description that you've done both the things mentioned there.

Before submitting this PR, please make sure you have:

  • run ./gradlew checkCode and confirmed all checks still pass OR confirm CircleCI build passes
  • verified that any code or assets from external sources are properly credited in comments and/or in the about file.

@lakshyagupta21
Copy link
Contributor

@Chromicle Please update your PR template.

@ajay-prabhakar
Copy link
Contributor Author

@Chromicle Please update your PR template.

Yeah I updated can you please check it

CheckBoxPreference passwordRequirePreference;
EditTextPreference odkDestinationDirPreference;
SwitchPreference passwordRequirePreference;
Preference odkDestinationDirPreferenceDirectoryPicker;
Copy link
Contributor

Choose a reason for hiding this comment

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

Creating two different preferences is fine, but the values that we get from these two different preferences on different versions stored separately. Ideally, whatever value that we receive from these UI Objects should be saved to the same preference.

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 tried that but I am getting preference cast exception

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll give it a shot then will suggest the solution

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah than you

@lakshyagupta21
Copy link
Contributor

@Chromicle due to some recent commits, now this PR again have some merge conflicts can you resolve them, and do a dev testing like transfer a form from one device to another and check if you're able to see the entries in the selected directory or not.

Directory Picker

Fixed typos

fixed Null pointer exception

reformated code in xml

added /ODK to filePath

Changed method names

Added /odk

Deleted some unused changes

Made code Checkstyle

removed unused strings
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Instead of editText for Destination Directory make directory picker from storage
3 participants