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 / 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>
@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//\""
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 / MyAmazingActivity
Created November 30, 2020 13:46
screenOrientation - smartphone = PORTRAIT and tablet = DYNAMIC
class MyAmazingActivity: AppCompatActivity {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (resources.getBoolean(R.bool.portrait_only)) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
} else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR)
}
}
/**
* Check if a point cliked is in the are of a line.
*/
class CheckLineClicked {
/**
* Returns the distance between a point(clickPosition) and a line(start and end point).
*/
fun checkLineClicked(clickPosition: PointF, startPoint: PointF, endPointF: PointF): Float {
val x = clickPosition.x