Skip to content

Commit

Permalink
new Image preview UI
Browse files Browse the repository at this point in the history
  • Loading branch information
zhwanng committed Dec 2, 2024
1 parent 18d89c1 commit 6edbdc5
Show file tree
Hide file tree
Showing 35 changed files with 1,859 additions and 233 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ android {
implementation "androidx.media3:media3-exoplayer:$media3_version"
implementation "androidx.media3:media3-ui:$media3_version"

// implementation 'com.github.rubensousa:gravitysnaphelper:2.2.2'

implementation 'androidx.core:core-ktx:1.13.1'
implementation 'androidx.core:core-splashscreen:1.0.1'
implementation "androidx.appcompat:appcompat:1.7.0"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@
<activity android:name=".ui.data_migrate.DataMigrationV303Activity" />
<activity android:name=".ui.sdoc.SDocWebViewActivity" />
<activity android:name=".ui.sdoc.comments.SDocCommentsActivity" />
<activity android:name=".ui.media.image_preview2.CarouselImagePreviewActivity" />

<provider
android:name=".provider.SeafileProvider"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,19 @@ public interface DirentDAO {
Single<List<DirentModel>> getListByAccount(String related_account);

@Query("select * from dirents where parent_dir = :parent_dir and repo_id = :repo_id")
Single<List<DirentModel>> getListByParentPath(String repo_id, String parent_dir);

@Query("select * from dirents where parent_dir = :parent_dir and repo_id = :repo_id")
Single<List<DirentModel>> getImageListByParentPath(String repo_id, String parent_dir);

Single<List<DirentModel>> getListByParentPathAsync(String repo_id, String parent_dir);

@Query("select * from dirents where parent_dir = :parent_dir and repo_id = :repo_id")
List<DirentModel> getListByParentPathSync(String repo_id, String parent_dir);

@Query("select * from dirents where type='file' and parent_dir = :parent_dir and repo_id = :repo_id")
Single<List<DirentModel>> getFileListByParentPath(String repo_id, String parent_dir);

/**
* get special one by full_path
*/
@Query("select * from dirents where full_path = :full_path and repo_id = :repo_id")
Single<List<DirentModel>> getListByFullPath(String repo_id, String full_path);
Single<List<DirentModel>> getListByFullPathAsync(String repo_id, String full_path);

@Query("select * from dirents where full_path = :full_path and repo_id = :repo_id limit 1")
List<DirentModel> getListByFullPathSync(String repo_id, String full_path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,15 @@ public boolean isRepo() {
return TextUtils.equals("/", path) && is_dir;
}

public static DirentModel converterThis2DirentModel(StarredModel model) {
public static DirentModel convert2DirentModel(StarredModel model) {
DirentModel d = new DirentModel();
d.full_path = model.path;
d.type = model.is_dir ? "dir" : "file";
d.mtime = 0;
d.name = model.obj_name;
d.repo_id = model.repo_id;
d.repo_name = model.repo_name;
d.parent_dir = Utils.getParentPath(model.path);
return d;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ public boolean isDir() {
}


public static DirentModel converterThis2DirentModel(ActivityModel model){
public static DirentModel convert2DirentModel(ActivityModel model){
DirentModel d = new DirentModel();
d.full_path = model.path;
d.type = model.obj_type;
d.mtime = 0;
d.name = model.name;
d.repo_id = model.repo_id;
d.repo_name = model.repo_name;

d.parent_dir = Utils.getParentPath(model.path);
return d;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public int getIcon() {
return Icons.getFileIcon(getTitle());
}

public static DirentModel converterThis2DirentModel(SearchModel model) {
public static DirentModel convert2DirentModel(SearchModel model) {
DirentModel d = new DirentModel();
d.full_path = model.fullpath;
d.type = model.is_dir ? "dir" : "file";
Expand All @@ -76,6 +76,7 @@ public static DirentModel converterThis2DirentModel(SearchModel model) {
d.repo_name = model.repo_name;
d.last_modified_at = model.last_modified;
d.size = model.size;
d.parent_dir = Utils.getParentPath(model.fullpath);
return d;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public DirentsRepository(RepoService service, DirentDAO dao) {

public Single<List<DirentModel>> getDirents(String repoId, String parent_dir) {
// 先尝试从数据库中获取数据
Single<List<DirentModel>> localData = dao.getListByParentPath(repoId, parent_dir)
Single<List<DirentModel>> localData = dao.getListByParentPathAsync(repoId, parent_dir)
.onErrorResumeNext(throwable -> Single.just(Collections.emptyList()));

// 发起网络请求并保存到数据库
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import androidx.core.content.FileProvider;

import com.blankj.utilcode.util.PathUtils;
import com.blankj.utilcode.util.TimeUtils;
import com.google.android.gms.common.util.DataUtils;
import com.seafile.seadroid2.BuildConfig;

import java.io.File;
Expand Down Expand Up @@ -35,15 +37,22 @@ public static File getMediaStoragePath(String folderName) {

public static Pair<Uri, File> buildTakePhotoUri(Context context) {
File parentFolder = getMediaStoragePath("images");
String fileName = "sf_photo_" + System.currentTimeMillis() + ".jpg";
String fileName = getOneNewName("jpg");
File file = new File(parentFolder, fileName);
Uri uri = FileProvider.getUriForFile(context, BuildConfig.FILE_PROVIDER_AUTHORITIES, file);
return new Pair<>(uri, file);
}

private static String getOneNewName(String prefix) {
long mills = System.currentTimeMillis();
long seconds = mills / 1000;
String date = TimeUtils.millis2String(mills, "yyyyMMdd");
return date + "_" + seconds + "." + prefix;
}

public static Pair<Uri, File> buildTakeVideoUri(Context context) {
File parentFolder = getMediaStoragePath("videos");
String fileName = "sf_video" + System.currentTimeMillis() + ".mp4";
String fileName = getOneNewName("mp4");
File file = new File(parentFolder, fileName);
Uri uri = FileProvider.getUriForFile(context, BuildConfig.FILE_PROVIDER_AUTHORITIES, file);
return new Pair<>(uri, file);
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,20 @@ public static Intent startThisFromRepo(Context context, DirentModel direntModel)

public static Intent startThisFromStarred(Context context, StarredModel starredModel) {
Intent intent = new Intent(context, ImagePreviewActivity.class);
intent.putExtra("dirent", StarredModel.converterThis2DirentModel(starredModel));
intent.putExtra("dirent", StarredModel.convert2DirentModel(starredModel));
return intent;
}

public static Intent startThisFromActivity(Context context, ActivityModel starredModel) {
Intent intent = new Intent(context, ImagePreviewActivity.class);
intent.putExtra("dirent", ActivityModel.converterThis2DirentModel(starredModel));
intent.putExtra("dirent", ActivityModel.convert2DirentModel(starredModel));
return intent;
}


public static void startThisFromSearch(Context context, SearchModel starredModel) {
Intent intent = new Intent(context, ImagePreviewActivity.class);
intent.putExtra("dirent", SearchModel.converterThis2DirentModel(starredModel));
intent.putExtra("dirent", SearchModel.convert2DirentModel(starredModel));
context.startActivity(intent);
}

Expand Down Expand Up @@ -145,8 +145,12 @@ public void onChanged(Boolean aBoolean) {
getViewModel().getStarLiveData().observe(this, new Observer<Boolean>() {
@Override
public void onChanged(Boolean aBoolean) {
isDataOperated = true;

if (aBoolean) {
isDataOperated = true;

}else{

}
ToastUtils.showLong(aBoolean ? R.string.star_file_succeed : R.string.star_file_failed);
}
Expand All @@ -159,6 +163,7 @@ public void onChanged(List<DirentModel> direntModels) {
if (CollectionUtils.isEmpty(direntModels)) {
direntModels = CollectionUtils.newArrayList(currentDirent);
}

direntList = direntModels;

notifyFragmentList();
Expand Down
Loading

0 comments on commit 6edbdc5

Please sign in to comment.