Add disable all button to InternalTwoWaySyncActivity menu

Signed-off-by: ZetaTom <70907959+ZetaTom@users.noreply.github.com>
This commit is contained in:
ZetaTom 2024-10-30 09:51:23 +01:00 committed by Alper Öztürk
parent d21321e1d6
commit 1fc4f51fd1
3 changed files with 55 additions and 3 deletions

View file

@ -17,16 +17,28 @@ import androidx.core.view.MenuProvider
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.owncloud.android.R
import com.owncloud.android.databinding.InternalTwoWaySyncLayoutBinding
import com.owncloud.android.ui.adapter.InternalTwoWaySyncAdapter
import kotlinx.coroutines.CoroutineScope
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)
@ -47,7 +59,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()
}
@ -79,10 +91,29 @@ class InternalTwoWaySyncActivity : DrawerActivity(), Injectable {
}
}
/**
* Disable two-way sync for all folders and stop all related workers.
*/
private fun removeAllFolders() {
CoroutineScope(Dispatchers.Main).launch {
val folders = fileDataStorageManager.getInternalTwoWaySyncFolders(user.get())
folders.forEach { folder ->
// update database to ignore folder
folder.internalFolderSyncTimestamp = -1L
fileDataStorageManager.saveFile(folder)
}
// update view
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) {
@ -90,7 +121,10 @@ class InternalTwoWaySyncActivity : DrawerActivity(), Injectable {
onBackPressed()
true
}
R.id.action_dismiss_two_way_sync -> {
removeAllFolders()
true
}
else -> false
}
}

View file

@ -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/action_dismiss_two_way_sync"
android:orderInCategory="1"
android:title="@string/action_dismiss_two_way_sync"
app:showAsAction="never" />
</menu>

View file

@ -1251,4 +1251,5 @@
<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="action_dismiss_two_way_sync">Disable all folders</string>
</resources>