Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View grumpyshoe's full-sized avatar

Thomas Cirksena grumpyshoe

View GitHub Profile
@grumpyshoe
grumpyshoe / usefull_code.md
Last active February 26, 2024 22:19
Usefull commands while developing android apps

Test related

UnitTest

Make test wait until everyting is idle

testDispatcher.scheduler.advanceUntilIdle()

Bundletool

build apks

@grumpyshoe
grumpyshoe / MainActivity.kt
Created August 22, 2022 08:28
Show PDF in zoomable Image in Jetpack Compose
package de.grumpyshoe.pdfviewer
import android.graphics.Bitmap
import android.graphics.pdf.PdfRenderer
import android.os.Bundle
import android.os.ParcelFileDescriptor
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.annotation.RawRes
import androidx.compose.foundation.Image
@grumpyshoe
grumpyshoe / build.gradle
Created March 11, 2019 19:34
Gradle: how to get git hash in build.gradle
String getGitHash() {
// git hash
def command = Runtime.getRuntime().exec("git rev-parse --short HEAD")
def result = command.waitFor()
if (result != 0) {
throw new IOException("Command 'getGitHash()' exited with " + result)
}
String gitCommitHash = command.inputStream.text.trim()
@grumpyshoe
grumpyshoe / tinder-like-card-dragging.kt
Created July 6, 2023 19:18
Compose: Tinder like card dragging
fun Modifier.swiper(
enabled: Boolean,
state: Swipe,
onDragReset: () -> Unit = {},
onTap: () -> Unit,
onLongPress: () -> Unit,
onDrag: (SwipeDirection?, Float) -> Unit = { _, _ -> },
onDragRight: () -> Unit,
onDragLeft: () -> Unit,
): Modifier = composed {
@grumpyshoe
grumpyshoe / pinch-to-zoom-modifier.kt
Created July 5, 2023 18:48
Composeable modifier: Pinch-To-Zoom
fun Modifier.pinchToZoom(
minZoom: Float? = null,
maxZoom: Float? = null,
): Modifier = composed {
var zoom by remember { mutableStateOf(1f) }
val state = rememberTransformableState { scaleChange, _, _ ->
val newZoom = (zoom * scaleChange).coerceIn(minZoom ?: MIN_VALUE, maxZoom ?: MAX_VALUE)
zoom = newZoom
}
@grumpyshoe
grumpyshoe / git_commands.md
Created January 4, 2023 08:02
Usefull git commands

Get number of commits

Source: StackOferflow

To see total no of commits you can do as Peter suggested above

git rev-list --count HEAD

And if you want to see number of commits made by each person try this line

git shortlog -s -n

@grumpyshoe
grumpyshoe / adb_commands.md
Last active November 10, 2021 22:16
Anroid adb commands

Enable/Disable WIFI:

adb shell cmd -w wifi set-wifi-enabled enable
adb shell cmd -w wifi set-wifi-enabled disable

Quelle: https://stackoverflow.com/a/68794783/5804482


Enable/Disable mobile data:

adb shell svc data enable

@grumpyshoe
grumpyshoe / Gradle: Invalidate dependencies
Created September 26, 2019 12:16
invalidate gradle dependecies for test purpose
# https://stackoverflow.com/questions/13565082/how-can-i-force-gradle-to-redownload-dependencies
# https://discuss.gradle.org/t/how-to-get-gradle-to-download-newer-snapshots-to-gradle-cache-when-using-an-ivy-repository/7344
# You can tell Gradle to re-download some dependencies in the build script by flagging
# the dependency as 'changing'. Gradle will then check for updates every 24 hours, but
# this can be configured using the resolutionStrategy DSL. I find it useful to use this
# for for SNAPSHOT or NIGHTLY builds.
configurations.all {
// Check for updates every build
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
@grumpyshoe
grumpyshoe / MainViewModelTest.kt
Last active February 15, 2019 10:30
JUnit-Test example
class MainViewModelTest {
private lateinit var apiService: ApiService
@Rule
@JvmField
var rule: TestRule = InstantTaskExecutorRule()
@Before
fun setUp() {
@grumpyshoe
grumpyshoe / TestApplication.kt
Last active January 18, 2019 12:35
Example of custom Application class containing values for mocking UI-Test-components
class TestAppApplication : Application() {
// initialize mock ApiService
var mockApiService = MockApiService
/**
* onCreate
*
*/
override fun onCreate() {