fixup! Migrate some classes to Kotlin

This commit is contained in:
Billy Brawner 2019-05-17 19:54:16 -07:00 committed by William Brawner
parent 7992b80787
commit eb14543ccf

View file

@ -52,8 +52,8 @@ class MainActivity : AppCompatActivity(), ActivityCompat.OnRequestPermissionsRes
override fun onUserLeaveHint() { override fun onUserLeaveHint() {
super.onUserLeaveHint() super.onUserLeaveHint()
if (shouldAutoSave && !presenter!!.markdown.isEmpty() && Utils.isAutosaveEnabled(this)) { if (shouldAutoSave && presenter.markdown.isNotEmpty() && Utils.isAutosaveEnabled(this)) {
presenter!!.saveMarkdown(null, null) presenter.saveMarkdown(null, null)
} }
} }
@ -75,7 +75,7 @@ class MainActivity : AppCompatActivity(), ActivityCompat.OnRequestPermissionsRes
R.id.action_save -> requestFileOp(Constants.REQUEST_SAVE_FILE) R.id.action_save -> requestFileOp(Constants.REQUEST_SAVE_FILE)
R.id.action_share -> { R.id.action_share -> {
val shareIntent = Intent(Intent.ACTION_SEND) val shareIntent = Intent(Intent.ACTION_SEND)
shareIntent.putExtra(Intent.EXTRA_TEXT, presenter!!.markdown) shareIntent.putExtra(Intent.EXTRA_TEXT, presenter.markdown)
shareIntent.type = "text/plain" shareIntent.type = "text/plain"
startActivity(Intent.createChooser( startActivity(Intent.createChooser(
shareIntent, shareIntent,
@ -83,7 +83,7 @@ class MainActivity : AppCompatActivity(), ActivityCompat.OnRequestPermissionsRes
)) ))
} }
R.id.action_load -> requestFileOp(Constants.REQUEST_OPEN_FILE) R.id.action_load -> requestFileOp(Constants.REQUEST_OPEN_FILE)
R.id.action_new -> presenter!!.saveMarkdown(newFileHandler, null) R.id.action_new -> presenter.saveMarkdown(newFileHandler, null)
R.id.action_lock_swipe -> { R.id.action_lock_swipe -> {
item.isChecked = !item.isChecked item.isChecked = !item.isChecked
pager!!.setSwipeLocked(item.isChecked) pager!!.setSwipeLocked(item.isChecked)
@ -124,7 +124,7 @@ class MainActivity : AppCompatActivity(), ActivityCompat.OnRequestPermissionsRes
if (assetManager != null) { if (assetManager != null) {
`in` = assetManager.open(fileName) `in` = assetManager.open(fileName)
} }
presenter!!.loadMarkdown(fileName, `in`, object : MarkdownPresenter.OnTempFileLoadedListener { presenter.loadMarkdown(fileName, `in`, object : MarkdownPresenter.OnTempFileLoadedListener {
override fun onSuccess(html: String) { override fun onSuccess(html: String) {
infoIntent.putExtra("html", html) infoIntent.putExtra("html", html)
startActivity(infoIntent) startActivity(infoIntent)
@ -150,7 +150,7 @@ class MainActivity : AppCompatActivity(), ActivityCompat.OnRequestPermissionsRes
when (requestCode) { when (requestCode) {
Constants.REQUEST_SAVE_FILE, Constants.REQUEST_OPEN_FILE -> { Constants.REQUEST_SAVE_FILE, Constants.REQUEST_OPEN_FILE -> {
// If request is cancelled, the result arrays are empty. // If request is cancelled, the result arrays are empty.
if (grantResults.size > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// Permission granted, open file save dialog // Permission granted, open file save dialog
requestFileOp(requestCode) requestFileOp(requestCode)
} else { } else {
@ -176,8 +176,8 @@ class MainActivity : AppCompatActivity(), ActivityCompat.OnRequestPermissionsRes
return return
} }
val markdownFile = data.getSerializableExtra(Constants.EXTRA_FILE) as File val markdownFile = data.getSerializableExtra(Constants.EXTRA_FILE) as? File?: return
presenter!!.loadMarkdown(markdownFile) presenter.loadMarkdown(markdownFile)
} }
Constants.REQUEST_SAVE_FILE -> { Constants.REQUEST_SAVE_FILE -> {
if (resultCode != Activity.RESULT_OK if (resultCode != Activity.RESULT_OK
@ -187,7 +187,7 @@ class MainActivity : AppCompatActivity(), ActivityCompat.OnRequestPermissionsRes
return return
} }
val path = data.getStringExtra(Constants.EXTRA_FILE_PATH) val path = data.getStringExtra(Constants.EXTRA_FILE_PATH)
presenter!!.saveMarkdown(null, path) presenter.saveMarkdown(null, path)
} }
} }
super.onActivityResult(requestCode, resultCode, data) super.onActivityResult(requestCode, resultCode, data)
@ -199,7 +199,7 @@ class MainActivity : AppCompatActivity(), ActivityCompat.OnRequestPermissionsRes
shouldAutoSave = false shouldAutoSave = false
val intent = Intent(this@MainActivity, ExplorerActivity::class.java) val intent = Intent(this@MainActivity, ExplorerActivity::class.java)
intent.putExtra(Constants.EXTRA_REQUEST_CODE, requestType) intent.putExtra(Constants.EXTRA_REQUEST_CODE, requestType)
intent.putExtra(Constants.EXTRA_FILE, presenter!!.file) intent.putExtra(Constants.EXTRA_FILE, presenter.file)
startActivityForResult( startActivityForResult(
intent, intent,
requestType requestType
@ -214,7 +214,7 @@ class MainActivity : AppCompatActivity(), ActivityCompat.OnRequestPermissionsRes
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
title = presenter!!.fileName title = presenter.fileName
shouldAutoSave = true shouldAutoSave = true
} }
@ -222,7 +222,7 @@ class MainActivity : AppCompatActivity(), ActivityCompat.OnRequestPermissionsRes
override fun saveComplete(success: Boolean) { override fun saveComplete(success: Boolean) {
if (success) { if (success) {
val newFile = Utils.getDefaultFileName(this@MainActivity) val newFile = Utils.getDefaultFileName(this@MainActivity)
presenter!!.newFile(newFile) presenter.newFile(newFile)
} else { } else {
Toast.makeText( Toast.makeText(
this@MainActivity, this@MainActivity,