Search in sources :

Example 96 with MainActivity

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

the class ChannelFormFragment method validateAndSaveClaim.

private void validateAndSaveClaim(Claim claim) {
    if (!editMode && Helper.isNullOrEmpty(claim.getName())) {
        showError(getString(R.string.please_enter_channel_name));
        return;
    }
    String channelName = claim.getName().startsWith("@") ? claim.getName().substring(1) : claim.getName();
    if (!LbryUri.isNameValid(channelName)) {
        showError(getString(R.string.channel_name_invalid_characters));
        return;
    }
    if (!editMode) {
        if (Helper.channelExists(channelName)) {
            showError(getString(R.string.channel_name_already_created));
            return;
        }
    }
    String depositString = Helper.getValue(inputDeposit.getText());
    double depositAmount = 0;
    try {
        depositAmount = Double.parseDouble(depositString);
    } catch (NumberFormatException ex) {
        // pass
        showError(getString(R.string.please_enter_valid_deposit));
        return;
    }
    if (depositAmount < Helper.MIN_DEPOSIT) {
        String error = getResources().getQuantityString(R.plurals.min_deposit_required, depositAmount == 1 ? 1 : 2, String.valueOf(Helper.MIN_DEPOSIT));
        showError(error);
        return;
    }
    if (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");
    ChannelCreateUpdateTask task = new ChannelCreateUpdateTask(claim, new BigDecimal(depositString), editMode, channelSaveProgress, authToken, new ClaimResultHandler() {

        @Override
        public void beforeStart() {
            preSave();
        }

        @Override
        public void onSuccess(Claim claimResult) {
            postSave();
            // Run the logPublish task
            if (!BuildConfig.DEBUG) {
                LogPublishTask logPublish = new LogPublishTask(claimResult);
                logPublish.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            }
            if (!editMode) {
                // channel created
                Bundle bundle = new Bundle();
                bundle.putString("claim_id", claimResult.getClaimId());
                bundle.putString("claim_name", claimResult.getName());
                LbryAnalytics.logEvent(LbryAnalytics.EVENT_CHANNEL_CREATE, bundle);
            }
            Context context = getContext();
            if (context instanceof MainActivity) {
                MainActivity activity = (MainActivity) context;
                activity.showMessage(R.string.channel_save_successful);
                activity.onBackPressed();
            }
        }

        @Override
        public void onError(Exception error) {
            showError(error != null ? error.getMessage() : getString(R.string.channel_save_failed));
            postSave();
        }
    });
    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : Context(android.content.Context) ClaimResultHandler(com.odysee.app.tasks.claim.ClaimResultHandler) ChannelCreateUpdateTask(com.odysee.app.tasks.claim.ChannelCreateUpdateTask) Bundle(android.os.Bundle) MainActivity(com.odysee.app.MainActivity) BigDecimal(java.math.BigDecimal) LogPublishTask(com.odysee.app.tasks.lbryinc.LogPublishTask) AccountManager(android.accounts.AccountManager) Claim(com.odysee.app.model.Claim)

Example 97 with MainActivity

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

the class ChannelFragment method onPause.

public void onPause() {
    Context context = getContext();
    if (context instanceof MainActivity) {
        MainActivity activity = (MainActivity) context;
        activity.updateMiniPlayerMargins(true);
        activity.removeFetchChannelsListener(this);
    }
    super.onPause();
}
Also used : Context(android.content.Context) MainActivity(com.odysee.app.MainActivity)

Example 98 with MainActivity

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

the class ChannelManagerFragment method onResume.

public void onResume() {
    super.onResume();
    Context context = getContext();
    if (context instanceof MainActivity) {
        MainActivity activity = (MainActivity) context;
        LbryAnalytics.setCurrentScreen(activity, "Channel Manager", "ChannelManager");
        MainActivity.suspendGlobalPlayer(context);
    }
    if (adapter != null && channelList != null) {
        channelList.setAdapter(adapter);
    }
    fetchChannels();
}
Also used : Context(android.content.Context) MainActivity(com.odysee.app.MainActivity)

Example 99 with MainActivity

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

the class ChannelManagerFragment method fetchChannels.

private void fetchChannels() {
    Helper.setViewVisibility(emptyView, View.GONE);
    AccountManager am = AccountManager.get(getContext());
    Account odyseeAccount = Helper.getOdyseeAccount(am.getAccounts());
    String authToken = am.peekAuthToken(odyseeAccount, "auth_token_type");
    MainActivity activity = (MainActivity) getActivity();
    final View progressView = getLoading();
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
        progressView.setVisibility(View.VISIBLE);
        Supplier<List<Claim>> s = new ClaimListSupplier(Collections.singletonList(Claim.TYPE_CHANNEL), authToken);
        CompletableFuture<List<Claim>> cf = CompletableFuture.supplyAsync(s);
        cf.whenComplete((result, e) -> {
            if (e != null && activity != null) {
                activity.runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        Throwable t = e.getCause();
                        if (t != null) {
                            activity.showError(t.getMessage());
                        }
                    }
                });
            }
            if (result != null && activity != null) {
                activity.runOnUiThread(new Runnable() {

                    public void run() {
                        Lbry.ownChannels = Helper.filterDeletedClaims(new ArrayList<>(result));
                        if (adapter == null) {
                            Context context = getContext();
                            if (context != null) {
                                adapter = new ClaimListAdapter(result, context);
                                adapter.setCanEnterSelectionMode(true);
                                adapter.setSelectionModeListener(ChannelManagerFragment.this);
                                adapter.setListener(new ClaimListAdapter.ClaimListItemListener() {

                                    @Override
                                    public void onClaimClicked(Claim claim, int position) {
                                        if (context instanceof MainActivity) {
                                            ((MainActivity) context).openChannelClaim(claim);
                                        }
                                    }
                                });
                                if (channelList != null) {
                                    channelList.setAdapter(adapter);
                                }
                            }
                        } else {
                            adapter.setItems(result);
                        }
                        checkNoChannels();
                    }
                });
            }
            if (activity != null)
                activity.runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        progressView.setVisibility(View.GONE);
                    }
                });
        });
    } else {
        ClaimListTask task = new ClaimListTask(Claim.TYPE_CHANNEL, getLoading(), Lbryio.AUTH_TOKEN, new ClaimListResultHandler() {

            @Override
            public void onSuccess(List<Claim> claims) {
                Lbry.ownChannels = Helper.filterDeletedClaims(new ArrayList<>(claims));
                if (adapter == null) {
                    Context context = getContext();
                    if (context != null) {
                        adapter = new ClaimListAdapter(claims, context);
                        adapter.setCanEnterSelectionMode(true);
                        adapter.setSelectionModeListener(ChannelManagerFragment.this);
                        adapter.setListener(new ClaimListAdapter.ClaimListItemListener() {

                            @Override
                            public void onClaimClicked(Claim claim, int position) {
                                if (context instanceof MainActivity) {
                                    ((MainActivity) context).openChannelClaim(claim);
                                }
                            }
                        });
                        if (channelList != null) {
                            channelList.setAdapter(adapter);
                        }
                    }
                } else {
                    adapter.setItems(claims);
                }
                checkNoChannels();
            }

            @Override
            public void onError(Exception error) {
                checkNoChannels();
            }
        });
        task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    }
}
Also used : Context(android.content.Context) Account(android.accounts.Account) ClaimListSupplier(com.odysee.app.supplier.ClaimListSupplier) ClaimListResultHandler(com.odysee.app.tasks.claim.ClaimListResultHandler) ClaimListTask(com.odysee.app.tasks.claim.ClaimListTask) MainActivity(com.odysee.app.MainActivity) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) ClaimListAdapter(com.odysee.app.adapter.ClaimListAdapter) AccountManager(android.accounts.AccountManager) ArrayList(java.util.ArrayList) List(java.util.List) Claim(com.odysee.app.model.Claim)

Example 100 with MainActivity

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

the class ChannelCommentsFragment method initCommentForm.

private void initCommentForm(View root) {
    MainActivity activity = (MainActivity) getActivity();
    if (activity != null) {
        activity.refreshChannelCreationRequired(root);
    }
    textCommentLimit.setText(String.format("%d / %d", Helper.getValue(inputComment.getText()).length(), Comment.MAX_LENGTH));
    buttonUserSignedInRequired.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            MainActivity activity = (MainActivity) getActivity();
            if (activity != null) {
                activity.simpleSignIn(0);
            }
        }
    });
    buttonClearReplyToComment.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            clearReplyToComment();
        }
    });
    buttonPostComment.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            validateAndCheckPostComment();
        }
    });
    buttonCreateChannel.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (!fetchingChannels) {
                showChannelCreator();
            }
        }
    });
    inputComment.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            int len = charSequence.length();
            textCommentLimit.setText(String.format("%d / %d", len, Comment.MAX_LENGTH));
        }

        @Override
        public void afterTextChanged(Editable editable) {
        }
    });
    commentChannelSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int position, long l) {
            Object item = adapterView.getItemAtPosition(position);
            if (item instanceof Claim) {
                Claim claim = (Claim) item;
                if (claim.isPlaceholder()) {
                    if (!fetchingChannels) {
                        showChannelCreator();
                        if (commentChannelSpinnerAdapter.getCount() > 1) {
                            commentChannelSpinner.setSelection(commentChannelSpinnerAdapter.getCount() - 1);
                        }
                    }
                } else {
                    updatePostAsChannel(claim);
                }
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {
        }
    });
}
Also used : MainActivity(com.odysee.app.MainActivity) NestedScrollView(androidx.core.widget.NestedScrollView) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) AdapterView(android.widget.AdapterView) Claim(com.odysee.app.model.Claim)

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