Skip to content

add grid view option when choosing a file from within the app#301

Merged
tobiasKaminsky merged 3 commits intonextcloud:masterfrom
apicellaj:master
Oct 6, 2016
Merged

add grid view option when choosing a file from within the app#301
tobiasKaminsky merged 3 commits intonextcloud:masterfrom
apicellaj:master

Conversation

@apicellaj
Copy link
Contributor

Implemented a grid view option for choosing a file from the app as mentioned in #185

@AndyScherzinger
Copy link
Member

Hi @apicellaj

thank you very much for your PR and welcome to Nextcloud. I did a small test and found two (minor) issues (for code review please see code comments):

  • grid/list state information gets lost during screen rotation: switch to grid view and rotate device, the menu still say "grid view" instead of "list view"
  • The grid view doesn't use the right layout file and grid width, see screenshot 1, while it should use the one the "regular" file listing view would use, see screenshot 2

Screenshot 1
device-2016-10-04-230925

Screenshot 2
device-2016-10-04-231417

R.drawable.ic_view_module));
mFileListFragment.switchToListView();
} else {
item.setTitle(getApplicationContext().getString(R.string.action_switch_list_view));
Copy link
Member

@AndyScherzinger AndyScherzinger Oct 4, 2016

Choose a reason for hiding this comment

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

getApplicationContext() should be removed

@apicellaj
Copy link
Contributor Author

Hi @AndyScherzinger

Thanks for the feedback and the warm welcome. The two issues seem to be resolved but let me know if you would like anything changed.

@AndyScherzinger
Copy link
Member

@apicellaj thanks for the code changes! 👍

@tobiasKaminsky please have a look, now the grid view for local files would look like this:
device-2016-10-05-103545

--> The local files grid view does distinguish between grid-item and grid-image (image/video) which it can't at the moment since we would have to dynamically detect the mime type. That is possible but we do not have a implementation for that. So I would say it is out of scope and rather open another issue for this matter and declare this one feature complete. What do you think?

@AndyScherzinger
Copy link
Member

Slight update, with some customization of the code:

@Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;
        File file = null;
        boolean isGridView = true;
        LayoutInflater inflator = (LayoutInflater) mContext
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        if (mFiles != null && mFiles.length > position && mFiles[position] != null) {
            file = mFiles[position];
        }

        // Find out which layout should be displayed
        ViewType viewType;
        if (parent instanceof GridView) {
            String mimeType = MimetypeIconUtil.getBestMimeTypeByFilename(file.getName());
            if (file != null && (MimetypeIconUtil.isImage(mimeType) || MimetypeIconUtil.isVideo(mimeType))) {
                viewType = ViewType.GRID_IMAGE;
            } else {
                viewType = ViewType.GRID_ITEM;
            }
        } else {
            viewType = ViewType.LIST_ITEM;
            isGridView = false;
        }

        // create view only if differs, otherwise reuse
        if (convertView == null || convertView.getTag() != viewType) {
            switch (viewType) {
                case GRID_IMAGE:
                    view = inflator.inflate(R.layout.grid_image, parent, false);
                    view.setTag(ViewType.GRID_IMAGE);
                    break;
                case GRID_ITEM:
                    view = inflator.inflate(R.layout.grid_item, parent, false);
                    view.setTag(ViewType.GRID_ITEM);
                    break;
                case LIST_ITEM:
                    view = inflator.inflate(R.layout.list_item, parent, false);
                    view.setTag(ViewType.LIST_ITEM);
                    break;
            }
        }

        if (file != null) {
            if(!ViewType.GRID_IMAGE.equals(viewType)) {
                TextView fileName = (TextView) view.findViewById(R.id.Filename);
                String name = file.getName();
                fileName.setText(name);
            }
            ....

leads to this:
device-2016-10-05-111101

@tobiasKaminsky I would apply these changes after we merged this PR since I did some refactorings in the background for MimeType utils and ViewType etc. etc.

@AndyScherzinger
Copy link
Member

@tobiasKaminsky what do you think? I'd say merge + another PR later on. 👍

@AndyScherzinger AndyScherzinger added this to the Nextcloud App 1.4.0 milestone Oct 5, 2016
@tobiasKaminsky tobiasKaminsky merged commit 7525088 into nextcloud:master Oct 6, 2016
@tobiasKaminsky
Copy link
Member

@apicellaj thank you very much for your contribution!

@AndyScherzinger
Copy link
Member

Thank you very much for your contribution @apicellaj 🎉 It will be included in the next stable-feature release 🚀

@apicellaj
Copy link
Contributor Author

Great! Thanks again for your feedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants