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);
}
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);
}
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);
}
});
}
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;
}
Aggregations