Merge pull request #301 from apicellaj/master

add grid view option when choosing a file from within the app
This commit is contained in:
Tobias Kaminsky 2016-10-06 20:29:21 +02:00 committed by GitHub
commit 7525088db2
4 changed files with 64 additions and 17 deletions

View file

@ -39,4 +39,10 @@
app:showAsAction="never"
android:title="@string/actionbar_sort"
android:contentDescription="@string/actionbar_sort"/>
<item
android:id="@+id/action_switch_view"
android:icon="@drawable/ic_view_module"
android:orderInCategory="3"
app:showAsAction="never"
android:title="@string/action_switch_grid_view" />
</menu>

View file

@ -29,6 +29,8 @@ import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.ActionBar;
import android.view.Menu;
import android.view.MenuItem;
@ -46,6 +48,7 @@ import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.ui.dialog.ConfirmationDialogFragment;
import com.owncloud.android.ui.dialog.ConfirmationDialogFragment.ConfirmationDialogFragmentListener;
import com.owncloud.android.ui.dialog.IndeterminateProgressDialog;
import com.owncloud.android.ui.fragment.ExtendedListFragment;
import com.owncloud.android.ui.fragment.LocalFileListFragment;
import com.owncloud.android.utils.FileStorageUtils;
@ -148,7 +151,7 @@ public class UploadFilesActivity extends FileActivity implements
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
actionBar.setListNavigationCallbacks(mDirectories, this);
// wait dialog
if (mCurrentDialog != null) {
mCurrentDialog.dismiss();
@ -179,6 +182,8 @@ public class UploadFilesActivity extends FileActivity implements
getMenuInflater().inflate(R.menu.upload_files_picker, menu);
MenuItem selectAll = menu.findItem(R.id.action_select_all);
setSelectAllMenuItem(selectAll, mSelectAll);
MenuItem switchView = menu.findItem(R.id.action_switch_view);
switchView.setTitle(isGridView() ? R.string.action_switch_list_view : R.string.action_switch_grid_view);
return super.onCreateOptionsMenu(menu);
}
@ -223,6 +228,18 @@ public class UploadFilesActivity extends FileActivity implements
builder.create().show();
break;
}
case R.id.action_switch_view: {
if (isGridView()) {
item.setTitle(getString(R.string.action_switch_grid_view));
item.setIcon(R.drawable.ic_view_module);
mFileListFragment.switchToListView();
} else {
item.setTitle(getApplicationContext().getString(R.string.action_switch_list_view));
item.setIcon(R.drawable.ic_view_list);
mFileListFragment.switchToGridView();
}
return true;
}
default:
retval = super.onOptionsItemSelected(item);
}
@ -515,4 +532,17 @@ public class UploadFilesActivity extends FileActivity implements
finish();
}
}
private boolean isGridView() {
return getListOfFilesFragment().isGridEnabled();
}
private ExtendedListFragment getListOfFilesFragment() {
Fragment listOfFiles = mFileListFragment;
if (listOfFiles != null) {
return (ExtendedListFragment) listOfFiles;
}
Log_OC.e(TAG, "Access to unexisting list of files fragment!!");
return null;
}
}

View file

@ -25,7 +25,9 @@ import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
@ -103,10 +105,12 @@ public class LocalFileListAdapter extends BaseAdapter implements FilterableListA
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
boolean isGridView = parent instanceof GridView;
if (view == null) {
LayoutInflater inflator = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflator.inflate(R.layout.list_item, null);
view = isGridView ? inflator.inflate(R.layout.grid_item, null) :
inflator.inflate(R.layout.list_item, null);
}
if (mFiles != null && mFiles.length > position && mFiles[position] != null) {
File file = mFiles[position];
@ -129,20 +133,24 @@ public class LocalFileListAdapter extends BaseAdapter implements FilterableListA
}
fileIcon.setTag(file.hashCode());
ImageView checkBoxV = (ImageView) view.findViewById(R.id.custom_checkbox);
TextView fileSizeV = (TextView) view.findViewById(R.id.file_size);
TextView fileSizeSeparatorV = (TextView) view.findViewById(R.id.file_separator);
TextView lastModV = (TextView) view.findViewById(R.id.last_mod);
ImageView checkBoxV = (ImageView) view.findViewById(R.id.custom_checkbox);
lastModV.setVisibility(View.VISIBLE);
lastModV.setText(DisplayUtils.getRelativeTimestamp(mContext, file.lastModified()));
if (!isGridView) {
TextView lastModV = (TextView) view.findViewById(R.id.last_mod);
lastModV.setVisibility(View.VISIBLE);
lastModV.setText(DisplayUtils.getRelativeTimestamp(mContext, file.lastModified()));
}
if (!file.isDirectory()) {
fileSizeSeparatorV.setVisibility(View.VISIBLE);
fileSizeV.setVisibility(View.VISIBLE);
fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.length()));
if (!isGridView) {
fileSizeSeparatorV.setVisibility(View.VISIBLE);
fileSizeV.setVisibility(View.VISIBLE);
fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.length()));
}
ListView parentList = (ListView) parent;
if (parentList.getChoiceMode() == ListView.CHOICE_MODE_NONE) {
AbsListView parentList = (AbsListView) parent;
if (parentList.getChoiceMode() == ListView.CHOICE_MODE_NONE) {
checkBoxV.setVisibility(View.GONE);
} else {
if (parentList.isItemChecked(position)) {
@ -191,8 +199,10 @@ public class LocalFileListAdapter extends BaseAdapter implements FilterableListA
}
} else {
fileSizeSeparatorV.setVisibility(View.GONE);
fileSizeV.setVisibility(View.GONE);
if (!isGridView) {
fileSizeSeparatorV.setVisibility(View.GONE);
fileSizeV.setVisibility(View.GONE);
}
checkBoxV.setVisibility(View.GONE);
}

View file

@ -30,6 +30,7 @@ import android.util.SparseBooleanArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
@ -127,7 +128,7 @@ public class LocalFileListFragment extends ExtendedListFragment {
} else { /// Click on a file
ImageView checkBoxV = (ImageView) v.findViewById(R.id.custom_checkbox);
if (checkBoxV != null) {
if (((ListView)getListView()).isItemChecked(position)) {
if (((AbsListView)getListView()).isItemChecked(position)) {
checkBoxV.setImageResource(R.drawable.ic_checkbox_marked);
} else {
checkBoxV.setImageResource(R.drawable.ic_checkbox_blank_outline);
@ -206,7 +207,7 @@ public class LocalFileListFragment extends ExtendedListFragment {
}
// by now, only files in the same directory will be kept as selected
((ListView)mCurrentListView).clearChoices();
((AbsListView)mCurrentListView).clearChoices();
mAdapter.swapDirectory(directory);
if (mDirectory == null || !mDirectory.equals(directory)) {
mCurrentListView.setSelection(0);
@ -222,7 +223,7 @@ public class LocalFileListFragment extends ExtendedListFragment {
*/
public String[] getCheckedFilePaths() {
ArrayList<String> result = new ArrayList<String>();
SparseBooleanArray positions = ((ListView)mCurrentListView).getCheckedItemPositions();
SparseBooleanArray positions = ((AbsListView)mCurrentListView).getCheckedItemPositions();
if (positions.size() > 0) {
for (int i = 0; i < positions.size(); i++) {
if (positions.get(positions.keyAt(i)) == true) {
@ -254,7 +255,7 @@ public class LocalFileListFragment extends ExtendedListFragment {
* @param select <code>true</code> to select all, <code>false</code> to deselect all
*/
public void selectAllFiles(boolean select) {
ListView listView = (ListView) getListView();
AbsListView listView = (AbsListView) getListView();
for (int position = 0; position < listView.getCount(); position++) {
File file = (File) mAdapter.getItem(position);
if (file.isFile()) {