diff --git a/p2p-sync/src/main/java/org/smartregister/p2p/activity/P2pModeSelectActivity.java b/p2p-sync/src/main/java/org/smartregister/p2p/activity/P2pModeSelectActivity.java index f4724db..8547211 100644 --- a/p2p-sync/src/main/java/org/smartregister/p2p/activity/P2pModeSelectActivity.java +++ b/p2p-sync/src/main/java/org/smartregister/p2p/activity/P2pModeSelectActivity.java @@ -480,12 +480,6 @@ public void handleActivityResult(int resultCode, Intent data) { }); } - @Override - public void showToast(@NonNull String text, int length) { - Toast.makeText(this, text, length) - .show(); - } - private void showLocationEnableRejectionDialog() { new AlertDialog.Builder(P2pModeSelectActivity.this) .setTitle(R.string.location_service_disabled) diff --git a/p2p-sync/src/main/java/org/smartregister/p2p/contract/P2pModeSelectContract.java b/p2p-sync/src/main/java/org/smartregister/p2p/contract/P2pModeSelectContract.java index 0a2d3a2..791b476 100644 --- a/p2p-sync/src/main/java/org/smartregister/p2p/contract/P2pModeSelectContract.java +++ b/p2p-sync/src/main/java/org/smartregister/p2p/contract/P2pModeSelectContract.java @@ -90,8 +90,6 @@ void showConnectionAcceptDialog(@NonNull String receiverDeviceName, @NonNull Str void requestEnableLocation(@NonNull OnLocationEnabled onLocationEnabled); - void showToast(@NonNull String text, int length); - @NonNull String getString(@StringRes int resId); diff --git a/p2p-sync/src/main/java/org/smartregister/p2p/presenter/P2PReceiverPresenter.java b/p2p-sync/src/main/java/org/smartregister/p2p/presenter/P2PReceiverPresenter.java index 123bae8..30fdaef 100644 --- a/p2p-sync/src/main/java/org/smartregister/p2p/presenter/P2PReceiverPresenter.java +++ b/p2p-sync/src/main/java/org/smartregister/p2p/presenter/P2PReceiverPresenter.java @@ -169,7 +169,6 @@ public void onStartedAdvertising(Object result) { public void onAdvertisingFailed(@NonNull Exception e) { stopConnectionTimeout(); - view.showToast(view.getString(R.string.an_error_occurred_start_receiving), Toast.LENGTH_LONG); view.removeAdvertisingProgressDialog(); view.enableSendReceiveButtons(true); } @@ -236,7 +235,6 @@ public void onAuthorizationDetailsProvided(@NonNull Map authoriz @Override public void onConnectionRejected(@NonNull String endpointId, @NonNull ConnectionResolution connectionResolution) { if (getCurrentPeerDevice() != null) { - view.showToast(view.getString(R.string.receiver_rejected_the_connection), Toast.LENGTH_LONG); resetState(); prepareForAdvertising(false); } else { @@ -250,7 +248,6 @@ public void onConnectionUnknownError(@NonNull String endpointId, @NonNull Connec //Todo: And show the user an error if (getCurrentPeerDevice() != null && endpointId.equals(getCurrentPeerDevice().getEndpointId())) { String errorMsg = String.format(view.getString(R.string.please_make_sure_device_is_turned_on_and_in_range), getCurrentPeerDevice().getEndpointName()); - view.showToast(view.getString(R.string.an_error_occurred_before_acceptance_or_rejection), Toast.LENGTH_LONG); disconnectAndReset(endpointId); @@ -282,7 +279,6 @@ public void onOkClicked() { }); disconnectAndReset(interactor.getCurrentEndpoint(), false); } - view.showToast(errorMsg, Toast.LENGTH_LONG); } else { Timber.e(view.getString(R.string.log_onconnectionbroken_without_peer_device), endpointId); } @@ -542,7 +538,6 @@ public void onSuccess(@Nullable Void result) { @Override public void onError(Exception e) { Timber.e(e); - view.showToast(view.getString(R.string.an_error_occurred_trying_to_save_new_sender_details), Toast.LENGTH_LONG); disconnectAndReset(endpointId); } @@ -601,7 +596,6 @@ public void onAuthenticationFailed(@NonNull String reason, @NonNull Exception ex disconnectAndReset(endpointId); } - view.showToast(view.getString(R.string.authentication_failed_connection_rejected), Toast.LENGTH_LONG); view.showErrorFragment(view.getString(R.string.connection_lost), reason, new ErrorFragment.OnOkClickCallback() { @Override public void onOkClicked() { @@ -645,8 +639,6 @@ private void resetState() { @Override public void onConnectionAuthorized() { connectionLevel = ConnectionLevel.AUTHORIZED; - view.showToast(String.format(view.getContext().getString(R.string.you_are_connected_to_sender), currentSender.getEndpointName()) - , Toast.LENGTH_LONG); view.showDevicesConnectedFragment(new P2pModeSelectContract.View.OnStartTransferClicked() { @Override @@ -682,11 +674,6 @@ public void onConnectionAuthorizationRejected(@NonNull String reason) { if (currentSender != null) { String endpointId = currentSender.getEndpointId(); addDeviceToBlacklist(endpointId); - - view.showToast(String.format(view.getString(R.string.connection_could_not_be_authorized) - , currentSender.getEndpointName()) - , Toast.LENGTH_LONG); - disconnectAndReset(endpointId, false); view.showErrorFragment(view.getString(R.string.authorization_failed), reason, new ErrorFragment.OnOkClickCallback() { diff --git a/p2p-sync/src/main/java/org/smartregister/p2p/presenter/P2PSenderPresenter.java b/p2p-sync/src/main/java/org/smartregister/p2p/presenter/P2PSenderPresenter.java index 3dc9cf0..7c74c37 100644 --- a/p2p-sync/src/main/java/org/smartregister/p2p/presenter/P2PSenderPresenter.java +++ b/p2p-sync/src/main/java/org/smartregister/p2p/presenter/P2PSenderPresenter.java @@ -233,7 +233,6 @@ public void onStartedDiscovering(@NonNull Object object) { public void onDiscoveringFailed(@NonNull Exception exception) { stopConnectionTimeout(); - view.showToast(view.getString(R.string.error_occurred_cannot_start_sending), Toast.LENGTH_LONG); view.removeDiscoveringProgressDialog(); view.enableSendReceiveButtons(true); } @@ -272,14 +271,12 @@ public void onFailure(@NonNull Exception e) { @Override public void onRequestConnectionSuccessful(@Nullable Object result) { // Just show a success - view.showToast(view.getString(R.string.connection_request_successful), Toast.LENGTH_LONG); view.removeDiscoveringProgressDialog(); } @Override public void onRequestConnectionFailed(@NonNull Exception exception) { // Show the user an error trying to connect device XYZ - view.showToast(view.getString(R.string.could_not_initiate_connection_request_to_device), Toast.LENGTH_LONG); resetState(); prepareForDiscovering(false); } @@ -366,7 +363,6 @@ public void performDeviceAuthentication() { public void onAuthenticationSuccessful() { if (getCurrentPeerDevice() != null){ connectionLevel = ConnectionLevel.AUTHENTICATED; - view.showToast(view.getString(R.string.authentication_successful_receiver_can_accept_connection), Toast.LENGTH_LONG); startDeviceAuthorization(getCurrentPeerDevice().getEndpointId()); } else { Timber.e(view.getString(R.string.log_onauthenticationsuccessful_without_peer_device)); @@ -381,7 +377,6 @@ public void onAuthenticationFailed(@NonNull String reason, @NonNull Exception ex disconnectAndReset(endpointId); } - view.showToast(view.getString(R.string.authentication_failed_connection_rejected), Toast.LENGTH_LONG); view.showErrorFragment(view.getString(R.string.connection_lost), reason, new ErrorFragment.OnOkClickCallback() { @Override public void onOkClicked() { @@ -445,7 +440,6 @@ public void onConnectionRejected(@NonNull String endpointId, @NonNull Connection if (currentReceiver != null) { rejectDeviceOnAuthentication(endpointId); - view.showToast(view.getString(R.string.receiver_rejected_the_connection), Toast.LENGTH_LONG); resetState(); startDiscoveringMode(); } else { @@ -459,7 +453,6 @@ public void onConnectionUnknownError(@NonNull String endpointId, @NonNull Connec //Todo: And show the user an error if (getCurrentPeerDevice() != null && endpointId.equals(getCurrentPeerDevice().getEndpointId())) { String errorMsg = String.format(view.getString(R.string.please_make_sure_device_is_turned_on_and_in_range), getCurrentPeerDevice().getEndpointName()); - view.showToast(view.getString(R.string.an_error_occurred_before_acceptance_or_rejection), Toast.LENGTH_LONG); resetState(); view.showErrorFragment(view.getString(R.string.connection_lost), errorMsg, new ErrorFragment.OnOkClickCallback() { @@ -494,8 +487,6 @@ public void onOkClicked() { resetState(); } } - - view.showToast(errorMsg, Toast.LENGTH_LONG); } else { Timber.e(view.getString(R.string.log_onconnectionbroken_without_peer_device), endpointId); } @@ -684,10 +675,6 @@ public void onConnectionAuthorizationRejected(@NonNull String reason) { String endpointId = currentReceiver.getEndpointId(); addDeviceToBlacklist(endpointId); - view.showToast(String.format(view.getString(R.string.connection_could_not_be_authorized) - , currentReceiver.getEndpointName()) - , Toast.LENGTH_LONG); - disconnectAndReset(endpointId, false); view.showErrorFragment(view.getString(R.string.authorization_failed), reason, new ErrorFragment.OnOkClickCallback() { diff --git a/p2p-sync/src/main/res/layout/fragment_devices_connected.xml b/p2p-sync/src/main/res/layout/fragment_devices_connected.xml index 7548746..e47f53d 100644 --- a/p2p-sync/src/main/res/layout/fragment_devices_connected.xml +++ b/p2p-sync/src/main/res/layout/fragment_devices_connected.xml @@ -12,9 +12,10 @@ app:layout_constraintGuide_percent="0.2"/> + + 21sp + 14sp + 5dp + \ No newline at end of file diff --git a/p2p-sync/src/main/res/values/dimens.xml b/p2p-sync/src/main/res/values/dimens.xml new file mode 100644 index 0000000..d27ad63 --- /dev/null +++ b/p2p-sync/src/main/res/values/dimens.xml @@ -0,0 +1,6 @@ + + + 26sp + 21sp + 40dp + \ No newline at end of file diff --git a/p2p-sync/src/test/java/org/smartregister/p2p/presenter/P2PSenderPresenterTest.java b/p2p-sync/src/test/java/org/smartregister/p2p/presenter/P2PSenderPresenterTest.java index 743a25f..f3365f2 100644 --- a/p2p-sync/src/test/java/org/smartregister/p2p/presenter/P2PSenderPresenterTest.java +++ b/p2p-sync/src/test/java/org/smartregister/p2p/presenter/P2PSenderPresenterTest.java @@ -429,9 +429,6 @@ public void onAuthenticationSuccessfulShouldCallStartDeviceAuthorizationAndChang assertEquals(ConnectionLevel.AUTHENTICATED, ReflectionHelpers.getField(p2PSenderPresenter, "connectionLevel")); Mockito.verify(p2PSenderPresenter, Mockito.times(1)) .startDeviceAuthorization(Mockito.eq(endpointId)); - Mockito.verify(view, Mockito.times(1)) - .showToast(ArgumentMatchers.eq("Authentication successful! Receiver can accept connection") - , ArgumentMatchers.eq(Toast.LENGTH_LONG)); } @Test @@ -448,9 +445,6 @@ public void onAuthenticationFailedShouldDisconnectFromEndpoint() { Mockito.verify(interactor, Mockito.times(1)) .disconnectFromEndpoint(ArgumentMatchers.eq(endpointId)); - Mockito.verify(view, Mockito.times(1)) - .showToast(ArgumentMatchers.eq("Authentication failed! The connection has been rejected") - , ArgumentMatchers.eq(Toast.LENGTH_LONG)); } @Test