diff --git a/ChangeLogLib/src/main/java/info/hannes/changelog/ChangeLog.kt b/ChangeLogLib/src/main/java/info/hannes/changelog/ChangeLog.kt index 512bdce..0afad3b 100644 --- a/ChangeLogLib/src/main/java/info/hannes/changelog/ChangeLog.kt +++ b/ChangeLogLib/src/main/java/info/hannes/changelog/ChangeLog.kt @@ -28,7 +28,8 @@ import java.util.Collections open class ChangeLog @JvmOverloads constructor( private val context: Context, preferences: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(context), - protected val css: String = DEFAULT_CSS + protected val css: String = DEFAULT_CSS, + val callback: (() -> Unit)? = null ) { /** * Get version code of last installation. @@ -208,6 +209,7 @@ open class ChangeLog @JvmOverloads constructor( ) { _, _ -> // The user clicked "OK" so save the current version code as "last version code". updateVersionInPreferences() + callback?.invoke() } if (!full) { diff --git a/app/src/main/java/info/hannes/changelog/sample/MainActivity.kt b/app/src/main/java/info/hannes/changelog/sample/MainActivity.kt index 17470e1..5de90dc 100644 --- a/app/src/main/java/info/hannes/changelog/sample/MainActivity.kt +++ b/app/src/main/java/info/hannes/changelog/sample/MainActivity.kt @@ -4,6 +4,7 @@ import android.content.Context import android.content.Intent import android.net.Uri import android.os.Bundle +import android.util.Log import android.view.ContextThemeWrapper import android.view.Menu import android.view.MenuItem @@ -36,7 +37,9 @@ class MainActivity : AppCompatActivity() { setupDrawerContent(it) } - val changeLog = ChangeLog(this) + val changeLog = ChangeLog(this, callback = { + Log.d("log", "dialog dismiss") + }) if (changeLog.isFirstRun) { changeLog.logDialog.show() } @@ -54,7 +57,10 @@ class MainActivity : AppCompatActivity() { private fun selectNavigationItem(itemId: Int) { when (itemId) { - R.id.nav_full_changelog -> ChangeLog(this).fullLogDialog.show() + R.id.nav_full_changelog -> ChangeLog(this, callback = { + Log.d("log", "dialog dismiss") + }).fullLogDialog.show() + R.id.nav_whats_new -> DarkThemeChangeLog(this).logDialog.show() R.id.nav_other_github -> { val url = "https://github.com/hannesa2/ChangeLog" @@ -74,7 +80,9 @@ class MainActivity : AppCompatActivity() { when (item.itemId) { android.R.id.home -> mDrawerLayout.openDrawer(GravityCompat.START) R.id.nav_whats_new -> DarkThemeChangeLog(this).logDialog.show() - R.id.nav_full_changelog -> ChangeLog(this).fullLogDialog.show() + R.id.nav_full_changelog -> ChangeLog(this, callback = { + Log.d("log", "dialog dismiss") + }).fullLogDialog.show() } return true } @@ -82,7 +90,12 @@ class MainActivity : AppCompatActivity() { /** * Example that shows how to create a themed dialog. */ - class DarkThemeChangeLog internal constructor(context: Context) : ChangeLog(ContextThemeWrapper(context, R.style.DarkTheme), DARK_THEME_CSS) + class DarkThemeChangeLog internal constructor(context: Context) : ChangeLog( + ContextThemeWrapper(context, R.style.DarkTheme), + css = DARK_THEME_CSS, + callback = { + Log.d("DarkThemeChangeLog", "dialog dismiss") + }) companion object { internal val DARK_THEME_CSS = "body { color: #ffffff; background-color: #282828; }\n$DEFAULT_CSS"