Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sort repo/file/dir on SeafilePathChooserActivity.java #639

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,12 +445,36 @@ private void refreshDir() {
}

private void updateAdapterWithDirents(List<SeafDirent> 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<SeafRepo> 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());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<SeafDirent> dirents;
Expand All @@ -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();
Expand All @@ -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);
Expand All @@ -59,6 +73,42 @@ public void setDirents(List<SeafDirent> dirents) {
notifyDataSetChanged();
}

public void sortFiles(int type, int order) {
List<SeafDirent> folders = Lists.newArrayList();
List<SeafDirent> 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;
Expand Down Expand Up @@ -111,4 +161,4 @@ public Viewholder(TextView title, TextView subtitle, ImageView icon) {
this.subtitle = subtitle;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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;

/**
Expand All @@ -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();
Expand All @@ -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<SeafRepo> 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;
Expand Down