\r
<ImageView\r
android:id="@+id/imageView2"\r
- android:layout_width="32dp"\r
- android:layout_height="32dp"\r
+ android:layout_width="@dimen/file_icon_size"\r
+ android:layout_height="@dimen/file_icon_size"\r
android:layout_gravity="center_vertical"\r
android:layout_marginLeft="22dp"\r
android:src="@drawable/local_file_indicator" />\r
\r
<ImageView\r
android:id="@+id/imageView1"\r
- android:layout_width="32dp"\r
- android:layout_height="32dp"\r
+ android:layout_width="@dimen/file_icon_size"\r
+ android:layout_height="@dimen/file_icon_size"\r
android:layout_gravity="center_vertical"\r
android:layout_marginLeft="9dp"\r
android:src="@drawable/ic_menu_archive" />\r
<string name="actionbar_settings">Настройки</string>
<string name="actionbar_see_details">Подробно</string>
<string name="actionbar_send_file">Отправить</string>
+ <string name="actionbar_sort">Упорядочить</string>
+ <string name="actionbar_sort_title">Упорядочить по</string>
+ <string-array name="actionbar_sortby">
+ <item>А-Я</item>
+ <item>Новые - Старые</item>
+ </string-array>
<!--TODO re-enable when server-side folder size calculation is available
<item>Biggest - Smallest</item>-->
<string name="prefs_category_general">Основные</string>
<string name="preview_image_description">Предпросмотр</string>
<string name="preview_image_error_unknown_format">Это изображение не может быть отображено</string>
<string name="error__upload__local_file_not_copied">%1$s не возможно скопировать в локальною папку %2$s </string>
+ <string name="prefs_instant_upload_path_title">Путь для загрузки</string>
<string name="share_link_no_support_share_api">К сожалению, на вашем сервере отключен совместный доступ. Пожалуйста, свяжитесь с вашим администратором.</string>
<string name="share_link_file_no_exist">Невозможно добавить в общий доступ. Пожалуйста, проверьте, существует ли файл</string>
<string name="share_link_file_error">Ошибка предоставления общего доступа к этому файлу или каталогу</string>
<string name="downloader_download_file_not_found">Этот файл больше недоступен на сервере</string>
<string name="prefs_category_accounts">Учётные записи</string>
<string name="prefs_add_account">Добавить учетную запись</string>
+ <string name="auth_redirect_non_secure_connection_title">Защищённое соединение перенаправлено по незащищённому маршруту</string>
<string name="actionbar_logger">Журналы</string>
<string name="log_send_history_button">История Отправлений</string>
<string name="log_mail_subject">Журналы Андроид-приложения ownCloud</string>
<string name="move_file_invalid_overwrite">Файл уже существует в папке назначения</string>
<string name="move_file_error">Произошла ошибка при попытке перемещения этого файла или папки</string>
<string name="forbidden_permissions_move">переместить этот файл</string>
+ <string name="prefs_category_instant_uploading">Мгновенные загрузки</string>
<string name="prefs_category_security">Безопасность</string>
</resources>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ownCloud Android client application
+
+ Copyright (C) 2014 ownCloud Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License version 2,
+ as published by the Free Software Foundation.
+
+ 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+-->
+<resources>
+ <dimen name="file_icon_size">32dp</dimen>
+</resources>
<string name="prefs_recommend">Recommend to a friend</string>
<string name="prefs_feedback">Feedback</string>
<string name="prefs_imprint">Imprint</string>
-
+ <string name="prefs_remember_last_share_location">Remember share location</string>
+ <string name="prefs_remember_last_upload_location_summary">Remember last share upload location</string>
+
<string name="recommend_subject">"Try %1$s on your smartphone!"</string>
<string name="recommend_text">"I want to invite you to use %1$s on your smartphone!\nDownload here: %2$s"</string>
<string name="network_error_socket_timeout_exception">An error occurred while waiting for the server, the operation couldn\'t have been done</string>
<string name="network_error_connect_timeout_exception">An error occurred while waiting for the server, the operation couldn\'t have been done</string>
<string name="network_host_not_available">The operation couldn\'t be completed, server is unavailable</string>
+
<string name="empty"></string>
<string name="forbidden_permissions">You do not have permission %s</string>
<string name="prefs_category_instant_uploading">Instant Uploads</string>
<string name="prefs_category_security">Security</string>
-
</resources>
} else {
OwnCloudClientManagerFactory.setDefaultPolicy(Policy.ALWAYS_NEW_CLIENT);
}
-
+
// initialise thumbnails cache on background thread
new ThumbnailsCacheManager.InitDiskCacheTask().execute();
cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, file.getPublicLink());
cv.put(ProviderTableMeta.FILE_PERMISSIONS, file.getPermissions());
cv.put(ProviderTableMeta.FILE_REMOTE_ID, file.getRemoteId());
+ cv.put(ProviderTableMeta.FILE_UPDATE_THUMBNAIL, file.needsUpdateThumbnail());
boolean existsByPath = fileExists(file.getRemotePath());
if (existsByPath || fileExists(file.getFileId())) {
import java.io.File;
import java.lang.ref.WeakReference;
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.httpclient.methods.GetMethod;
+
+import android.accounts.Account;
+import android.accounts.AccountManager;
import android.content.res.Resources;
import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
import android.graphics.Bitmap.CompressFormat;
+import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.media.ThumbnailUtils;
+import android.net.Uri;
import android.os.AsyncTask;
-import android.util.TypedValue;
import android.widget.ImageView;
import com.owncloud.android.MainApp;
+import com.owncloud.android.R;
+import com.owncloud.android.lib.common.OwnCloudAccount;
+import com.owncloud.android.lib.common.OwnCloudClient;
+import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
+import com.owncloud.android.lib.common.accounts.AccountUtils.Constants;
import com.owncloud.android.lib.common.utils.Log_OC;
+import com.owncloud.android.lib.resources.status.OwnCloudVersion;
import com.owncloud.android.ui.adapter.DiskLruImageCache;
import com.owncloud.android.utils.BitmapUtils;
import com.owncloud.android.utils.DisplayUtils;
private static final String TAG = ThumbnailsCacheManager.class.getSimpleName();
- private static final String CACHE_FOLDER = "thumbnailCache";
+ private static final String CACHE_FOLDER = "thumbnailCache";
+ private static final String MINOR_SERVER_VERSION_FOR_THUMBS = "7.8.0";
private static final Object mThumbnailsDiskCacheLock = new Object();
private static DiskLruImageCache mThumbnailCache = null;
private static final int DISK_CACHE_SIZE = 1024 * 1024 * 10; // 10MB
private static final CompressFormat mCompressFormat = CompressFormat.JPEG;
private static final int mCompressQuality = 70;
-
+ private static OwnCloudClient mClient = null;
+ private static String mServerVersion = null;
+
public static Bitmap mDefaultImg =
BitmapFactory.decodeResource(
MainApp.getAppContext().getResources(),
public static class InitDiskCacheTask extends AsyncTask<File, Void, Void> {
+
@Override
protected Void doInBackground(File... params) {
synchronized (mThumbnailsDiskCacheLock) {
mThumbnailCacheStarting = true;
+
if (mThumbnailCache == null) {
try {
// Check if media is mounted or storage is built-in, if so,
public static class ThumbnailGenerationTask extends AsyncTask<OCFile, Void, Bitmap> {
private final WeakReference<ImageView> mImageViewReference;
+ private static Account mAccount;
private OCFile mFile;
private FileDataStorageManager mStorageManager;
- public ThumbnailGenerationTask(ImageView imageView, FileDataStorageManager storageManager) {
+ public ThumbnailGenerationTask(ImageView imageView, FileDataStorageManager storageManager, Account account) {
// Use a WeakReference to ensure the ImageView can be garbage collected
mImageViewReference = new WeakReference<ImageView>(imageView);
if (storageManager == null)
throw new IllegalArgumentException("storageManager must not be NULL");
mStorageManager = storageManager;
+ mAccount = account;
}
// Decode image in background.
Bitmap thumbnail = null;
try {
+ if (mAccount != null) {
+ AccountManager accountMgr = AccountManager.get(MainApp.getAppContext());
+
+ mServerVersion = accountMgr.getUserData(mAccount, Constants.KEY_OC_VERSION);
+ OwnCloudAccount ocAccount = new OwnCloudAccount(mAccount, MainApp.getAppContext());
+ mClient = OwnCloudClientManagerFactory.getDefaultSingleton().
+ getClientFor(ocAccount, MainApp.getAppContext());
+ }
+
mFile = params[0];
final String imageKey = String.valueOf(mFile.getRemoteId());
if (thumbnail == null || mFile.needsUpdateThumbnail()) {
// Converts dp to pixel
Resources r = MainApp.getAppContext().getResources();
- int px = (int) Math.round(TypedValue.applyDimension(
- TypedValue.COMPLEX_UNIT_DIP, 150, r.getDisplayMetrics()
- ));
+
+ int px = (int) Math.round(r.getDimension(R.dimen.file_icon_size));
if (mFile.isDown()){
Bitmap bitmap = BitmapUtils.decodeSampledBitmapFromFile(
mStorageManager.saveFile(mFile);
}
+ } else {
+ // Download thumbnail from server
+ if (mClient != null && mServerVersion != null) {
+ OwnCloudVersion serverOCVersion = new OwnCloudVersion(mServerVersion);
+ if (serverOCVersion.compareTo(new OwnCloudVersion(MINOR_SERVER_VERSION_FOR_THUMBS)) >= 0) {
+ try {
+ int status = -1;
+
+ String uri = mClient.getBaseUri() + "/index.php/apps/files/api/v1/thumbnail/" +
+ px + "/" + px + Uri.encode(mFile.getRemotePath(), "/");
+ Log_OC.d("Thumbnail", "URI: " + uri);
+ GetMethod get = new GetMethod(uri);
+ status = mClient.executeMethod(get);
+ if (status == HttpStatus.SC_OK) {
+ byte[] bytes = get.getResponseBody();
+ Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
+ thumbnail = ThumbnailUtils.extractThumbnail(bitmap, px, px);
+
+ // Add thumbnail to cache
+ if (thumbnail != null) {
+ addBitmapToCache(imageKey, thumbnail);
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ } else {
+ Log_OC.d(TAG, "Server too old");
+ }
+ }
}
}
import android.accounts.Account;
import android.content.Context;
import android.content.Intent;
+import android.util.Log;
//import android.support.v4.content.LocalBroadcastManager;
import com.owncloud.android.datamodel.FileDataStorageManager;
private void synchronizeData(ArrayList<Object> folderAndFiles, OwnCloudClient client) {
// get 'fresh data' from the database
mLocalFolder = mStorageManager.getFileByPath(mLocalFolder.getRemotePath());
-
+
// parse data from remote folder
OCFile remoteFolder = fillOCFile((RemoteFile)folderAndFiles.get(0));
remoteFolder.setParentId(mLocalFolder.getParentId());
if (remoteFile.isFolder()) {
remoteFile.setFileLength(localFile.getFileLength());
// TODO move operations about size of folders to FileContentProvider
+ } else if (mRemoteFolderChanged && remoteFile.isImage() &&
+ remoteFile.getModificationTimestamp() != localFile.getModificationTimestamp()) {
+ remoteFile.setNeedsUpdateThumbnail(true);
+ Log.d(TAG, "Image " + remoteFile.getFileName() + " updated on the server");
}
remoteFile.setPublicLink(localFile.getPublicLink());
remoteFile.setShareByLink(localFile.isShareByLink());
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
-import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
+import android.content.SharedPreferences;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.Parcelable;
+import android.preference.PreferenceManager;
import android.provider.MediaStore.Audio;
import android.provider.MediaStore.Images;
import android.provider.MediaStore.Video;
import android.view.View;
-import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.SimpleAdapter;
import android.widget.Toast;
+import com.actionbarsherlock.app.ActionBar;
+import com.actionbarsherlock.app.SherlockListActivity;
+import com.actionbarsherlock.view.MenuItem;
+import com.owncloud.android.utils.DisplayUtils;
/**
* This can be used to upload things to an ownCloud instance.
* @author Bartek Przybylski
*
*/
-public class Uploader extends ListActivity implements OnItemClickListener, android.view.View.OnClickListener {
+public class Uploader extends SherlockListActivity implements OnItemClickListener, android.view.View.OnClickListener {
private static final String TAG = "ownCloudUploader";
private Account mAccount;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- getWindow().requestFeature(Window.FEATURE_NO_TITLE);
mParents = new Stack<String>();
- mParents.add("");
+
+ ActionBar actionBar = getSupportActionBar();
+ actionBar.setIcon(DisplayUtils.getSeasonalIconId());
+
if (prepareStreamsToUpload()) {
mAccountManager = (AccountManager) getSystemService(Context.ACCOUNT_SERVICE);
Account[] accounts = mAccountManager.getAccountsByType(MainApp.getAccountType());
} else {
mAccount = accounts[0];
mStorageManager = new FileDataStorageManager(mAccount, getContentResolver());
+ initTargetFolder();
populateDirectoryList();
+
}
+
} else {
showDialog(DIALOG_NO_STREAM);
}
public void onClick(DialogInterface dialog, int which) {
mAccount = mAccountManager.getAccountsByType(MainApp.getAccountType())[which];
mStorageManager = new FileDataStorageManager(mAccount, getContentResolver());
+ initTargetFolder();
populateDirectoryList();
}
});
private void populateDirectoryList() {
setContentView(R.layout.uploader_layout);
- String full_path = "";
- for (String a : mParents)
- full_path += a + "/";
+ String current_dir = mParents.peek();
+ if(current_dir.equals("")){
+ getSupportActionBar().setTitle(getString(R.string.default_display_name_for_root_folder));
+ }
+ else{
+ getSupportActionBar().setTitle(current_dir);
+ }
+ boolean notRoot = (mParents.size() > 1);
+ ActionBar actionBar = getSupportActionBar();
+ actionBar.setDisplayHomeAsUpEnabled(notRoot);
+ actionBar.setHomeButtonEnabled(notRoot);
+
+ String full_path = generatePath(mParents);
Log_OC.d(TAG, "Populating view with content of : " + full_path);
-
+
mFile = mStorageManager.getFileByPath(full_path);
if (mFile != null) {
Vector<OCFile> files = mStorageManager.getFolderContent(mFile);
}
}
+ private String generatePath(Stack<String> dirs) {
+ String full_path = "";
+
+ for (String a : dirs)
+ full_path += a + "/";
+ return full_path;
+ }
+
private boolean prepareStreamsToUpload() {
if (getIntent().getAction().equals(Intent.ACTION_SEND)) {
mStreamsToUpload = new ArrayList<Parcelable>();
intent.putExtra(FileUploader.KEY_REMOTE_FILE, remote.toArray(new String[remote.size()]));
intent.putExtra(FileUploader.KEY_ACCOUNT, mAccount);
startService(intent);
+
+ //Save the path to shared preferences
+ SharedPreferences.Editor appPrefs = PreferenceManager
+ .getDefaultSharedPreferences(getApplicationContext()).edit();
+ appPrefs.putString("last_upload_path", mUploadPath);
+ appPrefs.apply();
+
finish();
}
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
}
}
+
+ /**
+ * Loads the target folder initialize shown to the user.
+ *
+ * The target account has to be chosen before this method is called.
+ */
+ private void initTargetFolder() {
+ if (mStorageManager == null) {
+ throw new IllegalStateException("Do not call this method before initializing mStorageManager");
+ }
+
+ SharedPreferences appPreferences = PreferenceManager
+ .getDefaultSharedPreferences(getApplicationContext());
+
+ String last_path = appPreferences.getString("last_upload_path", "");
+ // "/" equals root-directory
+ if(last_path.equals("/")) {
+ mParents.add("");
+ }
+ else{
+ String[] dir_names = last_path.split("/");
+ for (String dir : dir_names)
+ mParents.add(dir);
+ }
+ //Make sure that path still exists, if it doesn't pop the stack and try the previous path
+ while(!mStorageManager.fileExists(generatePath(mParents)) && mParents.size() > 1){
+ mParents.pop();
+ }
+ }
+
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ boolean retval = true;
+ switch (item.getItemId()) {
+ case android.R.id.home: {
+ if((mParents.size() > 1)) {
+ onBackPressed();
+ }
+ break;
+ }
+ default:
+ retval = super.onOptionsItemSelected(item);
+ }
+ return retval;
+ }
+
}
Context context, \r
ComponentsGetter transferServiceGetter\r
) {\r
- \r
+\r
mJustFolders = justFolders;\r
mContext = context;\r
mAccount = AccountUtils.getCurrentOwnCloudAccount(mContext);\r
+
mTransferServiceGetter = transferServiceGetter;
\r
mAppPreferences = PreferenceManager\r
\r
// initialise thumbnails cache on background thread\r
new ThumbnailsCacheManager.InitDiskCacheTask().execute();\r
+\r
}\r
@Override\r
if (ThumbnailsCacheManager.cancelPotentialWork(file, fileIcon)) {\r
final ThumbnailsCacheManager.ThumbnailGenerationTask task = \r
new ThumbnailsCacheManager.ThumbnailGenerationTask(\r
- fileIcon, mStorageManager\r
+ fileIcon, mStorageManager, mAccount\r
);\r
if (thumbnail == null) {\r
thumbnail = ThumbnailsCacheManager.mDefaultImg;\r