mirror of
https://github.com/nextcloud/android.git
synced 2024-11-26 15:15:51 +03:00
add ability to set two way sync interval
Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
parent
5ba7713aea
commit
bc0ccba3ce
8 changed files with 122 additions and 14 deletions
|
@ -701,7 +701,8 @@ internal class BackgroundJobManagerImpl(
|
|||
override fun scheduleInternal2WaySync() {
|
||||
val request = periodicRequestBuilder(
|
||||
jobClass = InternalTwoWaySyncWork::class,
|
||||
jobName = JOB_INTERNAL_TWO_WAY_SYNC
|
||||
jobName = JOB_INTERNAL_TWO_WAY_SYNC,
|
||||
intervalMins = preferences.twoWaySyncInterval
|
||||
).build()
|
||||
|
||||
workManager.enqueueUniquePeriodicWork(JOB_INTERNAL_TWO_WAY_SYNC, ExistingPeriodicWorkPolicy.KEEP, request)
|
||||
|
|
|
@ -36,7 +36,7 @@ class InternalTwoWaySyncWork(
|
|||
|
||||
var result = true
|
||||
|
||||
if (!appPreferences.twoWayInternalSyncStatus ||
|
||||
if (!appPreferences.twoWaySyncStatus ||
|
||||
powerManagementService.isPowerSavingEnabled ||
|
||||
!connectivityService.isConnected ||
|
||||
connectivityService.isInternetWalled ||
|
||||
|
|
|
@ -392,9 +392,12 @@ public interface AppPreferences {
|
|||
@NonNull
|
||||
String getLastSelectedMediaFolder();
|
||||
|
||||
void setTwoWayInternalSyncStatus(boolean value);
|
||||
boolean getTwoWayInternalSyncStatus();
|
||||
void setTwoWaySyncStatus(boolean value);
|
||||
boolean getTwoWaySyncStatus();
|
||||
|
||||
void setTwoWaySyncTimestampDefault(boolean value);
|
||||
boolean isTwoWaySyncTimestampDefault();
|
||||
|
||||
void setTwoWaySyncInterval(Long value);
|
||||
Long getTwoWaySyncInterval();
|
||||
}
|
||||
|
|
|
@ -102,8 +102,9 @@ public final class AppPreferencesImpl implements AppPreferences {
|
|||
private static final String PREF__STORAGE_PERMISSION_REQUESTED = "storage_permission_requested";
|
||||
private static final String PREF__IN_APP_REVIEW_DATA = "in_app_review_data";
|
||||
|
||||
private static final String PREF__INTERNAL_TWO_WAY_STATUS = "internal_two_way_status";
|
||||
private static final String PREF__TWO_WAY_STATUS = "two_way_sync_status";
|
||||
private static final String PREF__RESET_TWO_WAY_SYNC_TIMESTAMP = "reset_two_way_sync_timestamp";
|
||||
private static final String PREF__TWO_WAY_SYNC_INTERVAL = "two_way_sync_interval";
|
||||
|
||||
private static final String LOG_ENTRY = "log_entry";
|
||||
|
||||
|
@ -794,13 +795,13 @@ public final class AppPreferencesImpl implements AppPreferences {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setTwoWayInternalSyncStatus(boolean value) {
|
||||
preferences.edit().putBoolean(PREF__INTERNAL_TWO_WAY_STATUS, value).apply();
|
||||
public void setTwoWaySyncStatus(boolean value) {
|
||||
preferences.edit().putBoolean(PREF__TWO_WAY_STATUS, value).apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getTwoWayInternalSyncStatus() {
|
||||
return preferences.getBoolean(PREF__INTERNAL_TWO_WAY_STATUS, false);
|
||||
public boolean getTwoWaySyncStatus() {
|
||||
return preferences.getBoolean(PREF__TWO_WAY_STATUS, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -812,4 +813,14 @@ public final class AppPreferencesImpl implements AppPreferences {
|
|||
public boolean isTwoWaySyncTimestampDefault() {
|
||||
return preferences.getBoolean(PREF__RESET_TWO_WAY_SYNC_TIMESTAMP, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTwoWaySyncInterval(Long value) {
|
||||
preferences.edit().putLong(PREF__TWO_WAY_SYNC_INTERVAL, value).apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getTwoWaySyncInterval() {
|
||||
return preferences.getLong(PREF__TWO_WAY_SYNC_INTERVAL, 15L);
|
||||
}
|
||||
}
|
||||
|
|
31
app/src/main/java/com/nextcloud/model/DurationOption.kt
Normal file
31
app/src/main/java/com/nextcloud/model/DurationOption.kt
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Nextcloud - Android Client
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2024 Alper Ozturk <alper.ozturk@nextcloud.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
package com.nextcloud.model
|
||||
|
||||
import android.content.Context
|
||||
import com.owncloud.android.R
|
||||
|
||||
data class DurationOption(
|
||||
val value: Long,
|
||||
val displayText: String
|
||||
) {
|
||||
companion object {
|
||||
fun twoWaySyncIntervals(context: Context): List<DurationOption> = listOf(
|
||||
DurationOption(15L, context.getString(R.string.two_way_sync_interval_15_min)),
|
||||
DurationOption(30L, context.getString(R.string.two_way_sync_interval_30_min)),
|
||||
DurationOption(45L, context.getString(R.string.two_way_sync_interval_45_min)),
|
||||
DurationOption(60L, context.getString(R.string.two_way_sync_interval_1_hour)),
|
||||
DurationOption(120L, context.getString(R.string.two_way_sync_interval_2_hours)),
|
||||
DurationOption(240L, context.getString(R.string.two_way_sync_interval_4_hours)),
|
||||
DurationOption(360L, context.getString(R.string.two_way_sync_interval_6_hours)),
|
||||
DurationOption(480L, context.getString(R.string.two_way_sync_interval_8_hours)),
|
||||
DurationOption(720L, context.getString(R.string.two_way_sync_interval_12_hours)),
|
||||
DurationOption(1440L, context.getString(R.string.two_way_sync_interval_24_hours))
|
||||
)
|
||||
}
|
||||
}
|
|
@ -8,8 +8,10 @@
|
|||
package com.owncloud.android.ui.activity
|
||||
|
||||
import android.os.Bundle
|
||||
import android.widget.ArrayAdapter
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.nextcloud.client.di.Injectable
|
||||
import com.nextcloud.model.DurationOption
|
||||
import com.nextcloud.utils.extensions.setVisibleIf
|
||||
import com.owncloud.android.databinding.InternalTwoWaySyncLayoutBinding
|
||||
import com.owncloud.android.ui.adapter.InternalTwoWaySyncAdapter
|
||||
|
@ -23,26 +25,55 @@ class InternalTwoWaySyncActivity : BaseActivity(), Injectable {
|
|||
binding = InternalTwoWaySyncLayoutBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
setVisibilities()
|
||||
setupTwoWaySyncInterval()
|
||||
setupTwoWaySyncToggle()
|
||||
setupList()
|
||||
}
|
||||
|
||||
private fun setupTwoWaySyncInterval() {
|
||||
val durations = DurationOption.twoWaySyncIntervals(this)
|
||||
|
||||
val adapter = ArrayAdapter(
|
||||
this,
|
||||
android.R.layout.simple_dropdown_item_1line,
|
||||
durations.map { it.displayText }
|
||||
)
|
||||
|
||||
binding.twoWaySyncInterval.run {
|
||||
setAdapter(adapter)
|
||||
setText(durations[0].displayText, false)
|
||||
setOnItemClickListener { _, _, position, _ ->
|
||||
val selectedDuration = durations[position]
|
||||
handleDurationSelected(selectedDuration.value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleDurationSelected(duration: Long) {
|
||||
preferences.twoWaySyncInterval = duration
|
||||
}
|
||||
|
||||
private fun setupTwoWaySyncToggle() {
|
||||
binding.twoWaySyncToggle.isChecked = preferences.twoWayInternalSyncStatus
|
||||
binding.twoWaySyncToggle.isChecked = preferences.twoWaySyncStatus
|
||||
binding.twoWaySyncToggle.setOnCheckedChangeListener { _, isChecked ->
|
||||
preferences.twoWayInternalSyncStatus = isChecked
|
||||
preferences.twoWaySyncStatus = isChecked
|
||||
setupList()
|
||||
setVisibilities()
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupList() {
|
||||
binding.list.setVisibleIf(preferences.twoWayInternalSyncStatus)
|
||||
|
||||
if (preferences.twoWayInternalSyncStatus) {
|
||||
if (preferences.twoWaySyncStatus) {
|
||||
binding.list.apply {
|
||||
adapter = InternalTwoWaySyncAdapter(fileDataStorageManager, user.get(), context)
|
||||
layoutManager = LinearLayoutManager(context)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setVisibilities() {
|
||||
binding.list.setVisibleIf(preferences.twoWaySyncStatus)
|
||||
binding.twoWaySyncIntervalLayout.setVisibleIf(preferences.twoWaySyncStatus)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
-->
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
@ -20,6 +21,24 @@
|
|||
android:layout_marginBottom="@dimen/alternate_margin"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/two_way_sync_interval_layout"
|
||||
android:layout_marginHorizontal="@dimen/standard_half_padding"
|
||||
style="@style/Widget.Material3.TextInputLayout.FilledBox.ExposedDropdownMenu"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="@dimen/alternate_margin"
|
||||
android:hint="@string/prefs_two_way_sync_interval">
|
||||
|
||||
<AutoCompleteTextView
|
||||
android:id="@+id/two_way_sync_interval"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="none"
|
||||
tools:ignore="LabelFor" />
|
||||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/list"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -116,6 +116,18 @@
|
|||
<string name="prefs_value_theme_system">Follow system</string>
|
||||
<string name="prefs_theme_title">Theme</string>
|
||||
<string name="prefs_two_way_sync">Two Way Sync</string>
|
||||
<string name="prefs_two_way_sync_interval">Two Way Sync Interval</string>
|
||||
|
||||
<string name="two_way_sync_interval_15_min">15 minutes</string>
|
||||
<string name="two_way_sync_interval_30_min">30 minutes</string>
|
||||
<string name="two_way_sync_interval_45_min">45 minutes</string>
|
||||
<string name="two_way_sync_interval_1_hour">1 hour</string>
|
||||
<string name="two_way_sync_interval_2_hours">2 hours</string>
|
||||
<string name="two_way_sync_interval_4_hours">4 hours</string>
|
||||
<string name="two_way_sync_interval_6_hours">6 hours</string>
|
||||
<string name="two_way_sync_interval_8_hours">8 hours</string>
|
||||
<string name="two_way_sync_interval_12_hours">12 hours</string>
|
||||
<string name="two_way_sync_interval_24_hours">24 hours</string>
|
||||
|
||||
<string name="recommend_subject">Try %1$s on your device!</string>
|
||||
<string name="recommend_text">I want to invite you to use %1$s on your device.\nDownload here: %2$s</string>
|
||||
|
|
Loading…
Reference in a new issue