convert Settings activity to kotlin

This commit is contained in:
tibbi 2017-04-08 18:32:20 +02:00
parent a76071ee5a
commit 5a628a7078
16 changed files with 77 additions and 128 deletions

View File

@ -31,6 +31,11 @@
android:label="@string/third_party_licences"
android:parentActivityName="com.simplemobiletools.commons.activities.AboutActivity"/>
<activity
android:name="com.simplemobiletools.commons.activities.CustomizationActivity"
android:label="@string/customize_colors"
android:parentActivityName=".activities.SettingsActivity"/>
<activity
android:name=".activities.SettingsActivity"
android:label="@string/settings"

View File

@ -23,20 +23,16 @@ public class Config {
mPrefs.edit().putBoolean(Constants.IS_FIRST_RUN, firstRun).apply();
}
public boolean getIsDarkTheme() {
return mPrefs.getBoolean(Constants.IS_DARK_THEME, false);
}
public void setIsDarkTheme(boolean isDarkTheme) {
mPrefs.edit().putBoolean(Constants.IS_DARK_THEME, isDarkTheme).apply();
}
public boolean getIsStrokeWidthBarEnabled() {
return mPrefs.getBoolean(Constants.IS_STROKE_WIDTH_BAR_ENABLED, false);
public boolean getShowBrushSizeEnabled() {
return mPrefs.getBoolean(Constants.SHOW_BRUSH_SIZE, false);
}
public void setIsStrokeWidthBarEnabled(boolean isStrokeWidthBarEnabled) {
mPrefs.edit().putBoolean(Constants.IS_STROKE_WIDTH_BAR_ENABLED, isStrokeWidthBarEnabled).apply();
public void setShowBrushSizeEnabled(boolean showBrushSize) {
mPrefs.edit().putBoolean(Constants.SHOW_BRUSH_SIZE, showBrushSize).apply();
}
public int getBrushColor() {

View File

@ -8,5 +8,5 @@ public class Constants {
public static final String BACKGROUND_COLOR_KEY = "background_color";
public static final String IS_FIRST_RUN = "is_first_run";
public static final String IS_DARK_THEME = "is_dark_theme";
public static final String IS_STROKE_WIDTH_BAR_ENABLED = "is_stroke_width_bar_enabled";
public static final String SHOW_BRUSH_SIZE = "show_brush_size";
}

View File

@ -70,10 +70,10 @@ public class MainActivity extends SimpleActivity implements MyCanvas.PathsChange
mMyCanvas.setListener(this);
mStrokeWidthBar.setOnSeekBarChangeListener(onStrokeWidthBarChangeListener);
setBackgroundColor(mConfig.getBackgroundColor());
setColor(mConfig.getBrushColor());
setBackgroundColor(Config.newInstance(this).getBackgroundColor());
setColor(Config.newInstance(this).getBrushColor());
strokeWidth = mConfig.getStrokeWidth();
strokeWidth = Config.newInstance(this).getStrokeWidth();
mMyCanvas.setStrokeWidth(strokeWidth);
mStrokeWidthBar.setProgress((int) strokeWidth);
}
@ -81,7 +81,7 @@ public class MainActivity extends SimpleActivity implements MyCanvas.PathsChange
@Override
protected void onResume() {
super.onResume();
boolean isStrokeWidthBarEnabled = mConfig.getIsStrokeWidthBarEnabled();
boolean isStrokeWidthBarEnabled = Config.newInstance(this).getShowBrushSizeEnabled();
mStrokeWidthBar.setVisibility(isStrokeWidthBarEnabled ? View.VISIBLE : View.GONE);
mMyCanvas.setIsStrokeWidthBarEnabled(isStrokeWidthBarEnabled);
}
@ -89,8 +89,8 @@ public class MainActivity extends SimpleActivity implements MyCanvas.PathsChange
@Override
protected void onPause() {
super.onPause();
mConfig.setBrushColor(color);
mConfig.setStrokeWidth(strokeWidth);
Config.newInstance(this).setBrushColor(color);
Config.newInstance(this).setStrokeWidth(strokeWidth);
}
@Override
@ -131,7 +131,7 @@ public class MainActivity extends SimpleActivity implements MyCanvas.PathsChange
@Override
public void onOk(AmbilWarnaDialog dialog, int pickedColor) {
setBackgroundColor(pickedColor);
mConfig.setBackgroundColor(pickedColor);
Config.newInstance(getApplicationContext()).setBackgroundColor(pickedColor);
}
});

View File

@ -1,51 +0,0 @@
package com.simplemobiletools.draw.activities;
import android.os.Bundle;
import android.support.v4.app.TaskStackBuilder;
import android.support.v7.widget.SwitchCompat;
import com.simplemobiletools.draw.Config;
import com.simplemobiletools.draw.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_brush_size) SwitchCompat mBrushSizeSwitch;
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);
setupSwitches();
}
private void setupSwitches() {
mDarkThemeSwitch.setChecked(mConfig.getIsDarkTheme());
mBrushSizeSwitch.setChecked(mConfig.getIsStrokeWidthBarEnabled());
}
@OnClick(R.id.settings_dark_theme_holder)
public void handleDarkTheme() {
mDarkThemeSwitch.setChecked(!mDarkThemeSwitch.isChecked());
mConfig.setIsDarkTheme(mDarkThemeSwitch.isChecked());
restartActivity();
}
@OnClick(R.id.settings_brush_size_holder)
public void handleBrushSize() {
mBrushSizeSwitch.setChecked(!mBrushSizeSwitch.isChecked());
mConfig.setIsStrokeWidthBarEnabled(mBrushSizeSwitch.isChecked());
}
private void restartActivity() {
TaskStackBuilder.create(getApplicationContext()).addNextIntentWithParentStack(getIntent()).startActivities();
}
}

View File

@ -1,31 +1,7 @@
package com.simplemobiletools.draw.activities;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
import com.simplemobiletools.commons.activities.BaseSimpleActivity;
import com.simplemobiletools.draw.Config;
import com.simplemobiletools.draw.R;
public class SimpleActivity extends BaseSimpleActivity {
public class SimpleActivity extends AppCompatActivity {
protected Config mConfig;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
mConfig = Config.newInstance(getApplicationContext());
setTheme(mConfig.getIsDarkTheme() ? R.style.AppTheme_Dark : R.style.AppTheme);
super.onCreate(savedInstanceState);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}

View File

@ -0,0 +1,36 @@
package com.simplemobiletools.draw.activities
import android.os.Bundle
import com.simplemobiletools.commons.extensions.updateTextColors
import com.simplemobiletools.draw.Config
import com.simplemobiletools.draw.R
import kotlinx.android.synthetic.main.activity_settings.*
class SettingsActivity : SimpleActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_settings)
}
override fun onResume() {
super.onResume()
setupCustomizeColors()
setupBrushSize()
updateTextColors(settings_holder)
}
private fun setupCustomizeColors() {
settings_customize_colors_holder.setOnClickListener {
startCustomizationActivity()
}
}
private fun setupBrushSize() {
settings_show_brush_size.isChecked = Config.newInstance(this).showBrushSizeEnabled
settings_show_brush_size_holder.setOnClickListener {
settings_show_brush_size.toggle()
Config.newInstance(this).showBrushSizeEnabled = settings_show_brush_size.isChecked
}
}
}

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:id="@+id/settings_scrollview"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/settings_scrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content">
@ -12,54 +12,41 @@
android:orientation="vertical">
<RelativeLayout
android:id="@+id/settings_dark_theme_holder"
android:id="@+id/settings_customize_colors_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/medium_margin"
android:background="?attr/selectableItemBackground"
android:padding="@dimen/activity_margin">
<TextView
android:id="@+id/settings_dark_theme_label"
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/settings_customize_colors"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:paddingLeft="@dimen/medium_margin"
android:text="@string/dark_theme"/>
<android.support.v7.widget.SwitchCompat
android:id="@+id/settings_dark_theme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="@null"
android:clickable="false"/>
android:paddingStart="@dimen/medium_margin"
android:text="@string/customize_colors"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/settings_brush_size_holder"
android:id="@+id/settings_show_brush_size_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/medium_margin"
android:background="?attr/selectableItemBackground"
android:padding="@dimen/activity_margin">
<TextView
android:id="@+id/settings_brush_size_label"
android:layout_width="wrap_content"
<com.simplemobiletools.commons.views.MySwitchCompat
android:id="@+id/settings_show_brush_size"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:paddingLeft="@dimen/medium_margin"
android:text="@string/brush_size"/>
<android.support.v7.widget.SwitchCompat
android:id="@+id/settings_brush_size"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="@null"
android:clickable="false"/>
android:clickable="false"
android:paddingLeft="@dimen/medium_margin"
android:paddingStart="@dimen/medium_margin"
android:text="@string/show_brush_size"/>
</RelativeLayout>
</LinearLayout>

View File

@ -15,7 +15,7 @@
<!-- Settings -->
<string name="dark_theme">Dunkles Design</string>
<string name="brush_size">Show brush size tool</string>
<string name="show_brush_size">Show brush size tool</string>
<string name="clear">Leeren</string>
<string name="change_background">Change background</string>

View File

@ -15,7 +15,7 @@
<!-- Settings -->
<string name="dark_theme">Tema oscuro</string>
<string name="brush_size">Show brush size tool</string>
<string name="show_brush_size">Show brush size tool</string>
<string name="clear">Limpiar</string>
<string name="change_background">Cambiar fondo</string>

View File

@ -15,7 +15,7 @@
<!-- Settings -->
<string name="dark_theme">Thème sombre</string>
<string name="brush_size">Show brush size tool</string>
<string name="show_brush_size">Show brush size tool</string>
<string name="clear">Tout effacer</string>
<string name="change_background">Changer le fond</string>

View File

@ -15,7 +15,7 @@
<!-- Settings -->
<string name="dark_theme">Tema scuro</string>
<string name="brush_size">Show brush size tool</string>
<string name="show_brush_size">Show brush size tool</string>
<string name="clear">Clear</string>
<string name="change_background">Change background</string>

View File

@ -15,7 +15,7 @@
<!-- Settings -->
<string name="dark_theme">ダークテーマ</string>
<string name="brush_size">Show brush size tool</string>
<string name="show_brush_size">Show brush size tool</string>
<string name="clear">クリア</string>
<string name="change_background">Change background</string>

View File

@ -15,7 +15,7 @@
<!-- Settings -->
<string name="dark_theme">Tema escuro</string>
<string name="brush_size">Mostrar ferramenta Tamanho do pincel</string>
<string name="show_brush_size">Mostrar ferramenta Tamanho do pincel</string>
<string name="clear">Limpar</string>
<string name="change_background">Alterar fundo</string>

View File

@ -15,7 +15,7 @@
<!-- Settings -->
<string name="dark_theme">Mörkt tema</string>
<string name="brush_size">Show brush size tool</string>
<string name="show_brush_size">Show brush size tool</string>
<string name="clear">Clear</string>
<string name="change_background">Change background</string>

View File

@ -15,7 +15,7 @@
<!-- Settings -->
<string name="dark_theme">Dark theme</string>
<string name="brush_size">Show brush size tool</string>
<string name="show_brush_size">Show brush size tool</string>
<string name="clear">Clear</string>
<string name="change_background">Change background</string>