|
|
|
|
@ -10,6 +10,7 @@ import android.widget.Toast |
|
|
|
|
import androidx.core.app.ActivityOptionsCompat |
|
|
|
|
import androidx.core.view.isVisible |
|
|
|
|
import androidx.interpolator.view.animation.FastOutSlowInInterpolator |
|
|
|
|
import com.google.android.material.chip.ChipGroup |
|
|
|
|
import io.realm.RealmResults |
|
|
|
|
import io.realm.Sort |
|
|
|
|
import io.realm.kotlin.where |
|
|
|
|
@ -19,12 +20,14 @@ import net.pokeranalytics.android.model.LiveData |
|
|
|
|
import net.pokeranalytics.android.model.interfaces.Editable |
|
|
|
|
import net.pokeranalytics.android.model.realm.Session |
|
|
|
|
import net.pokeranalytics.android.model.realm.Transaction |
|
|
|
|
import net.pokeranalytics.android.ui.activity.DataListActivity |
|
|
|
|
import net.pokeranalytics.android.ui.activity.EditableDataActivity |
|
|
|
|
import net.pokeranalytics.android.ui.activity.NewDataMenuActivity |
|
|
|
|
import net.pokeranalytics.android.ui.activity.SessionActivity |
|
|
|
|
import net.pokeranalytics.android.ui.adapter.FeedSessionRowRepresentableAdapter |
|
|
|
|
import net.pokeranalytics.android.ui.adapter.FeedTransactionRowRepresentableAdapter |
|
|
|
|
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate |
|
|
|
|
import net.pokeranalytics.android.ui.extensions.ChipGroupExtension |
|
|
|
|
import net.pokeranalytics.android.ui.fragment.components.PokerAnalyticsFragment |
|
|
|
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
|
|
|
|
import net.pokeranalytics.android.ui.view.SmoothScrollLinearLayoutManager |
|
|
|
|
@ -33,14 +36,12 @@ import java.text.SimpleDateFormat |
|
|
|
|
import java.util.* |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class FeedFragment : PokerAnalyticsFragment(), RowRepresentableDelegate { |
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
|
|
|
|
|
|
const val REQUEST_CODE_MENU = 100 |
|
|
|
|
const val REQUEST_CODE_TRANSACTION_DETAILS = 101 |
|
|
|
|
|
|
|
|
|
fun newInstance(): FeedFragment { |
|
|
|
|
val fragment = FeedFragment() |
|
|
|
|
@ -57,6 +58,8 @@ class FeedFragment : PokerAnalyticsFragment(), RowRepresentableDelegate { |
|
|
|
|
private lateinit var betaLimitDate: Date |
|
|
|
|
|
|
|
|
|
private var newSessionCreated: Boolean = false |
|
|
|
|
private var selectedTransaction: Transaction? = null |
|
|
|
|
private var selectedTransactionPosition: Int = -1 |
|
|
|
|
|
|
|
|
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { |
|
|
|
|
return inflater.inflate(R.layout.fragment_feed, container, false) |
|
|
|
|
@ -71,23 +74,32 @@ class FeedFragment : PokerAnalyticsFragment(), RowRepresentableDelegate { |
|
|
|
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { |
|
|
|
|
super.onActivityResult(requestCode, resultCode, data) |
|
|
|
|
if (requestCode == REQUEST_CODE_MENU && resultCode == RESULT_OK && data != null) { |
|
|
|
|
when(data.getIntExtra(NewDataMenuActivity.IntentKey.CHOICE.keyName, -1)) { |
|
|
|
|
when (data.getIntExtra(NewDataMenuActivity.IntentKey.CHOICE.keyName, -1)) { |
|
|
|
|
0 -> createNewSession(false) |
|
|
|
|
1 -> createNewSession(true) |
|
|
|
|
2 -> createNewTransaction() |
|
|
|
|
} |
|
|
|
|
} else if (requestCode == REQUEST_CODE_TRANSACTION_DETAILS && resultCode == RESULT_OK && data != null) { |
|
|
|
|
if (data.getBooleanExtra(DataListActivity.IntentKey.ITEM_DELETED.keyName, false)) { |
|
|
|
|
deleteSelectedTransaction() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onDestroyView() { |
|
|
|
|
super.onDestroyView() |
|
|
|
|
realmSessions.removeAllChangeListeners() |
|
|
|
|
realmTransactions.removeAllChangeListeners() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) { |
|
|
|
|
when(row) { |
|
|
|
|
when (row) { |
|
|
|
|
is Session -> SessionActivity.newInstance(requireContext(), sessionId = (row as Editable).id) |
|
|
|
|
is Transaction -> EditableDataActivity.newInstance(requireContext(), LiveData.TRANSACTION.ordinal, row.id) |
|
|
|
|
is Transaction -> { |
|
|
|
|
selectedTransaction = row |
|
|
|
|
selectedTransactionPosition = position |
|
|
|
|
EditableDataActivity.newInstanceForResult(this, LiveData.TRANSACTION.ordinal, row.id, REQUEST_CODE_TRANSACTION_DETAILS) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -115,13 +127,15 @@ class FeedFragment : PokerAnalyticsFragment(), RowRepresentableDelegate { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
filterSessions.setOnClickListener { |
|
|
|
|
recyclerView.adapter = this.feedSessionAdapter |
|
|
|
|
filters.setOnCheckedChangeListener(object : ChipGroupExtension.SingleSelectionOnCheckedListener() { |
|
|
|
|
override fun onCheckedChanged(group: ChipGroup, checkedId: Int) { |
|
|
|
|
super.onCheckedChanged(group, checkedId) |
|
|
|
|
when (checkedId) { |
|
|
|
|
R.id.filterSessions -> recyclerView.adapter = feedSessionAdapter |
|
|
|
|
R.id.filterTransactions -> recyclerView.adapter = feedTransactionAdapter |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
filterTransactions.setOnClickListener { |
|
|
|
|
recyclerView.adapter = this.feedTransactionAdapter |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -133,6 +147,7 @@ class FeedFragment : PokerAnalyticsFragment(), RowRepresentableDelegate { |
|
|
|
|
val sdf = SimpleDateFormat("dd/M/yyyy hh:mm", Locale.getDefault()) |
|
|
|
|
betaLimitDate = sdf.parse("17/7/2019 10:00") |
|
|
|
|
|
|
|
|
|
// Sessions |
|
|
|
|
this.realmSessions = getRealm().where<Session>().findAll().sort("startDate", Sort.DESCENDING) |
|
|
|
|
this.realmSessions.addChangeListener { _, _ -> |
|
|
|
|
this.feedSessionAdapter.refreshData() |
|
|
|
|
@ -143,7 +158,13 @@ class FeedFragment : PokerAnalyticsFragment(), RowRepresentableDelegate { |
|
|
|
|
val distinctDateSessions = getRealm().where<Session>().distinct("year", "month").findAll().sort("startDate", Sort.DESCENDING) |
|
|
|
|
this.feedSessionAdapter = FeedSessionRowRepresentableAdapter(this, realmSessions, pendingSessions, distinctDateSessions) |
|
|
|
|
|
|
|
|
|
// Transactions |
|
|
|
|
this.realmTransactions = getRealm().where<Transaction>().findAll().sort("date", Sort.DESCENDING) |
|
|
|
|
this.realmTransactions.addChangeListener { _, _ -> |
|
|
|
|
this.feedTransactionAdapter.refreshData() |
|
|
|
|
this.feedTransactionAdapter.notifyDataSetChanged() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
val distinctDateTransactions = getRealm().where<Transaction>().distinct("year", "month").findAll().sort("date", Sort.DESCENDING) |
|
|
|
|
this.feedTransactionAdapter = FeedTransactionRowRepresentableAdapter(this, realmTransactions, distinctDateTransactions) |
|
|
|
|
|
|
|
|
|
@ -182,6 +203,17 @@ class FeedFragment : PokerAnalyticsFragment(), RowRepresentableDelegate { |
|
|
|
|
EditableDataActivity.newInstance(requireContext(), LiveData.TRANSACTION.ordinal) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Delete selected transaction |
|
|
|
|
*/ |
|
|
|
|
private fun deleteSelectedTransaction() { |
|
|
|
|
val realm = getRealm() |
|
|
|
|
realm.beginTransaction() |
|
|
|
|
selectedTransaction?.deleteFromRealm() |
|
|
|
|
realm.commitTransaction() |
|
|
|
|
selectedTransactionPosition = -1 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Show end of beta message |
|
|
|
|
*/ |
|
|
|
|
|