Skip to content

Commit

Permalink
update transfer list page
Browse files Browse the repository at this point in the history
  • Loading branch information
zhwanng committed Jan 2, 2025
1 parent f6e5d8b commit fe11f28
Show file tree
Hide file tree
Showing 38 changed files with 481 additions and 292 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}
}
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ public enum TransferDataSource {
ALBUM_BACKUP,

/**
*
* (automatically)
* folder backup
*/
FOLDER_BACKUP,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public interface FileTransferDAO {
@Delete
void deleteOne(FileTransferEntity entity);

@Delete
void deleteMultiple(List<FileTransferEntity> entity);

@Delete
Single<Integer> deleteOneAsync(FileTransferEntity entity);

Expand All @@ -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<TransferDataSource> 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<TransferDataSource> 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<List<FileTransferEntity>> getListByDataSourceAsync(String related_account, List<TransferDataSource> 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")
Expand All @@ -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<List<FileTransferEntity>> 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<FileTransferEntity> 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<FileTransferEntity> getOnePendingDownloadByActionSync(String related_account);
List<FileTransferEntity> 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<FileTransferEntity> 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<FileTransferEntity> 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<List<FileTransferEntity>> 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<FileTransferEntity> 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<List<FileTransferEntity>> 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<FileTransferEntity> getByTargetPathSync(String related_account, TransferAction transferAction, String target_path);


Expand All @@ -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<FileTransferEntity> getListByFullPathsSync(String repoId, List<String> 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<FileTransferEntity> 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<FileTransferEntity> 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<List<FileTransferEntity>> 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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ public class ContextModel {
* parent_dir + name
*/
public String full_path;
public String permission;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -142,7 +142,7 @@ private void onBusEvent(TransferOpType opType) {

resetFolderMonitor();

BackgroundJobManagerImpl.getInstance().cancelAllFolderUploadWorker();
BackgroundJobManagerImpl.getInstance().cancelFolderAutoUploadWorker();
}
}

Expand Down Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -158,16 +158,16 @@ private OneTimeWorkRequest getMediaUploadRequest() {
}

//cancel media
public void cancelAllMediaWorker() {
public void cancelMediaWorker() {
cancelById(UploadMediaFileAutomaticallyWorker.UID);
cancelById(MediaBackupScannerWorker.UID);
}

///////////////////
/// upload folder
///////////////////
public void startFolderChainWorker(boolean isForce) {
cancelAllFolderUploadWorker();
public void startFolderAutoBackupWorkerChain(boolean isForce) {
cancelFolderAutoUploadWorker();

OneTimeWorkRequest scanRequest = getFolderScanRequest(isForce);
OneTimeWorkRequest uploadRequest = getFolderUploadRequest();
Expand Down Expand Up @@ -213,15 +213,15 @@ private OneTimeWorkRequest getFolderUploadRequest() {
.build();
}

public void cancelAllFolderUploadWorker() {
public void cancelFolderAutoUploadWorker() {
cancelById(FolderBackupScannerWorker.UID);
cancelById(UploadFolderFileAutomaticallyWorker.UID);
}

///////////////////
/// upload file
///////////////////
public void startFileUploadWorker() {
public void startFileManualUploadWorker() {
String workerName = UploadFileManuallyWorker.class.getSimpleName();
OneTimeWorkRequest request = getFileUploadRequest();
getWorkManager().enqueueUniqueWork(workerName, ExistingWorkPolicy.KEEP, request);
Expand All @@ -233,6 +233,10 @@ private OneTimeWorkRequest getFileUploadRequest() {
.build();
}

public void cancelFileManualUploadWorker() {
cancelById(UploadFileManuallyWorker.UID);
}

///////////////////
/// download
///////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public Result doWork() {
List<FileTransferEntity> list = AppDatabase
.getInstance()
.fileTransferDAO()
.getOnePendingDownloadByActionSync(account.getSignature());
.getOnePendingDownloadByAccountSync(account.getSignature());
if (CollectionUtils.isEmpty(list)) {
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -150,9 +134,9 @@ private void initViewModel() {
@Override
public void onChanged(Boolean aBoolean) {
if (aBoolean) {
showProgressDialog();
showLoadingDialog();
} else {
dismissProgressDialog();
dismissLoadingDialog();
}
}
});
Expand Down Expand Up @@ -274,7 +258,7 @@ private void onLoggedIn(Account loginAccount) {

@Override
protected void onDestroy() {
dismissProgressDialog();
dismissLoadingDialog();
super.onDestroy();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -157,9 +155,9 @@ private void initViewModel() {
@Override
public void onChanged(Boolean aBoolean) {
if (aBoolean) {
showProgressDialog();
showLoadingDialog();
} else {
dismissProgressDialog();
dismissLoadingDialog();
}
}
});
Expand Down
Loading

0 comments on commit fe11f28

Please sign in to comment.