Fix issue & warnings for lint and CI

dev
Aurelien Hubert 7 years ago
parent 2b8476227f
commit 17b27f085b
  1. 10
      app/src/main/java/net/pokeranalytics/android/ui/adapter/FeedSessionRowRepresentableAdapter.kt
  2. 13
      app/src/main/java/net/pokeranalytics/android/ui/adapter/FeedTransactionRowRepresentableAdapter.kt
  3. 1
      app/src/main/java/net/pokeranalytics/android/ui/fragment/FeedFragment.kt
  4. 10
      app/src/main/java/net/pokeranalytics/android/ui/fragment/SessionFragment.kt
  5. 65
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetType.kt
  6. 6
      app/src/main/java/net/pokeranalytics/android/ui/view/HistorySessionDiffCallback.kt
  7. 1
      app/src/main/java/net/pokeranalytics/android/ui/view/RowViewType.kt
  8. 1
      app/src/main/java/net/pokeranalytics/android/util/extensions/DateExtension.kt

@ -57,7 +57,7 @@ class FeedSessionRowRepresentableAdapter(
* Display a session view * Display a session view
*/ */
inner class HeaderTitleViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), BindableHolder { inner class HeaderTitleViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), BindableHolder {
fun bind(position: Int, title: String, adapter: FeedSessionRowRepresentableAdapter) { fun bind(title: String) {
// Title // Title
itemView.findViewById<AppCompatTextView>(R.id.title)?.let { itemView.findViewById<AppCompatTextView>(R.id.title)?.let {
it.text = title it.text = title
@ -66,12 +66,12 @@ class FeedSessionRowRepresentableAdapter(
} }
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
if (viewType == RowViewType.ROW_SESSION.ordinal) { return if (viewType == RowViewType.ROW_SESSION.ordinal) {
val layout = LayoutInflater.from(parent.context).inflate(R.layout.row_feed_session, parent, false) val layout = LayoutInflater.from(parent.context).inflate(R.layout.row_feed_session, parent, false)
return RowSessionViewHolder(layout) RowSessionViewHolder(layout)
} else { } else {
val layout = LayoutInflater.from(parent.context).inflate(R.layout.row_header_title, parent, false) val layout = LayoutInflater.from(parent.context).inflate(R.layout.row_header_title, parent, false)
return HeaderTitleViewHolder(layout) HeaderTitleViewHolder(layout)
} }
} }
@ -93,7 +93,7 @@ class FeedSessionRowRepresentableAdapter(
if (holder is RowSessionViewHolder) { if (holder is RowSessionViewHolder) {
holder.bind(position, getSessionForPosition(position), this) holder.bind(position, getSessionForPosition(position), this)
} else if (holder is HeaderTitleViewHolder) { } else if (holder is HeaderTitleViewHolder) {
holder.bind(position, getHeaderForPosition(holder.itemView.context, position), this) holder.bind(getHeaderForPosition(holder.itemView.context, position))
} }
} }

@ -1,6 +1,5 @@
package net.pokeranalytics.android.ui.adapter package net.pokeranalytics.android.ui.adapter
import android.content.Context
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
@ -56,7 +55,7 @@ class FeedTransactionRowRepresentableAdapter(
* Display a header * Display a header
*/ */
inner class HeaderTitleViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), BindableHolder { inner class HeaderTitleViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), BindableHolder {
fun bind(position: Int, title: String, adapter: FeedTransactionRowRepresentableAdapter) { fun bind(title: String) {
// Title // Title
itemView.findViewById<AppCompatTextView>(R.id.title)?.let { itemView.findViewById<AppCompatTextView>(R.id.title)?.let {
it.text = title it.text = title
@ -65,12 +64,12 @@ class FeedTransactionRowRepresentableAdapter(
} }
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
if (viewType == RowViewType.ROW_TRANSACTION.ordinal) { return if (viewType == RowViewType.ROW_TRANSACTION.ordinal) {
val layout = LayoutInflater.from(parent.context).inflate(R.layout.row_transaction, parent, false) val layout = LayoutInflater.from(parent.context).inflate(R.layout.row_transaction, parent, false)
return RowTransactionViewHolder(layout) RowTransactionViewHolder(layout)
} else { } else {
val layout = LayoutInflater.from(parent.context).inflate(R.layout.row_header_title, parent, false) val layout = LayoutInflater.from(parent.context).inflate(R.layout.row_header_title, parent, false)
return HeaderTitleViewHolder(layout) HeaderTitleViewHolder(layout)
} }
} }
@ -92,14 +91,14 @@ class FeedTransactionRowRepresentableAdapter(
if (holder is RowTransactionViewHolder) { if (holder is RowTransactionViewHolder) {
holder.bind(position, getTransactionForPosition(position), this) holder.bind(position, getTransactionForPosition(position), this)
} else if (holder is HeaderTitleViewHolder) { } else if (holder is HeaderTitleViewHolder) {
holder.bind(position, getHeaderForPosition(holder.itemView.context, position), this) holder.bind(getHeaderForPosition(position))
} }
} }
/** /**
* Return the header * Return the header
*/ */
private fun getHeaderForPosition(context: Context, position: Int): String { private fun getHeaderForPosition(position: Int): String {
if (sortedHeaders.containsKey(position)) { if (sortedHeaders.containsKey(position)) {
val realmHeaderPosition = sortedHeaders.keys.indexOf(position) val realmHeaderPosition = sortedHeaders.keys.indexOf(position)
return distinctTransactionsHeaders[realmHeaderPosition]?.date?.getMonthAndYear() ?: "" return distinctTransactionsHeaders[realmHeaderPosition]?.date?.getMonthAndYear() ?: ""

@ -139,7 +139,6 @@ class FeedFragment : PokerAnalyticsFragment(), RowRepresentableDelegate {
this.feedSessionAdapter.notifyDataSetChanged() this.feedSessionAdapter.notifyDataSetChanged()
} }
val startedSessions = getRealm().where<Session>().isNotNull("year").isNotNull("month").findAll().sort("startDate", Sort.DESCENDING)
val pendingSessions = getRealm().where<Session>().isNull("year").isNull("month").findAll().sort("startDate", Sort.DESCENDING) val pendingSessions = getRealm().where<Session>().isNull("year").isNull("month").findAll().sort("startDate", Sort.DESCENDING)
val distinctDateSessions = getRealm().where<Session>().distinct("year", "month").findAll().sort("startDate", Sort.DESCENDING) val distinctDateSessions = getRealm().where<Session>().distinct("year", "month").findAll().sort("startDate", Sort.DESCENDING)
this.feedSessionAdapter = FeedSessionRowRepresentableAdapter(this, realmSessions, pendingSessions, distinctDateSessions) this.feedSessionAdapter = FeedSessionRowRepresentableAdapter(this, realmSessions, pendingSessions, distinctDateSessions)

@ -314,13 +314,13 @@ class SessionFragment : PokerAnalyticsFragment(), RowRepresentableDelegate {
realm.commitTransaction() realm.commitTransaction()
// Find the nearest location around the user // Find the nearest location around the user
parentActivity.findNearestLocation { location -> parentActivity.findNearestLocation {
location?.let { it?.let { location ->
realm.beginTransaction() realm.beginTransaction()
val location = realm.where<Location>().equalTo("id", it.id).findFirst() val realmLocation = realm.where<Location>().equalTo("id", location.id).findFirst()
FavoriteSessionFinder.copyParametersFromFavoriteSession(currentSession, location, requireContext()) FavoriteSessionFinder.copyParametersFromFavoriteSession(currentSession, realmLocation, requireContext())
currentSession.location = location currentSession.location = realmLocation
realm.commitTransaction() realm.commitTransaction()
updateSessionUI(true) updateSessionUI(true)
} }

@ -1,33 +1,48 @@
package net.pokeranalytics.android.ui.fragment.components.bottomsheet package net.pokeranalytics.android.ui.fragment.components.bottomsheet
enum class BottomSheetType { enum class BottomSheetType {
NONE { override fun newInstance() = BottomSheetFragment()}, NONE,
LIST { override fun newInstance() = BottomSheetListFragment()}, LIST,
LIST_STATIC { override fun newInstance() = BottomSheetStaticListFragment()}, LIST_STATIC,
LIST_GAME { override fun newInstance() = BottomSheetListGameFragment()}, LIST_GAME,
DOUBLE_LIST { override fun newInstance() = BottomSheetListGameFragment()}, DOUBLE_LIST,
MULTI_SELECTION { override fun newInstance() = BottomSheetMultiSelectionFragment()}, MULTI_SELECTION,
GRID { override fun newInstance() = BottomSheetTableSizeGridFragment()}, GRID,
EDIT_TEXT { override fun newInstance() = BottomSheetEditTextFragment()}, EDIT_TEXT,
EDIT_TEXT_MULTI_LINES { override fun newInstance() = BottomSheetEditTextMultiLinesFragment()}, EDIT_TEXT_MULTI_LINES,
DOUBLE_EDIT_TEXT { override fun newInstance() = BottomSheetDoubleEditTextFragment()}, DOUBLE_EDIT_TEXT,
NUMERIC_TEXT { override fun newInstance() = BottomSheetNumericTextFragment()}, NUMERIC_TEXT,
SUM { override fun newInstance() = BottomSheetSumFragment()}; SUM;
abstract fun newInstance(): BottomSheetFragment fun newInstance(): BottomSheetFragment {
return when (this) {
NONE -> BottomSheetFragment()
LIST -> BottomSheetListFragment()
LIST_STATIC -> BottomSheetStaticListFragment()
LIST_GAME -> BottomSheetListGameFragment()
DOUBLE_LIST -> BottomSheetListGameFragment()
MULTI_SELECTION -> BottomSheetMultiSelectionFragment()
GRID -> BottomSheetTableSizeGridFragment()
EDIT_TEXT -> BottomSheetEditTextFragment()
EDIT_TEXT_MULTI_LINES -> BottomSheetEditTextMultiLinesFragment()
DOUBLE_EDIT_TEXT -> BottomSheetDoubleEditTextFragment()
NUMERIC_TEXT -> BottomSheetNumericTextFragment()
SUM -> BottomSheetSumFragment()
}
}
val validationRequired : Boolean val validationRequired: Boolean
get() = when (this) { get() = when (this) {
LIST, LIST_GAME, LIST_STATIC, GRID, DOUBLE_LIST -> false LIST, LIST_GAME, LIST_STATIC, GRID, DOUBLE_LIST -> false
else -> true else -> true
} }
val clearRequired : Boolean val clearRequired: Boolean
get() = true get() = true
val addRequired : Boolean val addRequired: Boolean
get() = when (this) { get() = when (this) {
EDIT_TEXT, NUMERIC_TEXT, DOUBLE_EDIT_TEXT, EDIT_TEXT_MULTI_LINES, GRID, LIST_STATIC, SUM -> false EDIT_TEXT, NUMERIC_TEXT, DOUBLE_EDIT_TEXT, EDIT_TEXT_MULTI_LINES, GRID, LIST_STATIC, SUM -> false
else -> true else -> true
} }
} }

@ -35,11 +35,7 @@ class HistorySessionDiffCallback(var newRows: List<RowRepresentable>, var oldRow
// Force to update all the rows that were already there // Force to update all the rows that were already there
if (oldRows[oldItemPosition] is Session && newRows[newItemPosition] is Session) { if (oldRows[oldItemPosition] is Session && newRows[newItemPosition] is Session) {
val session1 = oldRows[oldItemPosition] as Session return false
val session2 = newRows[newItemPosition] as Session
return false //session1.id == session2.id
} else if (oldRows[oldItemPosition] is CustomizableRowRepresentable && newRows[newItemPosition] is CustomizableRowRepresentable) { } else if (oldRows[oldItemPosition] is CustomizableRowRepresentable && newRows[newItemPosition] is CustomizableRowRepresentable) {
val header1 = oldRows[oldItemPosition] as CustomizableRowRepresentable val header1 = oldRows[oldItemPosition] as CustomizableRowRepresentable
val header2 = newRows[newItemPosition] as CustomizableRowRepresentable val header2 = newRows[newItemPosition] as CustomizableRowRepresentable

@ -126,6 +126,7 @@ enum class RowViewType(private var layoutRes: Int) {
/** /**
* Display a generic row (title, value, container) * Display a generic row (title, value, container)
*/ */
@SuppressWarnings("ResourceType")
inner class RowViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), BindableHolder { inner class RowViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), BindableHolder {
override fun bind(position: Int, row: RowRepresentable, adapter: RowRepresentableAdapter) { override fun bind(position: Int, row: RowRepresentable, adapter: RowRepresentableAdapter) {

@ -95,7 +95,6 @@ fun Date.getMonthAndYear(): String {
// Return the netDuration between two dates // Return the netDuration between two dates
fun Date.getFormattedDuration(toDate: Date) : String { fun Date.getFormattedDuration(toDate: Date) : String {
val difference = (toDate.time - this.time).toInt() val difference = (toDate.time - this.time).toInt()
val numOfDays = (difference / (1000 * 60 * 60 * 24))
val hours = (difference / (1000 * 60 * 60)) val hours = (difference / (1000 * 60 * 60))
val minutes = (difference / (1000 * 60)) % 60 val minutes = (difference / (1000 * 60)) % 60

Loading…
Cancel
Save