Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable-3.30] Add disable all button to InternalTwoWaySyncActivity menu #13909

Merged
merged 6 commits into from
Oct 30, 2024
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
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ dependencies {
implementation 'com.caverock:androidsvg:1.4'
implementation 'androidx.annotation:annotation:1.8.1'
implementation 'com.vanniktech:emoji-google:0.21.0'
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.6")

implementation "com.github.nextcloud-deps.hwsecurity:hwsecurity-fido:$fidoVersion"
implementation "com.github.nextcloud-deps.hwsecurity:hwsecurity-fido2:$fidoVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ interface BackgroundJobManager {
changedFiles: Array<String> = arrayOf<String>()
)

fun cancelTwoWaySyncJob()

fun scheduleOfflineSync()

fun scheduleMediaFoldersDetectionJob()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,10 @@ internal class BackgroundJobManagerImpl(
)
}

override fun cancelTwoWaySyncJob() {
workManager.cancelJob(JOB_INTERNAL_TWO_WAY_SYNC)
}

override fun scheduleOfflineSync() {
val constrains = Constraints.Builder()
.setRequiredNetworkType(NetworkType.UNMETERED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class InternalTwoWaySyncWork(
private val powerManagementService: PowerManagementService,
private val connectivityService: ConnectivityService
) : Worker(context, params) {
private var shouldRun = true

override fun doWork(): Result {
Log_OC.d(TAG, "Worker started!")

Expand All @@ -50,6 +52,11 @@ class InternalTwoWaySyncWork(
val folders = fileDataStorageManager.getInternalTwoWaySyncFolders(user)

for (folder in folders) {
if (!shouldRun) {
Log_OC.d(TAG, "Worker was stopped!")
return Result.failure()
}

checkFreeSpace(folder)?.let { checkFreeSpaceResult ->
return checkFreeSpaceResult
}
Expand Down Expand Up @@ -90,6 +97,12 @@ class InternalTwoWaySyncWork(
}
}

override fun onStopped() {
Log_OC.d(TAG, "OnStopped of worker called!")
shouldRun = false
super.onStopped()
}

@Suppress("TooGenericExceptionCaught")
private fun checkFreeSpace(folder: OCFile): Result? {
val storagePath = folder.storagePath ?: MainApp.getStoragePath()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,32 @@ import android.view.MenuInflater
import android.view.MenuItem
import android.view.View
import androidx.core.view.MenuProvider
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import com.nextcloud.android.common.ui.theme.utils.ColorRole
import com.nextcloud.client.di.Injectable
import com.nextcloud.client.jobs.BackgroundJobManager
import com.nextcloud.client.jobs.download.FileDownloadWorker
import com.owncloud.android.R
import com.owncloud.android.databinding.InternalTwoWaySyncLayoutBinding
import com.owncloud.android.ui.adapter.InternalTwoWaySyncAdapter
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import javax.inject.Inject

class InternalTwoWaySyncActivity : DrawerActivity(), Injectable {
@Inject
lateinit var backgroundJobManager: BackgroundJobManager

lateinit var binding: InternalTwoWaySyncLayoutBinding

private lateinit var internalTwoWaySyncAdapter: InternalTwoWaySyncAdapter

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

internalTwoWaySyncAdapter = InternalTwoWaySyncAdapter(fileDataStorageManager, user.get(), this)

binding = InternalTwoWaySyncLayoutBinding.inflate(layoutInflater)
setContentView(binding.root)

Expand All @@ -38,7 +51,7 @@ class InternalTwoWaySyncActivity : DrawerActivity(), Injectable {
}

private fun setupActionBar() {
updateActionBarTitleAndHomeButtonByString(getString(R.string.internal_two_way_sync_headline))
updateActionBarTitleAndHomeButtonByString(getString(R.string.two_way_sync_activity_title))
supportActionBar?.setDisplayHomeAsUpEnabled(true)
}

Expand All @@ -47,7 +60,7 @@ class InternalTwoWaySyncActivity : DrawerActivity(), Injectable {
binding.run {
list.run {
setEmptyView(emptyList.emptyListView)
adapter = InternalTwoWaySyncAdapter(fileDataStorageManager, user.get(), this@InternalTwoWaySyncActivity)
adapter = internalTwoWaySyncAdapter
layoutManager = LinearLayoutManager(this@InternalTwoWaySyncActivity)
adapter?.notifyDataSetChanged()
}
Expand All @@ -58,12 +71,12 @@ class InternalTwoWaySyncActivity : DrawerActivity(), Injectable {
binding.emptyList.run {
emptyListViewHeadline.run {
visibility = View.VISIBLE
setText(R.string.internal_two_way_sync_list_empty_headline)
setText(R.string.two_way_sync_activity_empty_list_title)
}

emptyListViewText.run {
visibility = View.VISIBLE
setText(R.string.internal_two_way_sync_text)
setText(R.string.two_way_sync_activity_empty_list_desc)
}

emptyListIcon.run {
Expand All @@ -79,18 +92,42 @@ class InternalTwoWaySyncActivity : DrawerActivity(), Injectable {
}
}

private fun disableTwoWaySyncAndWorkers() {
lifecycleScope.launch(Dispatchers.IO) {
backgroundJobManager.cancelTwoWaySyncJob()

val folders = fileDataStorageManager.getInternalTwoWaySyncFolders(user.get())
folders.forEach { folder ->
FileDownloadWorker.cancelOperation(user.get().accountName, folder.fileId)
backgroundJobManager.cancelFilesDownloadJob(user.get(), folder.fileId)

folder.internalFolderSyncTimestamp = -1L
fileDataStorageManager.saveFile(folder)
}

launch(Dispatchers.Main) {
internalTwoWaySyncAdapter.update()
}
}
}

private fun setupMenuProvider() {
addMenuProvider(
object : MenuProvider {
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) = Unit
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
menuInflater.inflate(R.menu.activity_internal_two_way_sync, menu)
}

override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
return when (menuItem.itemId) {
android.R.id.home -> {
onBackPressed()
true
}

R.id.action_dismiss_two_way_sync -> {
disableTwoWaySyncAndWorkers()
true
}
else -> false
}
}
Expand Down
17 changes: 17 additions & 0 deletions app/src/main/res/menu/activity_internal_two_way_sync.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Nextcloud - Android Client
~
~ SPDX-FileCopyrightText: 2024 ZetaTom
~ SPDX-License-Identifier: AGPL-3.0-or-later
-->
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<item
android:id="@+id/action_dismiss_two_way_sync"
android:contentDescription="@string/two_way_sync_activity_disable_all_button_title"
android:orderInCategory="1"
android:title="@string/two_way_sync_activity_disable_all_button_title"
app:showAsAction="never" />
</menu>
8 changes: 5 additions & 3 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,9 @@
<string name="sync">Sync</string>
<string name="please_select_a_server">Please select a server…</string>
<string name="unset_internal_two_way_sync_description">Remove folder from internal two way sync</string>
<string name="internal_two_way_sync_list_empty_headline">Two way sync not set up</string>
<string name="internal_two_way_sync_text">To set up a two way sync folder, please enable it in the details tab of the folder in question.</string>
<string name="internal_two_way_sync_headline">Internal two way sync</string>

<string name="two_way_sync_activity_empty_list_title">Two way sync not set up</string>
<string name="two_way_sync_activity_empty_list_desc">To set up a two way sync folder, please enable it in the details tab of the folder in question.</string>
<string name="two_way_sync_activity_title">Internal two way sync</string>
<string name="two_way_sync_activity_disable_all_button_title">Disable for all folders</string>
</resources>
Loading