Search in sources :

Example 1 with Claim

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

the class PublishFormFragment method initUi.

private void initUi() {
    Context context = getContext();
    languageSpinner.setAdapter(new LanguageSpinnerAdapter(context, R.layout.spinner_item_generic));
    licenseSpinner.setAdapter(new LicenseSpinnerAdapter(context, R.layout.spinner_item_generic));
    licenseSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int position, long l) {
            License license = (License) adapterView.getAdapter().getItem(position);
            boolean otherLicense = Arrays.asList(Predefined.LICENSE_COPYRIGHTED.toLowerCase(), Predefined.LICENSE_OTHER.toLowerCase()).contains(license.getName().toLowerCase());
            Helper.setViewVisibility(layoutOtherLicenseDescription, otherLicense ? View.VISIBLE : View.GONE);
            if (!otherLicense) {
                inputOtherLicenseDescription.setText(null);
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {
        }
    });
    linkGenerateAddress.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (!editMode) {
                inputAddress.setText(Helper.generateUrl());
            }
        }
    });
    switchPrice.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
            Helper.setViewVisibility(textNoPrice, checked ? View.GONE : View.VISIBLE);
            Helper.setViewVisibility(layoutPrice, checked ? View.VISIBLE : View.GONE);
        }
    });
    inputAddress.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) {
            String value = Helper.getValue(charSequence);
            boolean invalid = !Helper.isNullOrEmpty(value) && !LbryUri.isNameValid(value);
            Helper.setViewVisibility(textInlineAddressInvalid, invalid ? View.VISIBLE : View.INVISIBLE);
        }

        @Override
        public void afterTextChanged(Editable editable) {
        }
    });
    inputDeposit.setOnFocusChangeListener(new View.OnFocusChangeListener() {

        @Override
        public void onFocusChange(View view, boolean hasFocus) {
            Helper.setViewVisibility(inlineDepositBalanceContainer, hasFocus ? View.VISIBLE : View.GONE);
        }
    });
    linkShowExtraFields.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (layoutExtraFields.getVisibility() != View.VISIBLE) {
                layoutExtraFields.setVisibility(View.VISIBLE);
                linkShowExtraFields.setText(R.string.hide_extra_fields);
                scrollView.post(new Runnable() {

                    @Override
                    public void run() {
                        scrollView.fullScroll(NestedScrollView.FOCUS_DOWN);
                    }
                });
            } else {
                layoutExtraFields.setVisibility(View.GONE);
                linkShowExtraFields.setText(R.string.show_extra_fields);
            }
        }
    });
    mediaContainer.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            checkStoragePermissionAndLaunchFilePicker();
        }
    });
    channelSpinner.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() && !claim.isPlaceholderAnonymous()) {
                    if (!fetchingChannels) {
                        showChannelCreator();
                    }
                }
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {
        }
    });
    inputTagFilter.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) {
            String value = Helper.getValue(charSequence);
            setFilter(value);
        }

        @Override
        public void afterTextChanged(Editable editable) {
        }
    });
    linkPublishCancel.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (transcodeInProgress) {
                // show alert confirming the user is sure, and then cancel
                FFmpeg.cancel();
                transcodeInProgress = false;
            }
            Context context = getContext();
            if (context instanceof MainActivity) {
                ((MainActivity) context).onBackPressed();
            }
        }
    });
    buttonPublish.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (uploading) {
                Snackbar.make(view, R.string.publish_thumbnail_in_progress, Snackbar.LENGTH_LONG).show();
                return;
            } else if (Helper.isNullOrEmpty(uploadedThumbnailUrl)) {
                showError(getString(R.string.publish_no_thumbnail));
                return;
            }
            if (transcodeInProgress) {
                Snackbar.make(view, R.string.optimization_in_progress, Snackbar.LENGTH_LONG).show();
                return;
            }
            // check minimum deposit
            String depositString = Helper.getValue(inputDeposit.getText());
            double depositAmount = 0;
            try {
                depositAmount = Double.valueOf(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;
            }
            String priceString = Helper.getValue(inputPrice.getText());
            double priceAmount = Helper.parseDouble(priceString, 0);
            if (switchPrice.isChecked() && priceAmount == 0) {
                showError(getString(R.string.price_amount_not_set));
                return;
            }
            Claim claim = buildPublishClaim();
            if (validatePublishClaim(claim)) {
                publishClaim(claim);
            }
        }
    });
    channelSpinnerAdapter = new InlineChannelSpinnerAdapter(getContext(), R.layout.spinner_item_channel, new ArrayList<>());
    channelSpinnerAdapter.addPlaceholder(false);
}
Also used : License(com.odysee.app.model.License) MainActivity(com.odysee.app.MainActivity) LicenseSpinnerAdapter(com.odysee.app.adapter.LicenseSpinnerAdapter) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) Context(android.content.Context) InlineChannelSpinnerAdapter(com.odysee.app.adapter.InlineChannelSpinnerAdapter) NestedScrollView(androidx.core.widget.NestedScrollView) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(androidx.recyclerview.widget.RecyclerView) CardView(androidx.cardview.widget.CardView) TextView(android.widget.TextView) LanguageSpinnerAdapter(com.odysee.app.adapter.LanguageSpinnerAdapter) AdapterView(android.widget.AdapterView) JSONObject(org.json.JSONObject) CompoundButton(android.widget.CompoundButton) Claim(com.odysee.app.model.Claim)

Example 2 with Claim

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

the class PublishFormFragment method updateFieldsFromCurrentClaim.

private void updateFieldsFromCurrentClaim() {
    if (currentClaim != null && !editFieldsLoaded) {
        Context context = getContext();
        try {
            Claim.StreamMetadata metadata = (Claim.StreamMetadata) currentClaim.getValue();
            if (context != null) {
                uploadedThumbnailUrl = currentClaim.getThumbnailUrl(imageThumbnail.getLayoutParams().width, imageThumbnail.getLayoutParams().height, 85);
            }
            if (context != null && !Helper.isNullOrEmpty(uploadedThumbnailUrl)) {
                Glide.with(context.getApplicationContext()).load(uploadedThumbnailUrl).centerCrop().into(imageThumbnail);
            }
            inputTitle.setText(currentClaim.getTitle());
            inputDescription.setText(currentClaim.getDescription());
            if (addedTagsAdapter != null && currentClaim.getTagObjects() != null) {
                addedTagsAdapter.addTags(currentClaim.getTagObjects());
                updateSuggestedTags(currentFilter, SUGGESTED_LIMIT, true);
            }
            if (metadata.getFee() != null) {
                Fee fee = metadata.getFee();
                switchPrice.setChecked(true);
                inputPrice.setText(fee.getAmount());
                priceCurrencySpinner.setSelection("lbc".equalsIgnoreCase(fee.getCurrency()) ? 0 : 1);
            }
            inputAddress.setText(currentClaim.getName());
            inputDeposit.setText(currentClaim.getAmount());
            if (metadata.getLanguages() != null && metadata.getLanguages().size() > 0) {
                // get the first language
                String langCode = metadata.getLanguages().get(0);
                int langCodePosition = ((LanguageSpinnerAdapter) languageSpinner.getAdapter()).getItemPosition(langCode);
                if (langCodePosition > -1) {
                    languageSpinner.setSelection(langCodePosition);
                }
            }
            if (!Helper.isNullOrEmpty(metadata.getLicense())) {
                LicenseSpinnerAdapter adapter = (LicenseSpinnerAdapter) licenseSpinner.getAdapter();
                int licPosition = adapter.getItemPosition(metadata.getLicense());
                if (licPosition == -1) {
                    licPosition = adapter.getItemPosition(Predefined.LICENSE_OTHER);
                }
                if (licPosition > -1) {
                    licenseSpinner.setSelection(licPosition);
                }
                License selectedLicense = (License) licenseSpinner.getSelectedItem();
                boolean otherLicense = Arrays.asList(Predefined.LICENSE_COPYRIGHTED.toLowerCase(), Predefined.LICENSE_OTHER.toLowerCase()).contains(selectedLicense.getName().toLowerCase());
                inputOtherLicenseDescription.setText(otherLicense ? metadata.getLicense() : null);
            }
            inputAddress.setEnabled(false);
            editMode = true;
            editFieldsLoaded = true;
        } catch (ClassCastException ex) {
            // invalid claim value type
            cancelOnFatalCondition(getString(R.string.publish_invalid_claim_type));
        }
    }
}
Also used : Context(android.content.Context) LicenseSpinnerAdapter(com.odysee.app.adapter.LicenseSpinnerAdapter) Fee(com.odysee.app.model.Fee) License(com.odysee.app.model.License) Claim(com.odysee.app.model.Claim) LanguageSpinnerAdapter(com.odysee.app.adapter.LanguageSpinnerAdapter)

Example 3 with Claim

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

the class PublishFormFragment method publishClaim.

private void publishClaim(Claim claim) {
    String finalFilePath = transcodedFilePath;
    if (Helper.isNullOrEmpty(finalFilePath)) {
        finalFilePath = currentGalleryItem != null ? currentGalleryItem.getFilePath() : currentFilePath;
    }
    saveInProgress = true;
    PublishClaimTask task = new PublishClaimTask(claim, finalFilePath, progressPublish, new ClaimResultHandler() {

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

        @Override
        public void onSuccess(Claim claimResult) {
            postSave();
            // Run the logPublish task
            if (!BuildConfig.DEBUG) {
                claimResult.setSigningChannel(claim.getSigningChannel());
                LogPublishTask logPublish = new LogPublishTask(claimResult);
                logPublish.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            }
            // publish done
            Bundle bundle = new Bundle();
            bundle.putString("claim_id", claimResult.getClaimId());
            bundle.putString("claim_name", claimResult.getName());
            LbryAnalytics.logEvent(editMode ? LbryAnalytics.EVENT_PUBLISH_UPDATE : LbryAnalytics.EVENT_PUBLISH, bundle);
            Context context = getContext();
            if (context instanceof MainActivity) {
                MainActivity activity = (MainActivity) context;
                activity.showMessage(R.string.publish_successful);
                activity.sendBroadcast(new Intent(MainActivity.ACTION_PUBLISH_SUCCESSFUL));
            }
        }

        @Override
        public void onError(Exception error) {
            showError(error.getMessage());
            postSave();
        }
    });
    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : PublishClaimTask(com.odysee.app.tasks.claim.PublishClaimTask) Context(android.content.Context) ClaimResultHandler(com.odysee.app.tasks.claim.ClaimResultHandler) Bundle(android.os.Bundle) LogPublishTask(com.odysee.app.tasks.lbryinc.LogPublishTask) Intent(android.content.Intent) MainActivity(com.odysee.app.MainActivity) Claim(com.odysee.app.model.Claim) JSONException(org.json.JSONException)

Example 4 with Claim

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

the class PublishesFragment method handleDeleteSelectedClaims.

private void handleDeleteSelectedClaims(List<Claim> selectedClaims) {
    List<String> claimIds = new ArrayList<>();
    for (Claim claim : selectedClaims) {
        claimIds.add(claim.getClaimId());
    }
    if (actionMode != null) {
        actionMode.finish();
    }
    Helper.setViewVisibility(contentList, View.INVISIBLE);
    Helper.setViewVisibility(fabNewPublish, View.INVISIBLE);
    AbandonStreamTask task = new AbandonStreamTask(claimIds, bigLoading, new AbandonHandler() {

        @Override
        public void onComplete(List<String> successfulClaimIds, List<String> failedClaimIds, List<Exception> errors) {
            View root = getView();
            if (root != null) {
                if (failedClaimIds.size() > 0) {
                    Snackbar.make(root, R.string.one_or_more_publishes_failed_abandon, Snackbar.LENGTH_LONG).setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show();
                } else if (successfulClaimIds.size() == claimIds.size()) {
                    try {
                        String message = getResources().getQuantityString(R.plurals.publishes_deleted, successfulClaimIds.size());
                        Snackbar.make(root, message, Snackbar.LENGTH_LONG).show();
                    } catch (IllegalStateException ex) {
                    // pass
                    }
                }
            }
            Lbry.abandonedClaimIds.addAll(successfulClaimIds);
            if (adapter != null) {
                adapter.setItems(Helper.filterDeletedClaims(adapter.getItems()));
            }
            Helper.setViewVisibility(contentList, View.VISIBLE);
            Helper.setViewVisibility(fabNewPublish, View.VISIBLE);
            checkNoPublishes();
        }
    });
    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : AbandonStreamTask(com.odysee.app.tasks.claim.AbandonStreamTask) ArrayList(java.util.ArrayList) AbandonHandler(com.odysee.app.tasks.claim.AbandonHandler) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) Claim(com.odysee.app.model.Claim)

Example 5 with Claim

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

the class PublishesFragment method onActionItemClicked.

@Override
public boolean onActionItemClicked(androidx.appcompat.view.ActionMode actionMode, MenuItem menuItem) {
    if (R.id.action_edit == menuItem.getItemId()) {
        if (adapter != null && adapter.getSelectedCount() > 0) {
            Claim claim = adapter.getSelectedItems().get(0);
            // start channel editor with the claim
            Context context = getContext();
            if (context instanceof MainActivity) {
                ((MainActivity) context).openPublishForm(claim);
            }
            actionMode.finish();
            return true;
        }
    }
    if (R.id.action_delete == menuItem.getItemId()) {
        if (adapter != null && adapter.getSelectedCount() > 0) {
            final List<Claim> selectedClaims = new ArrayList<>(adapter.getSelectedItems());
            String message = getResources().getQuantityString(R.plurals.confirm_delete_publishes, selectedClaims.size());
            AlertDialog.Builder builder = new AlertDialog.Builder(getContext()).setTitle(R.string.delete_selection).setMessage(message).setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    handleDeleteSelectedClaims(selectedClaims);
                }
            }).setNegativeButton(R.string.no, null);
            builder.show();
            return true;
        }
    }
    return false;
}
Also used : Context(android.content.Context) AlertDialog(androidx.appcompat.app.AlertDialog) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) MainActivity(com.odysee.app.MainActivity) Claim(com.odysee.app.model.Claim)

Aggregations

Claim (com.odysee.app.model.Claim)133 Context (android.content.Context)51 MainActivity (com.odysee.app.MainActivity)44 JSONException (org.json.JSONException)42 View (android.view.View)41 TextView (android.widget.TextView)37 RecyclerView (androidx.recyclerview.widget.RecyclerView)36 ApiCallException (com.odysee.app.exceptions.ApiCallException)36 ArrayList (java.util.ArrayList)32 ImageView (android.widget.ImageView)31 AdapterView (android.widget.AdapterView)29 NestedScrollView (androidx.core.widget.NestedScrollView)28 ClaimListResultHandler (com.odysee.app.tasks.claim.ClaimListResultHandler)26 JSONObject (org.json.JSONObject)26 ExecutionException (java.util.concurrent.ExecutionException)25 TrackSelectionOverride (com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride)24 LbryUriException (com.odysee.app.exceptions.LbryUriException)24 SolidIconView (com.odysee.app.ui.controls.SolidIconView)24 WebView (android.webkit.WebView)23 PhotoView (com.github.chrisbanes.photoview.PhotoView)23