From: tobiasKaminsky Date: Thu, 29 Oct 2015 17:53:05 +0000 (+0100) Subject: Merge remote-tracking branch 'remotes/upstream/multiSelect' into beta X-Git-Tag: beta-20151122~81 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/af17dcc57236083ca0959bc1eb979a469bbfb101?hp=--cc Merge remote-tracking branch 'remotes/upstream/multiSelect' into beta --- af17dcc57236083ca0959bc1eb979a469bbfb101 diff --cc res/values-fr/strings.xml index 4d72b399,f67f654e..f91bb679 --- a/res/values-fr/strings.xml +++ b/res/values-fr/strings.xml @@@ -201,10 -200,10 +201,10 @@@ Ci-dessous la liste des fichiers locaux Impossible de s\'authentifier sur ce serveur Le compte n\'existe pas encore sur ce périphérique Ajouter aux favoris - Supprimer des favoris + Retirer des favoris Renommer Supprimer - Voulez-vous vraiment supprimer %1$s ? + Voulez-vous vraiment supprimer %1$s ? Voulez-vous vraiment supprimer %1$s et son contenu ? Local seulement Local seulement diff --cc res/values-lt-rLT/strings.xml index 855116d7,cd0dc50a..37e1752a --- a/res/values-lt-rLT/strings.xml +++ b/res/values-lt-rLT/strings.xml @@@ -190,14 -167,11 +190,14 @@@ Jungiamasi prie autentikacijos serverio... Serveris nepalaiko šio autentikacijos metodo %1$s nepalaiko kelių paskyrų iš karto + Serveris negražina tinkamo vartotojo ID, susisiekite su administratoriumi Jungiamasi prie autentikacijos serverio... + Paskyra neegzistuoja įrenginyje Mėgiamas + Nebemėgti Pervadinti Pašalinti - Ar tikrai norite pašalinti %1$s? + Ar tikrai norite pašalinti %1$s? Ar tikrai norite pašalinti %1$s ir ten esantį turinį? Tik vietiniai Tik vietiniai diff --cc res/values-uk/strings.xml index 3b675534,40106889..44b450da --- a/res/values-uk/strings.xml +++ b/res/values-uk/strings.xml @@@ -196,10 -184,9 +196,10 @@@ Аутентифікація на цьому сервері неможлива Користвача в пристрої не існуе Улюблений + Прибрати з вибраного Перейменувати Видалити - Ви дійсно бажаєте видалити %1$s? + Ви дійсно бажаєте видалити %1$s? Ви дійсно бажаєте видалити %1$s та весь вміст? Лише локально Лише локально diff --cc res/values/strings.xml index 70d00408,ef912938..d73dd573 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@@ -366,18 -364,8 +366,21 @@@ %1$d files %1$d files, 1 folder %1$d files, %2$d folders + Switch to grid view + Switch to list view + Common + Cache size + Upload file to server and ... + Behaviour + Copy file + Move file + + do nothing + copy file to OC folder + move file to OC folder + delete origin file + Do you really want to remove selected items? + Do you really want to remove a folder and its content? + selected items diff --cc src/com/owncloud/android/datamodel/OCFile.java index 0c7cc714,9e77f0d1..1c2ec265 --- a/src/com/owncloud/android/datamodel/OCFile.java +++ b/src/com/owncloud/android/datamodel/OCFile.java @@@ -27,7 -27,7 +27,6 @@@ import android.webkit.MimeTypeMap import com.owncloud.android.lib.common.utils.Log_OC; import java.io.File; - import java.util.Enumeration; -import java.io.Serializable; import third_parties.daveKoeller.AlphanumComparator; public class OCFile implements Parcelable, Comparable { diff --cc src/com/owncloud/android/files/FileOperationsHelper.java index 88cc8843,55368f43..51d447e1 --- a/src/com/owncloud/android/files/FileOperationsHelper.java +++ b/src/com/owncloud/android/files/FileOperationsHelper.java @@@ -51,14 -43,8 +51,16 @@@ import com.owncloud.android.ui.dialog.S import org.apache.http.protocol.HTTP; +import java.util.List; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; + + import java.util.ArrayList; + /** * */ @@@ -246,28 -207,14 +248,32 @@@ public class FileOperationsHelper } } + public void sendCachedImage(OCFile file) { + if (file != null) { + Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND); + // set MimeType + sendIntent.setType(file.getMimetype()); +// sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("content://" + DiskLruImageCacheFileProvider.AUTHORITY + "/#" + file.getRemoteId() + "#" + file.getFileName())); + sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("content://" + DiskLruImageCacheFileProvider.AUTHORITY + file.getRemotePath())); + sendIntent.putExtra(Intent.ACTION_SEND, true); // Send Action + + // Show dialog, without the own app + String[] packagesToExclude = new String[] { mFileActivity.getPackageName() }; + DialogFragment chooserDialog = ShareLinkToDialog.newInstance(sendIntent, packagesToExclude, file); + chooserDialog.show(mFileActivity.getSupportFragmentManager(), FTAG_CHOOSER_DIALOG); + } else { + Log_OC.wtf(TAG, "Trying to send a NULL OCFile"); + } + } + + public void syncFiles(ArrayList files) { + for (OCFile file: files) { + syncFile(file); + } + } public void syncFile(OCFile file) { - - if (!file.isFolder()){ + if (!file.isFolder()) { Intent intent = new Intent(mFileActivity, OperationsService.class); intent.setAction(OperationsService.ACTION_SYNC_FILE); intent.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount()); diff --cc src/com/owncloud/android/ui/adapter/FileListListAdapter.java index ab596c96,272a7ffc..97724046 --- a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java +++ b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java @@@ -194,16 -200,14 +200,15 @@@ public class FileListListAdapter extend switch (viewType){ case LIST_ITEM: 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(showRelativeTimestamp(file)); - checkBoxV.setVisibility(View.GONE); - + fileSizeSeparatorV.setVisibility(View.VISIBLE); fileSizeV.setVisibility(View.VISIBLE); fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength())); @@@ -490,7 -519,40 +520,44 @@@ mGridMode = gridMode; } + public boolean isGridMode() { + return mGridMode; + } ++ + public void setNewSelection(int position, boolean checked) { + mSelection.put(position, checked); + notifyDataSetChanged(); + } + + public void removeSelection(int position) { + mSelection.remove(position); + notifyDataSetChanged(); + } + + public void removeSelection(){ + mSelection.clear(); + notifyDataSetChanged(); + } + + public ArrayList getCheckedItemPositions() { + ArrayList ids = new ArrayList(); + + for (Map.Entry entry : mSelection.entrySet()){ + if (entry.getValue()){ + ids.add(entry.getKey()); + } + } + return ids; + } + + public ArrayList getCheckedItems() { + ArrayList files = new ArrayList(); + + for (Map.Entry entry : mSelection.entrySet()){ + if (entry.getValue()){ + files.add((OCFile) getItem(entry.getKey())); + } + } + return files; + } } diff --cc src/com/owncloud/android/ui/fragment/OCFileListFragment.java index 79a44088,31c19cc2..12ddc68d --- a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java @@@ -24,12 -24,9 +24,12 @@@ package com.owncloud.android.ui.fragmen import android.app.Activity; import android.content.Intent; +import android.content.SharedPreferences; +import android.os.Build; import android.os.Bundle; +import android.preference.PreferenceManager; import android.support.v4.widget.SwipeRefreshLayout; - import android.view.ContextMenu; + import android.view.ActionMode; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; @@@ -52,17 -47,14 +53,18 @@@ import com.owncloud.android.ui.activity import com.owncloud.android.ui.activity.FileDisplayActivity; import com.owncloud.android.ui.activity.FolderPickerActivity; import com.owncloud.android.ui.activity.OnEnforceableRefreshListener; +import com.owncloud.android.ui.activity.UploadFilesActivity; import com.owncloud.android.ui.adapter.FileListListAdapter; import com.owncloud.android.ui.dialog.ConfirmationDialogFragment; +import com.owncloud.android.ui.dialog.CreateFolderDialogFragment; import com.owncloud.android.ui.dialog.FileActionsDialogFragment; import com.owncloud.android.ui.dialog.RemoveFileDialogFragment; + import com.owncloud.android.ui.dialog.RemoveFilesDialogFragment; import com.owncloud.android.ui.dialog.RenameFileDialogFragment; +import com.owncloud.android.ui.dialog.UploadSourceDialogFragment; import com.owncloud.android.ui.preview.PreviewImageFragment; import com.owncloud.android.ui.preview.PreviewMediaFragment; +import com.owncloud.android.utils.DisplayUtils; import com.owncloud.android.utils.FileStorageUtils; import com.owncloud.android.ui.preview.PreviewTextFragment; @@@ -158,174 -143,59 +161,215 @@@ public class OCFileListFragment extend setListAdapter(mAdapter); registerLongClickListener(); + + boolean hideFab = (args != null) && args.getBoolean(ARG_HIDE_FAB, false); + if (hideFab) { + setFabEnabled(false); + } else { + setFabEnabled(true); + registerFabListeners(); + + // detect if a mini FAB has ever been clicked + final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); + if(prefs.getLong(KEY_FAB_EVER_CLICKED, 0) > 0) { + miniFabClicked = true; + } + + // add labels to the min FABs when none of them has ever been clicked on + if(!miniFabClicked) { + setFabLabels(); + } else { + removeFabLabels(); + } + } } + /** + * adds labels to all mini FABs. + */ + private void setFabLabels() { + getFabUpload().setTitle(getResources().getString(R.string.actionbar_upload)); + getFabMkdir().setTitle(getResources().getString(R.string.actionbar_mkdir)); + getFabUploadFromApp().setTitle(getResources().getString(R.string.actionbar_upload_from_apps)); + } + + /** + * registers all listeners on all mini FABs. + */ + private void registerFabListeners() { + registerFabUploadListeners(); + registerFabMkDirListeners(); + registerFabUploadFromAppListeners(); + } + + /** + * registers {@link android.view.View.OnClickListener} and {@link android.view.View.OnLongClickListener} + * on the Upload mini FAB for the linked action and {@link Toast} showing the underlying action. + */ + private void registerFabUploadListeners() { + getFabUpload().setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent action = new Intent(getActivity(), UploadFilesActivity.class); + action.putExtra( + UploadFilesActivity.EXTRA_ACCOUNT, + ((FileActivity) getActivity()).getAccount() + ); + getActivity().startActivityForResult(action, UploadSourceDialogFragment.ACTION_SELECT_MULTIPLE_FILES); + getFabMain().collapse(); + recordMiniFabClick(); + } + }); + + getFabUpload().setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + Toast.makeText(getActivity(), R.string.actionbar_upload, Toast.LENGTH_SHORT).show(); + return true; + } + }); + } + + /** + * registers {@link android.view.View.OnClickListener} and {@link android.view.View.OnLongClickListener} + * on the 'Create Dir' mini FAB for the linked action and {@link Toast} showing the underlying action. + */ + private void registerFabMkDirListeners() { + getFabMkdir().setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + CreateFolderDialogFragment dialog = + CreateFolderDialogFragment.newInstance(mFile); + dialog.show(getActivity().getSupportFragmentManager(), FileDisplayActivity.DIALOG_CREATE_FOLDER); + getFabMain().collapse(); + recordMiniFabClick(); + } + }); + + getFabMkdir().setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + Toast.makeText(getActivity(), R.string.actionbar_mkdir, Toast.LENGTH_SHORT).show(); + return true; + } + }); + } + + /** + * registers {@link android.view.View.OnClickListener} and {@link android.view.View.OnLongClickListener} + * on the Upload from App mini FAB for the linked action and {@link Toast} showing the underlying action. + */ + private void registerFabUploadFromAppListeners() { + getFabUploadFromApp().setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent action = new Intent(Intent.ACTION_GET_CONTENT); + action = action.setType("*/*").addCategory(Intent.CATEGORY_OPENABLE); + + //Intent.EXTRA_ALLOW_MULTIPLE is only supported on api level 18+, Jelly Bean + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { + action.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); + } + + getActivity().startActivityForResult( + Intent.createChooser(action, getString(R.string.upload_chooser_title)), + UploadSourceDialogFragment.ACTION_SELECT_CONTENT_FROM_APPS + ); + getFabMain().collapse(); + recordMiniFabClick(); + } + }); + + getFabUploadFromApp().setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + Toast.makeText(getActivity(), + R.string.actionbar_upload_from_apps, + Toast.LENGTH_SHORT).show(); + return true; + } + }); + } + + /** + * records a click on a mini FAB and thus: + *
    + *
  1. persists the click fact
  2. + *
  3. removes the mini FAB labels
  4. + *
+ */ + private void recordMiniFabClick() { + // only record if it hasn't been done already at some other time + if(!miniFabClicked) { + final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity()); + sp.edit().putLong(KEY_FAB_EVER_CLICKED, 1).commit(); + miniFabClicked = true; + } + } + + /** + * removes the labels on all known min FABs. + */ + private void removeFabLabels() { + getFabUpload().setTitle(null); + getFabMkdir().setTitle(null); + getFabUploadFromApp().setTitle(null); + ((TextView) getFabUpload().getTag(com.getbase.floatingactionbutton.R.id.fab_label)).setVisibility(View.GONE); + ((TextView) getFabMkdir().getTag(com.getbase.floatingactionbutton.R.id.fab_label)).setVisibility(View.GONE); + ((TextView) getFabUploadFromApp().getTag(com.getbase.floatingactionbutton.R.id.fab_label)).setVisibility(View.GONE); + } + private void registerLongClickListener() { - getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { - public boolean onItemLongClick(AdapterView arg0, View v, - int index, long arg3) { - showFileAction(index); + getListView().setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() { + private Menu menu; + + @Override + public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { + final int checkedCount = getListView().getCheckedItemCount(); + // TODO Tobi extract to values + mode.setTitle(checkedCount + " selected"); + + if (checked) { + mAdapter.setNewSelection(position, checked); + } else { + mAdapter.removeSelection(position); + } + + // TODO maybe change: only recreate menu if count changes + menu.clear(); + if (checkedCount == 1) { + createContextMenu(menu); + } else { + // download, move, copy, delete + getActivity().getMenuInflater().inflate(R.menu.multiple_file_actions_menu, menu); + } + + } + + @Override + public boolean onCreateActionMode(ActionMode mode, Menu menu) { + this.menu = menu; return true; } + + @Override + public boolean onPrepareActionMode(ActionMode mode, Menu menu) { + return false; + } + + @Override + public boolean onActionItemClicked(ActionMode mode, MenuItem item) { + return onFileActionChosen(item.getItemId()); + } + + @Override + public void onDestroyActionMode(ActionMode mode) { + mAdapter.removeSelection(); + } }); } - // TODO Tobi needed? ++ private void showFileAction(int fileIndex) { Bundle args = getArguments(); PopupMenu pm = new PopupMenu(getActivity(),null);