Skip to content

Instantly share code, notes, and snippets.

View silviorp's full-sized avatar

Silvio Pereira silviorp

  • will bank
  • Ribeirão Preto
View GitHub Profile
@silviorp
silviorp / ApiExt.kt
Created August 3, 2024 22:01 — forked from iamhariomsharma/ApiExt.kt
Retrofit Error & Response Handling Utility function
suspend fun <T : Any> executeApi(call: suspend () -> Response<T>): DataResult<T, DataError.Network> {
return try {
val response = call.invoke()
val body = response.body()
val errorBody = response.errorBody()
if (response.isSuccessful && body != null) {
DataResult.Success(body)
} else if (errorBody != null) {
val gson = Gson()
val errorResponse = gson.fromJson(String(errorBody.bytes()), ErrorResponse::class.java)
@silviorp
silviorp / BaseActivity.java
Last active April 14, 2018 07:55
Base Activity providing ButterKnife binding, forcing layout Id register and abstracting showFragment call
// include package path here
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import butterknife.ButterKnife;
public abstract class BaseActivity extends AppCompatActivity {
@silviorp
silviorp / MainActivity.java
Last active April 14, 2018 07:54
Example of activity using CustosmBottomNavigationBar registering menu items and controlling the back stack
// include package path here
import android.support.v4.app.FragmentManager;
import android.widget.Toast;
import br.com.intelize.onhome.presenter.R;
import br.com.intelize.onhome.presenter.components.CustomBottomNavigationView;
import br.com.intelize.onhome.presenter.view.base.BaseActivity;
import br.com.intelize.onhome.presenter.view.fragment.BillsFragment;
import br.com.intelize.onhome.presenter.view.fragment.SettingsFragment;
@silviorp
silviorp / CustomBottomNavigationView.java
Last active April 14, 2018 07:55
This is an implementation of a custom BottomNavigationView that provides control over the Android Back Button
// include package path here
import android.content.Context;
import android.support.design.widget.BottomNavigationView;
import android.support.v4.app.FragmentManager;
import android.util.AttributeSet;
import java.util.HashMap;
import java.util.Map;