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
*/
inner class HeaderTitleViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), BindableHolder {
fun bind(position: Int, title: String, adapter: FeedSessionRowRepresentableAdapter) {
fun bind(title: String) {
// Title
itemView.findViewById<AppCompatTextView>(R.id.title)?.let {
it.text = title
@ -66,12 +66,12 @@ class FeedSessionRowRepresentableAdapter(
}
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)
return RowSessionViewHolder(layout)
RowSessionViewHolder(layout)
} else {
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) {
holder.bind(position, getSessionForPosition(position), this)
} 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
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@ -56,7 +55,7 @@ class FeedTransactionRowRepresentableAdapter(
* Display a header
*/
inner class HeaderTitleViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), BindableHolder {
fun bind(position: Int, title: String, adapter: FeedTransactionRowRepresentableAdapter) {
fun bind(title: String) {
// Title
itemView.findViewById<AppCompatTextView>(R.id.title)?.let {
it.text = title
@ -65,12 +64,12 @@ class FeedTransactionRowRepresentableAdapter(
}
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)
return RowTransactionViewHolder(layout)
RowTransactionViewHolder(layout)
} else {
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) {
holder.bind(position, getTransactionForPosition(position), this)
} else if (holder is HeaderTitleViewHolder) {
holder.bind(position, getHeaderForPosition(holder.itemView.context, position), this)
holder.bind(getHeaderForPosition(position))
}
}
/**
* Return the header
*/
private fun getHeaderForPosition(context: Context, position: Int): String {
private fun getHeaderForPosition(position: Int): String {
if (sortedHeaders.containsKey(position)) {
val realmHeaderPosition = sortedHeaders.keys.indexOf(position)
return distinctTransactionsHeaders[realmHeaderPosition]?.date?.getMonthAndYear() ?: ""

@ -139,7 +139,6 @@ class FeedFragment : PokerAnalyticsFragment(), RowRepresentableDelegate {
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 distinctDateSessions = getRealm().where<Session>().distinct("year", "month").findAll().sort("startDate", Sort.DESCENDING)
this.feedSessionAdapter = FeedSessionRowRepresentableAdapter(this, realmSessions, pendingSessions, distinctDateSessions)

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

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

@ -35,11 +35,7 @@ class HistorySessionDiffCallback(var newRows: List<RowRepresentable>, var oldRow
// Force to update all the rows that were already there
if (oldRows[oldItemPosition] is Session && newRows[newItemPosition] is Session) {
val session1 = oldRows[oldItemPosition] as Session
val session2 = newRows[newItemPosition] as Session
return false //session1.id == session2.id
return false
} else if (oldRows[oldItemPosition] is CustomizableRowRepresentable && newRows[newItemPosition] is CustomizableRowRepresentable) {
val header1 = oldRows[oldItemPosition] 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)
*/
@SuppressWarnings("ResourceType")
inner class RowViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), BindableHolder {
override fun bind(position: Int, row: RowRepresentable, adapter: RowRepresentableAdapter) {

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

Loading…
Cancel
Save