parent
6398989dc4
commit
436385f217
@ -1,76 +0,0 @@ |
|||||||
package net.pokeranalytics.android.model.dao |
|
||||||
|
|
||||||
import io.realm.Realm |
|
||||||
import io.realm.RealmResults |
|
||||||
import io.realm.Sort |
|
||||||
import net.pokeranalytics.android.model.realm.Session |
|
||||||
import net.pokeranalytics.android.util.data.sessionDao |
|
||||||
|
|
||||||
/** |
|
||||||
* Session Dao |
|
||||||
*/ |
|
||||||
class SessionDao(realmDb: Realm) { |
|
||||||
|
|
||||||
var realm: Realm = realmDb |
|
||||||
|
|
||||||
/** |
|
||||||
* Create or update session |
|
||||||
*/ |
|
||||||
fun createOrUpdateSession(session: Session): Session { |
|
||||||
realm.beginTransaction() |
|
||||||
val sessionToSave = realm.copyToRealmOrUpdate(session) |
|
||||||
realm.commitTransaction() |
|
||||||
return realm.copyFromRealm(sessionToSave) |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Create or update sessions |
|
||||||
*/ |
|
||||||
fun createOrUpdateSessions(sessions: List<Session>): List<Session> { |
|
||||||
|
|
||||||
realm.beginTransaction() |
|
||||||
|
|
||||||
// Update |
|
||||||
val sessionsToSave = realm.copyToRealmOrUpdate(sessions) |
|
||||||
// Remove sessions not updated |
|
||||||
realm.where(Session::class.java).equalTo("isUpdating", true).findAll().deleteAllFromRealm() |
|
||||||
|
|
||||||
realm.commitTransaction() |
|
||||||
|
|
||||||
return realm.copyFromRealm(sessionsToSave) |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Find all sessions |
|
||||||
*/ |
|
||||||
fun findAllSessions(): RealmResults<Session> { |
|
||||||
return realm.where(Session::class.java).findAll().sort("updatedAt", Sort.DESCENDING) |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Find session by id |
|
||||||
*/ |
|
||||||
fun findSessionById(sessionId: Int): Session? { |
|
||||||
return realm.where(Session::class.java).equalTo("id", sessionId).findFirst() |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Delete session |
|
||||||
*/ |
|
||||||
fun deleteSession(sessionId: Int) { |
|
||||||
realm.beginTransaction() |
|
||||||
realm.sessionDao().findSessionById(sessionId)?.deleteFromRealm() |
|
||||||
realm.commitTransaction() |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Delete all sessions |
|
||||||
*/ |
|
||||||
fun deleteAllSessions() { |
|
||||||
realm.beginTransaction() |
|
||||||
realm.sessionDao().findAllSessions().deleteAllFromRealm() |
|
||||||
realm.commitTransaction() |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
} |
|
||||||
@ -0,0 +1,101 @@ |
|||||||
|
package net.pokeranalytics.android.ui.adapter |
||||||
|
|
||||||
|
import android.view.LayoutInflater |
||||||
|
import android.view.View |
||||||
|
import android.view.ViewGroup |
||||||
|
import androidx.recyclerview.widget.RecyclerView |
||||||
|
import net.pokeranalytics.android.R |
||||||
|
import net.pokeranalytics.android.Session |
||||||
|
|
||||||
|
class HistoryAdapter(private var sessions: ArrayList<Session>) : RecyclerView.Adapter<RecyclerView.ViewHolder>() { |
||||||
|
|
||||||
|
|
||||||
|
companion object { |
||||||
|
const val ROW_SESSION: Int = 100 |
||||||
|
} |
||||||
|
|
||||||
|
private var isLoadingItem = -1 |
||||||
|
private var lastSelectedItem = -1 |
||||||
|
|
||||||
|
var onClickOnProduct: ((position: Int, session: Session) -> Unit)? = null |
||||||
|
var isPlaceholder = false |
||||||
|
set(value) { |
||||||
|
field = value |
||||||
|
notifyDataSetChanged() |
||||||
|
} |
||||||
|
|
||||||
|
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { |
||||||
|
fun bind(session: Session) { |
||||||
|
val context = itemView.context |
||||||
|
|
||||||
|
/* |
||||||
|
itemView.productName.text = product.name |
||||||
|
itemView.productDescription.text = product.getMobileDescription() |
||||||
|
itemView.productPrice.text = product.getMinPrice() |
||||||
|
itemView.productSpecs.removeAllViews() |
||||||
|
|
||||||
|
if (product.getMobilePageCount().isNotEmpty()) { |
||||||
|
val specItemView = LayoutInflater.from(context).inflate(R.layout.layout_product_specifications, itemView.items, false) |
||||||
|
specItemView.specIcon.setImageResource(R.drawable.icon_spec_pages_count) |
||||||
|
specItemView.specDescription.text = product.getMobilePageCount() |
||||||
|
itemView.productSpecs.addView(specItemView) |
||||||
|
} |
||||||
|
|
||||||
|
if (product.getMobilePhotoCount().isNotEmpty()) { |
||||||
|
val specItemView = LayoutInflater.from(context).inflate(R.layout.layout_product_specifications, itemView.items, false) |
||||||
|
specItemView.specIcon.setImageResource(R.drawable.icon_spec_photos_count) |
||||||
|
specItemView.specDescription.text = product.getMobilePhotoCount() |
||||||
|
itemView.productSpecs.addView(specItemView) |
||||||
|
} |
||||||
|
|
||||||
|
if (product.getMobileFormatCount().isNotEmpty()) { |
||||||
|
val specItemView = LayoutInflater.from(context).inflate(R.layout.layout_product_specifications, itemView.items, false) |
||||||
|
specItemView.specIcon.setImageResource(R.drawable.icon_spec_formats) |
||||||
|
specItemView.specDescription.text = product.getMobileFormatCount() |
||||||
|
itemView.productSpecs.addView(specItemView) |
||||||
|
} |
||||||
|
|
||||||
|
Glide.with(context) |
||||||
|
.load(product.principalImagePath) |
||||||
|
.transition(withCrossFade()) |
||||||
|
.into(itemView.productImage) |
||||||
|
|
||||||
|
itemView.productOrder.setOnClickListener { |
||||||
|
onClickOnProduct?.invoke(adapterPosition, product) |
||||||
|
} |
||||||
|
|
||||||
|
itemView.container.setOnClickListener { |
||||||
|
onClickOnProduct?.invoke(adapterPosition, product) |
||||||
|
} |
||||||
|
*/ |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
inner class PlaceHolderViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { |
||||||
|
fun bind() { |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { |
||||||
|
when (viewType) { |
||||||
|
ROW_SESSION -> return ViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.row_history_session, parent, false)) |
||||||
|
else -> throw IllegalStateException("Need to implement type $viewType in HistoryAdapter") |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { |
||||||
|
when (getItemViewType(position)) { |
||||||
|
HistoryAdapter.ROW_SESSION -> (holder as HistoryAdapter.ViewHolder).bind(sessions[position]) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun getItemCount(): Int { |
||||||
|
return sessions.size |
||||||
|
} |
||||||
|
|
||||||
|
override fun getItemViewType(position: Int) : Int { |
||||||
|
return ROW_SESSION |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,23 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout |
||||||
|
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="wrap_content" |
||||||
|
android:padding="16dp"> |
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatTextView |
||||||
|
android:id="@+id/date" |
||||||
|
android:layout_width="wrap_content" |
||||||
|
android:layout_height="wrap_content" |
||||||
|
app:layout_constraintEnd_toEndOf="parent" |
||||||
|
android:layout_marginEnd="8dp" |
||||||
|
android:layout_marginTop="8dp" |
||||||
|
app:layout_constraintTop_toTopOf="parent" |
||||||
|
app:layout_constraintStart_toStartOf="parent" |
||||||
|
android:layout_marginStart="8dp" |
||||||
|
android:layout_marginBottom="8dp" |
||||||
|
app:layout_constraintBottom_toBottomOf="parent"/> |
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout> |
||||||
Loading…
Reference in new issue