import android.database.Cursor;
import android.net.Uri;
import android.os.RemoteException;
-import android.provider.BaseColumns;
import android.provider.MediaStore;
import com.owncloud.android.MainApp;
import com.owncloud.android.db.ProviderMeta.ProviderTableMeta;
import com.owncloud.android.lib.common.utils.Log_OC;
-import com.owncloud.android.lib.resources.files.FileUtils;
import com.owncloud.android.lib.resources.shares.OCShare;
import com.owncloud.android.lib.resources.shares.ShareType;
import com.owncloud.android.lib.resources.status.CapabilityBooleanType;
import com.owncloud.android.lib.resources.status.OCCapability;
import com.owncloud.android.utils.FileStorageUtils;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
public class FileDataStorageManager {
public static final int ROOT_PARENT_ID = 0;
if (!targetFolder.exists()) {
targetFolder.mkdirs();
}
- copied = copyFile(localFile, targetFile);
+ copied = FileStorageUtils.copyFile(localFile, targetFile);
}
Log_OC.d(TAG, "Local file COPIED : " + copied);
}
}
- private boolean copyFile(File src, File target) {
- boolean ret = true;
-
- InputStream in = null;
- OutputStream out = null;
-
- try {
- in = new FileInputStream(src);
- out = new FileOutputStream(target);
- byte[] buf = new byte[1024];
- int len;
- while ((len = in.read(buf)) > 0) {
- out.write(buf, 0, len);
- }
- } catch (IOException ex) {
- ret = false;
- } finally {
- if (in != null) try {
- in.close();
- } catch (IOException e) {
- e.printStackTrace(System.err);
- }
- if (out != null) try {
- out.close();
- } catch (IOException e) {
- e.printStackTrace(System.err);
- }
- }
-
- return ret;
- }
-
public void migrateStoredFiles(String srcPath, String dstPath) throws Exception {
Cursor c = null;
if (getContentResolver() != null) {
PreferenceCategory preferenceCategory = (PreferenceCategory) findPreference("more");
boolean helpEnabled = getResources().getBoolean(R.bool.help_enabled);
- Preference pHelp = findPreference("help");
+ Preference pHelp = findPreference("help");
if (pHelp != null ){
if (helpEnabled) {
pHelp.setOnPreferenceClickListener(new OnPreferenceClickListener() {
}
if (BuildConfig.DEBUG) {
- Preference pLog = findPreference("log");
+ Preference pLog = findPreference("log");
if (pLog != null ){
pLog.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
intent.putExtra(Intent.EXTRA_TEXT, recommendText);
startActivity(intent);
- return(true);
+ return true;
}
});
pFeedback.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
- String feedbackMail =(String) getText(R.string.mail_feedback);
- String feedback =(String) getText(R.string.prefs_feedback) + " - android v" + appVersion;
- Intent intent = new Intent(Intent.ACTION_SENDTO);
+ String feedbackMail = (String) getText(R.string.mail_feedback);
+ String feedback = String.format("%s - android v%s", getText(R.string.prefs_feedback), appVersion);
+ Intent intent = new Intent(Intent.ACTION_SENDTO);
+
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, feedback);
mPrefInstantUploadCategory =
(PreferenceCategory) findPreference("instant_uploading_category");
- mPrefInstantUploadPathWiFi = findPreference("instant_upload_on_wifi");
+ mPrefInstantUploadPathWiFi = findPreference("instant_upload_on_wifi");
mPrefInstantUpload = findPreference("instant_uploading");
toggleInstantPictureOptions(((CheckBoxPreference) mPrefInstantUpload).isChecked());
});
/* About App */
- pAboutApp = (Preference) findPreference("about_app");
+ pAboutApp = findPreference("about_app");
if (pAboutApp != null) {
pAboutApp.setTitle(String.format(getString(R.string.about_android), getString(R.string.app_name)));
pAboutApp.setSummary(String.format(getString(R.string.about_version), appVersion));
if (requestCode == ACTION_SELECT_UPLOAD_PATH && resultCode == RESULT_OK){
- OCFile folderToUpload =
- (OCFile) data.getParcelableExtra(UploadPathActivity.EXTRA_FOLDER);
+ OCFile folderToUpload = data.getParcelableExtra(UploadPathActivity.EXTRA_FOLDER);
mUploadPath = folderToUpload.getRemotePath();
} else if (requestCode == ACTION_SELECT_UPLOAD_VIDEO_PATH && resultCode == RESULT_OK) {
- OCFile folderToUploadVideo =
- (OCFile) data.getParcelableExtra(UploadPathActivity.EXTRA_FOLDER);
+ OCFile folderToUploadVideo = data.getParcelableExtra(UploadPathActivity.EXTRA_FOLDER);
mUploadVideoPath = folderToUploadVideo.getRemotePath();
editor.commit();
}
- // Methods for ComponetsGetter
+ // Methods for ComponentsGetter
@Override
public FileDownloader.FileDownloaderBinder getFileDownloaderBinder() {
return mDownloaderBinder;
if (component.equals(new ComponentName(Preferences.this, FileDownloader.class))) {
mDownloaderBinder = (FileDownloader.FileDownloaderBinder) service;
-
} else if (component.equals(new ComponentName(Preferences.this, FileUploader.class))) {
Log_OC.d(TAG, "Upload service connected");
mUploaderBinder = (FileUploader.FileUploaderBinder) service;
- } else {
- return;
}
-
}
@Override
import com.owncloud.android.R;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.lib.common.utils.Log_OC;
+import com.owncloud.android.utils.FileStorageUtils;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
/**
* Created by Bartosz Przybylski on 07.11.2015.
rollback();
return e.getResId();
} catch (MigrationCleanupException e) {
- Log_OC.w(TAG, "Migration mleanup step failed");
+ Log_OC.w(TAG, "Migration cleanup step failed");
return 0;
} finally {
publishProgress(mProgress++, R.string.file_migration_restoring_accounts_configuration);
if (new File(dstFile, MainApp.getDataFolder()).exists())
throw new MigrationException(R.string.file_migration_failed_dir_already_exists);
- if (dstFile.getFreeSpace() < calculateUsedSpace(new File(srcFile, MainApp.getDataFolder())))
+ if (dstFile.getFreeSpace() < FileStorageUtils.getFolderSize(new File(srcFile, MainApp.getDataFolder())))
throw new MigrationException(R.string.file_migration_failed_not_enough_space);
}
publishProgress(mProgress);
}
- private boolean copyFile(File src, File target) {
- boolean ret = true;
-
- InputStream in = null;
- OutputStream out = null;
-
- try {
- in = new FileInputStream(src);
- out = new FileOutputStream(target);
- byte[] buf = new byte[1024];
- int len;
- while ((len = in.read(buf)) > 0) {
- out.write(buf, 0, len);
- }
- } catch (IOException ex) {
- ret = false;
- } finally {
- if (in != null) try {
- in.close();
- } catch (IOException e) {
- e.printStackTrace(System.err);
- }
- if (out != null) try {
- out.close();
- } catch (IOException e) {
- e.printStackTrace(System.err);
- }
- }
-
- return ret;
- }
-
void copyDirs(File src, File dst) throws MigrationException {
if (!dst.mkdirs())
throw new MigrationException(R.string.file_migration_failed_while_coping);
if (f.isDirectory())
copyDirs(f, new File(dst, f.getName()));
- else if (!copyFile(f, new File(dst, f.getName())))
+ else if (!FileStorageUtils.copyFile(f, new File(dst, f.getName())))
throw new MigrationException(R.string.file_migration_failed_while_coping);
}
Log_OC.w(TAG, "Rollback step failed");
}
- long calculateUsedSpace(File dir) {
- long result = 0;
-
- for (File f : dir.listFiles()) {
- if (f.isDirectory())
- result += calculateUsedSpace(f);
- else
- result += f.length();
- }
-
- return result;
- }
-
void saveAccountsSyncStatus(String authority, Account accounts[], boolean syncs[]) {
for (int i = 0; i < accounts.length; ++i)
syncs[i] = ContentResolver.getSyncAutomatically(accounts[i], authority);
package com.owncloud.android.utils;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
import java.util.Collections;
import java.util.Comparator;
import java.util.Vector;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.net.Uri;
-import android.os.Environment;
import android.os.StatFs;
import android.webkit.MimeTypeMap;
public static long getFolderSize(File dir) {
if (dir.exists()) {
long result = 0;
- File[] fileList = dir.listFiles();
- for(int i = 0; i < fileList.length; i++) {
- if(fileList[i].isDirectory()) {
- result += getFolderSize(fileList[i]);
- } else {
- result += fileList[i].length();
- }
+ for (File f : dir.listFiles()) {
+ if (f.isDirectory())
+ result += getFolderSize(f);
+ else
+ result += f.length();
}
return result;
}
}
}
+ public static boolean copyFile(File src, File target) {
+ boolean ret = true;
+
+ InputStream in = null;
+ OutputStream out = null;
+
+ try {
+ in = new FileInputStream(src);
+ out = new FileOutputStream(target);
+ byte[] buf = new byte[1024];
+ int len;
+ while ((len = in.read(buf)) > 0) {
+ out.write(buf, 0, len);
+ }
+ } catch (IOException ex) {
+ ret = false;
+ } finally {
+ if (in != null) try {
+ in.close();
+ } catch (IOException e) {
+ e.printStackTrace(System.err);
+ }
+ if (out != null) try {
+ out.close();
+ } catch (IOException e) {
+ e.printStackTrace(System.err);
+ }
+ }
+
+ return ret;
+ }
+
}