Compare commits

...
19 Commits
Author SHA1 Message Date
seven332 c2c98003f1 1.0.0 2016-03-28 18:34:50 +08:00
seven332 dd6f02395c Save comments after voting 2016-03-28 18:32:48 +08:00
seven332 f419264540 Use extra buffer to avoid gif blink 2016-03-28 17:00:10 +08:00
seven332 d7565ce0bb Update Readme 2016-03-28 16:29:46 +08:00
seven332 095ccf1b55 Add check vote status 2016-03-28 16:15:36 +08:00
seven332 8abefdb6d4 Use user own apiuid and apikey 2016-03-28 15:14:05 +08:00
seven332 0aad8ca1e8 Add vote comment 2016-03-28 02:04:05 +08:00
seven332 0bc4569084 Safer 2016-03-27 22:49:48 +08:00
seven332 337c859040 Add UrlPreference, add help 2016-03-27 22:13:30 +08:00
seven332 e0cb0fca18 Fix typo 2016-03-27 19:13:29 +08:00
seven332 b8d5a7d80d Add reveal effect for gallery detail header on pre-L 2016-03-27 18:23:15 +08:00
seven332 2ddb234e72 Don't show all comment as default 2016-03-27 18:14:29 +08:00
seven332 19ebd4c28f Use my own reveal stuff 2016-03-27 18:13:35 +08:00
seven332 e6367055fb Improve GalleryCommentsScene 2016-03-27 16:22:56 +08:00
seven332 ba72dbff7c Add RevealLinearLayout for pre-L 2016-03-27 16:15:05 +08:00
seven332 df41c62269 Remove bookmark item in gallery page menu 2016-03-27 15:00:34 +08:00
seven332 a1cea27cdc Add fullBackupContent, only database 2016-03-27 14:49:09 +08:00
seven332 173f01853b Add largeHeap 2016-03-27 14:25:33 +08:00
seven332 8568f1c7a0 Adjust gallery list item rating view position 2016-03-27 14:23:26 +08:00
34 changed files with 977 additions and 123 deletions

No files matched your search

+2
View File
@@ -72,3 +72,5 @@ Here is the libraries
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
ic_launcher 图标为 Hippo Seven 所有,所有权利保留
+2 -2
View File
@@ -10,8 +10,8 @@ android {
applicationId "com.hippo.ehviewer"
minSdkVersion 16
targetSdkVersion 23
versionCode 52
versionName "0.9.4"
versionCode 53
versionName "1.0.0"
vectorDrawables.useSupportLibrary = true
}
+4 -2
View File
@@ -27,10 +27,12 @@
<application
android:name="com.hippo.ehviewer.EhApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme"
android:allowBackup="true"
android:fullBackupContent="@xml/backup_scheme"
android:largeHeap="true">
<activity
android:name="com.hippo.ehviewer.ui.MainActivity"
@@ -56,6 +56,7 @@ public class EhClient {
public static final int METHOD_GET_TORRENT_LIST = 12;
public static final int METHOD_GET_WHATS_HOT = 13;
public static final int METHOD_GET_PROFILE = 14;
public static final int METHOD_VOTE_COMMENT = 15;
private final ThreadPoolExecutor mRequestThreadPool;
private final OkHttpClient mOkHttpClient;
@@ -158,7 +159,7 @@ public class EhClient {
case METHOD_GET_PREVIEW_SET:
return EhEngine.getPreviewSet(this, mOkHttpClient, (String) params[0]);
case METHOD_GET_RATE_GALLERY:
return EhEngine.rateGallery(this, mOkHttpClient, (Long) params[0], (String) params[1], (Float) params[2]);
return EhEngine.rateGallery(this, mOkHttpClient, (Long) params[0], (String) params[1], (Long) params[2], (String) params[3], (Float) params[4]);
case METHOD_GET_COMMENT_GALLERY:
return EhEngine.commentGallery(this, mOkHttpClient, (String) params[0], (String) params[1]);
case METHOD_GET_GALLERY_TOKEN:
@@ -177,6 +178,8 @@ public class EhClient {
return EhEngine.getWhatsHot(this, mOkHttpClient);
case METHOD_GET_PROFILE:
return EhEngine.getProfile(this, mOkHttpClient);
case METHOD_VOTE_COMMENT:
return EhEngine.voteComment(this, mOkHttpClient, (Long) params[0], (String) params[1], (Long) params[2], (String) params[3], (Long) params[4], (Integer) params[5]);
default:
return new IllegalStateException("Can't detect method " + mMethod);
}
@@ -41,6 +41,7 @@ import com.hippo.ehviewer.client.parser.ProfileParser;
import com.hippo.ehviewer.client.parser.RateGalleryParser;
import com.hippo.ehviewer.client.parser.SignInParser;
import com.hippo.ehviewer.client.parser.TorrentParser;
import com.hippo.ehviewer.client.parser.VoteCommentParser;
import com.hippo.ehviewer.client.parser.WhatsHotParser;
import com.hippo.network.StatusCodeException;
import com.hippo.util.ReadableTime;
@@ -76,9 +77,6 @@ public class EhEngine {
private static final String SAD_PANDA_TYPE = "image/gif";
private static final String SAD_PANDA_LENGTH = "9615";
public static final long APIUID = 1363542;
public static final String APIKEY = "f4b5407ab1727b9d08d7";
public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
public static EhFilter sEhFilter;
@@ -335,11 +333,12 @@ public class EhEngine {
}
public static RateGalleryParser.Result rateGallery(EhClient.Task task,
OkHttpClient okHttpClient, long gid, String token, float rating) throws Exception {
OkHttpClient okHttpClient, long apiUid, String apiKey, long gid,
String token, float rating) throws Exception {
final JSONObject json = new JSONObject();
json.put("method", "rategallery");
json.put("apiuid", APIUID);
json.put("apikey", APIKEY);
json.put("apiuid", apiUid);
json.put("apikey", apiKey);
json.put("gid", gid);
json.put("token", token);
json.put("rating", (int) Math.ceil(rating * 2));
@@ -672,4 +671,40 @@ public class EhEngine {
throw e;
}
}
public static VoteCommentParser.Result voteComment(EhClient.Task task, OkHttpClient okHttpClient,
long apiUid, String apiKey, long gid, String token, long commentId, int commentVote) throws Exception {
final JSONObject json = new JSONObject();
json.put("method", "votecomment");
json.put("apiuid", apiUid);
json.put("apikey", apiKey);
json.put("gid", gid);
json.put("token", token);
json.put("comment_id", commentId);
json.put("comment_vote", commentVote);
final RequestBody requestBody = RequestBody.create(JSON, json.toString());
String url = EhUrl.getApiUrl();
Log.d(TAG, url);
Request request = new EhRequestBuilder(url, task.getEhConfig())
.post(requestBody)
.build();
Call call = okHttpClient.newCall(request);
// Put call
task.setCall(call);
String body = null;
Headers headers = null;
int code = -1;
try {
Response response = call.execute();
code = response.code();
headers = response.headers();
body = response.body().string();
return VoteCommentParser.parse(body, commentVote);
} catch (Exception e) {
throwException(call, code, headers, body, e);
throw e;
}
}
}
@@ -21,6 +21,12 @@ import android.os.Parcelable;
public class GalleryComment implements Parcelable {
// 0 for uploader comment. can't vote
public long id;
public int score;
public boolean voteUp;
public boolean voteDown;
public String voteState;
public long time;
public String user;
public String comment;
@@ -32,6 +38,11 @@ public class GalleryComment implements Parcelable {
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(this.id);
dest.writeInt(this.score);
dest.writeByte(voteUp ? (byte) 1 : (byte) 0);
dest.writeByte(voteDown ? (byte) 1 : (byte) 0);
dest.writeString(this.voteState);
dest.writeLong(this.time);
dest.writeString(this.user);
dest.writeString(this.comment);
@@ -41,16 +52,23 @@ public class GalleryComment implements Parcelable {
}
protected GalleryComment(Parcel in) {
this.id = in.readLong();
this.score = in.readInt();
this.voteUp = in.readByte() != 0;
this.voteDown = in.readByte() != 0;
this.voteState = in.readString();
this.time = in.readLong();
this.user = in.readString();
this.comment = in.readString();
}
public static final Creator<GalleryComment> CREATOR = new Creator<GalleryComment>() {
@Override
public GalleryComment createFromParcel(Parcel source) {
return new GalleryComment(source);
}
@Override
public GalleryComment[] newArray(int size) {
return new GalleryComment[size];
}
@@ -23,6 +23,8 @@ import java.util.Arrays;
public class GalleryDetail extends GalleryInfo {
public long apiUid = -1L;
public String apiKey;
public int torrentCount;
public String torrentUrl;
public String parent;
@@ -18,6 +18,7 @@ package com.hippo.ehviewer.client.parser;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import com.hippo.ehviewer.client.EhUtils;
import com.hippo.ehviewer.client.data.GalleryComment;
@@ -53,7 +54,7 @@ import java.util.regex.Pattern;
public class GalleryDetailParser {
private static final Pattern PATTERN_ERROR = Pattern.compile("<div class=\"d\">\n<p>([^<]+)</p>");
private static final Pattern PATTERN_DETAIL = Pattern.compile("var gid = (\\d+).+?var token = \"([a-f0-9]+)\"", Pattern.DOTALL);
private static final Pattern PATTERN_DETAIL = Pattern.compile("var gid = (\\d+);.+?var token = \"([a-f0-9]+)\";.+?var apiuid = ([\\-\\d]+);.+?var apikey = \"([a-f0-9]+)\";", Pattern.DOTALL);
private static final Pattern PATTERN_TORRENT = Pattern.compile("<a[^<>]*onclick=\"return popUp\\('([^']+)'[^)]+\\)\">Torrent Download \\( (\\d+) \\)</a>");
private static final Pattern PATTERN_TAG_GROUP = Pattern.compile("<tr><td[^<>]+>([\\w\\s]+):</td><td>(?:<div[^<>]+><a[^<>]+>[\\w\\s]+</a></div>)+</td></tr>");
private static final Pattern PATTERN_TAG = Pattern.compile("<div[^<>]+><a[^<>]+>([\\w\\s]+)</a></div>");
@@ -108,6 +109,8 @@ public class GalleryDetailParser {
if (matcher.find()) {
gd.gid = Long.parseLong(matcher.group(1));
gd.token = matcher.group(2);
gd.apiUid = NumberUtils.parseLongSafely(matcher.group(3), -1L);
gd.apiKey = matcher.group(4);
} else {
throw new ParseException("Can't parse gallery detail", body);
}
@@ -342,11 +345,40 @@ public class GalleryDetailParser {
public static GalleryComment parseComment(Element element) {
try {
GalleryComment comment = new GalleryComment();
// Id
Element a = element.previousElementSibling();
String name = a.attr("name");
comment.id = Integer.parseInt(StringUtils.trim(name).substring(1));
// Vote up and vote down
Element c4 = JsoupUtils.getElementByClass(element, "c4");
if (null != c4) {
Elements es = c4.children();
if (2 == es.size()) {
comment.voteUp = !TextUtils.isEmpty(StringUtils.trim(es.get(0).attr("style")));
comment.voteDown = !TextUtils.isEmpty(StringUtils.trim(es.get(1).attr("style")));
}
}
// Vote state
Element c7 = JsoupUtils.getElementByClass(element, "c7");
if (null != c7) {
comment.voteState = StringUtils.trim(c7.text());
}
// Score
Element c5 = JsoupUtils.getElementByClass(element, "c5");
if (null != c5) {
Elements es = c5.children();
if (!es.isEmpty()) {
comment.score = NumberUtils.parseIntSafely(StringUtils.trim(es.get(0).text()), 0);
}
}
// time
Element c3 = JsoupUtils.getElementByClass(element, "c3");
String temp = c3.ownText();
temp = temp.substring("Posted on ".length(), temp.length() - " by:  ".length());
comment.time = WEB_COMMENT_DATE_FORMAT.parse(temp).getTime();
// user
comment.user = c3.child(0).text();
// comment
comment.comment = JsoupUtils.getElementByClass(element, "c6").html();
return comment;
} catch (Exception e) {
@@ -0,0 +1,41 @@
/*
* Copyright 2016 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.client.parser;
import org.json.JSONException;
import org.json.JSONObject;
public class VoteCommentParser {
public static class Result {
public long id;
public int score;
public int vote;
public int expectVote;
}
// {"comment_id":1253922,"comment_score":-19,"comment_vote":0}
public static Result parse(String body, int vote) throws JSONException {
Result result = new Result();
JSONObject jo = new JSONObject(body);
result.id = jo.getLong("comment_id");
result.score = jo.getInt("comment_score");
result.vote = jo.getInt("comment_vote");
result.expectVote = vote;
return result;
}
}
@@ -25,7 +25,6 @@ import com.hippo.ehviewer.Analytics;
import com.hippo.ehviewer.EhApplication;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.Settings;
import com.hippo.ehviewer.UrlOpener;
import com.hippo.ehviewer.ui.CommonOperations;
import com.hippo.util.ActivityHelper;
@@ -34,11 +33,6 @@ public class AboutFragment extends PreferenceFragment
Preference.OnPreferenceClickListener {
private static final String KEY_AUTHOR = "author";
private static final String KEY_GOOGLE_PLUS = "google_plus";
private static final String KEY_WEBSITE = "website";
private static final String KEY_SOURCE = "source";
private static final String KEY_CHANGELOG = "changelog";
private static final String KEY_LICENSE = "license";
private static final String KEY_DONATE = "donate";
private static final String KEY_CHECK_FOR_UPDATES = "check_for_updates";
@@ -48,11 +42,7 @@ public class AboutFragment extends PreferenceFragment
addPreferencesFromResource(R.xml.about_settings);
Preference author = findPreference(KEY_AUTHOR);
Preference googlePlus = findPreference(KEY_GOOGLE_PLUS);
Preference enableAnalytics = findPreference(Settings.KEY_ENABLE_ANALYTICS);
Preference website = findPreference(KEY_WEBSITE);
Preference source = findPreference(KEY_SOURCE);
Preference changelog = findPreference(KEY_CHANGELOG);
Preference donate = findPreference(KEY_DONATE);
Preference checkForUpdate = findPreference(KEY_CHECK_FOR_UPDATES);
@@ -60,10 +50,6 @@ public class AboutFragment extends PreferenceFragment
donate.setSummary(getString(R.string.settings_about_donate_summary).replace('$', '@'));
author.setOnPreferenceClickListener(this);
googlePlus.setOnPreferenceClickListener(this);
website.setOnPreferenceClickListener(this);
source.setOnPreferenceClickListener(this);
changelog.setOnPreferenceClickListener(this);
donate.setOnPreferenceClickListener(this);
checkForUpdate.setOnPreferenceClickListener(this);
@@ -88,18 +74,6 @@ public class AboutFragment extends PreferenceFragment
if (KEY_AUTHOR.equals(key)) {
ActivityHelper.sendEmail(getActivity(), EhApplication.getDeveloperEmail(),
"About EhViewer", null);
} else if (KEY_GOOGLE_PLUS.equals(key)) {
UrlOpener.openUrl(getActivity(), "https://plus.google.com/communities/103823982034655188459",
false, true);
} else if (KEY_WEBSITE.equals(key)) {
UrlOpener.openUrl(getActivity(), "http://www.ehviewer.com",
false, true);
} else if (KEY_SOURCE.equals(key)) {
UrlOpener.openUrl(getActivity(), "https://github.com/seven332/EhViewer",
false, true);
} else if (KEY_CHANGELOG.equals(key)) {
UrlOpener.openUrl(getActivity(), "http://www.ehviewer.com/changlog",
false, true);
} else if (KEY_DONATE.equals(key)) {
new AlertDialog.Builder(getActivity())
.setTitle(R.string.settings_about_donate)
@@ -476,7 +476,7 @@ public class FavoritesScene extends BaseScene implements
AlertDialog.Builder builder = new AlertDialog.Builder(context);
context = builder.getContext();
final LayoutInflater inflater = LayoutInflater.from(context);
EasyRecyclerView rv = (EasyRecyclerView) inflater.inflate(R.layout.dialog_favorite_info, null);
EasyRecyclerView rv = (EasyRecyclerView) inflater.inflate(R.layout.dialog_recycler_view, null);
rv.setAdapter(new InfoAdapter(inflater));
rv.setLayoutManager(new LinearLayoutManager(context));
LinearDividerItemDecoration decoration = new LinearDividerItemDecoration(
@@ -17,25 +17,36 @@
package com.hippo.ehviewer.ui.scene;
import android.animation.Animator;
import android.annotation.TargetApi;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.style.ClickableSpan;
import android.text.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan;
import android.text.style.StyleSpan;
import android.text.style.URLSpan;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewAnimationUtils;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
@@ -50,7 +61,9 @@ import com.hippo.ehviewer.client.EhClient;
import com.hippo.ehviewer.client.EhRequest;
import com.hippo.ehviewer.client.EhUrl;
import com.hippo.ehviewer.client.data.GalleryComment;
import com.hippo.ehviewer.client.parser.VoteCommentParser;
import com.hippo.ehviewer.ui.MainActivity;
import com.hippo.reveal.ViewAnimationUtils;
import com.hippo.rippleold.RippleSalon;
import com.hippo.scene.SceneFragment;
import com.hippo.text.Html;
@@ -62,29 +75,48 @@ import com.hippo.view.ViewTransition;
import com.hippo.widget.LinkifyTextView;
import com.hippo.yorozuya.AnimationUtils;
import com.hippo.yorozuya.AssertUtils;
import com.hippo.yorozuya.IntList;
import com.hippo.yorozuya.LayoutUtils;
import com.hippo.yorozuya.ResourcesUtils;
import com.hippo.yorozuya.SimpleAnimatorListener;
import com.hippo.yorozuya.StringUtils;
import com.hippo.yorozuya.ViewUtils;
import java.util.ArrayList;
import java.util.List;
public final class GalleryCommentsScene extends ToolbarScene
implements EasyRecyclerView.OnItemClickListener,
EasyRecyclerView.OnItemLongClickListener, View.OnClickListener {
View.OnClickListener {
public static final String TAG = GalleryCommentsScene.class.getSimpleName();
public static final String KEY_API_UID = "api_uid";
public static final String KEY_API_KEY = "api_key";
public static final String KEY_GID = "gid";
public static final String KEY_TOKEN = "token";
public static final String KEY_COMMENTS = "comments";
private long mApiUid;
private String mApiKey;
private long mGid;
private String mToken;
@Nullable
private GalleryComment[] mComments;
@Nullable
private EasyRecyclerView mRecyclerView;
@Nullable
private FloatingActionButton mFab;
@Nullable
private View mEditPanel;
@Nullable
private ImageView mSendImage;
@Nullable
private EditText mEditText;
@Nullable
private CommentAdapter mAdapter;
@Nullable
private ViewTransition mViewTransition;
private boolean mInAnimation = false;
@@ -105,7 +137,9 @@ public final class GalleryCommentsScene extends ToolbarScene
return;
}
mGid = args.getLong(KEY_GID, -1);
mApiUid = args.getLong(KEY_API_UID, -1L);
mApiKey = args.getString(KEY_API_KEY);
mGid = args.getLong(KEY_GID, -1L);
mToken = args.getString(KEY_TOKEN, null);
Parcelable[] parcelables = args.getParcelableArray(KEY_COMMENTS);
if (parcelables instanceof GalleryComment[]) {
@@ -118,7 +152,9 @@ public final class GalleryCommentsScene extends ToolbarScene
}
private void onRestore(@NonNull Bundle savedInstanceState) {
mGid = savedInstanceState.getLong(KEY_GID, -1);
mApiUid = savedInstanceState.getLong(KEY_API_UID, -1L);
mApiKey = savedInstanceState.getString(KEY_API_KEY);
mGid = savedInstanceState.getLong(KEY_GID, -1L);
mToken = savedInstanceState.getString(KEY_TOKEN, null);
Parcelable[] parcelables = savedInstanceState.getParcelableArray(KEY_COMMENTS);
if (parcelables instanceof GalleryComment[]) {
@@ -129,6 +165,8 @@ public final class GalleryCommentsScene extends ToolbarScene
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putLong(KEY_API_UID, mApiUid);
outState.putString(KEY_API_KEY, mApiKey);
outState.putLong(KEY_GID, mGid);
outState.putString(KEY_TOKEN, mToken);
outState.putParcelableArray(KEY_COMMENTS, mComments);
@@ -139,7 +177,7 @@ public final class GalleryCommentsScene extends ToolbarScene
public View onCreateView3(LayoutInflater inflater,
@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.scene_gallery_comments, container, false);
mRecyclerView = (EasyRecyclerView) view.findViewById(R.id.recycler_view);
mRecyclerView = (EasyRecyclerView) ViewUtils.$$(view, R.id.recycler_view);
TextView tip = (TextView) ViewUtils.$$(view, R.id.tip);
mEditPanel = ViewUtils.$$(view, R.id.edit_panel);
mSendImage = (ImageView) ViewUtils.$$(mEditPanel, R.id.send);
@@ -167,20 +205,20 @@ public final class GalleryCommentsScene extends ToolbarScene
mRecyclerView.setSelector(RippleSalon.generateRippleDrawable(false));
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setOnItemClickListener(this);
mRecyclerView.setOnItemLongClickListener(this);
mRecyclerView.setPadding(mRecyclerView.getPaddingLeft(), mRecyclerView.getPaddingTop(),
mRecyclerView.getPaddingRight(), mRecyclerView.getPaddingBottom() + paddingBottomFab);
// Cancel change animator
RecyclerView.ItemAnimator itemAnimator = mRecyclerView.getItemAnimator();
if (itemAnimator instanceof DefaultItemAnimator) {
((DefaultItemAnimator) itemAnimator).setSupportsChangeAnimations(false);
}
mSendImage.setOnClickListener(this);
mFab.setOnClickListener(this);
mViewTransition = new ViewTransition(mRecyclerView, tip);
if (mComments == null || mComments.length <= 0) {
mViewTransition.showView(1);
} else {
mViewTransition.showView(0);
}
updateView(false);
return view;
}
@@ -194,6 +232,10 @@ public final class GalleryCommentsScene extends ToolbarScene
mRecyclerView = null;
}
mFab = null;
mEditPanel = null;
mSendImage = null;
mEditText = null;
mAdapter = null;
mViewTransition = null;
}
@@ -210,6 +252,140 @@ public final class GalleryCommentsScene extends ToolbarScene
onBackPressed();
}
private void voteComment(long id, int vote) {
Context context = getContext2();
MainActivity activity = getActivity2();
if (null == context || null == activity) {
return;
}
EhRequest request = new EhRequest()
.setMethod(EhClient.METHOD_VOTE_COMMENT)
.setArgs(mApiUid, mApiKey, mGid, mToken, id, vote)
.setCallback(new VoteCommentListener(context,
activity.getStageId(), getTag()));
EhApplication.getEhClient(context).execute(request);
}
private class InfoHolder extends RecyclerView.ViewHolder {
private final TextView key;
private final TextView value;
public InfoHolder(View itemView) {
super(itemView);
key = (TextView) ViewUtils.$$(itemView, R.id.key);
value = (TextView) ViewUtils.$$(itemView, R.id.value);
}
}
@SuppressLint("InflateParams")
public void showVoteStatusDialog(Context context, String voteStatus) {
String[] temp = StringUtils.split(voteStatus, ',');
final int length = temp.length;
final String[] userArray = new String[length];
final String[] voteArray = new String[length];
for (int i = 0; i < length; i++) {
String str = StringUtils.trim(temp[i]);
int index = str.lastIndexOf(' ');
if (index < 0) {
Log.d(TAG, "Something wrong happened about vote state");
userArray[i] = str;
voteArray[i] = "";
} else {
userArray[i] = StringUtils.trim(str.substring(0, index));
voteArray[i] = StringUtils.trim(str.substring(index + 1));
}
}
AlertDialog.Builder builder = new AlertDialog.Builder(context);
context = builder.getContext();
final LayoutInflater inflater = LayoutInflater.from(context);
EasyRecyclerView rv = (EasyRecyclerView) inflater.inflate(R.layout.dialog_recycler_view, null);
rv.setAdapter(new RecyclerView.Adapter<InfoHolder>() {
@Override
public InfoHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new InfoHolder(inflater.inflate(R.layout.item_favorite_info_data, parent, false));
}
@Override
public void onBindViewHolder(InfoHolder holder, int position) {
holder.key.setText(userArray[position]);
holder.value.setText(voteArray[position]);
}
@Override
public int getItemCount() {
return length;
}
});
rv.setLayoutManager(new LinearLayoutManager(context));
LinearDividerItemDecoration decoration = new LinearDividerItemDecoration(
LinearDividerItemDecoration.VERTICAL, context.getResources().getColor(R.color.divider),
LayoutUtils.dp2pix(context, 1));
decoration.setPadding(ResourcesUtils.getAttrDimensionPixelOffset(context, R.attr.dialogPreferredPadding));
rv.addItemDecoration(decoration);
rv.setSelector(RippleSalon.generateRippleDrawable(false));
rv.setClipToPadding(false);
builder.setView(rv).show();
}
private void showCommentDialog(int position) {
final Context context = getContext2();
if (null == context || null == mComments || position >= mComments.length || position < 0) {
return;
}
final GalleryComment comment = mComments[position];
List<String> menu = new ArrayList<>();
final IntList menuId = new IntList();
Resources resources = context.getResources();
if (0 == comment.id || mApiUid < 0) {
// 0 id is uploader comment, can't vote
// Not sign in, can't vote
menu.add(resources.getString(R.string.copy_comment_text));
menuId.add(R.id.copy);
} else {
menu.add(resources.getString(R.string.copy_comment_text));
menuId.add(R.id.copy);
menu.add(resources.getString(comment.voteUp ? R.string.cancel_vote_up : R.string.vote_up));
menuId.add(R.id.vote_up);
menu.add(resources.getString(comment.voteDown ? R.string.cancel_vote_down : R.string.vote_down));
menuId.add(R.id.vote_down);
}
if (!TextUtils.isEmpty(comment.voteState)) {
menu.add(resources.getString(R.string.check_vote_status));
menuId.add(R.id.check_vote_status);
}
new AlertDialog.Builder(context)
.setItems(menu.toArray(new String[menu.size()]), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which < 0 || which >= menuId.size()) {
return;
}
int id = menuId.get(which);
switch (id) {
case R.id.copy:
ClipboardManager cmb = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
cmb.setPrimaryClip(ClipData.newPlainText(null, comment.comment));
showTip(R.string.copied_to_clipboard, LENGTH_SHORT);
break;
case R.id.vote_up:
voteComment(comment.id, 1);
break;
case R.id.vote_down:
voteComment(comment.id, -1);
break;
case R.id.check_vote_status:
showVoteStatusDialog(context, comment.voteState);
break;
}
}
}).show();
}
@Override
public boolean onItemClick(EasyRecyclerView parent, View view, int position, long id) {
Activity activity = getActivity2();
@@ -228,16 +404,29 @@ public final class GalleryCommentsScene extends ToolbarScene
return true;
}
}
return false;
showCommentDialog(position);
return true;
}
@Override
public boolean onItemLongClick(EasyRecyclerView parent, View view, int position, long id) {
return false;
private void updateView(boolean animation) {
if (null == mViewTransition) {
return;
}
if (mComments == null || mComments.length <= 0) {
mViewTransition.showView(1, animation);
} else {
mViewTransition.showView(0, animation);
}
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void showEditPanelWithAnimationL() {
private void showEditPanelWithAnimation() {
if (null == mFab || null == mEditPanel) {
return;
}
mInAnimation = true;
mFab.setTranslationX(0.0f);
mFab.setTranslationY(0.0f);
@@ -255,10 +444,10 @@ public final class GalleryCommentsScene extends ToolbarScene
int halfW = mEditPanel.getWidth() / 2;
int halfH = mEditPanel.getHeight() / 2;
Animator animator = ViewAnimationUtils.createCircularReveal(mEditPanel, halfW, halfH, 0,
(float) Math.hypot(halfW, halfH)).setDuration(300);
(float) Math.hypot(halfW, halfH)).setDuration(300L);
animator.addListener(new SimpleAnimatorListener() {
@Override
public void onAnimationEnd(Animator animation) {
public void onAnimationEnd(Animator a) {
mInAnimation = false;
}
});
@@ -269,21 +458,22 @@ public final class GalleryCommentsScene extends ToolbarScene
private void showEditPanel(boolean animation) {
if (animation) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
showEditPanelWithAnimationL();
} else {
// TODO Add animation for pre-L
mFab.setVisibility(View.INVISIBLE);
mEditPanel.setVisibility(View.VISIBLE);
}
showEditPanelWithAnimation();
} else {
if (null == mFab || null == mEditPanel) {
return;
}
mFab.setVisibility(View.INVISIBLE);
mEditPanel.setVisibility(View.VISIBLE);
}
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void hideEditPanelWithAnimationL() {
private void hideEditPanelWithAnimation() {
if (null == mFab || null == mEditPanel) {
return;
}
mInAnimation = true;
int halfW = mEditPanel.getWidth() / 2;
int halfH = mEditPanel.getHeight() / 2;
@@ -291,7 +481,7 @@ public final class GalleryCommentsScene extends ToolbarScene
(float) Math.hypot(halfW, halfH), 0.0f).setDuration(300L);
animator.addListener(new SimpleAnimatorListener() {
@Override
public void onAnimationEnd(Animator animation) {
public void onAnimationEnd(Animator a) {
mEditPanel.setVisibility(View.GONE);
mFab.setVisibility(View.VISIBLE);
int fabStartX = mEditPanel.getLeft() + (mEditPanel.getWidth() / 2) - (mFab.getWidth() / 2);
@@ -315,14 +505,12 @@ public final class GalleryCommentsScene extends ToolbarScene
private void hideEditPanel(boolean animation) {
if (animation) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
hideEditPanelWithAnimationL();
} else {
// TODO Add animation for pre-L
mFab.setVisibility(View.VISIBLE);
mEditPanel.setVisibility(View.INVISIBLE);
}
hideEditPanelWithAnimation();
} else {
if (null == mFab || null == mEditPanel) {
return;
}
mFab.setVisibility(View.VISIBLE);
mEditPanel.setVisibility(View.INVISIBLE);
}
@@ -331,7 +519,7 @@ public final class GalleryCommentsScene extends ToolbarScene
@Nullable
private String getGalleryDetailUrl() {
if (mGid != -1 && mToken != null) {
return EhUrl.getGalleryDetailUrl(mGid, mToken, 0, true);
return EhUrl.getGalleryDetailUrl(mGid, mToken, 0, false);
} else {
return null;
}
@@ -341,7 +529,7 @@ public final class GalleryCommentsScene extends ToolbarScene
public void onClick(View v) {
Context context = getContext2();
MainActivity activity = getActivity2();
if (null == context || null == activity) {
if (null == context || null == activity || null == mEditText) {
return;
}
@@ -378,7 +566,7 @@ public final class GalleryCommentsScene extends ToolbarScene
if (mInAnimation) {
return;
}
if (mEditPanel.getVisibility() == View.VISIBLE) {
if (null != mEditPanel && mEditPanel.getVisibility() == View.VISIBLE) {
hideEditPanel(true);
} else {
finish();
@@ -387,9 +575,9 @@ public final class GalleryCommentsScene extends ToolbarScene
private class CommentHolder extends RecyclerView.ViewHolder {
public TextView user;
public TextView time;
public LinkifyTextView comment;
public final TextView user;
public final TextView time;
public final LinkifyTextView comment;
public CommentHolder(View itemView) {
super(itemView);
@@ -413,18 +601,35 @@ public final class GalleryCommentsScene extends ToolbarScene
return new CommentHolder(mInflater.inflate(R.layout.item_gallery_comment, parent, false));
}
public CharSequence generateComment(Context context, TextView textView, GalleryComment comment) {
SpannableStringBuilder ssb = Html.fromHtml(comment.comment, new URLImageGetter(textView,
EhApplication.getConaco(context)), null);
if (0 != comment.id && 0 != comment.score) {
int score = comment.score;
String scoreString = score > 0 ? "+" + score : Integer.toString(score);
SpannableString ss = new SpannableString(scoreString);
ss.setSpan(new RelativeSizeSpan(0.8f), 0, scoreString.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
ss.setSpan(new StyleSpan(Typeface.BOLD), 0, scoreString.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
ss.setSpan(new ForegroundColorSpan(context.getResources().getColor(R.color.secondary_text_default_light))
, 0, scoreString.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
ssb.append(" ").append(ss);
}
return TextUrl.handleTextUrl(ssb);
}
@Override
public void onBindViewHolder(CommentHolder holder, int position) {
Context context = getContext2();
if (null == context) {
if (null == context || null == mComments) {
return;
}
GalleryComment comment = mComments[position];
holder.user.setText(comment.user);
holder.time.setText(ReadableTime.getTimeAgo(comment.time));
holder.comment.setText(TextUrl.handleTextUrl(Html.fromHtml(comment.comment,
new URLImageGetter(holder.comment, EhApplication.getConaco(context)), null)));
holder.comment.setText(generateComment(context, holder.comment, comment));
}
@Override
@@ -434,6 +639,10 @@ public final class GalleryCommentsScene extends ToolbarScene
}
private void onCommentGallerySuccess(GalleryComment[] result) {
if (null == mAdapter) {
return;
}
mComments = result;
mAdapter.notifyDataSetChanged();
Bundle re = new Bundle();
@@ -444,6 +653,45 @@ public final class GalleryCommentsScene extends ToolbarScene
if (mEditText != null) {
mEditText.setText("");
}
updateView(true);
}
private void onVoteCommentSuccess(VoteCommentParser.Result result) {
if (null == mAdapter || null == mComments) {
return;
}
int position = -1;
for (int i = 0, n = mComments.length; i < n; i++) {
GalleryComment comment = mComments[i];
if (comment.id == result.id) {
position = i;
break;
}
}
if (-1 == position) {
Log.d(TAG, "Can't find comment with id " + result.id);
return;
}
// Update comment
GalleryComment comment = mComments[position];
comment.score = result.score;
if (result.expectVote > 0) {
comment.voteUp = 0 != result.vote;
comment.voteDown = false;
} else {
comment.voteDown = 0 != result.vote;
comment.voteUp = false;
}
mAdapter.notifyItemChanged(position);
Bundle re = new Bundle();
re.putParcelableArray(KEY_COMMENTS, mComments);
setResult(SceneFragment.RESULT_OK, re);
}
private static class CommentGalleryListener extends EhCallback<GalleryCommentsScene, GalleryComment[]> {
@@ -476,4 +724,37 @@ public final class GalleryCommentsScene extends ToolbarScene
return scene instanceof GalleryCommentsScene;
}
}
private static class VoteCommentListener extends EhCallback<GalleryCommentsScene, VoteCommentParser.Result> {
public VoteCommentListener(Context context, int stageId, String sceneTag) {
super(context, stageId, sceneTag);
}
@Override
public void onSuccess(VoteCommentParser.Result result) {
showTip(result.expectVote > 0 ?
(0 != result.vote ? R.string.vote_up_successfully : R.string.cancel_vote_up_successfully) :
(0 != result.vote ? R.string.vote_down_successfully : R.string.cancel_vote_down_successfully),
LENGTH_SHORT);
GalleryCommentsScene scene = getScene();
if (scene != null) {
scene.onVoteCommentSuccess(result);
}
}
@Override
public void onFailure(Exception e) {
showTip(R.string.vote_failed, LENGTH_SHORT);
}
@Override
public void onCancel() {}
@Override
public boolean isInstance(SceneFragment scene) {
return scene instanceof GalleryCommentsScene;
}
}
}
@@ -36,6 +36,7 @@ import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.PopupMenu;
import android.text.TextUtils;
@@ -45,7 +46,6 @@ import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewAnimationUtils;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
@@ -79,6 +79,7 @@ import com.hippo.ehviewer.ui.CommonOperations;
import com.hippo.ehviewer.ui.GalleryActivity;
import com.hippo.ehviewer.ui.MainActivity;
import com.hippo.ehviewer.ui.annotation.WholeLifeCircle;
import com.hippo.reveal.ViewAnimationUtils;
import com.hippo.rippleold.RippleSalon;
import com.hippo.scene.Announcer;
import com.hippo.scene.SceneFragment;
@@ -602,7 +603,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
private boolean request() {
Context context = getContext2();
MainActivity activity = getActivity2();
String url = getGalleryDetailUrl(true);
String url = getGalleryDetailUrl(false);
if (null == context || null == activity || null == url) {
return false;
}
@@ -639,7 +640,6 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
setActionDrawable(mSimilar, similar);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private boolean createCircularReveal() {
if (mColorBg == null) {
return false;
@@ -647,7 +647,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
int w = mColorBg.getWidth();
int h = mColorBg.getHeight();
if (mColorBg.isAttachedToWindow() && w != 0 && h != 0) {
if (ViewCompat.isAttachedToWindow(mColorBg) && w != 0 && h != 0) {
ViewAnimationUtils.createCircularReveal(mColorBg, w / 2, h / 2, 0,
(float) Math.hypot(w / 2, h / 2)).setDuration(300).start();
return true;
@@ -692,8 +692,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
break;
}
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP &&
(oldState == STATE_INIT || oldState == STATE_FAILED || oldState == STATE_REFRESH) &&
if ((oldState == STATE_INIT || oldState == STATE_FAILED || oldState == STATE_REFRESH) &&
(state == STATE_NORMAL || state == STATE_REFRESH_HEADER)) {
if (!createCircularReveal()) {
SimpleHandler.getInstance().post(new Runnable() {
@@ -1128,6 +1127,10 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
if (mGalleryDetail == null) {
return;
}
if (mGalleryDetail.apiUid < 0) {
showTip(R.string.sign_in_first, LENGTH_SHORT);
return;
}
RateDialogHelper helper = new RateDialogHelper();
Dialog dialog = new AlertDialog.Builder(context)
.setTitle(R.string.rate)
@@ -1143,6 +1146,8 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
return;
}
Bundle args = new Bundle();
args.putLong(GalleryCommentsScene.KEY_API_UID, mGalleryDetail.apiUid);
args.putString(GalleryCommentsScene.KEY_API_KEY, mGalleryDetail.apiKey);
args.putLong(GalleryCommentsScene.KEY_GID, mGalleryDetail.gid);
args.putString(GalleryCommentsScene.KEY_TOKEN, mGalleryDetail.token);
args.putParcelableArray(GalleryCommentsScene.KEY_COMMENTS, mGalleryDetail.comments);
@@ -1690,7 +1695,8 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
EhRequest request = new EhRequest()
.setMethod(EhClient.METHOD_GET_RATE_GALLERY)
.setArgs(mGalleryDetail.gid, mGalleryDetail.token, mRatingBar.getRating())
.setArgs(mGalleryDetail.apiUid, mGalleryDetail.apiKey,
mGalleryDetail.gid, mGalleryDetail.token, mRatingBar.getRating())
.setCallback(new RateGalleryListener(context,
activity.getStageId(), getTag(), mGalleryDetail.gid));
EhApplication.getEhClient(context).execute(request);
@@ -0,0 +1,65 @@
/*
* Copyright 2016 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.preference;
import android.content.Context;
import android.content.res.TypedArray;
import android.preference.Preference;
import android.util.AttributeSet;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.UrlOpener;
public class UrlPreference extends Preference {
private String mUrl;
public UrlPreference(Context context) {
super(context);
init(context, null, 0, 0);
}
public UrlPreference(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs, 0, 0);
}
public UrlPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs, defStyleAttr, 0);
}
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.UrlPreference, defStyleAttr, defStyleRes);
mUrl = a.getString(R.styleable.UrlPreference_url);
a.recycle();
}
@Override
public CharSequence getSummary() {
if (null != mUrl) {
return mUrl;
} else {
return super.getSummary();
}
}
@Override
protected void onClick() {
UrlOpener.openUrl(getContext(), mUrl, true, true);
}
}
@@ -0,0 +1,24 @@
/*
* Copyright 2016 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.reveal;
public interface Reveal {
void setRevealEnable(boolean enable);
void setReveal(int centerX, int centerY, float radius);
}
@@ -0,0 +1,87 @@
/*
* Copyright 2016 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.reveal;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Path;
import android.util.AttributeSet;
import android.widget.LinearLayout;
public class RevealLinearLayout extends LinearLayout implements Reveal {
private final Path mRevealPath = new Path();
private boolean mReveal;
private int mCenterX;
private int mCenterY;
private float mRadius;
public RevealLinearLayout(Context context) {
super(context);
init();
}
public RevealLinearLayout(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public RevealLinearLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
private void init() {
if (!ViewAnimationUtils.API_SUPPORT_CIRCULAR_REVEAL) {
setWillNotDraw(false);
}
}
@Override
public void setRevealEnable(boolean enable) {
mReveal = enable;
invalidate();
}
@Override
public void setReveal(int centerX, int centerY, float radius) {
mCenterX = centerX;
mCenterY = centerY;
mRadius = radius;
invalidate();
}
@Override
public void draw(Canvas canvas) {
boolean reveal = mReveal;
int saveCount = 0;
if (reveal) {
saveCount = canvas.save();
Path path = mRevealPath;
path.reset();
path.addCircle(mCenterX, mCenterY, mRadius, Path.Direction.CW);
canvas.clipPath(path);
}
super.draw(canvas);
if (reveal) {
canvas.restoreToCount(saveCount);
}
}
}
@@ -0,0 +1,78 @@
/*
* Copyright 2016 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.reveal;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Path;
import android.util.AttributeSet;
import android.view.View;
public class RevealView extends View implements Reveal {
private final Path mRevealPath = new Path();
private boolean mReveal;
private int mCenterX;
private int mCenterY;
private float mRadius;
public RevealView(Context context) {
super(context);
}
public RevealView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public RevealView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
public void setRevealEnable(boolean enable) {
mReveal = enable;
invalidate();
}
@Override
public void setReveal(int centerX, int centerY, float radius) {
mCenterX = centerX;
mCenterY = centerY;
mRadius = radius;
invalidate();
}
@Override
public void draw(Canvas canvas) {
boolean reveal = mReveal;
int saveCount = 0;
if (reveal) {
saveCount = canvas.save();
Path path = mRevealPath;
path.reset();
path.addCircle(mCenterX, mCenterY, mRadius, Path.Direction.CW);
canvas.clipPath(path);
}
super.draw(canvas);
if (reveal) {
canvas.restoreToCount(saveCount);
}
}
}
@@ -0,0 +1,107 @@
/*
* Copyright 2016 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.reveal;
import android.animation.Animator;
import android.animation.ValueAnimator;
import android.annotation.TargetApi;
import android.os.Build;
import android.view.View;
import com.hippo.yorozuya.SimpleAnimatorListener;
public final class ViewAnimationUtils {
private ViewAnimationUtils() {}
public static final boolean API_SUPPORT_CIRCULAR_REVEAL =
Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
// http://developer.android.com/guide/topics/graphics/hardware-accel.html#unsupported
public static final boolean API_SUPPORT_CANVAS_CLIP_PATH =
Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2;
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static Animator createCircularReveal(View view,
int centerX, int centerY, float startRadius, float endRadius) {
if (API_SUPPORT_CIRCULAR_REVEAL) {
return android.view.ViewAnimationUtils.createCircularReveal(
view, centerX, centerY, startRadius, endRadius);
} else if (view instanceof Reveal){
return createRevealAnimator((Reveal) view, centerX, centerY,
startRadius, endRadius);
} else {
throw new IllegalStateException("Only View implements CircularReveal or" +
" api >= 21 can create circular reveal");
}
}
private static Animator createRevealAnimator(Reveal reveal, int centerX, int centerY,
float startRadius, float endRadius) {
ValueAnimator animator = ValueAnimator.ofFloat(startRadius, endRadius);
animator.addUpdateListener(new RevealAnimatorUpdateListener(reveal, centerX, centerY));
animator.addListener(new RevealAnimatorListener(reveal));
return animator;
}
private static class RevealAnimatorUpdateListener
implements ValueAnimator.AnimatorUpdateListener {
private final Reveal mReveal;
private final int mCenterX;
private final int mCenterY;
public RevealAnimatorUpdateListener(Reveal reveal, int centerX, int centerY) {
mReveal = reveal;
mCenterX = centerX;
mCenterY = centerY;
}
@Override
public void onAnimationUpdate(ValueAnimator animation) {
Object value = animation.getAnimatedValue();
if (value instanceof Float) {
mReveal.setReveal(mCenterX, mCenterY, (Float) value);
}
}
}
private static class RevealAnimatorListener extends SimpleAnimatorListener {
private final Reveal mReveal;
private final View mView;
public RevealAnimatorListener(Reveal reveal) {
mReveal = reveal;
mView = (View) reveal;
}
@Override
public void onAnimationStart(Animator animation) {
if (!API_SUPPORT_CANVAS_CLIP_PATH) {
mView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
mReveal.setRevealEnable(true);
}
@Override
public void onAnimationEnd(Animator animation) {
mReveal.setRevealEnable(false);
if (!API_SUPPORT_CANVAS_CLIP_PATH) {
mView.setLayerType(View.LAYER_TYPE_NONE, null);
}
}
}
}
+2 -2
View File
@@ -136,7 +136,7 @@ public class Html {
*
* <p>This uses TagSoup to handle real HTML, including all of the brokenness found in the wild.
*/
public static Spanned fromHtml(String source, ImageGetter imageGetter,
public static SpannableStringBuilder fromHtml(String source, ImageGetter imageGetter,
TagHandler tagHandler) {
Parser parser = new Parser();
try {
@@ -462,7 +462,7 @@ class HtmlToSpannedConverter implements ContentHandler {
mReader = parser;
}
public Spanned convert() {
public SpannableStringBuilder convert() {
mReader.setContentHandler(this);
try {
+13 -2
View File
@@ -117,6 +117,7 @@ void* GIF_decode(JNIEnv* env, PatchHeadInputStream* patch_head_input_stream, boo
GIF* gif = NULL;
GifFileType* gif_file = NULL;
void* buffer = NULL;
void*shown_buffer = NULL;
GIF_FRAME_INFO* frame_info_array = NULL;
int i;
@@ -140,8 +141,11 @@ void* GIF_decode(JNIEnv* env, PatchHeadInputStream* patch_head_input_stream, boo
// Buffer
buffer = malloc(gif_file->SWidth * gif_file->SHeight * sizeof(RGBA));
if (buffer == NULL) {
shown_buffer = malloc(gif_file->SWidth * gif_file->SHeight * sizeof(RGBA));
if (buffer == NULL || shown_buffer == NULL) {
WTF_OM;
free(buffer);
free(shown_buffer);
DGifCloseFile(gif_file, &error_code);
free(gif);
close_patch_head_input_stream(get_env(), patch_head_input_stream);
@@ -226,6 +230,7 @@ void* GIF_decode(JNIEnv* env, PatchHeadInputStream* patch_head_input_stream, boo
gif->buffer = buffer;
gif->buffer_index = -1;
gif->backup = NULL;
gif->shown_buffer = shown_buffer;
GIF_advance(gif);
@@ -293,7 +298,7 @@ void GIF_render(GIF* gif, int src_x, int src_y,
void* dst, int dst_w, int dst_h, int dst_x, int dst_y,
int width, int height, bool fill_blank, int default_color)
{
copy_pixels(gif->buffer, gif->gif_file->SWidth, gif->gif_file->SHeight, src_x, src_y,
copy_pixels(gif->shown_buffer, gif->gif_file->SWidth, gif->gif_file->SHeight, src_x, src_y,
dst, dst_w, dst_h, dst_x, dst_y,
width, height, fill_blank, default_color);
}
@@ -454,6 +459,9 @@ void GIF_advance(GIF* gif)
blend(gif->gif_file, index, gif->buffer, frame_info.tran);
// Copy to shown buffer
memcpy(gif->shown_buffer, gif->buffer, (size_t) (gif->gif_file->SWidth * gif->gif_file->SHeight * 4));
gif->buffer_index = index;
}
@@ -490,6 +498,9 @@ void GIF_recycle(GIF* gif)
free(gif->backup);
gif->backup = NULL;
free(gif->shown_buffer);
gif->shown_buffer = NULL;
if (gif->patch_head_input_stream != NULL) {
close_patch_head_input_stream(get_env(), gif->patch_head_input_stream);
destroy_patch_head_input_stream(get_env(), &gif->patch_head_input_stream);
+2
View File
@@ -53,6 +53,8 @@ typedef struct
int buffer_index;
void* backup;
bool partially;
// Use extra buffer to avoid blink
void* shown_buffer;
PatchHeadInputStream* patch_head_input_stream;
} GIF;
@@ -26,7 +26,7 @@
android:layout_height="match_parent"
android:orientation="vertical">
<View
<com.hippo.reveal.RevealView
android:id="@+id/color_bg"
android:layout_width="match_parent"
android:layout_height="0dp"
@@ -47,14 +47,6 @@
android:layout_below="@id/title"
android:layout_marginTop="2dp"/>
<com.hippo.ehviewer.widget.SimpleRatingView
android:id="@+id/rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/title"
android:layout_below="@id/uploader"
android:layout_marginTop="2dp"/>
<TextView
android:id="@+id/category"
style="@style/CardMessage"
@@ -70,6 +62,14 @@
android:textColor="@android:color/white"
android:textAllCaps="true"/>
<com.hippo.ehviewer.widget.SimpleRatingView
android:id="@+id/rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/title"
android:layout_above="@id/category"
android:layout_marginBottom="4dp"/>
<TextView
android:id="@+id/posted"
style="@style/CardMessage"
@@ -38,7 +38,7 @@
android:text="@string/no_one_comments_gallery"
style="@style/TextAppearance.AppCompat.Medium"/>
<LinearLayout
<com.hippo.reveal.RevealLinearLayout
android:id="@+id/edit_panel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@@ -79,7 +79,7 @@
app:srcCompat="@drawable/v_send_dark_x24"/>
</LinearLayout>
</LinearLayout>
</com.hippo.reveal.RevealLinearLayout>
<com.hippo.widget.FabLayout
android:layout_width="match_parent"
@@ -36,6 +36,7 @@
<string name="display_name_dialog_title">输入昵称</string>
<string name="display_name">昵称</string>
<string name="display_name_is_empty">昵称为空</string>
<string name="sign_in_first">请先登录</string>
<string name="default_display_name">Little Hippo</string>
@@ -237,6 +238,17 @@
<string name="no_one_comments_gallery">暂时没有评论</string>
<string name="comment_successfully">评论成功</string>
<string name="comment_failed">评论失败</string>
<string name="copy_comment_text">复制评论文字</string>
<string name="vote_up">深表赞同</string>
<string name="cancel_vote_up">不再深表赞同</string>
<string name="vote_down">垃圾评论</string>
<string name="cancel_vote_down">不是垃圾评论</string>
<string name="vote_up_successfully">已深表赞同</string>
<string name="cancel_vote_up_successfully">已不再深表赞同</string>
<string name="vote_down_successfully">已钦定为垃圾评论</string>
<string name="cancel_vote_down_successfully">已不再钦定为垃圾评论</string>
<string name="vote_failed">投票失败</string>
<string name="check_vote_status">查看投票情况</string>
<!-- Gallery Previews -->
<string name="gallery_previews">画廊预览</string>
@@ -423,6 +435,7 @@
<string name="settings_about_website">网站</string>
<string name="settings_about_source">源码</string>
<string name="settings_about_changelog">更新日志</string>
<string name="settings_about_help">帮助</string>
<string name="settings_about_license">开源许可</string>
<string name="settings_about_license_summary">EhViewer 的诞生离不开许多开源项目</string>
<string name="settings_about_donate">捐赠</string>
@@ -36,6 +36,7 @@
<string name="display_name_dialog_title">輸入暱稱</string>
<string name="display_name">暱稱</string>
<string name="display_name_is_empty">暱稱為空</string>
<string name="sign_in_first">請先登錄</string>
<string name="default_display_name">Little Hippo</string>
@@ -237,6 +238,17 @@
<string name="no_one_comments_gallery">暫時沒有評論</string>
<string name="comment_successfully">評論成功</string>
<string name="comment_failed">評論失敗</string>
<string name="copy_comment_text">複製評論文字</string>
<string name="vote_up">深表贊同</string>
<string name="cancel_vote_up">不再深表贊同</string>
<string name="vote_down">垃圾評論</string>
<string name="cancel_vote_down">不是垃圾評論</string>
<string name="vote_up_successfully">已深表贊同</string>
<string name="cancel_vote_up_successfully">已不再深表贊同</string>
<string name="vote_down_successfully">已欽定為垃圾評論</string>
<string name="cancel_vote_down_successfully">已不再欽定為垃圾評論</string>
<string name="vote_failed">投票失敗</string>
<string name="check_vote_status">查看投票情況</string>
<!-- Gallery Previews -->
<string name="gallery_previews">畫廊預覽</string>
@@ -423,6 +435,7 @@
<string name="settings_about_website">網站</string>
<string name="settings_about_source">源碼</string>
<string name="settings_about_changelog">更新日誌</string>
<string name="settings_about_help">幫助</string>
<string name="settings_about_license">開源許可</string>
<string name="settings_about_license_summary">EhViewer 的誕生離不開許多開源項目</string>
<string name="settings_about_donate">捐贈</string>
@@ -36,6 +36,7 @@
<string name="display_name_dialog_title">輸入暱稱</string>
<string name="display_name">暱稱</string>
<string name="display_name_is_empty">暱稱為空</string>
<string name="sign_in_first">請先登入</string>
<string name="default_display_name">Little Hippo</string>
@@ -237,6 +238,17 @@
<string name="no_one_comments_gallery">暫時沒有評論</string>
<string name="comment_successfully">評論成功</string>
<string name="comment_failed">評論失敗</string>
<string name="copy_comment_text">複製評論文字</string>
<string name="vote_up">深表贊同</string>
<string name="cancel_vote_up">不再深表贊同</string>
<string name="vote_down">垃圾評論</string>
<string name="cancel_vote_down">不是垃圾評論</string>
<string name="vote_up_successfully">已深表贊同</string>
<string name="cancel_vote_up_successfully">已不再深表贊同</string>
<string name="vote_down_successfully">已欽定為垃圾評論</string>
<string name="cancel_vote_down_successfully">已不再欽定為垃圾評論</string>
<string name="vote_failed">投票失敗</string>
<string name="check_vote_status">檢視投票情況</string>
<!-- Gallery Previews -->
<string name="gallery_previews">畫廊預覽</string>
@@ -423,6 +435,7 @@
<string name="settings_about_website">網站</string>
<string name="settings_about_source">原始碼</string>
<string name="settings_about_changelog">更新日誌</string>
<string name="settings_about_help">幫助</string>
<string name="settings_about_license">開源許可</string>
<string name="settings_about_license_summary">EhViewer 的誕生離不開許多開源專案</string>
<string name="settings_about_donate">捐贈</string>
+1 -2
View File
@@ -119,12 +119,11 @@
<item>3</item>
<item>4</item>
</string-array>
<string-array name="page_menu_entries">
<item>@string/page_menu_refresh</item>
<item>@string/page_menu_share</item>
<item>@string/page_menu_save</item>
<item>@string/page_menu_add_bookmark</item>
</string-array>
<string-array name="gallery_list_menu_entries">
+4
View File
@@ -133,4 +133,8 @@
<attr name="activity" format="string"/>
</declare-styleable>
<declare-styleable name="UrlPreference">
<attr name="url" format="string"/>
</declare-styleable>
</resources>
+5
View File
@@ -22,4 +22,9 @@
<item name="fragment_tag" type="id"/>
<item name="copy" type="id"/>
<item name="vote_up" type="id"/>
<item name="vote_down" type="id"/>
<item name="check_vote_status" type="id"/>
</resources>
+13 -4
View File
@@ -52,6 +52,7 @@
<string name="display_name_dialog_title">Enter Display Name</string>
<string name="display_name">Display name</string>
<string name="display_name_is_empty">Display name is empty</string>
<string name="sign_in_first">Please sign in first</string>
<string name="default_display_name">Little Hippo</string>
@@ -280,6 +281,17 @@
<string name="no_one_comments_gallery">No one comments on this gallery</string>
<string name="comment_successfully">Comment successfully</string>
<string name="comment_failed">Comment failed</string>
<string name="copy_comment_text">Copy comment text</string>
<string name="vote_up">Vote up</string>
<string name="cancel_vote_up">Cancel up-vote</string>
<string name="vote_down">Vote down</string>
<string name="cancel_vote_down">Cancel down-vote</string>
<string name="vote_up_successfully">Vote up successfully</string>
<string name="cancel_vote_up_successfully">Cancel up-vote successfully</string>
<string name="vote_down_successfully">Vote down successfully</string>
<string name="cancel_vote_down_successfully">Cancel down-vote successfully</string>
<string name="vote_failed">Vote failed</string>
<string name="check_vote_status">Check vote status</string>
<!-- Gallery Previews -->
<string name="gallery_previews">Gallery Previews</string>
@@ -463,13 +475,10 @@
<string name="settings_about_author">Author</string>
<string name="settings_about_author_summary" translatable="false">Hippo &lt;ehviewersu$gmail.com&gt;</string>
<string name="settings_about_google_plus">Google+ Community</string>
<string name="settings_about_google_plus_summary" translatable="false">https://plus.google.com/communities/103823982034655188459</string>
<string name="settings_about_website">Website</string>
<string name="settings_about_website_summary" translatable="false">http://www.ehviewer.com</string>
<string name="settings_about_source">Source</string>
<string name="settings_about_source_summary" translatable="false">https://github.com/seven332/EhViewer</string>
<string name="settings_about_changelog">Changelog</string>
<string name="settings_about_changelog_summary" translatable="false">http://www.ehviewer.com/changlog</string>
<string name="settings_about_help">Help</string>
<string name="settings_about_license">License</string>
<string name="settings_about_license_summary">EhViewer is made possible by many open source projects</string>
<string name="settings_about_donate">Donate</string>
+13 -8
View File
@@ -23,25 +23,30 @@
android:key="author"
android:title="@string/settings_about_author"/>
<Preference
<com.hippo.preference.UrlPreference
android:key="google_plus"
android:title="@string/settings_about_google_plus"
android:summary="@string/settings_about_google_plus_summary"/>
app:url="https://plus.google.com/communities/103823982034655188459"/>
<Preference
<com.hippo.preference.UrlPreference
android:key="website"
android:title="@string/settings_about_website"
android:summary="@string/settings_about_website_summary"/>
app:url="http://www.ehviewer.com"/>
<Preference
<com.hippo.preference.UrlPreference
android:key="source"
android:title="@string/settings_about_source"
android:summary="@string/settings_about_source_summary"/>
app:url="https://github.com/seven332/EhViewer"/>
<Preference
<com.hippo.preference.UrlPreference
android:key="changelog"
android:title="@string/settings_about_changelog"
android:summary="@string/settings_about_changelog_summary"/>
app:url="http://www.ehviewer.com/changelog"/>
<com.hippo.preference.UrlPreference
android:key="help"
android:title="@string/settings_about_help"
app:url="http://www.ehviewer.com/help"/>
<com.hippo.preference.ActivityPreference
android:key="license"
+23
View File
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2016 Hippo Seven
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<full-backup-content>
<include domain="database" path="eh.db"/>
<include domain="database" path="search_database.db"/>
</full-backup-content>