use the main constructor at CreateNewItemDialog

This commit is contained in:
tibbi 2016-10-30 11:48:21 +01:00
parent 10d9653560
commit 78b14915a4

View File

@ -13,18 +13,8 @@ import kotlinx.android.synthetic.main.create_new.view.*
import java.io.File import java.io.File
import java.io.IOException import java.io.IOException
class CreateNewItemDialog() { class CreateNewItemDialog(val context: Context, val path: String, val listener: OnCreateNewItemListener) {
interface OnCreateNewItemListener { init {
fun onSuccess()
}
lateinit var mContext: Context
var mListener: OnCreateNewItemListener? = null
constructor(context: Context, path: String, listener: OnCreateNewItemListener) : this() {
mContext = context
mListener = listener
val view = LayoutInflater.from(context).inflate(R.layout.create_new, null) val view = LayoutInflater.from(context).inflate(R.layout.create_new, null)
AlertDialog.Builder(context) AlertDialog.Builder(context)
@ -66,21 +56,21 @@ class CreateNewItemDialog() {
private fun createDirectory(file: File, alertDialog: AlertDialog): Boolean { private fun createDirectory(file: File, alertDialog: AlertDialog): Boolean {
return if (file.mkdirs()) { return if (file.mkdirs()) {
alertDialog.dismiss() alertDialog.dismiss()
mListener?.onSuccess() listener.onSuccess()
true true
} else } else
false false
} }
private fun errorOccurred() { private fun errorOccurred() {
mContext.toast(R.string.error_occurred) context.toast(R.string.error_occurred)
} }
private fun createFile(file: File, alertDialog: AlertDialog): Boolean { private fun createFile(file: File, alertDialog: AlertDialog): Boolean {
try { try {
if (file.createNewFile()) { if (file.createNewFile()) {
alertDialog.dismiss() alertDialog.dismiss()
mListener?.onSuccess() listener.onSuccess()
return true return true
} }
} catch (ignored: IOException) { } catch (ignored: IOException) {
@ -89,4 +79,8 @@ class CreateNewItemDialog() {
return false return false
} }
interface OnCreateNewItemListener {
fun onSuccess()
}
} }