Skip to content
Merged

S206 #256

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,27 @@ public CurrencyDetails getCurrency(String currencyCode) {
}
return null;
}

/**
* truncate decimals for given value
*
* @param value Any value in string.
* @param noOfDecimals number of decimal to be truncate.
* @return Returns truncated decimal value.
*/
public static String getValueWithTruncateDecimals(String value, int noOfDecimals) {
if (value != null) {
String returnValue = value;
int decimalLength = 0;
if (value.contains(".")) {
decimalLength = value.substring(value.indexOf(".")).length();
}
if (decimalLength > noOfDecimals) {
returnValue = value.substring(0, value.indexOf(".") + noOfDecimals + 1);
}
return returnValue;
} else {
return "";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,17 @@ public void testGetNumberOfFractionDigits_NoDigitDecimal(){
int noOfDigits = CurrencyParser.getInstance(context).getNumberOfFractionDigits("JPY");
assertThat(noOfDigits, is(0));
}

@Test
public void testFXRateWithFourDecimal()
{
assertThat("1.2345",is(CurrencyParser.getValueWithTruncateDecimals("1.234567",4)));
assertThat("1.234",is(CurrencyParser.getValueWithTruncateDecimals("1.234",4)));
assertThat("1.0000",is(CurrencyParser.getValueWithTruncateDecimals("1.000056",4)));
assertThat("1",is(CurrencyParser.getValueWithTruncateDecimals("1",4)));
assertThat("",is(CurrencyParser.getValueWithTruncateDecimals(null,4)));
assertThat("1.234",is(CurrencyParser.getValueWithTruncateDecimals("1.234567",3)));
assertThat("1.23",is(CurrencyParser.getValueWithTruncateDecimals("1.234567",2)));
assertThat("1.2",is(CurrencyParser.getValueWithTruncateDecimals("1.234567",1)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.action.ViewActions.longClick;
import static androidx.test.espresso.assertion.ViewAssertions.doesNotExist;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.hasDescendant;
Expand All @@ -28,6 +29,7 @@
import androidx.test.core.app.ApplicationProvider;
import androidx.test.espresso.IdlingRegistry;
import androidx.test.espresso.contrib.RecyclerViewActions;
import androidx.test.espresso.matcher.RootMatchers;
import androidx.test.espresso.matcher.ViewMatchers;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.rule.ActivityTestRule;
Expand Down Expand Up @@ -565,6 +567,39 @@ public void testListReceipt_checkDateTextOnLocaleChange() {
onView(withId(R.id.list_receipts)).check(matches(atPosition(0, hasDescendant(withText("2 maggio 2019")))));
}

@Test
public void testListReceipt_selectTransactionDetails() {
mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager
.getResourceContent("receipt_list_response.json")).mock();
mMockWebServer.mockResponse().withHttpResponseCode(HTTP_NO_CONTENT).withBody("").mock();
// run test
mActivityTestRule.launchActivity(null);
// assert
onView(allOf(instanceOf(TextView.class), withParent(withId(R.id.toolbar))))
.check(matches(withText(R.string.title_activity_receipt_list)));
onView(withId(R.id.list_receipts)).check(matches(isDisplayed()));
onView(withId(R.id.list_receipts)).perform(RecyclerViewActions.actionOnItemAtPosition(3, click()));
onView(withId(R.id.transaction_header_text)).check(matches(withText(R.string.mobileTransactionTypeLabel)));
onView(withId(R.id.transaction_type_icon)).check(matches(withText(R.string.debit)));
onView(withId(R.id.transaction_title)).check(matches(withText(R.string.transfer_to_prepaid_card)));
onView(withId(R.id.transaction_title)).perform(longClick());
onView(withText("Copy")).inRoot(RootMatchers.isPlatformPopup()).check(matches(isDisplayed()));
onView(withId(R.id.transaction_amount)).perform(longClick());
onView(withText("Copy")).inRoot(RootMatchers.isPlatformPopup()).check(matches(isDisplayed()));
onView(withId(R.id.transaction_currency)).perform(longClick());
onView(withText("Copy")).inRoot(RootMatchers.isPlatformPopup()).check(matches(isDisplayed()));
onView(withId(R.id.transaction_date)).perform(longClick());
onView(withText("Copy")).inRoot(RootMatchers.isPlatformPopup()).check(matches(isDisplayed()));
onView(withId(R.id.receipt_id_label)).perform(longClick());
onView(withText("Copy")).inRoot(RootMatchers.isPlatformPopup()).check(matches(isDisplayed()));
onView(withId(R.id.receipt_id_value)).perform(longClick());
onView(withText("Copy")).inRoot(RootMatchers.isPlatformPopup()).check(matches(isDisplayed()));
onView(withId(R.id.date_label)).perform(longClick());
onView(withText("Copy")).inRoot(RootMatchers.isPlatformPopup()).check(matches(isDisplayed()));
onView(withId(R.id.date_value)).perform(longClick());
onView(withText("Copy")).inRoot(RootMatchers.isPlatformPopup()).check(matches(isDisplayed()));
}

@Test
public void testListReceipt_displaysNetworkErrorDialogOnConnectionTimeout() {
mMockWebServer.getServer().enqueue(new MockResponse().setResponseCode(HTTP_OK).setBody(sResourceManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@
package com.hyperwallet.android.ui.receipt.view;

import static android.text.format.DateUtils.FORMAT_ABBREV_MONTH;
import static android.text.format.DateUtils.FORMAT_ABBREV_WEEKDAY;
import static android.text.format.DateUtils.FORMAT_SHOW_DATE;
import static android.text.format.DateUtils.FORMAT_SHOW_TIME;
import static android.text.format.DateUtils.FORMAT_SHOW_WEEKDAY;
import static android.text.format.DateUtils.FORMAT_SHOW_YEAR;
import static android.text.format.DateUtils.formatDateTime;

import static com.hyperwallet.android.model.receipt.Receipt.Entries.CREDIT;
import static com.hyperwallet.android.model.receipt.Receipt.Entries.DEBIT;
import static com.hyperwallet.android.ui.common.util.CurrencyParser.getValueWithTruncateDecimals;

import android.content.Context;
import android.os.Build;
Expand Down Expand Up @@ -117,6 +116,22 @@ private void setTransactionView(@NonNull final Receipt receipt, @NonNull final V
TextView transactionCurrency = view.findViewById(R.id.transaction_currency);
String currencyString = Currency.getInstance(receipt.getCurrency()).getSymbol(Locale.getDefault());

transactionTitle.setTextIsSelectable(true);
transactionTitle.setLongClickable(true);
transactionTitle.setFocusable(true);

transactionDate.setTextIsSelectable(true);
transactionDate.setLongClickable(true);
transactionDate.setFocusable(true);

transactionAmount.setTextIsSelectable(true);
transactionAmount.setLongClickable(true);
transactionAmount.setFocusable(true);

transactionCurrency.setTextIsSelectable(true);
transactionCurrency.setLongClickable(true);
transactionCurrency.setFocusable(true);

if (CREDIT.equals(receipt.getEntry())) {
transactionAmount.setTextColor(transactionAmount.getContext()
.getResources().getColor(R.color.positiveColor));
Expand Down Expand Up @@ -213,8 +228,14 @@ private void setDetailsView(@NonNull final Receipt receipt, @NonNull final View
}

if (!TextUtils.isEmpty(receiptDetails.getNotes())) {
setViewInformation(R.id.receipt_notes_information, R.id.notes_value,
view, receiptDetails.getNotes());
if (receipt.getForeignExchangeRate() != null) {
String fxRate = getValueWithTruncateDecimals(receipt.getForeignExchangeRate(),4);
setViewInformation(R.id.receipt_notes_information, R.id.notes_value,
view, receiptDetails.getNotes().replace(receipt.getForeignExchangeRate(), fxRate));
} else {
setViewInformation(R.id.receipt_notes_information, R.id.notes_value,
view, receiptDetails.getNotes());
}
}
}
}
Expand Down
57 changes: 57 additions & 0 deletions receiptui/src/main/res/layout/fragment_receipt_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@
android:layout_alignParentTop="true"
android:layout_marginTop="@dimen/grid_margin_top"
android:text="@string/mobileJournalNumberLabel"
android:textIsSelectable="true"
android:focusable="true"
android:longClickable="true"
android:textAppearance="@style/TextAppearance.Hyperwallet.Body1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand All @@ -108,6 +111,9 @@
android:layout_toEndOf="@+id/receipt_id_label"
android:layout_marginTop="@dimen/grid_margin_top"
android:layout_marginBottom="0dp"
android:textIsSelectable="true"
android:focusable="true"
android:longClickable="true"
tools:text="@string/text_placeholder"
android:textAppearance="@style/TextAppearance.Hyperwallet.Caption"
app:layout_constraintEnd_toEndOf="parent"
Expand All @@ -127,6 +133,9 @@
android:layout_height="wrap_content"
android:paddingTop="@dimen/item_text_top_bottom_margin"
android:text="@string/date"
android:textIsSelectable="true"
android:focusable="true"
android:longClickable="true"
android:textAppearance="@style/TextAppearance.Hyperwallet.Body1" />

<TextView
Expand All @@ -139,6 +148,9 @@
android:gravity="end"
android:paddingTop="@dimen/item_text_top_bottom_margin"
tools:text="@string/text_placeholder"
android:textIsSelectable="true"
android:focusable="true"
android:longClickable="true"
android:textAppearance="@style/TextAppearance.Hyperwallet.Caption" />
</RelativeLayout>

Expand All @@ -158,6 +170,9 @@
android:layout_alignParentTop="true"
android:layout_marginTop="@dimen/item_text_top_bottom_margin"
android:text="@string/mobileMerchantTxnLabel"
android:textIsSelectable="true"
android:focusable="true"
android:longClickable="true"
android:textAppearance="@style/TextAppearance.Hyperwallet.Body1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintStart_toStartOf="parent" />
Expand All @@ -175,6 +190,9 @@
android:layout_toEndOf="@+id/client_id_label"
android:gravity="end"
tools:text="@string/text_placeholder"
android:textIsSelectable="true"
android:focusable="true"
android:longClickable="true"
android:textAppearance="@style/TextAppearance.Hyperwallet.Caption"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
Expand All @@ -196,6 +214,9 @@
android:layout_alignParentTop="true"
android:layout_marginTop="@dimen/item_text_top_bottom_margin"
android:text="@string/mobileCharityName"
android:textIsSelectable="true"
android:focusable="true"
android:longClickable="true"
android:textAppearance="@style/TextAppearance.Hyperwallet.Body1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintStart_toStartOf="parent"/>
Expand All @@ -210,6 +231,9 @@
android:layout_toEndOf="@+id/charity_label"
android:gravity="end"
tools:text="@string/text_placeholder"
android:textIsSelectable="true"
android:focusable="true"
android:longClickable="true"
android:textAppearance="@style/TextAppearance.Hyperwallet.Caption"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
Expand All @@ -231,6 +255,9 @@
android:layout_alignParentTop="true"
android:layout_marginTop="@dimen/item_text_top_bottom_margin"
android:text="@string/mobileCheckNumber"
android:textIsSelectable="true"
android:focusable="true"
android:longClickable="true"
android:textAppearance="@style/TextAppearance.Hyperwallet.Body1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintStart_toStartOf="parent" />
Expand All @@ -246,6 +273,9 @@
android:layout_toEndOf="@+id/check_number_label"
android:gravity="end"
tools:text="@string/text_placeholder"
android:textIsSelectable="true"
android:focusable="true"
android:longClickable="true"
android:textAppearance="@style/TextAppearance.Hyperwallet.Caption"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
Expand All @@ -267,6 +297,9 @@
android:layout_alignParentTop="true"
android:layout_marginTop="@dimen/item_text_top_bottom_margin"
android:text="@string/mobilePromoWebsite"
android:textIsSelectable="true"
android:focusable="true"
android:longClickable="true"
android:textAppearance="@style/TextAppearance.Hyperwallet.Body1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintStart_toStartOf="parent" />
Expand All @@ -282,6 +315,9 @@
android:layout_toEndOf="@+id/website_label"
android:gravity="end"
tools:text="@string/text_placeholder"
android:textIsSelectable="true"
android:focusable="true"
android:longClickable="true"
android:textAppearance="@style/TextAppearance.Hyperwallet.Caption"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
Expand Down Expand Up @@ -326,6 +362,9 @@
android:layout_marginTop="@dimen/grid_margin_top"
android:layout_marginBottom="@dimen/grid_margin_bottom"
tools:text="@string/text_placeholder"
android:textIsSelectable="true"
android:focusable="true"
android:longClickable="true"
android:textAppearance="@style/TextAppearance.Hyperwallet.Caption"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
Expand Down Expand Up @@ -374,6 +413,9 @@
android:layout_alignParentTop="true"
android:layout_marginTop="@dimen/grid_margin_top"
android:text="@string/amount"
android:textIsSelectable="true"
android:focusable="true"
android:longClickable="true"
android:textAppearance="@style/TextAppearance.Hyperwallet.Body1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand All @@ -391,6 +433,9 @@
android:layout_marginTop="@dimen/grid_margin_top"
android:layout_marginBottom="0dp"
tools:text="@string/text_placeholder"
android:textIsSelectable="true"
android:focusable="true"
android:longClickable="true"
android:textAppearance="@style/TextAppearance.Hyperwallet.Caption"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Expand All @@ -412,6 +457,9 @@
android:layout_alignParentTop="true"
android:layout_marginTop="@dimen/grid_margin_top"
android:text="@string/mobileFeeLabel"
android:textIsSelectable="true"
android:focusable="true"
android:longClickable="true"
android:textAppearance="@style/TextAppearance.Hyperwallet.Body1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand All @@ -429,6 +477,9 @@
android:layout_marginTop="@dimen/grid_margin_top"
android:layout_marginBottom="0dp"
tools:text="@string/text_placeholder"
android:textIsSelectable="true"
android:focusable="true"
android:longClickable="true"
android:textAppearance="@style/TextAppearance.Hyperwallet.Caption"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Expand All @@ -450,6 +501,9 @@
android:layout_alignParentTop="true"
android:layout_marginTop="@dimen/grid_margin_top"
android:text="@string/mobileTransactionDetailsTotal"
android:textIsSelectable="true"
android:focusable="true"
android:longClickable="true"
android:textAppearance="@style/TextAppearance.Hyperwallet.Body1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand All @@ -467,6 +521,9 @@
android:layout_marginTop="@dimen/grid_margin_top"
android:layout_marginBottom="0dp"
tools:text="@string/text_placeholder"
android:textIsSelectable="true"
android:focusable="true"
android:longClickable="true"
android:textAppearance="@style/TextAppearance.Hyperwallet.Caption"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Expand Down
Loading