|
|
|
@ -1,4 +1,4 @@ |
|
|
|
package net.pokeranalytics.android.ui.adapter |
|
|
|
package net.pokeranalytics.android.ui.modules.feed |
|
|
|
|
|
|
|
|
|
|
|
import android.view.LayoutInflater |
|
|
|
import android.view.LayoutInflater |
|
|
|
import android.view.View |
|
|
|
import android.view.View |
|
|
|
@ -9,10 +9,13 @@ import io.realm.RealmResults |
|
|
|
import net.pokeranalytics.android.R |
|
|
|
import net.pokeranalytics.android.R |
|
|
|
import net.pokeranalytics.android.exceptions.PAIllegalStateException |
|
|
|
import net.pokeranalytics.android.exceptions.PAIllegalStateException |
|
|
|
import net.pokeranalytics.android.model.realm.handhistory.HandHistory |
|
|
|
import net.pokeranalytics.android.model.realm.handhistory.HandHistory |
|
|
|
|
|
|
|
import net.pokeranalytics.android.ui.adapter.BindableHolder |
|
|
|
|
|
|
|
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate |
|
|
|
import net.pokeranalytics.android.ui.modules.handhistory.views.RowHandHistoryViewHolder |
|
|
|
import net.pokeranalytics.android.ui.modules.handhistory.views.RowHandHistoryViewHolder |
|
|
|
import net.pokeranalytics.android.ui.view.RowViewType |
|
|
|
import net.pokeranalytics.android.ui.view.RowViewType |
|
|
|
import net.pokeranalytics.android.util.NULL_TEXT |
|
|
|
import net.pokeranalytics.android.util.NULL_TEXT |
|
|
|
import net.pokeranalytics.android.util.extensions.getMonthAndYear |
|
|
|
import net.pokeranalytics.android.util.extensions.fullDate |
|
|
|
|
|
|
|
import net.pokeranalytics.android.util.extensions.longDate |
|
|
|
import java.util.* |
|
|
|
import java.util.* |
|
|
|
import kotlin.collections.HashMap |
|
|
|
import kotlin.collections.HashMap |
|
|
|
|
|
|
|
|
|
|
|
@ -35,28 +38,6 @@ class FeedHandHistoryRowRepresentableAdapter( |
|
|
|
refreshData() |
|
|
|
refreshData() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// inner class RowHandHistoryViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), |
|
|
|
|
|
|
|
// BindableHolder { |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
//// override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) { |
|
|
|
|
|
|
|
//// itemView.handHistoryRow.setData(row as HandHistory) |
|
|
|
|
|
|
|
//// val listener = View.OnClickListener { |
|
|
|
|
|
|
|
//// adapter.delegate?.onRowSelected(position, row) |
|
|
|
|
|
|
|
//// } |
|
|
|
|
|
|
|
//// itemView.handHistoryRow.setOnClickListener(listener) |
|
|
|
|
|
|
|
//// } |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// fun bind(position: Int, row: HandHistory?, adapter: FeedHandHistoryRowRepresentableAdapter) { |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// itemView.handHistoryRow.setData(row as HandHistory) |
|
|
|
|
|
|
|
// val listener = View.OnClickListener { |
|
|
|
|
|
|
|
// adapter.delegate?.onRowSelected(position, row) |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// itemView.handHistoryRow.setOnClickListener(listener) |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Display a header |
|
|
|
* Display a header |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@ -85,7 +66,6 @@ class FeedHandHistoryRowRepresentableAdapter( |
|
|
|
return if (this.sortedHeaders.containsKey(position)) { |
|
|
|
return if (this.sortedHeaders.containsKey(position)) { |
|
|
|
RowViewType.HEADER_TITLE.ordinal |
|
|
|
RowViewType.HEADER_TITLE.ordinal |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
// 1 |
|
|
|
|
|
|
|
RowViewType.HAND_HISTORY.ordinal |
|
|
|
RowViewType.HAND_HISTORY.ordinal |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -109,7 +89,7 @@ class FeedHandHistoryRowRepresentableAdapter( |
|
|
|
private fun getHeaderForPosition(position: Int): String { |
|
|
|
private fun getHeaderForPosition(position: Int): String { |
|
|
|
if (this.sortedHeaders.containsKey(position)) { |
|
|
|
if (this.sortedHeaders.containsKey(position)) { |
|
|
|
val realmHeaderPosition = this.sortedHeaders.keys.indexOf(position) |
|
|
|
val realmHeaderPosition = this.sortedHeaders.keys.indexOf(position) |
|
|
|
return this.distinctHandHistoryHeaders[realmHeaderPosition]?.date?.getMonthAndYear() ?: "" |
|
|
|
return this.distinctHandHistoryHeaders[realmHeaderPosition]?.date?.longDate() ?: "" |
|
|
|
} |
|
|
|
} |
|
|
|
return NULL_TEXT |
|
|
|
return NULL_TEXT |
|
|
|
} |
|
|
|
} |
|
|
|
@ -141,16 +121,18 @@ class FeedHandHistoryRowRepresentableAdapter( |
|
|
|
|
|
|
|
|
|
|
|
var previousYear = Int.MAX_VALUE |
|
|
|
var previousYear = Int.MAX_VALUE |
|
|
|
var previousMonth = Int.MAX_VALUE |
|
|
|
var previousMonth = Int.MAX_VALUE |
|
|
|
|
|
|
|
var previousDay = Int.MAX_VALUE |
|
|
|
|
|
|
|
|
|
|
|
val calendar = Calendar.getInstance() |
|
|
|
val calendar = Calendar.getInstance() |
|
|
|
|
|
|
|
|
|
|
|
// Add headers if the date doesn't exist yet |
|
|
|
// Add headers if the date doesn't exist yet |
|
|
|
for ((index, handHistory) in this.realmHandHistories.withIndex()) { |
|
|
|
for ((index, handHistory) in this.realmHandHistories.withIndex()) { |
|
|
|
calendar.time = handHistory.date |
|
|
|
calendar.time = handHistory.date |
|
|
|
if (checkHeaderCondition(calendar, previousYear, previousMonth)) { |
|
|
|
if (checkHeaderCondition(calendar, previousYear, previousMonth, previousDay)) { |
|
|
|
this.headersPositions[index + this.headersPositions.size] = handHistory.date |
|
|
|
this.headersPositions[index + this.headersPositions.size] = handHistory.date |
|
|
|
previousYear = calendar.get(Calendar.YEAR) |
|
|
|
previousYear = calendar.get(Calendar.YEAR) |
|
|
|
previousMonth = calendar.get(Calendar.MONTH) |
|
|
|
previousMonth = calendar.get(Calendar.MONTH) |
|
|
|
|
|
|
|
previousDay = calendar.get(Calendar.DAY_OF_MONTH) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -163,9 +145,15 @@ class FeedHandHistoryRowRepresentableAdapter( |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Check if we need to add a header |
|
|
|
* Check if we need to add a header |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private fun checkHeaderCondition(currentCalendar: Calendar, previousYear: Int, previousMonth: Int): Boolean { |
|
|
|
private fun checkHeaderCondition(currentCalendar: Calendar, previousYear: Int, previousMonth: Int, previousDay: Int): Boolean { |
|
|
|
return currentCalendar.get(Calendar.YEAR) == previousYear && currentCalendar.get(Calendar.MONTH) < previousMonth || (currentCalendar.get( |
|
|
|
|
|
|
|
Calendar.YEAR) < previousYear) |
|
|
|
val year = currentCalendar.get(Calendar.YEAR) |
|
|
|
|
|
|
|
val month = currentCalendar.get(Calendar.MONTH) |
|
|
|
|
|
|
|
val day = currentCalendar.get(Calendar.DAY_OF_MONTH) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (year == previousYear && month == previousMonth && day < previousDay) |
|
|
|
|
|
|
|
|| (year == previousYear && month < previousMonth) |
|
|
|
|
|
|
|
|| year < previousYear |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|