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

Commit

Permalink
WIP #1
Browse files Browse the repository at this point in the history
Replace ListFragment with RecyclerViewFragment
Update FileListAdapter
Update item click listener wiring
Add empty view tests, and moved the logic in RecyclerViewFragment

Ref #73
  • Loading branch information
George Venios committed Feb 12, 2018
1 parent d9b1b79 commit 5d45542
Show file tree
Hide file tree
Showing 16 changed files with 328 additions and 268 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ public class FileManagerActivityTest {
private final Android android = android(intentsRule);
private final File storageDir = Environment.getExternalStorageDirectory();
private final File testDirectory = new File(storageDir, "testDir");
private final File testEmptyDirectory = new File(testDirectory, "emptyDir");
private final File testChildFile = new File(testDirectory, "testChildFile");

@SuppressWarnings("ResultOfMethodCallIgnored")
@Before
public void setUp() throws Exception {
testDirectory.mkdir();
testEmptyDirectory.mkdir();
testChildFile.createNewFile();
}

Expand Down Expand Up @@ -96,6 +98,20 @@ public void launchesSearchForCurrentDirectory() throws Exception {
android.launched().searchIntentFor(testDirectory);
}

@Test
public void showsEmptyViewWhenDirectoryEmpty() throws Exception {
user.launches().viewWithFileScheme(testEmptyDirectory);

user.sees().emptyView();
}

@Test
public void doesNotShowEmptyViewWhenDirectoryHasItems() throws Exception {
user.launches().viewWithFileScheme(testDirectory);

user.cannotSee().emptyView();
}

@Test
@Ignore
public void filtersBasedOnMimetypeExtra() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public void visibleSearchResult(File result) {
}

public void searchEmptyView() {
emptyView();
}

public void emptyView() {
onView(withId(R.id.empty_text))
.check(matches(not(isDisplayed())));
onView(withId(R.id.empty_img))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ public void searchEmptyView() {
viewWithId(R.id.empty_img);
}

public void emptyView() {
onView(allOf(
withId(R.id.empty_text),
withText("Folder empty")
)).check(matches(isDisplayed()));
viewWithId(R.id.empty_img);
}

private void viewWithId(@IdRes int id) {
onView(withId(id)).check(matches(isDisplayed()));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2014 George Venios
* Copyright (C) 2018 George Venios
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,47 +16,36 @@

package com.veniosg.dir.android.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.veniosg.dir.R;
import com.veniosg.dir.android.adapter.viewholder.FileListViewHolder;
import com.veniosg.dir.android.adapter.viewholder.FileListViewHolder.OnItemClickListener;
import com.veniosg.dir.android.fragment.RecyclerViewFragment;
import com.veniosg.dir.mvvm.model.FileHolder;
import com.veniosg.dir.android.ui.ViewHolder;

import java.util.List;

import static com.nostra13.universalimageloader.core.ImageLoader.getInstance;
import static com.veniosg.dir.android.misc.ThumbnailHelper.requestIcon;

public class FileHolderListAdapter extends BaseAdapter {
public class FileHolderListAdapter extends RecyclerView.Adapter<FileListViewHolder>
implements RecyclerViewFragment.ClickableAdapter {
private List<FileHolder> mItems;
private int mItemLayoutId = R.layout.item_filelist;

private OnItemToggleListener mOnItemToggleListener;
private OnItemToggleListener mOnItemToggleListener;
private OnItemClickListener onItemClickListener;

public FileHolderListAdapter(List<FileHolder> files){
mItems = files;
setHasStableIds(true);
}

@Override
public boolean hasStableIds() {
return true;
}

@Override
public int getCount() {
public int getItemCount() {
return mItems.size();
}

@Override
@Nullable
public Object getItem(int position) {
public FileHolder getItem(int position) {
if (position < 0 || position >= mItems.size()) return null;

return mItems.get(position);
Expand All @@ -67,53 +56,15 @@ public long getItemId(int position) {
return position;
}

/**
* Set the layout to be used for item drawing.
* @param resId The item layout id. 0 to reset.
*/
public void setItemLayout(int resId){
if(resId > 0)
mItemLayoutId = resId;
else
mItemLayoutId = R.layout.item_filelist;
}

/**
* Creates a new list item view, along with it's ViewHolder set as a tag.
* @return The new view.
*/
private View newView(Context context){
View view = LayoutInflater.from(context).inflate(mItemLayoutId, null);

ViewHolder holder = new ViewHolder();
holder.icon = (ImageView) view.findViewById(R.id.icon);
holder.primaryInfo = (TextView) view.findViewById(R.id.primary_info);
holder.secondaryInfo = (TextView) view.findViewById(R.id.secondary_info);
holder.tertiaryInfo = (TextView) view.findViewById(R.id.tertiary_info);

view.setTag(holder);
return view;
}
@Override
public FileListViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new FileListViewHolder(parent);
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
FileHolder item = mItems.get(position);
if(convertView == null)
convertView = newView(parent.getContext());
ViewHolder holder = (ViewHolder) convertView.getTag();

getInstance().cancelDisplayTask(holder.icon);
holder.icon.setImageDrawable(item.getBestIcon());
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(
convertView.getContext(), false));

requestIcon(item, holder.icon);

return convertView;
}
@Override
public void onBindViewHolder(FileListViewHolder holder, int position) {
holder.bind(getItem(position), onItemClickListener);
}

public OnItemToggleListener getOnItemToggleListener() {
return mOnItemToggleListener;
Expand All @@ -123,11 +74,12 @@ public void setOnItemToggleListener(OnItemToggleListener mOnItemToggleListener)
this.mOnItemToggleListener = mOnItemToggleListener;
}

private boolean shouldLoadIcon(FileHolder item){
return item.getFile().isFile() && !item.getMimeType().equals("video/mpeg");
}
@Override
public void setOnItemClickListener(OnItemClickListener onClickListener) {
this.onItemClickListener = onClickListener;
}

public interface OnItemToggleListener {
public void onItemToggle(int position);
void onItemToggle(int position);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;

import com.veniosg.dir.android.adapter.FileListViewHolder.OnItemClickListener;
import com.veniosg.dir.android.adapter.viewholder.FileListViewHolder.OnItemClickListener;
import com.veniosg.dir.android.adapter.viewholder.SearchListViewHolder;

import java.util.List;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
package com.veniosg.dir.android.adapter;
/*
* Copyright (C) 2018 George Venios
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.veniosg.dir.android.adapter.viewholder;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
Expand All @@ -10,9 +26,8 @@
import com.veniosg.dir.R;
import com.veniosg.dir.mvvm.model.FileHolder;

import java.io.File;

import static android.view.LayoutInflater.from;
import static com.nostra13.universalimageloader.core.ImageLoader.getInstance;
import static com.veniosg.dir.android.misc.ThumbnailHelper.requestIcon;
import static com.veniosg.dir.android.ui.Themer.getThemedResourceId;

Expand All @@ -22,25 +37,26 @@ public class FileListViewHolder extends RecyclerView.ViewHolder {
TextView secondaryInfo;
private TextView tertiaryInfo;

FileListViewHolder(ViewGroup parent) {
public FileListViewHolder(ViewGroup parent) {
super(from(parent.getContext()).inflate(R.layout.item_filelist, parent, false));

icon = (ImageView) itemView.findViewById(R.id.icon);
primaryInfo = (TextView) itemView.findViewById(R.id.primary_info);
secondaryInfo = (TextView) itemView.findViewById(R.id.secondary_info);
tertiaryInfo = (TextView) itemView.findViewById(R.id.tertiary_info);
icon = itemView.findViewById(R.id.icon);
primaryInfo = itemView.findViewById(R.id.primary_info);
secondaryInfo = itemView.findViewById(R.id.secondary_info);
tertiaryInfo = itemView.findViewById(R.id.tertiary_info);

int selectorRes = getThemedResourceId(parent.getContext(), android.R.attr.listChoiceBackgroundIndicator);
itemView.setBackgroundResource(selectorRes);
}

void bind(String filePath, OnItemClickListener listener) {
public void bind(FileHolder item, OnItemClickListener listener) {
Context context = itemView.getContext();
FileHolder item = new FileHolder(new File(filePath), context);
boolean isDirectory = item.getFile().isDirectory();

getInstance().cancelDisplayTask(icon);
primaryInfo.setText(item.getName());
secondaryInfo.setText(item.getFormattedModificationDate(context));
// Hide directories' size as it's irrelevant if we can't recursively find it.
tertiaryInfo.setText(isDirectory ? "" : item.getFormattedSize(context, false));
icon.setImageDrawable(item.getBestIcon());
requestIcon(item, icon);
Expand All @@ -49,6 +65,6 @@ void bind(String filePath, OnItemClickListener listener) {
}

public interface OnItemClickListener {
public void onClick(View itemView, FileHolder item);
void onClick(View itemView, FileHolder item);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (C) 2018 George Venios
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.veniosg.dir.android.adapter.viewholder;

import android.view.ViewGroup;

import com.veniosg.dir.mvvm.model.FileHolder;

import java.io.File;

public class SearchListViewHolder extends FileListViewHolder {
public SearchListViewHolder(ViewGroup parent) {
super(parent);
}

public void bind(String filePath, OnItemClickListener listener) {
FileHolder fileHolder = new FileHolder(new File(filePath), itemView.getContext());
super.bind(fileHolder, listener);
secondaryInfo.setText(filePath);
}
}
Loading

0 comments on commit 5d45542

Please sign in to comment.