Skip to content

Commit

Permalink
showStarRepos (#852)
Browse files Browse the repository at this point in the history
* Update the translation

* show star repos

* star repos icon

* update repo thumbnail

* parseISODateTime
  • Loading branch information
maxiaoping authored May 9, 2020
1 parent 0bbe795 commit 5a5a708
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 19 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId 'com.seafile.seadroid2'
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 100
versionName "2.2.25"
versionCode 101
versionName "2.2.26"
multiDexEnabled true
resValue "string", "authorities", applicationId + '.cameraupload.provider'
resValue "string", "account_type", "com.seafile.seadroid2.account.api2"
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/seafile/seadroid2/SeafConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,8 @@ public String getHistoryChanges(String repoID, String commitId) throws SeafExcep

public String getStarredFiles() throws SeafException {
try {
HttpRequest req = prepareApiGetRequest("api2/starredfiles/");
// HttpRequest req = prepareApiGetRequest("api2/starredfiles/");
HttpRequest req = prepareApiGetRequest("api/v2.1/starred-items/");
checkRequestResponseStatus(req, HttpURLConnection.HTTP_OK);

return new String(req.bytes(), "UTF-8");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,9 @@ private List<SeafDirent> parseDirents(String json) {

private List<SeafStarredFile> parseStarredFiles(String json) {
try {
JSONArray array = Utils.parseJsonArray(json);
JSONObject jsonObject = new JSONObject(json);
JSONArray array = (JSONArray) jsonObject.opt("starred_item_list");
// JSONArray array = Utils.parseJsonArray(json);
if (array == null)
return null;

Expand Down
33 changes: 23 additions & 10 deletions app/src/main/java/com/seafile/seadroid2/data/SeafStarredFile.java
Original file line number Diff line number Diff line change
@@ -1,37 +1,41 @@
package com.seafile.seadroid2.data;

import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

import com.seafile.seadroid2.R;
import com.seafile.seadroid2.util.SystemSwitchUtils;
import com.seafile.seadroid2.util.Utils;

import org.json.JSONObject;

public class SeafStarredFile implements SeafItem {
public enum FileType { DIR, FILE };
private static final String DEBUG_TAG = "SeafStarredFile";

private String repoID;
private long mtime;
private String path;
private String obj_name;
private boolean repo_encrypted;
private FileType type;
private long size; // size of file, 0 if type is dir

static SeafStarredFile fromJson(JSONObject obj) {
SeafStarredFile starredFile = new SeafStarredFile();
try {
starredFile.repoID = obj.getString("repo");
starredFile.mtime = obj.getLong("mtime");
starredFile.path = obj.getString("path");
starredFile.size = obj.getLong("size");
boolean type = obj.getBoolean("dir");
starredFile.repoID = obj.optString("repo_id");
starredFile.mtime = SystemSwitchUtils.parseISODateTime(obj.optString("mtime"));
starredFile.path = obj.optString("path");
starredFile.obj_name = obj.optString("obj_name");
starredFile.size = obj.optLong("size");
starredFile.repo_encrypted = obj.optBoolean("repo_encrypted");
boolean type = obj.optBoolean("is_dir");
if (!type) {
starredFile.type = FileType.FILE;
} else
starredFile.type = FileType.DIR;
return starredFile;
} catch (JSONException e) {
} catch (Exception e) {
Log.d(DEBUG_TAG, e.getMessage());
return null;
}
Expand All @@ -45,10 +49,18 @@ public long getMtime() {
return mtime;
}

public String getObj_name() {
return obj_name;
}

public boolean isDir() {
return (type == FileType.DIR);
}

public boolean isRepo_encrypted() {
return repo_encrypted;
}

public String getRepoID() {
return repoID;
}
Expand All @@ -59,7 +71,8 @@ public String getPath() {

@Override
public String getTitle() {
return path.substring(path.lastIndexOf('/') + 1);
// return path.substring(path.lastIndexOf('/') + 1);
return getObj_name();
}

@Override
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/java/com/seafile/seadroid2/ui/WidgetUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,15 @@ public static void showRepo(Context context, String repoID, String repoName, Str
context.startActivity(intent);
}

public static void showStarredRepo(Activity activity, String repoID, String repoName, String path, String dirID) {
Intent intent = new Intent(activity, BrowserActivity.class);
intent.putExtra("repoID", repoID);
intent.putExtra("repoName", repoName);
intent.putExtra("path", path);
intent.putExtra("dirID", dirID);
activity.startActivityForResult(intent, 0);
}

public static void startMarkdownActivity(Context context, String path) {
Intent intent = new Intent(context, MarkdownActivity.class);
intent.putExtra("path", path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,8 @@ private void setFileView(SeafDirent dirent, Viewholder viewHolder, int position)
if (url == null) {
viewHolder.icon.setImageResource(dirent.getIcon());
} else {
ImageLoader.getInstance().clearMemoryCache();
ImageLoader.getInstance().clearDiskCache();
ImageLoader.getInstance().displayImage(url, viewHolder.icon, options, animateFirstListener);
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ public View getView(final int position, View convertView, ViewGroup parent) {
viewHolder = (Viewholder) convertView.getTag();
}

viewHolder.icon.setImageResource(item.getIcon());
viewHolder.title.setText(item.getTitle());
viewHolder.subtitle.setText(item.getSubtitle());
judgeRepo(item, viewHolder);

if (Utils.isViewableImage(item.getTitle())) {
DisplayImageOptions options = new DisplayImageOptions.Builder()
Expand All @@ -160,11 +160,13 @@ public View getView(final int position, View convertView, ViewGroup parent) {
ImageLoadingListener animateFirstListener = new AnimateFirstDisplayListener();
String url = mActivity.getDataManager().getThumbnailLink(((SeafStarredFile) item).getRepoID(), ((SeafStarredFile) item).getPath(), WidgetUtils.getThumbnailWidth());
if (url == null) {
viewHolder.icon.setImageResource(item.getIcon());
judgeRepo(item, viewHolder);
} else
ImageLoader.getInstance().displayImage(url, viewHolder.icon, options, animateFirstListener);
} else {
viewHolder.icon.setImageResource(item.getIcon());

judgeRepo(item, viewHolder);

}

if (actionModeOn) {
Expand Down Expand Up @@ -198,6 +200,19 @@ public void onClick(View v) {
return view;
}

private void judgeRepo(SeafItem item, Viewholder viewHolder) {
if (((SeafStarredFile) item).isRepo_encrypted() && ((SeafStarredFile) item).isDir() && ((SeafStarredFile) item).getPath().equals("/")) {
viewHolder.icon.setImageResource(R.drawable.repo_encrypted);

} else {
if (((SeafStarredFile) item).isDir() && ((SeafStarredFile) item).getPath().equals("/")) {
viewHolder.icon.setImageResource(R.drawable.repo);
} else {
viewHolder.icon.setImageResource(item.getIcon());
}
}
}

private class Viewholder {
TextView title, subtitle;
ImageView multiSelect, icon, action;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,20 @@
import com.seafile.seadroid2.R;
import com.seafile.seadroid2.SeafException;
import com.seafile.seadroid2.data.DataManager;
import com.seafile.seadroid2.data.SeafRepo;
import com.seafile.seadroid2.data.SeafStarredFile;
import com.seafile.seadroid2.ui.NavContext;
import com.seafile.seadroid2.ui.WidgetUtils;
import com.seafile.seadroid2.ui.activity.BrowserActivity;
import com.seafile.seadroid2.ui.adapter.StarredItemAdapter;
import com.seafile.seadroid2.ui.dialog.PasswordDialog;
import com.seafile.seadroid2.ui.dialog.TaskDialog;
import com.seafile.seadroid2.util.ConcurrentAsyncTask;
import com.seafile.seadroid2.util.Utils;

import java.util.List;


public class StarredFragment extends ListFragment {
private StarredItemAdapter adapter;
private BrowserActivity mActivity = null;
Expand All @@ -47,6 +52,7 @@ public class StarredFragment extends ListFragment {
private static final int REFRESH_ON_PULL = 1;
private static final int REFRESH_ON_OVERFLOW_MENU = 2;
private static int mRefreshType = -1;
public static final String PASSWORD_DIALOG_STARREDFRAGMENT_TAG = "password_starredfragment";

private DataManager getDataManager() {
return mActivity.getDataManager();
Expand Down Expand Up @@ -230,8 +236,51 @@ public void onListItemClick(final ListView l, final View v, final int position,
return;
}

final SeafStarredFile starredFile = (SeafStarredFile)adapter.getItem(position);
mActivity.onStarredFileSelected(starredFile);
final SeafStarredFile starredFile = (SeafStarredFile) adapter.getItem(position);
if (starredFile.isDir()) {
onStarredDirSelected(starredFile);
} else {
mActivity.onStarredFileSelected(starredFile);
}
}

public PasswordDialog showPasswordDialog(String repoName, String repoID,
TaskDialog.TaskDialogListener listener, String password) {
PasswordDialog passwordDialog = new PasswordDialog();
passwordDialog.setRepo(repoName, repoID, mActivity.getAccount());
if (password != null) {
passwordDialog.setPassword(password);
}
passwordDialog.setTaskDialogLisenter(listener);
passwordDialog.show(mActivity.getSupportFragmentManager(), PASSWORD_DIALOG_STARREDFRAGMENT_TAG);
return passwordDialog;
}

public void onStarredDirSelected(SeafStarredFile searchedFile) {
final String repoID = searchedFile.getRepoID();
final SeafRepo repo = getDataManager().getCachedRepoByID(repoID);
final String repoName = repo.getName();
final String filePath = searchedFile.getPath();

if (searchedFile.isRepo_encrypted()) {
if (repo.encrypted && !getDataManager().getRepoPasswordSet(repo.id)) {
String password = getDataManager().getRepoPassword(repo.id);
showPasswordDialog(repo.name, repo.id,
new TaskDialog.TaskDialogListener() {
@Override
public void onTaskSuccess() {
WidgetUtils.showStarredRepo(mActivity, repoID, repoName, filePath, null);
}
}, password);

return;
} else {
WidgetUtils.showStarredRepo(mActivity, repoID, repoName, filePath, null);
}
} else {
WidgetUtils.showStarredRepo(mActivity, repoID, repoName, filePath, null);
}
return;
}

private void unStarFiles(List<SeafStarredFile> starredFiles) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import com.seafile.seadroid2.R;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;


Expand Down Expand Up @@ -71,6 +73,19 @@ public static String parseDateTime(String dateString) {
return Utils.translateCommitTime(Long.parseLong(date2TimeStamp(arr1[0], "yyyy-MM-dd HH:mm:ss")) * 1000);
}

public static Long parseISODateTime(String dateString) {
String format;
DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
DateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
format = sd.format(sdf.parse(dateString));
String str = date2TimeStamp(format, "yyyy-MM-dd HH:mm:ss");
return Long.parseLong(str);
} catch (ParseException e) {
return null;
}
}

public static String obj_type(Context ct, String obj_type, String op_type) {
if (obj_type.equals("repo")) {
if (op_type.equals("create")) {
Expand Down

0 comments on commit 5a5a708

Please sign in to comment.