Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,28 @@
import android.content.SyncResult;
import android.os.Bundle;
import android.support.annotation.PluralsRes;
import android.preference.PreferenceManager;
import android.support.v4.app.NotificationCompat;

import com.owncloud.android.R;
import com.owncloud.android.authentication.AuthenticatorActivity;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.operations.RefreshFolderOperation;
import com.owncloud.android.operations.UpdateOCVersionOperation;
import com.owncloud.android.ui.activity.ErrorsWhileCopyingHandlerActivity;

import org.apache.jackrabbit.webdav.DavException;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.owncloud.android.R;
import com.owncloud.android.authentication.AuthenticatorActivity;
import com.owncloud.android.datamodel.FileDataStorageManager;
Expand Down Expand Up @@ -141,15 +161,18 @@ public synchronized void onPerformSync(Account account, Bundle extras,
String authority, ContentProviderClient providerClient,
SyncResult syncResult) {

String timeString = PreferenceManager.getDefaultSharedPreferences(getContext()).getString("time_between_sync", "60");
int timeTillNextSyncInMinutes = Integer.parseInt(timeString);

mCancellation = false;
mFailedResultsCounter = 0;
mLastFailedResult = null;
mConflictsFound = 0;
mFailsInFavouritesFound = 0;
mForgottenLocalFiles = new HashMap<String, String>();
mForgottenLocalFiles = new HashMap<>();
mSyncResult = syncResult;
mSyncResult.fullSyncRequested = false;
mSyncResult.delayUntil = (System.currentTimeMillis()/1000) + 3*60*60; // avoid too many automatic synchronizations
mSyncResult.delayUntil = (System.currentTimeMillis()/1000) + timeTillNextSyncInMinutes*60; // avoid too many automatic synchronizations

this.setAccount(account);
this.setContentProviderClient(providerClient);
Expand Down
48 changes: 47 additions & 1 deletion src/main/java/com/owncloud/android/ui/activity/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import android.accounts.Account;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
Expand Down Expand Up @@ -98,6 +99,7 @@ public class Preferences extends PreferenceActivity

public final static String PREFERENCE_USE_FINGERPRINT = "use_fingerprint";
public static final String PREFERENCE_EXPERT_MODE = "expert_mode";
public static final String PREFERENCE_TIME_BETWEEN_SYNC = "time_between_sync";

private static final int ACTION_REQUEST_PASSCODE = 5;
private static final int ACTION_CONFIRM_PASSCODE = 6;
Expand All @@ -119,6 +121,7 @@ public class Preferences extends PreferenceActivity
private SwitchPreference mExpertMode;
private AppCompatDelegate mDelegate;

private Preference mPrefTimeBetweenSynchronizations;
private ListPreference mPrefStoragePath;
private String mStoragePath;
private String pendingLock;
Expand Down Expand Up @@ -179,6 +182,25 @@ public void onCreate(Bundle savedInstanceState) {
setupDevCategory(accentColor, preferenceScreen);
}

@Override
protected void onResume() {
super.onResume();

boolean isAutoSyncEnabled = ContentResolver.getSyncAutomatically(
AccountUtils.getCurrentOwnCloudAccount(this), getString(R.string.authority));
mPrefTimeBetweenSynchronizations.setEnabled(isAutoSyncEnabled);
String summary;
if (isAutoSyncEnabled) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
int minutesBetweenSyncs = Integer.parseInt(prefs.getString("time_between_sync", "60"));
summary = getResources().getQuantityString(
R.plurals.minutes, minutesBetweenSyncs, minutesBetweenSyncs);
} else {
summary = getString(R.string.prefs_time_between_sync_sync_disabled);
}
mPrefTimeBetweenSynchronizations.setSummary(summary);
}

private void setupDevCategory(int accentColor, PreferenceScreen preferenceScreen) {
// Dev category
PreferenceCategory preferenceCategoryDev = (PreferenceCategory) findPreference("dev_category");
Expand Down Expand Up @@ -220,7 +242,6 @@ private void setupAboutCategory(int accentColor, String appVersion) {
PreferenceCategory preferenceCategoryAbout = (PreferenceCategory) findPreference("about");
preferenceCategoryAbout.setTitle(ThemeUtils.getColoredTitle(getString(R.string.prefs_category_about),
accentColor));

/* About App */
Preference pAboutApp = findPreference("about_app");
if (pAboutApp != null) {
Expand Down Expand Up @@ -564,11 +585,36 @@ private void setupDetailsCategory(int accentColor, PreferenceScreen preferenceSc

setupExpertModePreference(preferenceCategoryDetails, fSyncedFolderLightEnabled);

setupTimeBetweenSynchronizationsPreference(preferenceCategoryDetails, fSyncedFolderLightEnabled);

if (!fPassCodeEnabled && !fDeviceCredentialsEnabled && !fShowHiddenFilesEnabled && fSyncedFolderLightEnabled) {
preferenceScreen.removePreference(preferenceCategoryDetails);
}
}

private void setupTimeBetweenSynchronizationsPreference(
PreferenceCategory preferenceCategoryDetails,
boolean fSyncedFolderLightEnabled) {
mPrefTimeBetweenSynchronizations = findPreference(PREFERENCE_TIME_BETWEEN_SYNC);

if (fSyncedFolderLightEnabled) {
preferenceCategoryDetails.removePreference(mPrefTimeBetweenSynchronizations);
} else if (mPrefTimeBetweenSynchronizations != null) {
mPrefTimeBetweenSynchronizations.setOnPreferenceChangeListener((preference, newValueObject) -> {
if (newValueObject instanceof String && ((String) newValueObject).length() > 0) {
int newValue = Integer.parseInt((String) newValueObject);
if (newValue > 0) {
mPrefTimeBetweenSynchronizations.setSummary(
getResources().getQuantityString(
R.plurals.minutes, newValue, newValue));
return true;
}
}
return false;
});
}
}

private void setupExpertModePreference(PreferenceCategory preferenceCategoryDetails,
boolean fSyncedFolderLightEnabled) {
mExpertMode = (SwitchPreference) findPreference(PREFERENCE_EXPERT_MODE);
Expand Down
8 changes: 8 additions & 0 deletions src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,14 @@

<string name="prefs_category_details">Details</string>


<string name="prefs_time_between_sync">Time between synchronization</string>
<string name="prefs_time_between_sync_sync_disabled">Automatic synchronization disabled</string>
<plurals name="minutes">
<item quantity="one">One minute</item>
<item quantity="other">%d minutes</item>
</plurals>

<string name="sync_folder_failed_content">Sync of %1$s folder could not be completed</string>

<string name="subject_user_shared_with_you">%1$s shared \"%2$s\" with you</string>
Expand Down
1 change: 1 addition & 0 deletions src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<com.owncloud.android.ui.ThemeableSwitchPreference
android:title="@string/prefs_expert_mode"
android:key="expert_mode"/>
<android.preference.EditTextPreference android:numeric="integer" android:inputType="number" android:defaultValue="60" android:title="@string/prefs_time_between_sync" android:key="time_between_sync" />
</PreferenceCategory>

<PreferenceCategory android:title="@string/prefs_category_more" android:key="more">
Expand Down