Skip to content

Instantly share code, notes, and snippets.

View CostaFot's full-sized avatar
🍦

Costa Fotiadis CostaFot

🍦
View GitHub Profile
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// the URL we want to load
val url = "https://media.giphy.com/media/cYxLgjZI5ezI2lrItX/giphy.gif"
val circularProgressDrawable = createSpinner()
@CostaFot
CostaFot / MainViewModel.kt
Last active October 25, 2019 20:21
CatModel!
class MainViewModel : ViewModel() {
private val compositeDisposableOnDestroy = CompositeDisposable()
private var latestCatCall: Disposable? = null
// the list that will be observed by the activity
val bunchOfCats = MutableLiveData<List<NetCat>>()
// the error message observed
val errorMessage = MutableLiveData<String>()
// the API call
@CostaFot
CostaFot / MainActivity.kt
Created February 24, 2019 20:28
Cat activity
class MainActivity : AppCompatActivity() {
// Read the docs with detailed instructions to get your API key and endpoint!
// https://docs.thecatapi.com/
// public static fields in a companion object because im a horrible person
companion object {
// the server url endpoint
const val serverUrl = "https://api.thecatapi.com/v1/"
// this is where you declare your api key
@CostaFot
CostaFot / build.gradle
Last active February 25, 2019 19:39
Deps
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
// need this plugin to make this work
apply plugin: 'kotlin-kapt'
android {
// your android stuff goes here
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
// your android stuff goes here
}
dependencies {
// auto-generated dependencies
@CostaFot
CostaFot / onPause()
Last active February 25, 2019 19:44
override fun onPause() {
compositeDisposableOnPause.clear()
super.onPause()
}
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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">
<Button
android:id="@+id/button"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
button.setOnClickListener {
changeButtonText()
}
}
private fun changeButtonText() {
compositeDisposableOnPause.add(
Single.fromCallable {generateString()}
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe { textGenerated -> button.text = textGenerated }
)
}
private fun generateString(): String {
return "reddit"
}