|
|
|
@ -1,10 +1,12 @@ |
|
|
|
package net.pokeranalytics.android.ui.fragment |
|
|
|
package net.pokeranalytics.android.ui.fragment |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.content.DialogInterface |
|
|
|
import android.os.Bundle |
|
|
|
import android.os.Bundle |
|
|
|
import android.view.LayoutInflater |
|
|
|
import android.view.LayoutInflater |
|
|
|
import android.view.View |
|
|
|
import android.view.View |
|
|
|
import android.view.ViewGroup |
|
|
|
import android.view.ViewGroup |
|
|
|
import android.widget.Toast |
|
|
|
import android.widget.Toast |
|
|
|
|
|
|
|
import androidx.appcompat.app.AlertDialog |
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
import io.realm.Realm |
|
|
|
import io.realm.Realm |
|
|
|
import io.realm.RealmObject |
|
|
|
import io.realm.RealmObject |
|
|
|
@ -12,6 +14,7 @@ import kotlinx.android.synthetic.main.fragment_editable_data.* |
|
|
|
import kotlinx.android.synthetic.main.fragment_editable_data.view.* |
|
|
|
import kotlinx.android.synthetic.main.fragment_editable_data.view.* |
|
|
|
import net.pokeranalytics.android.R |
|
|
|
import net.pokeranalytics.android.R |
|
|
|
import net.pokeranalytics.android.model.LiveData |
|
|
|
import net.pokeranalytics.android.model.LiveData |
|
|
|
|
|
|
|
import net.pokeranalytics.android.model.ObjectSavable |
|
|
|
import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity |
|
|
|
import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity |
|
|
|
import net.pokeranalytics.android.ui.adapter.components.* |
|
|
|
import net.pokeranalytics.android.ui.adapter.components.* |
|
|
|
import net.pokeranalytics.android.ui.fragment.components.PokerAnalyticsFragment |
|
|
|
import net.pokeranalytics.android.ui.fragment.components.PokerAnalyticsFragment |
|
|
|
@ -78,26 +81,56 @@ class EditableDataFragment : PokerAnalyticsFragment(), RowRepresentableDelegate, |
|
|
|
setHasFixedSize(true) |
|
|
|
setHasFixedSize(true) |
|
|
|
layoutManager = viewManager |
|
|
|
layoutManager = viewManager |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.saveButton.text = this.saveButton.context.getString(R.string.save) |
|
|
|
|
|
|
|
this.saveButton.setOnClickListener { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ((this.item as ObjectSavable).isSavable()) { |
|
|
|
|
|
|
|
this.getRealm().executeTransaction { |
|
|
|
|
|
|
|
it.copyToRealmOrUpdate(this.item) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.activity?.let { |
|
|
|
|
|
|
|
it.finish() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
val builder = AlertDialog.Builder(it.context) |
|
|
|
|
|
|
|
builder.setTitle(R.string.warning) |
|
|
|
|
|
|
|
.setNegativeButton(R.string.ok, null) |
|
|
|
|
|
|
|
builder.show() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.deleteButton.text = this.deleteButton.context.getString(R.string.delete) |
|
|
|
|
|
|
|
this.deleteButton.setOnClickListener { |
|
|
|
|
|
|
|
val builder = AlertDialog.Builder(it.context) |
|
|
|
|
|
|
|
builder.setTitle(R.string.warning) |
|
|
|
|
|
|
|
.setMessage(R.string.are_you_sure_you_want_to_do_that_) |
|
|
|
|
|
|
|
.setNeutralButton(R.string.no, null) |
|
|
|
|
|
|
|
.setNegativeButton(R.string.yes, DialogInterface.OnClickListener { dialog, id -> |
|
|
|
|
|
|
|
this.getRealm().executeTransaction { |
|
|
|
|
|
|
|
this.item.deleteFromRealm() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.activity?.let { |
|
|
|
|
|
|
|
it.finish() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
builder.show() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Set fragment data |
|
|
|
* Set fragment data |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
fun setData(dataType: Int, primaryKey: String?) { |
|
|
|
fun setData(dataType: Int, primaryKey: String?) { |
|
|
|
|
|
|
|
|
|
|
|
this.liveDataType = LiveData.values()[dataType] |
|
|
|
this.liveDataType = LiveData.values()[dataType] |
|
|
|
val realm = Realm.getDefaultInstance() |
|
|
|
var proxyItem : RealmObject? = this.liveDataType.getData(this.getRealm(), primaryKey) |
|
|
|
var proxyItem : RealmObject? = this.liveDataType.getData(realm, primaryKey) |
|
|
|
|
|
|
|
proxyItem?.let { |
|
|
|
proxyItem?.let { |
|
|
|
this.appBar.toolbar.title = "Update ${this.liveDataType.name.toLowerCase().capitalize()}" |
|
|
|
this.appBar.toolbar.title = "Update ${this.liveDataType.name.toLowerCase().capitalize()}" |
|
|
|
} ?: run { |
|
|
|
} ?: run { |
|
|
|
this.appBar.toolbar.title = "New ${this.liveDataType.name.toLowerCase().capitalize()}" |
|
|
|
this.appBar.toolbar.title = "New ${this.liveDataType.name.toLowerCase().capitalize()}" |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
this.item = this.liveDataType.updateOrCreate(this.getRealm(), primaryKey) |
|
|
|
this.item = this.liveDataType.updateOrCreate(realm, primaryKey) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.rowRepresentableAdapter = RowRepresentableAdapter((this.item as RowRepresentableDataSource), this) |
|
|
|
this.rowRepresentableAdapter = RowRepresentableAdapter((this.item as RowRepresentableDataSource), this) |
|
|
|
this.recyclerView.adapter = rowRepresentableAdapter |
|
|
|
this.recyclerView.adapter = rowRepresentableAdapter |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |