Skip to content
Snippets Groups Projects
Commit 72e44d76 authored by FlyinPancake's avatar FlyinPancake
Browse files

Yeet

parent b35d537b
Branches
No related tags found
No related merge requests found
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<entry key="app/src/main/res/layout/activity_main.xml" value="0.16510416666666666" /> <entry key="app/src/main/res/layout/activity_main.xml" value="0.16510416666666666" />
<entry key="app/src/main/res/layout/activity_profile.xml" value="0.165" /> <entry key="app/src/main/res/layout/activity_profile.xml" value="0.165" />
<entry key="app/src/main/res/layout/recyclerview_main_menu_row.xml" value="0.1" /> <entry key="app/src/main/res/layout/recyclerview_main_menu_row.xml" value="0.1" />
<entry key="app/src/main/res/layout/recyclerview_spell_row.xml" value="0.16510416666666666" /> <entry key="app/src/main/res/layout/recyclerview_spell_row.xml" value="0.1" />
<entry key="app/src/main/res/menu/menu_main.xml" value="0.25" /> <entry key="app/src/main/res/menu/menu_main.xml" value="0.25" />
</map> </map>
</option> </option>
......
...@@ -2,7 +2,7 @@ package com.flyinpancake.dndspells ...@@ -2,7 +2,7 @@ package com.flyinpancake.dndspells
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle import android.os.Bundle
import androidx.lifecycle.map import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import com.flyinpancake.dndspells.adapter.ProfileSpellRecyclerViewAdapter import com.flyinpancake.dndspells.adapter.ProfileSpellRecyclerViewAdapter
import com.flyinpancake.dndspells.model.Spell import com.flyinpancake.dndspells.model.Spell
...@@ -15,7 +15,7 @@ class ProfileActivity : AppCompatActivity(), ProfileSpellRecyclerViewAdapter.Spe ...@@ -15,7 +15,7 @@ class ProfileActivity : AppCompatActivity(), ProfileSpellRecyclerViewAdapter.Spe
const val KEY_NAME = "KEY_NAME" const val KEY_NAME = "KEY_NAME"
} }
private lateinit var binding : ActivityProfileBinding private lateinit var binding : ActivityProfileBinding
private val spellListViewModel = SpellViewModel() private lateinit var spellListViewModel : SpellViewModel
private val recyclerViewAdapter = ProfileSpellRecyclerViewAdapter() private val recyclerViewAdapter = ProfileSpellRecyclerViewAdapter()
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
binding = ActivityProfileBinding.inflate(this.layoutInflater) binding = ActivityProfileBinding.inflate(this.layoutInflater)
...@@ -24,6 +24,11 @@ class ProfileActivity : AppCompatActivity(), ProfileSpellRecyclerViewAdapter.Spe ...@@ -24,6 +24,11 @@ class ProfileActivity : AppCompatActivity(), ProfileSpellRecyclerViewAdapter.Spe
binding.tvCharacterName.text = intent.getStringExtra(KEY_NAME)!! binding.tvCharacterName.text = intent.getStringExtra(KEY_NAME)!!
spellListViewModel = ViewModelProvider(this).get(SpellViewModel::class.java)
spellListViewModel.allSpells.observe(this,{ spells ->
recyclerViewAdapter.submitList(spells)
})
setupSpellList() setupSpellList()
} }
...@@ -31,8 +36,6 @@ class ProfileActivity : AppCompatActivity(), ProfileSpellRecyclerViewAdapter.Spe ...@@ -31,8 +36,6 @@ class ProfileActivity : AppCompatActivity(), ProfileSpellRecyclerViewAdapter.Spe
private fun setupSpellList() { private fun setupSpellList() {
spellListViewModel.allSpells.map { spells -> recyclerViewAdapter.addAll(spells) }
binding.rvSpellList.adapter = recyclerViewAdapter binding.rvSpellList.adapter = recyclerViewAdapter
binding.rvSpellList.layoutManager = LinearLayoutManager(this) binding.rvSpellList.layoutManager = LinearLayoutManager(this)
} }
......
package com.flyinpancake.dndspells.adapter package com.flyinpancake.dndspells.adapter
import android.os.Parcel
import android.os.Parcelable
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.ViewGroup import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.flyinpancake.dndspells.model.Spell import com.flyinpancake.dndspells.model.Spell
import com.flyinpancake.dndspells.databinding.RecyclerviewSpellRowBinding import com.flyinpancake.dndspells.databinding.RecyclerviewSpellRowBinding
class ProfileSpellRecyclerViewAdapter: RecyclerView.Adapter<ProfileSpellRecyclerViewAdapter.ViewHolder>() { class ProfileSpellRecyclerViewAdapter : ListAdapter<Spell, ProfileSpellRecyclerViewAdapter.ViewHolder>(itemCallback) {
companion object {
object itemCallback: DiffUtil.ItemCallback<Spell>() {
override fun areItemsTheSame(oldItem: Spell, newItem: Spell): Boolean {
return oldItem == newItem
}
override fun areContentsTheSame(oldItem: Spell, newItem: Spell): Boolean {
return newItem.name == oldItem.name
}
}
}
val spells = mutableListOf<Spell>() val spells = mutableListOf<Spell>()
...@@ -25,7 +42,7 @@ class ProfileSpellRecyclerViewAdapter: RecyclerView.Adapter<ProfileSpellRecycler ...@@ -25,7 +42,7 @@ class ProfileSpellRecyclerViewAdapter: RecyclerView.Adapter<ProfileSpellRecycler
) )
override fun onBindViewHolder(holder: ViewHolder, position: Int) { override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val spell = spells[position] val spell = this.getItem(position)
holder.binding.SpellComponents.text = spell.components holder.binding.SpellComponents.text = spell.components
holder.binding.SpellLevel.text = "${spell.level}" holder.binding.SpellLevel.text = "${spell.level}"
...@@ -33,13 +50,9 @@ class ProfileSpellRecyclerViewAdapter: RecyclerView.Adapter<ProfileSpellRecycler ...@@ -33,13 +50,9 @@ class ProfileSpellRecyclerViewAdapter: RecyclerView.Adapter<ProfileSpellRecycler
holder.binding.tvSpellName.text = spell.name holder.binding.tvSpellName.text = spell.name
} }
override fun getItemCount() = spells.size
var itemClickListener: SpellListItemClickListener? = null var itemClickListener: SpellListItemClickListener? = null
interface SpellListItemClickListener { interface SpellListItemClickListener {
fun onItemClick(spell: Spell, binding: RecyclerviewSpellRowBinding) fun onItemClick(spell: Spell, binding: RecyclerviewSpellRowBinding)
} }
fun addAll(spellList: List<Spell>) = spells.addAll(spellList)
} }
\ No newline at end of file
...@@ -29,10 +29,6 @@ class SpellRepository(private val spellDao: SpellDao) { ...@@ -29,10 +29,6 @@ class SpellRepository(private val spellDao: SpellDao) {
suspend fun nuke() = withContext(Dispatchers.IO) { suspend fun nuke() = withContext(Dispatchers.IO) {
spellDao.nukeSpells() spellDao.nukeSpells()
} }
suspend fun getAllSpellst() = withContext(Dispatchers.IO) {
}
} }
private fun Spell.toRoomModel(): RoomSpell { private fun Spell.toRoomModel(): RoomSpell {
......
...@@ -30,7 +30,4 @@ class SpellViewModel: ViewModel() { ...@@ -30,7 +30,4 @@ class SpellViewModel: ViewModel() {
fun nuke() = viewModelScope.launch { fun nuke() = viewModelScope.launch {
repo.nuke() repo.nuke()
} }
} }
\ No newline at end of file
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="wrap_content">
<TextView <TextView
android:id="@+id/tvSpellName" android:id="@+id/tvSpellName"
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:text="Power word kill" tools:text="Power word kill"
android:textSize="28sp" android:textSize="28sp"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
...@@ -22,35 +22,41 @@ ...@@ -22,35 +22,41 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:layout_marginEnd="8dp" android:layout_marginEnd="8dp"
android:text="Level 9" tools:text="Level 9"
android:textSize="28sp" android:textSize="28sp"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView <TextView
android:id="@+id/SpellSchool" android:id="@+id/SpellSchool"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="27dp"
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp" android:layout_marginBottom="8dp"
android:text="school" tools:text="school"
android:textSize="20sp" android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" /> app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvSpellName"
app:layout_constraintVertical_bias="1.0" />
<TextView <TextView
android:id="@+id/SpellComponents" android:id="@+id/SpellComponents"
android:layout_width="wrap_content" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="19dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="8dp" android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp" android:layout_marginBottom="8dp"
android:text="Components" android:ellipsize="end"
android:maxLines="1"
tools:text="ComponentsComponentsComponentsComponentsComponents"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" /> app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/SpellSchool"
app:layout_constraintTop_toBottomOf="@+id/SpellLevel"
app:layout_constraintVertical_bias="1.0" />
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment