Skip to content

Commit

Permalink
Code optimization (#966)
Browse files Browse the repository at this point in the history
* Selecting a Backup Directory

* Add a folder backup module

* The backup upload information is added to Settings

* Update Select or cancel a backup folder

* Updating a backup folder

* Updated the folder backup

* Update backup folder

* update backup folder

* Updated folder backup and added global exception capture

* Updated the backup folder name

* Folder backup reconstruction

* Update folder backup

* Updated the backup folder name

* Update folder backup message notification

* Update the display of folder backup status

* Update folder backup

* Update folder backup

* Update the folder backup logic

* Update the display of folder backup status

* Updated the folder backup and photo sync display status logic

* Update backup folder FileAlterationMonitor

* Updated the folder backup interface

* Update folder backup observer

* Update the folder backup upload link

* Update the folder backup transfer tag

* Improve the code

- Fix an issue: When select the root of the repo, the file upload fails
- Rename variables, classes, functions to make them more readable
- Format the code for some classes
- Format some UI layout code

* Improve the code

- Rename variables, classes, functions to make them more readable

* Fix and optimize

- FIX an issue: When no folder or library is selected, a crash occurs
- Optimize UI layout

* Improve the code

- A bug found, TODO has been marked

* Improve the code

* remove the leakcanary lib

* upgrade app version

- gitignore file adds ignore rules

* Improvements, optimizations and fixes

- Optimize AccountManager Class, add proxy implementation
- Optimize the Adapter of the three pages on the home page
- format code
- Optimize the UI of the star page and recently modified page
- Unified image loading framework
- Modify some strings, layout, dimens

* Improve

- Improve strings.xml
- upgrade transifex config
- format code

* add transifex gitignore

* modify BottomSheet

- Abstract BottomSheetListDIalog
- Refactoring the BottomSheet functionality of Activity fragment

* improve SearchActivity UI

* Refactor, update, optimize

- Upgrade app version
- Refactor the search page logic
- Settings page: Modify the select Backup Folder feature

* add SearchPage empty view

* add FolderBackupSelectedPathActivity

* fix and improve

- Optimize and fix the "out of quota" error logic
- Add outlined Star Icon
- Add filled Delete Icon
- update transfer_list_multi_choice_menu.xml
-

* commit master

* Revert "commit master"

This reverts commit 3ffc566.

* update FolderBackupSelectedPathActivity

- add item click listener
- update item UI

* update bottomsheetdialogfragment

* modify SettingsFragment's camera upload tip

* Update proguard-project.txt

* update FolderBackupSelectedPath feature

- upgrade gradle version

* fix this xml file: error 'toLeftOf' id

---------

Co-authored-by: maxiaoping <634115572@qq.com>
  • Loading branch information
zhwanng and maxiaoping authored Apr 8, 2023
1 parent 0b1f818 commit 49ed5ae
Show file tree
Hide file tree
Showing 52 changed files with 2,559 additions and 1,285 deletions.
5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId 'com.seafile.seadroid2'
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 126
versionName "2.3.0"
versionCode 128
versionName "2.3.1"
multiDexEnabled true
resValue "string", "authorities", applicationId + '.cameraupload.provider'
resValue "string", "account_type", "com.seafile.seadroid2.account.api2"
Expand Down Expand Up @@ -111,6 +111,7 @@ android {

//DO NOT upgrade this lib, unless the APP upgrade to AndroidX
implementation 'com.blankj:utilcode:1.30.0'
implementation 'com.jcodecraeer:xrecyclerview:1.6.0'

implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation "com.android.support:design:${rootProject.ext.supportLibVersion}"
Expand Down
11 changes: 11 additions & 0 deletions app/proguard-project.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@
# public *;
#}

#utilcode
-dontwarn com.blankj.utilcode.**
-keepclassmembers class * {
@com.blankj.utilcode.util.BusUtils$Bus <methods>;
}
-keep public class * extends com.blankj.utilcode.util.ApiUtils$BaseApi
-keep,allowobfuscation @interface com.blankj.utilcode.util.ApiUtils$Api
-keep @com.blankj.utilcode.util.ApiUtils$Api class *



-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
android:label="@string/app_name">
</activity>

<activity android:name="com.seafile.seadroid2.ui.activity.SearchActivity"
<activity android:name="com.seafile.seadroid2.ui.activity.search.SearchActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
Expand Down Expand Up @@ -185,6 +185,8 @@
android:theme="@style/AppTheme.Editor"
android:label="@string/app_name">
</activity>
<activity android:name=".ui.activity.search.Search2Activity" />
<activity android:name=".folderbackup.FolderBackupSelectedPathActivity" />

<provider
android:name="com.seafile.seadroid2.provider.SeafileProvider"
Expand Down
21 changes: 14 additions & 7 deletions app/src/main/java/com/seafile/seadroid2/SeafConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -377,14 +377,17 @@ public String getAvatar(String email, int size) throws SeafException {
}
}

public String searchLibraries(String query, int page) throws SeafException {
public String searchLibraries(String query, int page, int pageSize) throws SeafException {

try {
Map<String, Object> params = Maps.newHashMap();
params.put("q", encodeUriComponent(query));

if (page > 0)
params.put("per_page", page);
if (pageSize < 0) {
page = 20;
}
params.put("per_page", pageSize);
params.put("page", page);

HttpRequest req = prepareApiGetRequest("api2/search/", params);
checkRequestResponseStatus(req, HttpURLConnection.HTTP_OK);
Expand Down Expand Up @@ -879,8 +882,7 @@ private String commitUpload(String link, List<String> blkIds, String dir, String
* @return
* @throws SeafException
*/
public String uploadFile(String repoID, String dir, String filePath, ProgressMonitor monitor, boolean update)
throws SeafException, IOException {
public String uploadFile(String repoID, String dir, String filePath, ProgressMonitor monitor, boolean update) throws SeafException, IOException {
String url = getUploadLink(repoID, update, "/");
return uploadFileCommon(url, repoID, dir, filePath, monitor, update);
}
Expand All @@ -889,8 +891,7 @@ public String uploadFile(String repoID, String dir, String filePath, ProgressMon
/**
* Upload a file to seafile httpserver
*/
private String uploadFileCommon(String link, String repoID, String dir, String filePath, ProgressMonitor monitor, boolean update)
throws SeafException, IOException {
private String uploadFileCommon(String link, String repoID, String dir, String filePath, ProgressMonitor monitor, boolean update) throws SeafException, IOException {
File file = new File(filePath);
if (!file.exists()) {
throw new SeafException(SeafException.OTHER_EXCEPTION, "File not exists");
Expand Down Expand Up @@ -923,8 +924,14 @@ private String uploadFileCommon(String link, String repoID, String dir, String f
if (!TextUtils.isEmpty(str)) {
return str.replace("\"", "");
}
} else {
String b = response.body() != null ? response.body().string() : null;//[text={"error": "Out of quota.\n"}]
if (!TextUtils.isEmpty(b) && b.toLowerCase().contains("out of quota")) {
throw SeafException.OutOfQuota;
}
}
throw new SeafException(SeafException.OTHER_EXCEPTION, "File upload failed");

}

/**
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/seafile/seadroid2/SeafException.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.seafile.seadroid2;

import com.google.common.base.Objects;
import com.seafile.seadroid2.transfer.UploadTask;

public class SeafException extends Exception {
private static final long serialVersionUID = 1L;

public static final int OTHER_EXCEPTION = 599;
public static final int HTTP_ABOVE_QUOTA = 443;

private int code;

Expand All @@ -24,6 +26,8 @@ public class SeafException extends Exception {
public static final SeafException twoFactorAuthTokenMissing = new SeafException(13, "Two factor auth token is missing");
public static final SeafException twoFactorAuthTokenInvalid = new SeafException(14, "Two factor auth token is invalid");

public static final SeafException OutOfQuota = new SeafException(HTTP_ABOVE_QUOTA, "out of quota");

public SeafException(int code, String msg) {
super(msg);
this.code = code;
Expand Down
7 changes: 3 additions & 4 deletions app/src/main/java/com/seafile/seadroid2/data/DataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -704,8 +704,7 @@ public void setPassword(String repoID, String passwd) throws SeafException {
}
}

public void uploadFile(String repoName, String repoID, String dir, String filePath,
ProgressMonitor monitor, boolean isUpdate, boolean isCopyToLocal) throws SeafException, IOException {
public void uploadFile(String repoName, String repoID, String dir, String filePath, ProgressMonitor monitor, boolean isUpdate, boolean isCopyToLocal) throws SeafException, IOException {
uploadFileCommon(repoName, repoID, dir, filePath, monitor, isUpdate, isCopyToLocal);
}

Expand Down Expand Up @@ -1155,8 +1154,8 @@ public String getLastPullToRefreshTime(String whichFragment) {
* @return json format strings of searched result
* @throws SeafException
*/
public String search(String query, int page) throws SeafException {
String json = sc.searchLibraries(query, page);
public String search(String query,int page, int pageSize) throws SeafException {
String json = sc.searchLibraries(query, page,pageSize);
return json;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package com.seafile.seadroid2.folderbackup;

import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.blankj.utilcode.util.CollectionUtils;
import com.cocosw.bottomsheet.BottomSheet;
import com.google.gson.Gson;
import com.seafile.seadroid2.R;
import com.seafile.seadroid2.SettingsManager;
import com.seafile.seadroid2.listener.OnItemClickListener;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;

public class FolderBackSelectedPathRecyclerViewAdapter extends RecyclerView.Adapter<FolderBackSelectedPathRecyclerViewAdapter.SearchItemViewHolder> {
private final List<String> mItemList = new ArrayList<>();
private OnItemClickListener<String> onItemClickListener;

private final WeakReference<Context> contextWeakReference;

public FolderBackSelectedPathRecyclerViewAdapter(Context context) {
this.contextWeakReference = new WeakReference<>(context);
}

public void setOnItemClickListener(OnItemClickListener<String> onItemClickListener) {
this.onItemClickListener = onItemClickListener;
}

@NonNull
@Override
public SearchItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(contextWeakReference.get()).inflate(R.layout.item_text_more, parent, false);
return new SearchItemViewHolder(view);
}

@Override
public void onBindViewHolder(@NonNull FolderBackSelectedPathRecyclerViewAdapter.SearchItemViewHolder viewHolder, int position) {
final int p = position;
viewHolder.title.setText(mItemList.get(p));
viewHolder.title.setSelected(true);

viewHolder.icon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showRepoBottomSheet(p);
}
});

viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (onItemClickListener != null) {
onItemClickListener.onItemClick(mItemList.get(p), p);
}
}
});
}

public List<String> getItemList() {
return mItemList;
}

@Override
public int getItemCount() {
return mItemList.size();
}

public void notifyDataChanged(List<String> list) {
mItemList.clear();
if (!CollectionUtils.isEmpty(list)) {
mItemList.addAll(list);
notifyDataSetChanged();
}
}

public void notifyDataClear() {
if (!CollectionUtils.isEmpty(mItemList)) {
mItemList.clear();
notifyDataSetChanged();
}
}

public static class SearchItemViewHolder extends RecyclerView.ViewHolder {
public TextView title;
public View icon;

public SearchItemViewHolder(View view) {
super(view);

title = (TextView) view.findViewById(R.id.title);
icon = (View) view.findViewById(R.id.more);
}
}

private void showRepoBottomSheet(int position) {
BottomSheet.Builder builder = new BottomSheet.Builder((Activity) contextWeakReference.get());
builder.sheet(R.menu.folder_backup_bottom_sheet_delete).listener(new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == R.id.delete) {
mItemList.remove(position);
notifyDataSetChanged();

String strJsonPath = new Gson().toJson(mItemList);
SettingsManager.instance().saveBackupPaths(strJsonPath);
}
}
}).show();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package com.seafile.seadroid2.folderbackup;

import static com.seafile.seadroid2.folderbackup.FolderBackupConfigActivity.BACKUP_SELECT_PATHS;
import static com.seafile.seadroid2.folderbackup.FolderBackupConfigActivity.BACKUP_SELECT_PATHS_SWITCH;
import static com.seafile.seadroid2.ui.fragment.SettingsFragment.FOLDER_BACKUP_REMOTE_PATH;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

import com.blankj.utilcode.util.CollectionUtils;
import com.seafile.seadroid2.R;
import com.seafile.seadroid2.SettingsManager;
import com.seafile.seadroid2.folderbackup.selectfolder.StringTools;
import com.seafile.seadroid2.listener.OnItemClickListener;
import com.seafile.seadroid2.ui.activity.BaseActivity;
import com.seafile.seadroid2.ui.bottomsheet.BottomSheetTextFragment;
import com.seafile.seadroid2.ui.widget.SupportRecyclerView;

import java.util.ArrayList;
import java.util.List;

public class FolderBackupSelectedPathActivity extends BaseActivity {
private SupportRecyclerView mRecyclerView;
private FolderBackSelectedPathRecyclerViewAdapter mAdapter;

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
setContentView(R.layout.folder_backup_selected_path_activity);

mRecyclerView = findViewById(R.id.lv_search);
mAdapter = new FolderBackSelectedPathRecyclerViewAdapter(this);
mAdapter.setOnItemClickListener(new OnItemClickListener<String>() {
@Override
public void onItemClick(String text, int position) {
showBottomDialog(text);
}
});

findViewById(R.id.add_backup_folder).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(FolderBackupSelectedPathActivity.this, FolderBackupConfigActivity.class);
intent.putExtra(FOLDER_BACKUP_REMOTE_PATH, true);
startActivity(intent);
}
});

mRecyclerView.setAdapter(mAdapter);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this, RecyclerView.VERTICAL, false));
View t = findViewById(R.id.ll_message_content);
mRecyclerView.setEmptyView(t);

mRecyclerView.setLoadingMoreEnabled(false);
mRecyclerView.setPullRefreshEnabled(false);

setSupportActionBar(getActionBarToolbar());
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle(R.string.settings_folder_backup_select_title);

}

@Override
protected void onResume() {
super.onResume();
initData();
}

private void initData() {
String backupPaths = SettingsManager.instance().getBackupPaths();
if (!TextUtils.isEmpty(backupPaths)) {
List<String> backupSelectPaths = StringTools.getJsonToList(backupPaths);
mAdapter.notifyDataChanged(backupSelectPaths);
}
}

private void showBottomDialog(String text) {
BottomSheetTextFragment.newInstance(text).show(getSupportFragmentManager(), BottomSheetTextFragment.class.getSimpleName());
}

@Override
public void onBackPressed() {
setFinishPage();

super.onBackPressed();
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
setFinishPage();

finish();
return true;
}
return super.onOptionsItemSelected(item);
}

public void setFinishPage() {
Intent intent = new Intent();
if (!CollectionUtils.isEmpty(mAdapter.getItemList())) {
intent.putStringArrayListExtra(BACKUP_SELECT_PATHS, (ArrayList<String>) mAdapter.getItemList());
intent.putExtra(BACKUP_SELECT_PATHS_SWITCH, true);
}
setResult(RESULT_OK, intent);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.seafile.seadroid2.listener;

public interface OnItemClickListener<T> {
void onItemClick(T t, int position);
}
Loading

0 comments on commit 49ed5ae

Please sign in to comment.