parent
68c855e825
commit
be4c4bd306
@ -0,0 +1,59 @@ |
|||||||
|
package net.pokeranalytics.android.ui.activity |
||||||
|
|
||||||
|
import android.content.Context |
||||||
|
import android.content.Intent |
||||||
|
import android.os.Bundle |
||||||
|
import androidx.fragment.app.Fragment |
||||||
|
import net.pokeranalytics.android.R |
||||||
|
import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity |
||||||
|
import net.pokeranalytics.android.ui.fragment.FilterDataFragment |
||||||
|
|
||||||
|
class FilterActivity : PokerAnalyticsActivity() { |
||||||
|
|
||||||
|
enum class IntentKey(val keyName: String) { |
||||||
|
DATA_TYPE("DATA_TYPE"), |
||||||
|
PRIMARY_KEY("PRIMARY_KEY"); |
||||||
|
} |
||||||
|
|
||||||
|
companion object { |
||||||
|
/** |
||||||
|
* Default constructor |
||||||
|
*/ |
||||||
|
fun newInstance(context: Context) { |
||||||
|
val intent = Intent(context, FilterActivity::class.java) |
||||||
|
context.startActivity(intent) |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Create a new instance for result |
||||||
|
*/ |
||||||
|
fun newInstanceForResult(fragment: Fragment, requestCode: Int) { |
||||||
|
val intent = Intent(fragment.requireContext(), FilterActivity::class.java) |
||||||
|
fragment.startActivityForResult(intent, requestCode) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) { |
||||||
|
super.onCreate(savedInstanceState) |
||||||
|
setContentView(R.layout.activity_filter) |
||||||
|
initUI() |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Init UI |
||||||
|
*/ |
||||||
|
private fun initUI() { |
||||||
|
|
||||||
|
val fragmentManager = supportFragmentManager |
||||||
|
val fragmentTransaction = fragmentManager.beginTransaction() |
||||||
|
|
||||||
|
val fragment = FilterDataFragment() |
||||||
|
fragmentTransaction.add(R.id.container, fragment) |
||||||
|
fragmentTransaction.commit() |
||||||
|
//fragment.setData(dataType, primaryKey) |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,210 @@ |
|||||||
|
package net.pokeranalytics.android.ui.fragment |
||||||
|
|
||||||
|
import android.os.Bundle |
||||||
|
import android.view.* |
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager |
||||||
|
import io.realm.RealmObject |
||||||
|
import kotlinx.android.synthetic.main.fragment_editable_data.* |
||||||
|
import kotlinx.android.synthetic.main.fragment_filter.view.* |
||||||
|
import net.pokeranalytics.android.R |
||||||
|
import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity |
||||||
|
import net.pokeranalytics.android.ui.adapter.RowRepresentableAdapter |
||||||
|
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate |
||||||
|
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource |
||||||
|
import net.pokeranalytics.android.ui.fragment.components.PokerAnalyticsFragment |
||||||
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
||||||
|
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterRow |
||||||
|
|
||||||
|
|
||||||
|
open class FilterDataFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSource, RowRepresentableDelegate { |
||||||
|
|
||||||
|
lateinit var parentActivity: PokerAnalyticsActivity |
||||||
|
lateinit var item: RealmObject |
||||||
|
lateinit var rowRepresentableAdapter: RowRepresentableAdapter |
||||||
|
|
||||||
|
|
||||||
|
private var rows: ArrayList<RowRepresentable> = ArrayList() |
||||||
|
private var filterMenu: Menu? = null |
||||||
|
private var dataType: Int? = null |
||||||
|
private var primaryKey: String? = null |
||||||
|
|
||||||
|
var isUpdating = false |
||||||
|
var shouldOpenKeyboard = true |
||||||
|
|
||||||
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { |
||||||
|
return inflater.inflate(R.layout.fragment_filter, container, false) |
||||||
|
} |
||||||
|
|
||||||
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
||||||
|
super.onViewCreated(view, savedInstanceState) |
||||||
|
initUI() |
||||||
|
initData() |
||||||
|
} |
||||||
|
|
||||||
|
override fun onCreateOptionsMenu(menu: Menu?, inflater: MenuInflater?) { |
||||||
|
/* |
||||||
|
inflater?.inflate(R.menu.editable_data, menu) |
||||||
|
this.filterMenu = menu |
||||||
|
*/ |
||||||
|
updateMenuUI() |
||||||
|
super.onCreateOptionsMenu(menu, inflater) |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
override fun onOptionsItemSelected(item: MenuItem?): Boolean { |
||||||
|
when (item!!.itemId) { |
||||||
|
R.id.save -> saveData() |
||||||
|
R.id.delete -> deleteData() |
||||||
|
} |
||||||
|
return true |
||||||
|
} |
||||||
|
|
||||||
|
override fun adapterRows(): List<RowRepresentable>? { |
||||||
|
return rows |
||||||
|
} |
||||||
|
|
||||||
|
override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) { |
||||||
|
super.onRowSelected(position, row, fromAction) |
||||||
|
} |
||||||
|
|
||||||
|
override fun onRowValueChanged(value: Any?, row: RowRepresentable) { |
||||||
|
super.onRowValueChanged(value, row) |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Init UI |
||||||
|
*/ |
||||||
|
private fun initUI() { |
||||||
|
parentActivity = activity as PokerAnalyticsActivity |
||||||
|
parentActivity.setSupportActionBar(toolbar) |
||||||
|
parentActivity.supportActionBar?.setDisplayHomeAsUpEnabled(true) |
||||||
|
setHasOptionsMenu(true) |
||||||
|
|
||||||
|
val viewManager = LinearLayoutManager(requireContext()) |
||||||
|
|
||||||
|
recyclerView.apply { |
||||||
|
setHasFixedSize(true) |
||||||
|
layoutManager = viewManager |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Init data |
||||||
|
*/ |
||||||
|
private fun initData() { |
||||||
|
|
||||||
|
this.appBar.toolbar.title = getString(R.string.filter) |
||||||
|
|
||||||
|
rows.addAll(FilterRow.values()) |
||||||
|
|
||||||
|
this.rowRepresentableAdapter = RowRepresentableAdapter(this, this) |
||||||
|
this.recyclerView.adapter = rowRepresentableAdapter |
||||||
|
|
||||||
|
/* |
||||||
|
if (this.dataType != null) { |
||||||
|
val proxyItem: RealmObject? = this.liveDataType.getData(this.getRealm(), primaryKey) |
||||||
|
proxyItem?.let { |
||||||
|
//TODO: Localize |
||||||
|
this.appBar.toolbar.title = "Update ${this.liveDataType.localizedTitle(this.parentActivity).toLowerCase().capitalize()}" |
||||||
|
isUpdating = true |
||||||
|
} ?: run { |
||||||
|
//TODO: Localize |
||||||
|
this.appBar.toolbar.title = this.liveDataType.newEntityLocalizedTitle(requireContext()) |
||||||
|
} |
||||||
|
this.item = this.liveDataType.updateOrCreate(this.getRealm(), primaryKey) |
||||||
|
|
||||||
|
val dataSource = getDataSource() |
||||||
|
this.rowRepresentableAdapter = RowRepresentableAdapter(getDataSource(), this) |
||||||
|
this.recyclerView.adapter = rowRepresentableAdapter |
||||||
|
|
||||||
|
// When creating an object, open automatically the keyboard for the first row |
||||||
|
if (!isUpdating && shouldOpenKeyboard) { |
||||||
|
val row = dataSource.adapterRows()?.firstOrNull() |
||||||
|
row?.let { |
||||||
|
onRowSelected(0, it) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
*/ |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Update menu UI |
||||||
|
*/ |
||||||
|
private fun updateMenuUI() { |
||||||
|
/* |
||||||
|
editableMenu?.findItem(R.id.delete)?.isVisible = isUpdating |
||||||
|
editableMenu?.findItem(R.id.save)?.isVisible = true |
||||||
|
*/ |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Save data |
||||||
|
*/ |
||||||
|
fun saveData() { |
||||||
|
/* |
||||||
|
if ((this.item as Savable).isValidForSave()) { |
||||||
|
this.getRealm().executeTransaction { |
||||||
|
val item = it.copyToRealmOrUpdate(this.item) |
||||||
|
|
||||||
|
val uniqueIdentifier = if (item is Identifiable) { |
||||||
|
item.id |
||||||
|
} else "" |
||||||
|
|
||||||
|
finishActivityWithResult(uniqueIdentifier) |
||||||
|
} |
||||||
|
} else { |
||||||
|
val message = (this.item as Savable).getFailedSaveMessage() |
||||||
|
val builder = AlertDialog.Builder(requireContext()) |
||||||
|
.setMessage(message) |
||||||
|
.setNegativeButton(R.string.ok, null) |
||||||
|
builder.show() |
||||||
|
} |
||||||
|
*/ |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Delete data |
||||||
|
*/ |
||||||
|
private fun deleteData() { |
||||||
|
/* |
||||||
|
val builder = AlertDialog.Builder(requireContext()) |
||||||
|
builder.setTitle(R.string.warning) |
||||||
|
.setMessage(R.string.are_you_sure_you_want_to_do_that_) |
||||||
|
.setNegativeButton(R.string.no, null) |
||||||
|
.setPositiveButton(R.string.yes) { _, _ -> |
||||||
|
//TODO: Maybe update this code, does the object need to be managed? |
||||||
|
this.getRealm().executeTransaction { |
||||||
|
this.liveDataType.deleteData(it, (this.item as Manageable)) |
||||||
|
} |
||||||
|
this.activity?.finish() |
||||||
|
} |
||||||
|
builder.show() |
||||||
|
*/ |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Finish the activity with a result |
||||||
|
*/ |
||||||
|
private fun finishActivityWithResult(uniqueIdentifier: String) { |
||||||
|
/* |
||||||
|
val intent = Intent() |
||||||
|
intent.putExtra(EditableDataActivity.IntentKey.DATA_TYPE.keyName, dataType) |
||||||
|
intent.putExtra(EditableDataActivity.IntentKey.PRIMARY_KEY.keyName, uniqueIdentifier) |
||||||
|
activity?.setResult(RESULT_OK, intent) |
||||||
|
*/ |
||||||
|
activity?.finish() |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set fragment data |
||||||
|
*/ |
||||||
|
fun setData(dataType: Int, primaryKey: String?) { |
||||||
|
/* |
||||||
|
this.dataType = dataType |
||||||
|
this.liveDataType = LiveData.values()[dataType] |
||||||
|
this.primaryKey = primaryKey |
||||||
|
*/ |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,50 @@ |
|||||||
|
package net.pokeranalytics.android.ui.view.rowrepresentable |
||||||
|
|
||||||
|
import net.pokeranalytics.android.R |
||||||
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
||||||
|
import net.pokeranalytics.android.ui.view.RowViewType |
||||||
|
|
||||||
|
enum class FilterRow : RowRepresentable { |
||||||
|
|
||||||
|
GENERAL, |
||||||
|
DATE, |
||||||
|
DURATION, |
||||||
|
SESSION, |
||||||
|
CASH, |
||||||
|
TOURNAMENT, |
||||||
|
ONLINE, |
||||||
|
RESULT, |
||||||
|
TRANSACTION_TYPES, |
||||||
|
|
||||||
|
// Title Custom fields |
||||||
|
LOCATION, |
||||||
|
BANKROLL, |
||||||
|
PLAYERS; |
||||||
|
|
||||||
|
override val resId: Int? |
||||||
|
get() { |
||||||
|
return when (this) { |
||||||
|
GENERAL -> R.string.general |
||||||
|
DATE -> R.string.date |
||||||
|
DURATION -> R.string.duration |
||||||
|
SESSION -> R.string.session |
||||||
|
CASH -> R.string.cash |
||||||
|
TOURNAMENT -> R.string.tournament |
||||||
|
ONLINE -> R.string.online |
||||||
|
RESULT -> R.string.result |
||||||
|
TRANSACTION_TYPES -> R.string.operation_types |
||||||
|
LOCATION -> R.string.location |
||||||
|
BANKROLL -> R.string.bankroll |
||||||
|
PLAYERS -> R.string.players |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override val viewType: Int |
||||||
|
get() { |
||||||
|
return when (this) { |
||||||
|
GENERAL, DATE, DURATION, SESSION, CASH, TOURNAMENT, ONLINE, RESULT, TRANSACTION_TYPES, |
||||||
|
LOCATION, BANKROLL, PLAYERS -> RowViewType.TITLE_VALUE_ARROW.ordinal |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,7 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
|
android:id="@+id/container" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="match_parent"> |
||||||
|
|
||||||
|
</FrameLayout> |
||||||
@ -0,0 +1,61 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||||
|
xmlns:tools="http://schemas.android.com/tools" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="match_parent"> |
||||||
|
|
||||||
|
<androidx.core.widget.NestedScrollView |
||||||
|
android:id="@+id/nestedScrollView" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="match_parent" |
||||||
|
android:fillViewport="true" |
||||||
|
app:layout_behavior="@string/appbar_scrolling_view_behavior"> |
||||||
|
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="wrap_content"> |
||||||
|
|
||||||
|
<androidx.recyclerview.widget.RecyclerView |
||||||
|
android:id="@+id/recyclerView" |
||||||
|
android:layout_width="0dp" |
||||||
|
android:layout_height="0dp" |
||||||
|
app:layout_constraintBottom_toBottomOf="parent" |
||||||
|
app:layout_constraintEnd_toEndOf="parent" |
||||||
|
app:layout_constraintStart_toStartOf="parent" |
||||||
|
app:layout_constraintTop_toTopOf="parent" /> |
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout> |
||||||
|
|
||||||
|
</androidx.core.widget.NestedScrollView> |
||||||
|
|
||||||
|
<com.google.android.material.appbar.AppBarLayout |
||||||
|
android:id="@+id/appBar" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="128dp" |
||||||
|
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> |
||||||
|
|
||||||
|
<com.google.android.material.appbar.CollapsingToolbarLayout |
||||||
|
android:id="@+id/collapsingToolbar" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="match_parent" |
||||||
|
app:collapsedTitleTextAppearance="@style/PokerAnalyticsTheme.Toolbar.CollapsedTitleAppearance" |
||||||
|
app:contentScrim="?attr/colorPrimary" |
||||||
|
app:expandedTitleGravity="bottom" |
||||||
|
app:expandedTitleMarginStart="72dp" |
||||||
|
app:expandedTitleTextAppearance="@style/PokerAnalyticsTheme.Toolbar.ExpandedTitleAppearance" |
||||||
|
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"> |
||||||
|
|
||||||
|
<androidx.appcompat.widget.Toolbar |
||||||
|
android:id="@+id/toolbar" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="?attr/actionBarSize" |
||||||
|
app:layout_collapseMode="pin" |
||||||
|
app:title="Poker Analytics" |
||||||
|
app:titleTextColor="@color/white" /> |
||||||
|
|
||||||
|
</com.google.android.material.appbar.CollapsingToolbarLayout> |
||||||
|
|
||||||
|
</com.google.android.material.appbar.AppBarLayout> |
||||||
|
|
||||||
|
</androidx.coordinatorlayout.widget.CoordinatorLayout> |
||||||
@ -0,0 +1,11 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"> |
||||||
|
|
||||||
|
<item |
||||||
|
android:id="@+id/filter" |
||||||
|
android:icon="@drawable/ic_outline_filter_list" |
||||||
|
android:title="@string/filter" |
||||||
|
app:showAsAction="always" /> |
||||||
|
|
||||||
|
</menu> |
||||||
Loading…
Reference in new issue