Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mo/feature/show need resource #456

Merged
merged 11 commits into from
Oct 31, 2023
Prev Previous commit
Next Next commit
#414#Showing needs and resources that are created from add need and a…
…dd Resource Fragments# After they're created successfully, it pops back to corresponding page with Toast#
egecan.serbester committed Oct 30, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 77c1a2b531055d74735677e480725cd3a70abbda
Original file line number Diff line number Diff line change
@@ -124,7 +124,7 @@ class MainActivity : AppCompatActivity() {
}

private fun tryResourceViewModel(){
val resource = Resource(null,"Mansur",ResourceCondition.NEW,400,NeedTypes.Food,"Soap",DateUtil.getDate("dd-MM-yy").toString(),"Ankara")
val resource = Resource(null,"Mansur","new",400,NeedTypes.Food,"Soup",DateUtil.getDate("dd-MM-yy").toString(),"Ankara")
resourceViewModel.insertResource(resource)
android.os.Handler(Looper.getMainLooper()).postDelayed({ // it's a delay block
val location = resourceViewModel.getLocation("Mansur")
Original file line number Diff line number Diff line change
@@ -41,6 +41,7 @@ class NeedAdapter(private val needList: List<Need>?): RecyclerView.Adapter<NeedA
hb.tvLocation.text = currentNeed?.location
hb.tvQuantity.text = currentNeed?.quantity.toString()
hb.tvCreator.text = currentNeed?.creatorName
hb.tvDetails.text = currentNeed?.details

// for make them clickable
holder.itemView.setOnClickListener {view ->
Original file line number Diff line number Diff line change
@@ -39,6 +39,7 @@ class ResourceAdapter(private val resourceList: List<Resource>?): RecyclerView.A
hb.tvLocation.text = currentResource?.location
hb.tvQuantity.text = currentResource?.quantity.toString()
hb.tvCreator.text = currentResource?.creatorName
hb.tvDetails.text = currentResource?.details

// for make them clickable
holder.itemView.setOnClickListener {view ->
Original file line number Diff line number Diff line change
@@ -12,6 +12,6 @@ class DatabaseInfo {
const val NEED: String = "NEED"
const val RESOURCE: String = "RESOURCE"
const val USER_DATA: String = "USER_DATA"
const val DATABASE_VERSION: Int = 7 // you need to change that whenever you change any table on DB
const val DATABASE_VERSION: Int = 11 // you need to change that whenever you change any table on DB
}
}
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ data class Resource(
@ColumnInfo(name = NeedResourceCols.creatorName)
val creatorName: String,
@ColumnInfo(name = NeedResourceCols.condition)
val condition: ResourceCondition,
val condition: String,
@ColumnInfo(name = NeedResourceCols.quantity)
val quantity: Int?,
@ColumnInfo(name = NeedResourceCols.type)
Original file line number Diff line number Diff line change
@@ -8,9 +8,12 @@ import android.widget.ArrayAdapter
import android.widget.Toast
import androidx.fragment.app.Fragment
import com.example.disasterresponseplatform.R
import com.example.disasterresponseplatform.data.database.need.Need
import com.example.disasterresponseplatform.data.enums.NeedTypes
import com.example.disasterresponseplatform.databinding.FragmentAddNeedBinding
import com.example.disasterresponseplatform.utils.DateUtil

class AddNeedFragment : Fragment() {
class AddNeedFragment(private val needViewModel: NeedViewModel) : Fragment() {

private lateinit var binding: FragmentAddNeedBinding

@@ -93,6 +96,28 @@ class AddNeedFragment : Fragment() {
binding.btnSubmit.setOnClickListener {
if ((validateFullName() and validatePhoneNumber() and validateQuantity() and validateLocation()) and validateType() and validateSubType()) {
Toast.makeText(context, "{'created_by': ${binding.etFullName.editText?.text.toString().trim()}, 'quantity': ${binding.etQuantity.editText?.text.toString().trim()}, 'type': ${binding.boxNeedType.editText?.text.toString().trim()}}", Toast.LENGTH_SHORT).show()

val type: NeedTypes =
when(binding.boxNeedType.editText?.text.toString().trim()){
NeedTypes.Clothes.toString() -> NeedTypes.Clothes
NeedTypes.Food.toString() -> NeedTypes.Food
NeedTypes.Shelter.toString() -> NeedTypes.Shelter
NeedTypes.Medication.toString() ->NeedTypes.Medication
NeedTypes.Transportation.toString() ->NeedTypes.Transportation
NeedTypes.Tools.toString() -> NeedTypes.Tools
NeedTypes.Human.toString() -> NeedTypes.Human
else -> NeedTypes.Other
}
val creatorName = binding.etFullName.editText?.text.toString().trim()
val details = binding.spNeedSubType.text.toString().trim()
val quantity = binding.etQuantity.editText?.text.toString().trim().toInt()
val location = binding.etLocation.editText?.text.toString().trim()
val date = DateUtil.getDate("dd-MM-yy").toString()
val need = Need(null,creatorName,type,details, date,quantity,location,1)
//TODO do with token
needViewModel.insertNeed(need)
parentFragmentManager.popBackStack()

} else {
Toast.makeText(context, "Check the Fields", Toast.LENGTH_LONG).show()
}
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ import com.example.disasterresponseplatform.databinding.FragmentNeedBinding
class NeedFragment(private val needViewModel: NeedViewModel) : Fragment() {

private lateinit var binding: FragmentNeedBinding
private val addNeedFragment = AddNeedFragment()
private lateinit var addNeedFragment: AddNeedFragment
private lateinit var searchView: SearchView

override fun onCreateView(
@@ -36,6 +36,7 @@ class NeedFragment(private val needViewModel: NeedViewModel) : Fragment() {
private fun arrangeView(){
// add need clickable
binding.btAddNeed.setOnClickListener {
addNeedFragment = AddNeedFragment(needViewModel)
addFragment(addNeedFragment)
}
arrangeSearchView()
@@ -55,7 +56,7 @@ class NeedFragment(private val needViewModel: NeedViewModel) : Fragment() {

// this observes getLiveIntent, whenever a value is posted it enters this function
adapter.getLiveIntent().observe(requireActivity()){
val text = "Type: ${it?.type}, Location: ${it?.location}, " +
val text = "Type: ${it?.type}, SubType: ${it?.details}, Location: ${it?.location}, " +
"Date: ${it?.creationTime}, Quantity: ${it?.quantity}, Urgency: ${it?.urgency}"
Toast.makeText(requireActivity(), text, Toast.LENGTH_LONG).show()
}
Original file line number Diff line number Diff line change
@@ -8,9 +8,13 @@ import android.widget.ArrayAdapter
import android.widget.Toast
import androidx.fragment.app.Fragment
import com.example.disasterresponseplatform.R
import com.example.disasterresponseplatform.data.database.need.Need
import com.example.disasterresponseplatform.data.database.resource.Resource
import com.example.disasterresponseplatform.data.enums.NeedTypes
import com.example.disasterresponseplatform.databinding.FragmentAddResourceBinding
import com.example.disasterresponseplatform.utils.DateUtil

class AddResourceFragment : Fragment() {
class AddResourceFragment(private val resourceViewModel: ResourceViewModel) : Fragment() {

private lateinit var binding: FragmentAddResourceBinding

@@ -93,6 +97,27 @@ class AddResourceFragment : Fragment() {
binding.btnSubmit.setOnClickListener {
if ((validateFullName() and validatePhoneNumber() and validateQuantity() and validateLocation()) and validateType() and validateSubType()) {
Toast.makeText(context, "{'created_by': ${binding.etFullName.editText?.text.toString().trim()}, 'quantity': ${binding.etQuantity.editText?.text.toString().trim()}, 'type': ${binding.boxResourceType.editText?.text.toString().trim()}}", Toast.LENGTH_SHORT).show()

val type: NeedTypes =
when(binding.boxResourceType.editText?.text.toString().trim()){
NeedTypes.Clothes.toString() -> NeedTypes.Clothes
NeedTypes.Food.toString() -> NeedTypes.Food
NeedTypes.Shelter.toString() -> NeedTypes.Shelter
NeedTypes.Medication.toString() -> NeedTypes.Medication
NeedTypes.Transportation.toString() -> NeedTypes.Transportation
NeedTypes.Tools.toString() -> NeedTypes.Tools
NeedTypes.Human.toString() -> NeedTypes.Human
else -> NeedTypes.Other
}
val creatorName = binding.etFullName.editText?.text.toString().trim()
val details = binding.spResourceSubType.text.toString().trim()
val quantity = binding.etQuantity.editText?.text.toString().trim().toInt()
val location = binding.etLocation.editText?.text.toString().trim()
val date = DateUtil.getDate("dd-MM-yy").toString()
val resource = Resource(null,creatorName,"new",quantity,type,details,date,location)
//TODO do with token
resourceViewModel.insertResource(resource)
parentFragmentManager.popBackStack()
} else {
Toast.makeText(context, "Check the Fields", Toast.LENGTH_LONG).show()
}
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ import com.example.disasterresponseplatform.databinding.FragmentResourceBinding
class ResourceFragment(private val resourceViewModel: ResourceViewModel) : Fragment() {

private lateinit var binding: FragmentResourceBinding
private val addResourceFragment = AddResourceFragment()
private lateinit var addResourceFragment : AddResourceFragment
private lateinit var searchView: SearchView

override fun onCreateView(
@@ -35,6 +35,7 @@ class ResourceFragment(private val resourceViewModel: ResourceViewModel) : Fragm
private fun arrangeView(){
// add need clickable
binding.btAddResource.setOnClickListener {
val addResourceFragment = AddResourceFragment(resourceViewModel)
addFragment(addResourceFragment)
}
arrangeSearchView()
@@ -54,7 +55,7 @@ class ResourceFragment(private val resourceViewModel: ResourceViewModel) : Fragm

// this observes getLiveIntent, whenever a value is posted it enters this function
adapter.getLiveIntent().observe(requireActivity()){
val text = "Type: ${it?.type}, Location: ${it?.location}, " +
val text = "Type: ${it?.type}, SubType: ${it?.details}, Location: ${it?.location}, "+
"Date: ${it?.creationTime}, Quantity: ${it?.quantity}, Condition: ${it?.condition}"
Toast.makeText(requireActivity(), text, Toast.LENGTH_LONG).show()
}
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginBottom="10dp"
android:layout_marginBottom="16dp"
android:text="@string/location"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="parent"
@@ -72,7 +72,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:layout_marginBottom="24dp"
android:layout_marginBottom="16dp"
android:text="22.10.2023 13:02"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="parent"
@@ -92,7 +92,7 @@
android:id="@+id/tvQuantity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="24dp"
android:text="50"
android:textSize="12sp"
@@ -122,6 +122,28 @@
app:layout_constraintStart_toEndOf="@+id/titleLocation"
app:layout_constraintTop_toTopOf="@+id/titleCreatorName" />

<TextView
android:id="@+id/titleDetails"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginEnd="24dp"
android:text="Details:"
android:textSize="12sp"
app:layout_constraintEnd_toStartOf="@+id/tvDetails"
app:layout_constraintTop_toBottomOf="@+id/titleQuantity" />

<TextView
android:id="@+id/tvDetails"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:layout_marginTop="16dp"
android:layout_marginEnd="24dp"
android:text="Deatils"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvQuantity" />


</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginBottom="10dp"
android:layout_marginBottom="16dp"
android:text="@string/location"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="parent"
@@ -72,7 +72,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:layout_marginBottom="24dp"
android:layout_marginBottom="16dp"
android:text="22.10.2023 13:02"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="parent"
@@ -92,7 +92,7 @@
android:id="@+id/tvQuantity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="24dp"
android:text="50"
android:textSize="12sp"
@@ -122,6 +122,28 @@
app:layout_constraintStart_toEndOf="@+id/titleLocation"
app:layout_constraintTop_toTopOf="@+id/titleCreatorName" />

<TextView
android:id="@+id/titleDetails"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginEnd="24dp"
android:text="Details:"
android:textSize="12sp"
app:layout_constraintEnd_toStartOf="@+id/tvDetails"
app:layout_constraintTop_toBottomOf="@+id/titleQuantity" />

<TextView
android:id="@+id/tvDetails"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:layout_marginTop="16dp"
android:layout_marginEnd="24dp"
android:text="Deatils"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvQuantity" />


</androidx.constraintlayout.widget.ConstraintLayout>
</layout>