convert settings to kotlin

This commit is contained in:
tibbi 2016-11-01 21:46:45 +01:00
parent 964c1ed7d1
commit df0fcfcf4f
2 changed files with 46 additions and 63 deletions

View File

@ -1,63 +0,0 @@
package com.simplemobiletools.calendar.activities;
import android.os.Bundle;
import android.support.v4.app.TaskStackBuilder;
import android.support.v7.widget.SwitchCompat;
import com.simplemobiletools.calendar.R;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class SettingsActivity extends SimpleActivity {
@BindView(R.id.settings_dark_theme) SwitchCompat mDarkThemeSwitch;
@BindView(R.id.settings_sunday_first) SwitchCompat mSundayFirstSwitch;
@BindView(R.id.settings_week_numbers) SwitchCompat mWeekNumbersSwitch;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
ButterKnife.bind(this);
setupDarkTheme();
setupSundayFirst();
setupWeekNumbers();
}
private void setupDarkTheme() {
mDarkThemeSwitch.setChecked(mConfig.getIsDarkTheme());
}
private void setupSundayFirst() {
mSundayFirstSwitch.setChecked(mConfig.getIsSundayFirst());
}
private void setupWeekNumbers() {
mWeekNumbersSwitch.setChecked(mConfig.getDisplayWeekNumbers());
}
@OnClick(R.id.settings_dark_theme_holder)
public void handleDarkTheme() {
mDarkThemeSwitch.setChecked(!mDarkThemeSwitch.isChecked());
mConfig.setIsDarkTheme(mDarkThemeSwitch.isChecked());
restartActivity();
}
@OnClick(R.id.settings_sunday_first_holder)
public void handleSundayFirst() {
mSundayFirstSwitch.setChecked(!mSundayFirstSwitch.isChecked());
mConfig.setIsSundayFirst(mSundayFirstSwitch.isChecked());
}
@OnClick(R.id.settings_week_numbers_holder)
public void handleWeekNumbers() {
mWeekNumbersSwitch.setChecked(!mWeekNumbersSwitch.isChecked());
mConfig.setDisplayWeekNumbers(mWeekNumbersSwitch.isChecked());
}
private void restartActivity() {
TaskStackBuilder.create(getApplicationContext()).addNextIntentWithParentStack(getIntent()).startActivities();
}
}

View File

@ -0,0 +1,46 @@
package com.simplemobiletools.calendar.activities
import android.os.Bundle
import android.support.v4.app.TaskStackBuilder
import com.simplemobiletools.calendar.R
import kotlinx.android.synthetic.main.activity_settings.*
class SettingsActivity : SimpleActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_settings)
setupDarkTheme()
setupSundayFirst()
setupWeekNumbers()
}
private fun setupDarkTheme() {
settings_dark_theme.isChecked = mConfig.isDarkTheme
settings_dark_theme_holder.setOnClickListener {
settings_dark_theme.toggle()
mConfig.isDarkTheme = settings_dark_theme.isChecked
restartActivity()
}
}
private fun setupSundayFirst() {
settings_sunday_first.isChecked = mConfig.isSundayFirst
settings_sunday_first_holder.setOnClickListener {
settings_sunday_first.toggle()
mConfig.isSundayFirst = settings_sunday_first.isChecked
}
}
private fun setupWeekNumbers() {
settings_week_numbers!!.isChecked = mConfig.displayWeekNumbers
settings_week_numbers_holder.setOnClickListener {
settings_week_numbers.toggle()
mConfig.displayWeekNumbers = settings_week_numbers.isChecked
}
}
private fun restartActivity() {
TaskStackBuilder.create(applicationContext).addNextIntentWithParentStack(intent).startActivities()
}
}