From 27ec78ad18c2b4395485cc244e4e21ddfbed5e24 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 29 Dec 2016 22:38:33 +0100 Subject: [PATCH] extend BaseSimpleActivity with SimpleActivity --- .../calendar/activities/AboutActivity.kt | 2 +- .../calendar/activities/EventActivity.kt | 4 +-- .../calendar/activities/MainActivity.kt | 10 +++--- .../calendar/activities/SettingsActivity.kt | 33 ++++++++----------- .../calendar/activities/SimpleActivity.kt | 21 +++--------- 5 files changed, 26 insertions(+), 44 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/AboutActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/AboutActivity.kt index d344ece90..68c55dae0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/AboutActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/AboutActivity.kt @@ -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 { diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt index b8955b970..3f0a78cce 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt @@ -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) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt index 8bfe3c937..64efae90e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt @@ -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) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt index e5c22150d..8e97ac840 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt @@ -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(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() - } } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SimpleActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SimpleActivity.kt index a7e84170d..f1a5fb0e2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SimpleActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SimpleActivity.kt @@ -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) } }