diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 6edfa7d8..59b888a3 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -129,6 +129,11 @@
android:launchMode="singleTop"
android:screenOrientation="portrait" />
+
+
= RealmList()
- fun delete() {
+ @Ignore
+ override val isClickable: Boolean = false
- this.realm.executeTransaction {
+ @Ignore
+ override val viewType: Int = RowViewType.TITLE_SUBTITLE_ACTION.ordinal
- this.identifiableObjects.forEach {
+ @Ignore
+ override val imageRes: Int? = R.drawable.ic_outline_delete
+
+ @Ignore
+ override val imageClickable: Boolean? = true
+
+ override fun getDisplayName(context: Context): String {
+ return fileName
+ }
+ fun delete() {
+ this.realm.executeTransaction {
+ this.identifiableObjects.forEach {
val realmModel = it.realmModel
when (realmModel) {
is Session -> {
@@ -26,12 +44,9 @@ open class Import : RealmObject() {
}
else -> {}
}
-
realmModel?.deleteFromRealm()
}
-
}
-
}
}
\ No newline at end of file
diff --git a/app/src/main/java/net/pokeranalytics/android/ui/activity/ImportsHistoryActivity.kt b/app/src/main/java/net/pokeranalytics/android/ui/activity/ImportsHistoryActivity.kt
new file mode 100644
index 00000000..3914bca2
--- /dev/null
+++ b/app/src/main/java/net/pokeranalytics/android/ui/activity/ImportsHistoryActivity.kt
@@ -0,0 +1,33 @@
+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
+
+class ImportsHistoryActivity : PokerAnalyticsActivity() {
+
+ companion object {
+ fun newInstance(context: Context) {
+ val intent = Intent(context, ImportsHistoryActivity::class.java)
+ context.startActivity(intent)
+ }
+
+ /**
+ * Create a new instance for result
+ */
+ fun newInstanceForResult(fragment: Fragment, requestCode: Int) {
+ val intent = Intent(fragment.requireContext(), ImportsHistoryActivity::class.java)
+ fragment.startActivityForResult(intent, requestCode)
+ }
+
+ }
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_imports_history)
+ }
+
+}
\ No newline at end of file
diff --git a/app/src/main/java/net/pokeranalytics/android/ui/fragment/ImportsHistoryFragment.kt b/app/src/main/java/net/pokeranalytics/android/ui/fragment/ImportsHistoryFragment.kt
new file mode 100644
index 00000000..ce2beed1
--- /dev/null
+++ b/app/src/main/java/net/pokeranalytics/android/ui/fragment/ImportsHistoryFragment.kt
@@ -0,0 +1,123 @@
+package net.pokeranalytics.android.ui.fragment
+
+import android.os.Bundle
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import androidx.recyclerview.widget.LinearLayoutManager
+import io.realm.RealmResults
+import io.realm.Sort
+import io.realm.kotlin.where
+import kotlinx.android.synthetic.main.fragment_data_list.*
+import net.pokeranalytics.android.BuildConfig
+import net.pokeranalytics.android.R
+import net.pokeranalytics.android.model.realm.Import
+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.extensions.showAlertDialog
+import net.pokeranalytics.android.ui.fragment.components.RealmFragment
+import net.pokeranalytics.android.ui.view.RowRepresentable
+import net.pokeranalytics.android.ui.view.RowViewType
+import net.pokeranalytics.android.util.extensions.shortDateTime
+import java.util.*
+
+class ImportsHistoryFragment : RealmFragment(), StaticRowRepresentableDataSource, RowRepresentableDelegate {
+
+ companion object {
+
+ val rowRepresentation: List by lazy {
+ val rows = ArrayList()
+ //rows.addAll(mostUsedCurrencies)
+ //rows.add(SeparatorRow())
+ //rows.addAll(availableCurrencies)
+ rows
+ }
+
+ }
+
+ private lateinit var dataListAdapter: RowRepresentableAdapter
+ private lateinit var items: RealmResults
+
+ override fun rowRepresentableForPosition(position: Int): RowRepresentable? {
+ return this.items[position] as RowRepresentable
+ }
+
+ override fun numberOfRows(): Int {
+ return items.size
+ }
+
+ override fun viewTypeForPosition(position: Int): Int {
+ val viewType = (this.items[position] as RowRepresentable).viewType
+ return if (viewType != -1) viewType else RowViewType.DATA.ordinal
+ }
+
+ override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
+ super.onCreateView(inflater, container, savedInstanceState)
+ return inflater.inflate(R.layout.fragment_currencies, container, false)
+ }
+
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+ super.onViewCreated(view, savedInstanceState)
+ initData()
+ initUI()
+ }
+
+
+ override fun adapterRows(): List? {
+ return rowRepresentation
+ }
+
+ override fun stringForRow(row: RowRepresentable): String {
+ if (row is Import) {
+ return row.date.shortDateTime()
+ }
+ return super.stringForRow(row)
+ }
+
+ override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) {
+ if (row is Import && fromAction) {
+ showAlertDialog(message = R.string.import_deletion, showCancelButton = true, positiveAction = {
+ //TODO: Check the deletion works correctly
+ row.delete()
+ dataListAdapter.notifyItemRemoved(position)
+ })
+ }
+ }
+
+ private fun initData() {
+ items = getRealm().where().findAll().sort("date", Sort.DESCENDING)
+
+ if (BuildConfig.DEBUG && items.size == 0) {
+ val calendar = Calendar.getInstance()
+ getRealm().executeTransaction {
+ for (i in 0..2) {
+ val import = Import()
+ import.fileName = "Import_${i}_Android.csv"
+ import.date = calendar.time
+ it.copyToRealm(import)
+ calendar.add(Calendar.DAY_OF_MONTH, -1)
+
+ }
+ }
+ }
+ }
+
+ /**
+ * Init UI
+ */
+ private fun initUI() {
+
+ setDisplayHomeAsUpEnabled(true)
+ setToolbarTitle(getString(R.string.imports_history))
+
+ val viewManager = LinearLayoutManager(requireContext())
+ dataListAdapter = RowRepresentableAdapter(this, this)
+
+ recyclerView.apply {
+ setHasFixedSize(true)
+ layoutManager = viewManager
+ adapter = dataListAdapter
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/net/pokeranalytics/android/ui/fragment/SettingsFragment.kt b/app/src/main/java/net/pokeranalytics/android/ui/fragment/SettingsFragment.kt
index 1f679742..170e3e92 100644
--- a/app/src/main/java/net/pokeranalytics/android/ui/fragment/SettingsFragment.kt
+++ b/app/src/main/java/net/pokeranalytics/android/ui/fragment/SettingsFragment.kt
@@ -126,6 +126,7 @@ class SettingsFragment : PokerAnalyticsFragment(), RowRepresentableDelegate, Sta
SettingRow.CONTACT_US -> parentActivity?.openContactMail(R.string.contact)
SettingRow.BUG_REPORT -> parentActivity?.openContactMail(R.string.bug_report_subject, Realm.getDefaultInstance().path)
SettingRow.CURRENCY -> CurrenciesActivity.newInstanceForResult(this@SettingsFragment, RequestCode.CURRENCY.value)
+ SettingRow.IMPORTS_HISTORY -> ImportsHistoryActivity.newInstance(requireContext())
SettingRow.FOLLOW_US -> {
when (position) {
0 -> parentActivity?.openUrl(URL.BLOG.value)
diff --git a/app/src/main/java/net/pokeranalytics/android/ui/view/RowRepresentable.kt b/app/src/main/java/net/pokeranalytics/android/ui/view/RowRepresentable.kt
index 1f6ce50f..7ce3a4c7 100644
--- a/app/src/main/java/net/pokeranalytics/android/ui/view/RowRepresentable.kt
+++ b/app/src/main/java/net/pokeranalytics/android/ui/view/RowRepresentable.kt
@@ -76,6 +76,11 @@ interface Displayable : Localizable {
get() {
return null
}
+
+ val isClickable: Boolean
+ get() {
+ return true
+ }
}
/**
diff --git a/app/src/main/java/net/pokeranalytics/android/ui/view/RowViewType.kt b/app/src/main/java/net/pokeranalytics/android/ui/view/RowViewType.kt
index d0b739f0..f3481082 100644
--- a/app/src/main/java/net/pokeranalytics/android/ui/view/RowViewType.kt
+++ b/app/src/main/java/net/pokeranalytics/android/ui/view/RowViewType.kt
@@ -68,6 +68,7 @@ enum class RowViewType(private var layoutRes: Int) {
TITLE_VALUE(R.layout.row_title_value),
TITLE_VALUE_ARROW(R.layout.row_title_value_arrow),
TITLE_VALUE_ACTION(R.layout.row_title_value_action),
+ TITLE_SUBTITLE_ACTION(R.layout.row_title_subtitle_action),
TITLE_SWITCH(R.layout.row_title_switch),
TITLE_GRID(R.layout.row_bottom_sheet_grid_title),
DATA(R.layout.row_title),
@@ -102,8 +103,8 @@ enum class RowViewType(private var layoutRes: Int) {
// Row View Holder
HEADER_TITLE, HEADER_TITLE_VALUE, HEADER_TITLE_AMOUNT, HEADER_TITLE_AMOUNT_BIG, LOCATION_TITLE,
- INFO, TITLE, TITLE_ARROW, TITLE_ICON_ARROW, TITLE_VALUE, TITLE_VALUE_ARROW, TITLE_VALUE_ACTION, TITLE_GRID,
- TITLE_SWITCH, TITLE_CHECK, TITLE_VALUE_CHECK,
+ INFO, TITLE, TITLE_ARROW, TITLE_ICON_ARROW, TITLE_VALUE, TITLE_VALUE_ARROW, TITLE_VALUE_ACTION, TITLE_SUBTITLE_ACTION,
+ TITLE_GRID, TITLE_SWITCH, TITLE_CHECK, TITLE_VALUE_CHECK,
DATA, BOTTOM_SHEET_DATA, LOADER -> RowViewHolder(layout)
// Row Session
@@ -244,18 +245,20 @@ enum class RowViewType(private var layoutRes: Int) {
}
// Listener
- val listener = View.OnClickListener {
- itemView.findViewById(R.id.switchView)?.let {
- if (adapter.dataSource.isEnabled(row)) {
- it.isChecked = !it.isChecked
+ if (row.isClickable) {
+ val listener = View.OnClickListener {
+ itemView.findViewById(R.id.switchView)?.let {
+ if (adapter.dataSource.isEnabled(row)) {
+ it.isChecked = !it.isChecked
+ }
+ } ?: run {
+ adapter.delegate?.onRowSelected(position, row)
}
- } ?: run {
- adapter.delegate?.onRowSelected(position, row)
}
- }
- itemView.findViewById(R.id.container)?.setOnClickListener(listener)
- }
+ itemView.findViewById(R.id.container)?.setOnClickListener(listener)
+ }
+ }
}
// Switch
diff --git a/app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/SettingRow.kt b/app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/SettingRow.kt
index 5ed0d293..a859caa9 100644
--- a/app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/SettingRow.kt
+++ b/app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/SettingRow.kt
@@ -26,6 +26,9 @@ enum class SettingRow : RowRepresentable {
LANGUAGE,
CURRENCY,
+ // Import & Export
+ IMPORTS_HISTORY,
+
// Data management
CUSTOM_FIELD,
BANKROLL,
@@ -62,6 +65,9 @@ enum class SettingRow : RowRepresentable {
rows.add(CustomizableRowRepresentable(customViewType = RowViewType.HEADER_TITLE, resId = R.string.preferences))
rows.addAll(arrayListOf(CURRENCY))
+ rows.add(CustomizableRowRepresentable(customViewType = RowViewType.HEADER_TITLE, resId = R.string.data))
+ rows.addAll(arrayListOf(IMPORTS_HISTORY))
+
rows.add(
CustomizableRowRepresentable(
customViewType = RowViewType.HEADER_TITLE,
@@ -95,6 +101,7 @@ enum class SettingRow : RowRepresentable {
TERMS_OF_USE -> R.string.terms_of_use
FOLLOW_US -> R.string.follow_us
LANGUAGE -> R.string.language
+ IMPORTS_HISTORY -> R.string.imports_history
CURRENCY -> R.string.currency
GDPR -> R.string.gdpr
else -> null
diff --git a/app/src/main/res/layout/activity_imports_history.xml b/app/src/main/res/layout/activity_imports_history.xml
new file mode 100644
index 00000000..61e6a407
--- /dev/null
+++ b/app/src/main/res/layout/activity_imports_history.xml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/fragment_imports_history.xml b/app/src/main/res/layout/fragment_imports_history.xml
new file mode 100644
index 00000000..bab049a9
--- /dev/null
+++ b/app/src/main/res/layout/fragment_imports_history.xml
@@ -0,0 +1,61 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/row_title_subtitle_action.xml b/app/src/main/res/layout/row_title_subtitle_action.xml
new file mode 100644
index 00000000..88087588
--- /dev/null
+++ b/app/src/main/res/layout/row_title_subtitle_action.xml
@@ -0,0 +1,74 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+