Search in sources :

Example 81 with MainActivity

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);
}
Also used : Context(android.content.Context) DecimalFormatSymbols(java.text.DecimalFormatSymbols) HashMap(java.util.HashMap) ApiCallException(com.odysee.app.exceptions.ApiCallException) DecimalFormat(java.text.DecimalFormat) MainActivity(com.odysee.app.MainActivity) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) ListView(android.widget.ListView) CreditsBalanceView(com.odysee.app.views.CreditsBalanceView) BigDecimal(java.math.BigDecimal) ExecutorService(java.util.concurrent.ExecutorService)

Example 82 with MainActivity

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;
        }
    });
}
Also used : Context(android.content.Context) SharedPreferences(android.content.SharedPreferences) ViewGroup(android.view.ViewGroup) GestureDetector(android.view.GestureDetector) MainActivity(com.odysee.app.MainActivity) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) DividerItemDecoration(androidx.recyclerview.widget.DividerItemDecoration) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) ListView(android.widget.ListView) CreditsBalanceView(com.odysee.app.views.CreditsBalanceView) MotionEvent(android.view.MotionEvent)

Example 83 with MainActivity

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);
    }
}
Also used : Context(android.content.Context) MainActivity(com.odysee.app.MainActivity)

Example 84 with MainActivity

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);
}
Also used : Context(android.content.Context) ClaimListResultHandler(com.odysee.app.tasks.claim.ClaimListResultHandler) ClaimListTask(com.odysee.app.tasks.claim.ClaimListTask) MainActivity(com.odysee.app.MainActivity) ClaimListAdapter(com.odysee.app.adapter.ClaimListAdapter) Claim(com.odysee.app.model.Claim)

Example 85 with MainActivity

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();
}
Also used : Context(android.content.Context) MainActivity(com.odysee.app.MainActivity)

Aggregations

MainActivity (com.odysee.app.MainActivity)138 Context (android.content.Context)119 Claim (com.odysee.app.model.Claim)39 View (android.view.View)31 TextView (android.widget.TextView)30 RecyclerView (androidx.recyclerview.widget.RecyclerView)26 AttributeProviderContext (org.commonmark.renderer.html.AttributeProviderContext)25 ArrayList (java.util.ArrayList)21 TrackSelectionOverride (com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride)19 ImageView (android.widget.ImageView)18 SuppressLint (android.annotation.SuppressLint)15 AdapterView (android.widget.AdapterView)14 NestedScrollView (androidx.core.widget.NestedScrollView)14 JSONException (org.json.JSONException)13 JSONObject (org.json.JSONObject)13 SolidIconView (com.odysee.app.ui.controls.SolidIconView)12 HashMap (java.util.HashMap)12 ClaimListAdapter (com.odysee.app.adapter.ClaimListAdapter)11 ApiCallException (com.odysee.app.exceptions.ApiCallException)11 WebView (android.webkit.WebView)10