adding SimpleActivity and a couple common things
This commit is contained in:
parent
edfdf79e97
commit
92792ae3f3
|
@ -1,13 +1,17 @@
|
||||||
package com.simplemobiletools.thankyou.activities
|
package com.simplemobiletools.thankyou.activities
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.support.v7.app.AppCompatActivity
|
|
||||||
import com.simplemobiletools.thankyou.R
|
import com.simplemobiletools.thankyou.R
|
||||||
|
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : SimpleActivity() {
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_main)
|
setContentView(R.layout.activity_main)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onDestroy() {
|
||||||
|
super.onDestroy()
|
||||||
|
mConfig.isFirstRun = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
package com.simplemobiletools.thankyou.activities
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.support.v7.app.AppCompatActivity
|
||||||
|
import android.view.MenuItem
|
||||||
|
import com.simplemobiletools.thankyou.R
|
||||||
|
import com.simplemobiletools.thankyou.helpers.Config
|
||||||
|
|
||||||
|
open class SimpleActivity : AppCompatActivity() {
|
||||||
|
lateinit var mConfig: Config
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
mConfig = Config.newInstance(applicationContext)
|
||||||
|
setTheme(if (mConfig.isDarkTheme) R.style.AppTheme_Dark else R.style.AppTheme)
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
|
return when (item.itemId) {
|
||||||
|
android.R.id.home -> {
|
||||||
|
finish()
|
||||||
|
true
|
||||||
|
}
|
||||||
|
else -> super.onOptionsItemSelected(item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.simplemobiletools.thankyou.helpers
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.SharedPreferences
|
||||||
|
|
||||||
|
class Config(context: Context) {
|
||||||
|
private val mPrefs: SharedPreferences
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun newInstance(context: Context) = Config(context)
|
||||||
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
mPrefs = context.getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE)
|
||||||
|
}
|
||||||
|
|
||||||
|
var isFirstRun: Boolean
|
||||||
|
get() = mPrefs.getBoolean(IS_FIRST_RUN, true)
|
||||||
|
set(firstRun) = mPrefs.edit().putBoolean(IS_FIRST_RUN, firstRun).apply()
|
||||||
|
|
||||||
|
var isDarkTheme: Boolean
|
||||||
|
get() = mPrefs.getBoolean(IS_DARK_THEME, false)
|
||||||
|
set(isDarkTheme) = mPrefs.edit().putBoolean(IS_DARK_THEME, isDarkTheme).apply()
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
package com.simplemobiletools.thankyou.helpers
|
||||||
|
|
||||||
|
// Shared Preferences
|
||||||
|
val PREFS_KEY = "Thank You"
|
||||||
|
val IS_FIRST_RUN = "is_first_run"
|
||||||
|
val IS_DARK_THEME = "is_dark_theme"
|
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<color name="colorPrimary">#3F51B5</color>
|
<color name="colorPrimary">#fff68630</color>
|
||||||
<color name="colorPrimaryDark">#303F9F</color>
|
<color name="colorPrimaryDark">#ffe27725</color>
|
||||||
<color name="colorAccent">#FF4081</color>
|
<color name="colorAccent">@color/colorPrimary</color>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
<resources>
|
<resources>
|
||||||
<dimen name="activity_margin">16dp</dimen>
|
<dimen name="activity_margin">16dp</dimen>
|
||||||
|
|
||||||
|
<dimen name="normal_text_size">14sp</dimen>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -1,11 +1,29 @@
|
||||||
<resources>
|
<resources>
|
||||||
|
|
||||||
<!-- Base application theme. -->
|
|
||||||
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
|
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||||
<!-- Customize your theme here. -->
|
|
||||||
<item name="colorPrimary">@color/colorPrimary</item>
|
<item name="colorPrimary">@color/colorPrimary</item>
|
||||||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||||
<item name="colorAccent">@color/colorAccent</item>
|
<item name="colorAccent">@color/colorAccent</item>
|
||||||
|
<item name="actionBarStyle">@style/AppTheme.ActionBarStyle</item>
|
||||||
|
<item name="android:textSize">@dimen/normal_text_size</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style name="AppTheme.Dark" parent="Theme.AppCompat">
|
||||||
|
<item name="colorPrimary">@color/colorPrimary</item>
|
||||||
|
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||||
|
<item name="colorAccent">@color/colorAccent</item>
|
||||||
|
<item name="actionBarStyle">@style/AppTheme.ActionBarStyle</item>
|
||||||
|
<item name="android:textSize">@dimen/normal_text_size</item>
|
||||||
|
<item name="android:windowBackground">@android:color/black</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style name="AppTheme.ActionBarStyle" parent="@style/Base.Widget.AppCompat.ActionBar">
|
||||||
|
<item name="background">@color/colorPrimary</item>
|
||||||
|
<item name="titleTextStyle">@style/AppTheme.ActionBar.TitleTextStyle</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style name="AppTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
|
||||||
|
<item name="android:textSize">20sp</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in New Issue