Skip to content

Instantly share code, notes, and snippets.

View maiconhellmann's full-sized avatar
:octocat:

Maicon Hellmann maiconhellmann

:octocat:
View GitHub Profile
@maiconhellmann
maiconhellmann / RecyclerViewAdapter.kt
Last active November 28, 2017 10:11
RecyclerView/RxEvent/ViewHolder/Adapter example in Kotlin
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import kotlinx.android.synthetic.main.item_container.view.*
import rx.Observable
import rx.subjects.PublishSubject
import javax.inject.Inject
class RecyclerViewAdapter
@maiconhellmann
maiconhellmann / CustomMapMarker.java
Created December 2, 2017 14:07
Custom map Marker in Java
private MarkerOptions createMarkerIcon(LatLng position) {
FrameLayout frameLayout = new FrameLayout(getContext());
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.WRAP_CONTENT,
FrameLayout.LayoutParams.WRAP_CONTENT);
frameLayout.setLayoutParams(params);
View markerView = getActivity().getLayoutInflater().inflate(R.layout.custom_map_marker, frameLayout);
BitmapDescriptor bitmapMerged = BitmapDescriptorFactory.fromBitmap(BitmapUtils.createDrawableFromView(getContext(), markerView));
@maiconhellmann
maiconhellmann / sendImageMultipartRetrofitRxJava.kt
Created March 11, 2018 12:10
Send image or file multipart retrofit RxJava
//Preparing the request
val filePart = MultipartBody.Part
.createFormData("file", "fileName",
RequestBody.create(MediaType.parse("image/jpeg"), File("/your/File/Path.jpg")))
//service.sendFile(id, filePart)
//Request definition retrofit
@PUT("https://www.yourdomain.com/api/file/{id}")
@Multipart
fun sendFile(@Path("id") id: Long, @Part file: MultipartBody.Part ) : Observable<YourModel>
@maiconhellmann
maiconhellmann / bg_radio_toggle_left.xml
Created April 8, 2018 10:31
RadioButton with a behavior of a ToggleButton or TabButton
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true">
<shape android:shape="rectangle">
<solid android:color="#3B5A9A" />
<corners android:bottomLeftRadius="4dp"
android:topLeftRadius="4dp"/>
</shape>
</item>
import io.reactivex.Single
import io.reactivex.SingleSource
import io.reactivex.SingleTransformer
/**
* Sealed class to handle ViewStates.
*
* When an error happens it will return a [ViewState.Failed] with a [ViewState.Failed.throwable] field
*
@maiconhellmann
maiconhellmann / adapter.kt
Created September 1, 2019 11:52
A simple recyclerView adapter/viewHolder
class CurrencyAdapter: RecyclerView.Adapter<CurrencyAdapter.ViewHolder>() {
var data: List<YourModelName> = emptyList()
set(value) {
field = value
notifyDataSetChanged()
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return ViewHolder(parent)
@maiconhellmann
maiconhellmann / view.xml
Last active March 20, 2020 14:30
Android - makes a view consumes all available space(fixes an issue related to the width of the component when used inside a RecyclerView). This is also a work around, the real problem is when a component is instantiated in code it should provide the layoutParams.
<View
....
app:layout_constraintHorizontal_bias="0"
android:layout_width="0dp"
app:layout_constraintWidth_default="wrap" >
</View>
@maiconhellmann
maiconhellmann / API url
Last active June 12, 2020 20:37
Htpp client using Koin DI, Retrofit and OkHttp
//more plugins here....
apply plugin: 'kotlin-kapt'
android {
//your stuff...
buildTypes {
release {
//your stuff...
buildConfigField "String", "BASE_URL", "\"https://your.api.url//\""
@maiconhellmann
maiconhellmann / ViewExtensions.kt
Created November 21, 2017 16:40
Kotlin extensions for View
import android.support.design.widget.Snackbar
import android.view.View
import com.github.clans.fab.FloatingActionMenu
fun View.visible(){
this.visibility = View.VISIBLE
}
fun View.visible(visible : Boolean){
if(visible){
visible()
@maiconhellmann
maiconhellmann / ContextExctensions.kt
Created November 21, 2017 16:41
Kotlin extensions for Context
import android.content.ComponentName
import android.content.Context
import android.content.CursorLoader
import android.content.pm.PackageManager
import android.net.ConnectivityManager
import android.net.Uri
import android.os.Looper
import android.provider.MediaStore
import android.support.annotation.ColorRes
import android.support.annotation.StringRes