Skip to content

Commit

Permalink
Improve ImagePreview page
Browse files Browse the repository at this point in the history
- fix other issues
  • Loading branch information
zhwanng committed Dec 25, 2024
1 parent 8c566ca commit 14462c7
Show file tree
Hide file tree
Showing 78 changed files with 1,775 additions and 1,278 deletions.
1 change: 0 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@
<activity android:name=".ui.webview.SeaWebViewActivity" />
<activity android:name=".ui.data_migrate.DataMigrationActivity" />
<activity android:name=".ui.selector.ObjSelectorActivity" />
<activity android:name=".ui.media.image_preview.ImagePreviewActivity" />
<activity android:name=".ui.transfer_list.TransferActivity" />
<activity android:name=".ui.BugHandlerActivity" />
<activity android:name=".ui.settings.SettingsAlbumBackupAdvancedActivity" />
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/com/seafile/seadroid2/SeafException.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class SeafException extends Exception {
public static final SeafException notFoundException = new SeafException(404, "Not found");
public static final SeafException notFoundUserException = new SeafException(20, "Not logged in");
public static final SeafException notLoggedInException = new SeafException(21, "Not logged in");
public static final SeafException transferFileException = new SeafException(22, "The file transfer is abnormal");

public static final SeafException OUT_OF_QUOTA = new SeafException(HTTP_ABOVE_QUOTA, SeadroidApplication.getAppContext().getString(R.string.above_quota));
public static final SeafException REQUEST_EXCEPTION = new SeafException(400, "Request Failed");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public String getSpaceUsed() {

/**
* in fact, the value should be less than 0.
* however, in some cases, it may be 0, and should also return unlimited.
* however, in some cases, it may be 0, and should also return non-limit.
* even if the non-limit is returned, App does not need to verify "Out of quota" status.
* and the "Out of quota" error will be returned in the file upload result.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.seafile.seadroid2.framework.http.HttpIO;
import com.seafile.seadroid2.framework.util.SLogs;
import com.seafile.seadroid2.framework.worker.BackgroundJobManagerImpl;
import com.seafile.seadroid2.preferences.ContextStackPreferenceHelper;
import com.seafile.seadroid2.preferences.Settings;
import com.seafile.seadroid2.ssl.CertsManager;
import com.seafile.seadroid2.ui.camera_upload.CameraUploadManager;
Expand All @@ -17,11 +18,14 @@ public class AccountUtils {

public static void logout(Account account) {

// turn off the gesture lock anyway
// turn off the gesture lock
GestureLockSharePreferenceHelper.disable();

Settings.initUserSettings();

// clear
ContextStackPreferenceHelper.clearStack();

NotificationUtils.cancelAll();

// sign out operations
Expand Down Expand Up @@ -57,6 +61,9 @@ public static void switchAccount(Account account) {

NotificationUtils.cancelAll();

// clear
ContextStackPreferenceHelper.clearStack();

//
Settings.initUserSettings();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.seafile.seadroid2.config;

import androidx.annotation.DrawableRes;

import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.model.GlideUrl;
import com.bumptech.glide.load.model.LazyHeaders;
import com.bumptech.glide.request.RequestOptions;
Expand Down Expand Up @@ -38,12 +41,33 @@ public static RequestOptions getAvatarOptions() {
.override(WidgetUtils.getThumbnailWidth(), WidgetUtils.getThumbnailWidth());
}

private final static RequestOptions _cacheableThumbnailOptions = new RequestOptions()
.diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
.error(R.drawable.icon_image_error_filled)
.override(128);

/**
* Get cacheable thumbnail options, width and height are both 128
*/
public static RequestOptions getCacheableThumbnailOptions() {
return _cacheableThumbnailOptions;
}

public static RequestOptions getOptions() {
return new RequestOptions()
.diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
.fallback(R.drawable.file_image)
.placeholder(R.drawable.file_image);
}


public static RequestOptions getCustomDrawableOptions(@DrawableRes int resId) {
return new RequestOptions()
.diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
.fallback(resId)
.placeholder(resId);
}

public static RequestOptions getOptions(String key) {
return new RequestOptions()
.fallback(R.drawable.file_image)
Expand Down
38 changes: 38 additions & 0 deletions app/src/main/java/com/seafile/seadroid2/config/OriGlideUrl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.seafile.seadroid2.config;

import com.bumptech.glide.load.model.GlideUrl;
import com.bumptech.glide.load.model.Headers;
import com.seafile.seadroid2.framework.util.SLogs;

import java.net.URL;

public class OriGlideUrl extends GlideUrl {
private String oriKey;

public OriGlideUrl(URL url) {
super(url);
}

public OriGlideUrl(String url) {
super(url);
}

public OriGlideUrl(String url, String oriKey) {
super(url);
this.oriKey = oriKey;
}


public OriGlideUrl(URL url, Headers headers) {
super(url, headers);
}

public OriGlideUrl(String url, Headers headers) {
super(url, headers);
}

@Override
public String getCacheKey() {
return oriKey;
}
}
66 changes: 66 additions & 0 deletions app/src/main/java/com/seafile/seadroid2/context/NavContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import com.seafile.seadroid2.framework.data.model.BaseModel;
import com.seafile.seadroid2.framework.data.db.entities.DirentModel;
import com.seafile.seadroid2.framework.data.db.entities.RepoModel;
import com.seafile.seadroid2.framework.data.model.ContextModel;
import com.seafile.seadroid2.framework.util.Utils;
import com.seafile.seadroid2.preferences.ContextStackPreferenceHelper;

import java.util.Stack;

Expand All @@ -32,28 +34,90 @@ public void clear() {
}
}

/**
* Push a model to the stack
*/
public void push(BaseModel model) {
if (model instanceof RepoModel) {
//clear
navStack.clear();

//push
navStack.push(model);

saveToSp();

} else if (model instanceof DirentModel) {
//stack
navStack.push(model);
saveToSp();

} else {
throw new IllegalArgumentException("model must be RepoMode or DirentsModel.");
}
}

public void restoreNavContextFromSp() {

navStack.clear();

Stack<ContextModel> stack = ContextStackPreferenceHelper.getStack();
if (stack != null && !stack.isEmpty()) {
for (ContextModel contextModel : stack) {
if (contextModel.type.equals("repo")) {
RepoModel repoModel = new RepoModel();
repoModel.repo_id = contextModel.repo_id;
repoModel.repo_name = contextModel.repo_name;
navStack.push(repoModel);
} else if (contextModel.type.equals("dirent")) {
DirentModel direntModel = new DirentModel();
direntModel.repo_id = contextModel.repo_id;
direntModel.repo_name = contextModel.repo_name;
direntModel.full_path = contextModel.full_path;
direntModel.parent_dir = Utils.getParentPath(direntModel.full_path);
direntModel.name = Utils.getFileNameFromPath(contextModel.full_path);
direntModel.uid = direntModel.getUID();
navStack.push(direntModel);
}
}
}

}

private void saveToSp() {
Stack<ContextModel> stack = new Stack<>();
if (!navStack.isEmpty()) {
for (BaseModel baseModel : navStack) {
ContextModel contextModel = new ContextModel();

if (baseModel instanceof RepoModel e) {
contextModel.repo_id = e.repo_id;
contextModel.repo_name = e.repo_name;
contextModel.type = "repo";
contextModel.full_path = "/";
} 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;
}
stack.add(contextModel);
}
}

ContextStackPreferenceHelper.saveStack(stack);
}

public void pop() {
if (navStack.empty()) {
return;
}

//stack
navStack.pop();

saveToSp();

}

public void switchToPath(RepoModel repoModel, String full_path) {
Expand Down Expand Up @@ -87,6 +151,8 @@ public void switchToPath(RepoModel repoModel, String full_path) {
for (DirentModel model : stack) {
navStack.push(model);
}

saveToSp();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,11 @@ public interface FileTransferDAO {
@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 related_account = :related_account and transfer_action = :transferAction and full_path = :full_path and data_status = 0 order by created_at")
List<FileTransferEntity> getListByFullPathSync(String related_account, 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")
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,44 +361,6 @@ public static FileTransferEntity convertDirentModel2This(boolean is_block, boole
return entity;
}

public static FileTransferEntity convertDirentFileModel2This(RepoModel repoModel, String full_path, boolean is_auto_transfer, DirentFileModel direntModel) {
FileTransferEntity entity = new FileTransferEntity();
entity.full_path = full_path;
// entity.target_path = direntModel.full_path;
entity.data_source = TransferDataSource.DOWNLOAD;
entity.repo_id = repoModel.repo_id;
entity.repo_name = repoModel.repo_name;
entity.related_account = repoModel.related_account;


entity.file_id = direntModel.id;
entity.setParent_path(Utils.getParentPath(full_path));
entity.file_name = direntModel.name;
entity.file_format = FileTools.getFileExtension(entity.full_path);
entity.mime_type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(entity.file_format);
entity.file_size = direntModel.size;
entity.file_md5 = null;

entity.is_auto_transfer = is_auto_transfer;

// entity.is_block = repoModel.canLocalDecrypt();
entity.file_strategy = ExistingFileStrategy.AUTO;

entity.is_copy_to_local = true;

long now = System.currentTimeMillis();
entity.created_at = now;
entity.modified_at = direntModel.mtime * 1000;
entity.action_end_at = 0L;

entity.transfer_action = TransferAction.DOWNLOAD;
entity.transfer_status = TransferStatus.WAITING;
entity.transfer_result = TransferResult.NO_RESULT;

entity.uid = entity.getUID();

return entity;
}


public static FileTransferEntity convertDirentRecursiveModel2This(RepoModel repoModel, DirentRecursiveFileModel model) {
Expand Down Expand Up @@ -444,7 +406,7 @@ public static FileTransferEntity convertDirentRecursiveModel2This(RepoModel repo
return entity;
}

public static FileTransferEntity convert2ThisForUploadFileSyncWorker(Account account, RepoModel repoModel, File file, String backupPath) {
public static FileTransferEntity convert2ThisForUploadFileSyncWorker(Account account, File file, String backupPath) {
if (!file.isFile()) {
return null;
}
Expand All @@ -466,8 +428,8 @@ public static FileTransferEntity convert2ThisForUploadFileSyncWorker(Account acc
entity.mime_type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(entity.file_format);

// entity.is_block = repoModel.encrypted;
entity.repo_id = repoModel.repo_id;
entity.repo_name = repoModel.repo_name;
// entity.repo_id = repoModel.repo_id;
// entity.repo_name = repoModel.repo_name;
entity.related_account = account.getSignature();
entity.data_source = TransferDataSource.FOLDER_BACKUP;
entity.created_at = System.currentTimeMillis();
Expand All @@ -489,7 +451,7 @@ public static FileTransferEntity convert2ThisForUploadFileSyncWorker(Account acc
}


public static FileTransferEntity convert2ThisForUploadMediaSyncWorker(Account account, String repo_id, String repo_name, File file, String parenPath, long dateAdd, boolean isRemoteExists) {
public static FileTransferEntity convert2ThisForUploadMediaSyncWorker(Account account, File file, String parenPath, long dateAdd, boolean isRemoteExists) {
long now = System.currentTimeMillis();

FileTransferEntity entity = new FileTransferEntity();
Expand All @@ -502,8 +464,8 @@ public static FileTransferEntity convert2ThisForUploadMediaSyncWorker(Account ac
entity.file_md5 = FileUtils.getFileMD5ToString(entity.full_path).toLowerCase();
entity.mime_type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(entity.file_format);
// entity.is_block = false; //album backup is not store in encrypted repo.
entity.repo_id = repo_id;
entity.repo_name = repo_name;
// entity.repo_id = repo_id;
// entity.repo_name = repo_name;
entity.related_account = account.getSignature();
entity.created_at = now;
entity.modified_at = now;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.seafile.seadroid2.framework.data.model;

public class ContextModel {
public String repo_id;
public String repo_name; //repo_name

public String type; //repo/dirent

/**
* parent_dir + name
*/
public String full_path;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@

public class FileProfileConfigModel {
public UserWrapperModel users;
public MetadataConfigModel metadata;
public FileDetailModel detail;
public MetadataConfigModel metadataConfigModel;

public UserWrapperModel getUsers() {
return users;
public MetadataConfigModel getMetadataConfigModel() {
return metadataConfigModel;
}

public void setUsers(UserWrapperModel users) {
this.users = users;
public void setMetadataConfigModel(MetadataConfigModel metadataConfigModel) {
this.metadataConfigModel = metadataConfigModel;
}

public MetadataConfigModel getMetadata() {
return metadata;
public UserWrapperModel getUsers() {
return users;
}

public void setMetadata(MetadataConfigModel metadata) {
this.metadata = metadata;
public void setUsers(UserWrapperModel users) {
this.users = users;
}

public FileDetailModel getDetail() {
Expand Down
Loading

0 comments on commit 14462c7

Please sign in to comment.