View ZipManager.kt
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
object ZipManager { | |
fun zip(files: List<String>, outputStream: OutputStream): Boolean = try { | |
ZipOutputStream(BufferedOutputStream(outputStream)).use { stream -> | |
for (file in files) { | |
BufferedInputStream(FileInputStream(File(file))).use { origin -> | |
stream.putNextEntry(ZipEntry(file.substring(file.lastIndexOf("/") + 1))) | |
origin.copyTo(stream) | |
} | |
} | |
} |
View CircleView.kt
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
class CircleView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : View(context, attrs, defStyleAttr) { | |
private val paint by lazy { Paint(Paint.ANTI_ALIAS_FLAG).apply { style = Paint.Style.FILL } } | |
@ColorInt | |
var color: Int = Color.TRANSPARENT | |
set(value) { | |
field = value | |
invalidate() | |
} |
View TriangleView.kt
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
class TriangleView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : View(context, attrs, defStyleAttr) { | |
private val paint by lazy { Paint(Paint.ANTI_ALIAS_FLAG).apply { style = Paint.Style.FILL } } | |
private val path: Path = Path() | |
@ColorInt | |
var color: Int = Color.TRANSPARENT | |
set(value) { | |
field = value | |
invalidate() | |
} |
View TimeAgo.kt
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
object TimeAgo { | |
fun toRelative(millis: Long, spans: List<Span>): Map<Span, Long> { | |
var millisMutable = millis | |
return spans.sortedBy(Span::order).associateWith { span -> | |
val timeDelta: Long = millisMutable / span.millis | |
if (timeDelta.isGreaterThanZero()) millisMutable -= span.millis * timeDelta | |
timeDelta | |
} | |
} |
View FixedColumnsHorizontalGridLayoutManager.kt
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
class FixedColumnsHorizontalGridLayoutManager(context: Context?, spanCountVertical: Int, private var columns: Int, orientation: Int, reverseLayout: Boolean) : | |
GridLayoutManager(context, spanCountVertical, orientation, reverseLayout) { | |
private val safeWidth: Int | |
get() = width - paddingRight - paddingLeft | |
override fun generateDefaultLayoutParams(): RecyclerView.LayoutParams = spanLayoutSize(super.generateDefaultLayoutParams()) | |
override fun generateLayoutParams(context: Context, attrs: AttributeSet): RecyclerView.LayoutParams = spanLayoutSize(super.generateLayoutParams(context, attrs)) | |
override fun generateLayoutParams(layoutParams: ViewGroup.LayoutParams): RecyclerView.LayoutParams = spanLayoutSize(super.generateLayoutParams(layoutParams)) |
View Modules.kt
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
private val data = submodule { | |
/* ... */ | |
} | |
private val usecases = submodule { | |
/* ... */ | |
} | |
val locator = locator { | |
single<Application> { App.get() } | |
single<Context> { get<Application>().applicationContext } |
View Store.kt
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
interface Action | |
typealias Middleware<STATE> = (STATE, Action, Dispatcher, NextMiddleware<STATE>) -> Action | |
typealias NextMiddleware<STATE> = (STATE, Action, Dispatcher) -> Action | |
typealias Reducer<STATE> = (STATE, Action) -> STATE | |
interface State | |
typealias Binder<STATE> = (STATE, STATE) -> Boolean |
View WindowInsetsFrameLayout.kt
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
class WindowInsetsFrameLayout @JvmOverloads constructor( | |
context: Context, | |
attrs: AttributeSet? = null, | |
defStyleAttr: Int = 0 | |
) : FrameLayout(context, attrs, defStyleAttr) { | |
init { | |
setOnHierarchyChangeListener(object : OnHierarchyChangeListener { | |
override fun onChildViewAdded( | |
parent: View, |
View LineView.kt
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
class LineView @JvmOverloads constructor( | |
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 | |
) : View(context, attrs, defStyleAttr) { | |
companion object { | |
const val ORIENTATION_VERTICAL = 0 | |
const val ORIENTATION_HORIZONTAL = 1 | |
private const val DEFAULT_ORIENTATION = ORIENTATION_HORIZONTAL |
View KotlinDsl.kt
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
@DslMarker | |
annotation class HorizontalSelectorGroups | |
interface HorizontalSelectorHelper { | |
fun groups(block: GroupsBuilder.() -> Unit): List<Pair<Header, List<Item>>> = GroupsBuilder().apply(block).build() | |
@HorizontalSelectorGroups | |
class GroupsBuilder { | |
private val groups = mutableListOf<Group>() |
NewerOlder