extend BaseSimpleActivity with SimpleActivity

This commit is contained in:
tibbi 2016-12-29 22:38:33 +01:00
parent fbf58e3ae3
commit 27ec78ad18
5 changed files with 26 additions and 44 deletions

View file

@ -51,7 +51,7 @@ class AboutActivity : SimpleActivity() {
}
private fun setupRateUs() {
if (mConfig.isFirstRun) {
if (config.isFirstRun) {
about_rate_us.visibility = View.GONE
} else {
about_rate_us.setOnClickListener {

View file

@ -101,7 +101,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
}
private fun setupDefaultReminderType() {
val type = mConfig.defaultReminderType
val type = config.defaultReminderType
toggleCustomReminderVisibility(type == REMINDER_CUSTOM)
if (type == REMINDER_OFF) {
event_reminder.setSelection(0)
@ -114,7 +114,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
}
private fun setupDefaultReminderValue() {
val mins = mConfig.defaultReminderMinutes
val mins = config.defaultReminderMinutes
var value = mins
if (mins == 0) {
custom_reminder_other_period.setSelection(0)

View file

@ -49,7 +49,7 @@ class MainActivity : SimpleActivity(), EventListFragment.DeleteListener {
override fun onDestroy() {
super.onDestroy()
mConfig.isFirstRun = false
config.isFirstRun = false
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
@ -76,7 +76,7 @@ class MainActivity : SimpleActivity(), EventListFragment.DeleteListener {
}
override fun onBackPressed() {
if (mIsMonthSelected && mConfig.storedView == YEARLY_VIEW) {
if (mIsMonthSelected && config.storedView == YEARLY_VIEW) {
updateView(YEARLY_VIEW)
} else {
super.onBackPressed()
@ -92,14 +92,14 @@ class MainActivity : SimpleActivity(), EventListFragment.DeleteListener {
private fun updateView(view: Int) {
calendar_fab.visibility = if (view == YEARLY_VIEW) View.GONE else View.VISIBLE
mIsMonthSelected = view == MONTHLY_VIEW
mConfig.storedView = view
config.storedView = view
updateViewPager()
}
private fun updateViewPager() {
if (mConfig.storedView == YEARLY_VIEW) {
if (config.storedView == YEARLY_VIEW) {
fillYearlyViewPager()
} else if (mConfig.storedView == EVENTS_LIST_VIEW) {
} else if (config.storedView == EVENTS_LIST_VIEW) {
fillEventsList()
} else {
val targetDay = DateTime().toString(Formatter.DAYCODE_PATTERN)

View file

@ -6,7 +6,6 @@ import android.media.RingtoneManager
import android.net.Uri
import android.os.Bundle
import android.os.Parcelable
import android.support.v4.app.TaskStackBuilder
import android.view.View
import android.widget.AdapterView
import com.simplemobiletools.calendar.R
@ -33,28 +32,28 @@ class SettingsActivity : SimpleActivity() {
}
private fun setupSundayFirst() {
settings_sunday_first.isChecked = mConfig.isSundayFirst
settings_sunday_first.isChecked = config.isSundayFirst
settings_sunday_first_holder.setOnClickListener {
settings_sunday_first.toggle()
mConfig.isSundayFirst = settings_sunday_first.isChecked
config.isSundayFirst = settings_sunday_first.isChecked
}
}
private fun setupWeekNumbers() {
settings_week_numbers.isChecked = mConfig.displayWeekNumbers
settings_week_numbers.isChecked = config.displayWeekNumbers
settings_week_numbers_holder.setOnClickListener {
settings_week_numbers.toggle()
mConfig.displayWeekNumbers = settings_week_numbers.isChecked
config.displayWeekNumbers = settings_week_numbers.isChecked
}
}
private fun setupReminderSound() {
settings_reminder_sound.text = RingtoneManager.getRingtone(this, Uri.parse(mConfig.reminderSound)).getTitle(this)
settings_reminder_sound.text = RingtoneManager.getRingtone(this, Uri.parse(config.reminderSound)).getTitle(this)
settings_reminder_sound_holder.setOnClickListener {
Intent(RingtoneManager.ACTION_RINGTONE_PICKER).apply {
putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION)
putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, resources.getString(R.string.notification_sound))
putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, Uri.parse(mConfig.reminderSound))
putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, Uri.parse(config.reminderSound))
if (resolveActivity(packageManager) != null)
startActivityForResult(this, GET_RINGTONE_URI)
@ -66,16 +65,16 @@ class SettingsActivity : SimpleActivity() {
}
private fun setupVibrate() {
settings_vibrate.isChecked = mConfig.vibrateOnReminder
settings_vibrate.isChecked = config.vibrateOnReminder
settings_vibrate_holder.setOnClickListener {
settings_vibrate.toggle()
mConfig.vibrateOnReminder = settings_vibrate.isChecked
config.vibrateOnReminder = settings_vibrate.isChecked
}
}
private fun setupEventReminder() {
val reminderType = mConfig.defaultReminderType
val reminderMinutes = mConfig.defaultReminderMinutes
val reminderType = config.defaultReminderType
val reminderMinutes = config.defaultReminderMinutes
settings_default_reminder.setSelection(when (reminderType) {
REMINDER_OFF -> 0
REMINDER_AT_START -> 1
@ -99,7 +98,7 @@ class SettingsActivity : SimpleActivity() {
settings_custom_reminder_holder.visibility = View.GONE
}
mConfig.defaultReminderType = when (itemIndex) {
config.defaultReminderType = when (itemIndex) {
0 -> REMINDER_OFF
1 -> REMINDER_AT_START
else -> REMINDER_CUSTOM
@ -116,8 +115,8 @@ class SettingsActivity : SimpleActivity() {
else -> 1
}
mConfig.defaultReminderMinutes = Integer.valueOf(if (value.isEmpty()) "0" else value) * multiplier
mConfig.defaultReminderType = REMINDER_CUSTOM
config.defaultReminderMinutes = Integer.valueOf(if (value.isEmpty()) "0" else value) * multiplier
config.defaultReminderType = REMINDER_CUSTOM
toast(R.string.reminder_saved)
hideKeyboard()
}
@ -142,11 +141,7 @@ class SettingsActivity : SimpleActivity() {
if (resultCode == Activity.RESULT_OK && requestCode == GET_RINGTONE_URI) {
val uri = intent?.getParcelableExtra<Parcelable>(RingtoneManager.EXTRA_RINGTONE_PICKED_URI) ?: return
settings_reminder_sound.text = RingtoneManager.getRingtone(this, uri as Uri).getTitle(this)
mConfig.reminderSound = uri.toString()
config.reminderSound = uri.toString()
}
}
private fun restartActivity() {
TaskStackBuilder.create(applicationContext).addNextIntentWithParentStack(intent).startActivities()
}
}

View file

@ -1,27 +1,14 @@
package com.simplemobiletools.calendar.activities
import com.simplemobiletools.calendar.R
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.MenuItem
import com.simplemobiletools.calendar.helpers.Config
import com.simplemobiletools.commons.activities.BaseSimpleActivity
open class SimpleActivity : AppCompatActivity() {
lateinit var mConfig: Config
open class SimpleActivity : BaseSimpleActivity() {
lateinit var config: Config
override fun onCreate(savedInstanceState: Bundle?) {
mConfig = Config.newInstance(applicationContext)
setTheme(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)
}
config = Config.newInstance(applicationContext)
}
}