|
|
|
@ -6,7 +6,6 @@ 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 androidx.appcompat.app.AlertDialog |
|
|
|
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
import com.google.android.material.snackbar.Snackbar |
|
|
|
import com.google.android.material.snackbar.Snackbar |
|
|
|
import io.realm.Realm |
|
|
|
import io.realm.Realm |
|
|
|
@ -28,7 +27,6 @@ import net.pokeranalytics.android.calculus.bankroll.BankrollCalculator |
|
|
|
import net.pokeranalytics.android.calculus.bankroll.BankrollReport |
|
|
|
import net.pokeranalytics.android.calculus.bankroll.BankrollReport |
|
|
|
import net.pokeranalytics.android.calculus.bankroll.BankrollReportSetup |
|
|
|
import net.pokeranalytics.android.calculus.bankroll.BankrollReportSetup |
|
|
|
import net.pokeranalytics.android.model.LiveData |
|
|
|
import net.pokeranalytics.android.model.LiveData |
|
|
|
import net.pokeranalytics.android.model.interfaces.Deletable |
|
|
|
|
|
|
|
import net.pokeranalytics.android.model.realm.Bankroll |
|
|
|
import net.pokeranalytics.android.model.realm.Bankroll |
|
|
|
import net.pokeranalytics.android.ui.activity.BankrollDetailsActivity |
|
|
|
import net.pokeranalytics.android.ui.activity.BankrollDetailsActivity |
|
|
|
import net.pokeranalytics.android.ui.activity.DataListActivity |
|
|
|
import net.pokeranalytics.android.ui.activity.DataListActivity |
|
|
|
@ -97,6 +95,9 @@ class BankrollFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSou |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
initData() |
|
|
|
|
|
|
|
//TODO: Refresh bankroll |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun adapterRows(): List<RowRepresentable>? { |
|
|
|
override fun adapterRows(): List<RowRepresentable>? { |
|
|
|
@ -117,6 +118,7 @@ class BankrollFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSou |
|
|
|
else -> { |
|
|
|
else -> { |
|
|
|
if (bankrollReportForRow.containsKey(row)) { |
|
|
|
if (bankrollReportForRow.containsKey(row)) { |
|
|
|
bankrollReportForRow[row]?.let { bankrollReport -> |
|
|
|
bankrollReportForRow[row]?.let { bankrollReport -> |
|
|
|
|
|
|
|
lastItemClickedPosition = position |
|
|
|
BankrollDetailsActivity.newInstanceForResult(this, bankrollReport, REQUEST_CODE_DETAILS) |
|
|
|
BankrollDetailsActivity.newInstanceForResult(this, bankrollReport, REQUEST_CODE_DETAILS) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -166,7 +168,6 @@ class BankrollFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSou |
|
|
|
bankrollReportForRow[row] = bankrollReport |
|
|
|
bankrollReportForRow[row] = bankrollReport |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!isDetached) { |
|
|
|
if (!isDetached) { |
|
|
|
bankrollAdapter.notifyDataSetChanged() |
|
|
|
bankrollAdapter.notifyDataSetChanged() |
|
|
|
} |
|
|
|
} |
|
|
|
@ -213,32 +214,41 @@ class BankrollFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSou |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private fun deleteItem(position: Int) { |
|
|
|
private fun deleteItem(position: Int) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//TODO: Get bankroll from bankrollReport and delete it |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
if (isDetached || activity == null) { |
|
|
|
if (isDetached || activity == null) { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Save the delete position & create a copy of the object |
|
|
|
// Save the delete position & create a copy of the object |
|
|
|
val mRecentlyDeletedItem = rowRepresentableForPosition(position) |
|
|
|
var mRecentlyDeletedItem = rowRepresentableForPosition(position) |
|
|
|
lastDeletedItemPosition = position |
|
|
|
lastDeletedItemPosition = position |
|
|
|
|
|
|
|
|
|
|
|
if (mRecentlyDeletedItem is RealmObject) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check if the object is valid for the deletion |
|
|
|
if (mRecentlyDeletedItem is BankrollReport) { |
|
|
|
if ((mRecentlyDeletedItem as Deletable).isValidForDelete(this.getRealm())) { |
|
|
|
|
|
|
|
deletedItem = getRealm().copyFromRealm(mRecentlyDeletedItem) |
|
|
|
if (mRecentlyDeletedItem is RealmObject) { |
|
|
|
getRealm().executeTransaction { |
|
|
|
// Check if the object is valid for the deletion |
|
|
|
mRecentlyDeletedItem.deleteFromRealm() |
|
|
|
if ((mRecentlyDeletedItem as Deletable).isValidForDelete(this.getRealm())) { |
|
|
|
|
|
|
|
deletedItem = getRealm().copyFromRealm(mRecentlyDeletedItem) |
|
|
|
|
|
|
|
getRealm().executeTransaction { |
|
|
|
|
|
|
|
mRecentlyDeletedItem.deleteFromRealm() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
bankrollAdapter.notifyItemRemoved(position) |
|
|
|
|
|
|
|
showUndoSnackBar() |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
bankrollAdapter.notifyItemChanged(position) |
|
|
|
|
|
|
|
val builder = AlertDialog.Builder(requireContext()) |
|
|
|
|
|
|
|
.setMessage((mRecentlyDeletedItem as Deletable).getFailedDeleteMessage()) |
|
|
|
|
|
|
|
.setNegativeButton(R.string.ok, null) |
|
|
|
|
|
|
|
builder.show() |
|
|
|
} |
|
|
|
} |
|
|
|
bankrollAdapter.notifyItemRemoved(position) |
|
|
|
|
|
|
|
showUndoSnackBar() |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
bankrollAdapter.notifyItemChanged(position) |
|
|
|
|
|
|
|
val builder = AlertDialog.Builder(requireContext()) |
|
|
|
|
|
|
|
.setMessage((mRecentlyDeletedItem as Deletable).getFailedDeleteMessage()) |
|
|
|
|
|
|
|
.setNegativeButton(R.string.ok, null) |
|
|
|
|
|
|
|
builder.show() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
|