Skip to content

Commit

Permalink
Reverted last commit and some last little improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
quadcopterman committed May 29, 2024
1 parent b21e409 commit bc4e9df
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.github.dedis.popstellar.R
import com.github.dedis.popstellar.SingleEvent
import com.github.dedis.popstellar.databinding.LinkedOrganizationsFragmentBinding
import com.github.dedis.popstellar.model.Role
import com.github.dedis.popstellar.ui.lao.LaoActivity
Expand Down Expand Up @@ -60,15 +59,6 @@ class LinkedOrganizationsFragment : Fragment() {
binding.inviteOtherOrganization.setOnClickListener(invitationPage)
binding.joinOtherOrganizationInvitation.setOnClickListener(joinButton)

linkedOrganizationsViewModel.isJoinScanningDone.observe(viewLifecycleOwner) {
booleanSingleEvent: SingleEvent<Boolean> ->
val finished = booleanSingleEvent.contentIfNotHandled
if (finished == true) {
closeScanner()
linkedOrganizationsViewModel.deactivateJoinScanningDone()
}
}

handleBackNav()

return binding.root
Expand Down Expand Up @@ -114,13 +104,6 @@ class LinkedOrganizationsFragment : Fragment() {
}
}

private fun closeScanner() {
LaoActivity.setCurrentFragment(
parentFragmentManager, R.id.fragment_linked_organizations_invite) {
LinkedOrganizationsInviteFragment.newInstance(false)
}
}

private fun handleBackNav() {
LaoActivity.addBackNavigationCallbackToEvents(requireActivity(), viewLifecycleOwner, TAG)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.github.dedis.popstellar.R
import com.github.dedis.popstellar.SingleEvent
import com.github.dedis.popstellar.databinding.LinkedOrganizationsInviteFragmentBinding
import com.github.dedis.popstellar.model.network.method.message.data.federation.Challenge
import com.github.dedis.popstellar.model.qrcode.FederationDetails
Expand All @@ -31,7 +30,9 @@ import kotlinx.coroutines.launch
import net.glxn.qrgen.android.QRCode

@AndroidEntryPoint
class LinkedOrganizationsInviteFragment : Fragment() {
class LinkedOrganizationsInviteFragment(createsInvitation: Boolean) : Fragment() {
private val createdInvitation = createsInvitation

@Inject lateinit var gson: Gson
@Inject lateinit var networkManager: GlobalNetworkManager

Expand Down Expand Up @@ -59,15 +60,6 @@ class LinkedOrganizationsInviteFragment : Fragment() {
displayQrCodeAndInfo(binding, null)
}

linkedOrganizationsViewModel.isInviteScanningDone.observe(viewLifecycleOwner) {
booleanSingleEvent: SingleEvent<Boolean> ->
val finished = booleanSingleEvent.contentIfNotHandled
if (finished == true) {
closeScanner()
linkedOrganizationsViewModel.deactivateInviteScanningDone()
}
}

handleBackNav()

return binding.root
Expand Down Expand Up @@ -158,12 +150,7 @@ class LinkedOrganizationsInviteFragment : Fragment() {
} else {
laoViewModel.addDisposable(
linkedOrganizationsViewModel
.sendFederationInit(
linkedOrganizationsViewModel.getOtherLao()!!,
linkedOrganizationsViewModel.getOtherServerAddress()!!,
linkedOrganizationsViewModel.getOtherPublicKey()!!,
linkedOrganizationsViewModel.getChallenge()!!,
)
.sendFederationInitFromRepository()
.subscribe(
{ logAndShow(requireContext(), TAG, R.string.init_sent) },
{ error: Throwable ->
Expand All @@ -184,21 +171,13 @@ class LinkedOrganizationsInviteFragment : Fragment() {
}
}

private fun closeScanner() {
LaoActivity.setCurrentFragment(parentFragmentManager, R.id.fragment_linked_organizations_home) {
LinkedOrganizationsFragment.newInstance()
}
}

companion object {
private val TAG: String = LinkedOrganizationsInviteFragment::class.java.simpleName
private const val QR_SIDE = 800
private var createdInvitation = false

@JvmStatic
fun newInstance(createsInvitation: Boolean): LinkedOrganizationsInviteFragment {
createdInvitation = createsInvitation
return LinkedOrganizationsInviteFragment()
return LinkedOrganizationsInviteFragment(createsInvitation)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import androidx.fragment.app.FragmentManager
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.MutableLiveData
import com.github.dedis.popstellar.R
import com.github.dedis.popstellar.SingleEvent
import com.github.dedis.popstellar.model.network.method.message.MessageGeneral
import com.github.dedis.popstellar.model.network.method.message.data.federation.Challenge
import com.github.dedis.popstellar.model.network.method.message.data.federation.ChallengeRequest
Expand Down Expand Up @@ -41,8 +40,6 @@ constructor(
private lateinit var laoId: String
private val connecting = AtomicBoolean(false)
private val disposables = CompositeDisposable()
val isInviteScanningDone = MutableLiveData<SingleEvent<Boolean>>()
val isJoinScanningDone = MutableLiveData<SingleEvent<Boolean>>()
var manager: FragmentManager? = null
override val nbScanned = MutableLiveData<Int>()

Expand Down Expand Up @@ -102,6 +99,15 @@ constructor(
)
}

/** Sends a Federation Init data with parameters from the repository */
fun sendFederationInitFromRepository(): Completable {
return sendFederationInit(
linkedOrgRepo.otherLaoId!!,
linkedOrgRepo.otherServerAddr!!,
linkedOrgRepo.otherPublicKey!!,
linkedOrgRepo.getChallenge()!!)
}

/**
* Sends a Federation Expect data
*
Expand Down Expand Up @@ -135,18 +141,6 @@ constructor(
return linkedOrgRepo.getChallenge()
}

fun getOtherLao(): String? {
return linkedOrgRepo.otherLaoId
}

fun getOtherServerAddress(): String? {
return linkedOrgRepo.otherServerAddr
}

fun getOtherPublicKey(): String? {
return linkedOrgRepo.otherPublicKey
}

fun isRepositoryValid(): Boolean {
return linkedOrgRepo.otherLaoId != null &&
linkedOrgRepo.otherServerAddr != null &&
Expand All @@ -165,21 +159,11 @@ constructor(
linkedOrgRepo.setOnChallengeUpdatedCallback(function)
}

fun deactivateInviteScanningDone() {
isInviteScanningDone.postValue(SingleEvent(false))
}

fun deactivateJoinScanningDone() {
isJoinScanningDone.postValue(SingleEvent(false))
}

override fun handleData(data: String?) {
// Don't process another data from the scanner if I'm already trying to scan
if (connecting.get()) {
return
}
isJoinScanningDone.postValue(SingleEvent(true))
isInviteScanningDone.postValue(SingleEvent(true))

connecting.set(true)
val federationDetails: FederationDetails =
Expand Down Expand Up @@ -210,14 +194,12 @@ constructor(
getApplication(), TAG, error, R.string.error_sending_federation_expect)
},
))
// isInviteScanningDone.postValue(SingleEvent(true))
} else {
// The federationDetails object is sent by the one who joins the invitation
linkedOrgRepo.otherLaoId = federationDetails.laoId
linkedOrgRepo.otherServerAddr = federationDetails.serverAddress
linkedOrgRepo.otherPublicKey = federationDetails.publicKey
linkedOrgRepo.updateChallenge(federationDetails.challenge)
// isJoinScanningDone.postValue(SingleEvent(true))
}
connecting.set(false)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import androidx.fragment.app.Fragment
import com.github.dedis.popstellar.R
import com.github.dedis.popstellar.databinding.QrScannerFragmentBinding
import com.github.dedis.popstellar.ui.PopViewModel
import com.github.dedis.popstellar.ui.lao.LaoActivity
import com.github.dedis.popstellar.ui.lao.federation.LinkedOrganizationsFragment
import com.github.dedis.popstellar.ui.lao.federation.LinkedOrganizationsInviteFragment
import com.github.dedis.popstellar.ui.lao.federation.LinkedOrganizationsViewModel
import com.github.dedis.popstellar.utility.UIUtils
import com.github.dedis.popstellar.utility.UIUtils.hideKeyboard
import com.github.dedis.popstellar.utility.error.ErrorUtils.logAndShow
Expand Down Expand Up @@ -176,7 +180,11 @@ class QrScannerFragment : Fragment() {
scanningViewModel.handleData(data)

// Special case for federation
/*val linkedOrganisationsViewModel = scanningViewModel
/*
* WARNING : this code is not ideal as it should be treated by the LinkedOrganizationFragment
* and by the LinkedOrganizationInviteFragment instead of the QrScannerFragment
*/
val linkedOrganisationsViewModel = scanningViewModel
if (linkedOrganisationsViewModel is LinkedOrganizationsViewModel) {
if (scanningAction == ScanningAction.FEDERATION_INVITE) {
LaoActivity.setCurrentFragment(
Expand All @@ -193,7 +201,7 @@ class QrScannerFragment : Fragment() {
LinkedOrganizationsInviteFragment.newInstance(false)
}
}
}*/
}
}

private fun setupManualAdd() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ enum class ScanningAction(
FEDERATION_INVITE(
R.string.qrcode_scanning_federation,
R.string.scanned_organizer,
R.string.other_organisation_add_title,
R.string.invite_other_organization,
R.string.manual_add_organization_title,
arrayOf(
InputFieldConfig(R.string.manual_add_organization_lao_id_hint, true),
Expand All @@ -145,7 +145,7 @@ enum class ScanningAction(
FEDERATION_JOIN(
R.string.qrcode_scanning_federation,
R.string.scanned_organizer,
R.string.other_organisation_add_title,
R.string.join_other_organization_invitation,
R.string.manual_add_organization_title,
arrayOf(
InputFieldConfig(R.string.manual_add_organization_lao_id_hint, true),
Expand Down

0 comments on commit bc4e9df

Please sign in to comment.