convert 3 simple activity to kotlin

This commit is contained in:
tibbi
2016-11-12 15:55:38 +01:00
parent 8d3b54b661
commit 7d30c4ec9a
6 changed files with 87 additions and 115 deletions

View File

@ -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)
}
}

View File

@ -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()
}
}

View File

@ -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)
}
}
}