|
| 1 | +/* |
| 2 | + * Copyright 2018 Hyperwallet |
| 3 | + * |
| 4 | + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated |
| 5 | + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation |
| 6 | + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and |
| 7 | + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: |
| 8 | + * |
| 9 | + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of |
| 10 | + * the Software. |
| 11 | + * |
| 12 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO |
| 13 | + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 14 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 15 | + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 16 | + * THE SOFTWARE. |
| 17 | + */ |
| 18 | +package com.hyperwallet.android.ui.balance.repository; |
| 19 | + |
| 20 | +import android.os.Handler; |
| 21 | + |
| 22 | +import androidx.annotation.NonNull; |
| 23 | +import androidx.annotation.Nullable; |
| 24 | +import androidx.annotation.VisibleForTesting; |
| 25 | + |
| 26 | +import com.hyperwallet.android.Hyperwallet; |
| 27 | +import com.hyperwallet.android.exception.HyperwalletException; |
| 28 | +import com.hyperwallet.android.listener.HyperwalletListener; |
| 29 | +import com.hyperwallet.android.model.balance.Balance; |
| 30 | +import com.hyperwallet.android.model.balance.PrepaidCardBalanceQueryParam; |
| 31 | +import com.hyperwallet.android.model.paging.PageList; |
| 32 | + |
| 33 | +import java.util.ArrayList; |
| 34 | + |
| 35 | +public class PrepaidCardBalanceRepositoryImpl implements PrepaidCardBalanceRepository { |
| 36 | + |
| 37 | + private final Handler mHandler = new Handler(); |
| 38 | + private final int LIMIT = 100; |
| 39 | + |
| 40 | + @VisibleForTesting |
| 41 | + Hyperwallet getHyperwallet() { |
| 42 | + return Hyperwallet.getDefault(); |
| 43 | + } |
| 44 | + |
| 45 | + |
| 46 | + @Override |
| 47 | + public void loadPrepaidCardBalances(String prepaidCardToken, |
| 48 | + @NonNull final LoadPrepaidCardBalanceCallback callback) { |
| 49 | + PrepaidCardBalanceQueryParam queryParam = new PrepaidCardBalanceQueryParam.Builder() |
| 50 | + .limit(LIMIT) |
| 51 | + .sortByCurrencyAsc() |
| 52 | + .build(); |
| 53 | + |
| 54 | + getHyperwallet().listPrepaidCardBalances(prepaidCardToken, queryParam, |
| 55 | + new HyperwalletListener<PageList<Balance>>() { |
| 56 | + @Override |
| 57 | + public void onSuccess(@Nullable PageList<Balance> result) { |
| 58 | + callback.onPrepaidCardBalanceLoaded( |
| 59 | + result != null ? result.getDataList() : new ArrayList<Balance>()); |
| 60 | + } |
| 61 | + |
| 62 | + @Override |
| 63 | + public void onFailure(HyperwalletException exception) { |
| 64 | + callback.onError(exception.getErrors()); |
| 65 | + } |
| 66 | + |
| 67 | + @Override |
| 68 | + public Handler getHandler() { |
| 69 | + return mHandler; |
| 70 | + } |
| 71 | + }); |
| 72 | + } |
| 73 | +} |
0 commit comments