Skip to content

Commit 871e4d5

Browse files
committed
修改Blocks,加入Title和Favorite
1 parent dc7342c commit 871e4d5

File tree

3 files changed

+31
-36
lines changed

3 files changed

+31
-36
lines changed

app/src/main/kotlin/com/rayfantasy/icode/ui/activity/BlocksActivity.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ class BlocksActivity : ActivityBindingStatus() {
2828
supportActionBar?.setDisplayHomeAsUpEnabled(true)
2929
codeGood = intent.getSerializableExtra("codeGood") as CodeGood
3030
title = codeGood.title
31-
32-
toolbar.subtitle = codeGood.subtitle
3331
with(recyclerView) {
3432
layoutManager = LinearLayoutManager(this@BlocksActivity)
3533
itemAnimator = RefactoredDefaultItemAnimator()

app/src/main/kotlin/com/rayfantasy/icode/ui/adapter/BlockAdapter.kt

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import android.content.Context
44
import android.support.v7.widget.RecyclerView
55
import android.view.View
66
import android.view.ViewGroup
7+
import com.bumptech.glide.Glide
78
import com.rayfantasy.icode.R
89
import com.rayfantasy.icode.extension.inflate
10+
import com.rayfantasy.icode.extension.loadPortrait
911
import com.rayfantasy.icode.postutil.bean.CodeGood
1012
import com.rayfantasy.icode.ui.fragment.SettingFragment
1113
import kotlinx.android.synthetic.main.item_block_favorite.view.*
@@ -20,34 +22,44 @@ class BlockAdapter(ctx: Context, val codeGood: CodeGood, var blocks: List<CodeG
2022
private val FAVORITE_VIEW = 999
2123
private val highlightTheme = ctx.defaultSharedPreferences.getString(SettingFragment.PREF_HIGHLIGHT, SettingFragment.DEFAULT_HIGHLIGHT)
2224
override fun onBindViewHolder(holder: RecyclerView.ViewHolder?, position: Int) {
23-
val block = blocks[position]
2425
when (holder) {
2526
is CodeViewHolder -> {
27+
val block = blocks[position - 1]
2628
val configure = holder.highlight.configure
2729
configure.mLanguage = block.extra
2830
holder.highlight.loadFromConfigure(configure)
2931
holder.highlight.setSource(block.content)
3032
}
31-
is TextViewHolder -> holder.content.text = block.content
33+
is TextViewHolder -> {
34+
val block = blocks[position - 1]
35+
holder.content.text = block.content
36+
}
3237
is TitleViewHolder -> {
3338
holder.username.text = codeGood.username
3439
holder.subtitle.text = codeGood.subtitle
40+
holder.user_icon.loadPortrait(codeGood.username)
41+
3542
}
43+
is FavoriteViewHolder ->{}
44+
3645
}
3746

3847
}
3948

40-
override fun getItemCount() = blocks.size
49+
override fun getItemCount() = blocks.size + 2
4150

4251
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = when (viewType) {
4352
CodeGood.BlockType.CODE -> CodeViewHolder(parent.inflate(R.layout.item_block_code) as ViewGroup, highlightTheme)
4453
TITLE_VIEW -> TitleViewHolder(parent.inflate(R.layout.item_block_title))
4554
FAVORITE_VIEW -> FavoriteViewHolder(parent.inflate(R.layout.item_block_favorite))
46-
else -> TextViewHolder(parent.inflate(R.layout.item_block_text))
55+
CodeGood.BlockType.TEXT -> TextViewHolder(parent.inflate(R.layout.item_block_text))
56+
else -> FavoriteViewHolder(parent.inflate(R.layout.item_block_favorite))
4757

4858
}
4959

50-
override fun getItemViewType(position: Int) = blocks[position].blockType
60+
override fun getItemViewType(position: Int) = if (position == 0) TITLE_VIEW else if (position == blocks.size+1) FAVORITE_VIEW else {
61+
blocks[position - 1].blockType
62+
}
5163

5264
class TextViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
5365
val content = itemView.tv_text
@@ -70,11 +82,10 @@ class BlockAdapter(ctx: Context, val codeGood: CodeGood, var blocks: List<CodeG
7082
class TitleViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
7183
val username = itemView.block_username
7284
val subtitle = itemView.block_sub_title
73-
val usericon = itemView.block_userIcon
85+
val user_icon = itemView.block_userIcon
7486
}
7587

7688
class FavoriteViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
7789
val favorite = itemView.favo_btn
78-
val favo_count = itemView.favo_count
7990
}
8091
}

app/src/main/res/layout/item_block_favorite.xml

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,25 @@
77
android:layout_width="match_parent"
88
android:layout_height="wrap_content">
99

10+
<TextView
11+
android:layout_width="wrap_content"
12+
android:layout_height="wrap_content"
13+
android:text="@string/add_code_favorite"
14+
android:textColor="#000"
15+
android:textSize="20dp"
16+
android:layout_centerHorizontal="true"
17+
android:layout_centerVertical="true" />
18+
1019
<com.like.LikeButton
1120
app:icon_type="heart"
12-
app:icon_size="30dp"
21+
app:icon_size="24dp"
1322
android:id="@+id/favo_btn"
1423
android:layout_width="wrap_content"
1524
android:layout_height="wrap_content"
16-
android:layout_alignParentTop="true"
17-
android:layout_alignParentRight="true"
18-
android:layout_alignParentEnd="true">
25+
android:layout_alignParentTop="true"
26+
android:layout_alignParentLeft="true"
27+
android:layout_alignParentStart="true">
1928

2029
</com.like.LikeButton>
21-
<TextView
22-
android:layout_width="wrap_content"
23-
android:layout_height="wrap_content"
24-
android:text="+999"
25-
android:id="@+id/favo_count"
26-
android:gravity="center"
27-
android:textColor="#fff"
28-
android:layout_alignParentTop="true"
29-
android:layout_alignRight="@+id/favo_btn"
30-
android:layout_alignEnd="@+id/favo_btn"
31-
android:layout_marginTop="30dp"
32-
android:layout_marginRight="28dp"/>
33-
<TextView
34-
android:layout_width="wrap_content"
35-
android:layout_height="wrap_content"
36-
android:text="@string/add_code_favorite"
37-
android:layout_centerVertical="true"
38-
android:layout_alignParentLeft="true"
39-
android:layout_alignParentStart="true"
40-
android:textColor="#000"
41-
android:layout_marginLeft="70dp"
42-
android:layout_marginStart="70dp"
43-
android:textSize="20dp"/>
4430
</RelativeLayout>
4531
</android.support.v7.widget.CardView>

0 commit comments

Comments
 (0)