Skip to content

Instantly share code, notes, and snippets.

View ramonrabello's full-sized avatar

Ramon Ribeiro Rabello ramonrabello

View GitHub Profile
@ramonrabello
ramonrabello / build.gradle
Last active March 16, 2023 17:11
Example of how to use build fields for different build types.
android {
// defaultConfig goes here
buildTypes {
debug {
buildConfigField "String", 'BASE_URL', "https://dev-api.yourbackend.com"
}
staging {
buildConfigField "String", 'BASE_URL', "https://stg-api.yourbackend.com"
}
release {
@ramonrabello
ramonrabello / build.gradle
Last active January 21, 2018 01:29
app module build.gradle with Kotlin dependencies
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
dependencies {
// other dependencies
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
@ramonrabello
ramonrabello / build.gradle
Last active January 22, 2018 12:33
project module build.gradle with Kotlin
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.2.20'
repositories {
google()
jcenter()
}
dependencies {
@ramonrabello
ramonrabello / PeopleRepository.kt
Last active February 11, 2019 17:08
Callback Hell with nested Retrofit calls
peopleRepository.loadPeopleAsync().enqueue(object: Callback<PeopleResponse> {
override fun onFailure(call: Call<PeopleResponse>, t: Throwable) { }
override fun onResponse(call: Call<PeopleResponse>, response: Response<PeopleResponse>) {
if (response.isSuccessful) {
val result = response.body()?.results
result?.let { characters ->
characters.forEach { character ->
peopleRepository.loadPerson(character.url).enqueue(object: Callback<PersonResponse>{
override fun onFailure(call: Call<PersonResponse>, t: Throwable) {}
override fun onResponse(call: Call<PersonResponse>, response: Response<PersonResponse>) {
@ramonrabello
ramonrabello / PeopleRepository.kt
Created February 12, 2019 22:49
PeopleRepository using RxJava
tmdbApi.loadPeople()
.map { movie -> movie.urls }
.map { url -> tmdbApi.movieDetails(url) }
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(onSuccess = { details -> view. showMovieDetails(details) },
onError = { view. showErrorMessage() })
@ramonrabello
ramonrabello / MainActivity.java
Created September 16, 2019 05:33
View Binding using ButterKnife
// declaring views
@BindView(R.id.description) TextView description;
@BindView(R.id.signInButton) Button signInButton;
@BindView(R.id.cancelButton) Button cancelButton;
// onCreate()
ButterKnife.bind(this)
@ramonrabello
ramonrabello / MainActivity.java
Created September 16, 2019 05:44
View Binding using findViewById()
public class MainActivity extends Activity {
private TextView description;
private Button signInButton;
private Button cancelButton;
// onCreate()
description = (TextView) findViewById(R.id.description);
signInButton = (Button) findViewById(R.id.signInButton);
cancelButton = (Button) findViewById(R.id.cancelButton);
@ramonrabello
ramonrabello / build.gradle
Last active September 16, 2019 16:42
Add ViewBinding support
android {
// ...
viewBinding.enabled = true
// ...
}
@ramonrabello
ramonrabello / MainActivity.kt
Last active September 16, 2019 16:43
ActivityMainBinding usage on MainActivity - complete
class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(LayoutInflater.from(this))
setContentView(binding.root)
binding.bindUserButton.setOnClickListener {
viewModel.onBindUserButtonClicked(
@ramonrabello
ramonrabello / activity_main.xml
Last active September 16, 2019 06:02
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<!-- region Guidelines -->
<androidx.constraintlayout.widget.Guideline