Search in sources :

Example 6 with GenericTaskHandler

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

the class InvitesFragment method initUi.

private void initUi() {
    layoutAccountDriver.setVisibility(Lbryio.isSignedIn() ? View.GONE : View.VISIBLE);
    Helper.applyHtmlForTextView(textLearnMoreLink);
    rewardDriverCard.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Context context = getContext();
            if (context instanceof MainActivity) {
                ((MainActivity) context).openRewards();
            }
        }
    });
    inputEmail.setOnFocusChangeListener(new View.OnFocusChangeListener() {

        @Override
        public void onFocusChange(View view, boolean hasFocus) {
            layoutInputEmail.setHint(hasFocus ? getString(R.string.email) : Helper.getValue(inputEmail.getText()).length() > 0 ? getString(R.string.email) : getString(R.string.invite_email_placeholder));
        }
    });
    inputEmail.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) {
            Helper.setViewEnabled(buttonInviteByEmail, charSequence.length() > 0);
        }

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

        @Override
        public void onClick(View view) {
            String email = Helper.getValue(inputEmail.getText());
            if (!email.contains("@")) {
                showError(getString(R.string.provide_valid_email));
                return;
            }
            InviteByEmailTask task = new InviteByEmailTask(email, progressLoadingInviteByEmail, new GenericTaskHandler() {

                @Override
                public void beforeStart() {
                    Helper.setViewEnabled(buttonInviteByEmail, false);
                }

                @Override
                public void onSuccess() {
                    Snackbar.make(getView(), getString(R.string.invite_sent_to, email), Snackbar.LENGTH_LONG).show();
                    Helper.setViewText(inputEmail, null);
                    Helper.setViewEnabled(buttonInviteByEmail, true);
                    fetchInviteStatus();
                }

                @Override
                public void onError(Exception error) {
                    showError(error.getMessage());
                    Helper.setViewEnabled(buttonInviteByEmail, true);
                }
            });
            task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    });
    buttonGetStarted.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Context context = getContext();
            if (context instanceof MainActivity) {
                ((MainActivity) context).simpleSignIn(R.id.action_home_menu);
            }
        }
    });
    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()) {
                    if (!fetchingChannels) {
                        showChannelCreator();
                    }
                } else {
                    // build invite link
                    updateInviteLink(claim);
                }
            }
        }

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

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

        @Override
        public void onClick(View view) {
            copyInviteLink();
        }
    });
    channelSpinnerAdapter = new InlineChannelSpinnerAdapter(getContext(), R.layout.spinner_item_channel, new ArrayList<>());
    channelSpinnerAdapter.addPlaceholder(false);
}
Also used : Context(android.content.Context) GenericTaskHandler(com.odysee.app.tasks.GenericTaskHandler) ArrayList(java.util.ArrayList) MainActivity(com.odysee.app.MainActivity) InlineChannelSpinnerAdapter(com.odysee.app.adapter.InlineChannelSpinnerAdapter) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(androidx.recyclerview.widget.RecyclerView) CardView(androidx.cardview.widget.CardView) TextView(android.widget.TextView) InviteByEmailTask(com.odysee.app.tasks.lbryinc.InviteByEmailTask) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) AdapterView(android.widget.AdapterView) Claim(com.odysee.app.model.Claim)

Aggregations

GenericTaskHandler (com.odysee.app.tasks.GenericTaskHandler)6 View (android.view.View)4 TextView (android.widget.TextView)3 Context (android.content.Context)2 WebView (android.webkit.WebView)2 AdapterView (android.widget.AdapterView)2 RecyclerView (androidx.recyclerview.widget.RecyclerView)2 Claim (com.odysee.app.model.Claim)2 PhoneNewVerifyTask (com.odysee.app.tasks.verification.PhoneNewVerifyTask)2 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 ImageView (android.widget.ImageView)1 CardView (androidx.cardview.widget.CardView)1 NestedScrollView (androidx.core.widget.NestedScrollView)1 PhotoView (com.github.chrisbanes.photoview.PhotoView)1 TrackSelectionOverride (com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride)1 PlayerView (com.google.android.exoplayer2.ui.PlayerView)1 MaterialButton (com.google.android.material.button.MaterialButton)1 MainActivity (com.odysee.app.MainActivity)1 InlineChannelSpinnerAdapter (com.odysee.app.adapter.InlineChannelSpinnerAdapter)1