Skip to content

Commit

Permalink
Handle link click in topic detail and comments
Browse files Browse the repository at this point in the history
ref #61
  • Loading branch information
mzlogin committed Jan 1, 2019
1 parent bbae0fd commit f2155c8
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 13 deletions.
19 changes: 10 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apply plugin: 'com.android.application'

def Properties mVersionProps = getVersionProperties()
Properties mVersionProps = getVersionProperties()

def mVersionCode = getVersionCode()

Expand All @@ -12,7 +12,7 @@ android {
buildToolsVersion '28.0.2'
defaultConfig {
applicationId "org.mazhuang.guanggoo"
minSdkVersion 15
minSdkVersion 16
targetSdkVersion 28
versionCode mVersionCode
versionName mVersionName
Expand Down Expand Up @@ -46,7 +46,7 @@ android {

}
release {
def Properties signingProps = getSignProperties()
Properties signingProps = getSignProperties()
if (signingProps != null) {
storeFile file(signingProps['STORE_FILE'])
storePassword signingProps['STORE_PASSWORD']
Expand Down Expand Up @@ -80,25 +80,25 @@ android {
}

def getVersionProperties() {
def Properties versionProps = new Properties()
Properties versionProps = new Properties()
versionProps.load(new FileInputStream(file('../config/version.properties')))
return versionProps
}

static def getVersionCode() {
try {
String output = 'git rev-list HEAD --count '.execute().text.trim()
return Integer.valueOf(output);
return Integer.valueOf(output)
} catch (Exception e) {
System.out.println(e.getMessage());
System.out.println(e.getMessage())
}
return 1;
return 1
}

def getSignProperties() {
File signingPropertiesFile = file('../config/signing.properties')
if (signingPropertiesFile.exists()) {
def Properties signingProperties = new Properties()
Properties signingProperties = new Properties()
signingProperties.load(new FileInputStream(signingPropertiesFile))
if (signingProperties.containsKey('STORE_FILE') &&
signingProperties.containsKey('STORE_PASSWORD') &&
Expand All @@ -125,7 +125,8 @@ dependencies {
implementation 'com.jakewharton:butterknife:8.8.1'
implementation 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
implementation 'org.sufficientlysecure:html-textview:3.5'
implementation 'org.sufficientlysecure:html-textview:3.6'
implementation 'me.saket:better-link-movement-method:2.2.0'
implementation 'com.tencent.bugly:crashreport_upgrade:1.3.5'
testImplementation 'junit:junit:4.12'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package org.mazhuang.guanggoo.topicdetail;

import android.support.v4.app.Fragment;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.text.util.Linkify;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -13,8 +16,10 @@
import org.mazhuang.guanggoo.R;
import org.mazhuang.guanggoo.data.OnResponseListener;
import org.mazhuang.guanggoo.data.entity.Comment;
import org.mazhuang.guanggoo.router.FragmentFactory;
import org.mazhuang.guanggoo.util.GlideUtil;
import org.mazhuang.guanggoo.util.MyHtmlHttpImageGetter;
import org.mazhuang.guanggoo.util.UrlUtil;
import org.sufficientlysecure.htmltextview.HtmlTextView;

import java.util.Map;
Expand All @@ -23,6 +28,7 @@
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.OnLongClick;
import me.saket.bettermovementmethod.BetterLinkMovementMethod;

/**
* @author mazhuang
Expand All @@ -31,6 +37,23 @@ public class CommentsListAdapter extends RecyclerView.Adapter<CommentsListAdapte

private Map<Integer, Comment> mData;
private final CommentsActionListener mListener;
private BetterLinkMovementMethod.OnLinkClickListener mOnLinkClickListener = new BetterLinkMovementMethod.OnLinkClickListener() {
@Override
public boolean onClick(TextView textView, String url) {
if (mListener == null || TextUtils.isEmpty(url)) {
return false;
}

url = UrlUtil.removeQuery(url);

if (FragmentFactory.PageType.NONE != FragmentFactory.getPageTypeByUrl(url)) {
mListener.openPage(url, null);
return true;
}

return false;
}
};

public CommentsListAdapter(CommentsActionListener listener) {
mListener = listener;
Expand Down Expand Up @@ -79,7 +102,12 @@ public void onBindViewHolder(final ViewHolder holder, int position) {
holder.mFloorTextView.setText("#" + holder.mItem.getMeta().getFloor());
MyHtmlHttpImageGetter imageGetter = new MyHtmlHttpImageGetter(holder.mContentTextView);
imageGetter.enableCompressImage(true, 30);

holder.mContentTextView.setHtml(holder.mItem.getContent(), imageGetter);
BetterLinkMovementMethod
.linkifyHtml(holder.mContentTextView)
.setOnLinkClickListener(mOnLinkClickListener);

holder.mVoteImageView.setEnabled(!holder.mItem.getMeta().getVote().isVoted());
holder.mVoteCountTextView.setText(String.valueOf(holder.mItem.getMeta().getVote().getCount()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.mazhuang.guanggoo.util.GlideUtil;
import org.mazhuang.guanggoo.util.PrefsUtil;
import org.mazhuang.guanggoo.util.SoftInputUtil;
import org.mazhuang.guanggoo.util.UrlUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
Expand Down Expand Up @@ -348,11 +349,11 @@ private void initWebView() {
mContentWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
url = UrlUtil.removeQuery(url);

FragmentFactory.PageType pageType = FragmentFactory.getPageTypeByUrl(url);
if (mListener != null) {
if (pageType == FragmentFactory.PageType.VIEW_IMAGE ||
pageType == FragmentFactory.PageType.TOPIC_DETAIL ||
pageType == FragmentFactory.PageType.USER_PROFILE) {
if (pageType != FragmentFactory.PageType.NONE) {
mListener.openPage(url, null);
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion config/version.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
MAJOR_VERSION_NAME=2.0
MAJOR_VERSION_NAME=2.1

0 comments on commit f2155c8

Please sign in to comment.