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 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 |
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 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 */ |
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 UIKit | |
extension UIView { | |
/* Usage Example | |
* bgView.addBottomRoundedEdge(desiredCurve: 1.5) | |
*/ | |
func addBottomRoundedEdge(desiredCurve: CGFloat?) { |
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
/* 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()) { |
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 BroadcastReceiverLeakActivity extends AppCompatActivity { | |
private BroadcastReceiver broadcastReceiver; | |
@Override | |
protected void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_first); | |
} |
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
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 |
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 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") |
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 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 |
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
@Module | |
class ApiModule { | |
/* | |
* The method returns the Gson object | |
* */ | |
@Provides | |
@Singleton | |
internal fun provideGson(): Gson { | |
val gsonBuilder = GsonBuilder() |
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
recyclerView.addOnScrollListener(object : RecyclerViewPaginator(recyclerView) { | |
override val isLastPage: Boolean | |
get() = viewModel.isLastPage() | |
override fun loadMore(page: Long) { | |
viewModel.loadData(page) | |
} | |
}) |
NewerOlder