Merge remote-tracking branch 'origin/master'

pull/32/head
atbest 6 years ago
commit 706eb4a810
  1. 18
      app/src/main/java/io/legado/app/base/BaseActivity.kt
  2. 1
      app/src/main/java/io/legado/app/help/permission/PermissionActivity.kt
  3. 26
      app/src/main/java/io/legado/app/help/permission/PermissionsCompat.kt
  4. 37
      app/src/main/java/io/legado/app/ui/widget/TitleBar.kt

@ -22,7 +22,7 @@ abstract class BaseActivity<BD : ViewDataBinding, VM : ViewModel> : AppCompatAct
onViewModelCreated(viewModel, savedInstanceState) onViewModelCreated(viewModel, savedInstanceState)
} }
open fun onViewModelCreated(viewModel: VM, savedInstanceState: Bundle?){ open fun onViewModelCreated(viewModel: VM, savedInstanceState: Bundle?) {
} }
@ -39,20 +39,4 @@ abstract class BaseActivity<BD : ViewDataBinding, VM : ViewModel> : AppCompatAct
open fun onCompatOptionsItemSelected(item: MenuItem): Boolean { open fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
return true return true
} }
override fun setTitle(title: CharSequence?) {
supportActionBar?.title = title
}
override fun setTitle(titleId: Int) {
supportActionBar?.setTitle(titleId)
}
fun setSubTitle(subtitle: CharSequence?) {
supportActionBar?.subtitle = subtitle
}
fun setSubTitle(subtitleId: Int) {
supportActionBar?.setSubtitle(subtitleId)
}
} }

@ -14,7 +14,6 @@ class PermissionActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
val intent = intent
when (intent.getIntExtra(KEY_INPUT_REQUEST_TYPE, Request.TYPE_REQUEST_PERMISSION)) { when (intent.getIntExtra(KEY_INPUT_REQUEST_TYPE, Request.TYPE_REQUEST_PERMISSION)) {
Request.TYPE_REQUEST_PERMISSION//权限请求 Request.TYPE_REQUEST_PERMISSION//权限请求

@ -6,35 +6,35 @@ import androidx.fragment.app.Fragment
class PermissionsCompat private constructor() { class PermissionsCompat private constructor() {
private var mRequest: Request? = null private var request: Request? = null
fun request() { fun request() {
RequestManager.pushRequest(mRequest) RequestManager.pushRequest(request)
} }
class Builder { class Builder {
private val mRequest: Request private val request: Request
constructor(activity: AppCompatActivity) { constructor(activity: AppCompatActivity) {
mRequest = Request(activity) request = Request(activity)
} }
constructor(fragment: Fragment) { constructor(fragment: Fragment) {
mRequest = Request(fragment) request = Request(fragment)
} }
fun addPermissions(vararg permissions: String): Builder { fun addPermissions(vararg permissions: String): Builder {
mRequest.addPermissions(*permissions) request.addPermissions(*permissions)
return this return this
} }
fun requestCode(requestCode: Int): Builder { fun requestCode(requestCode: Int): Builder {
mRequest.setRequestCode(requestCode) request.setRequestCode(requestCode)
return this return this
} }
fun onGranted(callback: (requestCode: Int) -> Unit): Builder { fun onGranted(callback: (requestCode: Int) -> Unit): Builder {
mRequest.setOnGrantedCallback(object : OnPermissionsGrantedCallback { request.setOnGrantedCallback(object : OnPermissionsGrantedCallback {
override fun onPermissionsGranted(requestCode: Int) { override fun onPermissionsGranted(requestCode: Int) {
callback(requestCode) callback(requestCode)
} }
@ -43,7 +43,7 @@ class PermissionsCompat private constructor() {
} }
fun onDenied(callback: (requestCode: Int, deniedPermissions: Array<String>) -> Unit): Builder { fun onDenied(callback: (requestCode: Int, deniedPermissions: Array<String>) -> Unit): Builder {
mRequest.setOnDeniedCallback(object : OnPermissionsDeniedCallback { request.setOnDeniedCallback(object : OnPermissionsDeniedCallback {
override fun onPermissionsDenied(requestCode: Int, deniedPermissions: Array<String>) { override fun onPermissionsDenied(requestCode: Int, deniedPermissions: Array<String>) {
callback(requestCode, deniedPermissions) callback(requestCode, deniedPermissions)
} }
@ -52,24 +52,24 @@ class PermissionsCompat private constructor() {
} }
fun rationale(rationale: CharSequence): Builder { fun rationale(rationale: CharSequence): Builder {
mRequest.setRationale(rationale) request.setRationale(rationale)
return this return this
} }
fun rationale(@StringRes resId: Int): Builder { fun rationale(@StringRes resId: Int): Builder {
mRequest.setRationale(resId) request.setRationale(resId)
return this return this
} }
fun build(): PermissionsCompat { fun build(): PermissionsCompat {
val compat = PermissionsCompat() val compat = PermissionsCompat()
compat.mRequest = mRequest compat.request = request
return compat return compat
} }
fun request(): PermissionsCompat { fun request(): PermissionsCompat {
val compat = build() val compat = build()
compat.mRequest = mRequest compat.request = request
compat.request() compat.request()
return compat return compat
} }

@ -14,7 +14,6 @@ import androidx.appcompat.widget.Toolbar
import androidx.core.graphics.drawable.DrawableCompat import androidx.core.graphics.drawable.DrawableCompat
import com.google.android.material.appbar.AppBarLayout import com.google.android.material.appbar.AppBarLayout
import io.legado.app.R import io.legado.app.R
import kotlinx.android.synthetic.main.view_titlebar.view.*
class TitleBar(context: Context, attrs: AttributeSet?) : AppBarLayout(context, attrs) { class TitleBar(context: Context, attrs: AttributeSet?) : AppBarLayout(context, attrs) {
@ -22,6 +21,18 @@ class TitleBar(context: Context, attrs: AttributeSet?) : AppBarLayout(context, a
val menu: Menu val menu: Menu
get() = toolbar.menu get() = toolbar.menu
var title: CharSequence?
get() = toolbar.title
set(title) {
toolbar.title = title
}
var subtitle: CharSequence?
get() = toolbar.subtitle
set(subtitle) {
toolbar.subtitle = subtitle
}
init { init {
inflate(context, R.layout.view_titlebar, this) inflate(context, R.layout.view_titlebar, this)
toolbar = findViewById(R.id.toolbar) toolbar = findViewById(R.id.toolbar)
@ -39,7 +50,7 @@ class TitleBar(context: Context, attrs: AttributeSet?) : AppBarLayout(context, a
val subtitleText = a.getString(R.styleable.TitleBar_subtitle) val subtitleText = a.getString(R.styleable.TitleBar_subtitle)
toolbar.apply { toolbar.apply {
if(showNavigationIcon){ if (showNavigationIcon) {
this.navigationIcon = navigationIcon this.navigationIcon = navigationIcon
this.navigationContentDescription = navigationContentDescription this.navigationContentDescription = navigationContentDescription
wrapDrawableTint(this.navigationIcon, navigationIconTint, navigationIconTintMode) wrapDrawableTint(this.navigationIcon, navigationIconTint, navigationIconTintMode)
@ -61,11 +72,11 @@ class TitleBar(context: Context, attrs: AttributeSet?) : AppBarLayout(context, a
this.setSubtitleTextColor(a.getColor(R.styleable.TitleBar_subtitleTextColor, -0x1)) this.setSubtitleTextColor(a.getColor(R.styleable.TitleBar_subtitleTextColor, -0x1))
} }
if(!titleText.isNullOrBlank()){ if (!titleText.isNullOrBlank()) {
this.title = titleText this.title = titleText
} }
if(!subtitleText.isNullOrBlank()){ if (!subtitleText.isNullOrBlank()) {
this.subtitle = subtitleText this.subtitle = subtitleText
} }
} }
@ -77,39 +88,31 @@ class TitleBar(context: Context, attrs: AttributeSet?) : AppBarLayout(context, a
} }
} }
fun setNavigationOnClickListener(clickListener: ((View) -> Unit)){ fun setNavigationOnClickListener(clickListener: ((View) -> Unit)) {
toolbar.setNavigationOnClickListener(clickListener) toolbar.setNavigationOnClickListener(clickListener)
} }
fun setTitle(title: CharSequence?) {
toolbar.title = title
}
fun setTitle(titleId: Int) { fun setTitle(titleId: Int) {
toolbar.setTitle(titleId) toolbar.setTitle(titleId)
} }
fun setSubTitle(subtitle: CharSequence?) {
toolbar.subtitle = subtitle
}
fun setSubTitle(subtitleId: Int) { fun setSubTitle(subtitleId: Int) {
toolbar.setSubtitle(subtitleId) toolbar.setSubtitle(subtitleId)
} }
fun setTitleTextColor(@ColorInt color: Int){ fun setTitleTextColor(@ColorInt color: Int) {
toolbar.setTitleTextColor(color) toolbar.setTitleTextColor(color)
} }
fun setTitleTextAppearance(@StyleRes resId: Int){ fun setTitleTextAppearance(@StyleRes resId: Int) {
toolbar.setTitleTextAppearance(context, resId) toolbar.setTitleTextAppearance(context, resId)
} }
fun setSubTitleTextColor(@ColorInt color: Int){ fun setSubTitleTextColor(@ColorInt color: Int) {
toolbar.setSubtitleTextColor(color) toolbar.setSubtitleTextColor(color)
} }
fun setSubTitleTextAppearance(@StyleRes resId: Int){ fun setSubTitleTextAppearance(@StyleRes resId: Int) {
toolbar.setSubtitleTextAppearance(context, resId) toolbar.setSubtitleTextAppearance(context, resId)
} }

Loading…
Cancel
Save