Skip to content

Commit

Permalink
add booleanx
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanCheen committed Jul 18, 2022
1 parent af12e8e commit 5e07688
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ package me.yifeiyuan.onepiece.dev.data
* Created by 程序亦非猿 on 2022/7/6.
*/
class RemoteDataSource {

suspend fun getDataList():List<String>{
return emptyList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ package me.yifeiyuan.onepiece.architecture.domain
* 2.
*/

interface OpUserCase{
interface OpUserCase
// private val defaultScope:Cour
{

// operator fun invoke()

Expand Down
Original file line number Diff line number Diff line change
@@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package me.yifeiyuan.onepiece.pandora.ktx
import android.os.Bundle

/**
* Bundle
*
* Created by 程序亦非猿 on 2021/7/16.
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import android.os.Handler
import android.os.Looper

/**
* Handler
*
* Created by 程序亦非猿 on 2021/10/12.
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@ fun <T> T.startNewThread(action: T.() -> Unit) {
Thread {
action()
}.start()
}

fun <T> T.mainThread(block: T.() -> Unit) {
mainThreadHandler.post {
block.invoke(this)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import java.lang.reflect.Field


/**
* 默认情况下 PopupMenu 不会展示 icon,即便你在菜单里定义了 icon。
* 需要反射调用开启
* 让 PopupMenu 支持展示 Icon。
*
* 默认情况下即便在菜单里定义了 icon ,PopupMenu 也不会展示它,需要反射调用开启。
*/
@SuppressLint("RestrictedApi")
fun PopupMenu.setForceShowIcon(forceShowIcon: Boolean = true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/

/**
Expand Down Expand Up @@ -43,24 +45,32 @@ fun <T : RecyclerView.Adapter<*>> 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)
}

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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import androidx.annotation.StringRes
import androidx.core.content.ContextCompat

/**
* TextView 的扩展
*
* Created by 程序亦非猿 on 2021/10/12.
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
}
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import android.view.ViewGroup
import android.widget.Checkable

/**
*
* View & ViewGroup
*
* Created by 程序亦非猿 on 2021/6/24.
*/

Expand Down

0 comments on commit 5e07688

Please sign in to comment.