美化书详情页

pull/132/head
yangyxd 5 years ago
parent b7bae95675
commit 8533a83c9a
  1. 2
      app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt
  2. 93
      app/src/main/java/io/legado/app/ui/widget/ArcView.java
  3. 103
      app/src/main/java/io/legado/app/ui/widget/ScrollTextView.java
  4. 456
      app/src/main/res/layout/activity_book_info.xml
  5. 1
      app/src/main/res/layout/item_search.xml
  6. 9
      app/src/main/res/values/strings_yxd.xml

@ -55,7 +55,7 @@ class BookInfoActivity :
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
setSupportActionBar(toolbar) setSupportActionBar(toolbar)
supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayHomeAsUpEnabled(true)
tv_intro.movementMethod = ScrollingMovementMethod.getInstance() // tv_intro.movementMethod = ScrollingMovementMethod.getInstance()
viewModel.bookData.observe(this, Observer { showBook(it) }) viewModel.bookData.observe(this, Observer { showBook(it) })
viewModel.chapterListData.observe(this, Observer { upLoading(false, it) }) viewModel.chapterListData.observe(this, Observer { upLoading(false, it) })
viewModel.initData(intent) viewModel.initData(intent)

@ -0,0 +1,93 @@
package io.legado.app.ui.widget;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;
import io.legado.app.R;
import androidx.annotation.Nullable;
public class ArcView extends View {
private int mWidth;
private int mHeight;
/**
* 弧形高度
*/
private int mArcHeight;
/**
* 背景颜色
*/
private int mBgColor;
private Paint mPaint;
private boolean mDirectionTop;
private Context mContext;
public ArcView(Context context) {
this(context, null);
}
public ArcView(Context context, @Nullable AttributeSet attrs) {
this(context, attrs, 0);
}
public ArcView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ArcView);
mArcHeight = typedArray.getDimensionPixelSize(R.styleable.ArcView_arcHeight, 0);
mBgColor = typedArray.getColor(R.styleable.ArcView_bgColor, Color.parseColor("#303F9F"));
mDirectionTop = typedArray.getBoolean(R.styleable.ArcView_arcDirectionTop, false);
mContext = context;
mPaint = new Paint();
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
mPaint.setStyle(Paint.Style.FILL);
mPaint.setColor(mBgColor);
if (mDirectionTop) {
Rect rect = new Rect(0, mArcHeight, mWidth, mHeight);
canvas.drawRect(rect, mPaint);
Path path = new Path();
path.moveTo(0, mArcHeight);
path.quadTo(mWidth / 2, 0, mWidth, mArcHeight);
canvas.drawPath(path, mPaint);
} else {
Rect rect = new Rect(0, 0, mWidth, mHeight - mArcHeight);
canvas.drawRect(rect, mPaint);
Path path = new Path();
path.moveTo(0, mHeight - mArcHeight);
path.quadTo(mWidth / 2, mHeight, mWidth, mHeight - mArcHeight);
canvas.drawPath(path, mPaint);
}
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
if (widthMode == MeasureSpec.EXACTLY) {
mWidth = widthSize;
}
if (heightMode == MeasureSpec.EXACTLY) {
mHeight = heightSize;
}
setMeasuredDimension(mWidth, mHeight);
}
}

@ -0,0 +1,103 @@
package io.legado.app.ui.widget;
import android.annotation.SuppressLint;
import android.content.Context;
import android.text.Layout;
import android.util.AttributeSet;
import android.view.MotionEvent;
import androidx.appcompat.widget.AppCompatTextView;
public class ScrollTextView extends AppCompatTextView {
//滑动距离的最大边界
private int mOffsetHeight;
//是否到顶或者到底的标志
private boolean mBottomFlag = false;
public ScrollTextView(Context context) {
super(context);
}
public ScrollTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ScrollTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
initOffsetHeight();
}
@Override
protected void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter) {
super.onTextChanged(text, start, lengthBefore, lengthAfter);
initOffsetHeight();
}
private void initOffsetHeight() {
int paddingTop;
int paddingBottom;
int mHeight;
int mLayoutHeight;
//获得内容面板
Layout mLayout = getLayout();
if (mLayout == null) return;
//获得内容面板的高度
mLayoutHeight = mLayout.getHeight();
//获取上内边距
paddingTop = getTotalPaddingTop();
//获取下内边距
paddingBottom = getTotalPaddingBottom();
//获得控件的实际高度
mHeight = getMeasuredHeight();
//计算滑动距离的边界
mOffsetHeight = mLayoutHeight + paddingTop + paddingBottom - mHeight;
if (mOffsetHeight <= 0) {
scrollTo(0, 0);
}
}
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
//如果是新的按下事件,则对mBottomFlag重新初始化
mBottomFlag = mOffsetHeight <= 0;
}
//如果已经不要这次事件,则传出取消的信号,这里的作用不大
if (mBottomFlag) {
event.setAction(MotionEvent.ACTION_CANCEL);
}
return super.dispatchTouchEvent(event);
}
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouchEvent(MotionEvent event) {
boolean result = super.onTouchEvent(event);
//如果是需要拦截,则再拦截,这个方法会在onScrollChanged方法之后再调用一次
if (!mBottomFlag)
getParent().requestDisallowInterceptTouchEvent(true);
return result;
}
@Override
protected void onScrollChanged(int horiz, int vert, int oldHoriz, int oldVert) {
super.onScrollChanged(horiz, vert, oldHoriz, oldVert);
if (vert == mOffsetHeight || vert == 0) {
//这里触发父布局或祖父布局的滑动事件
getParent().requestDisallowInterceptTouchEvent(false);
mBottomFlag = true;
}
}
}

@ -9,227 +9,335 @@
<ImageView <ImageView
android:id="@+id/bg_book" android:id="@+id/bg_book"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="match_parent"
android:scaleType="centerCrop" android:scaleType="centerCrop"
android:contentDescription="@string/bg_image" android:contentDescription="@string/bg_image"
app:layout_constraintBottom_toTopOf="@+id/view_info"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<View <LinearLayout
android:id="@+id/vw_bg" android:id="@+id/vw_bg"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="match_parent"
android:background="#50000000" android:background="#50000000"
app:layout_constraintBottom_toTopOf="@+id/view_info" android:orientation="vertical">
app:layout_constraintTop_toTopOf="parent" />
<androidx.appcompat.widget.Toolbar <androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar" android:id="@+id/toolbar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:theme="?attr/actionBarStyle" android:theme="?attr/actionBarStyle"
android:fitsSystemWindows="true" android:fitsSystemWindows="true"
app:popupTheme="@style/AppTheme.PopupOverlay" app:popupTheme="@style/AppTheme.PopupOverlay"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:title="@string/book_info" /> app:title="@string/book_info" />
<io.legado.app.ui.widget.image.CoverImageView <RelativeLayout
android:id="@+id/iv_cover" android:layout_width="match_parent"
android:layout_width="110dp" android:layout_height="wrap_content"
android:layout_height="160dp" android:layout_marginTop="8dp">
android:layout_margin="10dp"
android:scaleType="centerCrop" <io.legado.app.ui.widget.ArcView
android:src="@drawable/image_cover_default" app:arcHeight="36dp"
app:layout_constraintLeft_toLeftOf="parent" app:bgColor="@color/background"
app:layout_constraintTop_toBottomOf="@+id/toolbar" /> app:arcDirectionTop="true"
android:layout_marginTop="90dp"
android:layout_width="match_parent"
android:layout_height="78dp" />
<androidx.cardview.widget.CardView
app:cardCornerRadius="5dp"
app:cardElevation="8dp"
android:layout_margin="3dp"
android:layout_centerHorizontal="true"
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="110dp"
android:layout_height="160dp"
android:contentDescription="@string/img_cover"
android:scaleType="centerCrop"
android:src="@drawable/image_cover_default" />
</androidx.cardview.widget.CardView>
</RelativeLayout>
<LinearLayout <LinearLayout
android:id="@+id/ll_book_info" android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="12dp" android:background="@color/background"
android:layout_marginRight="12dp"
android:minHeight="115dp"
android:orientation="vertical" android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="@+id/iv_cover" android:paddingLeft="10dp"
app:layout_constraintLeft_toRightOf="@+id/iv_cover" android:paddingTop="8dp"
app:layout_constraintRight_toRightOf="parent" android:paddingRight="10dp"
app:layout_constraintTop_toTopOf="@+id/iv_cover"> android:paddingBottom="3dp">
<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="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="6dp" android:layout_marginBottom="6dp"
android:gravity="center"
android:includeFontPadding="false"
android:singleLine="true" android:singleLine="true"
android:textColor="@color/md_white_1000" android:text="@string/book_name"
android:textSize="18sp" /> android:textColor="@color/tv_text_default"
android:textSize="18sp"
tools:ignore="RtlHardcoded" />
<TextView <io.legado.app.ui.widget.LabelsBar
android:id="@+id/tv_author" android:id="@+id/lb_kind"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="3dp" android:layout_marginBottom="3dp"
android:singleLine="true" android:layout_gravity="center"
android:textColor="@color/md_white_1000" android:gravity="center"
android:textSize="16sp" /> android:visibility="gone" />
<LinearLayout </LinearLayout>
<ScrollView
android:background="@color/background"
android:layout_weight="1.0"
android:padding="0dp"
android:layout_height="0dp"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:scrollbarStyle="outsideInset"
android:layout_marginBottom="4dp" android:scrollbars="vertical"
android:orientation="horizontal"> android:fillViewport="true"
android:fitsSystemWindows="false"
android:focusable="true" >
<TextView <LinearLayout
android:id="@+id/tv_origin" android:orientation="vertical"
android:layout_width="0dp" android:paddingLeft="8dp"
android:layout_height="wrap_content" android:paddingRight="8dp"
android:layout_weight="1" android:paddingBottom="8dp"
android:singleLine="true" android:background="@color/background"
android:textSize="16sp" android:layout_width="match_parent"
android:textColor="@color/md_white_1000" android:layout_height="wrap_content">
tools:ignore="NestedWeights" />
<io.legado.app.ui.widget.text.AccentBgTextView <LinearLayout
android:id="@+id/tv_change_source" android:orientation="vertical"
android:layout_width="wrap_content" android:paddingLeft="8dp"
android:layout_height="wrap_content" android:paddingRight="8dp"
android:layout_marginStart="8dp" android:paddingBottom="8dp"
android:paddingLeft="5dp" android:background="@color/background"
android:paddingRight="5dp" android:layout_width="match_parent"
android:text="@string/change_origin" android:layout_height="wrap_content">
android:textSize="16sp"
app:radius="2dp" />
</LinearLayout>
<io.legado.app.ui.widget.LabelsBar <LinearLayout
android:id="@+id/lb_kind" android:layout_width="match_parent"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:gravity="center_vertical"
android:layout_marginBottom="3dp" android:orientation="horizontal"
android:visibility="gone" /> android:paddingTop="3dp"
android:paddingBottom="3dp">
<TextView <ImageView
android:id="@+id/tv_lasted" android:layout_width="18sp"
android:layout_width="match_parent" android:layout_height="18sp"
android:layout_height="wrap_content" android:contentDescription="@string/origin_format"
android:layout_marginBottom="4dp" android:paddingRight="2dp"
android:singleLine="true" android:src="@drawable/ic_author"
android:textSize="16sp" app:tint="@color/tv_text_summary"
android:textColor="@color/md_white_1000" tools:ignore="RtlHardcoded,RtlSymmetry" />
app:layout_constraintBottom_toBottomOf="@+id/iv_cover"
app:layout_constraintLeft_toLeftOf="@+id/tv_name"
app:layout_constraintRight_toRightOf="@id/tv_name" />
</LinearLayout> <TextView
android:id="@+id/tv_author"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="end"
android:includeFontPadding="false"
android:paddingRight="6dp"
android:singleLine="true"
android:text="@string/author"
android:textColor="@color/tv_text_summary"
android:textSize="13sp"
tools:ignore="NestedWeights" />
<LinearLayout </LinearLayout>
android:id="@+id/view_info"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="10dp"
android:orientation="vertical"
app:layout_constraintBottom_toTopOf="@+id/view_other"
app:layout_constraintTop_toBottomOf="@+id/iv_cover">
<View <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="5dp" android:layout_height="wrap_content"
android:background="@color/bg_divider_line" /> android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingTop="3dp"
android:paddingBottom="3dp">
<TextView <ImageView
android:layout_width="match_parent" android:id="@+id/iv_web"
android:layout_height="wrap_content" android:layout_width="18sp"
android:padding="8dp" android:layout_height="18sp"
android:text="@string/book_intro" android:contentDescription="@string/origin_format"
android:textStyle="bold" android:paddingRight="2dp"
android:textColor="@color/tv_text_default" android:src="@drawable/ic_web_outline"
android:textSize="16sp" /> app:tint="@color/tv_text_summary"
tools:ignore="RtlHardcoded,RtlSymmetry" />
<TextView <TextView
android:id="@+id/tv_intro" android:id="@+id/tv_origin"
android:layout_width="match_parent" android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:layout_marginLeft="8dp" android:ellipsize="end"
android:layout_marginRight="8dp" android:includeFontPadding="false"
android:minHeight="100dp" android:paddingRight="6dp"
android:textSize="14sp" /> android:singleLine="true"
android:text="@string/origin_format"
android:textColor="@color/tv_text_summary"
android:textSize="13sp"
tools:ignore="NestedWeights" />
<View <io.legado.app.ui.widget.text.AccentBgTextView
android:layout_width="match_parent" android:id="@+id/tv_change_source"
android:layout_height="5dp" android:layout_width="wrap_content"
android:background="@color/bg_divider_line" /> android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text="@string/change_origin"
android:textSize="16sp"
app:radius="2dp" />
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:id="@+id/view_other" android:layout_width="match_parent"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:gravity="center_vertical"
android:orientation="vertical" android:orientation="horizontal"
android:paddingTop="12dp" android:paddingTop="3dp"
android:paddingBottom="12dp" android:paddingBottom="3dp">
app:layout_constraintBottom_toTopOf="@+id/fl_action"
app:layout_constraintTop_toBottomOf="@+id/view_info">
<TextView <ImageView
android:id="@+id/tv_group" android:id="@+id/ic_book_last"
android:layout_width="18sp"
android:layout_height="18sp"
android:contentDescription="@string/read_dur_progress"
android:paddingRight="2dp"
android:src="@drawable/ic_book_last"
app:tint="@color/tv_text_summary"
tools:ignore="RtlHardcoded,RtlSymmetry" />
<TextView
android:id="@+id/tv_lasted"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="end"
android:includeFontPadding="false"
android:paddingRight="6dp"
android:singleLine="true"
android:text="@string/read_dur_progress"
android:textColor="@color/tv_text_summary"
android:textSize="13sp"
tools:ignore="NestedWeights" />
</LinearLayout>
</LinearLayout>
<io.legado.app.ui.widget.ScrollTextView
android:id="@+id/tv_intro"
android:layout_marginTop="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:text="@string/book_intro"
android:textColor="@color/tv_text_secondary"
android:textSize="14sp"
android:paddingLeft="8dp"
android:visibility="visible" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="@+id/view_other"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:padding="12dp" android:background="@color/background"
android:singleLine="true" android:orientation="vertical"
android:text="@string/group_s" android:paddingTop="12dp"
android:textColor="@color/tv_text_default" android:paddingBottom="12dp"
android:textSize="16sp" /> app:layout_constraintBottom_toTopOf="@+id/fl_action"
app:layout_constraintTop_toBottomOf="@+id/view_info">
<TextView <TextView
android:id="@+id/tv_toc" android:id="@+id/tv_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="12dp"
android:singleLine="true"
android:clickable="true"
android:text="@string/group_s"
android:textColor="@color/tv_text_default"
android:textSize="16sp" />
<TextView
android:id="@+id/tv_toc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="12dp"
android:background="?attr/selectableItemBackground"
android:singleLine="true"
android:clickable="true"
android:text="@string/toc_s"
android:textColor="@color/tv_text_default"
android:textSize="16sp" />
</LinearLayout>
<View
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="1px"
android:padding="12dp" android:background="@color/bg_divider_line" />
android:singleLine="true"
android:text="@string/toc_s"
android:textColor="@color/tv_text_default"
android:textSize="16sp" />
</LinearLayout> <LinearLayout
android:id="@+id/fl_action"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/background_menu"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent">
<LinearLayout <TextView
android:id="@+id/fl_action" android:id="@+id/tv_shelf"
android:layout_width="match_parent" android:layout_width="0dp"
android:layout_height="50dp" android:layout_height="match_parent"
android:background="@color/background_menu" android:layout_weight="1"
android:orientation="horizontal" android:background="?attr/selectableItemBackground"
app:layout_constraintBottom_toBottomOf="parent"> android:clickable="true"
android:focusable="true"
android:gravity="center"
android:includeFontPadding="false"
android:text="@string/remove_from_bookshelf"
android:textColor="@color/tv_text_default"
android:textSize="15sp" />
<TextView <io.legado.app.ui.widget.text.AccentBgTextView
android:id="@+id/tv_shelf" 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="?attr/selectableItemBackground" android:background="@drawable/selector_btn_accent_bg"
android:clickable="true" android:gravity="center"
android:focusable="true" android:includeFontPadding="false"
android:gravity="center" android:text="@string/reading"
android:includeFontPadding="false" android:textColor="@color/tv_text_button_nor"
android:text="@string/remove_from_bookshelf" android:textSize="15sp" />
android:textColor="@color/tv_text_default"
android:textSize="15sp" /> </LinearLayout>
<io.legado.app.ui.widget.text.AccentBgTextView
android:id="@+id/tv_read"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/selector_btn_accent_bg"
android:gravity="center"
android:includeFontPadding="false"
android:text="@string/reading"
android:textColor="@color/tv_text_button_nor"
android:textSize="15sp" />
</LinearLayout> </LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

@ -43,6 +43,7 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="0dp"
android:orientation="vertical" android:orientation="vertical"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="@id/iv_cover" app:layout_constraintBottom_toBottomOf="@id/iv_cover"
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"

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="ArcView">
<attr name="arcHeight" format="dimension" />
<attr name="bgColor" format="color" />
<attr name="arcDirectionTop" format="boolean" />
</declare-styleable>
</resources>
Loading…
Cancel
Save