Search in sources :

Example 1 with Transaction

use of com.odysee.app.model.Transaction in project odysee-android by OdyseeTeam.

the class TransactionHistoryFragment method loadTransactions.

private void loadTransactions() {
    currentTransactionPage = currentTransactionPage == 0 ? 1 : currentTransactionPage;
    transactionsLoading = true;
    TransactionListTask task = new TransactionListTask(currentTransactionPage, TRANSACTION_PAGE_LIMIT, Lbryio.AUTH_TOKEN, loading, new TransactionListTask.TransactionListHandler() {

        @Override
        public void onSuccess(List<Transaction> transactions, boolean hasReachedEnd) {
            Context context = getContext();
            transactionsLoading = false;
            transactionsHaveReachedEnd = hasReachedEnd;
            if (context != null) {
                if (adapter == null) {
                    adapter = new TransactionListAdapter(transactions, context);
                    adapter.setListener(TransactionHistoryFragment.this);
                    if (transactionList != null) {
                        transactionList.setAdapter(adapter);
                    }
                } else {
                    adapter.addTransactions(transactions);
                }
            }
            checkNoTransactions();
        }

        @Override
        public void onError(Exception error) {
            transactionsLoading = false;
            checkNoTransactions();
        }
    });
    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : Context(android.content.Context) Transaction(com.odysee.app.model.Transaction) TransactionListTask(com.odysee.app.tasks.wallet.TransactionListTask) TransactionListAdapter(com.odysee.app.adapter.TransactionListAdapter)

Example 2 with Transaction

use of com.odysee.app.model.Transaction in project odysee-android by OdyseeTeam.

the class WalletFragment method fetchRecentTransactions.

private void fetchRecentTransactions(boolean forceFetch) {
    if (!Helper.isSignedIn(getContext())) {
        return;
    }
    if (hasFetchedRecentTransactions && !forceFetch) {
        return;
    }
    Helper.setViewVisibility(textNoRecentTransactions, View.GONE);
    AccountManager am = AccountManager.get(getContext());
    Account[] accounts = am.getAccounts();
    TransactionListTask task = new TransactionListTask(1, 5, am.peekAuthToken(Helper.getOdyseeAccount(accounts), "auth_token_type"), loadingRecentContainer, new TransactionListTask.TransactionListHandler() {

        @Override
        public void onSuccess(List<Transaction> transactions, boolean hasReachedEnd) {
            hasFetchedRecentTransactions = true;
            recentTransactionsAdapter = new TransactionListAdapter(transactions, getContext());
            recentTransactionsAdapter.setListener(new TransactionListAdapter.TransactionClickListener() {

                @Override
                public void onTransactionClicked(Transaction transaction) {
                }

                @Override
                public void onClaimUrlClicked(LbryUri uri) {
                    Context context = getContext();
                    if (uri != null && context instanceof MainActivity) {
                        MainActivity activity = (MainActivity) context;
                        if (uri.isChannel()) {
                            activity.openChannelUrl(uri.toString());
                        } else {
                            activity.openFileUrl(uri.toString());
                        }
                    }
                }
            });
            recentTransactionsList.setAdapter(recentTransactionsAdapter);
            displayNoRecentTransactions();
        }

        @Override
        public void onError(Exception error) {
            hasFetchedRecentTransactions = true;
            displayNoRecentTransactions();
        }
    });
    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : Context(android.content.Context) Account(android.accounts.Account) TransactionListTask(com.odysee.app.tasks.wallet.TransactionListTask) MainActivity(com.odysee.app.MainActivity) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ApiCallException(com.odysee.app.exceptions.ApiCallException) ExecutionException(java.util.concurrent.ExecutionException) Transaction(com.odysee.app.model.Transaction) AccountManager(android.accounts.AccountManager) LbryUri(com.odysee.app.utils.LbryUri) TransactionListAdapter(com.odysee.app.adapter.TransactionListAdapter)

Example 3 with Transaction

use of com.odysee.app.model.Transaction in project odysee-android by OdyseeTeam.

the class TransactionListAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(TransactionListAdapter.ViewHolder vh, int position) {
    Transaction item = items.get(position);
    vh.descView.setText(item.getDescriptionStringId());
    vh.amountView.setText(TX_LIST_AMOUNT_FORMAT.format(item.getValue().doubleValue()));
    vh.claimView.setText(item.getClaim());
    vh.feeView.setText(context.getString(R.string.tx_list_fee, TX_LIST_AMOUNT_FORMAT.format(item.getFee().doubleValue())));
    vh.txidLinkView.setText(item.getTxid().substring(0, 7));
    vh.dateView.setVisibility(item.getConfirmations() > 0 ? View.VISIBLE : View.GONE);
    vh.dateView.setText(item.getConfirmations() > 0 ? TX_LIST_DATE_FORMAT.format(item.getTxDate()) : null);
    vh.pendingView.setVisibility(item.getConfirmations() == 0 ? View.VISIBLE : View.GONE);
    vh.infoFeeContainer.setVisibility(!Helper.isNullOrEmpty(item.getClaim()) || Math.abs(item.getFee().doubleValue()) > 0 ? View.VISIBLE : View.GONE);
    vh.claimView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            LbryUri claimUrl = item.getClaimUrl();
            if (claimUrl != null && listener != null) {
                listener.onClaimUrlClicked(claimUrl);
            }
        }
    });
    vh.txidLinkView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (context != null) {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(String.format("%s/%s", Helper.EXPLORER_TX_PREFIX, item.getTxid())));
                context.startActivity(intent);
            }
        }
    });
    vh.itemView.setOnClickListener(view -> {
        if (listener != null) {
            listener.onTransactionClicked(item);
        }
    });
}
Also used : Transaction(com.odysee.app.model.Transaction) Intent(android.content.Intent) LbryUri(com.odysee.app.utils.LbryUri) TextView(android.widget.TextView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 4 with Transaction

use of com.odysee.app.model.Transaction in project odysee-android by OdyseeTeam.

the class Lbry method transactionList.

public static List<Transaction> transactionList(int page, int pageSize, String authToken) throws ApiCallException {
    List<Transaction> transactions = new ArrayList<>();
    Map<String, Object> params = new HashMap<>();
    if (page > 0) {
        params.put("page", page);
    }
    if (pageSize > 0) {
        params.put("page_size", pageSize);
    }
    if (authToken != "") {
        params.put("auth_token", authToken);
    }
    try {
        JSONObject result = (JSONObject) parseResponse(apiCall(METHOD_TRANSACTION_LIST, params, API_CONNECTION_STRING));
        JSONArray items = result.getJSONArray("items");
        for (int i = 0; i < items.length(); i++) {
            Transaction tx = Transaction.fromJSONObject(items.getJSONObject(i));
            transactions.add(tx);
        }
    } catch (LbryRequestException | LbryResponseException | JSONException ex) {
        throw new ApiCallException("Could not execute transaction_list call", ex);
    }
    return transactions;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ApiCallException(com.odysee.app.exceptions.ApiCallException) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) LbryResponseException(com.odysee.app.exceptions.LbryResponseException) LbryRequestException(com.odysee.app.exceptions.LbryRequestException) Transaction(com.odysee.app.model.Transaction) JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject)

Aggregations

Transaction (com.odysee.app.model.Transaction)4 Context (android.content.Context)2 TransactionListAdapter (com.odysee.app.adapter.TransactionListAdapter)2 ApiCallException (com.odysee.app.exceptions.ApiCallException)2 TransactionListTask (com.odysee.app.tasks.wallet.TransactionListTask)2 LbryUri (com.odysee.app.utils.LbryUri)2 Account (android.accounts.Account)1 AccountManager (android.accounts.AccountManager)1 Intent (android.content.Intent)1 View (android.view.View)1 TextView (android.widget.TextView)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 MainActivity (com.odysee.app.MainActivity)1 LbryRequestException (com.odysee.app.exceptions.LbryRequestException)1 LbryResponseException (com.odysee.app.exceptions.LbryResponseException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 InvalidKeyException (java.security.InvalidKeyException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1