converting Constants to kotlin

This commit is contained in:
tibbi 2016-11-17 20:05:31 +01:00
parent 206dfe0271
commit eee184c51a
22 changed files with 187 additions and 192 deletions

View File

@ -1,40 +0,0 @@
package com.simplemobiletools.calendar;
public class Constants {
public static final float LOW_ALPHA = .2f;
public static final float MEDIUM_ALPHA = .6f;
public static final float HIGH_ALPHA = .8f;
public static final String DAY_CODE = "day_code";
public static final String YEAR_LABEL = "year";
public static final String EVENT_ID = "event_id";
public static final int MONTHLY_VIEW = 1;
public static final int YEARLY_VIEW = 2;
public static final int EVENTS_LIST_VIEW = 3;
public static final int REMINDER_OFF = -1;
public static final int REMINDER_AT_START = 0;
public static final int REMINDER_CUSTOM = 1;
public static final int DAY = 86400;
public static final int WEEK = 604800;
public static final int BIWEEK = 1209600;
public static final int MONTH = 2592000; // exact value not taken into account, Joda is used for adding months and years
public static final int YEAR = 31536000;
public static final int HOUR_MINS = 60;
public static final int DAY_MINS = 1440;
// Shared Preferences
public static final String PREFS_KEY = "Calendar";
public static final String IS_FIRST_RUN = "is_first_run";
public static final String IS_DARK_THEME = "is_dark_theme";
public static final String SUNDAY_FIRST = "sunday_first";
public static final String WEEK_NUMBERS = "week_numbers";
public static final String VIEW = "view";
public static final String REMINDER_TYPE = "reminder_type";
public static final String REMINDER_MINUTES = "reminder_minutes";
public static final String WIDGET_BG_COLOR = "widget_bg_color";
public static final String WIDGET_TEXT_COLOR = "widget_text_color";
}

View File

@ -6,10 +6,10 @@ import android.os.Bundle
import android.support.design.widget.Snackbar
import android.support.v4.view.ViewPager
import android.view.View
import com.simplemobiletools.calendar.Constants
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.adapters.MyDayPagerAdapter
import com.simplemobiletools.calendar.fragments.DayFragment
import com.simplemobiletools.calendar.helpers.DAY_CODE
import com.simplemobiletools.calendar.helpers.Formatter
import kotlinx.android.synthetic.main.activity_day.*
import org.joda.time.DateTime
@ -17,7 +17,7 @@ import java.util.*
class DayActivity : SimpleActivity(), DayFragment.DeleteListener, ViewPager.OnPageChangeListener {
private val PREFILLED_DAYS = 121
private var mDayCode: String? = null
private var mDayCode = ""
private var mSnackbar: Snackbar? = null
private var mPagerDays: MutableList<String>? = null
private var mPagerPos = 0
@ -27,11 +27,11 @@ class DayActivity : SimpleActivity(), DayFragment.DeleteListener, ViewPager.OnPa
setContentView(R.layout.activity_day)
val intent = intent ?: return
mDayCode = intent.getStringExtra(Constants.DAY_CODE)
if (mDayCode == null || mDayCode!!.isEmpty())
mDayCode = intent.getStringExtra(DAY_CODE)
if (mDayCode.isEmpty())
return
fillViewPager(mDayCode!!)
fillViewPager(mDayCode)
day_fab.setOnClickListener { addNewEvent() }
}
@ -53,9 +53,10 @@ class DayActivity : SimpleActivity(), DayFragment.DeleteListener, ViewPager.OnPa
}
private fun addNewEvent() {
val eventIntent = Intent(applicationContext, EventActivity::class.java)
eventIntent.putExtra(Constants.DAY_CODE, mPagerDays?.get(view_pager.currentItem))
startActivity(eventIntent)
Intent(applicationContext, EventActivity::class.java).apply {
putExtra(DAY_CODE, mPagerDays?.get(view_pager.currentItem))
startActivity(this)
}
}
private fun getDays(code: String) {

View File

@ -9,12 +9,10 @@ import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.widget.AdapterView
import com.simplemobiletools.calendar.Constants
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.extensions.*
import com.simplemobiletools.calendar.fragments.DayFragment
import com.simplemobiletools.calendar.helpers.DBHelper
import com.simplemobiletools.calendar.helpers.Formatter
import com.simplemobiletools.calendar.helpers.*
import com.simplemobiletools.calendar.models.Event
import kotlinx.android.synthetic.main.activity_event.*
import org.joda.time.DateTime
@ -36,7 +34,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventsListener {
val intent = intent ?: return
mWasReminderInit = false
val eventId = intent.getIntExtra(Constants.EVENT_ID, 0)
val eventId = intent.getIntExtra(EVENT_ID, 0)
val event = DBHelper(applicationContext).getEvent(eventId)
if (event != null) {
mEvent = event
@ -44,7 +42,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventsListener {
setupReminder()
} else {
mEvent = Event()
val dayCode = intent.getStringExtra(Constants.DAY_CODE)
val dayCode = intent.getStringExtra(DAY_CODE)
if (dayCode == null || dayCode.isEmpty())
return
@ -99,10 +97,10 @@ class EventActivity : SimpleActivity(), DBHelper.EventsListener {
private fun setupDefaultReminderType() {
val type = mConfig.defaultReminderType
toggleCustomReminderVisibility(type == Constants.REMINDER_CUSTOM)
if (type == Constants.REMINDER_OFF) {
toggleCustomReminderVisibility(type == REMINDER_CUSTOM)
if (type == REMINDER_OFF) {
event_reminder.setSelection(0)
} else if (type == Constants.REMINDER_AT_START) {
} else if (type == REMINDER_AT_START) {
event_reminder.setSelection(1)
} else {
event_reminder.setSelection(2)
@ -115,11 +113,11 @@ class EventActivity : SimpleActivity(), DBHelper.EventsListener {
var value = mins
if (mins == 0) {
custom_reminder_other_period.setSelection(0)
} else if (mins % Constants.DAY_MINS == 0) {
value = mins / Constants.DAY_MINS
} else if (mins % DAY_MINS == 0) {
value = mins / DAY_MINS
custom_reminder_other_period.setSelection(2)
} else if (mins % Constants.HOUR_MINS == 0) {
value = mins / Constants.HOUR_MINS
} else if (mins % HOUR_MINS == 0) {
value = mins / HOUR_MINS
custom_reminder_other_period.setSelection(1)
} else {
custom_reminder_other_period.setSelection(0)
@ -129,8 +127,8 @@ class EventActivity : SimpleActivity(), DBHelper.EventsListener {
private fun setupReminder() {
when (mEvent.reminderMinutes) {
Constants.REMINDER_OFF -> event_reminder.setSelection(0)
Constants.REMINDER_AT_START -> event_reminder.setSelection(1)
REMINDER_OFF -> event_reminder.setSelection(0)
REMINDER_AT_START -> event_reminder.setSelection(1)
else -> {
event_reminder.setSelection(2)
toggleCustomReminderVisibility(true)
@ -141,11 +139,11 @@ class EventActivity : SimpleActivity(), DBHelper.EventsListener {
private fun setupRepetition() {
when (mEvent.repeatInterval) {
Constants.DAY -> event_repetition.setSelection(1)
Constants.WEEK -> event_repetition.setSelection(2)
Constants.BIWEEK -> event_repetition.setSelection(3)
Constants.MONTH -> event_repetition.setSelection(4)
Constants.YEAR -> event_repetition.setSelection(5)
DAY -> event_repetition.setSelection(1)
WEEK -> event_repetition.setSelection(2)
BIWEEK -> event_repetition.setSelection(3)
MONTH -> event_repetition.setSelection(4)
YEAR -> event_repetition.setSelection(5)
else -> event_repetition.setSelection(0)
}
}
@ -178,11 +176,11 @@ class EventActivity : SimpleActivity(), DBHelper.EventsListener {
private fun setupReminderPeriod() {
val mins = mEvent.reminderMinutes
var value = mins
if (mins % Constants.DAY_MINS == 0) {
value = mins / Constants.DAY_MINS
if (mins % DAY_MINS == 0) {
value = mins / DAY_MINS
custom_reminder_other_period.setSelection(2)
} else if (mins % Constants.HOUR_MINS == 0) {
value = mins / Constants.HOUR_MINS
} else if (mins % HOUR_MINS == 0) {
value = mins / HOUR_MINS
custom_reminder_other_period.setSelection(1)
} else {
custom_reminder_other_period.setSelection(0)
@ -266,8 +264,8 @@ class EventActivity : SimpleActivity(), DBHelper.EventsListener {
else -> {
val value = custom_reminder_value.value
val multiplier = when (custom_reminder_other_period.selectedItemPosition) {
1 -> Constants.HOUR_MINS
2 -> Constants.DAY_MINS
1 -> HOUR_MINS
2 -> DAY_MINS
else -> 1
}
Integer.valueOf(value) * multiplier
@ -277,11 +275,11 @@ class EventActivity : SimpleActivity(), DBHelper.EventsListener {
private fun getRepeatInterval(): Int {
return when (event_repetition.selectedItemPosition) {
1 -> Constants.DAY
2 -> Constants.WEEK
3 -> Constants.BIWEEK
4 -> Constants.MONTH
5 -> Constants.YEAR
1 -> DAY
2 -> WEEK
3 -> BIWEEK
4 -> MONTH
5 -> YEAR
else -> 0
}
}

View File

@ -8,14 +8,14 @@ import android.support.v4.view.ViewPager
import android.view.Menu
import android.view.MenuItem
import android.view.View
import com.simplemobiletools.calendar.Constants
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.adapters.MyMonthPagerAdapter
import com.simplemobiletools.calendar.adapters.MyYearPagerAdapter
import com.simplemobiletools.calendar.dialogs.ChangeViewDialog
import com.simplemobiletools.calendar.extensions.updateWidget
import com.simplemobiletools.calendar.fragments.EventListFragment
import com.simplemobiletools.calendar.helpers.*
import com.simplemobiletools.calendar.helpers.Formatter
import com.simplemobiletools.calendar.dialogs.ChangeViewDialog
import kotlinx.android.synthetic.main.activity_main.*
import org.joda.time.DateTime
import org.joda.time.DateTimeZone
@ -76,8 +76,8 @@ class MainActivity : SimpleActivity(), EventListFragment.DeleteListener, ChangeV
}
override fun onBackPressed() {
if (mIsMonthSelected && mConfig.storedView == Constants.YEARLY_VIEW) {
updateView(Constants.YEARLY_VIEW)
if (mIsMonthSelected && mConfig.storedView == YEARLY_VIEW) {
updateView(YEARLY_VIEW)
} else {
super.onBackPressed()
}
@ -92,15 +92,15 @@ class MainActivity : SimpleActivity(), EventListFragment.DeleteListener, ChangeV
}
private fun updateView(view: Int) {
mIsMonthSelected = view == Constants.MONTHLY_VIEW
mIsMonthSelected = view == MONTHLY_VIEW
mConfig.storedView = view
updateViewPager()
}
private fun updateViewPager() {
if (mConfig.storedView == Constants.YEARLY_VIEW) {
if (mConfig.storedView == YEARLY_VIEW) {
fillYearlyViewPager()
} else if (mConfig.storedView == Constants.EVENTS_LIST_VIEW) {
} else if (mConfig.storedView == EVENTS_LIST_VIEW) {
fillEventsList()
} else {
val targetDay = DateTime().toString(Formatter.DAYCODE_PATTERN)
@ -109,10 +109,11 @@ class MainActivity : SimpleActivity(), EventListFragment.DeleteListener, ChangeV
}
private fun addNewEvent() {
val intent = Intent(applicationContext, EventActivity::class.java)
val tomorrowCode = Formatter.getDayCodeFromDateTime(DateTime(DateTimeZone.getDefault()).plusDays(1))
intent.putExtra(Constants.DAY_CODE, tomorrowCode)
startActivity(intent)
Intent(applicationContext, EventActivity::class.java).apply {
putExtra(DAY_CODE, tomorrowCode)
startActivity(this)
}
}
private fun fillMonthlyViewPager(targetDay: String) {

View File

@ -4,7 +4,7 @@ import android.os.Bundle
import android.support.v4.app.TaskStackBuilder
import android.view.View
import android.widget.AdapterView
import com.simplemobiletools.calendar.Constants
import com.simplemobiletools.calendar.helpers.Constants
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.extensions.*
import kotlinx.android.synthetic.main.activity_settings.*

View File

@ -12,12 +12,9 @@ import android.support.v7.app.AppCompatActivity
import android.view.View
import android.widget.SeekBar
import android.widget.TextView
import com.simplemobiletools.calendar.Constants
import com.simplemobiletools.calendar.MonthlyCalendarImpl
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.helpers.Config
import com.simplemobiletools.calendar.helpers.MyWidgetProvider
import com.simplemobiletools.calendar.helpers.Utils
import com.simplemobiletools.calendar.helpers.*
import com.simplemobiletools.calendar.interfaces.MonthlyCalendar
import com.simplemobiletools.calendar.models.Day
import kotlinx.android.synthetic.main.first_row.*
@ -69,10 +66,10 @@ class WidgetConfigureActivity : AppCompatActivity(), MonthlyCalendar {
mTodayTextSize /= mRes.displayMetrics.density
val prefs = initPrefs(this)
mTextColorWithoutTransparency = prefs.getInt(Constants.WIDGET_TEXT_COLOR, resources.getColor(R.color.colorPrimary))
mTextColorWithoutTransparency = prefs.getInt(WIDGET_TEXT_COLOR, resources.getColor(R.color.colorPrimary))
updateTextColors()
mBgColor = prefs.getInt(Constants.WIDGET_BG_COLOR, 1)
mBgColor = prefs.getInt(WIDGET_BG_COLOR, 1)
if (mBgColor == 1) {
mBgColor = Color.BLACK
mBgAlpha = .2f
@ -88,7 +85,7 @@ class WidgetConfigureActivity : AppCompatActivity(), MonthlyCalendar {
MonthlyCalendarImpl(this, applicationContext).updateMonthlyCalendar(DateTime())
}
private fun initPrefs(context: Context) = context.getSharedPreferences(Constants.PREFS_KEY, Context.MODE_PRIVATE)
private fun initPrefs(context: Context) = context.getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE)
fun saveConfig() {
storeWidgetColors()
@ -102,8 +99,8 @@ class WidgetConfigureActivity : AppCompatActivity(), MonthlyCalendar {
}
private fun storeWidgetColors() {
getSharedPreferences(Constants.PREFS_KEY, Context.MODE_PRIVATE).apply {
edit().putInt(Constants.WIDGET_BG_COLOR, mBgColor).putInt(Constants.WIDGET_TEXT_COLOR, mTextColorWithoutTransparency).apply()
getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE).apply {
edit().putInt(WIDGET_BG_COLOR, mBgColor).putInt(WIDGET_TEXT_COLOR, mTextColorWithoutTransparency).apply()
}
}
@ -137,14 +134,15 @@ class WidgetConfigureActivity : AppCompatActivity(), MonthlyCalendar {
}
private fun requestWidgetUpdate() {
val intent = Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE, null, this, MyWidgetProvider::class.java)
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, intArrayOf(mWidgetId))
sendBroadcast(intent)
Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE, null, this, MyWidgetProvider::class.java).apply {
putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, intArrayOf(mWidgetId))
sendBroadcast(this)
}
}
private fun updateTextColors() {
mTextColor = Utils.adjustAlpha(mTextColorWithoutTransparency, Constants.HIGH_ALPHA)
mWeakTextColor = Utils.adjustAlpha(mTextColorWithoutTransparency, Constants.LOW_ALPHA)
mTextColor = Utils.adjustAlpha(mTextColorWithoutTransparency, HIGH_ALPHA)
mWeakTextColor = Utils.adjustAlpha(mTextColorWithoutTransparency, LOW_ALPHA)
top_left_arrow.drawable.mutate().setColorFilter(mTextColor, PorterDuff.Mode.SRC_ATOP)
top_right_arrow.drawable.mutate().setColorFilter(mTextColor, PorterDuff.Mode.SRC_ATOP)

View File

@ -5,7 +5,7 @@ import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.support.v4.app.FragmentStatePagerAdapter
import android.util.SparseArray
import com.simplemobiletools.calendar.Constants
import com.simplemobiletools.calendar.helpers.Constants
import com.simplemobiletools.calendar.fragments.DayFragment
class MyDayPagerAdapter(fm: FragmentManager, private val mCodes: List<String>, private val mListener: DayFragment.DeleteListener) :

View File

@ -5,7 +5,7 @@ import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.support.v4.app.FragmentStatePagerAdapter
import com.simplemobiletools.calendar.Constants
import com.simplemobiletools.calendar.helpers.Constants
import com.simplemobiletools.calendar.interfaces.NavigationListener
import com.simplemobiletools.calendar.fragments.MonthFragment

View File

@ -4,7 +4,7 @@ import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.support.v4.app.FragmentStatePagerAdapter
import com.simplemobiletools.calendar.Constants
import com.simplemobiletools.calendar.helpers.Constants
import com.simplemobiletools.calendar.fragments.YearFragment
import com.simplemobiletools.calendar.interfaces.NavigationListener

View File

@ -3,9 +3,11 @@ package com.simplemobiletools.calendar.dialogs
import android.app.Activity
import android.app.AlertDialog
import android.widget.RadioGroup
import com.simplemobiletools.calendar.Constants
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.helpers.Config
import com.simplemobiletools.calendar.helpers.EVENTS_LIST_VIEW
import com.simplemobiletools.calendar.helpers.MONTHLY_VIEW
import com.simplemobiletools.calendar.helpers.YEARLY_VIEW
import kotlinx.android.synthetic.main.dialog_change_views.view.*
class ChangeViewDialog(val activity: Activity) : AlertDialog.Builder(activity), RadioGroup.OnCheckedChangeListener {
@ -30,14 +32,14 @@ class ChangeViewDialog(val activity: Activity) : AlertDialog.Builder(activity),
}
fun getNewView(id: Int) = when (id) {
R.id.dialog_radio_yearly -> Constants.YEARLY_VIEW
R.id.dialog_radio_events_list -> Constants.EVENTS_LIST_VIEW
else -> Constants.MONTHLY_VIEW
R.id.dialog_radio_yearly -> YEARLY_VIEW
R.id.dialog_radio_events_list -> EVENTS_LIST_VIEW
else -> MONTHLY_VIEW
}
fun getSavedItem() = when (Config.newInstance(activity).storedView) {
Constants.YEARLY_VIEW -> R.id.dialog_radio_yearly
Constants.EVENTS_LIST_VIEW -> R.id.dialog_radio_events_list
YEARLY_VIEW -> R.id.dialog_radio_yearly
EVENTS_LIST_VIEW -> R.id.dialog_radio_events_list
else -> R.id.dialog_radio_monthly
}

View File

@ -8,10 +8,8 @@ import android.content.Context
import android.content.Intent
import android.os.SystemClock
import android.widget.Toast
import com.simplemobiletools.calendar.Constants
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.helpers.Formatter
import com.simplemobiletools.calendar.helpers.MyWidgetProvider
import com.simplemobiletools.calendar.helpers.*
import com.simplemobiletools.calendar.models.Event
import com.simplemobiletools.calendar.receivers.NotificationReceiver
@ -20,11 +18,12 @@ fun Context.updateWidget() {
if (widgetsCnt.isEmpty())
return
val intent = Intent(this, MyWidgetProvider::class.java)
intent.action = AppWidgetManager.ACTION_APPWIDGET_UPDATE
val ids = intArrayOf(R.xml.widget_info)
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids)
sendBroadcast(intent)
Intent(this, MyWidgetProvider::class.java).apply {
action = AppWidgetManager.ACTION_APPWIDGET_UPDATE
putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids)
sendBroadcast(this)
}
}
fun Context.toast(id: Int) = Toast.makeText(this, resources.getString(id), Toast.LENGTH_SHORT).show()
@ -32,14 +31,14 @@ fun Context.toast(id: Int) = Toast.makeText(this, resources.getString(id), Toast
fun Context.scheduleNextEvent(event: Event) {
var startTS = event.startTS - event.reminderMinutes * 60
var newTS = startTS
if (event.repeatInterval == Constants.DAY || event.repeatInterval == Constants.WEEK || event.repeatInterval == Constants.BIWEEK) {
if (event.repeatInterval == DAY || event.repeatInterval == WEEK || event.repeatInterval == BIWEEK) {
while (startTS < System.currentTimeMillis() / 1000 + 5) {
startTS += event.repeatInterval
}
newTS = startTS
} else if (event.repeatInterval == Constants.MONTH) {
} else if (event.repeatInterval == MONTH) {
newTS = getNewTS(startTS, true)
} else if (event.repeatInterval == Constants.YEAR) {
} else if (event.repeatInterval == YEAR) {
newTS = getNewTS(startTS, false)
}

View File

@ -13,15 +13,12 @@ import android.widget.AbsListView
import android.widget.AdapterView
import android.widget.DatePicker
import android.widget.RelativeLayout
import com.simplemobiletools.calendar.Constants
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.activities.EventActivity
import com.simplemobiletools.calendar.adapters.EventsAdapter
import com.simplemobiletools.calendar.extensions.updateWidget
import com.simplemobiletools.calendar.helpers.Config
import com.simplemobiletools.calendar.helpers.DBHelper
import com.simplemobiletools.calendar.helpers.*
import com.simplemobiletools.calendar.helpers.Formatter
import com.simplemobiletools.calendar.helpers.Utils
import com.simplemobiletools.calendar.interfaces.NavigationListener
import com.simplemobiletools.calendar.models.Event
import kotlinx.android.synthetic.main.day_fragment.view.*
@ -53,7 +50,7 @@ class DayFragment : Fragment(), DBHelper.EventsListener, AdapterView.OnItemClick
mHolder = view.day_holder
mConfig = Config.newInstance(context)
mDayCode = arguments.getString(Constants.DAY_CODE)
mDayCode = arguments.getString(DAY_CODE)
val day = Formatter.getDayTitle(activity.applicationContext, mDayCode)
mHolder.top_value.text = day
@ -71,7 +68,7 @@ class DayFragment : Fragment(), DBHelper.EventsListener, AdapterView.OnItemClick
private fun setupButtons() {
val baseColor = if (mConfig.isDarkTheme) Color.WHITE else Color.BLACK
mTextColor = Utils.adjustAlpha(baseColor, Constants.HIGH_ALPHA)
mTextColor = Utils.adjustAlpha(baseColor, HIGH_ALPHA)
mHolder.apply {
top_left_arrow.drawable.mutate().setColorFilter(mTextColor, PorterDuff.Mode.SRC_ATOP)
@ -138,9 +135,10 @@ class DayFragment : Fragment(), DBHelper.EventsListener, AdapterView.OnItemClick
}
private fun editEvent(eventId: Int) {
val intent = Intent(activity.applicationContext, EventActivity::class.java)
intent.putExtra(Constants.EVENT_ID, eventId)
startActivityForResult(intent, EDIT_EVENT)
Intent(activity.applicationContext, EventActivity::class.java).apply {
putExtra(EVENT_ID, eventId)
startActivityForResult(this, EDIT_EVENT)
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {

View File

@ -8,7 +8,6 @@ import android.support.v4.app.Fragment
import android.view.*
import android.widget.AbsListView
import android.widget.AdapterView
import com.simplemobiletools.calendar.Constants
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.activities.EventActivity
import com.simplemobiletools.calendar.activities.MainActivity
@ -17,6 +16,7 @@ import com.simplemobiletools.calendar.extensions.beGoneIf
import com.simplemobiletools.calendar.extensions.beVisibleIf
import com.simplemobiletools.calendar.extensions.updateWidget
import com.simplemobiletools.calendar.helpers.DBHelper
import com.simplemobiletools.calendar.helpers.EVENT_ID
import com.simplemobiletools.calendar.helpers.Formatter
import com.simplemobiletools.calendar.interfaces.NavigationListener
import com.simplemobiletools.calendar.models.Event
@ -113,9 +113,10 @@ class EventListFragment : Fragment(), DBHelper.GetEventsListener, AdapterView.On
}
private fun editEvent(eventId: Int) {
val intent = Intent(activity.applicationContext, EventActivity::class.java)
intent.putExtra(Constants.EVENT_ID, eventId)
startActivityForResult(intent, EDIT_EVENT)
Intent(activity.applicationContext, EventActivity::class.java).apply {
putExtra(EVENT_ID, eventId)
startActivityForResult(this, EDIT_EVENT)
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {

View File

@ -11,12 +11,11 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.*
import com.simplemobiletools.calendar.*
import com.simplemobiletools.calendar.MonthlyCalendarImpl
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.activities.DayActivity
import com.simplemobiletools.calendar.extensions.beVisibleIf
import com.simplemobiletools.calendar.helpers.Config
import com.simplemobiletools.calendar.helpers.Formatter
import com.simplemobiletools.calendar.helpers.Utils
import com.simplemobiletools.calendar.helpers.*
import com.simplemobiletools.calendar.interfaces.MonthlyCalendar
import com.simplemobiletools.calendar.interfaces.NavigationListener
import com.simplemobiletools.calendar.models.Day
@ -48,7 +47,7 @@ class MonthFragment : Fragment(), MonthlyCalendar {
mRes = resources
mHolder = view.calendar_holder
mDayCode = arguments.getString(Constants.DAY_CODE)
mDayCode = arguments.getString(DAY_CODE)
mConfig = Config.newInstance(context)
mSundayFirst = mConfig.isSundayFirst
@ -93,10 +92,10 @@ class MonthFragment : Fragment(), MonthlyCalendar {
private fun setupButtons() {
val baseColor = if (mConfig.isDarkTheme) Color.WHITE else Color.BLACK
mTextColor = Utils.adjustAlpha(baseColor, Constants.HIGH_ALPHA)
mTextColorWithEvent = Utils.adjustAlpha(mRes.getColor(R.color.colorPrimary), Constants.HIGH_ALPHA)
mWeakTextColor = Utils.adjustAlpha(baseColor, Constants.LOW_ALPHA)
mWeakTextColorWithEvent = Utils.adjustAlpha(mRes.getColor(R.color.colorPrimary), Constants.LOW_ALPHA)
mTextColor = Utils.adjustAlpha(baseColor, HIGH_ALPHA)
mTextColorWithEvent = Utils.adjustAlpha(mRes.getColor(R.color.colorPrimary), HIGH_ALPHA)
mWeakTextColor = Utils.adjustAlpha(baseColor, LOW_ALPHA)
mWeakTextColorWithEvent = Utils.adjustAlpha(mRes.getColor(R.color.colorPrimary), LOW_ALPHA)
mHolder.apply {
top_left_arrow.drawable.mutate().setColorFilter(mTextColor, PorterDuff.Mode.SRC_ATOP)
@ -209,8 +208,9 @@ class MonthFragment : Fragment(), MonthlyCalendar {
if (code.isEmpty())
return
val intent = Intent(context, DayActivity::class.java)
intent.putExtra(Constants.DAY_CODE, code)
startActivity(intent)
Intent(context, DayActivity::class.java).apply {
putExtra(DAY_CODE, code)
startActivity(this)
}
}
}

View File

@ -8,9 +8,12 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.simplemobiletools.calendar.*
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.YearlyCalendarImpl
import com.simplemobiletools.calendar.helpers.Config
import com.simplemobiletools.calendar.helpers.HIGH_ALPHA
import com.simplemobiletools.calendar.helpers.Utils
import com.simplemobiletools.calendar.helpers.YEAR_LABEL
import com.simplemobiletools.calendar.interfaces.NavigationListener
import com.simplemobiletools.calendar.interfaces.YearlyCalendar
import com.simplemobiletools.calendar.views.SmallMonthView
@ -28,7 +31,7 @@ class YearFragment : Fragment(), YearlyCalendar {
override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
mView = inflater!!.inflate(R.layout.year_fragment, container, false)
mYear = arguments.getInt(Constants.YEAR_LABEL)
mYear = arguments.getInt(YEAR_LABEL)
setupMonths()
mCalendar = YearlyCalendarImpl(this, context, mYear)
@ -72,7 +75,7 @@ class YearFragment : Fragment(), YearlyCalendar {
val now = DateTime()
if (now.year == mYear) {
val monthLabel = mView.findViewById(res.getIdentifier("month_${now.monthOfYear}_label", "id", activity.packageName)) as TextView
monthLabel.setTextColor(Utils.adjustAlpha(res.getColor(R.color.colorPrimary), Constants.HIGH_ALPHA))
monthLabel.setTextColor(Utils.adjustAlpha(res.getColor(R.color.colorPrimary), HIGH_ALPHA))
val monthView = mView.findViewById(res.getIdentifier("month_${now.monthOfYear}", "id", activity.packageName)) as SmallMonthView
monthView.setTodaysId(now.dayOfMonth)

View File

@ -2,7 +2,6 @@ package com.simplemobiletools.calendar.helpers
import android.content.Context
import android.content.SharedPreferences
import com.simplemobiletools.calendar.Constants
import java.util.*
class Config(context: Context) {
@ -13,47 +12,47 @@ class Config(context: Context) {
}
init {
mPrefs = context.getSharedPreferences(Constants.PREFS_KEY, Context.MODE_PRIVATE)
mPrefs = context.getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE)
}
var isFirstRun: Boolean
get() = mPrefs.getBoolean(Constants.IS_FIRST_RUN, true)
set(firstRun) = mPrefs.edit().putBoolean(Constants.IS_FIRST_RUN, firstRun).apply()
get() = mPrefs.getBoolean(IS_FIRST_RUN, true)
set(firstRun) = mPrefs.edit().putBoolean(IS_FIRST_RUN, firstRun).apply()
var isDarkTheme: Boolean
get() = mPrefs.getBoolean(Constants.IS_DARK_THEME, false)
set(isDarkTheme) = mPrefs.edit().putBoolean(Constants.IS_DARK_THEME, isDarkTheme).apply()
get() = mPrefs.getBoolean(IS_DARK_THEME, false)
set(isDarkTheme) = mPrefs.edit().putBoolean(IS_DARK_THEME, isDarkTheme).apply()
var isSundayFirst: Boolean
get() {
val isSundayFirst = Calendar.getInstance(Locale.getDefault()).firstDayOfWeek == Calendar.SUNDAY
return mPrefs.getBoolean(Constants.SUNDAY_FIRST, isSundayFirst)
return mPrefs.getBoolean(SUNDAY_FIRST, isSundayFirst)
}
set(sundayFirst) = mPrefs.edit().putBoolean(Constants.SUNDAY_FIRST, sundayFirst).apply()
set(sundayFirst) = mPrefs.edit().putBoolean(SUNDAY_FIRST, sundayFirst).apply()
var displayWeekNumbers: Boolean
get() = mPrefs.getBoolean(Constants.WEEK_NUMBERS, false)
set(displayWeekNumbers) = mPrefs.edit().putBoolean(Constants.WEEK_NUMBERS, displayWeekNumbers).apply()
get() = mPrefs.getBoolean(WEEK_NUMBERS, false)
set(displayWeekNumbers) = mPrefs.edit().putBoolean(WEEK_NUMBERS, displayWeekNumbers).apply()
var storedView: Int
get() = mPrefs.getInt(Constants.VIEW, Constants.MONTHLY_VIEW)
set(view) = mPrefs.edit().putInt(Constants.VIEW, view).apply()
get() = mPrefs.getInt(VIEW, MONTHLY_VIEW)
set(view) = mPrefs.edit().putInt(VIEW, view).apply()
var defaultReminderType: Int
get() = mPrefs.getInt(Constants.REMINDER_TYPE, Constants.REMINDER_AT_START)
get() = mPrefs.getInt(REMINDER_TYPE, REMINDER_AT_START)
set(type) {
var newType = type
if (newType == Constants.REMINDER_CUSTOM && defaultReminderMinutes == 0)
newType = Constants.REMINDER_AT_START
if (newType == REMINDER_CUSTOM && defaultReminderMinutes == 0)
newType = REMINDER_AT_START
mPrefs.edit().putInt(Constants.REMINDER_TYPE, newType).apply()
mPrefs.edit().putInt(REMINDER_TYPE, newType).apply()
}
var defaultReminderMinutes: Int
get() = mPrefs.getInt(Constants.REMINDER_MINUTES, 10)
get() = mPrefs.getInt(REMINDER_MINUTES, 10)
set(mins) {
if (mins == 0)
defaultReminderType = Constants.REMINDER_AT_START
mPrefs.edit().putInt(Constants.REMINDER_MINUTES, mins).apply()
defaultReminderType = REMINDER_AT_START
mPrefs.edit().putInt(REMINDER_MINUTES, mins).apply()
}
}

View File

@ -0,0 +1,38 @@
package com.simplemobiletools.calendar.helpers
val LOW_ALPHA = .2f
val MEDIUM_ALPHA = .6f
val HIGH_ALPHA = .8f
val DAY_CODE = "day_code"
val YEAR_LABEL = "year"
val EVENT_ID = "event_id"
val MONTHLY_VIEW = 1
val YEARLY_VIEW = 2
val EVENTS_LIST_VIEW = 3
val REMINDER_OFF = -1
val REMINDER_AT_START = 0
val REMINDER_CUSTOM = 1
val DAY = 86400
val WEEK = 604800
val BIWEEK = 1209600
val MONTH = 2592000 // exact value not taken into account, Joda is used for adding months and years
val YEAR = 31536000
val HOUR_MINS = 60
val DAY_MINS = 1440
// Shared Preferences
val PREFS_KEY = "Calendar"
val IS_FIRST_RUN = "is_first_run"
val IS_DARK_THEME = "is_dark_theme"
val SUNDAY_FIRST = "sunday_first"
val WEEK_NUMBERS = "week_numbers"
val VIEW = "view"
val REMINDER_TYPE = "reminder_type"
val REMINDER_MINUTES = "reminder_minutes"
val WIDGET_BG_COLOR = "widget_bg_color"
val WIDGET_TEXT_COLOR = "widget_text_color"

View File

@ -7,7 +7,7 @@ import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper
import android.database.sqlite.SQLiteQueryBuilder
import android.text.TextUtils
import com.simplemobiletools.calendar.Constants
import com.simplemobiletools.calendar.helpers.Constants
import com.simplemobiletools.calendar.extensions.getIntValue
import com.simplemobiletools.calendar.extensions.getStringValue
import com.simplemobiletools.calendar.models.Event

View File

@ -13,10 +13,8 @@ import android.text.SpannableString
import android.text.style.UnderlineSpan
import android.view.View
import android.widget.RemoteViews
import com.simplemobiletools.calendar.Constants
import com.simplemobiletools.calendar.MonthlyCalendarImpl
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.helpers.Utils
import com.simplemobiletools.calendar.activities.DayActivity
import com.simplemobiletools.calendar.activities.MainActivity
import com.simplemobiletools.calendar.interfaces.MonthlyCalendar
@ -52,9 +50,9 @@ class MyWidgetProvider : AppWidgetProvider(), MonthlyCalendar {
mRes = mContext.resources
val prefs = initPrefs(context)
val storedTextColor = prefs.getInt(Constants.WIDGET_TEXT_COLOR, Color.WHITE)
mTextColor = Utils.adjustAlpha(storedTextColor, Constants.HIGH_ALPHA)
mWeakTextColor = Utils.adjustAlpha(storedTextColor, Constants.LOW_ALPHA)
val storedTextColor = prefs.getInt(WIDGET_TEXT_COLOR, Color.WHITE)
mTextColor = Utils.adjustAlpha(storedTextColor, HIGH_ALPHA)
mWeakTextColor = Utils.adjustAlpha(storedTextColor, LOW_ALPHA)
mDayTextSize = mRes.getDimension(R.dimen.day_text_size) / mRes.displayMetrics.density
mTodayTextSize = mRes.getDimension(R.dimen.today_text_size) / mRes.displayMetrics.density
@ -66,7 +64,7 @@ class MyWidgetProvider : AppWidgetProvider(), MonthlyCalendar {
updateLabelColor()
updateTopViews()
val bgColor = prefs.getInt(Constants.WIDGET_BG_COLOR, Color.BLACK)
val bgColor = prefs.getInt(WIDGET_BG_COLOR, Color.BLACK)
mRemoteViews.setInt(R.id.calendar_holder, "setBackgroundColor", bgColor)
mCalendar = MonthlyCalendarImpl(this, mContext)
@ -85,16 +83,18 @@ class MyWidgetProvider : AppWidgetProvider(), MonthlyCalendar {
}
private fun setupAppOpenIntent(id: Int) {
val intent = Intent(mContext, MainActivity::class.java)
val pendingIntent = PendingIntent.getActivity(mContext, 0, intent, 0)
mRemoteViews.setOnClickPendingIntent(id, pendingIntent)
Intent(mContext, MainActivity::class.java).apply {
val pendingIntent = PendingIntent.getActivity(mContext, 0, this, 0)
mRemoteViews.setOnClickPendingIntent(id, pendingIntent)
}
}
private fun setupDayOpenIntent(id: Int, dayCode: String) {
val intent = Intent(mContext, DayActivity::class.java)
intent.putExtra(Constants.DAY_CODE, dayCode)
val pendingIntent = PendingIntent.getActivity(mContext, Integer.parseInt(dayCode), intent, 0)
mRemoteViews.setOnClickPendingIntent(id, pendingIntent)
Intent(mContext, DayActivity::class.java).apply {
putExtra(DAY_CODE, dayCode)
val pendingIntent = PendingIntent.getActivity(mContext, Integer.parseInt(dayCode), this, 0)
mRemoteViews.setOnClickPendingIntent(id, pendingIntent)
}
}
private fun setupButtons() {
@ -103,9 +103,7 @@ class MyWidgetProvider : AppWidgetProvider(), MonthlyCalendar {
setupAppOpenIntent(R.id.top_value)
}
private fun initPrefs(context: Context): SharedPreferences {
return context.getSharedPreferences(Constants.PREFS_KEY, Context.MODE_PRIVATE)
}
private fun initPrefs(context: Context) = context.getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE)
override fun onReceive(context: Context, intent: Intent) {
val action = intent.action

View File

@ -1,6 +1,6 @@
package com.simplemobiletools.calendar.models
import com.simplemobiletools.calendar.Constants
import com.simplemobiletools.calendar.helpers.Constants
import com.simplemobiletools.calendar.helpers.Formatter
import org.joda.time.DateTime
import java.io.Serializable

View File

@ -7,7 +7,6 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.media.RingtoneManager
import com.simplemobiletools.calendar.Constants
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.activities.EventActivity
import com.simplemobiletools.calendar.extensions.scheduleNextEvent
@ -45,7 +44,7 @@ class NotificationReceiver : BroadcastReceiver() {
private fun getPendingIntent(context: Context, event: Event): PendingIntent {
val intent = Intent(context, EventActivity::class.java)
intent.putExtra(Constants.EVENT_ID, event)
intent.putExtra(EVENT_ID, event)
return PendingIntent.getActivity(context, event.id, intent, PendingIntent.FLAG_UPDATE_CURRENT)
}

View File

@ -6,9 +6,9 @@ import android.graphics.Color
import android.graphics.Paint
import android.util.AttributeSet
import android.view.View
import com.simplemobiletools.calendar.Constants
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.helpers.Config
import com.simplemobiletools.calendar.helpers.MEDIUM_ALPHA
import com.simplemobiletools.calendar.helpers.Utils
import java.util.*
@ -58,8 +58,8 @@ class SmallMonthView(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
}
val baseColor = if (Config.newInstance(context).isDarkTheme) Color.WHITE else Color.BLACK
mTextColor = Utils.adjustAlpha(baseColor, Constants.MEDIUM_ALPHA)
mColoredTextColor = Utils.adjustAlpha(resources.getColor(R.color.colorPrimary), Constants.MEDIUM_ALPHA)
mTextColor = Utils.adjustAlpha(baseColor, MEDIUM_ALPHA)
mColoredTextColor = Utils.adjustAlpha(resources.getColor(R.color.colorPrimary), MEDIUM_ALPHA)
mPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
color = mTextColor