mirror of
https://github.com/nextcloud/android.git
synced 2024-11-23 13:45:35 +03:00
Merge branch 'master' of https://github.com/nextcloud/android into syncedFolders
This commit is contained in:
commit
4796633bcd
8 changed files with 178 additions and 44 deletions
|
@ -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>
|
|
@ -485,11 +485,9 @@ public class UploadFileOperation extends SyncOperation {
|
|||
boolean delayInstantPicture = isInstantPicture() &&
|
||||
PreferenceManager.instantPictureUploadWhenChargingOnly(mContext);
|
||||
|
||||
boolean delayInstantVideo = isInstantVideo() &&
|
||||
PreferenceManager.instantVideoUploadViaWiFiOnly(mContext);
|
||||
boolean delayInstantVideo = isInstantVideo() && PreferenceManager.instantVideoUploadWhenChargingOnly(mContext);
|
||||
|
||||
return ((delayInstantPicture || delayInstantVideo)
|
||||
&& !ConnectivityUtils.isCharging(mContext));
|
||||
return ((delayInstantPicture || delayInstantVideo) && !ConnectivityUtils.isCharging(mContext));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,8 +71,6 @@ public class FileListListAdapter extends BaseAdapter implements FilterableListAd
|
|||
private Account mAccount;
|
||||
private ComponentsGetter mTransferServiceGetter;
|
||||
|
||||
private enum ViewType {LIST_ITEM, GRID_IMAGE, GRID_ITEM}
|
||||
|
||||
public FileListListAdapter(
|
||||
boolean justFolders,
|
||||
Context context,
|
||||
|
|
|
@ -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,18 +105,54 @@ public class LocalFileListAdapter extends BaseAdapter implements FilterableListA
|
|||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
View view = convertView;
|
||||
if (view == null) {
|
||||
LayoutInflater inflator = (LayoutInflater) mContext
|
||||
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
view = inflator.inflate(R.layout.list_item, null);
|
||||
}
|
||||
File file = null;
|
||||
boolean isGridView = true;
|
||||
LayoutInflater inflater = (LayoutInflater) mContext
|
||||
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
|
||||
if (mFiles != null && mFiles.length > position && mFiles[position] != null) {
|
||||
File file = mFiles[position];
|
||||
|
||||
TextView fileName = (TextView) view.findViewById(R.id.Filename);
|
||||
String name = file.getName();
|
||||
fileName.setText(name);
|
||||
|
||||
file = mFiles[position];
|
||||
}
|
||||
|
||||
if (file != null) {
|
||||
// Find out which layout should be displayed
|
||||
ViewType viewType;
|
||||
if (parent instanceof GridView) {
|
||||
String mimeType = MimetypeIconUtil.getBestMimeTypeByFilename(file.getName());
|
||||
if (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 = inflater.inflate(R.layout.grid_image, parent, false);
|
||||
view.setTag(ViewType.GRID_IMAGE);
|
||||
break;
|
||||
case GRID_ITEM:
|
||||
view = inflater.inflate(R.layout.grid_item, parent, false);
|
||||
view.setTag(ViewType.GRID_ITEM);
|
||||
break;
|
||||
case LIST_ITEM:
|
||||
view = inflater.inflate(R.layout.list_item, parent, false);
|
||||
view.setTag(ViewType.LIST_ITEM);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!ViewType.GRID_IMAGE.equals(viewType)) {
|
||||
TextView fileName = (TextView) view.findViewById(R.id.Filename);
|
||||
String name = file.getName();
|
||||
fileName.setText(name);
|
||||
}
|
||||
|
||||
ImageView fileIcon = (ImageView) view.findViewById(R.id.thumbnail);
|
||||
|
||||
/** Cancellation needs do be checked and done before changing the drawable in fileIcon, or
|
||||
|
@ -129,20 +167,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)) {
|
||||
|
@ -167,19 +209,17 @@ public class LocalFileListAdapter extends BaseAdapter implements FilterableListA
|
|||
if (allowedToCreateNewThumbnail) {
|
||||
final ThumbnailsCacheManager.ThumbnailGenerationTask task =
|
||||
new ThumbnailsCacheManager.ThumbnailGenerationTask(fileIcon);
|
||||
if (thumbnail == null) {
|
||||
if (BitmapUtils.isVideo(file)) {
|
||||
thumbnail = ThumbnailsCacheManager.mDefaultVideo;
|
||||
} else {
|
||||
thumbnail = ThumbnailsCacheManager.mDefaultImg;
|
||||
}
|
||||
if (BitmapUtils.isVideo(file)) {
|
||||
thumbnail = ThumbnailsCacheManager.mDefaultVideo;
|
||||
} else {
|
||||
thumbnail = ThumbnailsCacheManager.mDefaultImg;
|
||||
}
|
||||
final ThumbnailsCacheManager.AsyncThumbnailDrawable asyncDrawable =
|
||||
new ThumbnailsCacheManager.AsyncThumbnailDrawable(
|
||||
mContext.getResources(),
|
||||
thumbnail,
|
||||
task
|
||||
);
|
||||
new ThumbnailsCacheManager.AsyncThumbnailDrawable(
|
||||
mContext.getResources(),
|
||||
thumbnail,
|
||||
task
|
||||
);
|
||||
fileIcon.setImageDrawable(asyncDrawable);
|
||||
task.execute(file);
|
||||
Log_OC.v(TAG, "Executing task to generate a new thumbnail");
|
||||
|
@ -191,8 +231,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);
|
||||
}
|
||||
|
||||
|
|
31
src/com/owncloud/android/ui/adapter/ViewType.java
Normal file
31
src/com/owncloud/android/ui/adapter/ViewType.java
Normal file
|
@ -0,0 +1,31 @@
|
|||
/**
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Andy Scherzinger
|
||||
* Copyright (C) 2016 Andy Scherzinger
|
||||
* Copyright (C) 2016 Nextcloud
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public
|
||||
* License along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.owncloud.android.ui.adapter;
|
||||
|
||||
/**
|
||||
* Enumeration of available/supported view types for file list/grid items
|
||||
*/
|
||||
public enum ViewType {
|
||||
LIST_ITEM,
|
||||
GRID_IMAGE,
|
||||
GRID_ITEM
|
||||
}
|
|
@ -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()) {
|
||||
|
|
|
@ -117,6 +117,34 @@ public class MimetypeIconUtil {
|
|||
return candidates.get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 'True' if the mime type defines image
|
||||
*/
|
||||
public static boolean isImage(String mimeType) {
|
||||
return (mimeType.startsWith("image/") && !mimeType.contains("djvu"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 'True' the mime type defines video
|
||||
*/
|
||||
public static boolean isVideo(String mimeType) {
|
||||
return (mimeType != null && mimeType.startsWith("video/"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 'True' the mime type defines audio
|
||||
*/
|
||||
public boolean isAudio(String mimeType) {
|
||||
return (mimeType != null && mimeType.startsWith("audio/"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 'True' if mime type defines text
|
||||
*/
|
||||
public boolean isText(String mimeType) {
|
||||
return (mimeType != null && mimeType.startsWith("text/"));
|
||||
}
|
||||
|
||||
/**
|
||||
* determines the icon based on the mime type.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue