Merge remote-tracking branch 'origin/master'

pull/32/head
atbest 6 years ago
commit 706eb4a810
  1. 16
      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. 21
      app/src/main/java/io/legado/app/ui/widget/TitleBar.kt

@ -39,20 +39,4 @@ abstract class BaseActivity<BD : ViewDataBinding, VM : ViewModel> : AppCompatAct
open fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
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?) {
super.onCreate(savedInstanceState)
val intent = intent
when (intent.getIntExtra(KEY_INPUT_REQUEST_TYPE, Request.TYPE_REQUEST_PERMISSION)) {
Request.TYPE_REQUEST_PERMISSION//权限请求

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

@ -14,7 +14,6 @@ import androidx.appcompat.widget.Toolbar
import androidx.core.graphics.drawable.DrawableCompat
import com.google.android.material.appbar.AppBarLayout
import io.legado.app.R
import kotlinx.android.synthetic.main.view_titlebar.view.*
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
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 {
inflate(context, R.layout.view_titlebar, this)
toolbar = findViewById(R.id.toolbar)
@ -81,18 +92,10 @@ class TitleBar(context: Context, attrs: AttributeSet?) : AppBarLayout(context, a
toolbar.setNavigationOnClickListener(clickListener)
}
fun setTitle(title: CharSequence?) {
toolbar.title = title
}
fun setTitle(titleId: Int) {
toolbar.setTitle(titleId)
}
fun setSubTitle(subtitle: CharSequence?) {
toolbar.subtitle = subtitle
}
fun setSubTitle(subtitleId: Int) {
toolbar.setSubtitle(subtitleId)
}

Loading…
Cancel
Save