use of com.odysee.app.MainActivity in project odysee-android by OdyseeTeam.
the class WalletFragment method sendCredits.
private void sendCredits() {
// wallet_send task
View view = getView();
String recipientAddress = Helper.getValue(inputSendAddress.getText());
String amountString = Helper.getValue(inputSendAmount.getText());
final String amount;
try {
amount = new DecimalFormat(Helper.SDK_AMOUNT_FORMAT, new DecimalFormatSymbols(Locale.US)).format(new BigDecimal(amountString).doubleValue());
} catch (NumberFormatException ex) {
if (view != null) {
Snackbar.make(view, R.string.invalid_amount, Snackbar.LENGTH_LONG).setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show();
}
return;
}
double actualSendAmount = Double.parseDouble(amount);
if (actualSendAmount < Helper.MIN_SPEND) {
if (view != null) {
Snackbar.make(view, R.string.min_spend_required, Snackbar.LENGTH_LONG).setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show();
}
return;
}
disableSendControls();
Helper.setViewVisibility(walletSendProgress, View.VISIBLE);
Runnable sendRunnable = new Runnable() {
@Override
public void run() {
boolean result = false;
Context ctx = getContext();
if (ctx instanceof MainActivity) {
MainActivity activity = (MainActivity) ctx;
try {
Map<String, Object> options = new HashMap<>();
options.put("addresses", Collections.singletonList(recipientAddress));
options.put("amount", amount);
options.put("blocking", true);
Lbry.directApiCall(Lbry.METHOD_WALLET_SEND, options, activity.getAuthToken());
result = true;
} catch (ApiCallException ex) {
// pass
}
}
handleSendResult(result, actualSendAmount);
}
};
ExecutorService executorService = Executors.newSingleThreadExecutor();
executorService.execute(sendRunnable);
}
use of com.odysee.app.MainActivity in project odysee-android by OdyseeTeam.
the class WalletFragment method initUi.
@SuppressWarnings("ClickableViewAccessibility")
private void initUi() {
onWalletBalanceUpdated(Lbry.walletBalance);
Helper.applyHtmlForTextView(textConvertCredits);
Helper.applyHtmlForTextView(textWhatSyncMeans);
Helper.applyHtmlForTextView(linkManualBackup);
Helper.applyHtmlForTextView(linkSyncFAQ);
Context context = getContext();
LinearLayoutManager llm = new LinearLayoutManager(context);
recentTransactionsList.setLayoutManager(llm);
DividerItemDecoration itemDecoration = new DividerItemDecoration(context, DividerItemDecoration.VERTICAL);
itemDecoration.setDrawable(ContextCompat.getDrawable(context, R.drawable.thin_divider));
recentTransactionsList.addItemDecoration(itemDecoration);
buttonViewMore.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Context context = getContext();
if (context instanceof MainActivity) {
View walletDetail = ((MainActivity) context).findViewById(R.id.balance_detail_listview);
if (walletDetail.getVisibility() == View.GONE) {
int listHeight = Math.round(getResources().getDisplayMetrics().density);
for (int i = 0; i < detailRows.size(); i++) {
View item = detailAdapter.getView(i, null, detailListView);
item.measure(0, 0);
listHeight += item.getMeasuredHeight();
}
// Avoid scroll bars being displayed
ViewGroup.LayoutParams params = detailListView.getLayoutParams();
params.height = listHeight + (detailListView.getCount() + 1) * detailListView.getDividerHeight();
detailListView.setLayoutParams(params);
detailListView.setVerticalScrollBarEnabled(false);
detailListView.requestLayout();
TransitionManager.beginDelayedTransition((ViewGroup) walletDetail.getParent());
walletDetail.setVisibility(View.VISIBLE);
buttonViewMore.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, R.drawable.ic_arrow_dropup, 0);
} else {
walletDetail.setVisibility(View.GONE);
buttonViewMore.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, R.drawable.ic_arrow_dropdown, 0);
}
}
}
});
textWalletReceiveAddress.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
copyReceiveAddress();
}
});
buttonCopyReceiveAddress.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
copyReceiveAddress();
}
});
buttonSend.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (validateSend()) {
sendCredits();
}
}
});
inputSendAddress.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean hasFocus) {
inputSendAddress.setHint(hasFocus ? getString(R.string.recipient_address_placeholder) : "");
}
});
inputSendAmount.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean hasFocus) {
inputSendAmount.setHint(hasFocus ? getString(R.string.zero) : "");
inlineBalanceContainer.setVisibility(hasFocus ? View.VISIBLE : View.INVISIBLE);
}
});
linkViewAll.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Context context = getContext();
if (context instanceof MainActivity) {
((MainActivity) context).openFragment(TransactionHistoryFragment.class, true, null);
}
}
});
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
final boolean walletSyncEnabled = sp.getBoolean(MainActivity.PREFERENCE_KEY_INTERNAL_WALLET_SYNC_ENABLED, false);
switchSyncStatus.setChecked(walletSyncEnabled);
switchSyncStatus.setText(walletSyncEnabled ? R.string.on : R.string.off);
textWalletHintSyncStatus.setText(walletSyncEnabled ? R.string.backup_synced : R.string.backup_notsynced);
textConnectedEmail.setText(walletSyncEnabled ? Lbryio.getSignedInEmail() : null);
GestureDetector.SimpleOnGestureListener gestureListener = new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
if (switchSyncStatus.isChecked()) {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
sp.edit().putBoolean(MainActivity.PREFERENCE_KEY_INTERNAL_WALLET_SYNC_ENABLED, false).apply();
switchSyncStatus.setText(R.string.off);
switchSyncStatus.setChecked(false);
} else {
// launch verification activity for wallet sync flow
Context context = getContext();
if (context instanceof MainActivity) {
((MainActivity) context).walletSyncSignIn();
}
}
return true;
}
};
GestureDetector detector = new GestureDetector(getContext(), gestureListener);
switchSyncStatus.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
detector.onTouchEvent(motionEvent);
return true;
}
});
}
use of com.odysee.app.MainActivity in project odysee-android by OdyseeTeam.
the class WalletFragment method onStart.
public void onStart() {
super.onStart();
Context context = getContext();
if (context instanceof MainActivity) {
MainActivity activity = (MainActivity) context;
if (!activity.isSignedIn()) {
activity.simpleSignIn(R.id.action_wallet_menu);
}
activity.addWalletBalanceListener(this);
}
}
use of com.odysee.app.MainActivity in project odysee-android by OdyseeTeam.
the class PublishesFragment method fetchPublishes.
private void fetchPublishes() {
Helper.setViewVisibility(emptyView, View.GONE);
ClaimListTask task = new ClaimListTask(Arrays.asList(Claim.TYPE_STREAM, Claim.TYPE_REPOST), getLoading(), new ClaimListResultHandler() {
@Override
public void onSuccess(List<Claim> claims) {
Lbry.ownClaims = Helper.filterDeletedClaims(new ArrayList<>(claims));
if (adapter == null) {
Context context = getContext();
if (context != null) {
adapter = new ClaimListAdapter(claims, context);
adapter.setCanEnterSelectionMode(true);
adapter.setSelectionModeListener(PublishesFragment.this);
adapter.setListener(new ClaimListAdapter.ClaimListItemListener() {
@Override
public void onClaimClicked(Claim claim, int position) {
if (context instanceof MainActivity) {
MainActivity activity = (MainActivity) context;
if (claim.getName().startsWith("@")) {
activity.openChannelClaim(claim);
} else {
activity.openFileClaim(claim);
}
}
}
});
if (contentList != null) {
contentList.setAdapter(adapter);
}
}
} else {
adapter.setItems(claims);
}
checkNoPublishes();
}
@Override
public void onError(Exception error) {
checkNoPublishes();
}
});
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
use of com.odysee.app.MainActivity in project odysee-android by OdyseeTeam.
the class PublishesFragment method onResume.
public void onResume() {
super.onResume();
Context context = getContext();
if (context instanceof MainActivity) {
MainActivity activity = (MainActivity) context;
activity.setWunderbarValue(null);
LbryAnalytics.setCurrentScreen(activity, "Publishes", "Publishes");
}
if (adapter != null && contentList != null) {
contentList.setAdapter(adapter);
}
fetchPublishes();
}
Aggregations