From f5c79a7c1016e3c2d30f82da16779bec938177fa Mon Sep 17 00:00:00 2001 From: Invinciblelee <1760316362@qq.com> Date: Fri, 24 May 2019 16:16:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9D=83=E9=99=90=E8=AF=B7?= =?UTF-8?q?=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/base/BaseActivity.kt | 18 +-------- .../app/help/permission/PermissionActivity.kt | 1 - .../app/help/permission/PermissionsCompat.kt | 26 ++++++------- .../java/io/legado/app/ui/widget/TitleBar.kt | 37 ++++++++++--------- 4 files changed, 34 insertions(+), 48 deletions(-) diff --git a/app/src/main/java/io/legado/app/base/BaseActivity.kt b/app/src/main/java/io/legado/app/base/BaseActivity.kt index f2f2aab07..8e23928f4 100644 --- a/app/src/main/java/io/legado/app/base/BaseActivity.kt +++ b/app/src/main/java/io/legado/app/base/BaseActivity.kt @@ -22,7 +22,7 @@ abstract class BaseActivity : AppCompatAct onViewModelCreated(viewModel, savedInstanceState) } - open fun onViewModelCreated(viewModel: VM, savedInstanceState: Bundle?){ + open fun onViewModelCreated(viewModel: VM, savedInstanceState: Bundle?) { } @@ -39,20 +39,4 @@ abstract class BaseActivity : 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) - } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/permission/PermissionActivity.kt b/app/src/main/java/io/legado/app/help/permission/PermissionActivity.kt index 98ecf5b67..04722997b 100644 --- a/app/src/main/java/io/legado/app/help/permission/PermissionActivity.kt +++ b/app/src/main/java/io/legado/app/help/permission/PermissionActivity.kt @@ -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//权限请求 diff --git a/app/src/main/java/io/legado/app/help/permission/PermissionsCompat.kt b/app/src/main/java/io/legado/app/help/permission/PermissionsCompat.kt index 45ef0f885..a5ccdb266 100644 --- a/app/src/main/java/io/legado/app/help/permission/PermissionsCompat.kt +++ b/app/src/main/java/io/legado/app/help/permission/PermissionsCompat.kt @@ -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) -> Unit): Builder { - mRequest.setOnDeniedCallback(object : OnPermissionsDeniedCallback { + request.setOnDeniedCallback(object : OnPermissionsDeniedCallback { override fun onPermissionsDenied(requestCode: Int, deniedPermissions: Array) { 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 } diff --git a/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt b/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt index 74226b58c..75fa15765 100644 --- a/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt +++ b/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt @@ -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) @@ -39,7 +50,7 @@ class TitleBar(context: Context, attrs: AttributeSet?) : AppBarLayout(context, a val subtitleText = a.getString(R.styleable.TitleBar_subtitle) toolbar.apply { - if(showNavigationIcon){ + if (showNavigationIcon) { this.navigationIcon = navigationIcon this.navigationContentDescription = navigationContentDescription 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)) } - if(!titleText.isNullOrBlank()){ + if (!titleText.isNullOrBlank()) { this.title = titleText } - if(!subtitleText.isNullOrBlank()){ + if (!subtitleText.isNullOrBlank()) { 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) } - 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) } - fun setTitleTextColor(@ColorInt color: Int){ + fun setTitleTextColor(@ColorInt color: Int) { toolbar.setTitleTextColor(color) } - fun setTitleTextAppearance(@StyleRes resId: Int){ + fun setTitleTextAppearance(@StyleRes resId: Int) { toolbar.setTitleTextAppearance(context, resId) } - fun setSubTitleTextColor(@ColorInt color: Int){ + fun setSubTitleTextColor(@ColorInt color: Int) { toolbar.setSubtitleTextColor(color) } - fun setSubTitleTextAppearance(@StyleRes resId: Int){ + fun setSubTitleTextAppearance(@StyleRes resId: Int) { toolbar.setSubtitleTextAppearance(context, resId) }