Skip to content

Commit

Permalink
加了点转场动画,去掉了书架底部的阴影
Browse files Browse the repository at this point in the history
  • Loading branch information
lang-v committed Nov 12, 2020
1 parent d39426f commit 20d6175
Show file tree
Hide file tree
Showing 17 changed files with 77 additions and 55 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ android {
minSdkVersion 21
targetSdkVersion 30
versionCode 2
versionName "1.1.6"
versionName "1.1.6r2"

ndk {
//设置支持的SO库架构
Expand Down
Binary file modified app/release/app-release.apk
Binary file not shown.
2 changes: 1 addition & 1 deletion app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"type": "SINGLE",
"filters": [],
"versionCode": 2,
"versionName": "1.1.6",
"versionName": "1.1.6r2",
"outputFile": "app-release.apk"
}
]
Expand Down
39 changes: 19 additions & 20 deletions app/src/main/java/com/novel/qingwen/view/activity/ReadActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ class ReadActivity : AppCompatActivity(), IBaseView, CustomSeekBar.OnProgressCha
if (index < 0) return
//让列表更加快速的定位
contentsManager.scrollToPosition(index)
contentsManager.smoothScrollToPosition(contentsList,RecyclerView.State(),index)
contentsManager.smoothScrollToPosition(contentsList, RecyclerView.State(), index)
}
}

Expand Down Expand Up @@ -358,7 +358,7 @@ class ReadActivity : AppCompatActivity(), IBaseView, CustomSeekBar.OnProgressCha
val item = contentViewModel.getList()[index]
//避免重复加载
readHead.text = item.name
if (item.chapterId == currentReadID)return
if (item.chapterId == currentReadID) return
currentReadID = item.chapterId
if (index == contentViewModel.getList().size - 1) {
if (contentViewModel.getList()[index].nid != -1L) {
Expand All @@ -374,7 +374,7 @@ class ReadActivity : AppCompatActivity(), IBaseView, CustomSeekBar.OnProgressCha
}
}
} else if (index == 0 && contentViewModel.getList()[0].pid != -1L) {
if (item.chapterId == currentReadID)return
if (item.chapterId == currentReadID) return
contentViewModel.cancelPrepare()
if (!firstRun)
contentViewModel.prepareChapter(0)
Expand All @@ -385,14 +385,16 @@ class ReadActivity : AppCompatActivity(), IBaseView, CustomSeekBar.OnProgressCha
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
//设置界面处于开启状态 不处理滑动加载事件
if (isOpen) return
// "now canScrollUp=${readList.canScrollVertically(-1)} canScrollDown=${readList.canScrollVertically(1)}")
//取消预加载
contentViewModel.cancelPrepare()
//加载下一章
if (contentManager.findLastVisibleItemPosition() == (contentAdapter.itemCount - 1)//屏幕最下面的完全可见的item是list中的最后一个
&& newState == RecyclerView.SCROLL_STATE_IDLE//当前recyclerview停止滑动
&& !readList.canScrollVertically(1) //recyclerview无法向上滑动时
) {
if (loadLock && autoScrollRunning){
return
}
nextChapter()
super.onScrollStateChanged(recyclerView, newState)
return
Expand Down Expand Up @@ -468,7 +470,6 @@ class ReadActivity : AppCompatActivity(), IBaseView, CustomSeekBar.OnProgressCha
})
contentsInit()
}

//自定义 重写了smoothScrollToPosition方法 实现修改滑动时间
// private val contentsManager = ContentsActivity.MyLinearLayoutManager(this)
private val contentsManager = CenterLayoutManager(this)
Expand All @@ -482,7 +483,7 @@ class ReadActivity : AppCompatActivity(), IBaseView, CustomSeekBar.OnProgressCha
private var currentHeadViewIndex: Int = 0

//数据由viewModel保管 数据视图分离
private val headList by lazy { contentsViewModel.getHeadList() }
private val headList by lazy { contentsViewModel.getHeadList()}

//初始化右侧的目录页
private fun contentsInit() {
Expand All @@ -499,6 +500,7 @@ class ReadActivity : AppCompatActivity(), IBaseView, CustomSeekBar.OnProgressCha
//清空阅读位置记录
readOffset = 0
dialog.show()
firstRun = true
contentViewModel.getChapter(item.id)
readDrawerLayout.closeDrawer(Gravity.RIGHT)
closeSetting()
Expand Down Expand Up @@ -606,16 +608,6 @@ class ReadActivity : AppCompatActivity(), IBaseView, CustomSeekBar.OnProgressCha

//选中当前章节位置
selectChapterItem()
// var index = 0
// contentsViewModel.getList().forEach {
// if (it.id == chapterId) {
//// contentsList.scrollToPosition(index)
// selectChapterItem()
// //contentsList.smoothScrollToPosition()
// return@forEach
// }
// index++
// }
}
}
})
Expand All @@ -633,7 +625,7 @@ class ReadActivity : AppCompatActivity(), IBaseView, CustomSeekBar.OnProgressCha
headView.text = headList[headList.size - 1].name
if (contentsAdapter.itemCount > 0)
// contentsManager.scrollToPosition(contentsAdapter.itemCount - 1)
contentsList.scrollToPosition(contentsAdapter.itemCount - 1)
contentsList.scrollToPosition(contentsAdapter.itemCount - 1)
}
readLocation.setOnClickListener {
selectChapterItem()
Expand Down Expand Up @@ -678,8 +670,9 @@ class ReadActivity : AppCompatActivity(), IBaseView, CustomSeekBar.OnProgressCha
if (nid == -1L) {
if (status == "状态:完结")
showSuccess("恭喜你又读完一本书。")
else
else {
loadLock = false
}
return
}
//加载下一章
Expand All @@ -689,8 +682,14 @@ class ReadActivity : AppCompatActivity(), IBaseView, CustomSeekBar.OnProgressCha

override fun showMsg(msg: String) {
showError(msg)
if (loadLock)
if (loadLock) {
loadLock = false
if (autoScrollRunning) {
PageScrollController.stop()
findViewById<TextView>(R.id.readAutoScroll).callOnClick()
show("阅读结束")
}
}
if (dialog.isShowing)
dialog.dismiss()
}
Expand Down Expand Up @@ -718,7 +717,7 @@ class ReadActivity : AppCompatActivity(), IBaseView, CustomSeekBar.OnProgressCha
readList.scrollBy(0, -readOffset)
//加载上下章节
contentViewModel.prepareChapter(0)
contentViewModel.prepareChapter(contentAdapter.itemCount-1)
contentViewModel.prepareChapter(contentAdapter.itemCount - 1)
firstRun = false
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.novel.qingwen.view.activity

import android.content.Context
import android.content.Intent
import android.graphics.Color
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.*
import android.widget.ImageView
import androidx.activity.viewModels
import androidx.core.app.ActivityOptionsCompat
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import com.novel.qingwen.R
import com.novel.qingwen.base.IBaseView
import com.novel.qingwen.databinding.ActivityResumeBinding
Expand All @@ -31,12 +33,17 @@ class ResumeActivity : AppCompatActivity(), IBaseView {
private val dialog: NoticeDialog by lazy { NoticeDialog.build(this, "请稍候") }

companion object {
fun start(context: Context, id: Long, name: String) {
val intent = Intent(context, ResumeActivity::class.java)
fun start(context: Fragment, id: Long, name: String,view:View) {
val intent = Intent(context.requireContext(), ResumeActivity::class.java)
intent.putExtra("id", id)
BookShelfListUtil.currentBookInfo
val bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(
context.requireActivity(),
view,
"novelPic"
).toBundle()
intent.putExtra("name", name)
context.startActivity(intent)
context.startActivity(intent,bundle)
}
}

Expand Down Expand Up @@ -130,7 +137,8 @@ class ResumeActivity : AppCompatActivity(), IBaseView {
when (item.itemId) {
android.R.id.home -> {
//返回按钮
finish()
// finish()
onBackPressed()
}
R.id.addToBookShelf -> {
if(!BookShelfListUtil.getList().contains(BookShelfListUtil.currentBookInfo)){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class BookShelfListAdapter(
override fun getItemCount(): Int = values.size

class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
val img: ImageView = view.findViewById(R.id.img)
val img: ImageView = view.findViewById(R.id.novelImg)
val title: TextView = view.findViewById(R.id.title)
val update: TextView = view.findViewById(R.id.update)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.novel.qingwen.R
import com.novel.qingwen.net.bean.Book
import com.novel.qingwen.view.activity.ResumeActivity

class BookStoreListAdapter(private val list: ArrayList<Book>) :
class BookStoreListAdapter(private val list: ArrayList<Book>,private val block:(item:Book,view:View)->Unit) :
RecyclerView.Adapter<BookStoreListAdapter.ViewHolder>() {

class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
val title: TextView = view.findViewById(R.id.title)
val img: ImageView = view.findViewById(R.id.img)
val img: ImageView = view.findViewById(R.id.novelImg)
val author: TextView = view.findViewById(R.id.author)
val resume: TextView = view.findViewById(R.id.resume)
val tags: LinearLayout = view.findViewById(R.id.tags)
Expand Down Expand Up @@ -49,7 +48,8 @@ class BookStoreListAdapter(private val list: ArrayList<Book>) :
holder.vote.text = list[position].Score.toString()

holder.itemView.setOnClickListener {
ResumeActivity.start(holder.itemView.context, item.Id.toLong(), item.Name)
block.invoke(item,holder.img)
// ResumeActivity.start(holder.itemView.context, item.Id.toLong(), item.Name)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import sl.view.elasticviewlibrary.ElasticLayout

class BookStoreRefreshHeader(private val context: Context, offset: Int) : ElasticLayout.HeaderAdapter(offset) {
private lateinit var view: View
private val icon by lazy { view.findViewById<ImageView>(R.id.img) }
private val icon by lazy { view.findViewById<ImageView>(R.id.novelImg) }
private val progressBar by lazy { view.findViewById<ProgressBar>(R.id.progressBar) }
private val text by lazy { view.findViewById<TextView>(R.id.text) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ object PageScrollController {
if (view == null) return@launch
view?.post {
view?.scrollBy(0, 2)
//发送已经停止滑动的消息,让自动加载下一章的监听生效
// view?.scrollTo(0,2)
// view?.setScrollState(RecyclerView.SCROLL_STATE_IDLE)
// view?.dispatchOnScrollStateChanged(RecyclerView.SCROLL_STATE_IDLE)
// view?.onScrollStateChanged(RecyclerView.SCROLL_STATE_IDLE)
}
// val time = (32 * ((200f - v) / 200f)).toLong()
val time = ((100 - v) / 2).toLong()
// Log.e("Time", time.toString())
// delay((32 * ((200 - v) / 200)).toLong())
delay(5 + time)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.novel.qingwen.R
import com.novel.qingwen.net.bean.SearchResultItem
import com.novel.qingwen.view.activity.ResumeActivity

class SearchBookListAdapter(private val list: ArrayList<SearchResultItem>) :
class SearchBookListAdapter(private val list: ArrayList<SearchResultItem>,private val block:(item:SearchResultItem,view:View)->Unit) :
RecyclerView.Adapter<SearchBookListAdapter.ViewHolder>() {

class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
val title: TextView = view.findViewById(R.id.title)
val img: ImageView = view.findViewById(R.id.img)
val img: ImageView = view.findViewById(R.id.novelImg)
val author: TextView = view.findViewById(R.id.author)
val resume: TextView = view.findViewById(R.id.resume)
val tags: LinearLayout = view.findViewById(R.id.tags)
Expand Down Expand Up @@ -46,7 +45,8 @@ class SearchBookListAdapter(private val list: ArrayList<SearchResultItem>) :
holder.tags.removeAllViews()
holder.tags.addView(view)
holder.itemView.setOnClickListener {
ResumeActivity.start(holder.itemView.context, item.Id.toLong(), item.Name)
block.invoke(item,holder.img)
// ResumeActivity.start(holder.itemView.context, item.Id.toLong(), item.Name)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.novel.qingwen.R
import com.novel.qingwen.base.IBaseView
import com.novel.qingwen.view.activity.ResumeActivity
import com.novel.qingwen.view.adapter.BookStoreCategoryAdapter
import com.novel.qingwen.view.adapter.BookStoreListAdapter
import com.novel.qingwen.view.dialog.NoticeDialog
import com.novel.qingwen.view.widget.CenterLayoutManager
import com.novel.qingwen.viewmodel.BookStoreVM
import kotlinx.android.synthetic.main.fragment_book_store.*
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -64,6 +66,7 @@ class BookStore : Fragment(), IBaseView {

private fun init() {
val temp = arrayListOf("玄幻", "武侠", "都市", "历史", "科幻", "网游", "女生", "同人")
val categoryManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
val categoryAdapter = BookStoreCategoryAdapter(
R.layout.fragment_book_store_item,
temp
Expand All @@ -84,7 +87,6 @@ class BookStore : Fragment(), IBaseView {
}
getContent()
}
val categoryManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
categoryList.adapter = categoryAdapter
categoryList.layoutManager = categoryManager
categoryList.addOnScrollListener(object : RecyclerView.OnScrollListener() {
Expand Down Expand Up @@ -154,7 +156,10 @@ class BookStore : Fragment(), IBaseView {

val manager = LinearLayoutManager(context)
bookStoreList.layoutManager = manager
bookStoreAdapter = BookStoreListAdapter(viewModel.getList())
bookStoreAdapter = BookStoreListAdapter(viewModel.getList()){
item,view->
ResumeActivity.start(this,item.Id.toLong(),item.Name,view)
}
bookStoreList.adapter = bookStoreAdapter
bookStoreList.addItemDecoration(
DividerItemDecoration(
Expand Down
16 changes: 11 additions & 5 deletions app/src/main/java/com/novel/qingwen/view/fragment/SearchBook.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.novel.qingwen.view.adapter.SearchBookListAdapter
import com.novel.qingwen.view.dialog.NoticeDialog
import com.novel.qingwen.viewmodel.SearchVM
import com.novel.qingwen.utils.Show
import com.novel.qingwen.view.activity.ResumeActivity
import kotlinx.android.synthetic.main.fragment_search_book.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
Expand Down Expand Up @@ -78,7 +79,10 @@ class SearchBook : Fragment(), IBaseView, TextView.OnEditorActionListener, View.
}
})
closeBtn.setOnClickListener(this)
adapter = SearchBookListAdapter(viewModel.getList())
adapter = SearchBookListAdapter(viewModel.getList()){
item,view->
ResumeActivity.start(this,item.Id.toLong(),item.Name,view)
}
val manager = LinearLayoutManager(context)
searchListView.adapter = adapter
searchListView.layoutManager = manager
Expand Down Expand Up @@ -106,8 +110,9 @@ class SearchBook : Fragment(), IBaseView, TextView.OnEditorActionListener, View.

override fun showMsg(msg: String) {
GlobalScope.launch(Dispatchers.Main) {
searchListView.visibility = if(viewModel.getList().size == 0)View.GONE else View.VISIBLE
tips.visibility = if(viewModel.getList().size == 0)View.VISIBLE else View.GONE
searchListView.visibility =
if (viewModel.getList().size == 0) View.GONE else View.VISIBLE
tips.visibility = if (viewModel.getList().size == 0) View.VISIBLE else View.GONE
Toast.makeText(context, msg, Toast.LENGTH_SHORT).show()
if (dialog.isShowing)
dialog.dismiss()
Expand All @@ -116,8 +121,9 @@ class SearchBook : Fragment(), IBaseView, TextView.OnEditorActionListener, View.

override fun onComplete(target: Int) {
GlobalScope.launch(Dispatchers.Main) {
searchListView.visibility = if(viewModel.getList().size == 0)View.GONE else View.VISIBLE
tips.visibility = if(viewModel.getList().size == 0)View.VISIBLE else View.GONE
searchListView.visibility =
if (viewModel.getList().size == 0) View.GONE else View.VISIBLE
tips.visibility = if (viewModel.getList().size == 0) View.VISIBLE else View.GONE
adapter.notifyDataSetChanged()
if (dialog.isShowing)
dialog.dismiss()
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_resume.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
android:layout_height="120dp"
android:layout_alignTop="@id/resumeBg"
android:layout_marginStart="10dp"
android:transitionName="novelPic"
android:layout_marginTop="90dp"
android:background="@android:color/white"
android:scaleType="fitXY"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_book_shelf.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
android:id="@+id/bottomBookShelf"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/backgroundColor">
android:background="@android:color/transparent">

<View
android:background="@drawable/shadow_shape"
Expand Down
Loading

0 comments on commit 20d6175

Please sign in to comment.