From 5e076886738b675622c52be090497619825571a8 Mon Sep 17 00:00:00 2001 From: mingjue Date: Mon, 18 Jul 2022 14:03:32 +0800 Subject: [PATCH] add booleanx --- .../onepiece/dev/data/RemoteDataSource.kt | 4 +++ .../architecture/domain/OpUserCase.kt | 4 ++- .../onepiece/pandora/ktx/Booleanx.kt | 25 +++++++++++++++++++ .../yifeiyuan/onepiece/pandora/ktx/Bundlex.kt | 2 ++ .../onepiece/pandora/ktx/Handlerx.kt | 2 ++ .../yifeiyuan/onepiece/pandora/ktx/Threadx.kt | 6 +++++ .../onepiece/pandora/ktx/ui/EditTextx.kt | 3 +++ .../onepiece/pandora/ktx/ui/PopupMenux.kt | 5 ++-- .../onepiece/pandora/ktx/ui/RecyclerViewx.kt | 20 +++++++++++---- .../onepiece/pandora/ktx/ui/TextViewx.kt | 2 ++ .../onepiece/pandora/ktx/ui/ViewPagerx.kt | 22 ++++++++++++++++ .../onepiece/pandora/ktx/ui/Viewx.kt | 3 +++ 12 files changed, 90 insertions(+), 8 deletions(-) create mode 100644 pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/Booleanx.kt diff --git a/app/src/main/java/me/yifeiyuan/onepiece/dev/data/RemoteDataSource.kt b/app/src/main/java/me/yifeiyuan/onepiece/dev/data/RemoteDataSource.kt index 966dcbe..6d8ff69 100644 --- a/app/src/main/java/me/yifeiyuan/onepiece/dev/data/RemoteDataSource.kt +++ b/app/src/main/java/me/yifeiyuan/onepiece/dev/data/RemoteDataSource.kt @@ -4,4 +4,8 @@ package me.yifeiyuan.onepiece.dev.data * Created by 程序亦非猿 on 2022/7/6. */ class RemoteDataSource { + + suspend fun getDataList():List{ + return emptyList(); + } } diff --git a/architecture/src/main/java/me/yifeiyuan/onepiece/architecture/domain/OpUserCase.kt b/architecture/src/main/java/me/yifeiyuan/onepiece/architecture/domain/OpUserCase.kt index 1bcc5d0..3163fd7 100644 --- a/architecture/src/main/java/me/yifeiyuan/onepiece/architecture/domain/OpUserCase.kt +++ b/architecture/src/main/java/me/yifeiyuan/onepiece/architecture/domain/OpUserCase.kt @@ -12,7 +12,9 @@ package me.yifeiyuan.onepiece.architecture.domain * 2. */ -interface OpUserCase{ +interface OpUserCase +// private val defaultScope:Cour +{ // operator fun invoke() diff --git a/pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/Booleanx.kt b/pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/Booleanx.kt new file mode 100644 index 0000000..379f00e --- /dev/null +++ b/pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/Booleanx.kt @@ -0,0 +1,25 @@ +package me.yifeiyuan.onepiece.pandora.ktx + +/** + * Boolean + * + * Created by 程序亦非猿 on 2022/7/18. + */ + +/** + * 如果为 true 则执行 + */ +fun Boolean.ifTrue(block: () -> Unit) { + if (this) { + block() + } +} + +/** + * 如果为 false 则执行 + */ +fun Boolean.ifFalse(block: () -> Unit) { + if (!this) { + block() + } +} \ No newline at end of file diff --git a/pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/Bundlex.kt b/pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/Bundlex.kt index efe3bd3..ccdb75d 100644 --- a/pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/Bundlex.kt +++ b/pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/Bundlex.kt @@ -3,6 +3,8 @@ package me.yifeiyuan.onepiece.pandora.ktx import android.os.Bundle /** + * Bundle + * * Created by 程序亦非猿 on 2021/7/16. */ diff --git a/pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/Handlerx.kt b/pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/Handlerx.kt index 17fc523..aed5c47 100644 --- a/pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/Handlerx.kt +++ b/pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/Handlerx.kt @@ -4,6 +4,8 @@ import android.os.Handler import android.os.Looper /** + * Handler + * * Created by 程序亦非猿 on 2021/10/12. */ diff --git a/pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/Threadx.kt b/pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/Threadx.kt index 276c07b..992a985 100644 --- a/pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/Threadx.kt +++ b/pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/Threadx.kt @@ -13,4 +13,10 @@ fun T.startNewThread(action: T.() -> Unit) { Thread { action() }.start() +} + +fun T.mainThread(block: T.() -> Unit) { + mainThreadHandler.post { + block.invoke(this) + } } \ No newline at end of file diff --git a/pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/ui/EditTextx.kt b/pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/ui/EditTextx.kt index fd1ccaa..99b9b41 100644 --- a/pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/ui/EditTextx.kt +++ b/pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/ui/EditTextx.kt @@ -5,7 +5,10 @@ import android.text.TextWatcher import android.widget.EditText /** + * EditText 的扩展 + * * Created by 程序亦非猿 on 2021/9/13. + * */ fun EditText.doOnTextChanged(func: (s: CharSequence, start: Int, before: Int, count: Int) -> Unit) { diff --git a/pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/ui/PopupMenux.kt b/pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/ui/PopupMenux.kt index feb2df0..76e5651 100644 --- a/pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/ui/PopupMenux.kt +++ b/pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/ui/PopupMenux.kt @@ -11,8 +11,9 @@ import java.lang.reflect.Field /** - * 默认情况下 PopupMenu 不会展示 icon,即便你在菜单里定义了 icon。 - * 需要反射调用开启 + * 让 PopupMenu 支持展示 Icon。 + * + * 默认情况下即便在菜单里定义了 icon ,PopupMenu 也不会展示它,需要反射调用开启。 */ @SuppressLint("RestrictedApi") fun PopupMenu.setForceShowIcon(forceShowIcon: Boolean = true) { diff --git a/pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/ui/RecyclerViewx.kt b/pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/ui/RecyclerViewx.kt index 08a9f6a..5d76969 100644 --- a/pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/ui/RecyclerViewx.kt +++ b/pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/ui/RecyclerViewx.kt @@ -6,9 +6,11 @@ import androidx.recyclerview.widget.RecyclerView import me.yifeiyuan.onepiece.pandora.ktx.ifIs /** - * Created by 程序亦非猿 on 2021/9/13. * * 关于 RecyclerView 的扩展 + * + * + * Created by 程序亦非猿 on 2021/9/13. */ /** @@ -43,7 +45,11 @@ fun > T.attachTo(recyclerView: RecyclerView): T { return this } -fun RecyclerView.doOnScrolled(func: (recyclerView: RecyclerView, dx: Int, dy: Int) -> Unit) { +/** + * @param block + * @see doOnScrollStateChanged + */ +fun RecyclerView.doOnScrolled(block: (recyclerView: RecyclerView, dx: Int, dy: Int) -> Unit) { addOnScrollListener(object : RecyclerView.OnScrollListener() { override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) { super.onScrollStateChanged(recyclerView, newState) @@ -51,16 +57,20 @@ fun RecyclerView.doOnScrolled(func: (recyclerView: RecyclerView, dx: Int, dy: In override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { super.onScrolled(recyclerView, dx, dy) - func(recyclerView, dx, dy) + block(recyclerView, dx, dy) } }) } -fun RecyclerView.doOnScrollStateChanged(func: (recyclerView: RecyclerView, newState: Int) -> Unit) { +/** + * @param block + * @see doOnScrolled + */ +fun RecyclerView.doOnScrollStateChanged(block: (recyclerView: RecyclerView, newState: Int) -> Unit) { addOnScrollListener(object : RecyclerView.OnScrollListener() { override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) { super.onScrollStateChanged(recyclerView, newState) - func(recyclerView, newState) + block(recyclerView, newState) } override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { diff --git a/pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/ui/TextViewx.kt b/pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/ui/TextViewx.kt index 74c82e9..4cf147a 100644 --- a/pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/ui/TextViewx.kt +++ b/pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/ui/TextViewx.kt @@ -6,6 +6,8 @@ import androidx.annotation.StringRes import androidx.core.content.ContextCompat /** + * TextView 的扩展 + * * Created by 程序亦非猿 on 2021/10/12. */ diff --git a/pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/ui/ViewPagerx.kt b/pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/ui/ViewPagerx.kt index c3c57fb..a5dc22e 100644 --- a/pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/ui/ViewPagerx.kt +++ b/pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/ui/ViewPagerx.kt @@ -3,7 +3,10 @@ package me.yifeiyuan.onepiece.pandora.ktx.ui import androidx.viewpager.widget.ViewPager /** + * ViewPager + * * Created by 程序亦非猿 on 2021/9/13. + * */ fun ViewPager.doOnPageScrolled( @@ -47,4 +50,23 @@ fun ViewPager.doOnPageSelected(func: (position: Int) -> Unit) { override fun onPageScrollStateChanged(state: Int) { } }) +} + +fun ViewPager.doOnPageScrollStateChanged(func: (state: Int) -> Unit) { + + addOnPageChangeListener(object : ViewPager.OnPageChangeListener { + override fun onPageScrolled( + position: Int, + positionOffset: Float, + positionOffsetPixels: Int + ) { + } + + override fun onPageSelected(position: Int) { + } + + override fun onPageScrollStateChanged(state: Int) { + func(state) + } + }) } \ No newline at end of file diff --git a/pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/ui/Viewx.kt b/pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/ui/Viewx.kt index f8d5655..ee8f8bd 100644 --- a/pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/ui/Viewx.kt +++ b/pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/ui/Viewx.kt @@ -8,6 +8,9 @@ import android.view.ViewGroup import android.widget.Checkable /** + * + * View & ViewGroup + * * Created by 程序亦非猿 on 2021/6/24. */