|
|
|
@ -20,7 +20,7 @@ import net.pokeranalytics.android.ui.viewmodel.DataManagerViewModel |
|
|
|
|
|
|
|
|
|
|
|
open class DataManagerFragment : RealmFragment() { |
|
|
|
open class DataManagerFragment : RealmFragment() { |
|
|
|
|
|
|
|
|
|
|
|
protected val viewModel: DataManagerViewModel by lazy { |
|
|
|
protected val model: DataManagerViewModel by lazy { |
|
|
|
ViewModelProviders.of(this).get(DataManagerViewModel::class.java) |
|
|
|
ViewModelProviders.of(this).get(DataManagerViewModel::class.java) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -78,7 +78,7 @@ open class DataManagerFragment : RealmFragment() { |
|
|
|
private fun loadItem() { |
|
|
|
private fun loadItem() { |
|
|
|
|
|
|
|
|
|
|
|
// this.item = this.liveDataType.updateOrCreate(this.getRealm(), primaryKey) |
|
|
|
// this.item = this.liveDataType.updateOrCreate(this.getRealm(), primaryKey) |
|
|
|
this.deleteButtonShouldAppear = this.viewModel.primaryKey != null |
|
|
|
this.deleteButtonShouldAppear = this.model.primaryKey != null |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -87,7 +87,7 @@ open class DataManagerFragment : RealmFragment() { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected open fun saveData() { |
|
|
|
protected open fun saveData() { |
|
|
|
|
|
|
|
|
|
|
|
val savable = this.viewModel.item |
|
|
|
val savable = this.model.item |
|
|
|
this.willSaveData() |
|
|
|
this.willSaveData() |
|
|
|
|
|
|
|
|
|
|
|
when (savable) { |
|
|
|
when (savable) { |
|
|
|
@ -96,7 +96,7 @@ open class DataManagerFragment : RealmFragment() { |
|
|
|
when (status) { |
|
|
|
when (status) { |
|
|
|
SaveValidityStatus.VALID -> { |
|
|
|
SaveValidityStatus.VALID -> { |
|
|
|
this.getRealm().executeTransaction { |
|
|
|
this.getRealm().executeTransaction { |
|
|
|
val managedItem = it.copyToRealmOrUpdate(this.viewModel.item) |
|
|
|
val managedItem = it.copyToRealmOrUpdate(this.model.item) |
|
|
|
if (managedItem is Savable) { |
|
|
|
if (managedItem is Savable) { |
|
|
|
val uniqueIdentifier = managedItem.id |
|
|
|
val uniqueIdentifier = managedItem.id |
|
|
|
finishActivityWithResult(uniqueIdentifier) |
|
|
|
finishActivityWithResult(uniqueIdentifier) |
|
|
|
@ -134,14 +134,14 @@ open class DataManagerFragment : RealmFragment() { |
|
|
|
|
|
|
|
|
|
|
|
val realm = this.getRealm() |
|
|
|
val realm = this.getRealm() |
|
|
|
|
|
|
|
|
|
|
|
if (this.viewModel.item.isValidForDelete(realm)) { |
|
|
|
if (this.model.item.isValidForDelete(realm)) { |
|
|
|
val intent = Intent() |
|
|
|
val intent = Intent() |
|
|
|
intent.putExtra(DataListActivity.IntentKey.ITEM_DELETED.keyName, this.viewModel.item.id) |
|
|
|
intent.putExtra(DataListActivity.IntentKey.ITEM_DELETED.keyName, this.model.item.id) |
|
|
|
activity?.setResult(Activity.RESULT_OK, intent) |
|
|
|
activity?.setResult(Activity.RESULT_OK, intent) |
|
|
|
activity?.finish() |
|
|
|
activity?.finish() |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
val status = this.viewModel.item.getDeleteStatus(requireContext(), realm) |
|
|
|
val status = this.model.item.getDeleteStatus(requireContext(), realm) |
|
|
|
val message = this.viewModel.item.getFailedDeleteMessage(status) |
|
|
|
val message = this.model.item.getFailedDeleteMessage(status) |
|
|
|
val builder = AlertDialog.Builder(requireContext()) |
|
|
|
val builder = AlertDialog.Builder(requireContext()) |
|
|
|
.setMessage(message) |
|
|
|
.setMessage(message) |
|
|
|
.setNegativeButton(R.string.ok, null) |
|
|
|
.setNegativeButton(R.string.ok, null) |
|
|
|
@ -156,7 +156,7 @@ open class DataManagerFragment : RealmFragment() { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private fun finishActivityWithResult(uniqueIdentifier: String) { |
|
|
|
private fun finishActivityWithResult(uniqueIdentifier: String) { |
|
|
|
val intent = Intent() |
|
|
|
val intent = Intent() |
|
|
|
intent.putExtra(EditableDataActivity.IntentKey.DATA_TYPE.keyName, viewModel.dataType) |
|
|
|
intent.putExtra(EditableDataActivity.IntentKey.DATA_TYPE.keyName, model.dataType) |
|
|
|
intent.putExtra(EditableDataActivity.IntentKey.PRIMARY_KEY.keyName, uniqueIdentifier) |
|
|
|
intent.putExtra(EditableDataActivity.IntentKey.PRIMARY_KEY.keyName, uniqueIdentifier) |
|
|
|
activity?.setResult(Activity.RESULT_OK, intent) |
|
|
|
activity?.setResult(Activity.RESULT_OK, intent) |
|
|
|
activity?.finish() |
|
|
|
activity?.finish() |
|
|
|
|