convert SettingsActivity to kotlin
This commit is contained in:
parent
ae0c9be18d
commit
70c07f9688
|
@ -1,5 +1,7 @@
|
|||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'android-apt'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'kotlin-android-extensions'
|
||||
|
||||
android {
|
||||
compileSdkVersion 23
|
||||
|
|
|
@ -1,124 +0,0 @@
|
|||
package com.simplemobiletools.camera.activities;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.TaskStackBuilder;
|
||||
import android.support.v7.widget.AppCompatSpinner;
|
||||
import android.support.v7.widget.SwitchCompat;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import com.simplemobiletools.camera.Config;
|
||||
import com.simplemobiletools.camera.R;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
import butterknife.OnItemSelected;
|
||||
|
||||
public class SettingsActivity extends SimpleActivity {
|
||||
@BindView(R.id.settings_dark_theme) SwitchCompat mDarkThemeSwitch;
|
||||
@BindView(R.id.settings_use_dcim) SwitchCompat mUseDCIMSwitch;
|
||||
@BindView(R.id.settings_sound) SwitchCompat mSoundSwitch;
|
||||
@BindView(R.id.settings_force_ratio) SwitchCompat mForceRatioSwitch;
|
||||
@BindView(R.id.settings_max_photo_resolution) AppCompatSpinner mMaxPhotoResolutionSpinner;
|
||||
@BindView(R.id.settings_max_video_resolution) AppCompatSpinner mMaxVideoResolutionSpinner;
|
||||
|
||||
private static Config mConfig;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_settings);
|
||||
mConfig = Config.newInstance(getApplicationContext());
|
||||
ButterKnife.bind(this);
|
||||
|
||||
setupDarkTheme();
|
||||
setupUseDCIM();
|
||||
setupSound();
|
||||
setupForceRatio();
|
||||
setupMaxPhotoResolution();
|
||||
setupMaxVideoResolution();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.menu, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.about:
|
||||
final Intent intent = new Intent(getApplicationContext(), AboutActivity.class);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void setupDarkTheme() {
|
||||
mDarkThemeSwitch.setChecked(mConfig.getIsDarkTheme());
|
||||
}
|
||||
|
||||
private void setupUseDCIM() {
|
||||
mUseDCIMSwitch.setChecked(mConfig.getUseDCIMFolder());
|
||||
}
|
||||
|
||||
private void setupSound() {
|
||||
mSoundSwitch.setChecked(mConfig.getIsSoundEnabled());
|
||||
}
|
||||
|
||||
private void setupForceRatio() {
|
||||
mForceRatioSwitch.setChecked(mConfig.getForceRatioEnabled());
|
||||
}
|
||||
|
||||
private void setupMaxPhotoResolution() {
|
||||
mMaxPhotoResolutionSpinner.setSelection(mConfig.getMaxPhotoResolution());
|
||||
}
|
||||
|
||||
private void setupMaxVideoResolution() {
|
||||
mMaxVideoResolutionSpinner.setSelection(mConfig.getMaxVideoResolution());
|
||||
}
|
||||
|
||||
@OnClick(R.id.settings_dark_theme_holder)
|
||||
public void handleDarkTheme() {
|
||||
mDarkThemeSwitch.setChecked(!mDarkThemeSwitch.isChecked());
|
||||
mConfig.setIsDarkTheme(mDarkThemeSwitch.isChecked());
|
||||
restartActivity();
|
||||
}
|
||||
|
||||
@OnClick(R.id.settings_use_dcim_holder)
|
||||
public void handleUseDCIM() {
|
||||
mUseDCIMSwitch.setChecked(!mUseDCIMSwitch.isChecked());
|
||||
mConfig.setUseDCIMFolder(mUseDCIMSwitch.isChecked());
|
||||
}
|
||||
|
||||
@OnClick(R.id.settings_sound_holder)
|
||||
public void handleSound() {
|
||||
mSoundSwitch.setChecked(!mSoundSwitch.isChecked());
|
||||
mConfig.setIsSoundEnabled(mSoundSwitch.isChecked());
|
||||
}
|
||||
|
||||
@OnClick(R.id.settings_force_ratio_holder)
|
||||
public void handleForceRatio() {
|
||||
mForceRatioSwitch.setChecked(!mForceRatioSwitch.isChecked());
|
||||
mConfig.setForceRatioEnabled(mForceRatioSwitch.isChecked());
|
||||
}
|
||||
|
||||
@OnItemSelected(R.id.settings_max_photo_resolution)
|
||||
public void handleMaxPhotoResolution() {
|
||||
mConfig.setMaxPhotoResolution(mMaxPhotoResolutionSpinner.getSelectedItemPosition());
|
||||
}
|
||||
|
||||
@OnItemSelected(R.id.settings_max_video_resolution)
|
||||
public void handleMaxVideoResolution() {
|
||||
mConfig.setMaxVideoResolution(mMaxVideoResolutionSpinner.getSelectedItemPosition());
|
||||
}
|
||||
|
||||
private void restartActivity() {
|
||||
TaskStackBuilder.create(getApplicationContext()).addNextIntentWithParentStack(getIntent()).startActivities();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,101 @@
|
|||
package com.simplemobiletools.camera.activities
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.support.v4.app.TaskStackBuilder
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.widget.AdapterView
|
||||
import com.simplemobiletools.camera.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()
|
||||
setupUseDCIM()
|
||||
setupSound()
|
||||
setupForceRatio()
|
||||
setupMaxPhotoResolution()
|
||||
setupMaxVideoResolution()
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
menuInflater.inflate(R.menu.menu, menu)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
return when (item.itemId) {
|
||||
R.id.about -> {
|
||||
startActivity(Intent(applicationContext, AboutActivity::class.java))
|
||||
true
|
||||
}
|
||||
else -> super.onOptionsItemSelected(item)
|
||||
}
|
||||
}
|
||||
|
||||
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 setupUseDCIM() {
|
||||
settings_use_dcim.isChecked = mConfig.useDCIMFolder
|
||||
settings_use_dcim_holder.setOnClickListener {
|
||||
settings_use_dcim.toggle()
|
||||
mConfig.useDCIMFolder = settings_use_dcim.isChecked
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupSound() {
|
||||
settings_sound.isChecked = mConfig.isSoundEnabled
|
||||
settings_sound_holder.setOnClickListener {
|
||||
settings_sound.toggle()
|
||||
mConfig.isSoundEnabled = settings_sound.isChecked
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupForceRatio() {
|
||||
settings_force_ratio.isChecked = mConfig.forceRatioEnabled
|
||||
settings_force_ratio_holder.setOnClickListener {
|
||||
settings_force_ratio.toggle()
|
||||
mConfig.forceRatioEnabled = settings_force_ratio.isChecked
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupMaxPhotoResolution() {
|
||||
settings_max_photo_resolution.setSelection(mConfig.maxPhotoResolution)
|
||||
settings_max_photo_resolution.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
||||
override fun onNothingSelected(parent: AdapterView<*>?) {
|
||||
}
|
||||
|
||||
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
|
||||
mConfig.maxPhotoResolution = settings_max_photo_resolution.selectedItemPosition
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupMaxVideoResolution() {
|
||||
settings_max_video_resolution.setSelection(mConfig.maxVideoResolution)
|
||||
settings_max_video_resolution.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
||||
override fun onNothingSelected(parent: AdapterView<*>?) {
|
||||
}
|
||||
|
||||
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
|
||||
mConfig.maxVideoResolution = settings_max_video_resolution.selectedItemPosition
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun restartActivity() {
|
||||
TaskStackBuilder.create(applicationContext).addNextIntentWithParentStack(intent).startActivities()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue