Merge remote-tracking branch 'origin/desirepath' into desirepath

# Conflicts:
#	app/src/main/java/io/legado/app/base/BaseActivity.kt
pull/32/head
Invinciblelee 6 years ago
commit ad8c42ba63
  1. 18
      app/src/main/java/io/legado/app/base/BaseActivity.kt
  2. 23
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt
  3. 6
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt
  4. 5
      app/src/main/java/io/legado/app/ui/main/booksource/BookSourceFragment.kt
  5. 5
      app/src/main/java/io/legado/app/ui/main/findbook/FindBookFragment.kt
  6. 5
      app/src/main/java/io/legado/app/ui/main/myconfig/MyConfigFragment.kt
  7. 15
      app/src/main/java/io/legado/app/ui/widget/TitleBar.kt
  8. 12
      app/src/main/java/io/legado/app/utils/AnkoExtensions.kt
  9. 17
      app/src/main/java/io/legado/app/utils/ContextExtensions.kt
  10. 4
      app/src/main/res/layout/activity_main.xml
  11. 1
      app/src/main/res/layout/fragment_book_source.xml
  12. 14
      app/src/main/res/layout/fragment_bookshelf.xml
  13. 1
      app/src/main/res/layout/fragment_find_book.xml
  14. 7
      app/src/main/res/layout/fragment_my_config.xml
  15. 2
      app/src/main/res/values/attrs.xml
  16. 3
      app/src/main/res/values/styles.xml

@ -1,12 +1,14 @@
package io.legado.app.base
import android.graphics.Color
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.view.WindowManager
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.view.menu.MenuBuilder
import androidx.appcompat.view.menu.MenuItemImpl
import androidx.core.content.ContextCompat
import androidx.core.view.forEach
import androidx.lifecycle.ViewModel
import io.legado.app.R
@ -14,6 +16,8 @@ import io.legado.app.lib.theme.ColorUtils
import io.legado.app.lib.theme.DrawableUtils
import io.legado.app.lib.theme.ThemeStore
import io.legado.app.lib.theme.getPrimaryTextColor
import io.legado.app.utils.getCompatColor
abstract class BaseActivity<VM : ViewModel> : AppCompatActivity() {
@ -23,6 +27,7 @@ abstract class BaseActivity<VM : ViewModel> : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
initTheme()
setupSystemBar()
super.onCreate(savedInstanceState)
setContentView(layoutID)
onViewModelCreated(viewModel, savedInstanceState)
@ -37,8 +42,8 @@ abstract class BaseActivity<VM : ViewModel> : AppCompatActivity() {
}
val bool = onCompatCreateOptionsMenu(it)
val primaryTextColor = getPrimaryTextColor(ColorUtils.isColorLight(ThemeStore.primaryColor(this)))
val defaultTextColor = ContextCompat.getColor(this, R.color.tv_text_default)
menu.forEach {item ->
val defaultTextColor = getCompatColor(R.color.tv_text_default)
menu.forEach { item ->
(item as MenuItemImpl).let { impl ->
//overflow:展开的item
DrawableUtils.setTint(
@ -77,4 +82,11 @@ abstract class BaseActivity<VM : ViewModel> : AppCompatActivity() {
setTheme(R.style.AppTheme_Dark)
}
}
protected fun setupSystemBar() {
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS or WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION)
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
window.statusBarColor = Color.TRANSPARENT
}
}

@ -22,7 +22,6 @@ import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : BaseActivity<MainViewModel>(), BottomNavigationView.OnNavigationItemSelectedListener,
ViewPager.OnPageChangeListener {
private val mFragmentList: ArrayList<Fragment> = ArrayList()
override val viewModel: MainViewModel
get() = getViewModel(MainViewModel::class.java)
@ -31,12 +30,8 @@ class MainActivity : BaseActivity<MainViewModel>(), BottomNavigationView.OnNavig
get() = R.layout.activity_main
override fun onViewModelCreated(viewModel: MainViewModel, savedInstanceState: Bundle?) {
mFragmentList.add(BookshelfFragment(R.layout.fragment_bookshelf))
mFragmentList.add(FindBookFragment(R.layout.fragment_find_book))
mFragmentList.add(BookSourceFragment(R.layout.fragment_book_source))
mFragmentList.add(MyConfigFragment(R.layout.fragment_my_config))
view_pager_main.adapter =
TabFragmentPageAdapter(supportFragmentManager, FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT)
view_pager_main.offscreenPageLimit = 3
view_pager_main.adapter = TabFragmentPageAdapter(supportFragmentManager)
view_pager_main.addOnPageChangeListener(this)
bottom_navigation_view.setOnNavigationItemSelectedListener(this)
}
@ -81,17 +76,21 @@ class MainActivity : BaseActivity<MainViewModel>(), BottomNavigationView.OnNavig
bottom_navigation_view.menu.getItem(position).isChecked = true
}
inner class TabFragmentPageAdapter internal constructor(fm: FragmentManager, behavior: Int) :
FragmentPagerAdapter(fm, behavior) {
private inner class TabFragmentPageAdapter internal constructor(fm: FragmentManager) :
FragmentPagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {
override fun getItem(position: Int): Fragment {
return mFragmentList[position]
return when (position) {
0 -> BookshelfFragment()
1 -> FindBookFragment()
2 -> BookSourceFragment()
else -> MyConfigFragment()
}
}
override fun getCount(): Int {
return mFragmentList.size
return 4
}
}
}

@ -1,13 +1,17 @@
package io.legado.app.ui.main.bookshelf
import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.fragment.app.Fragment
import io.legado.app.R
class BookshelfFragment(contentLayoutId: Int) : Fragment(contentLayoutId) {
class BookshelfFragment : Fragment(R.layout.fragment_bookshelf) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
Log.e("TAG", "BookshelfFragment")
}

@ -1,13 +1,16 @@
package io.legado.app.ui.main.booksource
import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.fragment.app.Fragment
import io.legado.app.R
class BookSourceFragment(contentLayoutId: Int) : Fragment(contentLayoutId) {
class BookSourceFragment : Fragment(R.layout.fragment_book_source) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
Log.e("TAG", "BookSourceFragment")
}
}

@ -1,13 +1,16 @@
package io.legado.app.ui.main.findbook
import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.fragment.app.Fragment
import io.legado.app.R
class FindBookFragment(contentLayoutId: Int) : Fragment(contentLayoutId) {
class FindBookFragment : Fragment(R.layout.fragment_find_book) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
Log.e("TAG", "FindBookFragment")
}
}

@ -1,13 +1,16 @@
package io.legado.app.ui.main.myconfig
import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.fragment.app.Fragment
import io.legado.app.R
class MyConfigFragment(contentLayoutId: Int) : Fragment(contentLayoutId) {
class MyConfigFragment : Fragment(R.layout.fragment_my_config) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
Log.e("TAG", "MyConfigFragment")
}
}

@ -14,6 +14,9 @@ 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.utils.getStatusBarHeight
import org.jetbrains.anko.bottomPadding
import org.jetbrains.anko.topPadding
class TitleBar(context: Context, attrs: AttributeSet?) : AppBarLayout(context, attrs) {
@ -84,6 +87,14 @@ class TitleBar(context: Context, attrs: AttributeSet?) : AppBarLayout(context, a
}
}
if (a.getBoolean(R.styleable.TitleBar_fitStatusBar, true)) {
topPadding = context.getStatusBarHeight()
}
if (a.getBoolean(R.styleable.TitleBar_fitNavigationBar, false)) {
bottomPadding = context.getStatusBarHeight()
}
a.recycle()
if (attachToActivity) {
@ -122,8 +133,8 @@ class TitleBar(context: Context, attrs: AttributeSet?) : AppBarLayout(context, a
private fun attachToActivity(context: Context) {
val activity = getCompatActivity(context)
activity?.let {
activity.setSupportActionBar(toolbar)
activity.supportActionBar?.setDisplayHomeAsUpEnabled(mDisplayHomeAsUp)
it.setSupportActionBar(toolbar)
it.supportActionBar?.setDisplayHomeAsUpEnabled(mDisplayHomeAsUp)
}
}

@ -1,6 +1,12 @@
package io.legado.app.utils
import android.app.Activity
import android.content.res.ColorStateList
import android.graphics.drawable.Drawable
import android.view.View
import android.view.WindowManager
import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.fragment.app.Fragment
import com.google.android.material.snackbar.Snackbar
@ -51,3 +57,9 @@ fun Fragment.longToast(text: CharSequence) = requireActivity().longToast(text)
fun Fragment.dip(value: Int): Int = requireActivity().dip(value)
fun Fragment.dip(value: Float): Int = requireActivity().dip(value)
fun Fragment.getCompatColor(@ColorRes id: Int): Int = requireContext().getCompatColor(id)
fun Fragment.getCompatDrawable(@DrawableRes id: Int): Drawable? = requireContext().getCompatDrawable(id)
fun Fragment.getCompatColorStateList(@ColorRes id: Int): ColorStateList? = requireContext().getCompatColorStateList(id)

@ -1,6 +1,11 @@
package io.legado.app.utils
import android.content.Context
import android.content.res.ColorStateList
import android.graphics.drawable.Drawable
import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes
import androidx.core.content.ContextCompat
import androidx.core.content.edit
import org.jetbrains.anko.connectivityManager
import org.jetbrains.anko.defaultSharedPreferences
@ -40,3 +45,15 @@ fun Context.putPrefStringSet(key: String, value: MutableSet<String>) =
fun Context.removePref(key: String) =
defaultSharedPreferences.edit { remove(key) }
fun Context.getCompatColor(@ColorRes id: Int): Int = ContextCompat.getColor(this, id)
fun Context.getCompatDrawable(@DrawableRes id: Int): Drawable? = ContextCompat.getDrawable(this, id)
fun Context.getCompatColorStateList(@ColorRes id: Int): ColorStateList? = ContextCompat.getColorStateList(this, id)
fun Context.getStatusBarHeight(): Int {
val resourceId = resources.getIdentifier("status_bar_height", "dimen", "android")
return resources.getDimensionPixelSize(resourceId)
}

@ -3,13 +3,13 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
android:layout_height="match_parent">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="6dp"
android:background="@color/background"
app:labelVisibilityMode="labeled"
app:menu="@menu/activity_main_bnv"

@ -9,6 +9,7 @@
android:id="@+id/title_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:attachToActivity="false"
app:layout_constraintTop_toTopOf="parent"
app:title="@string/book_source"/>

@ -1,15 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<io.legado.app.ui.widget.TitleBar
android:id="@+id/title_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:attachToActivity="false"
app:layout_constraintTop_toTopOf="parent"
app:title="@string/bookshelf"/>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

@ -9,6 +9,7 @@
android:id="@+id/title_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:attachToActivity="false"
app:layout_constraintTop_toTopOf="parent"
app:title="@string/find"/>

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
@ -9,7 +8,9 @@
android:id="@+id/title_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:attachToActivity="false"
app:layout_constraintTop_toTopOf="parent"
app:title="我的"/>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

@ -11,6 +11,8 @@
<attr name="attachToActivity" format="boolean"/>
<attr name="displayHomeAsUp" format="boolean"/>
<attr name="navigationIcon" format="reference"/>
<attr name="fitStatusBar" format="boolean"/>
<attr name="fitNavigationBar" format="boolean"/>
<attr name="navigationContentDescription" format="reference|string"/>
<attr name="navigationIconTint" format="color|reference"/>
<attr name="navigationIconTintMode" format="enum">

@ -31,7 +31,8 @@
<item name="actionOverflowMenuStyle">@style/Style.PopupMenu</item>
<item name="android:itemTextAppearance">@style/Style.MenuItemText</item>
<item name="android:popupMenuStyle">@style/Style.PopupMenu</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:statusBarColor">@color/transparent</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
</style>
<style name="AppTheme.AppBarOverlay.Light" parent="ThemeOverlay.AppCompat.Light">

Loading…
Cancel
Save