Skip to content

Instantly share code, notes, and snippets.

View worker8's full-sized avatar
:octocat:
code is compiling...

Tan Jun Rong worker8

:octocat:
code is compiling...
View GitHub Profile
fun main() {
// coldFlow()
hotFlow()
}
fun coldFlow() {
val scope = CoroutineScope(Dispatchers.IO)
var count = 10
val coldFlow = flow {
while (count > 0) {
/* // use side
* channelAvatarPicture.setOnClickListener {
* startActivityForResult(Intent(this@ChannelActivity, ImagePickingActivity::class.java), ImagePickingActivity.REQUEST_IMAGE_CAPTURE)
* }
* override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
* super.onActivityResult(requestCode, resultCode, data)
* if (requestCode == ImagePickingActivity.REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
* data?.getStringExtra(ImagePickingActivity.CHOSEN_IMAGE_PATH)?.ofType<String> { chosenImagePath ->
* // use 'chosenImagePath'
* }
@worker8
worker8 / SharedPreferenceUtil
Created November 19, 2018 02:57
A Kotlin share preference helper
import android.content.Context
import android.content.SharedPreferences
import android.preference.PreferenceManager
fun Context.defaultPrefs(): SharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
fun Context.customPrefs(name: String): SharedPreferences = getSharedPreferences(name, Context.MODE_PRIVATE)
fun SharedPreferences.save(key: String, value: Any) {
edit().apply {
when (value) {
override fun onTouchEvent(event: MotionEvent): Boolean {
// swapping the motionEvent's x and y, so that when finger moves right, it becomes moving down
// for VerticalViewPager effect
event.swapXY()
// this portion is used for injection ACTION_DOWN
if (firstTime && event.actionMasked == MotionEvent.ACTION_MOVE) {
injectActionDown(event)
firstTime = false
}
override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
val action = event.actionMasked
val currentPoint = Point(event.x.toInt(), event.y.toInt())
if (action == MotionEvent.ACTION_DOWN) {
// mark the beginning, when finger touched down
initialTouchPoint = Point(currentPoint)
} else if (action == MotionEvent.ACTION_UP) {
// reset the marking, when finger is lifted up
initialTouchPoint = Point(0, 0)
override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
val action = event.actionMasked
val currentPoint = Point(event.x.toInt(), event.y.toInt())
if (action == MotionEvent.ACTION_DOWN) {
// mark the beginning, when finger touched down
initialTouchPoint = Point(currentPoint)
} else if (action == MotionEvent.ACTION_UP) {
// reset the marking, when finger is lifted up
initialTouchPoint = Point(0, 0)
override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
val action = event.actionMasked
val currentPoint = Point(event.x.toInt(), event.y.toInt())
if (action == MotionEvent.ACTION_DOWN) {
// mark the beginning, when finger touched down
initialTouchPoint = Point(currentPoint)
} else if (action == MotionEvent.ACTION_UP) {
// reset the marking, when finger is lifted up
initialTouchPoint = Point(0, 0)
class RandomAdapter(val dataArray: List) : AccordionAdapter {
override fun onCreateViewHolderForTitle(parent: ViewGroup): AccordionView.ViewHolder {
return TitleViewHolder.create(parent)
}
override fun onCreateViewHolderForContent(parent: ViewGroup): AccordionView.ViewHolder {
return ContentViewHolder.create(parent)
}
override fun onBindViewForTitle(viewHolder: AccordionView.ViewHolder, position: Int, arrowDirection: AccordionAdapter.ArrowDirection) {
interface AccordianAdapter {
fun onCreateViewHolderForTitle(parent: ViewGroup): AccordionView.ViewHolder
fun onCreateViewHolderForContent(parent: ViewGroup): AccordionView.ViewHolder
fun onBindViewForTitle(viewHolder: AccordionView.ViewHolder, position: Int, arrowDirection: ArrowDirection)
fun onBindViewForContent(viewHolder: AccordionView.ViewHolder, position: Int)
fun getItemCount(): Int
}
val set = ConstraintSet()
set.clone(constraintLayout)
set.clear(titleView4.id, ConstraintSet.TOP)
set.applyTo(constraintLayout)