Skip to content

Commit

Permalink
日常修改:2024-01-09.
Browse files Browse the repository at this point in the history
  • Loading branch information
walgr committed Jan 9, 2024
1 parent a8e1aec commit 58a2ff9
Show file tree
Hide file tree
Showing 16 changed files with 235 additions and 194 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.wpf.app.quick.activity

import android.content.Context
import android.os.Bundle
import android.view.View
import androidx.annotation.LayoutRes
Expand Down Expand Up @@ -54,6 +55,8 @@ abstract class QuickActivity @JvmOverloads constructor(
return window.decorView
}

fun requireContext() = this

override fun onDestroy() {
super.onDestroy()
cancelJob()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.wpf.app.quick.activity

import androidx.annotation.LayoutRes
import androidx.databinding.ViewDataBinding
import com.wpf.app.quick.activity.viewmodel.QuickVBModel

/**
* Created by 王朋飞 on 2024/01/09
*
*/
abstract class QuickBindingFragment<VB : ViewDataBinding> @JvmOverloads constructor(
@LayoutRes layoutId: Int = 0,
titleName: String = ""
) : QuickVBFragment<QuickVBModel<VB>, VB>(layoutId, titleName = titleName)
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,33 @@ abstract class QuickVBActivity<VM : QuickVBModel<VB>, VB : ViewDataBinding> @Jvm
set(value) {
field = value
if (value != null) {
QuickBind.bind(this, value)
setViewBinding()
value.onBindingCreated(viewBinding)
}
}

private var viewBinding: VB? = null

private fun setViewBinding() {
viewBinding = DataBindingUtil.setContentView(this, layoutId)
viewBinding?.lifecycleOwner = this
if (viewBinding == null) {
viewBinding = DataBindingUtil.setContentView(this, layoutId)
viewBinding?.lifecycleOwner = this
}
viewBinding?.setVariable(BRConstant.viewModel, mViewModel)
setBindingVariable(viewBinding)
viewBinding?.executePendingBindings()
mViewModel?.mViewBinding = viewBinding
}

override fun dealContentView() {
super.dealContentView()
// super.dealContentView()
val viewModelCls: Class<VM>? = ViewModelEx.get0Clazz(this)
if (viewModelCls != null && this !is QuickBindingActivity && viewModelCls != QuickVBModel::class.java) {
mViewModel = ViewModelProvider(
this,
ViewModelProvider.AndroidViewModelFactory(application)
)[viewModelCls]
QuickBind.bind(this, mViewModel)
mViewModel?.onBindingCreated(viewBinding)
} else {
setViewBinding()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ abstract class QuickVBFragment<VM : QuickVBModel<VB>, VB : ViewDataBinding> @Jvm

open fun initViewModel(obj: Any) {
val viewModelCls: Class<VM>? = ViewModelEx.get0Clazz(obj)
if (viewModelCls != null && viewModelCls != QuickVBModel::class.java) {
if (viewModelCls != null && this !is QuickBindingFragment && viewModelCls != QuickVBModel::class.java) {
mViewModel = ViewModelProvider(
this,
ViewModelProvider.AndroidViewModelFactory(requireContext().applicationContext as Application)
Expand Down Expand Up @@ -97,6 +97,7 @@ abstract class QuickVBFragment<VM : QuickVBModel<VB>, VB : ViewDataBinding> @Jvm
mViewModel?.onStop()
}

@Deprecated("Deprecated by Fragment")
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
mViewModel?.onActivityResult(requestCode, resultCode, data)
Expand All @@ -109,7 +110,9 @@ abstract class QuickVBFragment<VM : QuickVBModel<VB>, VB : ViewDataBinding> @Jvm
}

override fun initView(view: View?) {}
abstract fun initView(view: VB?)
open fun initView(view: VB?) {

}

open fun setBindingVariable(view: VB?) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.wpf.app.quickbind.quickview.QuickBindView
import com.wpf.app.quickutil.bind.runOnContext
import com.wpf.app.quickutil.activity.quickStartActivity

@Deprecated("预览不了")
open class GotoThis @JvmOverloads constructor(
mContext: Context,
attributeSet: AttributeSet? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ abstract class QuickItemView @JvmOverloads constructor(
val parentGroup = parent as? ViewGroup ?: return@post
position = parentGroup.indexOfChild(this)
parentGroup.removeView(this)
parentGroup.addView(mView, position, ViewGroup.LayoutParams(layoutParams.width, layoutParams.height))
parentGroup.addView(
mView,
position,
ViewGroup.LayoutParams(layoutParams.width, layoutParams.height)
)
visibility = GONE
onCreateViewHolder()
onBindViewHolder(position)
Expand Down Expand Up @@ -86,7 +90,7 @@ abstract class QuickItemView @JvmOverloads constructor(

//预览可见
override fun onDraw(canvas: Canvas) {
getView()?.draw(canvas)
super.onDraw(canvas)
return getView()?.draw(canvas) ?: super.onDraw(canvas)
}
}
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<activity android:name=".ViewPagerBindFragmentTestActivity"/>
<activity android:name=".RequestTestActivity"/>
<activity android:name=".DialogTestActivity"/>
<activity android:name=".ShadowViewTestActivity"/>
<activity android:name=".wanandroid.WanAndroidHomeActivity"/>
<activity android:name=".wanandroid.WebViewActivity"/>
</application>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ import com.wpf.app.quick.demo.dialog.TestDialog
import com.wpf.app.quickdialog.DialogManager
import com.wpf.app.quickdialog.showInManager
import com.wpf.app.quickutil.bind.runOnContext
import com.wpf.app.quickutil.other.dp2px

class DialogTestActivity : QuickActivity(
layoutViewInContext = runOnContext {
LinearLayout(it).apply {
setPadding(16.dp2px(it), 0, 16.dp2px(it), 0)
orientation = LinearLayout.VERTICAL
gravity = Gravity.CENTER
addView(MaterialButton(it).apply {
text = "弹窗1"
text = "弹窗"
id = R.id.btnNext
})
}
Expand All @@ -27,9 +29,9 @@ class DialogTestActivity : QuickActivity(

override fun initView() {
findViewById<Button>(R.id.btnNext).setOnClickListener {
Test3Dialog(this).showInManager()
Test3Dialog(this).showInManager(showWithOther = true)
it.postDelayed({
Test2Dialog(this).showInManager()
Test2Dialog(this).showInManager(recoverInDismiss = false)
}, 1000)
it.postDelayed({
TestDialog(this).showInManager()
Expand Down
14 changes: 3 additions & 11 deletions app/src/main/java/com/wpf/app/quick/demo/RequestTestActivity.kt
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
package com.wpf.app.quick.demo

import android.content.Context
import android.util.AttributeSet
import com.wpf.app.quick.activity.QuickVBActivity
import com.wpf.app.quick.annotations.getclass.GetClass
import com.wpf.app.quick.demo.databinding.ActivityRequestTestBinding
import com.wpf.app.quick.demo.viewmodel.RequestTestModel
import com.wpf.app.quickbind.quickview.helper.GotoThis

@GetClass
class RequestTestActivity : QuickVBActivity<RequestTestModel, ActivityRequestTestBinding>(
R.layout.activity_request_test,
titleName = "接口测试页"
) {
class GotoRequestTest(
mContext: Context,
attributeSet: AttributeSet? = null,
): GotoThis(
mContext, attributeSet, "接口请求测试", RequestTestActivity::class.java
)
}
)
37 changes: 37 additions & 0 deletions app/src/main/java/com/wpf/app/quick/demo/ShadowViewTestActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.wpf.app.quick.demo

import android.annotation.SuppressLint
import androidx.core.view.isVisible
import com.wpf.app.quick.activity.QuickBindingActivity
import com.wpf.app.quick.annotations.getclass.GetClass
import com.wpf.app.quick.demo.databinding.ActivityShadowTestBinding
import com.wpf.app.quickutil.TimeDelayHelper
import com.wpf.app.quickutil.other.toColor

@GetClass
class ShadowViewTestActivity: QuickBindingActivity<ActivityShadowTestBinding>(
R.layout.activity_shadow_test,
titleName = "同步测试页"
) {
@SuppressLint("SetTextI18n")
override fun initView(view: ActivityShadowTestBinding?) {
val colorList = arrayOf(
R.color.black.toColor(requireContext()),
R.color.colorPrimary.toColor(requireContext()),
R.color.white.toColor(requireContext())
)
var pos = 0
TimeDelayHelper.registerTimeDelay("1s", 1) {
view?.shadow1?.post {
val index = (pos++) % colorList.size
view.shadow1.text = (index + 1).toString()
val newColor = colorList[index]
view.shadow1.setTextColor(newColor)
view.shadow1.visibility
}
}
view?.shadow6?.setOnCheckedChangeListener { _, isChecked ->
view.shadow8.isVisible = isChecked
}
}
}
Original file line number Diff line number Diff line change
@@ -1,41 +1,10 @@
package com.wpf.app.quick.demo.fragment

import android.annotation.SuppressLint
import androidx.compose.ui.graphics.Color
import androidx.core.view.isVisible
import com.wpf.app.quick.activity.QuickVBFragment
import com.wpf.app.quick.activity.QuickBindingFragment
import com.wpf.app.quick.demo.R
import com.wpf.app.quick.demo.databinding.FragmentMainTestBinding
import com.wpf.app.quickutil.LogUtil
import com.wpf.app.quickutil.TimeDelayHelper
import com.wpf.app.quickutil.other.toColor
import java.util.Timer
import java.util.TimerTask
import kotlin.random.Random

class MainTestFragment : QuickVBFragment<MainTestVM, FragmentMainTestBinding>(
class MainTestFragment : QuickBindingFragment<FragmentMainTestBinding>(
R.layout.fragment_main_test,
titleName = "测试场"
) {
@SuppressLint("SetTextI18n")
override fun initView(view: FragmentMainTestBinding?) {
val colorList = arrayOf(
R.color.black.toColor(requireContext()),
R.color.colorPrimary.toColor(requireContext()),
R.color.white.toColor(requireContext())
)
var pos = 0
TimeDelayHelper.registerTimeDelay("1s", 1) {
view?.shadow1?.post {
val index = (pos++) % colorList.size
view.shadow1.text = (index + 1).toString()
val newColor = colorList[index]
view.shadow1.setTextColor(newColor)
view.shadow1.visibility
}
}
view?.shadow6?.setOnCheckedChangeListener { _, isChecked ->
view.shadow8.isVisible = isChecked
}
}
}
)
10 changes: 0 additions & 10 deletions app/src/main/java/com/wpf/app/quick/demo/fragment/MainTestVM.kt

This file was deleted.

16 changes: 5 additions & 11 deletions app/src/main/java/com/wpf/app/quick/demo/http/TestResponse.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import com.wpf.app.quicknetwork.base.BaseResponseIS

@GenerateCommonCall("TestCommon")
@GenerateNormalCall("TestNormal")
open class TestResponse<Data>: BaseResponseIS<Data> {
var data: Data? = null
var errorCode: String? = null
var errorMsg: String? = null
open class TestResponse<Data> @JvmOverloads constructor(
var data: Data? = null,
var errorCode: String? = null,
var errorMsg: String? = null,
): BaseResponseIS<Data> {
override var codeI: String? = null
get() = errorCode
set(value) {
Expand All @@ -28,11 +29,4 @@ open class TestResponse<Data>: BaseResponseIS<Data> {
field = value
data = value
}

//给CallAdapter确定类型使用
internal constructor()
internal constructor(data: Class<Data>)
internal constructor(data: Data?) {
this.data = data
}
}
Loading

0 comments on commit 58a2ff9

Please sign in to comment.