|
|
|
@ -12,7 +12,7 @@ import io.realm.RealmObject |
|
|
|
import io.realm.RealmResults |
|
|
|
import io.realm.RealmResults |
|
|
|
import kotlinx.android.synthetic.main.fragment_data_list.* |
|
|
|
import kotlinx.android.synthetic.main.fragment_data_list.* |
|
|
|
import net.pokeranalytics.android.R |
|
|
|
import net.pokeranalytics.android.R |
|
|
|
import net.pokeranalytics.android.model.interfaces.Savable |
|
|
|
import net.pokeranalytics.android.model.interfaces.Manageable |
|
|
|
import net.pokeranalytics.android.ui.activity.EditableDataActivity |
|
|
|
import net.pokeranalytics.android.ui.activity.EditableDataActivity |
|
|
|
import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity |
|
|
|
import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity |
|
|
|
import net.pokeranalytics.android.ui.adapter.LiveRowRepresentableDataSource |
|
|
|
import net.pokeranalytics.android.ui.adapter.LiveRowRepresentableDataSource |
|
|
|
@ -23,6 +23,7 @@ import net.pokeranalytics.android.ui.helpers.SwipeToDeleteCallback |
|
|
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
|
|
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
|
|
|
import net.pokeranalytics.android.ui.view.RowViewType |
|
|
|
import net.pokeranalytics.android.ui.view.RowViewType |
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.SettingRow |
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.SettingRow |
|
|
|
|
|
|
|
import net.pokeranalytics.android.util.showAlertDialog |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DataListFragment : PokerAnalyticsFragment(), LiveRowRepresentableDataSource, RowRepresentableDelegate { |
|
|
|
class DataListFragment : PokerAnalyticsFragment(), LiveRowRepresentableDataSource, RowRepresentableDelegate { |
|
|
|
@ -69,7 +70,7 @@ class DataListFragment : PokerAnalyticsFragment(), LiveRowRepresentableDataSourc |
|
|
|
EditableDataActivity.newInstance( |
|
|
|
EditableDataActivity.newInstance( |
|
|
|
requireContext(), |
|
|
|
requireContext(), |
|
|
|
it.ordinal, |
|
|
|
it.ordinal, |
|
|
|
(row as Savable).uniqueIdentifier() |
|
|
|
(row as Manageable).uniqueIdentifier() |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -98,12 +99,18 @@ class DataListFragment : PokerAnalyticsFragment(), LiveRowRepresentableDataSourc |
|
|
|
lastDeletedItemPosition = position |
|
|
|
lastDeletedItemPosition = position |
|
|
|
|
|
|
|
|
|
|
|
if (mRecentlyDeletedItem is RealmObject) { |
|
|
|
if (mRecentlyDeletedItem is RealmObject) { |
|
|
|
deletedItem = getRealm().copyFromRealm(mRecentlyDeletedItem) |
|
|
|
|
|
|
|
getRealm().executeTransaction { |
|
|
|
if ((mRecentlyDeletedItem as Manageable).isValidForDelete()) { |
|
|
|
mRecentlyDeletedItem.deleteFromRealm() |
|
|
|
deletedItem = getRealm().copyFromRealm(mRecentlyDeletedItem) |
|
|
|
|
|
|
|
getRealm().executeTransaction { |
|
|
|
|
|
|
|
mRecentlyDeletedItem.deleteFromRealm() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
dataListAdapter.notifyItemRemoved(position) |
|
|
|
|
|
|
|
showUndoSnackBar() |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
dataListAdapter.notifyItemChanged(position) |
|
|
|
|
|
|
|
showAlertDialog(R.string.warning, (mRecentlyDeletedItem as Manageable).getFailedDeleteMessage()) |
|
|
|
} |
|
|
|
} |
|
|
|
dataListAdapter.notifyItemRemoved(position) |
|
|
|
|
|
|
|
showUndoSnackBar() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -134,9 +141,9 @@ class DataListFragment : PokerAnalyticsFragment(), LiveRowRepresentableDataSourc |
|
|
|
val message = String.format(getString(R.string.data_deleted), this.dataType.localizedTitle(requireContext())) |
|
|
|
val message = String.format(getString(R.string.data_deleted), this.dataType.localizedTitle(requireContext())) |
|
|
|
val snackBar = Snackbar.make(constraintLayout, message, Snackbar.LENGTH_LONG) |
|
|
|
val snackBar = Snackbar.make(constraintLayout, message, Snackbar.LENGTH_LONG) |
|
|
|
snackBar.setAction(R.string.cancel) { |
|
|
|
snackBar.setAction(R.string.cancel) { |
|
|
|
getRealm().executeTransaction {realm -> |
|
|
|
getRealm().executeTransaction { realm -> |
|
|
|
deletedItem?.let { |
|
|
|
deletedItem?.let { |
|
|
|
realm.copyToRealm(it) |
|
|
|
realm.copyToRealmOrUpdate(it) |
|
|
|
dataListAdapter.notifyItemInserted(lastDeletedItemPosition) |
|
|
|
dataListAdapter.notifyItemInserted(lastDeletedItemPosition) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|