convert 3 simple activity to kotlin
This commit is contained in:
parent
8d3b54b661
commit
7d30c4ec9a
6 changed files with 87 additions and 115 deletions
|
@ -1,31 +0,0 @@
|
|||
package com.simplemobiletools.filemanager.activities;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.simplemobiletools.filemanager.R;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
|
||||
public class LicenseActivity extends SimpleActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_license);
|
||||
ButterKnife.bind(this);
|
||||
}
|
||||
|
||||
@OnClick(R.id.license_butterknife_title)
|
||||
public void butterKnifeClicked() {
|
||||
openUrl(R.string.butterknife_url);
|
||||
}
|
||||
|
||||
private void openUrl(int id) {
|
||||
final String url = getResources().getString(id);
|
||||
final Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
||||
startActivity(browserIntent);
|
||||
}
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
package com.simplemobiletools.filemanager.activities;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.TaskStackBuilder;
|
||||
import android.support.v7.widget.SwitchCompat;
|
||||
|
||||
import com.simplemobiletools.filemanager.Config;
|
||||
import com.simplemobiletools.filemanager.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_show_hidden) SwitchCompat mShowHiddenSwitch;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_settings);
|
||||
mConfig = Config.newInstance(getApplicationContext());
|
||||
ButterKnife.bind(this);
|
||||
|
||||
setupDarkTheme();
|
||||
setupShowHidden();
|
||||
}
|
||||
|
||||
private void setupDarkTheme() {
|
||||
mDarkThemeSwitch.setChecked(mConfig.getIsDarkTheme());
|
||||
}
|
||||
|
||||
private void setupShowHidden() {
|
||||
mShowHiddenSwitch.setChecked(mConfig.getShowHidden());
|
||||
}
|
||||
|
||||
@OnClick(R.id.settings_dark_theme_holder)
|
||||
public void handleDarkTheme() {
|
||||
mDarkThemeSwitch.setChecked(!mDarkThemeSwitch.isChecked());
|
||||
mConfig.setIsDarkTheme(mDarkThemeSwitch.isChecked());
|
||||
restartActivity();
|
||||
}
|
||||
|
||||
@OnClick(R.id.settings_show_hidden_holder)
|
||||
public void handleShowHidden() {
|
||||
mShowHiddenSwitch.setChecked(!mShowHiddenSwitch.isChecked());
|
||||
mConfig.setShowHidden(mShowHiddenSwitch.isChecked());
|
||||
}
|
||||
|
||||
private void restartActivity() {
|
||||
TaskStackBuilder.create(getApplicationContext()).addNextIntentWithParentStack(getIntent()).startActivities();
|
||||
}
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
package com.simplemobiletools.filemanager.activities;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import com.simplemobiletools.filemanager.Config;
|
||||
import com.simplemobiletools.filemanager.R;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.simplemobiletools.filemanager.activities
|
||||
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import com.simplemobiletools.filemanager.R
|
||||
import kotlinx.android.synthetic.main.activity_license.*
|
||||
|
||||
class LicenseActivity : SimpleActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_license)
|
||||
license_butterknife_title.setOnClickListener { openUrl(R.string.butterknife_url) }
|
||||
}
|
||||
|
||||
private fun openUrl(id: Int) {
|
||||
val url = resources.getString(id)
|
||||
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
|
||||
startActivity(browserIntent)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package com.simplemobiletools.filemanager.activities
|
||||
|
||||
import android.os.Bundle
|
||||
import android.support.v4.app.TaskStackBuilder
|
||||
import com.simplemobiletools.filemanager.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()
|
||||
setupShowHidden()
|
||||
}
|
||||
|
||||
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 setupShowHidden() {
|
||||
settings_show_hidden.isChecked = mConfig.showHidden
|
||||
settings_show_hidden_holder.setOnClickListener {
|
||||
settings_show_hidden.toggle()
|
||||
mConfig.showHidden = settings_show_hidden.isChecked
|
||||
}
|
||||
}
|
||||
|
||||
private fun restartActivity() {
|
||||
TaskStackBuilder.create(applicationContext).addNextIntentWithParentStack(intent).startActivities()
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.simplemobiletools.filemanager.activities
|
||||
|
||||
import android.os.Bundle
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.view.MenuItem
|
||||
|
||||
import com.simplemobiletools.filemanager.Config
|
||||
import com.simplemobiletools.filemanager.R
|
||||
|
||||
open class SimpleActivity : AppCompatActivity() {
|
||||
lateinit var mConfig: Config
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
mConfig = Config.newInstance(applicationContext)
|
||||
setTheme(if (mConfig.isDarkTheme) R.style.AppTheme_Dark else R.style.AppTheme)
|
||||
super.onCreate(savedInstanceState)
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
return when (item.itemId) {
|
||||
android.R.id.home -> {
|
||||
finish()
|
||||
true
|
||||
}
|
||||
else -> super.onOptionsItemSelected(item)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue