androidx
Zhanty 5 years ago
parent 5eba23a1e9
commit 8d8768a06b
  1. 6
      lib_base/src/main/java/com/android/base/adapter/recycler/ItemViewBinder.kt
  2. 7
      lib_base/src/main/java/com/android/base/kotlin/Collections.kt
  3. 27
      lib_base/src/main/java/com/android/base/kotlin/SizeEx.kt
  4. 8
      lib_base/src/main/java/com/android/base/utils/common/CollectionUtils.java

@ -26,8 +26,12 @@ abstract class SimpleItemViewBinder<T> : ItemViewBinder<T, KtViewHolder>() {
inflater.inflate(layout, parent, false) inflater.inflate(layout, parent, false)
} else } else
layout as View layout as View
return KtViewHolder(itemView) return KtViewHolder(itemView).apply {
onViewHolderCreated(this)
} }
}
protected open fun onViewHolderCreated(viewHolder: KtViewHolder) = Unit
/**provide a layout id or a View*/ /**provide a layout id or a View*/
abstract fun provideLayout(inflater: LayoutInflater, parent: ViewGroup): Any abstract fun provideLayout(inflater: LayoutInflater, parent: ViewGroup): Any

@ -0,0 +1,7 @@
package com.android.base.kotlin
import com.android.base.utils.common.CollectionUtils
fun <T> List<T>?.toArrayList(): ArrayList<T> {
return CollectionUtils.toArrayList(this)
}

@ -1,27 +1,8 @@
package com.android.base.kotlin package com.android.base.kotlin
import android.content.Context
import android.support.v4.app.Fragment
import android.support.v7.widget.RecyclerView
import android.view.View
import com.android.base.utils.android.UnitConverter import com.android.base.utils.android.UnitConverter
fun Context.dip(value: Int): Int = UnitConverter.dpToPx(value) fun dip(value: Int): Int = UnitConverter.dpToPx(value)
fun Context.dip(value: Float): Float = UnitConverter.dpToPx(value) fun dip(value: Float): Float = UnitConverter.dpToPx(value)
fun Context.sp(value: Int): Int = UnitConverter.spToPx(value) fun sp(value: Int): Int = UnitConverter.spToPx(value)
fun Context.sp(value: Float): Float = UnitConverter.spToPx(value) fun sp(value: Float): Float = UnitConverter.spToPx(value)
fun Fragment.dip(value: Int): Int = UnitConverter.dpToPx(value)
fun Fragment.dip(value: Float): Float = UnitConverter.dpToPx(value)
fun Fragment.sp(value: Int): Int = UnitConverter.spToPx(value)
fun Fragment.sp(value: Float): Float = UnitConverter.spToPx(value)
fun View.dip(value: Int): Int = context.dip(value)
fun View.dip(value: Float): Float = context.dip(value)
fun View.sp(value: Int): Int = context.sp(value)
fun View.sp(value: Float): Float = context.sp(value)
fun RecyclerView.ViewHolder.dip(value: Int): Int = itemView.dip(value)
fun RecyclerView.ViewHolder.dip(value: Float): Float = itemView.dip(value)
fun RecyclerView.ViewHolder.sp(value: Int): Int = itemView.dip(value)
fun RecyclerView.ViewHolder.sp(value: Float): Float = itemView.dip(value)

@ -1,7 +1,6 @@
package com.android.base.utils.common; package com.android.base.utils.common;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
@ -21,11 +20,4 @@ public class CollectionUtils {
return new ArrayList<>(list); return new ArrayList<>(list);
} }
public static <T> List<T> emptyIfNull(List<T> list) {
if (list == null) {
return Collections.emptyList();
}
return list;
}
} }

Loading…
Cancel
Save