Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
beyond-clouds-android
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
云深项目组
beyond-clouds-android
Commits
521f8863
Commit
521f8863
authored
Mar 16, 2020
by
段启岩
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
话题解析和着色完成
parent
5ac2e857
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
104 additions
and
30 deletions
+104
-30
app/src/main/java/cn/yunliyunwai/beyondclouds/adapter/DynamicListRecyclerViewAdapter.java
+79
-16
app/src/main/res/color/color_topic_link.xml
+6
-0
app/src/main/res/layout/post_item.xml
+13
-14
app/src/main/res/values/colors.xml
+2
-0
app/src/main/res/values/styles.xml
+4
-0
No files found.
app/src/main/java/cn/yunliyunwai/beyondclouds/adapter/DynamicListRecyclerViewAdapter.java
View file @
521f8863
package
cn
.
yunliyunwai
.
beyondclouds
.
adapter
;
package
cn
.
yunliyunwai
.
beyondclouds
.
adapter
;
import
android.text.Spannable
;
import
android.text.SpannableString
;
import
android.text.SpannableStringBuilder
;
import
android.text.TextPaint
;
import
android.text.TextUtils
;
import
android.text.method.LinkMovementMethod
;
import
android.text.style.ClickableSpan
;
import
android.view.View
;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
androidx.annotation.NonNull
;
import
com.chad.library.adapter.base.BaseQuickAdapter
;
import
com.chad.library.adapter.base.BaseQuickAdapter
;
import
com.chad.library.adapter.base.BaseViewHolder
;
import
com.chad.library.adapter.base.BaseViewHolder
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
cn.yunliyunwai.beyondclouds.data.model.Post
;
import
cn.yunliyunwai.beyondclouds.data.model.Post
;
import
cn.yunliyunwai.beyondclouds.databinding.PostItemBinding
;
import
cn.yunliyunwai.beyondclouds.databinding.PostItemBinding
;
import
cn.yunliyunwai.beyondclouds.util.DateUtils
;
import
cn.yunliyunwai.beyondclouds.util.DateUtils
;
...
@@ -11,6 +29,23 @@ import cn.yunliyunwai.beyondclouds.util.GlideRoundTransform;
...
@@ -11,6 +29,23 @@ import cn.yunliyunwai.beyondclouds.util.GlideRoundTransform;
public
class
DynamicListRecyclerViewAdapter
extends
BaseQuickAdapter
<
Post
,
BaseViewHolder
>
{
public
class
DynamicListRecyclerViewAdapter
extends
BaseQuickAdapter
<
Post
,
BaseViewHolder
>
{
static
class
TopicLink
{
private
TopicLink
(
String
topic
,
int
start
,
int
end
)
{
this
.
topic
=
topic
;
this
.
start
=
start
;
this
.
end
=
end
;
}
private
int
start
;
private
int
end
;
private
String
topic
;
public
static
TopicLink
of
(
String
topic
,
int
start
,
int
end
)
{
return
new
TopicLink
(
topic
,
start
,
end
);
}
}
private
static
final
Pattern
TOPIC_LINK_PATTERN
=
Pattern
.
compile
(
"<a href=.+>(#.+#)</a>"
);
private
static
final
GlideRoundTransform
glideRoundTransform
=
new
GlideRoundTransform
(
3
);
private
static
final
GlideRoundTransform
glideRoundTransform
=
new
GlideRoundTransform
(
3
);
public
DynamicListRecyclerViewAdapter
(
int
layoutResId
)
{
public
DynamicListRecyclerViewAdapter
(
int
layoutResId
)
{
super
(
layoutResId
);
super
(
layoutResId
);
...
@@ -20,24 +55,51 @@ public class DynamicListRecyclerViewAdapter extends BaseQuickAdapter<Post,BaseVi
...
@@ -20,24 +55,51 @@ public class DynamicListRecyclerViewAdapter extends BaseQuickAdapter<Post,BaseVi
protected
void
convert
(
BaseViewHolder
helper
,
Post
post
)
{
protected
void
convert
(
BaseViewHolder
helper
,
Post
post
)
{
PostItemBinding
binding
=
PostItemBinding
.
bind
(
helper
.
itemView
);
PostItemBinding
binding
=
PostItemBinding
.
bind
(
helper
.
itemView
);
binding
.
txtTitle
.
setText
(
post
.
getContent
());
parseAndSetContent
(
binding
.
txtContent
,
post
.
getContent
());
binding
.
txtAbstract
.
setText
(
post
.
getContent
());
binding
.
txtAuthor
.
setText
(
post
.
getUserNick
());
binding
.
txtAuthor
.
setText
(
post
.
getUserNick
());
binding
.
txtCreateTime
.
setText
(
DateUtils
.
format
(
post
.
getCreateTime
()));
binding
.
txtCreateTime
.
setText
(
DateUtils
.
format
(
post
.
getCreateTime
()));
/*if (null != post.getCover() && !TextUtils.isEmpty(post.getCover().trim()) && post.getCover().startsWith("http")) {
binding.blogCover.setVisibility(View.VISIBLE);
RequestOptions options = new RequestOptions()
.centerCrop()
.placeholder(R.drawable.pre_load_blog)
.error(R.drawable.pre_load_blog)
.priority(Priority.HIGH)
.skipMemoryCache(true)
.diskCacheStrategy(DiskCacheStrategy.NONE)
.transform(glideRoundTransform);
Glide.with(binding.getRoot()).applyDefaultRequestOptions(options).load(post.getCover()).into(binding.blogCover);
} else {
binding.blogCover.setVisibility(View.GONE);
}*/
}
}
static
class
TopicLinkClickable
extends
ClickableSpan
{
@Override
public
void
onClick
(
@NonNull
View
widget
)
{
Toast
.
makeText
(
widget
.
getContext
(),
"点击了话题"
,
Toast
.
LENGTH_SHORT
).
show
();
}
@Override
public
void
updateDrawState
(
@NonNull
TextPaint
ds
)
{
ds
.
setUnderlineText
(
false
);
ds
.
setColor
(
ds
.
linkColor
);
}
}
private
void
parseAndSetContent
(
TextView
textView
,
String
content
)
{
SpannableStringBuilder
builder
=
new
SpannableStringBuilder
();
List
<
TopicLink
>
topicLinkList
=
new
ArrayList
<>(
10
);
Matcher
matcher
=
TOPIC_LINK_PATTERN
.
matcher
(
content
);
while
(
matcher
.
find
())
{
String
topic
=
matcher
.
group
(
1
);
topicLinkList
.
add
(
TopicLink
.
of
(
topic
,
matcher
.
start
(),
matcher
.
end
()));
}
int
currentIndex
=
0
;
for
(
TopicLink
topicLink:
topicLinkList
)
{
String
plainText
=
content
.
substring
(
currentIndex
,
topicLink
.
start
);
if
(!
TextUtils
.
isEmpty
(
plainText
))
{
builder
.
append
(
plainText
);
}
SpannableString
topicSpannable
=
new
SpannableString
(
topicLink
.
topic
);
topicSpannable
.
setSpan
(
new
TopicLinkClickable
(),
0
,
topicSpannable
.
length
(),
Spannable
.
SPAN_EXCLUSIVE_EXCLUSIVE
);
builder
.
append
(
topicSpannable
);
currentIndex
=
topicLink
.
end
;
}
if
(
currentIndex
!=
content
.
length
())
{
builder
.
append
(
content
.
substring
(
currentIndex
));
}
textView
.
setText
(
builder
);
textView
.
setMovementMethod
(
LinkMovementMethod
.
getInstance
());
}
}
}
\ No newline at end of file
app/src/main/res/color/color_topic_link.xml
0 → 100644
View file @
521f8863
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<item
android:color=
"@color/colorPrimaryTouched"
android:state_pressed=
"true"
/>
<item
android:color=
"@color/colorPrimary"
/>
</selector>
\ No newline at end of file
app/src/main/res/layout/post_item.xml
View file @
521f8863
...
@@ -15,15 +15,12 @@
...
@@ -15,15 +15,12 @@
<TextView
<TextView
android:id=
"@+id/txt_title"
android:id=
"@+id/txt_title"
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"22dp"
android:layout_height=
"wrap_content"
android:text=
"SpringBoot迭代发布JRA瘦身配置"
android:textSize=
"16sp"
android:textColor=
"@color/colorTextAccent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
/>
app:layout_constraintTop_toTopOf=
"parent"
/>
<androidx.constraintlayout.widget.Barrier
<androidx.constraintlayout.widget.Barrier
android:id=
"@+id/barrier_
title
"
android:id=
"@+id/barrier_
user_info
"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
app:barrierDirection=
"bottom"
app:barrierDirection=
"bottom"
...
@@ -32,23 +29,25 @@
...
@@ -32,23 +29,25 @@
tools:layout_editor_absoluteY=
"16dp"
/>
tools:layout_editor_absoluteY=
"16dp"
/>
<TextView
<TextView
android:id=
"@+id/txt_
abstrac
t"
android:id=
"@+id/txt_
conten
t"
android:layout_marginTop=
"10dp"
android:layout_marginTop=
"10dp"
android:layout_width=
"0dp"
android:text=
"SpringBoot迭代发布JRA瘦身配置"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:maxHeight=
"55dp"
android:textSize=
"16sp"
android:textSize=
"12sp"
android:textColorHint=
"@color/colorPrimaryTouched"
android:paddingEnd=
"10dp"
android:linksClickable=
"true"
android:paddingRight=
"10dp"
android:textColorHighlight=
"@color/colorBackgroundTopicTouched"
android:text=
"我们所处的时代我们所处的时代我们所处的时代我们所处的时代我们所处的时代我们所处的时代我们所处的时代我们所处的时代"
android:textColorLink=
"@color/color_topic_link"
app:layout_constraintTop_toBottomOf=
"@id/barrier_title"
android:textColor=
"@color/colorTextAccent"
app:layout_constraintTop_toBottomOf=
"@id/barrier_user_info"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintEnd_toStartOf=
"@id/blog_cover"
/>
app:layout_constraintEnd_toStartOf=
"@id/blog_cover"
/>
<ImageView
<ImageView
android:layout_marginTop=
"10dp"
android:layout_marginTop=
"10dp"
android:id=
"@+id/blog_cover"
android:id=
"@+id/blog_cover"
app:layout_constraintTop_toBottomOf=
"@id/barrier_
title
"
app:layout_constraintTop_toBottomOf=
"@id/barrier_
user_info
"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
android:layout_width=
"82dp"
android:layout_width=
"82dp"
android:layout_height=
"55dp"
android:layout_height=
"55dp"
...
...
app/src/main/res/values/colors.xml
View file @
521f8863
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<resources>
<color
name=
"colorPrimary"
>
#00AAE6
</color>
<color
name=
"colorPrimary"
>
#00AAE6
</color>
<color
name=
"colorPrimaryTouched"
>
#00AAFF
</color>
<color
name=
"colorPrimaryDark"
>
#333333
</color>
<color
name=
"colorPrimaryDark"
>
#333333
</color>
<color
name=
"colorAccent"
>
#03DAC5
</color>
<color
name=
"colorAccent"
>
#03DAC5
</color>
<!-- <color name="colorBackground">#EDF5F8</color>-->
<!-- <color name="colorBackground">#EDF5F8</color>-->
...
@@ -11,4 +12,5 @@
...
@@ -11,4 +12,5 @@
<color
name=
"colorText"
>
#999999
</color>
<color
name=
"colorText"
>
#999999
</color>
<color
name=
"colorGray"
>
#666666
</color>
<color
name=
"colorGray"
>
#666666
</color>
<color
name=
"colorTextAccent"
>
#333333
</color>
<color
name=
"colorTextAccent"
>
#333333
</color>
<color
name=
"colorBackgroundTopicTouched"
>
#3000AAE6
</color>
</resources>
</resources>
app/src/main/res/values/styles.xml
View file @
521f8863
...
@@ -40,4 +40,8 @@
...
@@ -40,4 +40,8 @@
<item
name=
"android:layout_height"
>
6dp
</item>
<item
name=
"android:layout_height"
>
6dp
</item>
<item
name=
"android:textSize"
>
0sp
</item>
<item
name=
"android:textSize"
>
0sp
</item>
</style>
</style>
<style
name=
"BeyondTopic"
>
<item
name=
"android:textColor"
>
@color/color_topic_link
</item>
</style>
</resources>
</resources>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment