Skip to content
This repository has been archived by the owner on Jan 29, 2023. It is now read-only.

Show number of items #83

Closed
wants to merge 8 commits into from
Closed

Show number of items #83

wants to merge 8 commits into from

Conversation

pavlospt
Copy link

Resolves #79

Added number of items label in directories showing the number of contained files:

  • No items when directory has 0 items
  • 1 item when directory has 1 item
  • # items when directory has more items

These should also be translated I guess! Leaving this up to you to handle the translations @veniosg :)

Copy link
Owner

@veniosg veniosg left a comment

Choose a reason for hiding this comment

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

Apologies for the ton of comments, most should be easy fixes!

@@ -39,6 +39,13 @@ public void fileInList(String filename) {
)).check(matches(isDisplayed()));
}

public void numOfItemsLabel(String numOfItemsLabel) {
Copy link
Owner

Choose a reason for hiding this comment

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

Please rename this to fileInfoInList

Copy link
Author

Choose a reason for hiding this comment

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

Done!

@@ -105,7 +105,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
holder.primaryInfo.setText(item.getName());
holder.secondaryInfo.setText(item.getFormattedModificationDate(convertView.getContext()));
// Hide directories' size as it's irrelevant if we can't recursively find it.
holder.tertiaryInfo.setText(item.getFile().isDirectory()? "" : item.getFormattedSize(
holder.tertiaryInfo.setText(item.getFile().isDirectory() ? item.getNumberOfItems(convertView.getContext()) : item.getFormattedSize(
Copy link
Owner

Choose a reason for hiding this comment

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

This should be extracted to FileHolder#getSizeInfo(Context ctx)

Copy link
Author

Choose a reason for hiding this comment

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

Done!

@@ -41,7 +41,7 @@ void bind(String filePath, OnItemClickListener listener) {

primaryInfo.setText(item.getName());
secondaryInfo.setText(item.getFormattedModificationDate(context));
tertiaryInfo.setText(isDirectory ? "" : item.getFormattedSize(context, false));
tertiaryInfo.setText(isDirectory ? item.getNumberOfItems(context) : item.getFormattedSize(context, false));
Copy link
Owner

Choose a reason for hiding this comment

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

Used here too. Ideally getNumberOfItems and getFormattedSize will now be private.

Copy link
Author

Choose a reason for hiding this comment

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

Done!

@@ -32,9 +33,12 @@
import java.io.File;

public class FileHolder implements Parcelable, Comparable<FileHolder> {

Copy link
Owner

Choose a reason for hiding this comment

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

Please remove this space :D

Copy link
Author

Choose a reason for hiding this comment

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

Done!


int numOfDirectoryItems = mFile.listFiles().length;

if (numOfDirectoryItems == 0) {
Copy link
Owner

Choose a reason for hiding this comment

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

This should all be handled by a single plural. This will also force a single point of return for the happy case.

Copy link
Author

Choose a reason for hiding this comment

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

@veniosg Plurals in English are a hard thing. Zero is not treated as a special case in English especially. Check this for example https://stackoverflow.com/questions/5651902/android-plurals-treatment-of-zero! Maybe I can check the current configuration or locale and only do it in English.

Copy link
Owner

Choose a reason for hiding this comment

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

Oh of course, good catch! In that case, it's acceptable to keep 0 items in the zero case in English to let the system handle plural localisation. This would involve duplicating the value of the many_items resource, but OneSky is smart enough to handle that so don't worry.

<?xml version="1.0" encoding="utf-8"?>
<resources>
<plurals name="num_of_directory_items">
<item quantity="one">1 item</item>
Copy link
Owner

Choose a reason for hiding this comment

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

Should still be %1$s item so it's properly localised if need be.

Copy link
Author

Choose a reason for hiding this comment

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

Done!

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
Copy link
Owner

Choose a reason for hiding this comment

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

Let's keep this file but point to strings in strings.xml. If it's allowed, this should be marked as translatable=false.

e.g. <item quantity="zero">@string/no_items</item>

Copy link
Author

Choose a reason for hiding this comment

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

Done!

private final File oneItemContainerDir = new File(testDirectoryWithOneItem, "oneItemContainerDir");
private final File multipleItemsContainerDir = new File(testDirectoryWithMultipleItems, "multipleItemsContainerDir");

private File oneFile = null;
Copy link
Owner

Choose a reason for hiding this comment

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

Make final and initialize the same way as the rest.

Copy link
Owner

Choose a reason for hiding this comment

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

Maybe also name these three something more consistent like countTestFile1/2/3

Copy link
Author

Choose a reason for hiding this comment

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

Done!

private final File testDirectoryWithOneItem = new File(sdCardDir, "testDirWithOneItem");
private final File testDirectoryWithMultipleItems = new File(sdCardDir, "testDirWithMultipleItems");

private final File zeroItemsContainerDir = new File(testDirectoryWithZeroItems, "zeroItemsContainerDir");
Copy link
Owner

Choose a reason for hiding this comment

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

What's the difference with the files above?

Copy link
Author

Choose a reason for hiding this comment

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

Done!

@@ -38,6 +40,17 @@
private final File testChildDirectory = new File(testDirectory, "testChildDir");
private final File testCopyDestination = new File(testDirectory, "testCopyDestination");
private final File testChildFile = new File(testDirectory, "testChildFile");
private final File testDirectoryWithZeroItems = new File(sdCardDir, "testDirWithZeroItems");
Copy link
Owner

@veniosg veniosg Dec 11, 2017

Choose a reason for hiding this comment

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

Please create these under testDirectory. That way you need nothing more in tearDown, everything should be cleaned up by cleanDirectory(testDirectory)

Copy link
Author

Choose a reason for hiding this comment

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

Done!

@@ -143,7 +143,7 @@ protected void onPostExecute(String result) {

@Override
protected String doInBackground(Void... params) {
return mFileHolder.getFormattedSize(getActivity(), true);
return mFileHolder.getSizeInfo(getActivity(), true);
Copy link
Owner

Choose a reason for hiding this comment

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

AFAIK this will break the details Dialog. We should still use getFormattedSize(ctx, true) here.

return Formatter.formatFileSize(c, getSizeInBytes(recursive));
}

private String getNumberOfItems(@NonNull Context context) {
Copy link
Owner

Choose a reason for hiding this comment

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

Maybe rename to getFormattedNumberOfItems for consistency

Update strings, names, scopes
Fix details dialog
Fix test crash
@veniosg
Copy link
Owner

veniosg commented Dec 18, 2017

Any update on this? I'd love to include it in 1.5 :)

@pavlospt
Copy link
Author

@veniosg Sorry is there a pending thing on this?

@veniosg
Copy link
Owner

veniosg commented Dec 19, 2017

AFAIK the new test still doesn't pass. That should be all though

@pavlospt
Copy link
Author

@veniosg ok will check it when I got some free time!

@veniosg
Copy link
Owner

veniosg commented Dec 19, 2017 via email

@pavlospt
Copy link
Author

I guess it can be closed!

@pavlospt pavlospt closed this May 10, 2018
@veniosg
Copy link
Owner

veniosg commented May 12, 2018

It was very close to being completed. Feel free to reopen if you're keen to fix the test and get it merged :)
Thanks for the effort!

@pavlospt
Copy link
Author

Ohh thought it was fixed... i guess i can find some time to fix it then!

@pavlospt pavlospt reopened this May 12, 2018
@pavlospt pavlospt closed this Dec 14, 2021
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.

Show number of items instead of size for directories
2 participants