|
|
|
|
@ -6,15 +6,12 @@ import android.os.Bundle |
|
|
|
|
import android.view.LayoutInflater |
|
|
|
|
import android.view.View |
|
|
|
|
import android.view.ViewGroup |
|
|
|
|
import androidx.appcompat.app.AlertDialog |
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
|
import com.github.mikephil.charting.data.LineDataSet |
|
|
|
|
import com.google.android.material.snackbar.Snackbar |
|
|
|
|
import io.realm.RealmObject |
|
|
|
|
import io.realm.RealmResults |
|
|
|
|
import kotlinx.android.synthetic.main.fragment_bankroll.* |
|
|
|
|
import kotlinx.android.synthetic.main.fragment_bankroll.addButton |
|
|
|
|
import kotlinx.android.synthetic.main.fragment_bankroll.toolbar |
|
|
|
|
import kotlinx.android.synthetic.main.fragment_data_list.* |
|
|
|
|
import kotlinx.android.synthetic.main.fragment_stats.recyclerView |
|
|
|
|
import kotlinx.coroutines.Dispatchers |
|
|
|
|
import kotlinx.coroutines.GlobalScope |
|
|
|
|
@ -27,6 +24,7 @@ import net.pokeranalytics.android.calculus.bankroll.BankrollCalculator |
|
|
|
|
import net.pokeranalytics.android.calculus.bankroll.BankrollReport |
|
|
|
|
import net.pokeranalytics.android.calculus.bankroll.BankrollReportSetup |
|
|
|
|
import net.pokeranalytics.android.model.LiveData |
|
|
|
|
import net.pokeranalytics.android.model.interfaces.Deletable |
|
|
|
|
import net.pokeranalytics.android.model.realm.Bankroll |
|
|
|
|
import net.pokeranalytics.android.ui.activity.BankrollDetailsActivity |
|
|
|
|
import net.pokeranalytics.android.ui.activity.DataListActivity |
|
|
|
|
@ -49,7 +47,8 @@ class BankrollFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSou |
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
|
|
|
|
|
|
const val REQUEST_CODE_DETAILS = 1000 |
|
|
|
|
const val REQUEST_CODE_DETAILS = 100 |
|
|
|
|
const val REQUEST_CODE_CREATE = 101 |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Create new instance |
|
|
|
|
@ -94,10 +93,11 @@ class BankrollFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSou |
|
|
|
|
deleteItem(lastItemClickedPosition) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else if (requestCode == REQUEST_CODE_CREATE && resultCode == Activity.RESULT_OK) { |
|
|
|
|
//TODO: Refresh bankrolls |
|
|
|
|
initData() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
initData() |
|
|
|
|
//TODO: Refresh bankroll |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun adapterRows(): List<RowRepresentable>? { |
|
|
|
|
@ -192,11 +192,7 @@ class BankrollFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSou |
|
|
|
|
|
|
|
|
|
addButton.setOnClickListener { |
|
|
|
|
LiveData.BANKROLL?.let { |
|
|
|
|
EditableDataActivity.newInstance( |
|
|
|
|
requireContext(), |
|
|
|
|
dataType = it.ordinal, |
|
|
|
|
primaryKey = null |
|
|
|
|
) |
|
|
|
|
EditableDataActivity.newInstanceForResult(this@BankrollFragment, dataType = it.ordinal, primaryKey = null, requestCode = REQUEST_CODE_CREATE) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -209,47 +205,46 @@ class BankrollFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSou |
|
|
|
|
|
|
|
|
|
//TODO: Get bankroll from bankrollReport and delete it |
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
if (isDetached || activity == null) { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Save the delete position & create a copy of the object |
|
|
|
|
var mRecentlyDeletedItem = rowRepresentableForPosition(position) |
|
|
|
|
val bankrollReport = bankrollReportForRow[rowRepresentableForPosition(position)] |
|
|
|
|
val mRecentlyDeletedItem = bankrollReport?.setup?.bankroll |
|
|
|
|
lastDeletedItemPosition = position |
|
|
|
|
|
|
|
|
|
if (mRecentlyDeletedItem is Bankroll) { |
|
|
|
|
|
|
|
|
|
if (mRecentlyDeletedItem is BankrollReport) { |
|
|
|
|
|
|
|
|
|
if (mRecentlyDeletedItem is RealmObject) { |
|
|
|
|
// Check if the object is valid for the deletion |
|
|
|
|
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() |
|
|
|
|
// Check if the object is valid for the deletion |
|
|
|
|
if ((mRecentlyDeletedItem as Deletable).isValidForDelete(this.getRealm())) { |
|
|
|
|
deletedItem = getRealm().copyFromRealm(mRecentlyDeletedItem) |
|
|
|
|
getRealm().executeTransaction { |
|
|
|
|
mRecentlyDeletedItem.deleteFromRealm() |
|
|
|
|
} |
|
|
|
|
//bankrollAdapter.notifyItemRemoved(position) |
|
|
|
|
//showUndoSnackBar() |
|
|
|
|
|
|
|
|
|
//TODO: Refresh bankrolls |
|
|
|
|
initData() |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
bankrollAdapter.notifyItemChanged(position) |
|
|
|
|
val builder = AlertDialog.Builder(requireContext()) |
|
|
|
|
.setMessage((mRecentlyDeletedItem as Deletable).getFailedDeleteMessage()) |
|
|
|
|
.setNegativeButton(R.string.ok, null) |
|
|
|
|
builder.show() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Show undo snack bar |
|
|
|
|
*/ |
|
|
|
|
private fun showUndoSnackBar() { |
|
|
|
|
/* |
|
|
|
|
val message = String.format(getString(R.string.data_deleted), getString(R.string.bankroll)) |
|
|
|
|
val snackBar = Snackbar.make(constraintLayout, message, Snackbar.LENGTH_INDEFINITE) |
|
|
|
|
val snackBar = Snackbar.make(coordinatorLayout, message, Snackbar.LENGTH_INDEFINITE) |
|
|
|
|
snackBar.setAction(R.string.cancel) { |
|
|
|
|
getRealm().executeTransaction { realm -> |
|
|
|
|
deletedItem?.let { |
|
|
|
|
@ -259,6 +254,7 @@ class BankrollFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSou |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
snackBar.show() |
|
|
|
|
*/ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |