Skip to content

Instantly share code, notes, and snippets.

Avatar

Héctor de Isidro hrules6872

View GitHub Profile
@Zhuinden
Zhuinden / FragmentViewBindingDelegate.kt
Last active Jun 17, 2022
Fragment view binding delegate
View FragmentViewBindingDelegate.kt
// https://github.com/Zhuinden/fragmentviewbindingdelegate-kt
import android.view.View
import androidx.fragment.app.Fragment
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.Observer
import androidx.viewbinding.ViewBinding
import kotlin.properties.ReadOnlyProperty
@emmaguy
emmaguy / textcolor-stats.kts
Created Feb 17, 2020
Look at all Android layout files and collate what value is set for 'android:textColor' and count the usages of each
View textcolor-stats.kts
val textColorsUsed = mutableMapOf<String, Int>()
File("../").walkTopDown().forEach { file ->
if (file.isFile && file.extension == "xml" && file.path.contains("res/layout")) {
val builder: DocumentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder()
val xmlInput = InputSource(StringReader(file.readText()))
val doc: Document = builder.parse(xmlInput)
val androidViews = XPathFactory.newInstance()
.newXPath()
@gabrielemariotti
gabrielemariotti / README.MD
Last active Jun 26, 2022
How to use the ShapeableImageView.
View README.MD

The Material Components Library introduced with the 1.2.0-alpha03 the new ShapeableImageView.

In your layout you can use:

 <com.google.android.material.imageview.ShapeableImageView
      android:id="@+id/image_view"
      app:srcCompat="@drawable/..." />

Then in your code apply the ShapeAppearanceModel to define your custom corners:

@hrules6872
hrules6872 / Store.kt
Last active Apr 17, 2022
The Redux/Kotlin Killer :)
View Store.kt
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
@hrules6872
hrules6872 / WindowInsetsFrameLayout.kt
Created Dec 2, 2019
A fragment container enabling the use of android:fitsSystemWindows in fragment layouts
View WindowInsetsFrameLayout.kt
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,
@hrules6872
hrules6872 / LineView.kt
Last active Dec 10, 2019
Dash/LineView custom view for Android
View LineView.kt
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
@hrules6872
hrules6872 / KotlinDsl.kt
Last active Dec 10, 2019
Kotlin DSL example
View KotlinDsl.kt
@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>()
@burntcookie90
burntcookie90 / linguist-runner.sh
Last active Feb 23, 2021
runs linguist on ever commit since a date
View linguist-runner.sh
#!/usr/bin/bash
for commit in $(git --no-pager log --reverse --after="2016-10-01T10:36:00-07:00" --pretty=format:%H)
do
echo $commit
git checkout $commit
#write linguist data to a file
echo "" >> ~/repo-linguist-report.txt
echo "commit: $commit" >> ~/repo-linguist-report.txt
@hrules6872
hrules6872 / StickyHeaderItemDecoration.kt
Last active Sep 11, 2019
ItemDecorator for sticky headers in Kotlin
View StickyHeaderItemDecoration.kt
import android.graphics.*
import android.view.*
import android.view.MotionEvent.ACTION_DOWN
import androidx.recyclerview.widget.RecyclerView
class StickyHeaderItemDecoration(
parent: RecyclerView,
private val isHeader: (position: Int) -> Boolean
) : RecyclerView.ItemDecoration() {
@easterapps
easterapps / ActivityRestart.kt
Last active May 29, 2022
restart android application programmatically
View ActivityRestart.kt
fun triggerRestart(context: Activity) {
val intent = Intent(context, MainActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
context.startActivity(intent)
if (context is Activity) {
(context as Activity).finish()
}
Runtime.getRuntime().exit(0)
}