diff --git a/app/build.gradle b/app/build.gradle index 5a91fe8a6..5fa2dc596 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -203,8 +203,8 @@ android { implementation "androidx.webkit:webkit:1.12.1" implementation 'com.google.android.flexbox:flexbox:3.0.0' - implementation "androidx.paging:paging-runtime:3.3.5" - implementation "androidx.paging:paging-rxjava3:3.3.5" +// implementation "androidx.paging:paging-runtime:3.3.5" +// implementation "androidx.paging:paging-rxjava3:3.3.5" //https://github.com/material-components/material-components-android implementation "com.google.android.material:material:1.12.0" diff --git a/app/src/main/java/com/seafile/seadroid2/context/NavContext.java b/app/src/main/java/com/seafile/seadroid2/context/NavContext.java index 91770f282..d2b622ae8 100644 --- a/app/src/main/java/com/seafile/seadroid2/context/NavContext.java +++ b/app/src/main/java/com/seafile/seadroid2/context/NavContext.java @@ -68,6 +68,7 @@ public void restoreNavContextFromSp() { RepoModel repoModel = new RepoModel(); repoModel.repo_id = contextModel.repo_id; repoModel.repo_name = contextModel.repo_name; + repoModel.permission = contextModel.permission; navStack.push(repoModel); } else if (contextModel.type.equals("dirent")) { DirentModel direntModel = new DirentModel(); @@ -77,6 +78,7 @@ public void restoreNavContextFromSp() { direntModel.parent_dir = Utils.getParentPath(direntModel.full_path); direntModel.name = Utils.getFileNameFromPath(contextModel.full_path); direntModel.uid = direntModel.getUID(); + direntModel.permission = contextModel.permission; navStack.push(direntModel); } } @@ -95,11 +97,13 @@ private void saveToSp() { contextModel.repo_name = e.repo_name; contextModel.type = "repo"; contextModel.full_path = "/"; + contextModel.permission = e.permission; } else if (baseModel instanceof DirentModel e) { contextModel.repo_id = e.repo_id; contextModel.repo_name = e.repo_name; contextModel.type = "dirent"; contextModel.full_path = e.full_path; + contextModel.permission = e.permission; } stack.add(contextModel); } diff --git a/app/src/main/java/com/seafile/seadroid2/enums/TransferDataSource.java b/app/src/main/java/com/seafile/seadroid2/enums/TransferDataSource.java index eaee2aacf..a0b35e122 100644 --- a/app/src/main/java/com/seafile/seadroid2/enums/TransferDataSource.java +++ b/app/src/main/java/com/seafile/seadroid2/enums/TransferDataSource.java @@ -4,7 +4,8 @@ public enum TransferDataSource { ALBUM_BACKUP, /** - * + * (automatically) + * folder backup */ FOLDER_BACKUP, diff --git a/app/src/main/java/com/seafile/seadroid2/framework/data/db/dao/FileTransferDAO.java b/app/src/main/java/com/seafile/seadroid2/framework/data/db/dao/FileTransferDAO.java index f58885918..797747e97 100644 --- a/app/src/main/java/com/seafile/seadroid2/framework/data/db/dao/FileTransferDAO.java +++ b/app/src/main/java/com/seafile/seadroid2/framework/data/db/dao/FileTransferDAO.java @@ -50,6 +50,9 @@ public interface FileTransferDAO { @Delete void deleteOne(FileTransferEntity entity); + @Delete + void deleteMultiple(List entity); + @Delete Single deleteOneAsync(FileTransferEntity entity); @@ -66,19 +69,19 @@ public interface FileTransferDAO { /** * Modify the task that is being in IN_PROGRESS to CANCELLED */ - @Query("update file_transfer_list set transfer_result = 'USER_CANCELLED', transfer_status = 'CANCELLED' where related_account = :related_account and data_source in ( :feats ) and transfer_status in ('IN_PROGRESS','WAITING')") - Completable cancelByDataSource(String related_account, List feats); + @Query("update file_transfer_list set transfer_status = 'CANCELLED', transfer_result = 'USER_CANCELLED' where related_account = :related_account and data_source in ( :feats ) and transfer_status in ('IN_PROGRESS','WAITING')") + Completable cancelAllByDataSource(String related_account, List feats); - @Query("update file_transfer_list set transfer_result = 'CANCELLED', transfer_status = 'CANCELLED', transfer_result = :result where related_account = :related_account and data_source = :dataSource and transfer_status in ('IN_PROGRESS','WAITING')") - void cancel(String related_account, TransferDataSource dataSource, TransferResult result); + @Query("update file_transfer_list set transfer_status = 'CANCELLED', transfer_result = :result where related_account = :related_account and data_source = 'FILE_BACKUP' and transfer_status in ('IN_PROGRESS','WAITING')") + void cancelWithFileBackup(String related_account, TransferResult result); - @Query("update file_transfer_list set transfer_status = 'CANCELLED', transfer_result = :result where data_source = 'FILE_BACKUP' and transfer_status in ('IN_PROGRESS','WAITING')") - void cancelWithFileBackup(TransferResult result); - - @Query("update file_transfer_list set transfer_status = 'CANCELLED', transfer_result = 'CANCELLED', data_status = -1, transferred_size = 0 where data_source in ('FILE_BACKUP','FOLDER_BACKUP')") - void cancelAllWithFileBackup(); + /** + * remove all tasks for ['FILE_BACKUP','FOLDER_BACKUP','ALBUM_BACKUP'] + */ + @Query("update file_transfer_list set transfer_status = 'CANCELLED', transfer_result = 'USER_CANCELLED', data_status = -1, transferred_size = 0 where related_account = :related_account and data_source in ('FILE_BACKUP','FOLDER_BACKUP','ALBUM_BACKUP')") + Completable removeAllUploadByAccount(String related_account); - @Query("select * from file_transfer_list where related_account = :related_account and data_source in ( :feats ) and data_status = 0 order by created_at asc") + @Query("select * from file_transfer_list where related_account = :related_account and data_source in ( :feats ) order by created_at asc") Single> getListByDataSourceAsync(String related_account, List feats); @Query("select * from file_transfer_list where related_account = :related_account and transfer_action = :transfer_action and is_auto_transfer = 1 and transfer_status in ('IN_PROGRESS', 'WAITING') and data_source = :feature and data_status = 0 order by created_at asc limit 1") @@ -87,32 +90,26 @@ public interface FileTransferDAO { @Query("select COUNT(*) from file_transfer_list where related_account = :related_account and transfer_action = :transfer_action and is_auto_transfer = 1 and transfer_status in ('IN_PROGRESS', 'WAITING') and data_source = :feature and data_status = 0") int countPendingTransferSync(String related_account, TransferAction transfer_action, TransferDataSource feature); + @Query("select * from file_transfer_list where related_account = :related_account and transfer_action = :transferAction and transfer_status = :transferStatus and data_status = 0 order by created_at") + Single> getByActionAndStatusAsync(String related_account, TransferAction transferAction, TransferStatus transferStatus); + @Query("select * from file_transfer_list where transfer_action = :transfer_action and is_auto_transfer = 1 and transfer_status in ('IN_PROGRESS', 'WAITING') and data_source = :feature and data_status = 0 order by created_at asc limit 1") List getOnePendingTransferAllAccountSync(TransferAction transfer_action, TransferDataSource feature); @Query("select * from file_transfer_list where related_account = :related_account and is_auto_transfer = 1 and transfer_action = 'DOWNLOAD' and transfer_status in ('IN_PROGRESS', 'WAITING') and data_status = 0 order by created_at asc limit 1") - List getOnePendingDownloadByActionSync(String related_account); + List getOnePendingDownloadByAccountSync(String related_account); @Query("select COUNT(*) from file_transfer_list where related_account = :related_account and is_auto_transfer = 1 and transfer_action = 'DOWNLOAD' and transfer_status in ('IN_PROGRESS', 'WAITING') and data_status = 0") int countPendingDownloadListSync(String related_account); - @Query("select * from file_transfer_list where related_account = :related_account and transfer_action = :transfer_action and is_auto_transfer = 1 and transfer_status in ('IN_PROGRESS', 'WAITING') and data_status = 0 order by created_at asc limit :limit offset :offset") - List getPagePendingListTransferSync(String related_account, TransferAction transfer_action, int limit, int offset); - - @Query("select * from file_transfer_list where related_account = :related_account and transfer_action = 'UPLOAD' and data_source in ('FOLDER_BACKUP','FILE_BACKUP','ALBUM_BACKUP') and data_status = 0 order by modified_at desc limit :limit offset :offset") - List getPageUploadListSync(String related_account, int limit, int offset); - - @Query("select * from file_transfer_list where related_account = :related_account and transfer_action = 'UPLOAD' and data_source in ('FOLDER_BACKUP','FILE_BACKUP','ALBUM_BACKUP') and data_status = 0 order by modified_at desc limit :limit offset :offset") + @Query("select * from file_transfer_list where related_account = :related_account and transfer_action = 'UPLOAD' and data_source in ('FOLDER_BACKUP','FILE_BACKUP','ALBUM_BACKUP') and data_status = 0 order by created_at desc limit :limit offset :offset") Single> getPageUploadListAsync(String related_account, int limit, int offset); - @Query("select * from file_transfer_list where related_account = :related_account and transfer_action = 'DOWNLOAD' and data_status = 0 order by modified_at desc limit :limit offset :offset") - List getPageDownloadListSync(String related_account, int limit, int offset); - - @Query("select * from file_transfer_list where related_account = :related_account and transfer_action = 'DOWNLOAD' and data_status = 0 order by modified_at desc limit :limit offset :offset") + @Query("select * from file_transfer_list where related_account = :related_account and transfer_action = 'DOWNLOAD' and data_status = 0 order by created_at desc limit :limit offset :offset") Single> getPageDownloadListAsync(String related_account, int limit, int offset); - @Query("select * from file_transfer_list where related_account = :related_account and transfer_action = :transferAction and target_path = :target_path and data_status = 0 order by created_at desc limit 1") + @Query("select * from file_transfer_list where related_account = :related_account and transfer_action = :transferAction and target_path = :target_path and data_status = 0 order by created_at desc limit 1") List getByTargetPathSync(String related_account, TransferAction transferAction, String target_path); @@ -132,19 +129,12 @@ public interface FileTransferDAO { @Query("select * from file_transfer_list where repo_id = :repoId and full_path IN(:fullPaths) and transfer_action = :transfer_action order by created_at asc") List getListByFullPathsSync(String repoId, List fullPaths, TransferAction transfer_action); - @Query("select * from file_transfer_list where repo_id = :repoId and transfer_action = :transfer_action order by created_at asc limit :limit offset :offset") - List getPageListSync(String repoId, TransferAction transfer_action, int limit, int offset); - - @Query("select * from file_transfer_list where repo_id = :repoId and transfer_action = :transferAction and full_path = :full_path and data_status = 0 order by created_at") - List getListByFullPathSync(String repoId, TransferAction transferAction, String full_path); - @Query("select * from file_transfer_list where repo_id = :repoId and transfer_action = :transferAction and full_path = :full_path and data_status = 0 order by created_at") Single> getListByFullPathAsync(String repoId, TransferAction transferAction, String full_path); @Query("select COUNT(*) from file_transfer_list where repo_id = :repoId and full_path = :fullPath and transfer_action = :transfer_action and data_source = :feature and data_status = 0 ") int checkOneByFullPath(String repoId, String fullPath, TransferAction transfer_action, TransferDataSource feature); - @RawQuery int updateEntityStatus(SupportSQLiteQuery query); diff --git a/app/src/main/java/com/seafile/seadroid2/framework/data/model/ContextModel.java b/app/src/main/java/com/seafile/seadroid2/framework/data/model/ContextModel.java index cce811099..70ac51ebf 100644 --- a/app/src/main/java/com/seafile/seadroid2/framework/data/model/ContextModel.java +++ b/app/src/main/java/com/seafile/seadroid2/framework/data/model/ContextModel.java @@ -10,4 +10,5 @@ public class ContextModel { * parent_dir + name */ public String full_path; + public String permission; } diff --git a/app/src/main/java/com/seafile/seadroid2/framework/file_monitor/FileSyncService.java b/app/src/main/java/com/seafile/seadroid2/framework/file_monitor/FileSyncService.java index 4a0ca2302..a95003936 100644 --- a/app/src/main/java/com/seafile/seadroid2/framework/file_monitor/FileSyncService.java +++ b/app/src/main/java/com/seafile/seadroid2/framework/file_monitor/FileSyncService.java @@ -118,10 +118,10 @@ public void onCreate() { BackgroundJobManagerImpl.getInstance().startDownloadChainWorker(); //folder backup upload worker - BackgroundJobManagerImpl.getInstance().startFolderChainWorker(false); + BackgroundJobManagerImpl.getInstance().startFolderAutoBackupWorkerChain(false); //file upload backup - BackgroundJobManagerImpl.getInstance().startFileUploadWorker(); + BackgroundJobManagerImpl.getInstance().startFileManualUploadWorker(); //bus TransferBusHelper.getTransferObserver().observeForever(transferOpTypeObserver); @@ -142,7 +142,7 @@ private void onBusEvent(TransferOpType opType) { resetFolderMonitor(); - BackgroundJobManagerImpl.getInstance().cancelAllFolderUploadWorker(); + BackgroundJobManagerImpl.getInstance().cancelFolderAutoUploadWorker(); } } @@ -233,7 +233,7 @@ private void doBackup(String action, File file) { BackgroundJobManagerImpl.getInstance().startCheckDownloadedFileChainWorker(file.getAbsolutePath()); } } else { - BackgroundJobManagerImpl.getInstance().startFolderChainWorker(true); + BackgroundJobManagerImpl.getInstance().startFolderAutoBackupWorkerChain(true); } } diff --git a/app/src/main/java/com/seafile/seadroid2/framework/worker/BackgroundJobManagerImpl.java b/app/src/main/java/com/seafile/seadroid2/framework/worker/BackgroundJobManagerImpl.java index 4e99499a7..4fec53302 100644 --- a/app/src/main/java/com/seafile/seadroid2/framework/worker/BackgroundJobManagerImpl.java +++ b/app/src/main/java/com/seafile/seadroid2/framework/worker/BackgroundJobManagerImpl.java @@ -108,8 +108,8 @@ public WorkManager getWorkManager() { /////////////////// /// media worker /////////////////// - public void startMediaChainWorker(boolean isForce) { - cancelAllMediaWorker(); + public void startMediaWorkerChain(boolean isForce) { + cancelMediaWorker(); OneTimeWorkRequest scanRequest = getMediaScanRequest(isForce); OneTimeWorkRequest uploadRequest = getMediaUploadRequest(); @@ -158,7 +158,7 @@ private OneTimeWorkRequest getMediaUploadRequest() { } //cancel media - public void cancelAllMediaWorker() { + public void cancelMediaWorker() { cancelById(UploadMediaFileAutomaticallyWorker.UID); cancelById(MediaBackupScannerWorker.UID); } @@ -166,8 +166,8 @@ public void cancelAllMediaWorker() { /////////////////// /// upload folder /////////////////// - public void startFolderChainWorker(boolean isForce) { - cancelAllFolderUploadWorker(); + public void startFolderAutoBackupWorkerChain(boolean isForce) { + cancelFolderAutoUploadWorker(); OneTimeWorkRequest scanRequest = getFolderScanRequest(isForce); OneTimeWorkRequest uploadRequest = getFolderUploadRequest(); @@ -213,7 +213,7 @@ private OneTimeWorkRequest getFolderUploadRequest() { .build(); } - public void cancelAllFolderUploadWorker() { + public void cancelFolderAutoUploadWorker() { cancelById(FolderBackupScannerWorker.UID); cancelById(UploadFolderFileAutomaticallyWorker.UID); } @@ -221,7 +221,7 @@ public void cancelAllFolderUploadWorker() { /////////////////// /// upload file /////////////////// - public void startFileUploadWorker() { + public void startFileManualUploadWorker() { String workerName = UploadFileManuallyWorker.class.getSimpleName(); OneTimeWorkRequest request = getFileUploadRequest(); getWorkManager().enqueueUniqueWork(workerName, ExistingWorkPolicy.KEEP, request); @@ -233,6 +233,10 @@ private OneTimeWorkRequest getFileUploadRequest() { .build(); } + public void cancelFileManualUploadWorker() { + cancelById(UploadFileManuallyWorker.UID); + } + /////////////////// /// download /////////////////// diff --git a/app/src/main/java/com/seafile/seadroid2/framework/worker/download/DownloadWorker.java b/app/src/main/java/com/seafile/seadroid2/framework/worker/download/DownloadWorker.java index 941089ba9..c68db0955 100644 --- a/app/src/main/java/com/seafile/seadroid2/framework/worker/download/DownloadWorker.java +++ b/app/src/main/java/com/seafile/seadroid2/framework/worker/download/DownloadWorker.java @@ -119,7 +119,7 @@ public Result doWork() { List list = AppDatabase .getInstance() .fileTransferDAO() - .getOnePendingDownloadByActionSync(account.getSignature()); + .getOnePendingDownloadByAccountSync(account.getSignature()); if (CollectionUtils.isEmpty(list)) { break; } diff --git a/app/src/main/java/com/seafile/seadroid2/framework/worker/upload/UploadFileManuallyWorker.java b/app/src/main/java/com/seafile/seadroid2/framework/worker/upload/UploadFileManuallyWorker.java index 4eaebe57e..8093e0f9f 100644 --- a/app/src/main/java/com/seafile/seadroid2/framework/worker/upload/UploadFileManuallyWorker.java +++ b/app/src/main/java/com/seafile/seadroid2/framework/worker/upload/UploadFileManuallyWorker.java @@ -96,7 +96,7 @@ private ListenableWorker.Result start() { boolean isAmple = calcQuota(CollectionUtils.newArrayList(transferEntity)); if (!isAmple) { getGeneralNotificationHelper().showErrorNotification(R.string.above_quota, R.string.settings_folder_backup_info_title); - AppDatabase.getInstance().fileTransferDAO().cancelWithFileBackup(TransferResult.OUT_OF_QUOTA); + AppDatabase.getInstance().fileTransferDAO().cancelWithFileBackup(transferEntity.related_account, TransferResult.OUT_OF_QUOTA); finishFlagEvent = TransferEvent.EVENT_CANCEL_WITH_OUT_OF_QUOTA; break; diff --git a/app/src/main/java/com/seafile/seadroid2/ui/account/AccountDetailActivity.java b/app/src/main/java/com/seafile/seadroid2/ui/account/AccountDetailActivity.java index b96d0ce27..7dc20596b 100644 --- a/app/src/main/java/com/seafile/seadroid2/ui/account/AccountDetailActivity.java +++ b/app/src/main/java/com/seafile/seadroid2/ui/account/AccountDetailActivity.java @@ -1,40 +1,24 @@ package com.seafile.seadroid2.ui.account; -import android.app.Dialog; import android.content.Context; -import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.text.Editable; import android.text.TextUtils; import android.text.TextWatcher; -import android.text.method.HideReturnsTransformationMethod; -import android.text.method.PasswordTransformationMethod; import android.util.Log; import android.util.Pair; import android.view.MenuItem; import android.view.View; import android.view.inputmethod.InputMethodManager; -import android.widget.Button; -import android.widget.CheckBox; import android.widget.CompoundButton; -import android.widget.EditText; -import android.widget.ImageView; -import android.widget.TextView; -import androidx.appcompat.app.AlertDialog; import androidx.appcompat.widget.Toolbar; import androidx.core.app.NavUtils; import androidx.core.app.TaskStackBuilder; import androidx.lifecycle.Observer; -import com.blankj.utilcode.constant.RegexConstants; import com.blankj.utilcode.util.NetworkUtils; -import com.blankj.utilcode.util.RegexUtils; -import com.google.android.material.button.MaterialButton; -import com.google.android.material.dialog.MaterialAlertDialogBuilder; -import com.google.android.material.textfield.TextInputEditText; -import com.google.android.material.textfield.TextInputLayout; import com.seafile.seadroid2.R; import com.seafile.seadroid2.SeafException; import com.seafile.seadroid2.account.Account; @@ -150,9 +134,9 @@ private void initViewModel() { @Override public void onChanged(Boolean aBoolean) { if (aBoolean) { - showProgressDialog(); + showLoadingDialog(); } else { - dismissProgressDialog(); + dismissLoadingDialog(); } } }); @@ -274,7 +258,7 @@ private void onLoggedIn(Account loginAccount) { @Override protected void onDestroy() { - dismissProgressDialog(); + dismissLoadingDialog(); super.onDestroy(); } diff --git a/app/src/main/java/com/seafile/seadroid2/ui/account/AccountsActivity.java b/app/src/main/java/com/seafile/seadroid2/ui/account/AccountsActivity.java index 97ee1984d..ce5e726df 100644 --- a/app/src/main/java/com/seafile/seadroid2/ui/account/AccountsActivity.java +++ b/app/src/main/java/com/seafile/seadroid2/ui/account/AccountsActivity.java @@ -3,7 +3,6 @@ import android.accounts.AccountManagerCallback; import android.accounts.AccountManagerFuture; import android.accounts.OnAccountsUpdateListener; -import android.app.Dialog; import android.content.Intent; import android.os.Bundle; import android.util.Log; @@ -21,7 +20,6 @@ import com.blankj.utilcode.util.ActivityUtils; import com.blankj.utilcode.util.AppUtils; -import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.seafile.seadroid2.R; import com.seafile.seadroid2.framework.data.ServerInfo; import com.seafile.seadroid2.framework.datastore.sp.AppDataManager; @@ -157,9 +155,9 @@ private void initViewModel() { @Override public void onChanged(Boolean aBoolean) { if (aBoolean) { - showProgressDialog(); + showLoadingDialog(); } else { - dismissProgressDialog(); + dismissLoadingDialog(); } } }); diff --git a/app/src/main/java/com/seafile/seadroid2/ui/base/BaseActivity.java b/app/src/main/java/com/seafile/seadroid2/ui/base/BaseActivity.java index db0bf401e..34702fc2e 100644 --- a/app/src/main/java/com/seafile/seadroid2/ui/base/BaseActivity.java +++ b/app/src/main/java/com/seafile/seadroid2/ui/base/BaseActivity.java @@ -3,15 +3,12 @@ import android.app.Dialog; import android.os.Bundle; -import androidx.annotation.NonNull; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.seafile.seadroid2.R; -import com.seafile.seadroid2.framework.helper.NightModeHelper; /** * A base activity that handles common functionality in the app. This includes Action Bar tweaks. @@ -50,31 +47,31 @@ public void setContentView(int layoutResID) { getActionBarToolbar(); } - private Dialog dialog; + private Dialog loadingDialog; - public void showProgressDialog(boolean isShow) { + public void showLoadingDialog(boolean isShow) { if (isShow) { - showProgressDialog(); + showLoadingDialog(); } else { - dismissProgressDialog(); + dismissLoadingDialog(); } } - public void showProgressDialog() { - if (dialog == null) { + public void showLoadingDialog() { + if (loadingDialog == null) { MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(this); builder.setView(R.layout.layout_dialog_progress_bar); - dialog = builder.create(); + loadingDialog = builder.create(); } - if (!dialog.isShowing()) { - dialog.show(); + if (!loadingDialog.isShowing()) { + loadingDialog.show(); } } - public void dismissProgressDialog() { - if (dialog != null && dialog.isShowing()) { - dialog.dismiss(); + public void dismissLoadingDialog() { + if (loadingDialog != null && loadingDialog.isShowing()) { + loadingDialog.dismiss(); } } } diff --git a/app/src/main/java/com/seafile/seadroid2/ui/base/fragment/BaseFragment.java b/app/src/main/java/com/seafile/seadroid2/ui/base/fragment/BaseFragment.java index 3de25e4de..d661b7ebc 100644 --- a/app/src/main/java/com/seafile/seadroid2/ui/base/fragment/BaseFragment.java +++ b/app/src/main/java/com/seafile/seadroid2/ui/base/fragment/BaseFragment.java @@ -1,7 +1,11 @@ package com.seafile.seadroid2.ui.base.fragment; +import android.app.Dialog; + import androidx.fragment.app.Fragment; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; +import com.seafile.seadroid2.R; import com.seafile.seadroid2.framework.util.SLogs; public class BaseFragment extends Fragment { @@ -29,4 +33,32 @@ public void onFirstResume() { public void onOtherResume() { } + + private Dialog dialog; + + public void showLoadingDialog(boolean isShow) { + if (isShow) { + showLoadingDialog(); + } else { + dismissLoadingDialog(); + } + } + + public void showLoadingDialog() { + if (dialog == null) { + MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(requireContext()); + builder.setView(R.layout.layout_dialog_progress_bar); + dialog = builder.create(); + } + + if (!dialog.isShowing()) { + dialog.show(); + } + } + + public void dismissLoadingDialog() { + if (dialog != null && dialog.isShowing()) { + dialog.dismiss(); + } + } } diff --git a/app/src/main/java/com/seafile/seadroid2/ui/camera_upload/AlbumBackupAdapter.java b/app/src/main/java/com/seafile/seadroid2/ui/camera_upload/AlbumBackupAdapter.java index f0c0e647d..27837e06f 100644 --- a/app/src/main/java/com/seafile/seadroid2/ui/camera_upload/AlbumBackupAdapter.java +++ b/app/src/main/java/com/seafile/seadroid2/ui/camera_upload/AlbumBackupAdapter.java @@ -6,7 +6,6 @@ import android.content.Context; import android.content.SyncResult; import android.os.Bundle; -import android.util.Log; import com.seafile.seadroid2.account.Account; import com.seafile.seadroid2.account.SupportAccountManager; @@ -50,14 +49,14 @@ public boolean onUnsyncableAccount() { public void onSyncCanceled(Thread thread) { super.onSyncCanceled(thread); SLogs.e("onSyncCanceled ->" + thread.getName()); - BackgroundJobManagerImpl.getInstance().cancelAllMediaWorker(); + BackgroundJobManagerImpl.getInstance().cancelMediaWorker(); } @Override public void onSyncCanceled() { super.onSyncCanceled(); SLogs.e("onSyncCanceled"); - BackgroundJobManagerImpl.getInstance().cancelAllMediaWorker(); + BackgroundJobManagerImpl.getInstance().cancelMediaWorker(); } @Override @@ -89,6 +88,6 @@ public void onPerformSync(android.accounts.Account account, //start boolean isForce = extras.getBoolean(ContentResolver.SYNC_EXTRAS_MANUAL); - BackgroundJobManagerImpl.getInstance().startMediaChainWorker(isForce); + BackgroundJobManagerImpl.getInstance().startMediaWorkerChain(isForce); } } diff --git a/app/src/main/java/com/seafile/seadroid2/ui/camera_upload/CameraUploadManager.java b/app/src/main/java/com/seafile/seadroid2/ui/camera_upload/CameraUploadManager.java index 7b049fabe..31fe7d0cc 100644 --- a/app/src/main/java/com/seafile/seadroid2/ui/camera_upload/CameraUploadManager.java +++ b/app/src/main/java/com/seafile/seadroid2/ui/camera_upload/CameraUploadManager.java @@ -124,7 +124,7 @@ public void disableCameraUpload() { ContentResolver.setIsSyncable(account.getAndroidAccount(), AUTHORITY, 0); } - BackgroundJobManagerImpl.getInstance().cancelAllMediaWorker(); + BackgroundJobManagerImpl.getInstance().cancelMediaWorker(); } /** diff --git a/app/src/main/java/com/seafile/seadroid2/ui/editor/EditorActivity.java b/app/src/main/java/com/seafile/seadroid2/ui/editor/EditorActivity.java index 89bec8bf6..d5a8fb531 100644 --- a/app/src/main/java/com/seafile/seadroid2/ui/editor/EditorActivity.java +++ b/app/src/main/java/com/seafile/seadroid2/ui/editor/EditorActivity.java @@ -1,6 +1,5 @@ package com.seafile.seadroid2.ui.editor; -import android.app.Dialog; import android.content.Context; import android.content.Intent; import android.os.Bundle; @@ -9,7 +8,6 @@ import android.text.TextWatcher; import android.view.Menu; import android.view.MenuItem; -import android.widget.Toast; import androidx.activity.OnBackPressedCallback; import androidx.annotation.Nullable; @@ -18,7 +16,6 @@ import com.blankj.utilcode.util.EncryptUtils; import com.blankj.utilcode.util.ToastUtils; -import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.seafile.seadroid2.R; import com.seafile.seadroid2.SeafException; import com.seafile.seadroid2.framework.util.SLogs; @@ -97,9 +94,9 @@ private void initViewModel() { @Override public void onChanged(Boolean aBoolean) { if (aBoolean) { - showProgressDialog(); + showLoadingDialog(); } else { - dismissProgressDialog(); + dismissLoadingDialog(); } } }); diff --git a/app/src/main/java/com/seafile/seadroid2/ui/main/MainActivity.java b/app/src/main/java/com/seafile/seadroid2/ui/main/MainActivity.java index 3ce1ed266..2e717d2cc 100644 --- a/app/src/main/java/com/seafile/seadroid2/ui/main/MainActivity.java +++ b/app/src/main/java/com/seafile/seadroid2/ui/main/MainActivity.java @@ -42,7 +42,6 @@ import com.seafile.seadroid2.account.SupportAccountManager; import com.seafile.seadroid2.context.NavContext; import com.seafile.seadroid2.databinding.ActivityMainBinding; -import com.seafile.seadroid2.enums.ActionModeCallbackType; import com.seafile.seadroid2.enums.FileViewType; import com.seafile.seadroid2.enums.NightMode; import com.seafile.seadroid2.enums.SortBy; @@ -467,25 +466,9 @@ public void onChanged(NightMode nightMode) { // } } }); - - mainViewModel.getOnActionModeLiveData().observe(this, new Observer() { - @Override - public void onChanged(ActionModeCallbackType callbackType) { - - onShowRepoActionMode(callbackType); - - } - }); } - private void onShowRepoActionMode(ActionModeCallbackType type) { - if (type == ActionModeCallbackType.CREATE) { - binding.pager.setUserInputEnabled(false); - } else if (type == ActionModeCallbackType.DESTORY) { - binding.pager.setUserInputEnabled(true); - } - } private void refreshToolbarTitle() { if (!getNavContext().inRepo()) { @@ -1199,7 +1182,7 @@ public void onActivityResult(Boolean o) { ///////////////////////////// private void doSelectedMultiFile(List uriList) { - showProgressDialog(); + showLoadingDialog(); try { RepoModel repoModel = getNavContext().getRepoModel(); @@ -1209,13 +1192,13 @@ private void doSelectedMultiFile(List uriList) { @Override public void accept(List newUris) { - dismissProgressDialog(); + dismissLoadingDialog(); if (!CollectionUtils.isEmpty(newUris)) { ToastUtils.showLong(R.string.added_to_upload_tasks); //start worker - BackgroundJobManagerImpl.getInstance().startFileUploadWorker(); + BackgroundJobManagerImpl.getInstance().startFileManualUploadWorker(); } } }); @@ -1226,7 +1209,7 @@ public void accept(List newUris) { } private void doSelectSingleFile(Uri uri) { - showProgressDialog(); + showLoadingDialog(); try { String fileName = Utils.getFilenameFromUri(this, uri); String parent_dir = getNavContext().getNavPath(); @@ -1242,7 +1225,7 @@ public void accept(DirentFileModel direntFileModel) throws Exception { addUploadTask(repoModel, getNavContext().getNavPath(), uri, false); } - dismissProgressDialog(); + dismissLoadingDialog(); } }); } catch (Exception e) { diff --git a/app/src/main/java/com/seafile/seadroid2/ui/main/MainViewModel.java b/app/src/main/java/com/seafile/seadroid2/ui/main/MainViewModel.java index 45ee1143a..dc17f177a 100644 --- a/app/src/main/java/com/seafile/seadroid2/ui/main/MainViewModel.java +++ b/app/src/main/java/com/seafile/seadroid2/ui/main/MainViewModel.java @@ -14,7 +14,6 @@ import com.seafile.seadroid2.R; import com.seafile.seadroid2.account.Account; import com.seafile.seadroid2.account.SupportAccountManager; -import com.seafile.seadroid2.enums.ActionModeCallbackType; import com.seafile.seadroid2.framework.data.db.entities.EncKeyCacheEntity; import com.seafile.seadroid2.framework.data.db.entities.FileTransferEntity; import com.seafile.seadroid2.framework.data.db.entities.PermissionEntity; @@ -28,7 +27,6 @@ import com.seafile.seadroid2.framework.datastore.DataManager; import com.seafile.seadroid2.framework.util.Utils; import com.seafile.seadroid2.framework.worker.ExistingFileStrategy; -import com.seafile.seadroid2.preferences.Settings; import com.seafile.seadroid2.ui.base.viewmodel.BaseViewModel; import com.seafile.seadroid2.context.NavContext; import com.seafile.seadroid2.framework.data.ServerInfo; @@ -42,7 +40,6 @@ import com.seafile.seadroid2.framework.http.HttpIO; import com.seafile.seadroid2.ui.activities.AllActivitiesFragment; import com.seafile.seadroid2.ui.repo.RepoQuickFragment; -import com.seafile.seadroid2.ui.settings.TabSettings2Fragment; import com.seafile.seadroid2.ui.settings.TabSettingsFragment; import com.seafile.seadroid2.ui.star.StarredQuickFragment; import com.seafile.seadroid2.framework.util.SLogs; @@ -56,7 +53,6 @@ import java.io.OutputStream; import java.nio.file.Files; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Optional; @@ -84,11 +80,6 @@ public class MainViewModel extends BaseViewModel { private final MutableLiveData OnNavChangeListenerLiveData = new MutableLiveData<>(); private final MutableLiveData _searchViewExpandedLiveData = new MutableLiveData<>(false); - private final MutableLiveData _onActionModeLiveData = new MutableLiveData<>(); - - public MutableLiveData getOnActionModeLiveData() { - return _onActionModeLiveData; - } public MutableLiveData getSearchViewExpandedLiveData() { return _searchViewExpandedLiveData; @@ -548,7 +539,7 @@ public void accept(FileTransferEntity transferEntity) throws Exception { } //start worker - BackgroundJobManagerImpl.getInstance().startFileUploadWorker(); + BackgroundJobManagerImpl.getInstance().startFileManualUploadWorker(); if (consumer != null) { consumer.accept(transferEntity); diff --git a/app/src/main/java/com/seafile/seadroid2/ui/media/image_preview2/CarouselImagePreviewActivity.java b/app/src/main/java/com/seafile/seadroid2/ui/media/image_preview2/CarouselImagePreviewActivity.java index e0a9b8c2e..892ef3839 100644 --- a/app/src/main/java/com/seafile/seadroid2/ui/media/image_preview2/CarouselImagePreviewActivity.java +++ b/app/src/main/java/com/seafile/seadroid2/ui/media/image_preview2/CarouselImagePreviewActivity.java @@ -227,9 +227,9 @@ private void initViewModel() { @Override public void onChanged(Boolean aBoolean) { if (aBoolean) { - showProgressDialog(); + showLoadingDialog(); } else { - dismissProgressDialog(); + dismissLoadingDialog(); } } }); diff --git a/app/src/main/java/com/seafile/seadroid2/ui/media/image_preview2/OnlyImagePreviewActivity.java b/app/src/main/java/com/seafile/seadroid2/ui/media/image_preview2/OnlyImagePreviewActivity.java index f10782d75..69e61df3d 100644 --- a/app/src/main/java/com/seafile/seadroid2/ui/media/image_preview2/OnlyImagePreviewActivity.java +++ b/app/src/main/java/com/seafile/seadroid2/ui/media/image_preview2/OnlyImagePreviewActivity.java @@ -3,39 +3,22 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; -import android.view.View; import androidx.activity.OnBackPressedCallback; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import androidx.lifecycle.Observer; -import androidx.viewpager2.widget.ViewPager2; import com.blankj.utilcode.util.BarUtils; import com.blankj.utilcode.util.CollectionUtils; -import com.blankj.utilcode.util.NetworkUtils; -import com.blankj.utilcode.util.ToastUtils; -import com.seafile.seadroid2.R; -import com.seafile.seadroid2.databinding.ActivityImagePreviewBinding; import com.seafile.seadroid2.databinding.ActivityOnlyImagePreviewBinding; -import com.seafile.seadroid2.framework.data.db.entities.DirentModel; -import com.seafile.seadroid2.framework.data.db.entities.RepoModel; -import com.seafile.seadroid2.framework.data.db.entities.StarredModel; -import com.seafile.seadroid2.framework.data.model.activities.ActivityModel; -import com.seafile.seadroid2.framework.data.model.search.SearchModel; -import com.seafile.seadroid2.framework.util.Objs; import com.seafile.seadroid2.ui.adapter.ViewPager2Adapter; import com.seafile.seadroid2.ui.base.BaseActivityWithVM; -import com.seafile.seadroid2.ui.dialog_fragment.DeleteFileDialogFragment; -import com.seafile.seadroid2.ui.dialog_fragment.listener.OnRefreshDataListener; import com.seafile.seadroid2.ui.media.image_preview.ImagePreviewViewModel; import com.seafile.seadroid2.ui.media.image_preview.PhotoFragment; import java.util.ArrayList; import java.util.List; -import java.util.Locale; - -import io.reactivex.functions.Consumer; public class OnlyImagePreviewActivity extends BaseActivityWithVM { private ActivityOnlyImagePreviewBinding binding; @@ -105,9 +88,9 @@ private void initViewModel() { @Override public void onChanged(Boolean aBoolean) { if (aBoolean) { - showProgressDialog(); + showLoadingDialog(); } else { - dismissProgressDialog(); + dismissLoadingDialog(); } } }); diff --git a/app/src/main/java/com/seafile/seadroid2/ui/repo/RepoQuickFragment.java b/app/src/main/java/com/seafile/seadroid2/ui/repo/RepoQuickFragment.java index 61d5d6148..29113b622 100644 --- a/app/src/main/java/com/seafile/seadroid2/ui/repo/RepoQuickFragment.java +++ b/app/src/main/java/com/seafile/seadroid2/ui/repo/RepoQuickFragment.java @@ -334,7 +334,7 @@ public void onChanged(Boolean aBoolean) { MainActivity mainActivity = (MainActivity) getActivity(); if (mainActivity != null) { - mainActivity.showProgressDialog(aBoolean); + mainActivity.showLoadingDialog(aBoolean); } } }); @@ -384,12 +384,6 @@ public void onChanged(String s) { } }); - mainViewModel.getOnActionModeLiveData().observe(getViewLifecycleOwner(), new Observer() { - @Override - public void onChanged(ActionModeCallbackType callbackType) { - onShowActionMode(callbackType); - } - }); searchViewModel.getSearchListLiveData().observe(getViewLifecycleOwner(), new Observer>() { @Override public void onChanged(List searchModels) { @@ -1161,13 +1155,7 @@ public boolean onCreateActionMode(ActionMode mode, Menu menu) { inflater.inflate(R.menu.repos_fragment_menu, menu); if (adapter == null) return true; - mainViewModel.getOnActionModeLiveData().setValue(ActionModeCallbackType.CREATE); - -// // to hidden "r" permissions files or folder -// if (!getNavContext().isParentHasWritePermission()) { -// menu.findItem(R.id.action_mode_delete).setVisible(false); -// menu.findItem(R.id.action_mode_move).setVisible(false); -// } + onShowActionMode(ActionModeCallbackType.CREATE); return true; } @@ -1202,14 +1190,14 @@ public boolean onActionItemClicked(ActionMode mode, MenuItem item) { if (itemId == R.id.action_mode_select_all) { adapter.setItemSelected(!allItemsSelected); - startOrUpdateContextualActionBar(); - if (!allItemsSelected) { - mainViewModel.getOnActionModeLiveData().setValue(ActionModeCallbackType.SELECT_ALL); + onShowActionMode(ActionModeCallbackType.SELECT_ALL); } else { - mainViewModel.getOnActionModeLiveData().setValue(ActionModeCallbackType.SELECT_NONE); + onShowActionMode(ActionModeCallbackType.SELECT_NONE); } + startOrUpdateContextualActionBar(); + allItemsSelected = !allItemsSelected; } @@ -1221,7 +1209,7 @@ public boolean onActionItemClicked(ActionMode mode, MenuItem item) { public void onDestroyActionMode(ActionMode mode) { if (adapter == null) return; - mainViewModel.getOnActionModeLiveData().setValue(ActionModeCallbackType.DESTORY); + onShowActionMode(ActionModeCallbackType.DESTORY); } } diff --git a/app/src/main/java/com/seafile/seadroid2/ui/settings/SettingsCameraBackupAdvanceFragment.java b/app/src/main/java/com/seafile/seadroid2/ui/settings/SettingsCameraBackupAdvanceFragment.java index de440bb9e..d90f17892 100644 --- a/app/src/main/java/com/seafile/seadroid2/ui/settings/SettingsCameraBackupAdvanceFragment.java +++ b/app/src/main/java/com/seafile/seadroid2/ui/settings/SettingsCameraBackupAdvanceFragment.java @@ -81,7 +81,7 @@ public boolean onPreferenceChange(@NonNull Preference preference, Object newValu boolean isCustom = (Boolean) newValue; AlbumBackupManager.writeAllowDataPlanSwitch(isCustom); - BackgroundJobManagerImpl.getInstance().startMediaChainWorker(isCustom); + BackgroundJobManagerImpl.getInstance().startMediaWorkerChain(isCustom); return true; } @@ -98,7 +98,7 @@ public boolean onPreferenceChange(@NonNull Preference preference, Object newValu boolean isCustom = (Boolean) newValue; AlbumBackupManager.writeAllowVideoSwitch(isCustom); - BackgroundJobManagerImpl.getInstance().startMediaChainWorker(isCustom); + BackgroundJobManagerImpl.getInstance().startMediaWorkerChain(isCustom); return true; } @@ -146,7 +146,7 @@ private void scanCustomDirs(boolean isCustomScanOn) { List selectedBuckets = new ArrayList<>(); AlbumBackupManager.writeBucketIds(selectedBuckets); - BackgroundJobManagerImpl.getInstance().startMediaChainWorker(false); + BackgroundJobManagerImpl.getInstance().startMediaWorkerChain(false); refreshPreferenceView(); } @@ -193,7 +193,7 @@ public void onActivityResult(ActivityResult o) { return; } - BackgroundJobManagerImpl.getInstance().startMediaChainWorker(true); + BackgroundJobManagerImpl.getInstance().startMediaWorkerChain(true); refreshPreferenceView(); } diff --git a/app/src/main/java/com/seafile/seadroid2/ui/settings/SettingsFragment.java b/app/src/main/java/com/seafile/seadroid2/ui/settings/SettingsFragment.java index 4c55a7d97..133f635e8 100644 --- a/app/src/main/java/com/seafile/seadroid2/ui/settings/SettingsFragment.java +++ b/app/src/main/java/com/seafile/seadroid2/ui/settings/SettingsFragment.java @@ -629,7 +629,7 @@ public void onFragmentResult(@NonNull String requestKey, @NonNull Bundle result) refreshFolderBackNetworkMode(which); //restart - BackgroundJobManagerImpl.getInstance().startFolderChainWorker(true); + BackgroundJobManagerImpl.getInstance().startFolderAutoBackupWorkerChain(true); } }); @@ -716,10 +716,10 @@ private void setCameraPreferencesVisible(boolean isChecked) { private void switchCameraWorker(boolean isChecked) { if (isChecked) { CameraUploadManager.getInstance().setCameraAccount(currentAccount); - BackgroundJobManagerImpl.getInstance().startMediaChainWorker(true); + BackgroundJobManagerImpl.getInstance().startMediaWorkerChain(true); } else { CameraUploadManager.getInstance().disableCameraUpload(); - BackgroundJobManagerImpl.getInstance().cancelAllMediaWorker(); + BackgroundJobManagerImpl.getInstance().cancelMediaWorker(); } } @@ -733,7 +733,7 @@ private void refreshFolderBackupView(boolean isSync) { setFolderPreferencesVisible(isFolderAutomaticBackup); if (!isFolderAutomaticBackup) { - BackgroundJobManagerImpl.getInstance().cancelAllFolderUploadWorker(); + BackgroundJobManagerImpl.getInstance().cancelFolderAutoUploadWorker(); if (fileSyncService != null) { // fileSyncService.stopFolderMonitor(); } @@ -759,7 +759,7 @@ private void refreshFolderBackupView(boolean isSync) { // fileSyncService.startFolderMonitor(); } - BackgroundJobManagerImpl.getInstance().startFolderChainWorker(true); + BackgroundJobManagerImpl.getInstance().startFolderAutoBackupWorkerChain(true); } } diff --git a/app/src/main/java/com/seafile/seadroid2/ui/settings/TabSettings2Fragment.java b/app/src/main/java/com/seafile/seadroid2/ui/settings/TabSettings2Fragment.java index dc14d3df1..750207e43 100644 --- a/app/src/main/java/com/seafile/seadroid2/ui/settings/TabSettings2Fragment.java +++ b/app/src/main/java/com/seafile/seadroid2/ui/settings/TabSettings2Fragment.java @@ -69,7 +69,6 @@ import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.Set; import rikka.preference.SimpleMenuPreference; @@ -774,7 +773,7 @@ private void dispatchFolderBackupWork(boolean isEnable) { if (!CollectionUtils.isEmpty(pathList) && repoConfig != null) { TransferBusHelper.startFileMonitor(); - BackgroundJobManagerImpl.getInstance().startFolderChainWorker(true); + BackgroundJobManagerImpl.getInstance().startFolderAutoBackupWorkerChain(true); } } @@ -866,7 +865,7 @@ public void onActivityResult(ActivityResult o) { updateAlbumBackupSelectedRepoSummary(); - BackgroundJobManagerImpl.getInstance().startMediaChainWorker(true); + BackgroundJobManagerImpl.getInstance().startMediaWorkerChain(true); } }); diff --git a/app/src/main/java/com/seafile/seadroid2/ui/settings/TabSettingsFragment.java b/app/src/main/java/com/seafile/seadroid2/ui/settings/TabSettingsFragment.java index e312a1c18..9e8f251e2 100644 --- a/app/src/main/java/com/seafile/seadroid2/ui/settings/TabSettingsFragment.java +++ b/app/src/main/java/com/seafile/seadroid2/ui/settings/TabSettingsFragment.java @@ -765,7 +765,7 @@ private void dispatchFolderBackupWork(boolean isEnable) { if (!CollectionUtils.isEmpty(pathList) && repoConfig != null) { TransferBusHelper.startFileMonitor(); - BackgroundJobManagerImpl.getInstance().startFolderChainWorker(true); + BackgroundJobManagerImpl.getInstance().startFolderAutoBackupWorkerChain(true); } } @@ -869,7 +869,7 @@ public void onActivityResult(ActivityResult o) { updateAlbumBackupSelectedRepoSummary(); - BackgroundJobManagerImpl.getInstance().startMediaChainWorker(true); + BackgroundJobManagerImpl.getInstance().startMediaWorkerChain(true); } }); diff --git a/app/src/main/java/com/seafile/seadroid2/ui/share/ShareToSeafileViewModel.java b/app/src/main/java/com/seafile/seadroid2/ui/share/ShareToSeafileViewModel.java index f684fe058..b210b3869 100644 --- a/app/src/main/java/com/seafile/seadroid2/ui/share/ShareToSeafileViewModel.java +++ b/app/src/main/java/com/seafile/seadroid2/ui/share/ShareToSeafileViewModel.java @@ -164,7 +164,7 @@ public void subscribe(SingleEmitter emitter) throws Exception { addSingleDisposable(booleanSingle, new Consumer() { @Override public void accept(Boolean aBoolean) throws Exception { - BackgroundJobManagerImpl.getInstance().startFileUploadWorker(); + BackgroundJobManagerImpl.getInstance().startFileManualUploadWorker(); getActionLiveData().setValue(true); } diff --git a/app/src/main/java/com/seafile/seadroid2/ui/transfer_list/DownloadListFragment.java b/app/src/main/java/com/seafile/seadroid2/ui/transfer_list/DownloadListFragment.java index 9d26702e8..6a91cb01e 100644 --- a/app/src/main/java/com/seafile/seadroid2/ui/transfer_list/DownloadListFragment.java +++ b/app/src/main/java/com/seafile/seadroid2/ui/transfer_list/DownloadListFragment.java @@ -11,9 +11,11 @@ import androidx.work.Data; import androidx.work.WorkInfo; +import com.blankj.utilcode.util.CollectionUtils; import com.blankj.utilcode.util.ToastUtils; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.seafile.seadroid2.R; +import com.seafile.seadroid2.enums.TransferStatus; import com.seafile.seadroid2.framework.data.db.entities.FileTransferEntity; import com.seafile.seadroid2.enums.TransferAction; import com.seafile.seadroid2.enums.TransferDataSource; @@ -124,37 +126,58 @@ public void deleteSelectedItems(List list) { } private void showDeleteConfirmDialog(List list) { - showConfirmDialog(new DialogInterface.OnClickListener() { + if (CollectionUtils.isEmpty(list)) { + return; + } + + MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(requireContext()); + builder.setTitle(R.string.delete_records); + + String deleteFile = getString(R.string.delete_local_file_sametime); + CharSequence[] sequences = new CharSequence[1]; + sequences[0] = deleteFile; + boolean[] booleans = new boolean[1]; + booleans[0] = true; + builder.setMultiChoiceItems(sequences, booleans, new DialogInterface.OnMultiChoiceClickListener() { + @Override + public void onClick(DialogInterface dialog, int which, boolean isChecked) { + booleans[which] = isChecked; + } + }); + + builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { + doDeleteSelectedItem(list, booleans[0]); + dialog.dismiss(); + } + }); - BackgroundJobManagerImpl.getInstance().cancelDownloadWorker(); + builder.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss()); + builder.show(); + } - getViewModel().removeSpecialDownloadListTask(list, new Consumer() { - @Override - public void accept(Boolean aBoolean) throws Exception { + private void doDeleteSelectedItem(List list, boolean isDeleteLocalFile) { + getViewModel().getShowLoadingDialogLiveData().setValue(true); - BackgroundJobManagerImpl.getInstance().startDownloadChainWorker(); + BackgroundJobManagerImpl.getInstance().cancelDownloadWorker(); - ToastUtils.showLong(R.string.deleted); + getViewModel().removeSpecialDownloadListTask(list, new Consumer() { + @Override + public void accept(Boolean aBoolean) { - dialog.dismiss(); + BackgroundJobManagerImpl.getInstance().startDownloadChainWorker(); - refreshData(); - } - }); - } - }); - } + //You never know which item a user will select, so we need to remove them one by one, and then resort. + for (FileTransferEntity fileTransferEntity : list) { + removeSpecialEntity(fileTransferEntity.uid); + } - private void showConfirmDialog(DialogInterface.OnClickListener listener) { - MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(getContext()); - builder.setTitle(R.string.delete); - builder.setMessage(R.string.delete_records_and_file); - builder.setPositiveButton(R.string.ok, listener); + getViewModel().getShowLoadingDialogLiveData().setValue(false); - builder.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss()); - builder.show(); + ToastUtils.showLong(R.string.deleted); + } + }); } @Override @@ -163,18 +186,9 @@ public void restartSelectedItems(List list) { @Override public void accept(Boolean aBoolean) throws Exception { ToastUtils.showLong(R.string.transfer_list_restart_all); - } - }); - - getViewModel().restartUpload(list, new Consumer() { - @Override - public void accept(Boolean aBoolean) throws Exception { - - // BackgroundJobManagerImpl.getInstance().startDownloadChainWorker(); } }); - } /** @@ -197,10 +211,24 @@ public void accept(Boolean aBoolean) throws Exception { * remove all download tasks */ public void removeAllTasks() { - showConfirmDialog(new DialogInterface.OnClickListener() { + MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(requireContext()); + builder.setTitle(R.string.delete_records); + + String deleteFile = getString(R.string.delete_local_file_sametime); + CharSequence[] sequences = new CharSequence[1]; + sequences[0] = deleteFile; + boolean[] booleans = new boolean[1]; + booleans[0] = true; + builder.setMultiChoiceItems(sequences, booleans, new DialogInterface.OnMultiChoiceClickListener() { @Override - public void onClick(DialogInterface dialog, int which) { + public void onClick(DialogInterface dialog, int which, boolean isChecked) { + booleans[which] = isChecked; + } + }); + builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { //cancel worker BackgroundJobManagerImpl.getInstance().cancelDownloadWorker(); @@ -211,10 +239,15 @@ public void accept(Boolean aBoolean) throws Exception { refreshData(); } - }); + }, booleans[0]); } }); + builder.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss()); + builder.show(); + + } + } diff --git a/app/src/main/java/com/seafile/seadroid2/ui/transfer_list/TransferActivity.java b/app/src/main/java/com/seafile/seadroid2/ui/transfer_list/TransferActivity.java index a9da3e19b..0a8cfddc8 100644 --- a/app/src/main/java/com/seafile/seadroid2/ui/transfer_list/TransferActivity.java +++ b/app/src/main/java/com/seafile/seadroid2/ui/transfer_list/TransferActivity.java @@ -18,6 +18,8 @@ import com.google.android.material.tabs.TabLayoutMediator; import com.seafile.seadroid2.R; import com.seafile.seadroid2.databinding.TransferListLayoutBinding; +import com.seafile.seadroid2.enums.TransferAction; +import com.seafile.seadroid2.enums.TransferStatus; import com.seafile.seadroid2.framework.notification.base.NotificationUtils; import com.seafile.seadroid2.ui.adapter.ViewPager2Adapter; import com.seafile.seadroid2.ui.base.BaseActivity; @@ -191,6 +193,19 @@ public boolean onMenuItemClick(MenuItem item) { getUploadFragment().removeAllTasks(); } } +// else if (item.getItemId() == R.id.retry_all_cancelled_transfer_tasks) { +// if (whichTab == 0) { +// getDownloadFragment().restartAllSpecialStatusTasks(TransferAction.DOWNLOAD, TransferStatus.CANCELLED); +// } else { +// getUploadFragment().restartAllSpecialStatusTasks(TransferAction.UPLOAD, TransferStatus.CANCELLED); +// } +// } else if (item.getItemId() == R.id.retry_all_cancelled_transfer_tasks) { +// if (whichTab == 0) { +// getDownloadFragment().restartAllSpecialStatusTasks(TransferAction.DOWNLOAD, TransferStatus.FAILED); +// } else { +// getUploadFragment().restartAllSpecialStatusTasks(TransferAction.UPLOAD, TransferStatus.FAILED); +// } +// } return super.onOptionsItemSelected(item); } diff --git a/app/src/main/java/com/seafile/seadroid2/ui/transfer_list/TransferListFragment.java b/app/src/main/java/com/seafile/seadroid2/ui/transfer_list/TransferListFragment.java index bc1dbb4ae..4cb504e6e 100644 --- a/app/src/main/java/com/seafile/seadroid2/ui/transfer_list/TransferListFragment.java +++ b/app/src/main/java/com/seafile/seadroid2/ui/transfer_list/TransferListFragment.java @@ -52,10 +52,14 @@ public abstract class TransferListFragment extends BaseFragment { protected TransferActivity activity = null; private LinearLayoutManager layoutManager; private TransferListViewModel viewModel; + + /** + * key is uid, value is position + */ private final ConcurrentHashMap positionMap = new ConcurrentHashMap<>(); private int pageIndex = 0; - private final int pageSize = 10; + private final int pageSize = 100; private QuickAdapterHelper helper; @Override @@ -178,6 +182,12 @@ public boolean isAllowLoading() { private void initViewModel() { getViewModel().getRefreshLiveData().observe(getViewLifecycleOwner(), aBoolean -> binding.swipeRefreshLayout.setRefreshing(aBoolean)); + getViewModel().getShowLoadingDialogLiveData().observe(getViewLifecycleOwner(), new Observer() { + @Override + public void onChanged(Boolean aBoolean) { + showLoadingDialog(aBoolean); + } + }); getViewModel().getTransferListLiveData().observe(getViewLifecycleOwner(), new Observer>() { @Override @@ -191,6 +201,7 @@ private void submitData(List list) { if (CollectionUtils.isEmpty(list)) { if (pageIndex <= 1) { adapter.setStateViewEnable(true); + adapter.submitList(null); } return; } @@ -243,31 +254,45 @@ public void showBottomSheet(FileTransferEntity entity) { } protected void onBottomSheetFileDelete(FileTransferEntity entity) { - showDeleteConfirmDialog(entity); + if (TransferAction.DOWNLOAD == getTransferAction()) { + showDeleteDownloadConfirmDialog(entity); + } else { + showDeleteUploadConfirmDialog(entity); + } } - private void showDeleteConfirmDialog(FileTransferEntity entity) { - MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(getContext()); - builder.setTitle(R.string.delete); + private void showDeleteDownloadConfirmDialog(FileTransferEntity entity) { + MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(requireContext()); + builder.setTitle(R.string.delete_records); - if (getTransferAction() == TransferAction.DOWNLOAD) { - builder.setMessage(R.string.delete_records_and_file); - } else {//do not delete file when upload - builder.setMessage(R.string.delete_records); - } + String deleteFile = getString(R.string.delete_local_file_sametime); + CharSequence[] sequences = new CharSequence[1]; + sequences[0] = deleteFile; + boolean[] booleans = new boolean[1]; + booleans[0] = true; + builder.setMultiChoiceItems(sequences, booleans, new DialogInterface.OnMultiChoiceClickListener() { + @Override + public void onClick(DialogInterface dialog, int which, boolean isChecked) { + booleans[which] = isChecked; + } + }); builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - getViewModel().deleteTransferData(entity, getTransferAction(), new Consumer() { + getViewModel().getShowLoadingDialogLiveData().setValue(true); + + getViewModel().deleteTransferData(entity, booleans[0], getTransferAction(), new Consumer() { @Override public void accept(Boolean aBoolean) throws Exception { ToastUtils.showLong(R.string.deleted); - dialog.dismiss(); - refreshData(); + removeSpecialEntity(entity.uid); + + getViewModel().getShowLoadingDialogLiveData().setValue(false); } }); + dialog.dismiss(); } }); @@ -275,6 +300,63 @@ public void accept(Boolean aBoolean) throws Exception { builder.show(); } + private void showDeleteUploadConfirmDialog(FileTransferEntity entity) { + MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(requireContext()); + builder.setTitle(R.string.delete_records); + + builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + getViewModel().getShowLoadingDialogLiveData().setValue(true); + + getViewModel().deleteTransferData(entity, false, getTransferAction(), new Consumer() { + @Override + public void accept(Boolean aBoolean) throws Exception { + ToastUtils.showLong(R.string.deleted); + + removeSpecialEntity(entity.uid); + + getViewModel().getShowLoadingDialogLiveData().setValue(false); + } + }); + dialog.dismiss(); + } + }); + + builder.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss()); + builder.show(); + } + + public void restartAllSpecialStatusTasks(TransferAction transferAction, TransferStatus transferStatus) { + getViewModel().restartSpecialStatusTask(transferAction, transferStatus, new Consumer() { + @Override + public void accept(Boolean aBoolean) { + if (aBoolean) { + if (TransferAction.DOWNLOAD == transferAction) { + // + BackgroundJobManagerImpl.getInstance().cancelDownloadWorker(); + + // + BackgroundJobManagerImpl.getInstance().startDownloadChainWorker(); + } else { + + // + BackgroundJobManagerImpl.getInstance().cancelMediaWorker(); + BackgroundJobManagerImpl.getInstance().cancelFolderAutoUploadWorker(); + BackgroundJobManagerImpl.getInstance().cancelFileManualUploadWorker(); + + // + BackgroundJobManagerImpl.getInstance().startMediaWorkerChain(false); + BackgroundJobManagerImpl.getInstance().startFolderAutoBackupWorkerChain(false); + BackgroundJobManagerImpl.getInstance().startFileManualUploadWorker(); + } + } else { + ToastUtils.showLong(R.string.done); + } + } + }); + } + private void toggleAdapterItemSelectedOnLongClick(int i) { //action mode on if (!adapter.getActionMode()) { @@ -287,19 +369,39 @@ private void toggleAdapterItemSelectedOnLongClick(int i) { adapter.notifyItemChanged(i); } - public void startContextualActionMode() { - if (actionMode == null) { - // start the actionMode - actionMode = activity.startSupportActionMode(new ActionModeCallback()); - } - } - public abstract TransferAction getTransferAction(); public abstract void deleteSelectedItems(List list); public abstract void restartSelectedItems(List list); + public ConcurrentHashMap getPositionMap() { + return positionMap; + } + + protected void removeSpecialEntity(String uid) { + Integer integer = positionMap.get(uid); + if (integer == null) { + return; + } + + adapter.notifyItemRemoved(integer); + adapter.getItems().remove(integer.intValue()); + + resort(); + } + + protected void resort() { + // + positionMap.clear(); + + + List list = adapter.getItems(); + for (int i = 0; i < list.size(); i++) { + positionMap.put(list.get(i).uid, i); + } + } + protected void refreshData() { pageIndex = 0; loadNext(true); @@ -373,6 +475,14 @@ public void cancelSelectItems() { } } + + public void startContextualActionMode() { + if (actionMode == null) { + // start the actionMode + actionMode = activity.startSupportActionMode(new ActionModeCallback()); + } + } + public ActionMode getActionMode() { return actionMode; } diff --git a/app/src/main/java/com/seafile/seadroid2/ui/transfer_list/TransferListViewModel.java b/app/src/main/java/com/seafile/seadroid2/ui/transfer_list/TransferListViewModel.java index 86d7b7bd7..249878607 100644 --- a/app/src/main/java/com/seafile/seadroid2/ui/transfer_list/TransferListViewModel.java +++ b/app/src/main/java/com/seafile/seadroid2/ui/transfer_list/TransferListViewModel.java @@ -78,7 +78,7 @@ public void loadData(TransferAction transferAction, int pageIndex, int pageSize, } - public void deleteTransferData(FileTransferEntity fileTransferEntity, TransferAction transferAction, Consumer consumer) { + public void deleteTransferData(FileTransferEntity fileTransferEntity, boolean isDeleteLocalFile, TransferAction transferAction, Consumer consumer) { Single single = Single.create(new SingleOnSubscribe() { @Override @@ -89,7 +89,9 @@ public void subscribe(SingleEmitter emitter) throws Exception { BackgroundJobManagerImpl.getInstance().cancelDownloadWorker(); } - FileUtils.delete(fileTransferEntity.target_path); + if (isDeleteLocalFile) { + FileUtils.delete(fileTransferEntity.target_path); + } AppDatabase.getInstance().fileTransferDAO().deleteOne(fileTransferEntity); @@ -104,7 +106,7 @@ public void subscribe(SingleEmitter emitter) throws Exception { AppDatabase.getInstance().fileTransferDAO().deleteOne(fileTransferEntity); FileUtils.delete(fileTransferEntity.full_path); - BackgroundJobManagerImpl.getInstance().startFileUploadWorker(); + BackgroundJobManagerImpl.getInstance().startFileManualUploadWorker(); } else if (TransferDataSource.FOLDER_BACKUP == fileTransferEntity.data_source) { // @@ -118,7 +120,7 @@ public void subscribe(SingleEmitter emitter) throws Exception { AppDatabase.getInstance().fileTransferDAO().update(fileTransferEntity); - BackgroundJobManagerImpl.getInstance().startFolderChainWorker(true); + BackgroundJobManagerImpl.getInstance().startFolderAutoBackupWorkerChain(true); } else if (TransferDataSource.ALBUM_BACKUP == fileTransferEntity.data_source) { BackgroundJobManagerImpl.getInstance().cancelById(UploadMediaFileAutomaticallyWorker.UID); @@ -131,7 +133,7 @@ public void subscribe(SingleEmitter emitter) throws Exception { AppDatabase.getInstance().fileTransferDAO().update(fileTransferEntity); - BackgroundJobManagerImpl.getInstance().startMediaChainWorker(true); + BackgroundJobManagerImpl.getInstance().startMediaWorkerChain(true); } emitter.onSuccess(true); } @@ -147,8 +149,8 @@ public void accept(Boolean aBoolean) throws Exception { public void cancelAllUploadTask(Consumer consumer) { Account account = SupportAccountManager.getInstance().getCurrentAccount(); - List dataSources = CollectionUtils.newArrayList(TransferDataSource.ALBUM_BACKUP, TransferDataSource.FOLDER_BACKUP); - Completable completable = AppDatabase.getInstance().fileTransferDAO().cancelByDataSource(account.getSignature(), dataSources); + List dataSources = CollectionUtils.newArrayList(TransferDataSource.ALBUM_BACKUP, TransferDataSource.FILE_BACKUP, TransferDataSource.FOLDER_BACKUP); + Completable completable = AppDatabase.getInstance().fileTransferDAO().cancelAllByDataSource(account.getSignature(), dataSources); addCompletableDisposable(completable, new Action() { @Override public void run() throws Exception { @@ -164,7 +166,7 @@ public void cancelAllDownloadTask(Consumer consumer) { } List dataSources = CollectionUtils.newArrayList(TransferDataSource.DOWNLOAD); - Completable completable = AppDatabase.getInstance().fileTransferDAO().cancelByDataSource(account.getSignature(), dataSources); + Completable completable = AppDatabase.getInstance().fileTransferDAO().cancelAllByDataSource(account.getSignature(), dataSources); addCompletableDisposable(completable, new Action() { @Override public void run() throws Exception { @@ -173,7 +175,35 @@ public void run() throws Exception { }); } - public void removeAllDownloadTask(Consumer consumer) { + + public void removeSpecialDownloadListTask(List list, Consumer consumer) { + Single single = Single.create(new SingleOnSubscribe() { + @Override + public void subscribe(SingleEmitter emitter) throws Exception { + + for (FileTransferEntity entity : list) { + //delete record + AppDatabase.getInstance().fileTransferDAO().deleteOne(entity); + + FileUtils.delete(entity.target_path); + SLogs.d("deleted : " + entity.target_path); + } + + emitter.onSuccess(true); + } + }); + + addSingleDisposable(single, new Consumer() { + @Override + public void accept(Boolean aBoolean) throws Exception { + if (consumer != null) { + consumer.accept(true); + } + } + }); + } + + public void removeAllDownloadTask(Consumer consumer, boolean isDeleteLocalFile) { getRefreshLiveData().setValue(true); Account account = SupportAccountManager.getInstance().getCurrentAccount(); @@ -183,25 +213,24 @@ public void removeAllDownloadTask(Consumer consumer) { } List features = CollectionUtils.newArrayList(TransferDataSource.DOWNLOAD); + //query all data, including deleted data, based on different users Single> single = AppDatabase.getInstance().fileTransferDAO().getListByDataSourceAsync(account.getSignature(), features); Single single1 = single.flatMap(new Function, SingleSource>() { @Override - public SingleSource apply(List entities) throws Exception { + public SingleSource apply(List transferList) throws Exception { return Single.create(new SingleOnSubscribe() { @Override public void subscribe(SingleEmitter emitter) throws Exception { - - AppDatabase.getInstance().fileTransferDAO().deleteAllByAction(account.getSignature(), TransferAction.DOWNLOAD); - - for (FileTransferEntity entity : entities) { - //delete record - if (entity.transfer_action == TransferAction.DOWNLOAD) { + if (isDeleteLocalFile) { + for (FileTransferEntity entity : transferList) { FileUtils.delete(entity.target_path); SLogs.d("deleted : " + entity.target_path); } } + AppDatabase.getInstance().fileTransferDAO().deleteAllByAction(account.getSignature(), TransferAction.DOWNLOAD); + emitter.onSuccess(true); } }); @@ -225,11 +254,11 @@ public void subscribe(SingleEmitter emitter) throws Exception { for (FileTransferEntity entity : list) { entity.data_status = -1; - entity.transfer_result = TransferResult.NO_RESULT; entity.transfer_status = TransferStatus.CANCELLED; + entity.transfer_result = TransferResult.USER_CANCELLED; entity.transferred_size = 0; - AppDatabase.getInstance().fileTransferDAO().insert(entity); + AppDatabase.getInstance().fileTransferDAO().update(entity); } emitter.onSuccess(true); @@ -246,55 +275,60 @@ public void accept(Boolean aBoolean) throws Exception { }); } - public void removeSpecialDownloadListTask(List list, Consumer consumer) { - Single single = Single.create(new SingleOnSubscribe() { - @Override - public void subscribe(SingleEmitter emitter) throws Exception { - - for (FileTransferEntity entity : list) { - //delete record - AppDatabase.getInstance().fileTransferDAO().deleteOne(entity); - - FileUtils.delete(entity.target_path); - SLogs.d("deleted : " + entity.target_path); - } + public void removeAllUploadTask(Consumer consumer) { + getShowLoadingDialogLiveData().setValue(true); - emitter.onSuccess(true); - } - }); + Account account = SupportAccountManager.getInstance().getCurrentAccount(); - addSingleDisposable(single, new Consumer() { + Completable completable = AppDatabase.getInstance().fileTransferDAO().removeAllUploadByAccount(account.getSignature()); + addCompletableDisposable(completable, new Action() { @Override - public void accept(Boolean aBoolean) throws Exception { + public void run() throws Exception { if (consumer != null) { consumer.accept(true); } + + getShowLoadingDialogLiveData().setValue(false); } }); + } - public void removeAllUploadTask(Consumer consumer) { - getRefreshLiveData().setValue(true); + public void restartSpecialStatusTask(TransferAction transferAction, TransferStatus transferStatus, Consumer consumer) { + getShowLoadingDialogLiveData().setValue(true); Account account = SupportAccountManager.getInstance().getCurrentAccount(); - List features = CollectionUtils.newArrayList(TransferDataSource.FILE_BACKUP, TransferDataSource.FOLDER_BACKUP); - Single> single = AppDatabase.getInstance().fileTransferDAO().getListByDataSourceAsync(account.getSignature(), features); + if (account == null) { + getShowLoadingDialogLiveData().setValue(false); + return; + } + Single> single = AppDatabase.getInstance().fileTransferDAO().getByActionAndStatusAsync(account.getSignature(), transferAction, transferStatus); Single single1 = single.flatMap(new Function, SingleSource>() { @Override - public SingleSource apply(List entities) throws Exception { + public SingleSource apply(List list) throws Exception { + + if (CollectionUtils.isEmpty(list)) { + return Single.just(false); + } + return Single.create(new SingleOnSubscribe() { @Override public void subscribe(SingleEmitter emitter) throws Exception { - AppDatabase.getInstance().fileTransferDAO().cancelAllWithFileBackup(); - for (FileTransferEntity entity : entities) { - if (entity.transfer_action == TransferAction.DOWNLOAD) { + for (FileTransferEntity entity : list) { + if (transferAction == TransferAction.DOWNLOAD) { FileUtils.delete(entity.target_path); SLogs.d("deleted : " + entity.target_path); } - } + entity.transfer_status = TransferStatus.WAITING; + entity.transfer_result = TransferResult.NO_RESULT; + entity.transferred_size = 0; + entity.action_end_at = 0; + + AppDatabase.getInstance().fileTransferDAO().update(entity); + } emitter.onSuccess(true); } }); @@ -303,12 +337,14 @@ public void subscribe(SingleEmitter emitter) throws Exception { addSingleDisposable(single1, new Consumer() { @Override - public void accept(Boolean b) throws Exception { + public void accept(Boolean aBoolean) throws Exception { if (consumer != null) { - consumer.accept(true); + consumer.accept(aBoolean); } + getShowLoadingDialogLiveData().setValue(false); } }); + } public void restartUpload(List list, Consumer consumer) { diff --git a/app/src/main/java/com/seafile/seadroid2/ui/transfer_list/UploadListFragment.java b/app/src/main/java/com/seafile/seadroid2/ui/transfer_list/UploadListFragment.java index 782a97af9..a8961ecc3 100644 --- a/app/src/main/java/com/seafile/seadroid2/ui/transfer_list/UploadListFragment.java +++ b/app/src/main/java/com/seafile/seadroid2/ui/transfer_list/UploadListFragment.java @@ -14,6 +14,7 @@ import com.blankj.utilcode.util.ToastUtils; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.seafile.seadroid2.R; +import com.seafile.seadroid2.enums.TransferStatus; import com.seafile.seadroid2.framework.data.db.entities.FileTransferEntity; import com.seafile.seadroid2.enums.TransferAction; import com.seafile.seadroid2.enums.TransferDataSource; @@ -148,7 +149,7 @@ public void deleteSelectedItems(List list) { @Override public void onClick(DialogInterface dialog, int which) { - BackgroundJobManagerImpl.getInstance().cancelAllFolderUploadWorker(); + BackgroundJobManagerImpl.getInstance().cancelFolderAutoUploadWorker(); getViewModel().removeSpecialUploadListTask(list, new Consumer() { @Override @@ -156,13 +157,18 @@ public void accept(Boolean aBoolean) throws Exception { //todo 检查此处逻辑 // BackgroundJobManagerImpl.getInstance().startFolderUploadWorker(); - ToastUtils.showLong(R.string.deleted); + //You never know which item a user will select, so we need to remove them one by one, and then resort. + for (FileTransferEntity fileTransferEntity : list) { + removeSpecialEntity(fileTransferEntity.uid); + } - dialog.dismiss(); + getViewModel().getShowLoadingDialogLiveData().setValue(false); - refreshData(); + ToastUtils.showLong(R.string.deleted); } }); + + dialog.dismiss(); } }); } @@ -175,8 +181,8 @@ public void restartSelectedItems(List list) { public void accept(Boolean aBoolean) throws Exception { //todo 检查此处逻辑 - BackgroundJobManagerImpl.getInstance().startFolderChainWorker(true); - BackgroundJobManagerImpl.getInstance().startMediaChainWorker(true); + BackgroundJobManagerImpl.getInstance().startFolderAutoBackupWorkerChain(true); + BackgroundJobManagerImpl.getInstance().startMediaWorkerChain(true); } }); } @@ -186,8 +192,8 @@ public void accept(Boolean aBoolean) throws Exception { */ public void cancelAllTasks() { - BackgroundJobManagerImpl.getInstance().cancelAllFolderUploadWorker(); - BackgroundJobManagerImpl.getInstance().cancelAllMediaWorker(); + BackgroundJobManagerImpl.getInstance().cancelFolderAutoUploadWorker(); + BackgroundJobManagerImpl.getInstance().cancelMediaWorker(); getViewModel().cancelAllUploadTask(new Consumer() { @Override @@ -204,12 +210,11 @@ public void accept(Boolean aBoolean) throws Exception { * remove all download tasks */ public void removeAllTasks() { - //todo showConfirmDialog(new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // - BackgroundJobManagerImpl.getInstance().cancelAllFolderUploadWorker(); + BackgroundJobManagerImpl.getInstance().cancelFolderAutoUploadWorker(); // getViewModel().removeAllUploadTask(new Consumer() { @@ -226,7 +231,7 @@ public void accept(Boolean aBoolean) throws Exception { } private void showConfirmDialog(DialogInterface.OnClickListener listener) { - MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(getContext()); + MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(requireContext()); builder.setTitle(R.string.delete); builder.setMessage(R.string.delete_records); builder.setPositiveButton(R.string.ok, listener); @@ -234,6 +239,5 @@ private void showConfirmDialog(DialogInterface.OnClickListener listener) { builder.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss()); builder.show(); } - } diff --git a/app/src/main/res/drawable/baseline_close_24.xml b/app/src/main/res/drawable/baseline_close_24.xml new file mode 100644 index 000000000..3d89fb7ce --- /dev/null +++ b/app/src/main/res/drawable/baseline_close_24.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/menu/transfer_list_menu.xml b/app/src/main/res/menu/transfer_list_menu.xml index 4896017d7..933d9c493 100644 --- a/app/src/main/res/menu/transfer_list_menu.xml +++ b/app/src/main/res/menu/transfer_list_menu.xml @@ -4,13 +4,30 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 89147d57a..ecb58f7e4 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -23,6 +23,7 @@ Переместить папку Удалить папку Имя + Сервер Адрес сервера Эл. почта или логин Пароль @@ -328,6 +329,8 @@ Далее Пропустить + + Режим отображения Резервное копирование контактов Включить резервное копирование контактов @@ -586,6 +589,8 @@ Загрузка Сеть недоступна Ошибка сети + Загрузка не удалась + нажмите, чтобы повторить попытку Необходим пароль. Пароль слишком слабый. @@ -671,7 +676,9 @@ На рассмотрении Завершено Устаревший + Теги Отметить как решенное Вы уверены, что хотите удалить этот элемент? + Отменено diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index fc458ddca..513603c66 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -445,11 +445,13 @@ Email: support@seafile.com
网络连接错误,请稍后重试! 取消所有任务 + 取消所有正在进行的文件传输任务;单击重新启动按钮时,它们将被恢复以继续传输文件。 重新开始 重试失败的任务 重试取消的任务 清除失败的任务 清除所有任务 + 删除所有传输记录;如果是下载,它将删除所有下载记录(可选:本地文件也是)。如果是上传,它只会删除上传记录,但以后不会重新上传相应的目标文件。 清除完成的任务 下载列表 上传列表 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 120fb9e62..aefc08de7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -466,11 +466,13 @@ Network connection error, please try again later! Cancel all tasks + Cancel all ongoing file transfer tasks; they will be restored to continue transferring files when the restart button is clicked. Restart Retry failed tasks Restart cancelled tasks Clear failed tasks Clear all tasks + Remove all transfer records; if it is a download, it will delete all download records (optionally: local files as well). If it is an upload, it will only delete the upload records, but the corresponding target files will not be re-uploaded in the future. Clear finished tasks Download List Upload List diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 3169e38d1..74bf4e2ad 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -72,6 +72,7 @@ @color/bar_background_color @color/bar_background_color +