Skip to content

Instantly share code, notes, and snippets.

View cuber5566's full-sized avatar

Cuber cuber5566

View GitHub Profile
class Solution {
fun merge(intervals: Array<IntArray>): Array<IntArray> {
if (intervals.size < 2) return intervals
intervals.sortBy { it[0] }
var index = 1
val result = ArrayList<IntArray>()
var merge: IntArray = intervals[0]
package eventpal.com.play
import org.junit.Assert
import org.junit.Test
import kotlin.math.abs
class ElevatorTest {
interface Elevator {
fun SpannableStringBuilder.appendText(string: String, self: SpannableStringBuilder.() -> SpannableStringBuilder): SpannableStringBuilder {
val newSpan = SpannableStringBuilder(string)
self(newSpan)
return append(newSpan)
}
fun SpannableStringBuilder.color(color: Int): SpannableStringBuilder {
val span = ForegroundColorSpan(color)
setSpan(span, 0, length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
return this
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/textMyTime"
android:layout_width="wrap_content"
@SuppressLint("InflateParams")
fun View.showPopupInfo(text: String) {
val view = LayoutInflater.from(context).inflate(R.layout.popup_info, null, false)
val popupWindow = PopupWindow(view, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true)
popupWindow.isTouchable = true
popupWindow.setTouchInterceptor { _, _ -> false }
val windowWidth = Resources.getSystem().displayMetrics.widthPixels
popupWindow.showAsDropDown(this, windowWidth, -height * 2)
/**
* Provides resources without context.
* should be initial when [Application.onCreate]
*/
@SuppressLint("StaticFieldLeak")
class ResourceProvider(
private var resources: Resources
@cuber5566
cuber5566 / PostDetailAdapter.kt
Created January 8, 2018 16:06
RecyclerView multiType
package com.dpick.screen.post.detail
import android.content.Context
import android.content.res.Resources
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.ViewGroup
import com.dpick.R
import com.dpick.model.Comment
import com.dpick.model.Post
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/avatar"
android:layout_width="100dp"
android:layout_height="100dp"
class ViewModelFactory(
private val application: Application,
private val schedulerProvider: SchedulerProvider,
private val authRepository: AuthRepository,
private val loginRepository: LoginRepository,
private val forumRepository: ForumSource,
private val postRepository: PostSource,
private val commentRepository: CommentRepository
class PostDetailViewModel(
application: Application,
private var schedulerProvider: AppScheduler,
private var postRepository: PostSource,
private var commentRepository: CommentRepository
) : AndroidViewModel(application) {
companion object {