Skip to content

Instantly share code, notes, and snippets.

Avatar

David Vavra davidvavra

View GitHub Profile
View ExampleTest.kt
@Composable
fun AppGreeting() {
Text(text = "Hello from app module!")
}
@Preview(name = "App module greeting", group = "Greetings")
@Composable
fun DefaultPreview() {
ShowkaseTheme {
AppGreeting()
View ComposeTests.kt
@ShowkaseScreenshot(rootShowkaseClass = ShowkaseRoot::class)
abstract class ComposeTests : ShowkaseScreenshotTest {
override fun onScreenshot(
id: String,
name: String,
group: String,
styleName: String?,
screenshotType: ShowkaseScreenshotType,
screenshotBitmap: Bitmap
View AskForReview.kt
lateinit var manager: ReviewManager
var reviewInfo: ReviewInfo? = null
// Call this method asap, for example in onCreate()
private fun initReviews() {
manager = ReviewManagerFactory.create(this)
manager.requestReviewFlow().addOnCompleteListener { request ->
if (request.isSuccessful) {
reviewInfo = request.result
} else {
@davidvavra
davidvavra / NonNullAssertionDetector.kt
Created Mar 22, 2019
Lint check for detecting non-null assertion (!!) in your code
View NonNullAssertionDetector.kt
import com.android.tools.lint.client.api.UElementHandler
import com.android.tools.lint.detector.api.*
import org.jetbrains.uast.UElement
import org.jetbrains.uast.UPostfixExpression
class NonNullAssertionDetector : Detector(), Detector.UastScanner {
override fun getApplicableUastTypes(): List<Class<out UElement>>? {
return listOf(UPostfixExpression::class.java)
}
View navigateBackWithResult.kt
fun navigateBackWithResult(result: Bundle) {
val childFragmentManager = supportFragmentManager.findFragmentById(R.id.nav_host_fragment)?.childFragmentManager
var backStackListener: FragmentManager.OnBackStackChangedListener by Delegates.notNull()
backStackListener = FragmentManager.OnBackStackChangedListener {
(childFragmentManager?.fragments?.get(0) as NavigationResult).onNavigationResult(result)
childFragmentManager.removeOnBackStackChangedListener(backStackListener)
}
childFragmentManager?.addOnBackStackChangedListener(backStackListener)
navController().popBackStack()
}
View gameConNahradniciTesting.php
/**
* Vrátí html kód pro přihlášení / odhlášení / informaci o zaplněnosti pro
* daného uživatele. Pokud není zadán, vrací prázdný řetězec.
* @todo v rodině instancí maximálně jedno přihlášení?
* @todo konstanty pro jména POST proměnných? viz prihlasovatkoZpracuj
*/
function prihlasovatko(Uzivatel $u = null, $parametry = 0) {
$out = '';
if($u && $u->gcPrihlasen() && $this->prihlasovatelna($parametry)) {
if (($stav = $this->prihlasenStav($u)) > -1) {
View EasierToDebug.kt
uploadPhoto(requireNotNull(intent.getStringExtra("PHOTO_URL"), { "Activity parameter 'PHOTO_URL' is missing" }))
View HardToDebug.kt
uploadPhoto(intent.getStringExtra("PHOTO_URL")!!)
View WithElvis.kt
fun getUserName(): String {
return mUserName ?: "Anonymous"
}
View WithoutElvis.kt
fun getUserName(): String {
if (mUserName != null) {
return mUserName!!
} else {
return "Anonymous"
}
}