This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class RecyclerBaseAdapter : RecyclerView.Adapter<RecyclerViewHolder>() { | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = | |
RecyclerViewHolder(DataBindingUtil.inflate<ViewDataBinding>(LayoutInflater.from(parent.context), viewType, parent, false)) | |
override fun onBindViewHolder(holder: RecyclerViewHolder, position: Int) { | |
getViewModel(position) | |
?.let { | |
val bindingSuccess = holder.binding.setVariable(BR.viewModel, it) | |
if (!bindingSuccess) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inline fun <T, R> Observable<List<T>>.scanMap(crossinline func2: (List<T>, List<T>) -> R): Observable<R> { | |
return this.startWith(emptyList<T>()) //emit a empty list first, otherwise the .buffer() below won't emit at first (needs 2 emissions to emit) | |
.buffer(2, 1) //buffer the previous and current emission | |
.filter { it.size >= 2 } | |
.map { func2.invoke(it[0], it[1]) } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inline fun <T, R> Observable<List<T>>.scanMap(crossinline func2: (List<T>, List<T>) -> R): Observable<R> { | |
return this.startWith(emptyList<T>()) //emit a empty list first, otherwise the .buffer() below won't emit at first (needs 2 emissions to emit) | |
.buffer(2, 1) //buffer the previous and current emission | |
.filter { it.size >= 2 } | |
.map { func2.invoke(it[0], it[1]) } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AvatarView extends AppCompatImageView { | |
/* | |
* Path of them image to be clipped (to be shown) | |
* */ | |
Path clipPath; | |
/* | |
* Place holder drawable (with background color and initials) | |
* */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
protected void onDraw(Canvas canvas) { | |
if (shape == RECTANGLE) { | |
canvas.drawRoundRect(rectF, cornerRadius, cornerRadius, borderPaint); | |
clipPath.addRoundRect(rectF, cornerRadius, cornerRadius, Path.Direction.CW); | |
} else { | |
canvas.drawCircle(rectF.centerX(), rectF.centerY(), (rectF.height() / 2) - borderWidth, borderPaint); | |
clipPath.addCircle(rectF.centerX(), rectF.centerY(), (rectF.height() / 2), Path.Direction.CW); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Set the canvas bounds here | |
* */ | |
@Override | |
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { | |
super.onMeasure(widthMeasureSpec, heightMeasureSpec); | |
int screenWidth = MeasureSpec.getSize(widthMeasureSpec); | |
int screenHeight = MeasureSpec.getSize(heightMeasureSpec); | |
rectF.set(0, 0, screenWidth, screenHeight); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Create placeholder drawable | |
* */ | |
private void setDrawable() { | |
drawable = new Drawable() { | |
@Override | |
public void draw(@NonNull Canvas canvas) { | |
int centerX = Math.round(canvas.getWidth() * 0.5f); | |
int centerY = Math.round(canvas.getHeight() * 0.5f); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Return user short name | |
* */ | |
public static String getShortName(String name) { | |
String[] strings = name.split(" ");//no i18n | |
String shortName; | |
if (strings.length == 1) { | |
shortName = strings[0].substring(0, 2); | |
} else { | |
shortName = strings[0].substring(0, 1) + strings[1].substring(0, 1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Initialize fields | |
* */ | |
protected void init() { | |
rectF = new RectF(); | |
clipPath = new Path(); | |
imageSize = getResources().getDimensionPixelSize(R.dimen.avatar_size); | |
cornerRadius = (int) Utils.dpToPixel(2, getResources()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Path of them image to be clipped (to be shown) | |
* */ | |
Path clipPath; | |
/* | |
* Place holder drawable (with background color and initials) | |
* */ | |
Drawable drawable; |