mirror of
https://github.com/nextcloud/android.git
synced 2024-11-22 05:05:31 +03:00
Merge pull request #301 from apicellaj/master
add grid view option when choosing a file from within the app
This commit is contained in:
commit
7525088db2
4 changed files with 64 additions and 17 deletions
|
@ -39,4 +39,10 @@
|
||||||
app:showAsAction="never"
|
app:showAsAction="never"
|
||||||
android:title="@string/actionbar_sort"
|
android:title="@string/actionbar_sort"
|
||||||
android:contentDescription="@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>
|
</menu>
|
|
@ -29,6 +29,8 @@ import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.support.v4.app.DialogFragment;
|
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.support.v7.app.ActionBar;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
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;
|
||||||
import com.owncloud.android.ui.dialog.ConfirmationDialogFragment.ConfirmationDialogFragmentListener;
|
import com.owncloud.android.ui.dialog.ConfirmationDialogFragment.ConfirmationDialogFragmentListener;
|
||||||
import com.owncloud.android.ui.dialog.IndeterminateProgressDialog;
|
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.ui.fragment.LocalFileListFragment;
|
||||||
import com.owncloud.android.utils.FileStorageUtils;
|
import com.owncloud.android.utils.FileStorageUtils;
|
||||||
|
|
||||||
|
@ -148,7 +151,7 @@ public class UploadFilesActivity extends FileActivity implements
|
||||||
actionBar.setDisplayShowTitleEnabled(false);
|
actionBar.setDisplayShowTitleEnabled(false);
|
||||||
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
|
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
|
||||||
actionBar.setListNavigationCallbacks(mDirectories, this);
|
actionBar.setListNavigationCallbacks(mDirectories, this);
|
||||||
|
|
||||||
// wait dialog
|
// wait dialog
|
||||||
if (mCurrentDialog != null) {
|
if (mCurrentDialog != null) {
|
||||||
mCurrentDialog.dismiss();
|
mCurrentDialog.dismiss();
|
||||||
|
@ -179,6 +182,8 @@ public class UploadFilesActivity extends FileActivity implements
|
||||||
getMenuInflater().inflate(R.menu.upload_files_picker, menu);
|
getMenuInflater().inflate(R.menu.upload_files_picker, menu);
|
||||||
MenuItem selectAll = menu.findItem(R.id.action_select_all);
|
MenuItem selectAll = menu.findItem(R.id.action_select_all);
|
||||||
setSelectAllMenuItem(selectAll, mSelectAll);
|
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);
|
return super.onCreateOptionsMenu(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,6 +228,18 @@ public class UploadFilesActivity extends FileActivity implements
|
||||||
builder.create().show();
|
builder.create().show();
|
||||||
break;
|
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:
|
default:
|
||||||
retval = super.onOptionsItemSelected(item);
|
retval = super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
@ -515,4 +532,17 @@ public class UploadFilesActivity extends FileActivity implements
|
||||||
finish();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,9 @@ import android.graphics.Bitmap;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.AbsListView;
|
||||||
import android.widget.BaseAdapter;
|
import android.widget.BaseAdapter;
|
||||||
|
import android.widget.GridView;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
@ -103,10 +105,12 @@ public class LocalFileListAdapter extends BaseAdapter implements FilterableListA
|
||||||
@Override
|
@Override
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
View view = convertView;
|
View view = convertView;
|
||||||
|
boolean isGridView = parent instanceof GridView;
|
||||||
if (view == null) {
|
if (view == null) {
|
||||||
LayoutInflater inflator = (LayoutInflater) mContext
|
LayoutInflater inflator = (LayoutInflater) mContext
|
||||||
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
.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) {
|
if (mFiles != null && mFiles.length > position && mFiles[position] != null) {
|
||||||
File file = mFiles[position];
|
File file = mFiles[position];
|
||||||
|
@ -129,20 +133,24 @@ public class LocalFileListAdapter extends BaseAdapter implements FilterableListA
|
||||||
}
|
}
|
||||||
fileIcon.setTag(file.hashCode());
|
fileIcon.setTag(file.hashCode());
|
||||||
|
|
||||||
|
ImageView checkBoxV = (ImageView) view.findViewById(R.id.custom_checkbox);
|
||||||
TextView fileSizeV = (TextView) view.findViewById(R.id.file_size);
|
TextView fileSizeV = (TextView) view.findViewById(R.id.file_size);
|
||||||
TextView fileSizeSeparatorV = (TextView) view.findViewById(R.id.file_separator);
|
TextView fileSizeSeparatorV = (TextView) view.findViewById(R.id.file_separator);
|
||||||
TextView lastModV = (TextView) view.findViewById(R.id.last_mod);
|
if (!isGridView) {
|
||||||
ImageView checkBoxV = (ImageView) view.findViewById(R.id.custom_checkbox);
|
TextView lastModV = (TextView) view.findViewById(R.id.last_mod);
|
||||||
lastModV.setVisibility(View.VISIBLE);
|
lastModV.setVisibility(View.VISIBLE);
|
||||||
lastModV.setText(DisplayUtils.getRelativeTimestamp(mContext, file.lastModified()));
|
lastModV.setText(DisplayUtils.getRelativeTimestamp(mContext, file.lastModified()));
|
||||||
|
}
|
||||||
|
|
||||||
if (!file.isDirectory()) {
|
if (!file.isDirectory()) {
|
||||||
fileSizeSeparatorV.setVisibility(View.VISIBLE);
|
if (!isGridView) {
|
||||||
fileSizeV.setVisibility(View.VISIBLE);
|
fileSizeSeparatorV.setVisibility(View.VISIBLE);
|
||||||
fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.length()));
|
fileSizeV.setVisibility(View.VISIBLE);
|
||||||
|
fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.length()));
|
||||||
|
}
|
||||||
|
|
||||||
ListView parentList = (ListView) parent;
|
AbsListView parentList = (AbsListView) parent;
|
||||||
if (parentList.getChoiceMode() == ListView.CHOICE_MODE_NONE) {
|
if (parentList.getChoiceMode() == ListView.CHOICE_MODE_NONE) {
|
||||||
checkBoxV.setVisibility(View.GONE);
|
checkBoxV.setVisibility(View.GONE);
|
||||||
} else {
|
} else {
|
||||||
if (parentList.isItemChecked(position)) {
|
if (parentList.isItemChecked(position)) {
|
||||||
|
@ -191,8 +199,10 @@ public class LocalFileListAdapter extends BaseAdapter implements FilterableListA
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
fileSizeSeparatorV.setVisibility(View.GONE);
|
if (!isGridView) {
|
||||||
fileSizeV.setVisibility(View.GONE);
|
fileSizeSeparatorV.setVisibility(View.GONE);
|
||||||
|
fileSizeV.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
checkBoxV.setVisibility(View.GONE);
|
checkBoxV.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ import android.util.SparseBooleanArray;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.AbsListView;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
@ -127,7 +128,7 @@ public class LocalFileListFragment extends ExtendedListFragment {
|
||||||
} else { /// Click on a file
|
} else { /// Click on a file
|
||||||
ImageView checkBoxV = (ImageView) v.findViewById(R.id.custom_checkbox);
|
ImageView checkBoxV = (ImageView) v.findViewById(R.id.custom_checkbox);
|
||||||
if (checkBoxV != null) {
|
if (checkBoxV != null) {
|
||||||
if (((ListView)getListView()).isItemChecked(position)) {
|
if (((AbsListView)getListView()).isItemChecked(position)) {
|
||||||
checkBoxV.setImageResource(R.drawable.ic_checkbox_marked);
|
checkBoxV.setImageResource(R.drawable.ic_checkbox_marked);
|
||||||
} else {
|
} else {
|
||||||
checkBoxV.setImageResource(R.drawable.ic_checkbox_blank_outline);
|
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
|
// by now, only files in the same directory will be kept as selected
|
||||||
((ListView)mCurrentListView).clearChoices();
|
((AbsListView)mCurrentListView).clearChoices();
|
||||||
mAdapter.swapDirectory(directory);
|
mAdapter.swapDirectory(directory);
|
||||||
if (mDirectory == null || !mDirectory.equals(directory)) {
|
if (mDirectory == null || !mDirectory.equals(directory)) {
|
||||||
mCurrentListView.setSelection(0);
|
mCurrentListView.setSelection(0);
|
||||||
|
@ -222,7 +223,7 @@ public class LocalFileListFragment extends ExtendedListFragment {
|
||||||
*/
|
*/
|
||||||
public String[] getCheckedFilePaths() {
|
public String[] getCheckedFilePaths() {
|
||||||
ArrayList<String> result = new ArrayList<String>();
|
ArrayList<String> result = new ArrayList<String>();
|
||||||
SparseBooleanArray positions = ((ListView)mCurrentListView).getCheckedItemPositions();
|
SparseBooleanArray positions = ((AbsListView)mCurrentListView).getCheckedItemPositions();
|
||||||
if (positions.size() > 0) {
|
if (positions.size() > 0) {
|
||||||
for (int i = 0; i < positions.size(); i++) {
|
for (int i = 0; i < positions.size(); i++) {
|
||||||
if (positions.get(positions.keyAt(i)) == true) {
|
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
|
* @param select <code>true</code> to select all, <code>false</code> to deselect all
|
||||||
*/
|
*/
|
||||||
public void selectAllFiles(boolean select) {
|
public void selectAllFiles(boolean select) {
|
||||||
ListView listView = (ListView) getListView();
|
AbsListView listView = (AbsListView) getListView();
|
||||||
for (int position = 0; position < listView.getCount(); position++) {
|
for (int position = 0; position < listView.getCount(); position++) {
|
||||||
File file = (File) mAdapter.getItem(position);
|
File file = (File) mAdapter.getItem(position);
|
||||||
if (file.isFile()) {
|
if (file.isFile()) {
|
||||||
|
|
Loading…
Reference in a new issue