Skip to content

Instantly share code, notes, and snippets.

@mrsasha
mrsasha / build.gradle
Last active March 21, 2024 10:36
adding Sonarqube reporting for Lint and test coverage to Android Kotlin project (single module)
buildscript {
dependencies {
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.6.2"
}
}
@mrsasha
mrsasha / code_review_guidelines.md
Last active September 10, 2023 13:46
Code review guidelines

Some helpful guidelines for pull requests and code reviews

It's been often said that programming is part art, part science - that because lots of times there's no single, simple solution to a problem; or if there is, we might not know about it. There's also an infamous joke that if there are n developers in the room, then there are n+1 opinions on how things should be done. That being said, here are some guidelines that should prevent friction when submitting or reviewing code.

The most important thing

The code has to work. Unless you open a PR as a work in progress, the code should be built and tested on a device or emulator.

If you have touched the gradle build files and changed build setup, it's useful to test the whole build from scratch (clean build) and all of the types and flavours. If you have touched payments (logic or UI), you should test that it still works correctly, both in test and production builds. If you updated external libraries, test the pertaining features (e.g. if you

@mrsasha
mrsasha / README.md
Created July 13, 2018 08:25
Jacoco setup for calculating kotlin test coverage (single module)

Jacoco setup for calculating kotlin test coverage (single module)

put the jacoco.gradle file below somewhere in your app repo (like scripts folder), and then add apply from: '../scripts/jacoco.gradle' to your module gradle file.

This will add additional gradle build tasks to your app, in the form of "testFlavourUnitTestCoverage" that you can run manually (e.g. testStagingDebugUnitTestCoverage) to generate the coverage.

You can edit def excludes definition to further exclude classes you don't want to generate the coverage for. If you have source in other folders beyond those specified in def coverageSourceDirs, add them.

This will generate both exec file used by external code quality analyzers (like Sonarqube), in the build/jacoco folder, and XML and HTML reports, in the build/reports/jacoco/flavourName folder.

@mrsasha
mrsasha / HomeViewModel.kt
Created May 27, 2022 09:42
HomeViewModel v2
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.CredentialsManager
import com.uniwhere.kmp.elephas.model.ExamStatsAverageType
import com.uniwhere.kmp.elephas.model.UWErrorCodeClass
@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
@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 / 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 / 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 / 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 / Activity.kt
Last active February 18, 2020 16:25
viewmodels with channels
private fun observeViewModel() {
mainViewModel.observe(lifecycleScope) {
when (it) {
MainScreenState.InProgress -> showProgress()
}
}
}