From 3271f0b421fae3d6dbc4eaed6ead144e0b8a835b Mon Sep 17 00:00:00 2001 From: Chun yu Yao Date: Wed, 29 Mar 2017 08:11:23 +0800 Subject: [PATCH 1/2] sort repo/file/dir on SeafilePathChooserActivity.java --- .../activity/SeafilePathChooserActivity.java | 28 +++++++++- .../seadroid2/ui/adapter/DirentsAdapter.java | 56 ++++++++++++++++++- .../ui/adapter/SeafReposAdapter.java | 51 ++++++++++++++++- 3 files changed, 129 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/seafile/seadroid2/ui/activity/SeafilePathChooserActivity.java b/app/src/main/java/com/seafile/seadroid2/ui/activity/SeafilePathChooserActivity.java index 192149de2..ee3650055 100644 --- a/app/src/main/java/com/seafile/seadroid2/ui/activity/SeafilePathChooserActivity.java +++ b/app/src/main/java/com/seafile/seadroid2/ui/activity/SeafilePathChooserActivity.java @@ -445,12 +445,36 @@ private void refreshDir() { } private void updateAdapterWithDirents(List dirents) { - getDirentsAdapter().setDirents(dirents); + //getDirentsAdapter().setDirents(dirents); + DirentsAdapter adapter=getDirentsAdapter(); + if (dirents.size() > 0) { + adapter.clearDirents(); + for (SeafDirent dirent : dirents) { + adapter.add(dirent); + } + int sort_type = SettingsManager.instance().getSortFilesTypePref(); + int sort_order = SettingsManager.instance().getSortFilesOrderPref(); + adapter.sortFiles(sort_type, sort_order); + adapter.notifyChanged(); + } + showListOrEmptyText(dirents.size()); } private void updateAdapterWithRepos(List repos) { - getReposAdapter().setRepos(repos); + //getReposAdapter().setRepos(repos); + SeafReposAdapter adapter=getReposAdapter(); + if (repos.size() > 0) { + adapter.clearRepos(); + for (SeafRepo item: repos) { + adapter.add(item); + } + int sort_type = SettingsManager.instance().getSortFilesTypePref(); + int sort_order = SettingsManager.instance().getSortFilesOrderPref(); + adapter.sortFiles(sort_type, sort_order); + adapter.notifyChanged(); + } + showListOrEmptyText(repos.size()); } diff --git a/app/src/main/java/com/seafile/seadroid2/ui/adapter/DirentsAdapter.java b/app/src/main/java/com/seafile/seadroid2/ui/adapter/DirentsAdapter.java index 07b31b999..91efb41af 100644 --- a/app/src/main/java/com/seafile/seadroid2/ui/adapter/DirentsAdapter.java +++ b/app/src/main/java/com/seafile/seadroid2/ui/adapter/DirentsAdapter.java @@ -1,7 +1,5 @@ package com.seafile.seadroid2.ui.adapter; -import java.util.List; - import android.graphics.Color; import android.view.LayoutInflater; import android.view.View; @@ -15,6 +13,9 @@ import com.seafile.seadroid2.SeadroidApplication; import com.seafile.seadroid2.data.SeafDirent; +import java.util.Collections; +import java.util.List; + public class DirentsAdapter extends BaseAdapter { private List dirents; @@ -23,6 +24,15 @@ public DirentsAdapter() { dirents = Lists.newArrayList(); } + /** sort files type */ + public static final int SORT_BY_NAME = 9; + /** sort files type */ + public static final int SORT_BY_LAST_MODIFIED_TIME = 10; + /** sort files order */ + public static final int SORT_ORDER_ASCENDING = 11; + /** sort files order */ + public static final int SORT_ORDER_DESCENDING = 12; + @Override public int getCount() { return dirents.size(); @@ -37,6 +47,10 @@ public void add(SeafDirent entry) { dirents.add(entry); } + public void notifyChanged() { + notifyDataSetChanged(); + } + @Override public SeafDirent getItem(int position) { return dirents.get(position); @@ -59,6 +73,42 @@ public void setDirents(List dirents) { notifyDataSetChanged(); } + public void sortFiles(int type, int order) { + List folders = Lists.newArrayList(); + List files = Lists.newArrayList(); + + for (SeafDirent item : dirents) { + if (((SeafDirent) item).isDir()) + folders.add(((SeafDirent) item)); + else + files.add(((SeafDirent) item)); + } + + dirents.clear(); + + // sort SeafDirents + if (type == SORT_BY_NAME) { + // sort by name, in ascending order + Collections.sort(folders, new SeafDirent.DirentNameComparator()); + Collections.sort(files, new SeafDirent.DirentNameComparator()); + if (order == SORT_ORDER_DESCENDING) { + Collections.reverse(folders); + Collections.reverse(files); + } + } else if (type == SORT_BY_LAST_MODIFIED_TIME) { + // sort by last modified time, in ascending order + Collections.sort(folders, new SeafDirent.DirentLastMTimeComparator()); + Collections.sort(files, new SeafDirent.DirentLastMTimeComparator()); + if (order == SORT_ORDER_DESCENDING) { + Collections.reverse(folders); + Collections.reverse(files); + } + } + // Adds the objects in the specified collection to this ArrayList + dirents.addAll(folders); + dirents.addAll(files); + } + @Override public View getView(int position, View convertView, ViewGroup parent) { View view = convertView; @@ -111,4 +161,4 @@ public Viewholder(TextView title, TextView subtitle, ImageView icon) { this.subtitle = subtitle; } } -} +} \ No newline at end of file diff --git a/app/src/main/java/com/seafile/seadroid2/ui/adapter/SeafReposAdapter.java b/app/src/main/java/com/seafile/seadroid2/ui/adapter/SeafReposAdapter.java index 53ce5415e..785b358b4 100644 --- a/app/src/main/java/com/seafile/seadroid2/ui/adapter/SeafReposAdapter.java +++ b/app/src/main/java/com/seafile/seadroid2/ui/adapter/SeafReposAdapter.java @@ -1,11 +1,12 @@ package com.seafile.seadroid2.ui.adapter; import android.widget.ImageView; -import android.widget.RelativeLayout; + import com.google.common.collect.Lists; import com.seafile.seadroid2.R; import com.seafile.seadroid2.data.SeafRepo; +import java.util.Collections; import java.util.List; /** @@ -17,6 +18,16 @@ public SeafReposAdapter(boolean onlyShowWritableRepos, String encryptedRepoId) { super(onlyShowWritableRepos, encryptedRepoId); } + /** sort files type */ + public static final int SORT_BY_NAME = 9; + /** sort files type */ + public static final int SORT_BY_LAST_MODIFIED_TIME = 10; + /** sort files order */ + public static final int SORT_ORDER_ASCENDING = 11; + /** sort files order */ + public static final int SORT_ORDER_DESCENDING = 12; + + @Override public int getCount() { return repos.size(); @@ -31,11 +42,49 @@ public void add(SeafRepo repo) { repos.add(repo); } + public void notifyChanged() { + notifyDataSetChanged(); + } + @Override public SeafRepo getItem(int position) { return repos.get(position); } + @Override + public long getItemId(int position) { + return position; + } + + public void clearRepos() { + repos.clear(); + } + + public void sortFiles(int type, int order) { + List folders = Lists.newArrayList(); + + for (SeafRepo item : repos) { + folders.add(((SeafRepo) item)); + } + repos.clear(); + + if (type == SORT_BY_NAME) { + // sort by name, in ascending order + Collections.sort(folders, new SeafRepo.RepoNameComparator()); + if (order == SORT_ORDER_DESCENDING) { + Collections.reverse(folders); + } + } else if (type == SORT_BY_LAST_MODIFIED_TIME) { + // sort by last modified time, in ascending order + Collections.sort(folders, new SeafRepo.RepoLastMTimeComparator()); + if (order == SORT_ORDER_DESCENDING) { + Collections.reverse(folders); + } + } + // Adds the objects in the specified collection to this ArrayList + repos.addAll(folders); + } + @Override protected int getChildLayout() { return R.layout.repo_list_item; From f98d0db15383851a6864fe8347ddfcd243a3bb29 Mon Sep 17 00:00:00 2001 From: Chun yu Yao Date: Thu, 30 Mar 2017 19:08:49 +0800 Subject: [PATCH 2/2] upload new photos/videos first --- .../com/seafile/seadroid2/cameraupload/CameraSyncAdapter.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/seafile/seadroid2/cameraupload/CameraSyncAdapter.java b/app/src/main/java/com/seafile/seadroid2/cameraupload/CameraSyncAdapter.java index f079f425e..33b461217 100644 --- a/app/src/main/java/com/seafile/seadroid2/cameraupload/CameraSyncAdapter.java +++ b/app/src/main/java/com/seafile/seadroid2/cameraupload/CameraSyncAdapter.java @@ -390,7 +390,7 @@ private void uploadImages(SyncResult syncResult, DataManager dataManager) throws }, selection, selectionArgs, - MediaStore.Images.ImageColumns.DATE_ADDED + " ASC" + MediaStore.Images.ImageColumns.DATE_ADDED + " DESC" ); try { @@ -448,7 +448,7 @@ private void uploadVideos(SyncResult syncResult, DataManager dataManager) throws }, selection, selectionArgs, - MediaStore.Video.VideoColumns.DATE_ADDED + " ASC" + MediaStore.Video.VideoColumns.DATE_ADDED + " DESC" ); try {