Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
zhwanng committed Nov 23, 2024
1 parent 828af6a commit af0ca6e
Show file tree
Hide file tree
Showing 44 changed files with 1,315 additions and 527 deletions.
17 changes: 17 additions & 0 deletions app/src/main/java/com/seafile/seadroid2/annotation/Todo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.seafile.seadroid2.annotation;


import static java.lang.annotation.ElementType.CONSTRUCTOR;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;

import java.lang.annotation.Target;

/**
* In this project, this feature is not yet complete, and will continue to be maintained in the future
*/

@Target({TYPE, METHOD, CONSTRUCTOR, FIELD})
public @interface Todo {
}
45 changes: 23 additions & 22 deletions app/src/main/java/com/seafile/seadroid2/context/NavContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
public class NavContext {
private final Stack<BaseModel> navStack = new Stack<>();

// repoId = xxx, path = /
/**
* repoId = xxx, path = /
*/
public boolean inRepoRoot() {
return navStack.size() == 1;
}
Expand Down Expand Up @@ -97,27 +99,26 @@ public DirentModel getTopDirentModel() {
return (DirentModel) navStack.peek();
}

/**
* Get the parents model of the current Dirent, maybe RepoModel
*/
public boolean isParentHasWritePermission() {
if (!inRepo()) {
//repo list page should not have permission verification
throw new IllegalArgumentException("Please check your code");
}

if (inRepoRoot()) {
return getRepoModel().hasWritePermission();
}

BaseModel bd = navStack.elementAt(navStack.size() - 1);
DirentModel d = (DirentModel) bd;
if (d == null) {
return false;
}

return d.hasWritePermission();
}
// /**
// * Get the parents model of the current Dirent, maybe RepoModel
// */
// public boolean isParentHasWritePermission() {
// if (!inRepo()) {
// //repo list page should not have permission verification
// throw new IllegalArgumentException("Please check your code");
// }
//
// if (inRepoRoot()) {
// return getRepoModel().hasWritePermission();
// }
//
// BaseModel bd = navStack.elementAt(navStack.size() - 1);
// if (bd instanceof DirentModel d) {
// return d.hasWritePermission();
// } else {
// return false;
// }
// }

public RepoModel getRepoModel() {
if (navStack.empty()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.seafile.seadroid2.enums;

public enum ActionModeCallbackType {
CREATE, DESTORY, SELECT_ALL, SELECT_NONE
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;
import androidx.room.Update;

import com.seafile.seadroid2.framework.data.db.entities.FileTransferEntity;
import com.seafile.seadroid2.framework.data.db.entities.PermissionEntity;
import com.seafile.seadroid2.framework.data.db.entities.PermissionEntity;

import java.util.List;
Expand All @@ -18,16 +15,20 @@
@Dao
public interface PermissionDAO {

@Query("select * from permissions where repo_id = :repoId and id = :id limit 1")
List<PermissionEntity> getByIdSync(String repoId, int id);
@Query("select * from permissions where id = :id limit 1")
List<PermissionEntity> getByIdSync(int id);

@Query("select * from permissions where id IN (:ids)")
Single<List<PermissionEntity>> getByIdsAsync(List<Integer> ids);

@Query("select * from permissions where repo_id = :repoId and id = :id limit 1")
Single<List<PermissionEntity>> getByIdAsync(String repoId, int id);
Single<List<PermissionEntity>> getWithAsync(String repoId, int id);

@Query("select * from permissions where repo_id = :repoId")
Single<List<PermissionEntity>> getByRepoIdAsync(String repoId);



@Query("DELETE FROM permissions")
void deleteAll();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public interface RepoDAO {
@Query("select * from repos where repo_id = :repo_id limit 1")
Single<List<RepoModel>> getRepoById(String repo_id);

@Query("select * from repos where repo_id IN (:ids)")
Single<List<RepoModel>> getRepoListByIds(List<String> ids);

@Query("select * from repos where repo_id = :repo_id limit 1")
List<RepoModel> getByIdSync(String repo_id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ public boolean hasDownloadPermission() {
return true;
}

/**
* is start with "custom-" ?
*/
public boolean isCustomPermission() {
return !TextUtils.isEmpty(permission) && permission.startsWith("custom-");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
package com.seafile.seadroid2.framework.data.db.entities;

import android.text.TextUtils;

import androidx.annotation.NonNull;
import androidx.room.Entity;
import androidx.room.Ignore;

import com.seafile.seadroid2.framework.data.model.BaseModel;
import com.seafile.seadroid2.framework.data.model.permission.PermissionWrapperModel;

import java.util.HashMap;
import java.util.Set;

@Entity(tableName = "permissions", primaryKeys = {"repo_id", "id"})
public class PermissionEntity extends BaseModel {
Expand All @@ -24,5 +31,127 @@ public class PermissionEntity extends BaseModel {
public boolean delete;
public boolean modify;
public boolean download_external_link;
//1001010


/**
* key -> repo_id or dirent_id(uid)
*/
@Ignore
public HashMap<String, BaseModel> cachedMap;

public boolean hasId(String id) {
if (cachedMap == null) {
return false;
}

return cachedMap.containsKey(id);
}

public void cacheBaseModel(BaseModel model) {
if (cachedMap == null) {
cachedMap = new HashMap<>();
return;
}

if (model instanceof RepoModel m) {
cachedMap.put(m.repo_id, m);
} else if (model instanceof DirentModel m) {
cachedMap.put(m.uid, m);
}
}

public void removeById(String id) {
if (cachedMap == null) {
return;
}

cachedMap.remove(id);
}

public void removeByModel(BaseModel model) {
if (cachedMap == null) {
return;
}

if (model instanceof RepoModel m) {
cachedMap.remove(m.repo_id);
} else if (model instanceof DirentModel m) {
cachedMap.remove(m.uid);
}
}

public boolean isEmptyIds() {
return cachedMap == null || cachedMap.isEmpty();
}

public PermissionEntity() {
}

public PermissionEntity(@NonNull String repoId, @NonNull PermissionWrapperModel model) {
this.id = model.id;
this.name = model.name;
this.description = model.description;

this.create = model.permission.create;
this.upload = model.permission.upload;
this.download = model.permission.download;
this.copy = model.permission.copy;
this.delete = model.permission.delete;
this.modify = model.permission.modify;
this.download_external_link = model.permission.download_external_link;
this.preview = model.permission.preview;
this.repo_id = repoId;
}

public PermissionEntity(@NonNull String repoId, @NonNull String permission) {
if (TextUtils.isEmpty(permission)) {
throw new IllegalArgumentException("permission is null");
}

this.name = permission;
this.id = -1;
this.repo_id = repoId;

if ("cloud-edit".equals(permission)) {
//用户可以通过浏览器在线查看和编辑,文件不能被下载。
this.create = true;
this.upload = false;
this.download = false;
this.preview = true;
this.copy = true;
this.delete = true;
this.modify = true;
this.download_external_link = false;

} else if ("preview".equals(permission)) {
//用户只能通过浏览器在线查看,文件不能被下载。
this.create = false;
this.upload = false;
this.download = false;
this.preview = true;
this.copy = false;
this.delete = false;
this.modify = false;
this.download_external_link = false;
} else if ("r".equals(permission)) {
//用户可以查看、下载和同步文件
this.create = false;
this.upload = false;
this.download = true;
this.preview = true;
this.copy = true;
this.delete = false;
this.modify = false;
this.download_external_link = false;
} else if ("rw".equals(permission)) {
this.create = true;
this.upload = true;
this.download = true;
this.preview = true;
this.copy = true;
this.delete = true;
this.modify = true;
this.download_external_link = true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public int getIcon() {
}

/**
* You'll also need to check if it's a custom permission
* You should to check if it's a custom permission firstly
*/
public boolean hasWritePermission() {
if (TextUtils.isEmpty(permission)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.seafile.seadroid2.framework.data.model.repo;

import com.seafile.seadroid2.framework.data.db.entities.PermissionEntity;
import com.seafile.seadroid2.framework.data.db.entities.RepoModel;

public class RepoPermissionWrapper {
public RepoModel repoModel;
public PermissionEntity permission;

public RepoPermissionWrapper(RepoModel repoModel, PermissionEntity permission) {
this.repoModel = repoModel;
this.permission = permission;
}

public PermissionEntity getPermission() {
return permission;
}

public void setPermission(PermissionEntity permission) {
this.permission = permission;
}

public void setRepoModel(RepoModel repoModel) {
this.repoModel = repoModel;
}

public RepoModel getRepoModel() {
return repoModel;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ public final class SettingsManager {
//force refresh starred list state
public static final String ON_FORCE_REFRESH_STARRED_LIST_KEY = "on_force_refresh_starred_list";

public static void setForceRefreshStarredListState() {
Settings.getCommonPreferences().edit().putBoolean(ON_FORCE_REFRESH_STARRED_LIST_KEY, true).apply();
public static void setForceRefreshStarredListState(boolean state) {
Settings.getCommonPreferences().edit().putBoolean(ON_FORCE_REFRESH_STARRED_LIST_KEY, state).apply();
}

public static boolean getForceRefreshStarredListState() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ protected void onBindViewHolder(@NonNull BottomSheetMenuAdapter.BottomSheetViewH

holder.name.setEnabled(menuItem.isEnabled());
holder.itemView.setClickable(menuItem.isEnabled());

int color;
if (menuItem.isEnabled()) {
color = ContextCompat.getColor(getContext(), R.color.material_grey_600);
color = ContextCompat.getColor(getContext(), R.color.bottom_sheet_pop_enable_color);
} else {
color = ContextCompat.getColor(getContext(), R.color.material_grey_400);
color = ContextCompat.getColor(getContext(), R.color.bottom_sheet_pop_disable_color);
}
holder.icon.setImageTintList(ColorStateList.valueOf(color));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,5 +193,9 @@ public BottomSheetMenuFragment build() {
public void show(FragmentManager fragmentManager) {
build().show(fragmentManager, BottomSheetMenuFragment.class.getSimpleName());
}

public void show(FragmentManager fragmentManager, String tag) {
build().show(fragmentManager, tag);
}
}
}
Loading

0 comments on commit af0ca6e

Please sign in to comment.