Skip to content

Instantly share code, notes, and snippets.

@mrsasha
mrsasha / methodcount.bat
Created September 14, 2014 16:08
.jar and .dex method count helpers for Windows. dx from build-tools in the Android SDK has to be in your PATH. Just call methodcount.bat "filename"
@ECHO OFF
IF "%1"=="" GOTO MissingFileNameError
IF EXIST "%1" (GOTO ContinueProcessing) ELSE (GOTO FileDoesntExist)
:ContinueProcessing
set FileNameToProcess=%1
set FileNameForDx=%~n1.dex
IF "%~x1"==".dex" GOTO ProcessWithPowerShell
REM preprocess Jar with dx
@mrsasha
mrsasha / detekt-config.yml
Created December 18, 2019 10:41
detekt setup for 1.2.2 version
build:
maxIssues: 0
comments:
active: true
excludes: "**/*Test.kt, **/*Spec.kt"
CommentOverPrivateFunction:
active: false
CommentOverPrivateProperty:
active: false
@mrsasha
mrsasha / Activity.kt
Created February 4, 2020 12:39
Permission management
override fun onStart() {
super.onStart()
permissionManager.requestLocationPermission(this, object : LocationPermissionListener {
override fun permissionGranted() {
Timber.v("location permission granted!")
}
override fun permissionError(error: DexterError) {
Timber.w("location permission error: $error!")
}
@mrsasha
mrsasha / GsonSetup.kt
Last active February 10, 2020 13:45
date & time formatting & de/serialization with Gson and ThreeTenABP
private fun createGson(): Gson = GsonBuilder()
.registerTypeAdapter(OffsetDateTime::class.java, OffsetDateTimeTypeAdapter())
.create()
class OffsetDateTimeTypeAdapter : JsonSerializer<OffsetDateTime>, JsonDeserializer<OffsetDateTime> {
override fun serialize(
src: OffsetDateTime,
typeOfSrc: Type,
context: JsonSerializationContext
@mrsasha
mrsasha / Activity.kt
Last active February 18, 2020 16:25
viewmodels with channels
private fun observeViewModel() {
mainViewModel.observe(lifecycleScope) {
when (it) {
MainScreenState.InProgress -> showProgress()
}
}
}
@mrsasha
mrsasha / AndroidManifest.xml
Last active February 24, 2020 15:16
Image passing
<manifest>
<application>
<activity
android:name="com.yalantis.ucrop.UCropActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
@mrsasha
mrsasha / add_detekt_single_module.md
Created July 13, 2018 08:31
Adding detekt static code analysis to kotlin projects

You can add static code analysis to kotlin using detekt. Below is the basic configuration, for more details about configuration and rules go to project page: https://arturbosch.github.io/detekt/.

//add to top-level gradle file
buildscript {
    ext {
        detektVersion = '1.0.0.RC7'
    }

 repositories {
@mrsasha
mrsasha / build.gradle
Last active April 14, 2022 12:24
adding Sonarqube reporting for Lint and test coverage to Android Kotlin project (multi-module)
apply plugin: "org.sonarqube"
buildscript {
dependencies {
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.6.2"
}
}
//ADD ALL THE TASKS (coverage, lint) FOR ALL THE MODULES YOU WANT TO BE REPORTED
project.tasks["sonarqube"].dependsOn ':library-core:testDebugUnitTestCoverage'
@mrsasha
mrsasha / page.html
Created May 17, 2022 10:09
Example of page with change password request
<html id="top" lang="it"><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Cambio password, Università di UNICAL</title>
<meta content="IE=edge" http-equiv="X-UA-Compatible">
<meta content="width=device-width, initial-scale=1" name="viewport">
<meta content="Servizi online dell'ateneo" name="description">
<meta content="noindex, nofollow" name="robots">
<base href="https://unical.esse3.cineca.it/">
<link href="img/layout/favicons/apple-touch-icon.png" sizes="120x120" rel="apple-touch-icon" class="favicon">
<link href="https://unical.esse3.cineca.it/img/layout/favicons/favicon-32x32.png" sizes="32x32" type="image/png" rel="icon" class="favicon">
@mrsasha
mrsasha / HomeViewModel.kt
Created May 27, 2022 09:31
HomeViewModel v1
package lu.gian.uniwhere.features.home.ui
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.google.firebase.iid.FirebaseInstanceId
import com.uniwhere.kmp.elephas.localdatasource.LocalDataSource
import com.uniwhere.kmp.elephas.model.ExamStatsAverageType
import com.uniwhere.kmp.elephas.model.UWErrorCodeClass
import com.uniwhere.kmp.elephas.model.UniAccountWrapper