-
Notifications
You must be signed in to change notification settings - Fork 16
HW-53039 receipt view ppc #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
1b44713
HW-52585 UI - Receipt Details
6f222bd
remove unnecessary configs
4d87981
formatted amounts
5ffbcb3
remove static
30d585a
fixed variable name
c692629
refactored methods
f7cf238
Merge remote-tracking branch 'remotes/origin/development' into featur…
8987e71
added 12-HR to 24-HR and vice-versa formatter
5c00306
granular code {^__^}
1241fdc
convention
8d9138a
fix amount and transfer amount reversed
9d743d1
Merge remote-tracking branch 'remotes/origin/development' into featur…
465ecb9
fix date localization formatting to receipt views
bf61a05
update background effect to use ripple, added todos for currency form…
8163d53
ui specs changes
cf23ee8
update notes value layout
83d424d
try remove lint exception
972dd0c
fixed lint
7ddf49d
by design decision removing binding classes into duplicate code
2be481e
synced with core sdk
7443ad6
fixing typo
fmattos-hw ff14349
revert rename
43b351f
Automation for receipt details and receipt network retry (#43)
skoong 9a87a91
added finalizer identifiers
1127fc1
Merge branch 'development' into feature/HW-52585-ui-receipt-details
skoong ca29ad4
Updating response throttling
skoong 2ac6d59
renamed receipts to user list specific
680b4c6
changed singletone to immutable data source factory
0f5e5d5
generalized view model so that we can reuse the user receipt view for…
4082b82
added data source for prepaid card and test equivalent unit test
109db66
initial integration of ppc and user receipts
5d28e64
Merge remote-tracking branch 'remotes/origin/development' into featur…
77ade14
fixed test
21175ff
removed extra import
7cf603c
local review
d8fa65b
Merge remote-tracking branch 'remotes/origin/development' into featur…
d4c97ea
change data
e47433c
fix javadocs
73fd500
removed unused exception in test
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
107 changes: 107 additions & 0 deletions
107
.../src/androidTest/java/com/hyperwallet/android/ui/receipt/ListPrepaidCardReceiptsTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| package com.hyperwallet.android.ui.receipt; | ||
|
|
||
| import static androidx.test.espresso.Espresso.onView; | ||
| import static androidx.test.espresso.assertion.ViewAssertions.matches; | ||
| import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; | ||
| import static androidx.test.espresso.matcher.ViewMatchers.withId; | ||
| import static androidx.test.espresso.matcher.ViewMatchers.withParent; | ||
| import static androidx.test.espresso.matcher.ViewMatchers.withText; | ||
|
|
||
| import static org.hamcrest.Matchers.allOf; | ||
| import static org.hamcrest.Matchers.instanceOf; | ||
|
|
||
| import static java.net.HttpURLConnection.HTTP_NO_CONTENT; | ||
| import static java.net.HttpURLConnection.HTTP_OK; | ||
|
|
||
| import static com.hyperwallet.android.ui.receipt.view.ListPrepaidCardReceiptActivity.EXTRA_PREPAID_CARD_TOKEN; | ||
|
|
||
| import android.content.Context; | ||
| import android.content.Intent; | ||
| import android.content.res.Configuration; | ||
| import android.content.res.Resources; | ||
| import android.widget.TextView; | ||
|
|
||
| import androidx.test.core.app.ApplicationProvider; | ||
| import androidx.test.espresso.IdlingRegistry; | ||
| import androidx.test.ext.junit.runners.AndroidJUnit4; | ||
| import androidx.test.rule.ActivityTestRule; | ||
|
|
||
| import com.hyperwallet.android.Hyperwallet; | ||
| import com.hyperwallet.android.ui.common.util.EspressoIdlingResource; | ||
| import com.hyperwallet.android.ui.receipt.rule.HyperwalletExternalResourceManager; | ||
| import com.hyperwallet.android.ui.receipt.rule.HyperwalletMockWebServer; | ||
| import com.hyperwallet.android.ui.receipt.util.TestAuthenticationProvider; | ||
| import com.hyperwallet.android.ui.receipt.view.ListPrepaidCardReceiptActivity; | ||
|
|
||
| import org.junit.After; | ||
| import org.junit.Before; | ||
| import org.junit.ClassRule; | ||
| import org.junit.Rule; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
|
|
||
| import java.util.Locale; | ||
|
|
||
| @RunWith(AndroidJUnit4.class) | ||
| public class ListPrepaidCardReceiptsTest { | ||
|
|
||
| @ClassRule | ||
| public static HyperwalletExternalResourceManager sResourceManager = new HyperwalletExternalResourceManager(); | ||
| @Rule | ||
| public HyperwalletMockWebServer mMockWebServer = new HyperwalletMockWebServer(8080); | ||
| @Rule | ||
| public ActivityTestRule<ListPrepaidCardReceiptActivity> mActivityTestRule = | ||
| new ActivityTestRule<ListPrepaidCardReceiptActivity>(ListPrepaidCardReceiptActivity.class, true, false) { | ||
| @Override | ||
| protected Intent getActivityIntent() { | ||
| Intent intent = new Intent(ApplicationProvider.getApplicationContext(), | ||
| ListPrepaidCardReceiptActivity.class); | ||
| intent.putExtra(EXTRA_PREPAID_CARD_TOKEN, "trm-test-token"); | ||
| return intent; | ||
| } | ||
| }; | ||
|
|
||
| @Before | ||
| public void setup() { | ||
| Hyperwallet.getInstance(new TestAuthenticationProvider()); | ||
|
|
||
| mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager | ||
| .getResourceContent("authentication_token_response.json")).mock(); | ||
|
|
||
| setLocale(Locale.US); | ||
| IdlingRegistry.getInstance().register(EspressoIdlingResource.getIdlingResource()); | ||
| } | ||
|
|
||
| @After | ||
| public void unregisterIdlingResource() { | ||
| IdlingRegistry.getInstance().unregister(EspressoIdlingResource.getIdlingResource()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testListReceipt_userHasMultipleTransactions() { | ||
| mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager | ||
| .getResourceContent("prepaid_card_receipt_list.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())); | ||
| } | ||
|
|
||
| private void setLocale(Locale locale) { | ||
| Context context = ApplicationProvider.getApplicationContext(); | ||
| Locale.setDefault(locale); | ||
| Resources resources = context.getResources(); | ||
| Configuration configuration = resources.getConfiguration(); | ||
| if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.JELLY_BEAN) { | ||
| configuration.setLocale(locale); | ||
| } else { | ||
| configuration.locale = locale; | ||
| } | ||
| resources.updateConfiguration(configuration, resources.getDisplayMetrics()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
198 changes: 198 additions & 0 deletions
198
...main/java/com/hyperwallet/android/ui/receipt/repository/PrepaidCardReceiptDataSource.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,198 @@ | ||
| /* | ||
| * The MIT License (MIT) | ||
| * Copyright (c) 2019 Hyperwallet Systems Inc. | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and | ||
| * associated documentation files (the "Software"), to deal in the Software without restriction, | ||
| * including without limitation the rights to use, copy, modify, merge, publish, distribute, | ||
| * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT | ||
| * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
| * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
| * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| */ | ||
| package com.hyperwallet.android.ui.receipt.repository; | ||
|
|
||
| import android.os.Handler; | ||
|
|
||
| import androidx.annotation.NonNull; | ||
| import androidx.annotation.Nullable; | ||
| import androidx.lifecycle.LiveData; | ||
| import androidx.lifecycle.MutableLiveData; | ||
| import androidx.paging.PageKeyedDataSource; | ||
|
|
||
| import com.hyperwallet.android.Hyperwallet; | ||
| import com.hyperwallet.android.exception.HyperwalletException; | ||
| import com.hyperwallet.android.listener.HyperwalletListener; | ||
| import com.hyperwallet.android.model.HyperwalletErrors; | ||
| import com.hyperwallet.android.model.paging.HyperwalletPageList; | ||
| import com.hyperwallet.android.model.receipt.Receipt; | ||
| import com.hyperwallet.android.model.receipt.ReceiptQueryParam; | ||
| import com.hyperwallet.android.ui.common.viewmodel.Event; | ||
| import com.hyperwallet.android.util.DateUtil; | ||
|
|
||
| import java.util.Calendar; | ||
| import java.util.Date; | ||
|
|
||
| /** | ||
| * PrepaidCardReceiptDataSource mediates communication to HW API Platform particularly on | ||
| * Receipts PrepaidCard V3 API | ||
| */ | ||
| public class PrepaidCardReceiptDataSource extends PageKeyedDataSource<Date, Receipt> { | ||
|
|
||
| private static final int YEAR_BEFORE_NOW = -1; | ||
|
|
||
| private final Calendar mCalendarYearBeforeNow; | ||
| private final String mToken; | ||
| private final MutableLiveData<Event<HyperwalletErrors>> mErrors = new MutableLiveData<>(); | ||
| private final MutableLiveData<Boolean> mIsFetchingData = new MutableLiveData<>(); | ||
| private PageKeyedDataSource.LoadCallback<Date, Receipt> mLoadAfterCallback; | ||
| private PageKeyedDataSource.LoadParams<Date> mLoadAfterParams; | ||
| private PageKeyedDataSource.LoadInitialCallback<Date, Receipt> mLoadInitialCallback; | ||
| private PageKeyedDataSource.LoadInitialParams<Date> mLoadInitialParams; | ||
|
|
||
| /** | ||
| * Initialize Prepaid card data source | ||
| * | ||
| * @param token Prepaid card token identifier, please get this data from HW Platform | ||
| */ | ||
| PrepaidCardReceiptDataSource(@NonNull final String token) { | ||
| mToken = token; | ||
| mCalendarYearBeforeNow = Calendar.getInstance(); | ||
| mCalendarYearBeforeNow.add(Calendar.YEAR, YEAR_BEFORE_NOW); | ||
| } | ||
|
|
||
| /** | ||
| * @see PageKeyedDataSource#loadInitial(LoadInitialParams, LoadInitialCallback) | ||
| */ | ||
| @Override | ||
| public void loadInitial(@NonNull final LoadInitialParams<Date> params, | ||
| @NonNull final LoadInitialCallback<Date, Receipt> callback) { | ||
| mLoadInitialCallback = callback; | ||
| mLoadInitialParams = params; | ||
| mIsFetchingData.postValue(Boolean.TRUE); | ||
|
|
||
| ReceiptQueryParam queryParam = new ReceiptQueryParam.Builder() | ||
| .createdAfter(mCalendarYearBeforeNow.getTime()) | ||
| .sortByCreatedOnDesc().build(); | ||
|
|
||
| getHyperwallet().listPrepaidCardReceipts(mToken, queryParam, | ||
| new HyperwalletListener<HyperwalletPageList<Receipt>>() { | ||
| @Override | ||
| public void onSuccess(@Nullable HyperwalletPageList<Receipt> result) { | ||
| mIsFetchingData.postValue(Boolean.FALSE); | ||
| mErrors.postValue(null); | ||
|
|
||
| if (result != null) { | ||
| callback.onResult(result.getDataList(), mCalendarYearBeforeNow.getTime(), null); | ||
| } | ||
|
|
||
| // reset | ||
| mLoadInitialCallback = null; | ||
| mLoadInitialParams = null; | ||
| } | ||
|
|
||
| @Override | ||
| public void onFailure(HyperwalletException exception) { | ||
| mIsFetchingData.postValue(Boolean.FALSE); | ||
| mErrors.postValue(new Event<>(exception.getHyperwalletErrors())); | ||
| } | ||
|
|
||
| @Override | ||
| public Handler getHandler() { | ||
| return null; | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * @see PageKeyedDataSource#loadBefore(LoadParams, LoadCallback) | ||
| */ | ||
| @Override | ||
| public void loadBefore(@NonNull final LoadParams<Date> params, | ||
| @NonNull final LoadCallback<Date, Receipt> callback) { | ||
| } | ||
|
|
||
| /** | ||
| * @see PageKeyedDataSource#loadAfter(LoadParams, LoadCallback) | ||
| */ | ||
| @Override | ||
| public void loadAfter(@NonNull final LoadParams<Date> params, @NonNull final LoadCallback<Date, Receipt> callback) { | ||
| mLoadAfterCallback = callback; | ||
| mLoadAfterParams = params; | ||
| mIsFetchingData.postValue(Boolean.TRUE); | ||
|
|
||
| ReceiptQueryParam queryParam = new ReceiptQueryParam.Builder() | ||
| .createdAfter(params.key) | ||
| .limit(params.requestedLoadSize) | ||
| .sortByCreatedOnDesc().build(); | ||
|
|
||
| getHyperwallet().listPrepaidCardReceipts(mToken, queryParam, | ||
| new HyperwalletListener<HyperwalletPageList<Receipt>>() { | ||
| @Override | ||
| public void onSuccess(@Nullable HyperwalletPageList<Receipt> result) { | ||
| mIsFetchingData.postValue(Boolean.FALSE); | ||
| mErrors.postValue(null); | ||
|
|
||
| if (result != null) { | ||
| callback.onResult(result.getDataList(), getNextDate(result)); | ||
| } | ||
|
|
||
| // reset | ||
| mLoadAfterCallback = null; | ||
| mLoadAfterParams = null; | ||
| } | ||
|
|
||
| @Override | ||
| public void onFailure(HyperwalletException exception) { | ||
| mIsFetchingData.postValue(Boolean.FALSE); | ||
| mErrors.postValue(new Event<>(exception.getHyperwalletErrors())); | ||
| } | ||
|
|
||
| @Override | ||
| public Handler getHandler() { | ||
| return null; | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Facilitates retry when network is down; any error that we can have a retry operation | ||
| */ | ||
| void retry() { | ||
| if (mLoadInitialCallback != null) { | ||
| loadInitial(mLoadInitialParams, mLoadInitialCallback); | ||
| } else if (mLoadAfterCallback != null) { | ||
| loadAfter(mLoadAfterParams, mLoadAfterCallback); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Retrieve reference of Hyperwallet errors inorder for consumers to observe on data changes | ||
| * | ||
| * @return Live event data of {@link HyperwalletErrors} | ||
| */ | ||
| public LiveData<Event<HyperwalletErrors>> getErrors() { | ||
| return mErrors; | ||
| } | ||
|
|
||
| LiveData<Boolean> isFetchingData() { | ||
| return mIsFetchingData; | ||
| } | ||
|
|
||
| Hyperwallet getHyperwallet() { | ||
| return Hyperwallet.getDefault(); | ||
| } | ||
|
|
||
| private Date getNextDate(@Nullable final HyperwalletPageList<Receipt> result) { | ||
| if (result != null && result.getDataList() != null && !result.getDataList().isEmpty()) { | ||
| // get last receipt date | ||
| return DateUtil.fromDateTimeString( | ||
| result.getDataList().get(result.getDataList().size() - 1).getCreatedOn()); | ||
| } | ||
| return Calendar.getInstance().getTime(); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.