Skip to content

Instantly share code, notes, and snippets.

View JoaquimLey's full-sized avatar
👨‍💻
Product oriented, software perfectionist and developer

Joaquim Ley JoaquimLey

👨‍💻
Product oriented, software perfectionist and developer
View GitHub Profile
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
...
<item name="android:windowLightStatusBar">true</item>
<item name="android:statusBarColor">@color/colorStatusBar</item>
<item name="android:windowBackground">@color/colorWindowBackground</item>
<item name="android:navigationBarColor">@color/colorNavigationBar</item>
<item name="android:windowLightNavigationBar">true</item>
<item name="android:navigationBarDividerColor">@color/colorNavigationBarDivider</item>
fun RecyclerView.applyToolbarNavigationViewWithFabInsets() {
applyVerticalInsets()
clipToPadding = false
addItemDecoration(RecyclerViewToolbarItemDecoration())
addItemDecoration(RecyclerViewBottomNavigationViewFabItemDecoration())
}
open class RecyclerViewMarginItemDecoration(
private val sizeInDp: Int = 16,
private val isTop: Boolean = false
) : RecyclerView.ItemDecoration() {
override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
super.getItemOffsets(outRect, view, parent, state)
if (isTop) {
if (parent.getChildAdapterPosition(view) == 0) {
outRect.top = sizeInDp.toPx()
// Extension function
fun TabLayout.setupWithViewPager2(
viewPager: ViewPager2,
callback: (TabLayout.Tab, Int) -> Unit
) {
TabLayoutMediator(this, viewPager) { tab, position ->
callback.invoke(tab, position)
}.attach()
}
import androidx.recyclerview.widget.ListAdapter
/**
* Creates a copy of itself if no new [data] is passed, this is used
* so [ListAdapter] correctly diffs and animates. :facepalms:
*/
fun <T> List<T>.refresh(data: List<T> = this): List<T> {
return mutableListOf<T>().apply { addAll(data) }.toList()
}
@JoaquimLey
JoaquimLey / debug_over_wifi.md
Last active October 7, 2021 00:18
Debug over WIFI

How to Debug with your device over WIFI

  1. Connect the device via USB and make sure debugging is enabled.

  2. Run adb tcpip 5555

  3. Find the IP address

MACOS: adb shell ip route

@JoaquimLey
JoaquimLey / IntroVideoView.java
Created April 12, 2017 16:02
A simple VideoView subclass that displays in full screen while keeping the aspect ration
/**
* Subclass of VideoView to enable video scaling
* CustomAttribute: "scaleType": "normal", "centerCrop", "fill"
* <p>
* Add this stylable:
* <declare-styleable name="IntroVideoView">
* <attr name="scaleType" format="integer">
* <flag name="normal" value="0" />
* <flag name="centerCrop" value="1" />
* <flag name="fill" value="2" />
/************************************************
* Insets Section *
************************************************/
/*******************
* Utility methods *
*******************/
fun View.applySystemBarPaddingInsets() {
this.doOnApplyWindowInsets { view, insets, padding, _ ->
@JoaquimLey
JoaquimLey / github_multiple-accounts.md
Last active April 30, 2023 22:17
How to Work with GitHub and Multiple Accounts

Step 1 - Create a New SSH Key

We need to generate a unique SSH key for our second GitHub account.

ssh-keygen -t rsa -C "your-email-address"

Be careful that you don't over-write your existing key for your personal account. Instead, when prompted, save the file as id_rsa_COMPANY. In my case, I've saved the file to ~/.ssh/id_rsa_work.

Step 2 - Attach the New Key

@JoaquimLey
JoaquimLey / restart-ssh-gist.sh
Created August 10, 2016 23:02
Restart ssh-agent
killall ssh-agent; eval `ssh-agent`