Skip to content

Commit

Permalink
Ref. #18: cleanup field after adding new offer
Browse files Browse the repository at this point in the history
  • Loading branch information
dkazakov committed Jun 9, 2023
1 parent 537e10a commit 67d558a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,30 @@ import androidx.lifecycle.ViewModelProvider
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import dagger.android.support.AndroidSupportInjection
import ru.home.swap.App
import ru.home.swap.AppApplication
import ru.home.swap.R
import ru.home.swap.databinding.AddItemFragmentBinding
import ru.home.swap.core.di.ViewModelFactory
import java.lang.IllegalStateException
import javax.inject.Inject


class AddItemBottomSheetDialogFragment: BottomSheetDialogFragment() {

interface IAddItemDialog {
fun onAddItemDialogDismiss()
}

companion object {

const val TAG = "AddItemBottomSheetDialogFragment"

fun newInstance(args: Bundle): AddItemBottomSheetDialogFragment{
val fragment = AddItemBottomSheetDialogFragment()
fragment.arguments = args
return fragment
}
}

private lateinit var binding: AddItemFragmentBinding

@Inject
Expand All @@ -46,6 +61,11 @@ class AddItemBottomSheetDialogFragment: BottomSheetDialogFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

if (parentFragment !is IAddItemDialog) {
throw IllegalStateException("Did you forget to implement IAddItemDialog interface? " +
"One of the parent's fragments in the hierarchy must respond on addItem() action.")
}

view.findViewById<TextView>(R.id.offer_option)
.setOnClickListener {
binding.groupChoice.onOfferClick()
Expand All @@ -59,19 +79,8 @@ class AddItemBottomSheetDialogFragment: BottomSheetDialogFragment() {
binding.save.setOnClickListener {
Log.d(App.TAG, "${viewModel.proposal.get()}")
viewModel.addItem(binding.groupChoice.isOfferSelected())
(parentFragment as IAddItemDialog).onAddItemDialogDismiss()
dismiss()
}
}


companion object {

const val TAG = "AddItemBottomSheetDialogFragment"

fun newInstance(args: Bundle): AddItemBottomSheetDialogFragment{
val fragment = AddItemBottomSheetDialogFragment()
fragment.arguments = args
return fragment
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ import ru.home.swap.ui.common.BaseFragment
import javax.inject.Inject


class ProfileFragment : BaseFragment(), ItemAdapter.Listener {
class ProfileFragment :
BaseFragment(),
ItemAdapter.Listener,
AddItemBottomSheetDialogFragment.IAddItemDialog {

@Inject
lateinit var viewModelFactory: ViewModelFactory
Expand Down Expand Up @@ -121,4 +124,8 @@ class ProfileFragment : BaseFragment(), ItemAdapter.Listener {
override fun onPositiveClick() {
viewModel.removeShownError()
}

override fun onAddItemDialogDismiss() {
viewModel.clearInputField()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,6 @@ class ProfileV2ViewModel
loadAllFromCache()
}

/**
* TODO: [ready for tests] remove offer
* 1. cache chain and server tx
* 2. execute burn() on-chain
* 3. get tx from queue and do backend remove()
* 4. in a backend response the client will get person profile which should be updated in cache
*
* For test:
* 1. Test burn() on-chain call in isolated environment of TestWalletActivity
* 2. Run a whole process to confirm it works
*
* Bugs:
* - [in progress] service id passed on DELETE is not correct
* */

private val logger = Logger.getInstance()

private val assignedUri = "uri is turned off in current version"
Expand Down Expand Up @@ -292,6 +277,10 @@ class ProfileV2ViewModel
}
}

fun clearInputField() {
RequestBuilder().clearProposal()
}

fun createAnAccount() {
Log.d(App.TAG, "[check] contact value (${uiState.value.profile.contact}) and secret value(${uiState.value.profile.secret})")
val validator = PersonProvider()
Expand Down

0 comments on commit 67d558a

Please sign in to comment.