Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ dependencies {
/// dependencies for app building
implementation name: 'touch-image-view'
implementation 'com.android.support:multidex:1.0.2'
implementation 'com.github.nextcloud:android-library:1.0.26'
implementation 'com.github.nextcloud:android-library:1.0.28'
implementation "com.android.support:support-v4:${supportLibraryVersion}"
implementation "com.android.support:design:${supportLibraryVersion}"
implementation 'com.jakewharton:disklrucache:2.0.2'
Expand Down
2 changes: 1 addition & 1 deletion scripts/lint/lint-results.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
DO NOT TOUCH; GENERATED BY DRONE
<span class="mdl-layout-title">Lint Report: 1 error and 515 warnings</span>
<span class="mdl-layout-title">Lint Report: 1 error and 512 warnings</span>
3 changes: 3 additions & 0 deletions src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@
<receiver android:name=".files.BootupBroadcastReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON"/>
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED"/>
</intent-filter>
</receiver>

Expand Down
87 changes: 49 additions & 38 deletions src/main/java/com/owncloud/android/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,26 +125,7 @@ public void onCreate() {
Log_OC.d("Debug", "start logging");
}

updateToAutoUpload();
cleanOldEntries();
updateAutoUploadEntries();

if (PermissionUtil.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
splitOutAutoUploadEntries();
} else {
PreferenceManager.setAutoUploadSplitEntries(this, true);
}

initiateExistingAutoUploadEntries();

FilesSyncHelper.scheduleFilesSyncIfNeeded();
FilesSyncHelper.restartJobsIfNeeded();

ReceiversHelper.registerNetworkChangeReceiver();

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
ReceiversHelper.registerPowerChangeReceiver();
}
initAutoUpload();

// register global protection with pass code
registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
Expand Down Expand Up @@ -190,6 +171,31 @@ public void onActivityDestroyed(Activity activity) {
});
}

public static void initAutoUpload() {
updateToAutoUpload();
cleanOldEntries();
updateAutoUploadEntries();

if (getAppContext() != null) {
if (PermissionUtil.checkSelfPermission(getAppContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
splitOutAutoUploadEntries();
} else {
PreferenceManager.setAutoUploadSplitEntries(getAppContext(), true);
}
}

initiateExistingAutoUploadEntries();

FilesSyncHelper.scheduleFilesSyncIfNeeded();
FilesSyncHelper.restartJobsIfNeeded();

ReceiversHelper.registerNetworkChangeReceiver();

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
ReceiversHelper.registerPowerChangeReceiver();
}
}

public static Context getAppContext() {
return MainApp.mContext;
}
Expand Down Expand Up @@ -301,12 +307,13 @@ public static String getUserAgent() {
return userAgent;
}

private void updateToAutoUpload() {
if (PreferenceManager.instantPictureUploadEnabled(this) ||
PreferenceManager.instantPictureUploadEnabled(this)) {
private static void updateToAutoUpload() {
Context context = getAppContext();
if (PreferenceManager.instantPictureUploadEnabled(context) ||
PreferenceManager.instantPictureUploadEnabled(context)) {

// remove legacy shared preferences
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit();
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
editor.remove("instant_uploading")
.remove("instant_video_uploading")
.remove("instant_upload_path")
Expand All @@ -322,16 +329,16 @@ private void updateToAutoUpload() {

// show info pop-up
try {
new AlertDialog.Builder(this, R.style.Theme_ownCloud_Dialog)
new AlertDialog.Builder(context, R.style.Theme_ownCloud_Dialog)
.setTitle(R.string.drawer_synced_folders)
.setMessage(R.string.synced_folders_new_info)
.setPositiveButton(R.string.drawer_open, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// show Auto Upload
Intent folderSyncIntent = new Intent(getApplicationContext(),
Intent folderSyncIntent = new Intent(context,
SyncedFoldersActivity.class);
dialog.dismiss();
startActivity(folderSyncIntent);
context.startActivity(folderSyncIntent);
}
})
.setNegativeButton(R.string.drawer_close, new DialogInterface.OnClickListener() {
Expand All @@ -347,21 +354,23 @@ public void onClick(DialogInterface dialog, int which) {
}
}

private void updateAutoUploadEntries() {
private static void updateAutoUploadEntries() {
// updates entries to reflect their true paths
if (!PreferenceManager.getAutoUploadPathsUpdate(this)) {
Context context = getAppContext();
if (!PreferenceManager.getAutoUploadPathsUpdate(context)) {
SyncedFolderProvider syncedFolderProvider =
new SyncedFolderProvider(MainApp.getAppContext().getContentResolver());
syncedFolderProvider.updateAutoUploadPaths(mContext);
}
}

private void splitOutAutoUploadEntries() {
if (!PreferenceManager.getAutoUploadSplitEntries(this)) {
private static void splitOutAutoUploadEntries() {
Context context = getAppContext();
if (!PreferenceManager.getAutoUploadSplitEntries(context)) {
// magic to split out existing synced folders in two when needed
// otherwise, we migrate them to their proper type (image or video)
Log_OC.i(TAG, "Migrate synced_folders records for image/video split");
ContentResolver contentResolver = this.getContentResolver();
ContentResolver contentResolver = context.getContentResolver();

SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(contentResolver);

Expand Down Expand Up @@ -405,11 +414,11 @@ private void splitOutAutoUploadEntries() {
syncedFolderProvider.deleteSyncedFolder(id);
}

PreferenceManager.setAutoUploadSplitEntries(this, true);
PreferenceManager.setAutoUploadSplitEntries(context, true);
}
}

private void initiateExistingAutoUploadEntries() {
private static void initiateExistingAutoUploadEntries() {
new Thread(() -> {
if (!PreferenceManager.getAutoUploadInit(getAppContext())) {
SyncedFolderProvider syncedFolderProvider =
Expand All @@ -427,13 +436,15 @@ private void initiateExistingAutoUploadEntries() {
}).start();
}

private void cleanOldEntries() {
private static void cleanOldEntries() {
// previous versions of application created broken entries in the SyncedFolderProvider
// database, and this cleans all that and leaves 1 (newest) entry per synced folder

if (!PreferenceManager.getLegacyClean(this)) {
Context context = getAppContext();

if (!PreferenceManager.getLegacyClean(context)) {
SyncedFolderProvider syncedFolderProvider =
new SyncedFolderProvider(MainApp.getAppContext().getContentResolver());
new SyncedFolderProvider(context.getContentResolver());

List<SyncedFolder> syncedFolderList = syncedFolderProvider.getSyncedFolders();
Map<Pair<String, String>, Long> syncedFolders = new HashMap<>();
Expand All @@ -454,7 +465,7 @@ private void cleanOldEntries() {
if (ids.size() > 0) {
syncedFolderProvider.deleteSyncedFoldersNotInList(mContext, ids);
} else {
PreferenceManager.setLegacyClean(this, true);
PreferenceManager.setLegacyClean(context, true);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ public int updateUpload(OCUpload ocUpload) {
cv.put(ProviderTableMeta.UPLOADS_STATUS, ocUpload.getUploadStatus().value);
cv.put(ProviderTableMeta.UPLOADS_LAST_RESULT, ocUpload.getLastResult().getValue());
cv.put(ProviderTableMeta.UPLOADS_UPLOAD_END_TIMESTAMP, ocUpload.getUploadEndTimestamp());
cv.put(ProviderTableMeta.UPLOADS_FILE_SIZE, ocUpload.getFileSize());

int result = getDB().update(ProviderTableMeta.CONTENT_URI_UPLOADS,
cv,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* @author David A. Velasco
* Copyright (C) 2012 Bartek Przybylski
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2017 Mario Danic
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
Expand All @@ -24,6 +25,7 @@
import android.content.Context;
import android.content.Intent;

import com.owncloud.android.MainApp;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.services.observer.FileObserverService;

Expand All @@ -46,13 +48,11 @@ public class BootupBroadcastReceiver extends BroadcastReceiver {
*/
@Override
public void onReceive(Context context, Intent intent) {
if (!intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
Log_OC.e(TAG, "Incorrect action sent " + intent.getAction());
return;
}
Log_OC.d(TAG, "Starting file observer service...");
Intent initObservers = FileObserverService.makeInitIntent(context);
context.startService(initObservers);

MainApp.initAutoUpload();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Binder;
import android.os.Handler;
import android.os.HandlerThread;
Expand Down Expand Up @@ -59,6 +60,7 @@
import com.owncloud.android.ui.preview.PreviewImageActivity;
import com.owncloud.android.ui.preview.PreviewImageFragment;
import com.owncloud.android.utils.ErrorMessageAdapter;
import com.owncloud.android.utils.ThemeUtils;

import java.io.File;
import java.util.AbstractList;
Expand Down Expand Up @@ -127,6 +129,10 @@ public void onCreate() {

mNotification = new NotificationCompat.Builder(this).setContentTitle(getApplicationContext().
getResources().getString(R.string.app_name))
.setContentText(getApplicationContext().getResources().getString(R.string.foreground_service_download))
.setSmallIcon(R.drawable.notification_icon)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.notification_icon))
.setColor(ThemeUtils.primaryColor())
.build();

// add AccountsUpdatedListener
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Binder;
import android.os.Handler;
import android.os.HandlerThread;
Expand Down Expand Up @@ -71,6 +72,7 @@
import com.owncloud.android.ui.activity.UploadListActivity;
import com.owncloud.android.ui.notifications.NotificationUtils;
import com.owncloud.android.utils.ErrorMessageAdapter;
import com.owncloud.android.utils.ThemeUtils;

import java.io.File;
import java.util.AbstractList;
Expand Down Expand Up @@ -418,6 +420,10 @@ public void onCreate() {

mNotification = new NotificationCompat.Builder(this).setContentTitle(getApplicationContext().
getResources().getString(R.string.app_name))
.setContentText(getApplicationContext().getResources().getString(R.string.foreground_service_upload))
.setSmallIcon(R.drawable.notification_icon)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.notification_icon))
.setColor(ThemeUtils.primaryColor())
.build();

int failedCounter = mUploadsStorageManager.failInProgressUploads(
Expand Down
Loading