Skip to content

Instantly share code, notes, and snippets.

View anitaa1990's full-sized avatar
🎯
Focusing

Anitaa Murthy anitaa1990

🎯
Focusing
  • Chennai
View GitHub Profile
@anitaa1990
anitaa1990 / RecyclerViewPaginator.java
Created December 24, 2018 04:25
An alternate to Android Paging Library - to enable Pagination in RecyclerView
public abstract class RecyclerViewPaginator extends RecyclerView.OnScrollListener {
/*
* This is the Page Limit for each request
* i.e. every request will fetch 19 transactions
* */
private Long batchSize = 19l;
/*
* Variable to keep track of the current page
public static void slideView(View view,
int currentHeight,
int newHeight) {
ValueAnimator slideAnimator = ValueAnimator
.ofInt(currentHeight, newHeight)
.setDuration(500);
/* We use an update listener which listens to each tick
* and manually updates the height of the view */
@anitaa1990
anitaa1990 / CurvedUIView.swift
Last active May 18, 2022 16:22
A Swift extension of UIView to display a curved view
import UIKit
extension UIView {
/* Usage Example
* bgView.addBottomRoundedEdge(desiredCurve: 1.5)
*/
func addBottomRoundedEdge(desiredCurve: CGFloat?) {
@anitaa1990
anitaa1990 / NetworkBoundSource.kt
Created December 24, 2018 05:56
NetworkBoundSource.kt using RxJava/RxAndroid
/* NetworkBoundSource - using Observable in RxJava/RxAndroid */
abstract class NetworkBoundResource<ResultType, RequestType> @MainThread
protected constructor() {
private val asObservable: Observable<Resource<ResultType>>
init {
val source: Observable<Resource<ResultType>>
if (shouldFetch()) {
@anitaa1990
anitaa1990 / BroadcastLeakActivity.java
Last active July 5, 2021 12:57
Gist to demonstrate memory leak when using Broadcast Receivers
public class BroadcastReceiverLeakActivity extends AppCompatActivity {
private BroadcastReceiver broadcastReceiver;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_first);
}
abstract class RecyclerViewPaginator(recyclerView: RecyclerView) : RecyclerView.OnScrollListener() {
/*
* This is the Page Limit for each request
* i.e. every request will fetch 19 transactions
* */
private val batchSize = 19L
/*
* Variable to keep track of the current page
public interface RestApi {
/*
* We would be using the below url:
* https://newsapi.org/v2/everything?q=movies&apiKey=079dac74a5f94ebdb990ecf61c8854b7&pageSize=20&page=2
* The url has four query parameters.
* We would be changing the pageSize and the page
*/
@GET("/v2/everything")
class Resource<T> private constructor(val status: Status, val data: T?, val message: String?) {
val isSuccess: Boolean
get() = status === Status.SUCCESS && data != null
val isLoading: Boolean
get() = status === Status.LOADING
val isLoaded: Boolean
get() = status !== Status.LOADING
@Module
class ApiModule {
/*
* The method returns the Gson object
* */
@Provides
@Singleton
internal fun provideGson(): Gson {
val gsonBuilder = GsonBuilder()
recyclerView.addOnScrollListener(object : RecyclerViewPaginator(recyclerView) {
override val isLastPage: Boolean
get() = viewModel.isLastPage()
override fun loadMore(page: Long) {
viewModel.loadData(page)
}
})