This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun Fragment.isGranted(permission: AppPermission) = run { | |
context?.let { | |
(PermissionChecker.checkSelfPermission(it, permission.permissionName | |
) == PermissionChecker.PERMISSION_GRANTED) | |
} ?: false | |
} | |
fun Fragment.shouldShowRationale(permission: AppPermission) = run { | |
shouldShowRequestPermissionRationale(permission.permissionName) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.flyingdutchman.material.components | |
import android.app.Activity | |
import android.content.Context | |
import android.view.LayoutInflater | |
import android.view.Window | |
import androidx.appcompat.app.AlertDialog | |
import androidx.core.view.isVisible | |
import androidx.fragment.app.Fragment | |
import com.flyingdutchman.material.components.databinding.CustomDialogComponentBinding |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val showDialogButton = findViewById<Button>(R.id.show_dialog_button) | |
showDialogButton?.let { | |
it.setOnClickListener { | |
dialog { | |
title = resources.getString(R.string.custom_dialog_title) | |
contentText = resources.getString(R.string.custom_dialog_body) | |
negativeText = resources.getString(R.string.custom_dialog_negative_text) | |
positiveText = resources.getString(R.string.custom_dialog_positive_text) | |
positiveAction = { toast("Positive Action!!!") } | |
negativeAction = { toast("Negative Action!!!") } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Call inside a button on debug drawer or through a kinda of easter egg backdoor inside your app | |
button.setOnClickListener { analytics(it.context).simulateCrash() } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* You can report it using trackEvent or do your own logic, but remember, you are running in the Main Thread. | |
* Besides, you shouldn't rely on heavy libraries like RxJava, but Coroutines or Executors are easy to follow as well | |
*/ | |
override fun uncaughtException(thread: Thread, throwable: Throwable) { | |
try { | |
analytics(context) | |
.track { | |
name = EventName.EXCEPTION | |
EventName.STACK_TRACE to extractStackTraceInfo(throwable) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--------- beginning of crash | |
2021-01-26 22:25:18.607 8665-8665/com.flyingdutchman.simple_analytics E/AndroidRuntime: FATAL EXCEPTION: main | |
Process: com.flyingdutchman.simple_analytics, PID: 8665 | |
java.lang.RuntimeException: Simulate Crash: Boom!! | |
at com.flyingdutchman.simple_analytics.AndroidCrashLogger.simulateCrash(AndroidCrashLogger.kt:35) | |
at com.flyingdutchman.simple_analytics.AnalyticsImpl.simulateCrash(Analytics.kt:46) | |
at com.flyingdutchman.simple_analytics.Main2Activity$onCreate$1.onClick(Main2Activity.kt:14) | |
at android.view.View.performClick(View.java:6256) | |
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:992) | |
at android.view.View$PerformClick.run(View.java:24701) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun simulateCrash() { | |
//Here you can throw a RuntimeException or use a related method of your crash report SDK | |
throw RuntimeException("Simulate Crash: Boom!!") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class App : Application() { | |
override fun onCreate() { | |
super.onCreate() | |
StrictMode.setThreadPolicy( | |
StrictMode.ThreadPolicy.Builder() | |
.detectAll() | |
.penaltyLog() | |
.penaltyDialog() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class BaseActivity : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
log("onCreate()") | |
super.onCreate(savedInstanceState) | |
} | |
override fun onStart() { | |
log("onStart()") | |
super.onStart() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private var defaultHandler: Thread.UncaughtExceptionHandler? = | |
Thread.getDefaultUncaughtExceptionHandler() |
NewerOlder