Skip to content

Commit

Permalink
Optimize the function of Google drive.
Browse files Browse the repository at this point in the history
  • Loading branch information
healergyl committed Jul 6, 2023
1 parent 2ee3168 commit 3f19408
Show file tree
Hide file tree
Showing 8 changed files with 197 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,25 @@ public void onSuccess(FileList fileList) {
list.add(fileList.getFiles().get(i));
}
}
removeDuplicate(list);
for (int j = 0; j < list.size(); j++) {
if (list.get(j).getName().contains(User.getInstance().getWalletAddress(mContext))) {
backupList.add(list.get(j));
if (!list.get(j).getName().startsWith("1")) {
mDriveServiceHelper.deleteFile(list.get(j).getId());
} else {
if (list.get(j).getName().contains(User.getInstance().getWalletAddress(mContext))) {
backupList.add(list.get(j));
}
}
}
if (backupList.size() == 0) {
createAddressFile();
} else if (backupList.size() == 1) {
mDriveServiceHelper.deleteFile(backupList.get(0).getId());
createAddressFile();
} else if (backupList.size() == 2) {
mDriveServiceHelper.deleteFile(backupList.get(0).getId());
mDriveServiceHelper.deleteFile(backupList.get(1).getId());
createAddressFile();
} else {
saveAddressFile(backupList.get(1).getId(), backupList.get(0).getId(), backupList.get(2).getId());
}
Expand Down Expand Up @@ -375,6 +387,21 @@ public void onSuccess(String s) {
}
}

/**
* @备注: 循环删除重复数据
* @description: Circular deletion of duplicate data
*/
public static void removeDuplicate(List<com.google.api.services.drive.model.File> list) {
for (int i = 0; i < list.size() - 1; i++) {
for (int j = list.size() - 1; j > i; j--) {
if (list.get(j).getName().equals(list.get(i).getName())) {
list.remove(j);
}
}
}
System.out.println(list);
}

@Override
protected void onDestroy() {
super.onDestroy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
import com.omni.wallet_mainnet.ui.activity.channel.ChannelsActivity;
import com.omni.wallet_mainnet.utils.CopyUtil;
import com.omni.wallet_mainnet.utils.DriveServiceHelper;
import com.omni.wallet_mainnet.utils.FilesUtils;
import com.omni.wallet_mainnet.utils.GetResourceUtil;
import com.omni.wallet_mainnet.utils.MoveCacheFileToFileObd;
import com.omni.wallet_mainnet.utils.TimeFormatUtil;
Expand All @@ -109,6 +110,7 @@
import java.text.DecimalFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -246,8 +248,16 @@ protected void initData() {
}
EventBus.getDefault().register(this);
if (User.getInstance().isBackUp(mContext) == true) {
mLoadingDialog.show();
showPageData();
String downloadDirectoryPath = mContext.getExternalFilesDir(null) + "/obd" + ConstantWithNetwork.getInstance(ConstantInOB.networkType).getDownloadDirectory();
long nowMillis = Calendar.getInstance().getTimeInMillis();
long fileHeaderLastEdit = FilesUtils.fileLastUpdate(downloadDirectoryPath + ConstantInOB.blockHeaderBin);
if (nowMillis - fileHeaderLastEdit > ConstantInOB.WEEK_MILLIS) {
DataStatusDialog mDataStatusDialog = new DataStatusDialog(mContext);
mDataStatusDialog.show();
} else {
mLoadingDialog.show();
showPageData();
}
}
if (User.getInstance().isNeutrinoDbChecked(mContext)) {
// TODO: 2023/5/31 暂定
Expand Down Expand Up @@ -1369,13 +1379,25 @@ public void onSuccess(FileList fileList) {
list.add(fileList.getFiles().get(i));
}
}
removeDuplicate(list);
for (int j = 0; j < list.size(); j++) {
if (list.get(j).getName().contains(User.getInstance().getWalletAddress(mContext))) {
backupList.add(list.get(j));
if (!list.get(j).getName().startsWith("1")) {
mDriveServiceHelper.deleteFile(list.get(j).getId());
} else {
if (list.get(j).getName().contains(User.getInstance().getWalletAddress(mContext))) {
backupList.add(list.get(j));
}
}
}
if (backupList.size() == 0) {
createAddressFile();
} else if (backupList.size() == 1) {
mDriveServiceHelper.deleteFile(backupList.get(0).getId());
createAddressFile();
} else if (backupList.size() == 2) {
mDriveServiceHelper.deleteFile(backupList.get(0).getId());
mDriveServiceHelper.deleteFile(backupList.get(1).getId());
createAddressFile();
} else {
saveAddressFile(backupList.get(1).getId(), backupList.get(0).getId(), backupList.get(2).getId());
}
Expand Down Expand Up @@ -1500,6 +1522,21 @@ public void onSuccess(String s) {
}
}

/**
* @备注: 循环删除重复数据
* @description: Circular deletion of duplicate data
*/
public static void removeDuplicate(List<com.google.api.services.drive.model.File> list) {
for (int i = 0; i < list.size() - 1; i++) {
for (int j = list.size() - 1; j > i; j--) {
if (list.get(j).getName().equals(list.get(i).getName())) {
list.remove(j);
}
}
}
System.out.println(list);
}

/**
* Start node
* 启动节点
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2232,13 +2232,25 @@ public void onSuccess(FileList fileList) {
list.add(fileList.getFiles().get(i));
}
}
removeDuplicateFile(list);
for (int j = 0; j < list.size(); j++) {
if (list.get(j).getName().contains(User.getInstance().getWalletAddress(mContext))) {
backupList.add(list.get(j));
if (!list.get(j).getName().startsWith("1")) {
mDriveServiceHelper.deleteFile(list.get(j).getId());
} else {
if (list.get(j).getName().contains(User.getInstance().getWalletAddress(mContext))) {
backupList.add(list.get(j));
}
}
}
if (backupList.size() == 0) {
createAddressFile();
} else if (backupList.size() == 1) {
mDriveServiceHelper.deleteFile(backupList.get(0).getId());
createAddressFile();
} else if (backupList.size() == 2) {
mDriveServiceHelper.deleteFile(backupList.get(0).getId());
mDriveServiceHelper.deleteFile(backupList.get(1).getId());
createAddressFile();
} else {
saveAddressFile(backupList.get(1).getId(), backupList.get(0).getId(), backupList.get(2).getId());
}
Expand Down Expand Up @@ -2363,6 +2375,21 @@ public void onSuccess(String s) {
}
}

/**
* @备注: 循环删除重复数据
* @description: Circular deletion of duplicate data
*/
public static void removeDuplicateFile(List<com.google.api.services.drive.model.File> list) {
for (int i = 0; i < list.size() - 1; i++) {
for (int j = list.size() - 1; j > i; j--) {
if (list.get(j).getName().equals(list.get(i).getName())) {
list.remove(j);
}
}
}
System.out.println(list);
}

@Override
protected void onDestroy() {
super.onDestroy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,18 +216,27 @@ public void clickStart() {
return;
}
LogUtils.e("==========list=========", list.toString());
List<com.google.api.services.drive.model.File> backupList = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
if (list.get(i).getName().contains(checkAddress)) {
backupList.add(list.get(i));
}
}
LogUtils.e("==========backupList=========", backupList.toString());
if (backupList.size() == 0) {
if (list.size() == 0) {
ToastUtils.showToast(mContext, "No backup files found.");
} else {
mLoadingDialog.show();
readAddressFile(backupList.get(1).getId(), backupList.get(0).getId(), backupList.get(2).getId());
removeDuplicateFile(list);
List<com.google.api.services.drive.model.File> backupList = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
if (!list.get(i).getName().contains(checkAddress)) {
mLoadingDialog.show();
readAddressFile(list.get(1).getId(), list.get(0).getId(), list.get(2).getId());
return;
} else {
backupList.add(list.get(i));
}
}
LogUtils.e("==========backupList=========", backupList.toString());
if (backupList.size() == 0) {
ToastUtils.showToast(mContext, "No backup files found.");
} else {
mLoadingDialog.show();
readAddressFile(backupList.get(1).getId(), backupList.get(0).getId(), backupList.get(2).getId());
}
}
} else if (tag == 2) {
// 本地恢复(Local restore)
Expand Down Expand Up @@ -346,6 +355,7 @@ public void onSuccess(FileList fileList) {
}
}
}
removeDuplicate(mData);
mAdapter.notifyDataSetChanged();
mGoogleDriveFileLayout.setVisibility(View.VISIBLE);
mLocalDirectoryFileLayout.setVisibility(View.GONE);
Expand Down Expand Up @@ -445,4 +455,34 @@ public void binaryToFile(byte[] bytes, String filePath) {
}
}
}

/**
* @备注: 循环删除重复数据
* @description: Circular deletion of duplicate data
*/
public static void removeDuplicate(List list) {
for (int i = 0; i < list.size() - 1; i++) {
for (int j = list.size() - 1; j > i; j--) {
if (list.get(j).equals(list.get(i))) {
list.remove(j);
}
}
}
System.out.println(list);
}

/**
* @备注: 循环删除重复数据
* @description: Circular deletion of duplicate data
*/
public static void removeDuplicateFile(List<com.google.api.services.drive.model.File> list) {
for (int i = 0; i < list.size() - 1; i++) {
for (int j = list.size() - 1; j > i; j--) {
if (list.get(j).getName().equals(list.get(i).getName())) {
list.remove(j);
}
}
}
System.out.println(list);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -673,13 +673,25 @@ public void onSuccess(FileList fileList) {
list.add(fileList.getFiles().get(i));
}
}
removeDuplicate(list);
for (int j = 0; j < list.size(); j++) {
if (list.get(j).getName().contains(User.getInstance().getWalletAddress(mContext))) {
backupList.add(list.get(j));
if (!list.get(j).getName().startsWith("1")) {
mDriveServiceHelper.deleteFile(list.get(j).getId());
} else {
if (list.get(j).getName().contains(User.getInstance().getWalletAddress(mContext))) {
backupList.add(list.get(j));
}
}
}
if (backupList.size() == 0) {
createAddressFile();
} else if (backupList.size() == 1) {
mDriveServiceHelper.deleteFile(backupList.get(0).getId());
createAddressFile();
} else if (backupList.size() == 2) {
mDriveServiceHelper.deleteFile(backupList.get(0).getId());
mDriveServiceHelper.deleteFile(backupList.get(1).getId());
createAddressFile();
} else {
saveAddressFile(backupList.get(1).getId(), backupList.get(0).getId(), backupList.get(2).getId());
}
Expand Down Expand Up @@ -804,6 +816,21 @@ public void onSuccess(String s) {
}
}

/**
* @备注: 循环删除重复数据
* @description: Circular deletion of duplicate data
*/
public static void removeDuplicate(List<com.google.api.services.drive.model.File> list) {
for (int i = 0; i < list.size() - 1; i++) {
for (int j = list.size() - 1; j > i; j--) {
if (list.get(j).getName().equals(list.get(i).getName())) {
list.remove(j);
}
}
}
System.out.println(list);
}

@Override
protected void onDestroy() {
super.onDestroy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ public Task<String> saveDbFile(String fileId, String filePath, String fileName)
});
}

public Task<Void> deleteFile(String fileId) {
return Tasks.call(mExecutor, () ->
mDriveService.files().delete(fileId).execute());
}

/**
* Returns a {@link FileList} containing all the visible files in the user's My Drive.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public void show() {
mAlertDialog = new AlertDialog.Builder(mContext, R.style.dialog_translucent_theme)
.setContentView(R.layout.layout_dialog_data_status)
.setAnimation(R.style.popup_anim_style)
.setCanceledOnTouchOutside(false)
.setCancelable(false)
.fullWidth()
.fullHeight()
.create();
Expand All @@ -65,7 +67,7 @@ public void show() {
mProgressBar = mAlertDialog.findViewById(R.id.progressbar);

if (User.getInstance().isNeutrinoDbChecked(mContext)) {
doExplainTv.setText(R.string.download_db);
doExplainTv.setText("(3/3)" + mContext.getString(R.string.download_db));
double percent = (100 / 100 * 100);
String percentString = String.format("%.2f", percent) + "%";
syncPercentView.setText(percentString);
Expand Down Expand Up @@ -238,7 +240,15 @@ public void getNeutrinoFile() {

@Subscribe(threadMode = ThreadMode.MAIN)
public void onDownloadEvent(DownloadEvent event) {
doExplainTv.setText(event.getFileName());
if (event.getFileName().equals(mContext.getString(R.string.download_header))){
doExplainTv.setText("(1/3)" + event.getFileName());
} else if (event.getFileName().equals(mContext.getString(R.string.download_filter_header))) {
doExplainTv.setText("(2/3)" + event.getFileName());
} else if (event.getFileName().equals(mContext.getString(R.string.download_db))) {
doExplainTv.setText("(3/3)" + event.getFileName());
} else {
doExplainTv.setText(event.getFileName());
}
double percent = (event.getCurrent() / event.getTotal() * 100);
String percentString = String.format("%.2f", percent) + "%";
syncPercentView.setText(percentString);
Expand Down
4 changes: 2 additions & 2 deletions config.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ ext {
targetSdkVersion: 28,
compileVersion : 28,
buildToolVersion: "28.0.3",
versionCode : 4,
versionName : "0.1.3"
versionCode : 5,
versionName : "0.1.4"
]
// 依赖相关版本控制
depVersion = [
Expand Down

0 comments on commit 3f19408

Please sign in to comment.