Merge pull request #2 from gedoor/master

up
pull/60/head
口口吕 5 years ago committed by GitHub
commit 67e270f2db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/build.gradle
  2. 3
      app/src/main/AndroidManifest.xml
  3. 23
      app/src/main/java/io/legado/app/base/BaseActivity.kt
  4. 7
      app/src/main/java/io/legado/app/base/VMBaseActivity.kt
  5. 1
      app/src/main/java/io/legado/app/constant/PreferKey.kt
  6. 2
      app/src/main/java/io/legado/app/ui/about/DonateActivity.kt
  7. 2
      app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt
  8. 20
      app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt
  9. 2
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  10. 2
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  11. 1
      app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt
  12. 2
      app/src/main/java/io/legado/app/ui/chapterlist/ChapterListActivity.kt
  13. 2
      app/src/main/java/io/legado/app/ui/config/ConfigActivity.kt
  14. 2
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt
  15. 50
      app/src/main/java/io/legado/app/ui/widget/TitleBar.kt
  16. 27
      app/src/main/res/layout/activity_book_info.xml
  17. 7
      app/src/main/res/values/styles.xml

@ -160,8 +160,6 @@ dependencies {
//MarkDown
implementation 'ru.noties.markwon:core:3.0.2'
//
implementation 'jp.wasabeef:glide-transformations:4.1.0'
}
apply plugin: 'com.google.gms.google-services'

@ -78,8 +78,7 @@
<activity
android:name=".ui.about.DonateActivity"
android:launchMode="singleTask" />
<activity android:name=".ui.book.info.BookInfoActivity"
android:theme="@style/AppTheme.BookInfo" />
<activity android:name=".ui.book.info.BookInfoActivity" />
<activity android:name="io.legado.app.ui.book.info.edit.BookInfoEditActivity" />
<activity android:name=".ui.book.source.debug.BookSourceDebugActivity" />
<activity android:name=".ui.book.source.manage.BookSourceActivity">

@ -19,8 +19,11 @@ import kotlinx.coroutines.MainScope
import kotlinx.coroutines.cancel
abstract class BaseActivity(private val layoutID: Int, private val fullScreen: Boolean = true) :
AppCompatActivity(),
abstract class BaseActivity(
private val layoutID: Int,
private val fullScreen: Boolean = true,
private val theme: Theme = Theme.Auto
) : AppCompatActivity(),
CoroutineScope by MainScope() {
override fun onCreate(savedInstanceState: Bundle?) {
@ -73,10 +76,14 @@ abstract class BaseActivity(private val layoutID: Int, private val fullScreen: B
private fun initTheme() {
ATH.applyBackgroundTint(window.decorView)
if (ColorUtils.isColorLight(primaryColor)) {
setTheme(R.style.AppTheme_Light)
} else {
setTheme(R.style.AppTheme_Dark)
when (theme) {
Theme.Dark -> setTheme(R.style.AppTheme_Dark)
Theme.Light -> setTheme(R.style.AppTheme_Light)
else -> if (ColorUtils.isColorLight(primaryColor)) {
setTheme(R.style.AppTheme_Light)
} else {
setTheme(R.style.AppTheme_Dark)
}
}
}
@ -100,4 +107,8 @@ abstract class BaseActivity(private val layoutID: Int, private val fullScreen: B
currentFocus?.hideSoftInput()
super.finish()
}
enum class Theme {
Dark, Light, Auto
}
}

@ -2,8 +2,11 @@ package io.legado.app.base
import androidx.lifecycle.ViewModel
abstract class VMBaseActivity<VM : ViewModel>(layoutID: Int, fullScreen: Boolean = true) :
BaseActivity(layoutID, fullScreen) {
abstract class VMBaseActivity<VM : ViewModel>(
layoutID: Int,
fullScreen: Boolean = true,
theme: Theme = Theme.Auto
) : BaseActivity(layoutID, fullScreen, theme) {
protected abstract val viewModel: VM

@ -13,4 +13,5 @@ object PreferKey {
const val recordLog = "recordLog"
const val processText = "process_text"
const val cleanCache = "cleanCache"
const val lastGroup = "lastGroup"
}

@ -13,7 +13,6 @@ import io.legado.app.base.BaseActivity
import io.legado.app.lib.theme.ATH
import io.legado.app.utils.ACache
import kotlinx.android.synthetic.main.activity_donate.*
import kotlinx.android.synthetic.main.view_title_bar.*
import org.jetbrains.anko.toast
import java.net.URLEncoder
@ -25,7 +24,6 @@ import java.net.URLEncoder
class DonateActivity : BaseActivity(R.layout.activity_donate) {
override fun onActivityCreated(savedInstanceState: Bundle?) {
setSupportActionBar(toolbar)
ATH.applyEdgeEffectColor(scroll_view)
vw_zfb_tz.setOnClickListener { aliDonate(this) }
cv_wx_gzh.setOnClickListener {

@ -26,7 +26,6 @@ import io.legado.app.ui.changesource.ChangeSourceDialog
import io.legado.app.ui.chapterlist.ChapterListActivity
import io.legado.app.utils.*
import kotlinx.android.synthetic.main.activity_audio_play.*
import kotlinx.android.synthetic.main.view_title_bar.*
import org.apache.commons.lang3.time.DateFormatUtils
import org.jetbrains.anko.sdk27.listeners.onClick
import org.jetbrains.anko.sdk27.listeners.onLongClick
@ -43,7 +42,6 @@ class AudioPlayActivity : VMBaseActivity<AudioPlayViewModel>(R.layout.activity_a
private var adjustProgress = false
override fun onActivityCreated(savedInstanceState: Bundle?) {
setSupportActionBar(toolbar)
AudioPlay.titleData.observe(this, Observer { title_bar.title = it })
AudioPlay.coverData.observe(this, Observer { upCover(it) })
viewModel.initData(intent)

@ -2,11 +2,13 @@ package io.legado.app.ui.book.info
import android.app.Activity
import android.content.Intent
import android.graphics.drawable.Drawable
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import androidx.lifecycle.Observer
import com.bumptech.glide.Glide
import com.bumptech.glide.RequestBuilder
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.bumptech.glide.request.RequestOptions.bitmapTransform
import io.legado.app.R
@ -15,6 +17,7 @@ import io.legado.app.constant.BookType
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter
import io.legado.app.data.entities.BookGroup
import io.legado.app.help.BlurTransformation
import io.legado.app.help.ImageLoader
import io.legado.app.help.IntentDataHelp
import io.legado.app.ui.audio.AudioPlayActivity
@ -26,15 +29,14 @@ import io.legado.app.ui.chapterlist.ChapterListActivity
import io.legado.app.utils.getViewModel
import io.legado.app.utils.gone
import io.legado.app.utils.visible
import jp.wasabeef.glide.transformations.BlurTransformation
import kotlinx.android.synthetic.main.activity_book_info.*
import kotlinx.android.synthetic.main.view_title_bar.*
import org.jetbrains.anko.sdk27.listeners.onClick
import org.jetbrains.anko.startActivity
import org.jetbrains.anko.toast
class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_book_info),
class BookInfoActivity :
VMBaseActivity<BookInfoViewModel>(R.layout.activity_book_info, theme = Theme.Dark),
GroupSelectDialog.CallBack,
ChapterListAdapter.CallBack,
ChangeSourceDialog.CallBack {
@ -43,8 +45,7 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_boo
get() = getViewModel(BookInfoViewModel::class.java)
override fun onActivityCreated(savedInstanceState: Bundle?) {
setSupportActionBar(toolbar)
title_bar.getBackground().setAlpha(0)
title_bar.background.alpha = 0
viewModel.bookData.observe(this, Observer { showBook(it) })
viewModel.isLoadingData.observe(this, Observer { upLoading(it) })
viewModel.chapterListData.observe(this, Observer { showChapter(it) })
@ -96,6 +97,11 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_boo
return super.onMenuOpened(featureId, menu)
}
private fun defaultCover(): RequestBuilder<Drawable> {
return ImageLoader.load(this, R.drawable.image_cover_default)
.apply(bitmapTransform(BlurTransformation(this, 25)))
}
private fun showBook(book: Book) {
tv_name.text = book.name
tv_author.text = getString(R.string.author_show, book.author)
@ -110,9 +116,9 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_boo
.into(iv_cover)
Glide.with(this).load(it)
.transition(DrawableTransitionOptions.withCrossFade(1500))
.error(R.drawable.image_cover_default)
.thumbnail(defaultCover())
.centerCrop()
.apply(bitmapTransform(BlurTransformation(125, 6)))
.apply(bitmapTransform(BlurTransformation(this, 25)))
.into(bg_book) //模糊、渐变、缩小效果
}
val kinds = book.getKindList()

@ -40,7 +40,6 @@ import io.legado.app.utils.*
import kotlinx.android.synthetic.main.activity_book_read.*
import kotlinx.android.synthetic.main.view_book_page.*
import kotlinx.android.synthetic.main.view_read_menu.*
import kotlinx.android.synthetic.main.view_title_bar.*
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.launch
@ -66,7 +65,6 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
override fun onActivityCreated(savedInstanceState: Bundle?) {
Help.upLayoutInDisplayCutoutMode(window)
setSupportActionBar(toolbar)
initView()
ReadBook.callBack = this
ReadBook.titleDate.observe(this, Observer { title_bar.title = it })

@ -36,7 +36,6 @@ import io.legado.app.utils.*
import kotlinx.android.synthetic.main.activity_book_source.*
import kotlinx.android.synthetic.main.dialog_edit_text.view.*
import kotlinx.android.synthetic.main.view_search.*
import kotlinx.android.synthetic.main.view_title_bar.*
import org.jetbrains.anko.startActivity
import org.jetbrains.anko.startActivityForResult
import org.jetbrains.anko.startService
@ -57,7 +56,6 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
private var groupMenu: SubMenu? = null
override fun onActivityCreated(savedInstanceState: Bundle?) {
setSupportActionBar(toolbar)
initUriScheme()
initRecyclerView()
initSearchView()

@ -121,6 +121,7 @@ class ChangeSourceDialog : DialogFragment(),
override fun changeTo(searchBook: SearchBook) {
val book = searchBook.toBook()
callBack?.oldBook?.let { oldBook ->
book.group = oldBook.group
book.durChapterIndex = oldBook.durChapterIndex
book.durChapterPos = oldBook.durChapterPos
book.durChapterTitle = oldBook.durChapterTitle

@ -17,7 +17,6 @@ import io.legado.app.utils.gone
import io.legado.app.utils.visible
import kotlinx.android.synthetic.main.activity_chapter_list.*
import kotlinx.android.synthetic.main.view_tab_layout.*
import kotlinx.android.synthetic.main.view_title_bar.*
class ChapterListActivity : VMBaseActivity<ChapterListViewModel>(R.layout.activity_chapter_list) {
override val viewModel: ChapterListViewModel
@ -26,7 +25,6 @@ class ChapterListActivity : VMBaseActivity<ChapterListViewModel>(R.layout.activi
private var searchView: SearchView? = null
override fun onActivityCreated(savedInstanceState: Bundle?) {
setSupportActionBar(toolbar)
tab_layout.setSelectedTabIndicatorColor(accentColor)
viewModel.bookUrl = intent.getStringExtra("bookUrl")
viewModel.loadBook {

@ -5,7 +5,6 @@ import io.legado.app.R
import io.legado.app.base.VMBaseActivity
import io.legado.app.utils.getViewModel
import kotlinx.android.synthetic.main.activity_config.*
import kotlinx.android.synthetic.main.view_title_bar.*
class ConfigActivity : VMBaseActivity<ConfigViewModel>(R.layout.activity_config) {
override val viewModel: ConfigViewModel
@ -15,7 +14,6 @@ class ConfigActivity : VMBaseActivity<ConfigViewModel>(R.layout.activity_config)
intent.getIntExtra("configType", -1).let {
if (it != -1) viewModel.configType = it
}
this.setSupportActionBar(toolbar)
when (viewModel.configType) {
ConfigViewModel.TYPE_CONFIG -> {

@ -35,7 +35,6 @@ import io.legado.app.utils.*
import kotlinx.android.synthetic.main.activity_rss_source.*
import kotlinx.android.synthetic.main.dialog_edit_text.view.*
import kotlinx.android.synthetic.main.view_search.*
import kotlinx.android.synthetic.main.view_title_bar.*
import org.jetbrains.anko.startActivity
import org.jetbrains.anko.startActivityForResult
@ -55,7 +54,6 @@ class RssSourceActivity : VMBaseActivity<RssSourceViewModel>(R.layout.activity_r
private var groupMenu: SubMenu? = null
override fun onActivityCreated(savedInstanceState: Bundle?) {
setSupportActionBar(toolbar)
initRecyclerView()
initSearchView()
initLiveDataGroup()

@ -2,21 +2,15 @@ package io.legado.app.ui.widget
import android.content.Context
import android.content.res.ColorStateList
import android.graphics.Color
import android.graphics.PorterDuff
import android.graphics.drawable.Drawable
import android.util.AttributeSet
import android.view.Menu
import android.view.View
import androidx.annotation.ColorInt
import androidx.annotation.StyleRes
import androidx.appcompat.widget.Toolbar
import androidx.core.graphics.drawable.DrawableCompat
import com.google.android.material.appbar.AppBarLayout
import io.legado.app.R
import io.legado.app.lib.theme.DrawableUtils
import io.legado.app.lib.theme.primaryColor
import io.legado.app.lib.theme.primaryTextColor
import io.legado.app.utils.activity
import io.legado.app.utils.getNavigationBarHeight
import io.legado.app.utils.getStatusBarHeight
@ -190,50 +184,6 @@ class TitleBar(context: Context, attrs: AttributeSet?) : AppBarLayout(context, a
it.supportActionBar?.setDisplayHomeAsUpEnabled(displayHomeAsUp)
}
}
val primaryTextColor = if (isInEditMode) Color.BLACK else context.primaryTextColor
DrawableUtils.setTint(toolbar.overflowIcon, primaryTextColor)
toolbar.setTitleTextColor(primaryTextColor)
if (navigationIconTint != null) {
wrapDrawableTint(toolbar.navigationIcon, navigationIconTint, navigationIconTintMode)
} else {
wrapDrawableTint(
toolbar.navigationIcon,
ColorStateList.valueOf(primaryTextColor),
navigationIconTintMode
)
}
}
private fun wrapDrawableTint(drawable: Drawable?, tintList: ColorStateList?, tintMode: Int) {
if (drawable == null || tintList == null) return
val wrappedDrawable = DrawableCompat.wrap(drawable.mutate())
DrawableCompat.setTintList(wrappedDrawable, tintList)
DrawableCompat.setTintMode(wrappedDrawable, intToMode(tintMode))
}
private fun intToMode(`val`: Int): PorterDuff.Mode {
when (`val`) {
0 -> return PorterDuff.Mode.CLEAR
1 -> return PorterDuff.Mode.SRC
2 -> return PorterDuff.Mode.DST
3 -> return PorterDuff.Mode.SRC_OVER
4 -> return PorterDuff.Mode.DST_OVER
5 -> return PorterDuff.Mode.SRC_IN
6 -> return PorterDuff.Mode.DST_IN
7 -> return PorterDuff.Mode.SRC_OUT
8 -> return PorterDuff.Mode.DST_OUT
9 -> return PorterDuff.Mode.SRC_ATOP
10 -> return PorterDuff.Mode.DST_ATOP
11 -> return PorterDuff.Mode.XOR
16 -> return PorterDuff.Mode.DARKEN
17 -> return PorterDuff.Mode.LIGHTEN
13 -> return PorterDuff.Mode.MULTIPLY
14 -> return PorterDuff.Mode.SCREEN
12 -> return PorterDuff.Mode.ADD
15 -> return PorterDuff.Mode.OVERLAY
else -> return PorterDuff.Mode.CLEAR
}
}
}

@ -9,9 +9,19 @@
<ImageView
android:id="@+id/bg_book"
android:layout_width="match_parent"
android:layout_height="256dp"
android:layout_height="0dp"
android:scaleType="centerCrop"
android:contentDescription="@string/bg_image"
app:layout_constraintBottom_toTopOf="@+id/view_info"
android:scaleType="centerCrop" />
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/vw_bg"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#50000000"
app:layout_constraintBottom_toTopOf="@+id/view_info"
app:layout_constraintTop_toTopOf="parent" />
<io.legado.app.ui.widget.TitleBar
android:id="@+id/title_bar"
@ -49,7 +59,7 @@
android:layout_height="wrap_content"
android:layout_marginBottom="6dp"
android:singleLine="true"
android:textColor="@color/tv_text_default"
android:textColor="@color/md_white_1000"
android:textSize="18sp" />
<TextView
@ -58,6 +68,7 @@
android:layout_height="wrap_content"
android:layout_marginBottom="3dp"
android:singleLine="true"
android:textColor="@color/md_white_1000"
android:textSize="16sp" />
<LinearLayout
@ -73,6 +84,7 @@
android:layout_weight="1"
android:singleLine="true"
android:textSize="16sp"
android:textColor="@color/md_white_1000"
tools:ignore="NestedWeights" />
<io.legado.app.lib.theme.view.ATEAccentBgTextView
@ -140,6 +152,7 @@
android:layout_marginBottom="4dp"
android:singleLine="true"
android:textSize="16sp"
android:textColor="@color/md_white_1000"
app:layout_constraintBottom_toBottomOf="@+id/iv_cover"
app:layout_constraintLeft_toLeftOf="@+id/tv_name"
app:layout_constraintRight_toRightOf="@id/tv_name" />
@ -152,8 +165,8 @@
android:layout_height="0dp"
android:layout_marginTop="10dp"
android:orientation="vertical"
app:layout_constraintTop_toBottomOf="@+id/iv_cover"
app:layout_constraintBottom_toTopOf="@+id/view_other">
app:layout_constraintBottom_toTopOf="@+id/view_other"
app:layout_constraintTop_toBottomOf="@+id/iv_cover">
<View
android:layout_width="match_parent"
@ -196,8 +209,8 @@
android:orientation="vertical"
android:paddingTop="12dp"
android:paddingBottom="12dp"
app:layout_constraintTop_toBottomOf="@+id/view_info"
app:layout_constraintBottom_toTopOf="@+id/fl_action">
app:layout_constraintBottom_toTopOf="@+id/fl_action"
app:layout_constraintTop_toBottomOf="@+id/view_info">
<TextView
android:id="@+id/tv_group"

@ -23,12 +23,6 @@
<item name="android:windowNoTitle">true</item>
</style>
<!-- BookInfo主题 -->
<style name="AppTheme.BookInfo" parent="Base.AppTheme">
<item name="actionBarStyle">@style/AppTheme.AppBarOverlay.Light</item>
<item name="elevation">0dp</item><!--去掉toolbar阴影,去线留白-->
</style>
<!-- Base application theme. -->
<style name="Base.AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
@ -39,6 +33,7 @@
<item name="android:popupMenuStyle">@style/Style.PopupMenu</item>
<item name="android:statusBarColor">@color/transparent</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="elevation">0dp</item>
</style>
<style name="AppTheme.AppBarOverlay.Light" parent="ThemeOverlay.AppCompat.Light">

Loading…
Cancel
Save