Skip to content

Instantly share code, notes, and snippets.

View danielgomezrico's full-sized avatar

Daniel Gomez danielgomezrico

View GitHub Profile
@danielgomezrico
danielgomezrico / TextViewExtensions.kt
Created February 26, 2018 20:19
Extension to set a text with HTML tags on TextView
fun TextView.setHtmlText(text: String) {
val formattedText = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Html.fromHtml(text, Html.FROM_HTML_MODE_LEGACY)
} else {
Html.fromHtml(text)
}
setText(formattedText, TextView.BufferType.SPANNABLE)
movementMethod = LinkMovementMethod.getInstance()
}
@danielgomezrico
danielgomezrico / gist:874cd2f7a923173415817136d761d3e8
Created February 17, 2018 19:44
[Kotlin, rxjava and room] - how to always get a value from Maybe
class Optional<out M>(val data: M?)
@Dao
interface PatientDao {
@Query("SELECT * FROM $patientTableName LIMIT 1")
fun getFirst(): Maybe<User>
}
@danielgomezrico
danielgomezrico / rbenv-install-system-wide.sh
Last active February 5, 2018 18:38 — forked from tomazzlender/rbenv-install-system-wide.sh
rbenv install and system wide install on Ubuntu to /opt/rbenv
# Update, upgrade and install development tools:
apt-get update
apt-get -y upgrade
apt-get -y install build-essential
apt-get -y install git-core
# Install rbenv
git clone git://github.com/rbenv/rbenv.git /opt/rbenv
# Add rbenv to the path:
@danielgomezrico
danielgomezrico / .gitlab-ci.yml
Last active June 16, 2020 11:47
Android / Gitlab ci - sample setup files to setup your own local gitlab runner with real physical android devices. Check https://github.com/caipivara/awesome-android-scripts
stages:
- build
- test
- deploy
variables:
GIT_STRATEGY: clone
cache:
key: ${CI_PROJECT_ID}
@danielgomezrico
danielgomezrico / .gitlab-ci.yml
Last active April 26, 2018 14:54
Gitlab - Local Gitlab Runner for Android (setup your computer with real usb attached devices)
stages:
- build
- test
cache:
key: ${CI_PROJECT_ID}
paths:
- .gradle/
before_script:
@danielgomezrico
danielgomezrico / Repository.kt
Last active May 4, 2017 20:27
Android / Retrofit 2 - Upload file
fun uploadFile(user: User, avatarPath: String, mimeType: String): Observable<Answer<Any>> {
val avatarFile = File(avatarPath)
val requestFile = RequestBody.create(MediaType.parse(mimeType.toLowerCase()), avatarFile)
val body = MultipartBody.Part.createFormData("file", avatarFile.name, requestFile)
return service.uploadFile(user.id, body) // Service is an instance created by retrofit with Service.kt
}
@danielgomezrico
danielgomezrico / cheatsheet.kt
Created April 20, 2017 14:55
Android UI Cheatsheet
# Show back arrow on actionBar/toolbar
supportActionBar?.setDisplayHomeAsUpEnabled(true)
@danielgomezrico
danielgomezrico / install-deps-with-android.sh
Last active July 23, 2018 07:38
Android - install dependencies to build android projects on linux/ci/other using sdkmanager/android terminal tools
#!/usr/bin/env bash
#
# Install required dependencies with android command
#
for DEP in android-25 \
build-tools-25.0.2 \
tool \
extra-android-m2repository \
extra-android-support \
@danielgomezrico
danielgomezrico / add local aar file.md
Created January 21, 2017 17:09 — forked from shau-lok/add local aar file.md
Android Studio add local .aar reference

Add local .aar file

  1. basic build.gradle directory using flatDir
repositories {
    mavenCentral()
    flatDir {
 dirs 'libs'
@danielgomezrico
danielgomezrico / AndroidDevice.kt
Created January 18, 2017 16:56
Android - how to get logcat File
class AndroidDevice(val activity: AppCompatActivity) {
/**
* Source: http://stackoverflow.com/a/22174245/273119
*/
fun readLogFile(): String {
val fullName = "appLog.log"
val file = File(activity.cacheDir, fullName)
val pid = android.os.Process.myPid().toString()