mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-02-09 16:08:49 +01:00
convert config to kotlin
This commit is contained in:
parent
a911c8f97d
commit
0444d3f0ad
@ -1,56 +0,0 @@
|
||||
package com.simplemobiletools.notes;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
public class Config {
|
||||
private SharedPreferences mPrefs;
|
||||
|
||||
public static Config newInstance(Context context) {
|
||||
return new Config(context);
|
||||
}
|
||||
|
||||
private Config(Context context) {
|
||||
mPrefs = context.getSharedPreferences(Constants.PREFS_KEY, Context.MODE_PRIVATE);
|
||||
}
|
||||
|
||||
public boolean getIsFirstRun() {
|
||||
return mPrefs.getBoolean(Constants.IS_FIRST_RUN, true);
|
||||
}
|
||||
|
||||
public void setIsFirstRun(boolean firstRun) {
|
||||
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 int getFontSize() {
|
||||
return mPrefs.getInt(Constants.FONT_SIZE, Constants.FONT_SIZE_MEDIUM);
|
||||
}
|
||||
|
||||
public void setFontSize(int size) {
|
||||
mPrefs.edit().putInt(Constants.FONT_SIZE, size).apply();
|
||||
}
|
||||
|
||||
public int getCurrentNoteId() {
|
||||
return mPrefs.getInt(Constants.CURRENT_NOTE_ID, 1);
|
||||
}
|
||||
|
||||
public void setCurrentNoteId(int id) {
|
||||
mPrefs.edit().putInt(Constants.CURRENT_NOTE_ID, id).apply();
|
||||
}
|
||||
|
||||
public int getWidgetNoteId() {
|
||||
return mPrefs.getInt(Constants.WIDGET_NOTE_ID, 1);
|
||||
}
|
||||
|
||||
public void setWidgetNoteId(int id) {
|
||||
mPrefs.edit().putInt(Constants.WIDGET_NOTE_ID, id).apply();
|
||||
}
|
||||
}
|
@ -13,7 +13,7 @@ public class Utils {
|
||||
}
|
||||
|
||||
public static float getTextSize(Context context) {
|
||||
final int fontSize = Config.newInstance(context).getFontSize();
|
||||
final int fontSize = Config.Companion.newInstance(context).getFontSize();
|
||||
final Resources res = context.getResources();
|
||||
float textSize = res.getDimension(R.dimen.medium_text_size);
|
||||
switch (fontSize) {
|
||||
|
@ -55,7 +55,7 @@ public class AboutActivity extends SimpleActivity {
|
||||
}
|
||||
|
||||
private void setupRateUs() {
|
||||
if (Config.newInstance(getApplicationContext()).getIsFirstRun()) {
|
||||
if (Config.Companion.newInstance(getApplicationContext()).isFirstRun()) {
|
||||
mRateUs.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ public class MainActivity extends SimpleActivity implements OpenNoteDialog.OpenN
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
mConfig.setIsFirstRun(false);
|
||||
mConfig.setFirstRun(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -18,13 +18,11 @@ public class SettingsActivity extends SimpleActivity {
|
||||
@BindView(R.id.settings_dark_theme) SwitchCompat mDarkThemeSwitch;
|
||||
@BindView(R.id.settings_font_size) AppCompatSpinner mFontSizeSpinner;
|
||||
|
||||
private static Config mConfig;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_settings);
|
||||
mConfig = Config.newInstance(getApplicationContext());
|
||||
mConfig = Config.Companion.newInstance(getApplicationContext());
|
||||
ButterKnife.bind(this);
|
||||
|
||||
setupDarkTheme();
|
||||
@ -32,7 +30,7 @@ public class SettingsActivity extends SimpleActivity {
|
||||
}
|
||||
|
||||
private void setupDarkTheme() {
|
||||
mDarkThemeSwitch.setChecked(mConfig.getIsDarkTheme());
|
||||
mDarkThemeSwitch.setChecked(mConfig.isDarkTheme());
|
||||
}
|
||||
|
||||
private void setupFontSize() {
|
||||
@ -42,7 +40,7 @@ public class SettingsActivity extends SimpleActivity {
|
||||
@OnClick(R.id.settings_dark_theme_holder)
|
||||
public void handleDarkTheme() {
|
||||
mDarkThemeSwitch.setChecked(!mDarkThemeSwitch.isChecked());
|
||||
mConfig.setIsDarkTheme(mDarkThemeSwitch.isChecked());
|
||||
mConfig.setDarkTheme(mDarkThemeSwitch.isChecked());
|
||||
restartActivity();
|
||||
}
|
||||
|
||||
|
@ -13,8 +13,8 @@ public class SimpleActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
mConfig = Config.newInstance(getApplicationContext());
|
||||
setTheme(mConfig.getIsDarkTheme() ? R.style.AppTheme_Dark : R.style.AppTheme);
|
||||
mConfig = Config.Companion.newInstance(getApplicationContext());
|
||||
setTheme(mConfig.isDarkTheme() ? R.style.AppTheme_Dark : R.style.AppTheme);
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
|
38
app/src/main/kotlin/com/simplemobiletools/notes/Config.kt
Normal file
38
app/src/main/kotlin/com/simplemobiletools/notes/Config.kt
Normal file
@ -0,0 +1,38 @@
|
||||
package com.simplemobiletools.notes
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
|
||||
class Config(context: Context) {
|
||||
private val mPrefs: SharedPreferences
|
||||
|
||||
companion object {
|
||||
fun newInstance(context: Context): Config {
|
||||
return Config(context)
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
mPrefs = context.getSharedPreferences(Constants.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()
|
||||
|
||||
var isDarkTheme: Boolean
|
||||
get() = mPrefs.getBoolean(Constants.IS_DARK_THEME, false)
|
||||
set(isDarkTheme) = mPrefs.edit().putBoolean(Constants.IS_DARK_THEME, isDarkTheme).apply()
|
||||
|
||||
var fontSize: Int
|
||||
get() = mPrefs.getInt(Constants.FONT_SIZE, Constants.FONT_SIZE_MEDIUM)
|
||||
set(size) = mPrefs.edit().putInt(Constants.FONT_SIZE, size).apply()
|
||||
|
||||
var currentNoteId: Int
|
||||
get() = mPrefs.getInt(Constants.CURRENT_NOTE_ID, 1)
|
||||
set(id) = mPrefs.edit().putInt(Constants.CURRENT_NOTE_ID, id).apply()
|
||||
|
||||
var widgetNoteId: Int
|
||||
get() = mPrefs.getInt(Constants.WIDGET_NOTE_ID, 1)
|
||||
set(id) = mPrefs.edit().putInt(Constants.WIDGET_NOTE_ID, id).apply()
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user