Merge pull request #33 from yangyxd/master

优化详情页UI
pull/34/head
kunfei 5 years ago committed by GitHub
commit 55edd96c94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 21
      app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt
  2. 14
      app/src/main/java/io/legado/app/ui/bookinfo/ChapterListAdapter.kt
  3. 2
      app/src/main/res/drawable/bg_chapter_item_divider.xml
  4. 2
      app/src/main/res/drawable/ic_divider.xml
  5. 11
      app/src/main/res/drawable/ic_exchange_order.xml
  6. 12
      app/src/main/res/drawable/recyclerview_item_divider.xml
  7. 5
      app/src/main/res/drawable/selector_btn_accent_bg.xml
  8. 5
      app/src/main/res/drawable/selector_btn_write_bg.xml
  9. 264
      app/src/main/res/layout/activity_book_info.xml
  10. 6
      app/src/main/res/values/colors.xml

@ -24,6 +24,9 @@ import kotlinx.android.synthetic.main.activity_book_info.*
import kotlinx.android.synthetic.main.view_title_bar.* import kotlinx.android.synthetic.main.view_title_bar.*
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivity
import androidx.recyclerview.widget.RecyclerView
class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_book_info), class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_book_info),
ChapterListAdapter.CallBack, ChapterListAdapter.CallBack,
@ -82,7 +85,7 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_boo
tv_author.text = getString(R.string.author_show, book.author) tv_author.text = getString(R.string.author_show, book.author)
tv_origin.text = getString(R.string.origin_show, book.originName) tv_origin.text = getString(R.string.origin_show, book.originName)
tv_lasted.text = getString(R.string.lasted_show, book.latestChapterTitle) tv_lasted.text = getString(R.string.lasted_show, book.latestChapterTitle)
tv_intro.text = getString(R.string.intro_show, book.getDisplayIntro()) tv_intro.text = book.getDisplayIntro(); // getString(R.string.intro_show, book.getDisplayIntro())
book.getDisplayCover()?.let { book.getDisplayCover()?.let {
ImageLoader.load(this, it) ImageLoader.load(this, it)
.placeholder(R.drawable.img_cover_default) .placeholder(R.drawable.img_cover_default)
@ -153,10 +156,16 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_boo
adapter = ChapterListAdapter(this, this) adapter = ChapterListAdapter(this, this)
ATH.applyEdgeEffectColor(rv_chapter_list) ATH.applyEdgeEffectColor(rv_chapter_list)
rv_chapter_list.layoutManager = LinearLayoutManager(this) rv_chapter_list.layoutManager = LinearLayoutManager(this)
rv_chapter_list.addItemDecoration(DividerItemDecoration(this, LinearLayout.VERTICAL)) rv_chapter_list.addItemDecoration(getRecyclerViewDivider())
rv_chapter_list.adapter = adapter rv_chapter_list.adapter = adapter
} }
private fun getRecyclerViewDivider(): RecyclerView.ItemDecoration {
val itemDecoration = DividerItemDecoration(this, DividerItemDecoration.VERTICAL)
itemDecoration.setDrawable(resources.getDrawable(R.drawable.recyclerview_item_divider))
return itemDecoration
}
private fun initOnClick() { private fun initOnClick() {
tv_read.onClick { tv_read.onClick {
viewModel.bookData.value?.let { viewModel.bookData.value?.let {
@ -195,12 +204,8 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_boo
} }
} }
iv_chapter_top.onClick { iv_chapter_top.onClick {
rv_chapter_list.scrollToPosition(0) adapter.reorder = !adapter.reorder;
} adapter.notifyDataSetChanged();
iv_chapter_bottom.onClick {
viewModel.chapterListData.value?.let {
rv_chapter_list.scrollToPosition(it.size - 1)
}
} }
} }

@ -13,16 +13,22 @@ import org.jetbrains.anko.textColorResource
class ChapterListAdapter(context: Context, var callBack: CallBack) : class ChapterListAdapter(context: Context, var callBack: CallBack) :
SimpleRecyclerAdapter<BookChapter>(context, R.layout.item_chapter_list) { SimpleRecyclerAdapter<BookChapter>(context, R.layout.item_chapter_list) {
var reorder: Boolean = false; // 是否倒序
override fun convert(holder: ItemViewHolder, item: BookChapter, payloads: MutableList<Any>) { override fun convert(holder: ItemViewHolder, item: BookChapter, payloads: MutableList<Any>) {
holder.itemView.apply { holder.itemView.apply {
tv_chapter_name.text = item.title var _item: BookChapter = item;
if (item.index == callBack.durChapterIndex()) { if (reorder) {
_item = getItems().get(getItems().size - item.index - 1);
}
tv_chapter_name.text = _item.title
if (_item.index == callBack.durChapterIndex()) {
tv_chapter_name.setTextColor(context.accentColor) tv_chapter_name.setTextColor(context.accentColor)
} else { } else {
tv_chapter_name.textColorResource = R.color.tv_text_default tv_chapter_name.textColorResource = R.color.tv_text_secondary
} }
this.onClick { this.onClick {
callBack.openChapter(item) callBack.openChapter(_item)
} }
} }
} }

@ -2,7 +2,7 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android" <shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line"> android:shape="line">
<stroke <stroke
android:width="1dp" android:width="1px"
android:color="@color/bg_divider_line" android:color="@color/bg_divider_line"
android:dashWidth="3dp" android:dashWidth="3dp"
android:dashGap="3dp" /> android:dashGap="3dp" />

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" <shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"> android:shape="rectangle">
<size android:height="0.5dp" /> <size android:height="1px" />
<solid android:color="@color/divider" /> <solid android:color="@color/divider" />
</shape> </shape>

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="1112"
android:viewportHeight="1024">
<path android:fillColor="#595757"
android:pathData="M385.722775 1023.999431a42.664285 42.664285 0 0 1-42.664285-42.664284V138.573312L72.851354 381.190877a42.664285 42.664285 0 1 1-56.885712-63.42757L357.279918 10.864887A42.664285 42.664285 0 0 1 428.387059 42.720886v938.614261a42.664285 42.664285 0 0 1-42.664284 42.664284zM727.037051 1023.999431a41.52657 41.52657 0 0 1-17.350142-3.697571A42.664285 42.664285 0 0 1 684.372767 981.335147v-938.614261a42.664285 42.664285 0 0 1 85.328569 0v842.761835l270.207135-242.617565a42.664285 42.664285 0 1 1 56.885713 63.427569l-341.314276 306.898421a42.664285 42.664285 0 0 1-28.442857 10.808285z"></path>
</vector>

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:insetLeft="10dp">
<!--android:insetLeft="10dp" 分割线距离左侧10dp-->
<shape>
<!--分割线的高度,横向的RecyclerView,这里设置宽度即可-->
<size android:height="1px" />
<!--分割线的颜色-->
<solid android:color="@color/bg_divider_line" />
</shape>
</inset>

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false" android:drawable="@color/colorAccent" />
<item android:state_pressed="true" android:drawable="@color/btn_bg_press" />
</selector>

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false" android:drawable="@color/btn_write" />
<item android:state_pressed="true" android:drawable="@color/btn_write_press" />
</selector>

@ -13,46 +13,58 @@
app:title="@string/book_info" app:title="@string/book_info"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<io.legado.app.ui.widget.image.CoverImageView <androidx.cardview.widget.CardView
android:id="@+id/iv_cover" android:id="@+id/iv_cover_s"
android:layout_width="76dp"
android:layout_height="110dp"
android:layout_margin="10dp"
android:src="@drawable/img_cover_default"
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/title_bar" /> app:layout_constraintTop_toBottomOf="@+id/title_bar"
app:cardCornerRadius="5.0dp"
android:layout_margin="12dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<io.legado.app.ui.widget.image.CoverImageView
android:id="@+id/iv_cover"
android:layout_width="76dp"
android:layout_height="110dp"
android:src="@drawable/img_cover_default"
/>
</androidx.cardview.widget.CardView>
<LinearLayout <LinearLayout
android:id="@+id/ll_book_info" android:id="@+id/ll_book_info"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="wrap_content"
android:layout_marginLeft="6dp" android:layout_marginLeft="12dp"
android:layout_marginRight="6dp" android:layout_marginRight="6dp"
android:orientation="vertical" android:orientation="vertical"
app:layout_constraintTop_toTopOf="@+id/iv_cover" android:minHeight="115dp"
app:layout_constraintLeft_toRightOf="@+id/iv_cover" android:paddingBottom="8dp"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="@+id/iv_cover_s"
app:layout_constraintBottom_toBottomOf="@+id/iv_cover"> app:layout_constraintLeft_toRightOf="@+id/iv_cover_s"
app:layout_constraintRight_toRightOf="parent">
<TextView <TextView
android:id="@+id/tv_name" android:id="@+id/tv_name"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="wrap_content"
android:layout_weight="1"
android:singleLine="true" android:singleLine="true"
android:textSize="16sp" /> android:layout_marginBottom="12dp"
android:textColor="@color/tv_text_default"
android:textSize="18sp" />
<TextView <TextView
android:id="@+id/tv_author" android:id="@+id/tv_author"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_marginBottom="4dp"
android:textSize="14sp"
android:singleLine="true" /> android:singleLine="true" />
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_marginBottom="4dp"
android:orientation="horizontal"> android:orientation="horizontal">
<TextView <TextView
@ -61,6 +73,8 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:singleLine="true" android:singleLine="true"
android:textSize="14sp"
android:layout_marginRight="8dp"
tools:ignore="NestedWeights" /> tools:ignore="NestedWeights" />
<io.legado.app.lib.theme.view.ATEAccentBgTextView <io.legado.app.lib.theme.view.ATEAccentBgTextView
@ -76,8 +90,8 @@
<LinearLayout <LinearLayout
android:id="@+id/ll_kind" android:id="@+id/ll_kind"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_marginBottom="4dp"
android:visibility="gone" android:visibility="gone"
android:orientation="horizontal"> android:orientation="horizontal">
@ -119,113 +133,162 @@
<TextView <TextView
android:id="@+id/tv_lasted" android:id="@+id/tv_lasted"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_marginBottom="4dp"
android:singleLine="true" android:singleLine="true"
android:textSize="14sp"
app:layout_constraintLeft_toLeftOf="@+id/tv_name" app:layout_constraintLeft_toLeftOf="@+id/tv_name"
app:layout_constraintRight_toRightOf="@id/tv_name" app:layout_constraintRight_toRightOf="@id/tv_name"
app:layout_constraintBottom_toBottomOf="@+id/iv_cover" /> app:layout_constraintBottom_toBottomOf="@+id/iv_cover" />
</LinearLayout> </LinearLayout>
<TextView
android:id="@+id/tv_intro"
android:layout_width="match_parent"
android:layout_height="160dp"
android:layout_margin="10dp"
android:scrollbars="vertical"
android:textIsSelectable="true"
app:layout_constraintTop_toBottomOf="@+id/iv_cover" />
<View
android:id="@+id/view_shadow"
android:layout_width="match_parent"
android:layout_height="10dp"
android:layout_marginTop="10dp"
android:background="@drawable/bg_shadow_top"
app:layout_constraintTop_toBottomOf="@+id/iv_cover" />
<LinearLayout <LinearLayout
android:id="@+id/ll_chapter_base_info" android:id="@+id/view_info"
app:layout_constraintTop_toBottomOf="@+id/ll_book_info"
android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="36dp" android:layout_height="wrap_content">
android:background="@color/background"
android:paddingLeft="10dp" <View
android:paddingRight="10dp" android:layout_width="match_parent"
android:elevation="5dp" android:layout_height="5dp"
android:gravity="center_vertical" android:layout_marginTop="4dp"
android:orientation="horizontal" android:background="@color/bg_divider_line" />
app:layout_constraintTop_toBottomOf="@+id/tv_intro">
<TextView <TextView
android:layout_width="wrap_content" android:textSize="16sp"
android:layout_height="wrap_content" android:textColor="@color/tv_text_default"
android:text="@string/chapter_list" /> android:text="简介"
android:padding="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView <TextView
android:id="@+id/tv_current_chapter_info" android:id="@+id/tv_intro"
android:layout_width="0dp" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_marginLeft="8dp"
android:background="?android:attr/selectableItemBackgroundBorderless" android:layout_marginRight="8dp"
android:ellipsize="middle" android:minHeight="100dp"
android:maxHeight="160dp"
android:scrollbars="vertical"
android:textIsSelectable="true"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/view_chapter"
app:layout_constraintTop_toBottomOf="@+id/view_info"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:layout_width="match_parent"
android:layout_height="5dp"
android:layout_marginTop="4dp"
android:background="@color/bg_divider_line" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:textSize="16sp"
android:textColor="@color/tv_text_default"
android:text="目录"
android:paddingTop="8dp"
android:paddingLeft="8dp"
android:layout_weight="1.0"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_chapter_base_info"
android:layout_width="match_parent"
android:layout_height="36dp"
android:paddingLeft="10dp" android:paddingLeft="10dp"
android:paddingRight="10dp" android:paddingRight="10dp"
android:singleLine="true" android:elevation="5dp"
android:gravity="center_vertical" android:gravity="center_vertical"
android:textColor="@color/tv_text_default" android:orientation="horizontal"
android:textSize="12sp" /> app:layout_constraintTop_toBottomOf="@+id/view_chapter">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="当前位置:" />
<TextView
android:id="@+id/tv_current_chapter_info"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:ellipsize="middle"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:singleLine="true"
android:gravity="center_vertical"
android:textColor="@color/tv_text_default"
android:textSize="14sp" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_chapter_top"
android:layout_width="36dp"
android:layout_height="match_parent"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/go_to_top"
android:padding="10dp"
android:src="@drawable/ic_exchange_order"
android:tooltipText="@string/go_to_top"
app:tint="@color/tv_text_default"
tools:ignore="UnusedAttribute" />
</LinearLayout>
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_chapter_top"
android:layout_width="36dp"
android:layout_height="match_parent"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/go_to_top"
android:src="@drawable/ic_arrow_drop_up"
android:tooltipText="@string/go_to_top"
app:tint="@color/tv_text_default"
tools:ignore="UnusedAttribute" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_chapter_bottom"
android:layout_width="36dp"
android:layout_height="match_parent"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/go_to_bottom"
android:src="@drawable/ic_arrow_drop_down"
android:tooltipText="@string/go_to_bottom"
app:tint="@color/tv_text_default"
tools:ignore="UnusedAttribute" />
</LinearLayout> </LinearLayout>
<io.legado.app.ui.widget.recycler.scroller.FastScrollRecyclerView <io.legado.app.ui.widget.recycler.scroller.FastScrollRecyclerView
android:id="@+id/rv_chapter_list" android:id="@+id/rv_chapter_list"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@+id/ll_chapter_base_info" app:layout_constraintTop_toBottomOf="@+id/view_chapter"
app:layout_constraintBottom_toTopOf="@id/fl_action" /> app:layout_constraintBottom_toTopOf="@id/fl_action" />
<FrameLayout <FrameLayout
android:id="@+id/fl_action" android:id="@+id/fl_action"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="50dp" android:layout_height="50dp"
android:background="@color/background"
app:layout_constraintBottom_toBottomOf="parent"> app:layout_constraintBottom_toBottomOf="parent">
<TextView
android:id="@+id/tv_loading"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/tv_text_button_nor"
android:clickable="true"
android:focusable="true"
android:gravity="center"
android:text="@string/data_loading"
android:textColor="#767676"
android:textSize="16sp" />
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@color/background_menu" android:orientation="horizontal">
android:orientation="horizontal"
android:padding="3dp">
<TextView <TextView
android:id="@+id/tv_shelf" android:id="@+id/tv_shelf"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="1" android:layout_weight="1"
android:background="@drawable/selector_fillet_btn_bg" android:background="@drawable/selector_btn_write_bg"
android:clickable="true" android:clickable="true"
android:focusable="true" android:focusable="true"
android:gravity="center" android:gravity="center"
@ -234,37 +297,28 @@
android:textColor="@color/tv_text_default" android:textColor="@color/tv_text_default"
android:textSize="15sp" /> android:textSize="15sp" />
<Space
android:layout_width="3dp"
android:layout_height="match_parent" />
<TextView <TextView
android:id="@+id/tv_read" android:id="@+id/tv_read"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="1" android:layout_weight="1"
android:background="@drawable/selector_fillet_btn_bg" android:background="@drawable/selector_btn_accent_bg"
android:clickable="true" android:clickable="true"
android:focusable="true" android:focusable="true"
android:gravity="center" android:gravity="center"
android:includeFontPadding="false" android:includeFontPadding="false"
android:text="@string/reading" android:text="@string/reading"
android:textColor="@color/tv_text_default" android:textColor="@color/tv_text_button_nor"
android:textSize="15sp" /> android:textSize="15sp" />
</LinearLayout> </LinearLayout>
<TextView <View
android:id="@+id/tv_loading" android:background="@color/bg_divider_line"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="1px" />
android:background="@color/tv_text_button_nor"
android:clickable="true"
android:focusable="true"
android:gravity="center"
android:text="@string/data_loading"
android:textColor="#767676"
android:textSize="16sp" />
</FrameLayout> </FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

@ -40,7 +40,7 @@
<color name="darker_gray">#aaaaaaaa</color> <color name="darker_gray">#aaaaaaaa</color>
<!-- 分格线背景色 --> <!-- 分格线背景色 -->
<color name="bg_divider_line">#FFD4D4D4</color> <color name="bg_divider_line">#8fe0e0e0</color>
<!--statusBarBackground--> <!--statusBarBackground-->
<color name="status_bar_bag">#19000000</color> <color name="status_bar_bag">#19000000</color>
<color name="navigation_bar_bag">#f4f4f4</color> <color name="navigation_bar_bag">#f4f4f4</color>
@ -50,6 +50,10 @@
<color name="black">#000000</color> <color name="black">#000000</color>
<color name="white">#ffffff</color> <color name="white">#ffffff</color>
<!-- btn -->
<color name="btn_write">#ffffffff</color>
<color name="btn_write_press">#efe0e0e0</color>
<!--"control" means checkbox / radio button--> <!--"control" means checkbox / radio button-->
<!--LIGHT--> <!--LIGHT-->

Loading…
Cancel
Save