Search in sources :

Example 51 with MainActivity

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

the class ChannelCreateDialogFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.channel_form_bottom_sheet, container, false);
    View balanceView = v.findViewById(R.id.channel_form_balanceview);
    TextInputEditText inputDeposit = v.findViewById(R.id.inline_channel_form_input_deposit);
    inputDeposit.setOnFocusChangeListener(new View.OnFocusChangeListener() {

        @Override
        public void onFocusChange(View view, boolean hasFocus) {
            Helper.setViewVisibility(balanceView, hasFocus ? View.VISIBLE : View.INVISIBLE);
        }
    });
    TextInputEditText inputChannelName = v.findViewById(R.id.inline_channel_form_input_name);
    TextView linkCancel = v.findViewById(R.id.inline_channel_form_cancel_link);
    linkCancel.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            inputChannelName.setText("");
            inputDeposit.setText(R.string.min_deposit);
            dismiss();
        }
    });
    View progressView = v.findViewById(R.id.inline_channel_form_create_progress);
    Button createButton = v.findViewById(R.id.inline_channel_form_create_button);
    createButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            // validate deposit and channel name
            String channelNameString = Helper.normalizeChannelName(Helper.getValue(inputChannelName.getText()));
            Claim claimToSave = new Claim();
            claimToSave.setName(channelNameString);
            String channelName = claimToSave.getName().startsWith("@") ? claimToSave.getName().substring(1) : claimToSave.getName();
            String depositString = Helper.getValue(inputDeposit.getText());
            if ("@".equals(channelName) || Helper.isNullOrEmpty(channelName)) {
                showError(getString(R.string.please_enter_channel_name));
                return;
            }
            if (!LbryUri.isNameValid(channelName)) {
                showError(getString(R.string.channel_name_invalid_characters));
                return;
            }
            if (Helper.channelExists(channelName)) {
                showError(getString(R.string.channel_name_already_created));
                return;
            }
            double depositAmount;
            try {
                depositAmount = Double.parseDouble(depositString);
            } catch (NumberFormatException ex) {
                // pass
                showError(getString(R.string.please_enter_valid_deposit));
                return;
            }
            if (depositAmount == 0) {
                String error = getResources().getQuantityString(R.plurals.min_deposit_required, depositAmount == 1 ? 1 : 2, String.valueOf(Helper.MIN_DEPOSIT));
                showError(error);
                return;
            }
            if (Lbry.walletBalance == null || Lbry.getAvailableBalance() < depositAmount) {
                showError(getString(R.string.deposit_more_than_balance));
                return;
            }
            AccountManager am = AccountManager.get(getContext());
            String authToken = am.peekAuthToken(Helper.getOdyseeAccount(am.getAccounts()), "auth_token_type");
            MainActivity activity = (MainActivity) getActivity();
            enableViews(inputChannelName, inputDeposit, createButton, linkCancel, false);
            Helper.setViewVisibility(progressView, View.VISIBLE);
            Callable<Claim> c = new ChannelCreateUpdate(claimToSave, new BigDecimal(depositString), false, authToken);
            ExecutorService executor = Executors.newSingleThreadExecutor();
            Future<Claim> future = executor.submit(c);
            Thread t = new Thread(new Runnable() {

                @Override
                public void run() {
                    try {
                        Claim result = future.get();
                        if (result != null) {
                            if (!BuildConfig.DEBUG) {
                                LogPublishTask logPublishTask = new LogPublishTask(result);
                                logPublishTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                            }
                            // channel created
                            Bundle bundle = new Bundle();
                            bundle.putString("claim_id", result.getClaimId());
                            bundle.putString("claim_name", result.getName());
                            LbryAnalytics.logEvent(LbryAnalytics.EVENT_CHANNEL_CREATE, bundle);
                            if (activity != null) {
                                activity.runOnUiThread(new Runnable() {

                                    @Override
                                    public void run() {
                                        if (listener != null) {
                                            listener.onChannelCreated(result);
                                        }
                                    }
                                });
                            }
                        }
                    } catch (ExecutionException ex) {
                        Throwable cause = ex.getCause();
                        if (cause instanceof ApiCallException) {
                            showError(cause.getMessage());
                        }
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    } finally {
                        if (activity != null) {
                            activity.runOnUiThread(new Runnable() {

                                @Override
                                public void run() {
                                    Helper.setViewVisibility(progressView, View.GONE);
                                    enableViews(inputChannelName, inputDeposit, createButton, linkCancel, true);
                                    dismiss();
                                }
                            });
                        }
                    }
                }
            });
            t.start();
        }
    });
    Helper.setViewText((TextView) balanceView, Helper.shortCurrencyFormat(Lbry.getAvailableBalance()));
    return v;
}
Also used : MainActivity(com.odysee.app.MainActivity) Callable(java.util.concurrent.Callable) Button(android.widget.Button) LogPublishTask(com.odysee.app.tasks.lbryinc.LogPublishTask) TextView(android.widget.TextView) ExecutionException(java.util.concurrent.ExecutionException) ChannelCreateUpdate(com.odysee.app.callable.ChannelCreateUpdate) ApiCallException(com.odysee.app.exceptions.ApiCallException) Bundle(android.os.Bundle) View(android.view.View) TextView(android.widget.TextView) BigDecimal(java.math.BigDecimal) ApiCallException(com.odysee.app.exceptions.ApiCallException) ExecutionException(java.util.concurrent.ExecutionException) ExecutorService(java.util.concurrent.ExecutorService) TextInputEditText(com.google.android.material.textfield.TextInputEditText) Future(java.util.concurrent.Future) AccountManager(android.accounts.AccountManager) Claim(com.odysee.app.model.Claim)

Example 52 with MainActivity

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

the class ChannelCreateDialogFragment method onStop.

@Override
public void onStop() {
    super.onStop();
    MainActivity activity = (MainActivity) getActivity();
    if (activity != null) {
        activity.destroyChannelCreator();
    }
}
Also used : MainActivity(com.odysee.app.MainActivity)

Example 53 with MainActivity

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

the class ChannelFormFragment method onResume.

public void onResume() {
    super.onResume();
    checkParams();
    checkRewardsDriver();
    updateFieldsFromCurrentClaim();
    Context context = getContext();
    if (context instanceof MainActivity) {
        MainActivity activity = (MainActivity) context;
        LbryAnalytics.setCurrentScreen(activity, "Channel Form", "ChannelForm");
        activity.addStoragePermissionListener(this);
        if (editMode) {
            activity.setActionBarTitle(R.string.edit_channel);
        }
        MainActivity.suspendGlobalPlayer(context);
    }
    String filterText = Helper.getValue(inputTagFilter.getText());
    updateSuggestedTags(filterText, SUGGESTED_LIMIT, true);
}
Also used : Context(android.content.Context) MainActivity(com.odysee.app.MainActivity)

Example 54 with MainActivity

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

the class ChannelFormFragment method onStop.

@Override
public void onStop() {
    Context context = getContext();
    if (context instanceof MainActivity) {
        MainActivity activity = (MainActivity) getContext();
        activity.removeStoragePermissionListener(this);
        activity.removeWalletBalanceListener(this);
        if (!MainActivity.startingFilePickerActivity) {
            activity.removeFilePickerListener(this);
        }
    }
    super.onStop();
}
Also used : Context(android.content.Context) MainActivity(com.odysee.app.MainActivity)

Example 55 with MainActivity

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

the class ChannelFormFragment method onStart.

@Override
public void onStart() {
    super.onStart();
    MainActivity activity = (MainActivity) getContext();
    if (activity != null) {
        activity.hideSearchBar();
        activity.addFilePickerListener(this);
        activity.addWalletBalanceListener(this);
        activity.setActionBarTitle(editMode ? R.string.edit_channel : R.string.create_a_channel);
    }
}
Also used : 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