View ListAdapterHack.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
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() | |
} |
View TabLayoutWithViewPager2.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
// Extension function | |
fun TabLayout.setupWithViewPager2( | |
viewPager: ViewPager2, | |
callback: (TabLayout.Tab, Int) -> Unit | |
) { | |
TabLayoutMediator(this, viewPager) { tab, position -> | |
callback.invoke(tab, position) | |
}.attach() | |
} |
View RecyclerViewExtensions.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
fun RecyclerView.applyToolbarNavigationViewWithFabInsets() { | |
applyVerticalInsets() | |
clipToPadding = false | |
addItemDecoration(RecyclerViewToolbarItemDecoration()) | |
addItemDecoration(RecyclerViewBottomNavigationViewFabItemDecoration()) | |
} |
View ViewExtensions.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
/************************************************ | |
* Insets Section * | |
************************************************/ | |
/******************* | |
* Utility methods * | |
*******************/ | |
fun View.applySystemBarPaddingInsets() { | |
this.doOnApplyWindowInsets { view, insets, padding, _ -> |
View RecyclerViewMarginItemDecoration.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
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() |
View SingleLiveEvent.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
import androidx.annotation.MainThread | |
import androidx.annotation.Nullable | |
import androidx.lifecycle.LifecycleOwner | |
import androidx.lifecycle.MutableLiveData | |
import androidx.lifecycle.Observer | |
import java.util.concurrent.atomic.AtomicBoolean | |
/** |
View BusListActivity.java
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
public class BusListActivity extends AppCompatActivity implements LifecycleRegistryOwner, | |
BusListAdapter.ClickListener { | |
private final LifecycleRegistry lifecycleRegistry = new LifecycleRegistry(this); | |
private BusListViewModel viewModel; | |
private BusListAdapter adapter; | |
private ContentLoadingProgressBar progressDialogView; |
View BusRepository.java
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
public class BusRepository { | |
private static BusRepository sInstance; | |
private final RemoteRepository remoteRepository; | |
private final BusDao busDao; | |
public static BusRepository getInstance(RemoteRepository remoteRepository, BusDao busDao) { | |
if (sInstance == null) { |
View IntroVideoView.java
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
/** | |
* 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" /> |
NewerOlder