Skip to content

Commit

Permalink
Merge pull request #499 from Logan676/feature/support_built-in_activi…
Browse files Browse the repository at this point in the history
…ties

Support build-in ActivitiesFragment
  • Loading branch information
Logan676 committed Mar 30, 2016
2 parents ecc2f16 + 7a07c5e commit 2d94d34
Show file tree
Hide file tree
Showing 46 changed files with 1,963 additions and 293 deletions.
5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 50
versionName "2.0.4"
versionCode 51
versionName "2.0.5"
}

lintOptions {
Expand Down Expand Up @@ -62,6 +62,7 @@ android {
compile 'com.cocosw:bottomsheet:1.+@aar'
compile project(':libraries:MarkdownView')
compile 'com.commit451:PhotoView:1.2.4'
compile 'com.joanzapata.iconify:android-iconify-material-community:2.2.1'
testCompile 'junit:junit:4.12'
testCompile 'org.robolectric:robolectric:3.0'
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.seafile.seadroid2"
android:versionCode="50"
android:versionName="2.0.4">
android:versionCode="51"
android:versionName="2.0.5">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import android.app.Application;
import android.content.Context;

import com.joanzapata.iconify.Iconify;
import com.joanzapata.iconify.fonts.MaterialCommunityModule;
import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiscCache;
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.core.ImageLoader;
Expand All @@ -19,6 +21,8 @@ public class SeadroidApplication extends Application {

public void onCreate() {
super.onCreate();
Iconify.with(new MaterialCommunityModule());

SeadroidApplication.context = getApplicationContext();
initImageLoader(getApplicationContext());

Expand Down
40 changes: 40 additions & 0 deletions app/src/main/java/com/seafile/seadroid2/SeafConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,46 @@ public String getRepos() throws SeafException {
}
}

public String getEvents(int start) throws SeafException {
try {
String apiPath = String.format("api2/events/");

Map<String, Object> params = Maps.newHashMap();
params.put("start", start);
HttpRequest req = prepareApiGetRequest(apiPath, params);
checkRequestResponseStatus(req, HttpURLConnection.HTTP_OK);

String result = new String(req.bytes(), "UTF-8");
return result;
} catch (SeafException e) {
throw e;
} catch (HttpRequestException e) {
throw getSeafExceptionFromHttpRequestException(e);
} catch (IOException e) {
throw SeafException.networkException;
}
}

public String getHistoryChanges(String repoID, String commitId) throws SeafException {
try {
String apiPath = String.format("api2/repo_history_changes/%s/", repoID);
Map<String, Object> params = Maps.newHashMap();
params.put("commit_id", commitId);
HttpRequest req = prepareApiGetRequest(apiPath, params);
checkRequestResponseStatus(req, HttpURLConnection.HTTP_OK);

String result = new String(req.bytes(), "UTF-8");

return result;
} catch (SeafException e) {
throw e;
} catch (HttpRequestException e) {
throw getSeafExceptionFromHttpRequestException(e);
} catch (IOException e) {
throw SeafException.networkException;
}
}

public String getStarredFiles() throws SeafException {
try {
HttpRequest req = prepareApiGetRequest("api2/starredfiles/");
Expand Down
108 changes: 108 additions & 0 deletions app/src/main/java/com/seafile/seadroid2/data/CommitDetails.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package com.seafile.seadroid2.data;

import com.google.common.collect.Lists;
import com.seafile.seadroid2.util.Utils;

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

import java.util.List;

/**
* Commit details for activities history changes
*/
public class CommitDetails {
public List<String> addedFiles;
public List<String> deletedFiles;
public List<String> modifiedFiles;
public List<String> renamedFiles;
public List<String> addedDirs;
public List<String> deletedDirs;

public CommitDetails() {
addedFiles = Lists.newArrayList();
deletedFiles = Lists.newArrayList();
modifiedFiles = Lists.newArrayList();
renamedFiles = Lists.newArrayList();
addedDirs = Lists.newArrayList();
deletedDirs = Lists.newArrayList();
}

public static CommitDetails fromJson(String json) throws JSONException {
final JSONObject jsonObject = Utils.parseJsonObject(json);
final JSONArray addedFiles = jsonObject.optJSONArray("added_files");
final JSONArray deletedFiles = jsonObject.optJSONArray("deleted_files");
final JSONArray modifiedFiles = jsonObject.optJSONArray("modified_files");
final JSONArray renamedFiles = jsonObject.optJSONArray("renamed_files");
final JSONArray addedDirs = jsonObject.optJSONArray("added_dirs");
final JSONArray deletedDirs = jsonObject.optJSONArray("deleted_dirs");

CommitDetails details = new CommitDetails();
processFileList(details.addedFiles, addedFiles);
processFileList(details.deletedFiles, deletedFiles);
processFileList(details.modifiedFiles, modifiedFiles);
processFileList(details.renamedFiles, renamedFiles);
processFileList(details.addedDirs, addedDirs);
processFileList(details.deletedDirs, deletedDirs);

return details;
}

private static void processFileList(List<String> list, JSONArray jsonArray) throws JSONException {
if (jsonArray == null) return;

for (int i = 0; i < jsonArray.length(); i++) {
list.add(jsonArray.getString(i));
}
}

public List<String> getDeletedDirs() {
return deletedDirs;
}

public void setDeletedDirs(List<String> deletedDirs) {
this.deletedDirs = deletedDirs;
}

public List<String> getRenamedFiles() {
return renamedFiles;
}

public void setRenamedFiles(List<String> renamedFiles) {
this.renamedFiles = renamedFiles;
}

public List<String> getModifiedFiles() {
return modifiedFiles;
}

public void setModifiedFiles(List<String> modifiedFiles) {
this.modifiedFiles = modifiedFiles;
}

public List<String> getAddedFiles() {
return addedFiles;
}

public void setAddedFiles(List<String> addedFiles) {
this.addedFiles = addedFiles;
}

public List<String> getDeletedFiles() {
return deletedFiles;
}

public void setDeletedFiles(List<String> deletedFiles) {
this.deletedFiles = deletedFiles;
}

public List<String> getAddedDirs() {
return addedDirs;
}

public void setAddedDirs(List<String> addedDirs) {
this.addedDirs = addedDirs;
}

}
48 changes: 48 additions & 0 deletions app/src/main/java/com/seafile/seadroid2/data/DataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.os.Environment;
import android.util.Log;
import android.util.Pair;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.seafile.seadroid2.R;
Expand All @@ -12,6 +13,7 @@
import com.seafile.seadroid2.account.Account;
import com.seafile.seadroid2.account.AccountInfo;
import com.seafile.seadroid2.util.Utils;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
Expand Down Expand Up @@ -764,6 +766,52 @@ public void move(String srcRepoId, String srcDir, String srcFn, String dstRepoId

}

public SeafActivities getEvents(int start) throws SeafException, JSONException {
if (!Utils.isNetworkOn()) {
throw SeafException.networkException;
}

final String json = sc.getEvents(start);

if (json == null) return null;

final JSONObject object = Utils.parseJsonObject(json);
final int moreOffset = object.getInt("more_offset");
final boolean more = object.getBoolean("more");
final List<SeafEvent> events = parseEvents(json);
return new SeafActivities(events, moreOffset, more);

}

public String getHistoryChanges(String repoId, String commitId) throws SeafException {
return sc.getHistoryChanges(repoId, commitId);
}

public List<SeafEvent> parseEvents(String json) {
try {
// may throw ClassCastException
JSONArray array = Utils.parseJsonArrayByKey(json, "events");
if (array.length() == 0)
return Lists.newArrayListWithCapacity(0);

ArrayList<SeafEvent> events = Lists.newArrayList();
for (int i = 0; i < array.length(); i++) {
JSONObject obj = array.getJSONObject(i);
SeafEvent event = SeafEvent.fromJson(obj);
if (event != null)
events.add(event);
}
return events;
} catch (JSONException e) {
Log.e(DEBUG_TAG, "parse json error");
return null;
} catch (Exception e) {
// other exception, for example ClassCastException
Log.e(DEBUG_TAG, "parseEvents exception");
return null;
}
}

private static class PasswordInfo {
String password;
long timestamp;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.seafile.seadroid2.data;

public class EventDetailsFileItem {

public enum EType {
FILE_ADDED,
FILE_DELETED,
FILE_MODIFIED,
FILE_RENAMED,
DIR_ADDED,
DIR_DELETED
}

private String path;
private EType eType;
private SeafEvent event;

public EventDetailsFileItem(SeafEvent event, String path, EType etype) {
this.path = path;
this.eType = etype;
this.event = event;
}

public String getPath() {
return path;
}

public void setPath(String path) {
this.path = path;
}

public EType geteType() {
return eType;
}

public SeafEvent getEvent() {
return event;
}

public void setEvent(SeafEvent event) {
this.event = event;
}

public boolean isFileOpenable() {
return eType == EType.FILE_ADDED ||
eType == EType.FILE_MODIFIED ||
eType == EType.FILE_RENAMED ||
eType == EType.DIR_ADDED;
}

public boolean isDir() {
return eType == EType.DIR_ADDED;
}

}
52 changes: 52 additions & 0 deletions app/src/main/java/com/seafile/seadroid2/data/EventDetailsTree.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.seafile.seadroid2.data;

import com.google.common.collect.Lists;
import com.seafile.seadroid2.data.EventDetailsFileItem.EType;

import java.util.List;

/**
* Event details tree of each commit
*/
public class EventDetailsTree {
private List<EventDetailsFileItem> items;
private SeafEvent event;

public EventDetailsTree(SeafEvent event) {
this.items = Lists.newArrayList();
this.event = event;
}

public List<EventDetailsFileItem> setCommitDetails(CommitDetails details) {

items.clear();

processEventCategory(details.addedFiles, "Added files", EType.FILE_ADDED);
processEventCategory(details.deletedFiles, "Deleted files", EType.FILE_DELETED);
processEventCategory(details.modifiedFiles, "Modified files", EType.FILE_MODIFIED);

processEventCategory(details.addedDirs, "Added folders", EType.DIR_ADDED);
processEventCategory(details.deletedDirs, "Deleted folders", EType.DIR_DELETED);

// renamed files is a list of (before rename, after rename) pair
List<String> renamedFiles = Lists.newArrayList();
for (int i = 1, n = details.renamedFiles.size(); i < n; i += 2) {
final String rename = details.renamedFiles.get(i);
renamedFiles.add(rename);
}
processEventCategory(renamedFiles, "Renamed files", EType.FILE_RENAMED);

return items;
}

private void processEventCategory(List<String> files, String desc, EType etype) {
if (files == null || files.isEmpty()) {
return;
}

for (int i = 0, n = files.size(); i < n; i++) {
EventDetailsFileItem item = new EventDetailsFileItem(event, files.get(i), etype);
items.add(item);
}
}
}
Loading

0 comments on commit 2d94d34

Please sign in to comment.