Skip to content

Commit

Permalink
日常提交:2022-11-07.
Browse files Browse the repository at this point in the history
Signed-off-by: 王朋飞 <walgr1010>
  • Loading branch information
王朋飞 committed Nov 7, 2022
1 parent acc9628 commit fd27ad5
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,8 @@ open class QuickBottomSheetView(
init {
initView()
}

override fun getViewContext(): Context {
return context
}
}
1 change: 1 addition & 0 deletions QuickDialog/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ android {

dependencies {
compileOnly deps.androidx.material
compileOnly deps.androidx.activityktx

if (IS_REMOTE.toBoolean()) {
api deps.quickbind.util
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ abstract class QuickBottomSheetDialog : BottomSheetDialog,
mView = if (layoutView != null) {
layoutView
} else {
View.inflate(context, layoutId, null)
View.inflate(getViewContext(), layoutId, null)
}
setContentView(mView!!)
val window = window
Expand Down Expand Up @@ -139,4 +139,8 @@ abstract class QuickBottomSheetDialog : BottomSheetDialog,
super.dismiss()
onDialogClose()
}

override fun getViewContext(): Context {
return context
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ open class QuickBottomSheetDialogFragment @JvmOverloads constructor(
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
this.mContext = getRealActivity()
val dialog = BottomSheetDialog(
context, if (initDialogStyle() == DialogSize.NO_SET) this.theme else initDialogStyle()
getViewContext(), if (initDialogStyle() == DialogSize.NO_SET) this.theme else initDialogStyle()
)
if (initDialogAnim() != DialogSize.NO_SET) {
getWindow()?.setWindowAnimations(initDialogAnim())
Expand Down Expand Up @@ -100,10 +100,6 @@ open class QuickBottomSheetDialogFragment @JvmOverloads constructor(
protected var mNewWidth = DialogSize.NO_SET
protected var mNewHeight = DialogSize.NO_SET

override fun getContext(): Context {
return mContext!!
}

/**
* 重新设置高度
*/
Expand Down Expand Up @@ -152,4 +148,8 @@ open class QuickBottomSheetDialogFragment @JvmOverloads constructor(
super.dismissAllowingStateLoss()
onDialogClose()
}

override fun getViewContext(): Context {
return context!!
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ abstract class QuickDialog : Dialog, DialogSize, DialogLifecycle {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
dealSize()
mView = layoutView ?: View.inflate(context, layoutId, null)
mView = layoutView ?: View.inflate(getViewContext(), layoutId, null)
setContentView(mView!!)
if (window != null) {
if (initDialogAnim() != DialogSize.NO_SET) {
Expand Down Expand Up @@ -129,4 +129,8 @@ abstract class QuickDialog : Dialog, DialogSize, DialogLifecycle {
super.dismiss()
onDialogClose()
}

override fun getViewContext(): Context {
return context
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ abstract class QuickDialogFragment @JvmOverloads constructor(
return super.getView()
}

override fun getContext(): Context {
override fun getViewContext(): Context {
return super.requireContext()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,35 @@ import androidx.appcompat.app.AppCompatActivity
*/
interface QuickContext {

fun getContext(): Context
fun getViewContext(): Context
fun getRealContext(): Context? {
return this.getRealActivity()?: getContext()
return this.getRealActivity()?: getViewContext()
}

fun getRealActivity(): Activity? {
if (getContext() is Activity) {
return getContext() as Activity
} else if (getContext() is ContextThemeWrapper) {
if ((getContext() as ContextThemeWrapper).baseContext is Activity) {
return (getContext() as ContextThemeWrapper).baseContext as Activity
} else if ((getContext() as ContextThemeWrapper).baseContext is ContextThemeWrapper) {
if (((getContext() as ContextThemeWrapper).baseContext as ContextThemeWrapper).baseContext is Activity) {
return ((getContext() as ContextThemeWrapper).baseContext as ContextThemeWrapper).baseContext as Activity
if (getViewContext() is Activity) {
return getViewContext() as Activity
} else if (getViewContext() is ContextThemeWrapper) {
if ((getViewContext() as ContextThemeWrapper).baseContext is Activity) {
return (getViewContext() as ContextThemeWrapper).baseContext as Activity
} else if ((getViewContext() as ContextThemeWrapper).baseContext is ContextThemeWrapper) {
if (((getViewContext() as ContextThemeWrapper).baseContext as ContextThemeWrapper).baseContext is Activity) {
return ((getViewContext() as ContextThemeWrapper).baseContext as ContextThemeWrapper).baseContext as Activity
}
}
}
return null
}

fun getAppCompatActivity() : AppCompatActivity? {
if (getContext() is AppCompatActivity) {
return getContext() as AppCompatActivity
} else if (getContext() is ContextThemeWrapper) {
if ((getContext() as ContextThemeWrapper).baseContext is AppCompatActivity) {
return (getContext() as ContextThemeWrapper).baseContext as AppCompatActivity
} else if ((getContext() as ContextThemeWrapper).baseContext is ContextThemeWrapper) {
if (((getContext() as ContextThemeWrapper).baseContext as ContextThemeWrapper).baseContext is AppCompatActivity) {
return ((getContext() as ContextThemeWrapper).baseContext as ContextThemeWrapper).baseContext as AppCompatActivity
if (getViewContext() is AppCompatActivity) {
return getViewContext() as AppCompatActivity
} else if (getViewContext() is ContextThemeWrapper) {
if ((getViewContext() as ContextThemeWrapper).baseContext is AppCompatActivity) {
return (getViewContext() as ContextThemeWrapper).baseContext as AppCompatActivity
} else if ((getViewContext() as ContextThemeWrapper).baseContext is ContextThemeWrapper) {
if (((getViewContext() as ContextThemeWrapper).baseContext as ContextThemeWrapper).baseContext is AppCompatActivity) {
return ((getViewContext() as ContextThemeWrapper).baseContext as ContextThemeWrapper).baseContext as AppCompatActivity
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import com.wpf.app.quickbind.interfaces.Bind
*/
open class QuickBindData(
@LayoutRes open val layoutId: Int = 0,
open val layoutView: View? = null,
@Transient open val layoutView: View? = null,
override val isSuspension: Boolean = false, //View是否悬浮置顶
) : QuickItemData(isSuspension = isSuspension), Bind {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.wpf.app.quickrecyclerview.utils

import android.view.View
import com.wpf.app.quickbind.helper.binddatahelper.BindData2ViewHelper
import com.wpf.app.quickbind.helper.binddatahelper.ItemClick
import com.wpf.app.quickrecyclerview.data.QuickBindData
import com.wpf.app.quickbind.interfaces.RunItemClick
import com.wpf.app.quickbind.interfaces.RunItemClickWithSelf
import com.wpf.app.quickrecyclerview.QuickAdapter
import com.wpf.app.quickrecyclerview.holder.QuickViewHolder

/**
* Created by 王朋飞 on 2022/7/20.
Expand All @@ -17,10 +18,10 @@ open class ClickItem @JvmOverloads constructor(
private val click: RunItemClick? = null,
) : QuickBindData(layoutId) {

override fun onCreateViewHolder(itemView: View) {
super.onCreateViewHolder(itemView)
override fun onBindViewHolder(adapter: QuickAdapter, viewHolder: QuickViewHolder<QuickBindData>, position: Int) {
super.onBindViewHolder(adapter, viewHolder, position)
if (clickSelf != null || click != null) {
BindData2ViewHelper.bind(itemView, clickSelf?.run(this) ?: click?.run()!!, ItemClick)
BindData2ViewHelper.bind(viewHolder.itemView, clickSelf?.run(this) ?: click?.run()!!, ItemClick)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.wpf.app.quickrecyclerview.utils

import android.view.View
import android.view.ViewGroup
import androidx.annotation.ColorRes
import com.wpf.app.quickbind.helper.binddatahelper.BindData2ViewHelper
import com.wpf.app.quickbind.helper.binddatahelper.Color2View
import com.wpf.app.quickbind.helper.binddatahelper.Height2View
import com.wpf.app.quickrecyclerview.QuickAdapter
import com.wpf.app.quickrecyclerview.R
import com.wpf.app.quickrecyclerview.data.QuickBindData
import com.wpf.app.quickrecyclerview.holder.QuickViewHolder

/**
* Created by 王朋飞 on 2022/7/21.
Expand All @@ -20,9 +22,9 @@ open class LineItem(
override val isVertical: Boolean = true
) : SpaceItem(space = width, isVertical) {

override fun onCreateViewHolder(itemView: View) {
super.onCreateViewHolder(itemView)
BindData2ViewHelper.bind(itemView.findViewById(R.id.rootView), color, Color2View)
BindData2ViewHelper.bind(itemView.findViewById(R.id.rootView), height, Height2View)
override fun onBindViewHolder(adapter: QuickAdapter, viewHolder: QuickViewHolder<QuickBindData>, position: Int) {
super.onBindViewHolder(adapter, viewHolder, position)
BindData2ViewHelper.bind(viewHolder.itemView.findViewById(R.id.rootView), color, Color2View)
BindData2ViewHelper.bind(viewHolder.itemView.findViewById(R.id.rootView), height, Height2View)
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.wpf.app.quickrecyclerview.utils

import android.view.View
import com.wpf.app.quickbind.helper.binddatahelper.BindData2ViewHelper
import com.wpf.app.quickbind.helper.binddatahelper.Height2View
import com.wpf.app.quickbind.helper.binddatahelper.Width2View
import com.wpf.app.quickrecyclerview.QuickAdapter
import com.wpf.app.quickrecyclerview.R
import com.wpf.app.quickrecyclerview.data.QuickBindData
import com.wpf.app.quickrecyclerview.holder.QuickViewHolder

/**
* Created by 王朋飞 on 2022/7/20.
Expand All @@ -16,9 +17,9 @@ open class SpaceItem(
open val isVertical: Boolean = true
): QuickBindData(R.layout.adapter_space) {

override fun onCreateViewHolder(itemView: View) {
super.onCreateViewHolder(itemView)
BindData2ViewHelper.bind(itemView.findViewById(R.id.rootView),
override fun onBindViewHolder(adapter: QuickAdapter, viewHolder: QuickViewHolder<QuickBindData>, position: Int) {
super.onBindViewHolder(adapter, viewHolder, position)
BindData2ViewHelper.bind(viewHolder.itemView.findViewById(R.id.rootView),
space, if (isVertical) Height2View else Width2View
)
}
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ dependencies {
//viewpager2
implementation 'androidx.viewpager2:viewpager2:1.0.0'
//Navigation
implementation 'androidx.navigation:navigation-fragment-ktx:2.5.2'
implementation 'androidx.navigation:navigation-ui-ktx:2.5.2'
implementation 'androidx.navigation:navigation-fragment-ktx:2.5.3'
implementation 'androidx.navigation:navigation-ui-ktx:2.5.3'
//Sp存储
implementation 'androidx.preference:preference-ktx:1.2.0'
implementation 'androidx.datastore:datastore:1.0.0'
Expand Down

0 comments on commit fd27ad5

Please sign in to comment.