Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
438 changes: 438 additions & 0 deletions app/schemas/org.phenoapps.intercross.data.IntercrossDatabase/3.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,8 @@ class MainActivity : AppCompatActivity(), SearchPreferenceResultListener {
}

doubleBackToExitPressedOnce = true
Toast.makeText(this@MainActivity, "Press back again to exit", Toast.LENGTH_SHORT).show()
Toast.makeText(this@MainActivity,
getString(R.string.press_back_again_to_exit), Toast.LENGTH_SHORT).show()

Handler(Looper.getMainLooper()).postDelayed(
{ doubleBackToExitPressedOnce = false },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ fun bindCrossTypeImage(view: ImageView, event: Event?) {

@BindingAdapter("setQRCode")
fun bindQRCodeImage(view: ImageView, code: String?) {

code?.let {

view.tag = code

AsyncLoadBarcode(view, code).execute(code)
if (code.isNullOrBlank()) {
view.tag = null
view.setImageDrawable(null)
return
}

view.tag = code
AsyncLoadBarcode(view, code).execute(code)
}

@BindingAdapter("layoutMarginStart")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package org.phenoapps.intercross.adapters

import android.graphics.Color
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.content.res.AppCompatResources
import androidx.databinding.DataBindingUtil
import androidx.core.view.isVisible
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import androidx.sqlite.throwSQLiteException
import org.phenoapps.intercross.R
import org.phenoapps.intercross.data.models.BaseParent
import org.phenoapps.intercross.data.models.Parent
Expand All @@ -15,7 +18,8 @@ import org.phenoapps.intercross.data.viewmodels.PollenGroupListViewModel
import org.phenoapps.intercross.databinding.ListItemSelectableParentRowBinding

class ParentsAdapter(private val listModel: ParentsListViewModel,
private val groupModel: PollenGroupListViewModel)
private val groupModel: PollenGroupListViewModel,
private val crossCountProvider: (BaseParent) -> Int = { 0 })
: ListAdapter<BaseParent, ParentsAdapter.ViewHolder>(BaseParent.Companion.DiffCallback()) {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
Expand Down Expand Up @@ -46,25 +50,43 @@ class ParentsAdapter(private val listModel: ParentsListViewModel,
fun bind(p: BaseParent) {

with(binding) {
val context = root.context
val isPollenGroup = p is PollenGroup
val crossCount = crossCountProvider(p)
val isSelected = when (p) {
is Parent -> p.selected
is PollenGroup -> p.selected
else -> false
}

if (p is Parent) {

name = p.name
name = when (p) {
is Parent -> p.name
is PollenGroup -> p.name
else -> ""
}

checked = p.selected
code = when (p) {
is Parent -> p.codeId
is PollenGroup -> p.codeId
else -> null
}

} else if (p is PollenGroup) {
checked = isSelected

this.textField.setBackgroundColor(Color.parseColor("#42FF5722"))
doneCheckBox.isChecked = isSelected
pollenGroupChip.isVisible = isPollenGroup
pollenGroupChip.text = context.getString(R.string.parent_pollen_group_chip)
crossCountChip.text = crossCount.toString()

name = p.name
crossCountChip.visibility = if (crossCount > 0) View.VISIBLE else View.GONE

checked = p.selected
parentTypeChip.chipIcon = when((p as? Parent)?.sex) {
0 -> AppCompatResources.getDrawable(context, R.drawable.ic_female_black_24dp)
else -> AppCompatResources.getDrawable(context, R.drawable.ic_male_black_24dp)
}

linearLayout.setOnClickListener {

doneCheckBox.isChecked=!doneCheckBox.isChecked
parentCard.setOnClickListener {
doneCheckBox.isChecked = !doneCheckBox.isChecked

if (p is Parent) {

Expand All @@ -82,6 +104,8 @@ class ParentsAdapter(private val listModel: ParentsListViewModel,
})
}
}

executePendingBindings()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase
import org.phenoapps.intercross.data.dao.*
import org.phenoapps.intercross.data.migrations.MigrationV2MetaData
import org.phenoapps.intercross.data.migrations.MigrationV3WishlistView
import org.phenoapps.intercross.data.migrations.MigrationV4UniqueWishType
import org.phenoapps.intercross.data.models.*
import kotlin.jvm.java

@Database(entities = [Event::class, Parent::class,
Wishlist::class, Settings::class, PollenGroup::class,
Expand Down Expand Up @@ -46,6 +46,7 @@ abstract class IntercrossDatabase : RoomDatabase() {
return Room.databaseBuilder(ctx, IntercrossDatabase::class.java, DATABASE_NAME)
.addMigrations(MigrationV2MetaData()) //v1 -> v2 migration added JSON based metadata
.addMigrations(MigrationV3WishlistView()) // v2 -> v3 migration for WishlistView
.addMigrations(MigrationV4UniqueWishType()) // v3 -> v4 migration for unique wishlist type
.setJournalMode(JournalMode.TRUNCATE) //truncate mode makes it easier to export/import database w/o having to manage WAL files.
.build()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package org.phenoapps.intercross.data.dao

import androidx.lifecycle.LiveData
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Transaction
import org.phenoapps.intercross.data.models.Wishlist
Expand Down Expand Up @@ -52,4 +54,7 @@ interface WishlistDao : BaseDao<Wishlist> {
@Transaction
@Query("DELETE FROM wishlist")
fun drop()

@Insert(onConflict = OnConflictStrategy.IGNORE)
override fun insert(vararg items: Wishlist)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.phenoapps.intercross.data.migrations

import android.database.sqlite.SQLiteException
import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase

class MigrationV4UniqueWishType : Migration(3, 4) {

override fun migrate(db: SupportSQLiteDatabase) {
with(db) {
try {
beginTransaction()

createWishTypeIndex()

setTransactionSuccessful()
} catch (e: SQLiteException) {
e.printStackTrace()
} finally {
endTransaction()
}
}
}

private fun SupportSQLiteDatabase.createWishTypeIndex() {
execSQL(
"CREATE UNIQUE INDEX IF NOT EXISTS index_intercross_maleDbId_femaleDbId_wishType " +
"ON wishlist(maleDbId, femaleDbId, wishType)"
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ package org.phenoapps.intercross.data.models

import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.Index
import androidx.room.PrimaryKey

@Entity(tableName = "wishlist")
@Entity(tableName = "wishlist",
indices = [
Index(value = ["femaleDbId", "maleDbId", "wishType"], unique = true)
])
data class Wishlist(var femaleDbId: String,
var maleDbId: String,
var femaleName: String=femaleDbId,
Expand Down
Loading