mirror of
https://github.com/nextcloud/android.git
synced 2024-11-28 02:17:43 +03:00
Remove useless files
This commit is contained in:
parent
0ffb67c506
commit
db829c5e56
3 changed files with 0 additions and 280 deletions
|
@ -1,93 +0,0 @@
|
|||
/**
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Tobias Kaminsky
|
||||
* Copyright (C) 2016 Tobias Kaminsky
|
||||
* 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.services;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.job.JobParameters;
|
||||
import android.app.job.JobService;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.PersistableBundle;
|
||||
|
||||
import com.owncloud.android.MainApp;
|
||||
import com.owncloud.android.authentication.AccountUtils;
|
||||
import com.owncloud.android.files.services.FileUploader;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.operations.UploadFileOperation;
|
||||
import com.owncloud.android.utils.FileStorageUtils;
|
||||
import com.owncloud.android.utils.MimeTypeUtil;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
public class SyncedFolderJobService extends JobService {
|
||||
private static final String TAG = "SyncedFolderJobService";
|
||||
|
||||
public static final String LOCAL_PATH = "filePath";
|
||||
public static final String REMOTE_PATH = "remotePath";
|
||||
public static final String ACCOUNT = "account";
|
||||
public static final String UPLOAD_BEHAVIOUR = "uploadBehaviour";
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
return START_REDELIVER_INTENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onStartJob(JobParameters params) {
|
||||
Context context = MainApp.getAppContext();
|
||||
PersistableBundle bundle = params.getExtras();
|
||||
String filePath = bundle.getString(LOCAL_PATH);
|
||||
String remotePath = bundle.getString(REMOTE_PATH);
|
||||
Account account = AccountUtils.getOwnCloudAccountByName(context, bundle.getString(ACCOUNT));
|
||||
Integer uploadBehaviour = bundle.getInt(UPLOAD_BEHAVIOUR);
|
||||
|
||||
Log_OC.d(TAG, "startJob: " + params.getJobId() + ", filePath: " + filePath);
|
||||
|
||||
File file = new File(filePath);
|
||||
|
||||
// File can be deleted between job generation and job execution. If file does not exist, just ignore it
|
||||
if (file.exists()) {
|
||||
String mimeType = MimeTypeUtil.getBestMimeTypeByFilename(file.getAbsolutePath());
|
||||
|
||||
FileUploader.UploadRequester requester = new FileUploader.UploadRequester();
|
||||
requester.uploadNewFile(
|
||||
context,
|
||||
account,
|
||||
filePath,
|
||||
remotePath,
|
||||
uploadBehaviour,
|
||||
mimeType,
|
||||
true, // create parent folder if not existent
|
||||
UploadFileOperation.CREATED_AS_INSTANT_PICTURE
|
||||
);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onStopJob(JobParameters params) {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
package com.owncloud.android.services.observer;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.job.JobInfo;
|
||||
import android.app.job.JobScheduler;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.FileObserver;
|
||||
import android.os.PersistableBundle;
|
||||
import android.util.Log;
|
||||
|
||||
import com.owncloud.android.MainApp;
|
||||
import com.owncloud.android.datamodel.SyncedFolder;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.services.SyncedFolderJobService;
|
||||
import com.owncloud.android.utils.FileStorageUtils;
|
||||
import com.owncloud.android.utils.RecursiveFileObserver;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Date;
|
||||
|
||||
class SyncedFolderObserver extends RecursiveFileObserver {
|
||||
|
||||
private Context context;
|
||||
|
||||
public static final String TAG = "SyncedFolderObserver";
|
||||
private SyncedFolder syncedFolder;
|
||||
|
||||
|
||||
public SyncedFolderObserver(SyncedFolder syncedFolder) {
|
||||
super(syncedFolder.getLocalPath(), FileObserver.CREATE + FileObserver.MOVED_TO);
|
||||
|
||||
context = MainApp.getAppContext();
|
||||
this.syncedFolder = syncedFolder;
|
||||
Log_OC.d("SyncedFolderObserver", "Started watching: " + syncedFolder.getLocalPath());
|
||||
}
|
||||
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
@Override
|
||||
public void onEvent(int event, String path) {
|
||||
Log.d(TAG, "Event: " + event + " Path: " + path);
|
||||
|
||||
File temp = new File(path);
|
||||
|
||||
// do not upload "null"-files, test if file exists and is a real file
|
||||
if (!temp.getName().equalsIgnoreCase("null") && temp.isFile() && !temp.getName().endsWith(".tmp")) {
|
||||
PersistableBundle bundle = new PersistableBundle();
|
||||
// TODO extract
|
||||
bundle.putString(SyncedFolderJobService.LOCAL_PATH, path);
|
||||
bundle.putString(SyncedFolderJobService.REMOTE_PATH, FileStorageUtils.getInstantUploadFilePath(
|
||||
syncedFolder.getRemotePath(), temp.getName(),
|
||||
new Date().getTime(),
|
||||
syncedFolder.getSubfolderByDate()));
|
||||
bundle.putString(SyncedFolderJobService.ACCOUNT, syncedFolder.getAccount());
|
||||
bundle.putInt(SyncedFolderJobService.UPLOAD_BEHAVIOUR, syncedFolder.getUploadAction());
|
||||
|
||||
JobScheduler js = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
|
||||
|
||||
Long date = new Date().getTime();
|
||||
JobInfo job = new JobInfo.Builder(
|
||||
date.intValue(),
|
||||
new ComponentName(context, SyncedFolderJobService.class))
|
||||
.setRequiresCharging(syncedFolder.getChargingOnly())
|
||||
.setMinimumLatency(10000)
|
||||
.setRequiredNetworkType(syncedFolder.getWifiOnly() ? JobInfo.NETWORK_TYPE_UNMETERED : JobInfo.NETWORK_TYPE_ANY)
|
||||
.setExtras(bundle)
|
||||
.setPersisted(true)
|
||||
.build();
|
||||
|
||||
Integer result = js.schedule(job);
|
||||
if (result <= 0) {
|
||||
Log_OC.d(TAG, "Job failed to start: " + result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,109 +0,0 @@
|
|||
/**
|
||||
* ownCloud Android client application
|
||||
*
|
||||
* Copyright (C) 2012 Bartek Przybylski
|
||||
* Copyright (C) 2015 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.owncloud.android.utils;
|
||||
|
||||
import android.os.FileObserver;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
public class RecursiveFileObserver extends FileObserver {
|
||||
|
||||
private final List<SingleFileObserver> mObservers = new ArrayList<>();
|
||||
private boolean watching = false;
|
||||
private String mPath;
|
||||
private int mMask;
|
||||
|
||||
public RecursiveFileObserver(String path) {
|
||||
this(path, ALL_EVENTS);
|
||||
}
|
||||
|
||||
public RecursiveFileObserver(String path, int mask) {
|
||||
super(path, mask);
|
||||
mPath = path;
|
||||
mMask = mask;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startWatching() {
|
||||
if (watching) {
|
||||
return;
|
||||
}
|
||||
watching = true;
|
||||
final Stack<String> stack = new Stack<String>();
|
||||
stack.push(mPath);
|
||||
|
||||
while (!stack.empty()) {
|
||||
String parent = stack.pop();
|
||||
mObservers.add(new SingleFileObserver(parent, mMask));
|
||||
File path = new File(parent);
|
||||
File[] files = path.listFiles();
|
||||
if (files == null) {
|
||||
continue;
|
||||
}
|
||||
for (final File file : files) {
|
||||
if (file.isDirectory() && !file.getName().equals(".")
|
||||
&& !file.getName().equals("..")) {
|
||||
stack.push(file.getPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < mObservers.size(); i++) {
|
||||
mObservers.get(i).startWatching();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopWatching() {
|
||||
if (!watching) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < mObservers.size(); ++i) {
|
||||
mObservers.get(i).stopWatching();
|
||||
}
|
||||
mObservers.clear();
|
||||
watching = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEvent(int event, String path) {
|
||||
|
||||
}
|
||||
|
||||
private class SingleFileObserver extends FileObserver {
|
||||
private String mPath;
|
||||
|
||||
SingleFileObserver(String path, int mask) {
|
||||
super(path, mask);
|
||||
mPath = path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEvent(int event, String path) {
|
||||
String newPath = mPath + "/" + path;
|
||||
RecursiveFileObserver.this.onEvent(event, newPath);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue