Skip to content

Commit

Permalink
Fix text size on Devices connected screen
Browse files Browse the repository at this point in the history
Also remove toast messages

Adds a fix for issue #61
  • Loading branch information
ekigamba committed Jun 20, 2019
1 parent 4640dc9 commit 0cab846
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -236,7 +235,6 @@ public void onAuthorizationDetailsProvided(@NonNull Map<String, Object> 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 {
Expand All @@ -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);

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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));
Expand All @@ -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() {
Expand Down Expand Up @@ -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 {
Expand All @@ -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() {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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() {
Expand Down
11 changes: 6 additions & 5 deletions p2p-sync/src/main/res/layout/fragment_devices_connected.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
app:layout_constraintGuide_percent="0.2"/>

<ImageView
android:id="@+id/iv_devicesConnectedFragment_errorMark"
android:id="@+id/iv_devicesConnectedFragment_connectedIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/imageViewGuideline"
Expand All @@ -24,12 +25,12 @@
android:id="@+id/tv_devicesConnectedFragment_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/iv_devicesConnectedFragment_errorMark"
app:layout_constraintTop_toBottomOf="@id/iv_devicesConnectedFragment_connectedIcon"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:textColor="@android:color/black"
android:textSize="26sp"
android:layout_marginTop="40dp"
android:textSize="@dimen/start_transfer_title_size"
android:layout_marginTop="@dimen/start_transfer_title_margin"
android:text="@string/devices_connected"/>

<TextView
Expand All @@ -41,7 +42,7 @@
app:layout_constraintRight_toRightOf="parent"
android:textColor="@android:color/black"
android:layout_marginTop="15dp"
android:textSize="21sp"
android:textSize="@dimen/start_transfer_message_size"
android:paddingLeft="40dp"
android:paddingRight="40dp"
android:gravity="center"
Expand Down
6 changes: 6 additions & 0 deletions p2p-sync/src/main/res/values-sw320dp/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="start_transfer_title_size">21sp</dimen>
<dimen name="start_transfer_message_size">14sp</dimen>
<dimen name="start_transfer_title_margin">5dp</dimen>
</resources>
6 changes: 6 additions & 0 deletions p2p-sync/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="start_transfer_title_size">26sp</dimen>
<dimen name="start_transfer_message_size">21sp</dimen>
<dimen name="start_transfer_title_margin">40dp</dimen>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 0cab846

Please sign in to comment.