allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
compile 'com.github.Thor-jelly:CommonUtils:最新版本号'
}
需要注意如果是有无数据模型时 不能通过notifyItemInserted(0)插入第一条数据,只能通过notifyItemChanged(0)更新 无图暂时支持线性布局,如果非要GridLayoutManager实现无图展示,需要动态设置setSpanSizeLookup 根据状态动态改变数列个数
ActivityUtils
CommonUtils
fun closeKeyboard(activity: Activity, vararg editText: EditText)
fun showKeyboard(activity: Activity, editText: EditText)
fun getSTime(time: String?, rule: String): String
fun getMSTime(time: String?, rule: String): String
fun hasCamera(): Boolean
具体看代码NumberUtils
NumberTurnToHz
NumberTurnToHz.builder()
.setNumber(String.valueOf(allPrice))
.setUnit("元")
.build()
.getHz();
PreferencesBy
使用
-
首先先创建一个扩展方便使用
/** * 类描述:sharePreferences扩展<br/> * 创建人:吴冬冬<br/> * 创建时间:2018/11/15 14:46 <br/> */ inline fun <reified I, T> I.preferencesExt(default: T) = PreferencesBy(AppContext, "", default, "shandian")
-
代码中使用
var mName by preferencesExt("")
fun Int.dp2px(context: Context): Int
fun Int.sp2px(context: Context): Int
fun String?.parseInt(): Int
fun String?.parseDouble(): Double
/**
* 格式化数字升级版
* @param dot 保留小数点位数
* @param isShowEnd0 是否显示末尾0
* @param roundingMode 四舍五入模式
*/
@JvmOverloads
fun String?.formatNumber(
dot: Int,
isShowEnd0: Boolean = false,
roundingMode: RoundingMode = RoundingMode.FLOOR
): String
/**
* 格式化数字
* ##0.000
* @param roundingMode 四舍五入模式
*/
@JvmOverloads
fun String?.formatNumber(
formatStr: String,
roundingMode: RoundingMode = RoundingMode.FLOOR
): String
/**
* string 转换为中英文数组 设置到富文本中
*/
fun String?.toZhEnSpan(zhTextSizePx: Int, enTextSizePx: Int): Array<TextMoreStyle>
/**
* 添加中英文字体大小富文本 进入数组
*/
private fun addZhEnSpanType2Array(
sb: StringBuilder,
zhTextSizePx: Int,
result: MutableList<TextMoreStyle>
)
/**
* 设置字体样式
*/
fun TextView?.setMoreStyle(
vararg itemArray: TextMoreStyle?
)
/**
* 通过defaultFromStyle设置textView字体typeface
*/
fun TextView?.setDefaultFromStyle(typefaceType: Int = Typeface.BOLD)
/**
* textView显示全部文字
*/
fun TextView?.setShowAllText()
可以直接.yes 或者 .no 执行判断 如果需要判断中的值,则可以在.otherwise
val otherwise = true.yes {
Log.d("123===", "true")
1
}.otherwise {
Log.d("123===", "false")
2
}
Log.d("123===", "-->${otherwise}")
123===: true
123===: -->1
val otherwise1 = false.yes {
Log.d("123===", "true")
3
}.otherwise {
Log.d("123===", "false")
4
}
Log.d("123===", "-->${otherwise1}")
false
-->4