Skip to content

Instantly share code, notes, and snippets.

View Hasiy's full-sized avatar
🤒
something something

Hasiy Hasiy

🤒
something something
View GitHub Profile
@Hasiy
Hasiy / SharedPreferenceDelegate.kt
Created July 3, 2020 09:35
SharedPreferenceDelegate
import android.content.SharedPreferences
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty
/**
* @author : Hasiy
* @date : 2020/7/1 14:31
* @desc : SharedPreferenceDelegate
* @use : var someValue : Boolean by SharedPreferenceDelegate(Application), "someValue", defaultValue=false)
@Hasiy
Hasiy / MarqueeTextView.kt
Last active July 14, 2022 10:26
横向滚动文字
class MarqueeTextView @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : AppCompatTextView(context, attrs, defStyleAttr) {
// 获取焦点
override fun isFocused(): Boolean {
return true
}
}
@Hasiy
Hasiy / NoScrollViewPager.kt
Last active July 14, 2022 10:25
NoScrollViewPager
class NoScrollViewPager @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : ViewPager(context, attrs) {
private var isScroll = false
override fun onInterceptTouchEvent(ev: MotionEvent?): Boolean {
// return false;//可行,不拦截事件,
// return true;//不行,孩子无法处理事件
// return super.onInterceptTouchEvent(ev);//不行,会有细微移动
return if (isScroll) {
super.onInterceptTouchEvent(ev)
} else {
@Hasiy
Hasiy / RedDotView.kt
Last active July 14, 2022 10:25
控件添加小红点 RedDotView
class RedDotView @JvmOverloads constructor(context: Context?, attrs: AttributeSet? = null, defStyleAttr: Int = android.R.attr.textViewStyle) :
AppCompatTextView(context, attrs, defStyleAttr) {
/**
* 是否隐藏红点上的数字
*/
var isHideOnNull = true
private set
@Hasiy
Hasiy / RoundedDrawable.kt
Last active July 14, 2022 10:25
画圆角Drawable
package customView
import android.graphics.Bitmap
import android.graphics.BitmapShader
import android.graphics.Canvas
import android.graphics.ColorFilter
import android.graphics.PixelFormat
import android.graphics.drawable.Drawable
import android.graphics.Matrix
import android.graphics.Paint
@Hasiy
Hasiy / QuickSort.kt
Last active July 14, 2022 10:25
QuickSort kotlin 快排
fun quickSort(list: List<Int>): List<Int> {
return if (list.size <= 1) list
else {
list.takeLast(list.lastIndex)
.partition { it < list[0] } //分隔操作(partition)
.run { quickSort(first) + list[0] + quickSort(second) }
}
}
@Hasiy
Hasiy / ListNode.kt
Last active July 14, 2022 10:25
Kotlin ListNode链表
package com
/*
* @Author: Hasiy
* @Date: 2020/4/1 - 16 : 47
* @Description: institute-Android
* @Email: Zhuxs@venpoo.com
*/
class ListNode<T>(val value: T) {
var next: ListNode<T>? = null
@Hasiy
Hasiy / sort
Created March 31, 2020 08:54
排序
package sort
/*
* @Author: Hasiy
* @Date: 2020/3/31 - 10 : 00
*/
fun <T> MutableList<T>.swap(indexI: Int, indexJ: Int) {
val temp = get(indexI)
set(indexI, get(indexJ))
@Hasiy
Hasiy / BaseViewModel
Created March 17, 2020 01:43
BaseViewModel
open class BaseViewModel : ViewModel() {
fun launch(block: suspend () -> Unit, error: suspend (Throwable) -> Unit) =
viewModelScope.launch {
try {
block()
} catch (e: Throwable) {
error(e)
}
}
@Hasiy
Hasiy / BaseCode
Created March 17, 2020 01:42
http 请求后数据过滤
const val HTTP_SUCCESS = 200
open class BaseCode : Serializable {
var code: Int = 0
var error: String? = null
}
fun BaseCode.handling(success: () -> Unit, failure: () -> Unit) {
when (code == HTTP_SUCCESS) {
true -> {