From 9d6b3ddf8168b6b2da2124d431bedd693e9ac739 Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Thu, 25 Jun 2020 20:15:58 +0100 Subject: [PATCH] combined tip / support dialog and signed supports (#944) * combined tip / support dialog and signed supports * update button label when amount is updated --- .../adapter/InlineChannelSpinnerAdapter.java | 6 + .../dialog/CreateSupportDialogFragment.java | 346 ++++++++++++++++++ .../browser/dialog/SendTipDialogFragment.java | 200 ---------- .../tasks/wallet/SupportCreateTask.java | 7 +- .../browser/ui/channel/ChannelFragment.java | 13 +- .../ui/findcontent/FileViewFragment.java | 12 +- ...send_tip.xml => dialog_create_support.xml} | 78 +++- .../main/res/layout/fragment_file_view.xml | 2 +- app/src/main/res/values/strings.xml | 12 +- 9 files changed, 441 insertions(+), 235 deletions(-) create mode 100644 app/src/main/java/io/lbry/browser/dialog/CreateSupportDialogFragment.java delete mode 100644 app/src/main/java/io/lbry/browser/dialog/SendTipDialogFragment.java rename app/src/main/res/layout/{dialog_send_tip.xml => dialog_create_support.xml} (63%) diff --git a/app/src/main/java/io/lbry/browser/adapter/InlineChannelSpinnerAdapter.java b/app/src/main/java/io/lbry/browser/adapter/InlineChannelSpinnerAdapter.java index 457749ad..5a1069fa 100644 --- a/app/src/main/java/io/lbry/browser/adapter/InlineChannelSpinnerAdapter.java +++ b/app/src/main/java/io/lbry/browser/adapter/InlineChannelSpinnerAdapter.java @@ -41,6 +41,12 @@ public class InlineChannelSpinnerAdapter extends ArrayAdapter { channels.add(1, anonymous); } } + public void addAnonymousPlaceholder() { + Claim anonymous = new Claim(); + anonymous.setPlaceholderAnonymous(true); + insert(anonymous, 0); + channels.add(0, anonymous); + } public void addAll(Collection collection) { for (Claim claim : collection) { diff --git a/app/src/main/java/io/lbry/browser/dialog/CreateSupportDialogFragment.java b/app/src/main/java/io/lbry/browser/dialog/CreateSupportDialogFragment.java new file mode 100644 index 00000000..51e63ec2 --- /dev/null +++ b/app/src/main/java/io/lbry/browser/dialog/CreateSupportDialogFragment.java @@ -0,0 +1,346 @@ +package io.lbry.browser.dialog; + +import android.app.Dialog; +import android.content.Context; +import android.graphics.Color; +import android.os.AsyncTask; +import android.os.Bundle; +import android.text.Editable; +import android.text.TextWatcher; +import android.text.method.LinkMovementMethod; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.CompoundButton; +import android.widget.ProgressBar; +import android.widget.Switch; +import android.widget.TextView; + +import androidx.appcompat.widget.AppCompatSpinner; +import androidx.core.text.HtmlCompat; + +import com.google.android.material.bottomsheet.BottomSheetDialogFragment; +import com.google.android.material.button.MaterialButton; +import com.google.android.material.snackbar.Snackbar; +import com.google.android.material.switchmaterial.SwitchMaterial; +import com.google.android.material.textfield.TextInputEditText; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; + +import io.lbry.browser.MainActivity; +import io.lbry.browser.R; +import io.lbry.browser.adapter.InlineChannelSpinnerAdapter; +import io.lbry.browser.listener.WalletBalanceListener; +import io.lbry.browser.model.Claim; +import io.lbry.browser.model.WalletBalance; +import io.lbry.browser.tasks.GenericTaskHandler; +import io.lbry.browser.tasks.claim.ClaimListResultHandler; +import io.lbry.browser.tasks.claim.ClaimListTask; +import io.lbry.browser.tasks.wallet.SupportCreateTask; +import io.lbry.browser.utils.Helper; +import io.lbry.browser.utils.Lbry; +import lombok.Setter; + +public class CreateSupportDialogFragment extends BottomSheetDialogFragment implements WalletBalanceListener { + public static final String TAG = "CreateSupportDialog"; + + private MaterialButton sendButton; + private View cancelLink; + private TextInputEditText inputAmount; + private View inlineBalanceContainer; + private TextView inlineBalanceValue; + private ProgressBar sendProgress; + + private InlineChannelSpinnerAdapter channelSpinnerAdapter; + private AppCompatSpinner channelSpinner; + private SwitchMaterial switchTip; + + private boolean fetchingChannels; + private ProgressBar progressLoadingChannels; + + + @Setter + private CreateSupportListener listener; + @Setter + private Claim claim; + + public static CreateSupportDialogFragment newInstance() { + return new CreateSupportDialogFragment(); + } + + private void disableControls() { + Dialog dialog = getDialog(); + if (dialog != null) { + dialog.setCanceledOnTouchOutside(false); + } + channelSpinner.setEnabled(false); + switchTip.setEnabled(false); + sendButton.setEnabled(false); + cancelLink.setEnabled(false); + } + private void enableControls() { + Dialog dialog = getDialog(); + if (dialog != null) { + dialog.setCanceledOnTouchOutside(true); + } + channelSpinner.setEnabled(true); + switchTip.setEnabled(true); + sendButton.setEnabled(true); + cancelLink.setEnabled(true); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.dialog_create_support, container, false); + + inputAmount = view.findViewById(R.id.create_support_input_amount); + inlineBalanceContainer = view.findViewById(R.id.create_support_inline_balance_container); + inlineBalanceValue = view.findViewById(R.id.create_support_inline_balance_value); + sendProgress = view.findViewById(R.id.create_support_progress); + cancelLink = view.findViewById(R.id.create_support_cancel_link); + sendButton = view.findViewById(R.id.create_support_send); + + channelSpinner = view.findViewById(R.id.create_support_channel_spinner); + switchTip = view.findViewById(R.id.create_support_make_tip_switch); + progressLoadingChannels = view.findViewById(R.id.create_support_channel_progress); + + inputAmount.setOnFocusChangeListener(new View.OnFocusChangeListener() { + @Override + public void onFocusChange(View view, boolean hasFocus) { + inputAmount.setHint(hasFocus ? getString(R.string.zero) : ""); + inlineBalanceContainer.setVisibility(hasFocus ? View.VISIBLE : View.INVISIBLE); + } + }); + inputAmount.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) { + updateSendButtonText(); + } + + @Override + public void afterTextChanged(Editable editable) { + + } + }); + updateInfoText(); + updateSendButtonText(); + + String channel = null; + if (Claim.TYPE_CHANNEL.equalsIgnoreCase(claim.getValueType())) { + channel = claim.getTitleOrName(); + } else if (claim.getSigningChannel() != null) { + channel = claim.getPublisherTitle(); + } + TextView titleView = view.findViewById(R.id.create_support_title); + String tipTitleText = Helper.isNullOrEmpty(channel) ? getString(R.string.send_a_tip) : getString(R.string.send_a_tip_to, channel); + titleView.setText(tipTitleText); + + switchTip.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + if (checked) { + // show tip info + titleView.setText(tipTitleText); + updateSendButtonText(); + } else { + // show support info + titleView.setText(R.string.support_this_content); + sendButton.setText(R.string.send_revocable_support); + } + updateInfoText(); + } + }); + + sendButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + String amountString = Helper.getValue(inputAmount.getText()); + if (Helper.isNullOrEmpty(amountString)) { + showError(getString(R.string.invalid_amount)); + return; + } + + BigDecimal amount = new BigDecimal(amountString); + if (amount.doubleValue() > Lbry.walletBalance.getAvailable().doubleValue()) { + showError(getString(R.string.insufficient_balance)); + return; + } + if (amount.doubleValue() < Helper.MIN_SPEND) { + showError(getString(R.string.min_spend_required)); + return; + } + + Claim selectedChannel = (Claim) channelSpinner.getSelectedItem(); + String channelId = !fetchingChannels && selectedChannel != null ? selectedChannel.getClaimId() : null; + boolean isTip = switchTip.isChecked(); + SupportCreateTask task = new SupportCreateTask( + claim.getClaimId(), channelId, amount, isTip, sendProgress, new GenericTaskHandler() { + @Override + public void beforeStart() { + disableControls(); + } + + @Override + public void onSuccess() { + enableControls(); + if (listener != null) { + listener.onSupportCreated(amount, isTip); + } + + dismiss(); + } + + @Override + public void onError(Exception error) { + showError(error.getMessage()); + enableControls(); + } + }); + task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } + }); + + cancelLink.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + dismiss(); + } + }); + + onWalletBalanceUpdated(Lbry.walletBalance); + updateInfoText(); + + return view; + } + + private void updateSendButtonText() { + boolean isTip = switchTip.isChecked(); + if (!isTip) { + sendButton.setText(R.string.send_revocable_support); + } else { + String amountString = Helper.getValue(inputAmount.getText()); + double parsedAmount = Helper.parseDouble(amountString, 0); + sendButton.setText(parsedAmount == 0 ? getString(R.string.send_a_tip) : getString(R.string.send_lbc_tip, amountString)); + } + } + + private void updateInfoText() { + View view = getView(); + if (view != null && switchTip != null) { + TextView infoText = view.findViewById(R.id.create_support_info); + boolean isTip = switchTip.isChecked(); + + infoText.setMovementMethod(LinkMovementMethod.getInstance()); + if (!isTip) { + infoText.setText(HtmlCompat.fromHtml(getString(R.string.support_info), HtmlCompat.FROM_HTML_MODE_LEGACY)); + } else if (claim != null) { + infoText.setText(HtmlCompat.fromHtml( + Claim.TYPE_CHANNEL.equalsIgnoreCase(claim.getValueType()) ? + getString(R.string.send_tip_info_channel, claim.getTitleOrName()) : + getString(R.string.send_tip_info_content, claim.getTitleOrName()), + HtmlCompat.FROM_HTML_MODE_LEGACY)); + } + } + } + + private void fetchChannels() { + if (Lbry.ownChannels != null && Lbry.ownChannels.size() > 0) { + updateChannelList(Lbry.ownChannels); + return; + } + + fetchingChannels = true; + disableChannelSpinner(); + ClaimListTask task = new ClaimListTask(Claim.TYPE_CHANNEL, progressLoadingChannels, new ClaimListResultHandler() { + @Override + public void onSuccess(List claims) { + Lbry.ownChannels = new ArrayList<>(claims); + updateChannelList(Lbry.ownChannels); + enableChannelSpinner(); + fetchingChannels = false; + } + + @Override + public void onError(Exception error) { + enableChannelSpinner(); + fetchingChannels = false; + } + }); + task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } + private void disableChannelSpinner() { + Helper.setViewEnabled(channelSpinner, false); + } + private void enableChannelSpinner() { + Helper.setViewEnabled(channelSpinner, true); + } + + private void updateChannelList(List channels) { + if (channelSpinnerAdapter == null) { + Context context = getContext(); + if (context != null) { + channelSpinnerAdapter = new InlineChannelSpinnerAdapter(context, R.layout.spinner_item_channel, new ArrayList<>(channels)); + channelSpinnerAdapter.addAnonymousPlaceholder(); + channelSpinnerAdapter.notifyDataSetChanged(); + } + } else { + channelSpinnerAdapter.clear(); + channelSpinnerAdapter.addAll(channels); + channelSpinnerAdapter.addAnonymousPlaceholder(); + channelSpinnerAdapter.notifyDataSetChanged(); + } + + if (channelSpinner != null) { + channelSpinner.setAdapter(channelSpinnerAdapter); + } + + if (channelSpinnerAdapter != null && channelSpinner != null) { + if (channelSpinnerAdapter.getCount() > 1) { + channelSpinner.setSelection(1); + } + } + } + + public void onResume() { + super.onResume(); + Context context = getContext(); + if (context instanceof MainActivity) { + ((MainActivity) context).addWalletBalanceListener(this); + } + updateInfoText(); + fetchChannels(); + } + + public void onPause() { + Context context = getContext(); + if (context instanceof MainActivity) { + ((MainActivity) context).removeWalletBalanceListener(this); + } + super.onPause(); + } + + @Override + public void onWalletBalanceUpdated(WalletBalance walletBalance) { + if (walletBalance != null && inlineBalanceValue != null) { + inlineBalanceValue.setText(Helper.shortCurrencyFormat(walletBalance.getAvailable().doubleValue())); + } + } + + private void showError(String message) { + Snackbar.make(getView(), message, Snackbar.LENGTH_LONG). + setBackgroundTint(Color.RED). + setTextColor(Color.WHITE). + show(); + } + + public interface CreateSupportListener { + void onSupportCreated(BigDecimal amount, boolean isTip); + } +} diff --git a/app/src/main/java/io/lbry/browser/dialog/SendTipDialogFragment.java b/app/src/main/java/io/lbry/browser/dialog/SendTipDialogFragment.java deleted file mode 100644 index eed10265..00000000 --- a/app/src/main/java/io/lbry/browser/dialog/SendTipDialogFragment.java +++ /dev/null @@ -1,200 +0,0 @@ -package io.lbry.browser.dialog; - -import android.app.Dialog; -import android.content.Context; -import android.graphics.Color; -import android.os.AsyncTask; -import android.os.Bundle; -import android.text.method.LinkMovementMethod; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ProgressBar; -import android.widget.TextView; - -import androidx.core.text.HtmlCompat; - -import com.google.android.material.bottomsheet.BottomSheetDialogFragment; -import com.google.android.material.button.MaterialButton; -import com.google.android.material.snackbar.Snackbar; -import com.google.android.material.textfield.TextInputEditText; - -import java.math.BigDecimal; - -import io.lbry.browser.MainActivity; -import io.lbry.browser.R; -import io.lbry.browser.listener.WalletBalanceListener; -import io.lbry.browser.model.Claim; -import io.lbry.browser.model.WalletBalance; -import io.lbry.browser.tasks.GenericTaskHandler; -import io.lbry.browser.tasks.wallet.SupportCreateTask; -import io.lbry.browser.utils.Helper; -import io.lbry.browser.utils.Lbry; -import lombok.Setter; - -public class SendTipDialogFragment extends BottomSheetDialogFragment implements WalletBalanceListener { - public static final String TAG = "SendTipDialog"; - - private MaterialButton sendButton; - private View cancelLink; - private TextInputEditText inputAmount; - private View inlineBalanceContainer; - private TextView inlineBalanceValue; - private ProgressBar sendProgress; - - @Setter - private SendTipListener listener; - @Setter - private Claim claim; - - public static SendTipDialogFragment newInstance() { - return new SendTipDialogFragment(); - } - - private void disableControls() { - Dialog dialog = getDialog(); - if (dialog != null) { - dialog.setCanceledOnTouchOutside(false); - } - sendButton.setEnabled(false); - cancelLink.setEnabled(false); - } - private void enableControls() { - Dialog dialog = getDialog(); - if (dialog != null) { - dialog.setCanceledOnTouchOutside(true); - } - sendButton.setEnabled(true); - cancelLink.setEnabled(true); - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.dialog_send_tip, container, false); - - inputAmount = view.findViewById(R.id.tip_input_amount); - inlineBalanceContainer = view.findViewById(R.id.tip_inline_balance_container); - inlineBalanceValue = view.findViewById(R.id.tip_inline_balance_value); - sendProgress = view.findViewById(R.id.tip_send_progress); - cancelLink = view.findViewById(R.id.tip_cancel_link); - sendButton = view.findViewById(R.id.tip_send); - - inputAmount.setOnFocusChangeListener(new View.OnFocusChangeListener() { - @Override - public void onFocusChange(View view, boolean hasFocus) { - inputAmount.setHint(hasFocus ? getString(R.string.zero) : ""); - inlineBalanceContainer.setVisibility(hasFocus ? View.VISIBLE : View.INVISIBLE); - } - }); - - TextView infoText = view.findViewById(R.id.tip_info); - infoText.setMovementMethod(LinkMovementMethod.getInstance()); - if (claim != null) { - infoText.setText(HtmlCompat.fromHtml( - Claim.TYPE_CHANNEL.equalsIgnoreCase(claim.getValueType()) ? - getString(R.string.send_tip_info_channel, claim.getTitleOrName()) : - getString(R.string.send_tip_info_content, claim.getTitleOrName()), - HtmlCompat.FROM_HTML_MODE_LEGACY)); - } - - sendButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - String amountString = Helper.getValue(inputAmount.getText()); - if (Helper.isNullOrEmpty(amountString)) { - showError(getString(R.string.invalid_amount)); - return; - } - - BigDecimal amount = new BigDecimal(amountString); - if (amount.doubleValue() > Lbry.walletBalance.getAvailable().doubleValue()) { - showError(getString(R.string.insufficient_balance)); - return; - } - if (amount.doubleValue() < Helper.MIN_SPEND) { - showError(getString(R.string.min_spend_required)); - return; - } - - SupportCreateTask task = new SupportCreateTask(claim.getClaimId(), amount, true, sendProgress, new GenericTaskHandler() { - @Override - public void beforeStart() { - disableControls(); - } - - @Override - public void onSuccess() { - enableControls(); - if (listener != null) { - listener.onTipSent(amount); - } - - dismiss(); - } - - @Override - public void onError(Exception error) { - showError(error.getMessage()); - enableControls(); - } - }); - task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - }); - - cancelLink.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - dismiss(); - } - }); - - String channel = null; - if (Claim.TYPE_CHANNEL.equalsIgnoreCase(claim.getValueType())) { - channel = claim.getTitleOrName(); - } else if (claim.getSigningChannel() != null) { - channel = claim.getPublisherTitle(); - } - ((TextView) view.findViewById(R.id.tip_send_title)).setText( - Helper.isNullOrEmpty(channel) ? getString(R.string.send_a_tip) : getString(R.string.send_a_tip_to, channel) - ); - - onWalletBalanceUpdated(Lbry.walletBalance); - - return view; - } - - public void onResume() { - super.onResume(); - Context context = getContext(); - if (context instanceof MainActivity) { - ((MainActivity) context).addWalletBalanceListener(this); - } - } - - public void onPause() { - Context context = getContext(); - if (context instanceof MainActivity) { - ((MainActivity) context).removeWalletBalanceListener(this); - } - super.onPause(); - } - - @Override - public void onWalletBalanceUpdated(WalletBalance walletBalance) { - if (walletBalance != null && inlineBalanceValue != null) { - inlineBalanceValue.setText(Helper.shortCurrencyFormat(walletBalance.getAvailable().doubleValue())); - } - } - - private void showError(String message) { - Snackbar.make(getView(), message, Snackbar.LENGTH_LONG). - setBackgroundTint(Color.RED). - setTextColor(Color.WHITE). - show(); - } - - public interface SendTipListener { - void onTipSent(BigDecimal amount); - } -} diff --git a/app/src/main/java/io/lbry/browser/tasks/wallet/SupportCreateTask.java b/app/src/main/java/io/lbry/browser/tasks/wallet/SupportCreateTask.java index d11fb937..5426f0cb 100644 --- a/app/src/main/java/io/lbry/browser/tasks/wallet/SupportCreateTask.java +++ b/app/src/main/java/io/lbry/browser/tasks/wallet/SupportCreateTask.java @@ -17,14 +17,16 @@ import io.lbry.browser.utils.Lbry; public class SupportCreateTask extends AsyncTask { private String claimId; + private String channelId; private BigDecimal amount; private boolean tip; private View progressView; private GenericTaskHandler handler; private Exception error; - public SupportCreateTask(String claimId, BigDecimal amount, boolean tip, View progressView, GenericTaskHandler handler) { + public SupportCreateTask(String claimId, String channelId, BigDecimal amount, boolean tip, View progressView, GenericTaskHandler handler) { this.claimId = claimId; + this.channelId = channelId; this.amount = amount; this.tip = tip; this.progressView = progressView; @@ -44,6 +46,9 @@ public class SupportCreateTask extends AsyncTask { options.put("claim_id", claimId); options.put("amount", new DecimalFormat(Helper.SDK_AMOUNT_FORMAT, new DecimalFormatSymbols(Locale.US)).format(amount.doubleValue())); options.put("tip", tip); + if (!Helper.isNullOrEmpty(channelId)) { + options.put("channel_id", channelId); + } Lbry.genericApiCall(Lbry.METHOD_SUPPORT_CREATE, options); } catch (ApiCallException ex) { error = ex; diff --git a/app/src/main/java/io/lbry/browser/ui/channel/ChannelFragment.java b/app/src/main/java/io/lbry/browser/ui/channel/ChannelFragment.java index 789317fe..5c5d9aed 100644 --- a/app/src/main/java/io/lbry/browser/ui/channel/ChannelFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/channel/ChannelFragment.java @@ -11,7 +11,6 @@ import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; -import android.widget.Toast; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; @@ -36,7 +35,7 @@ import java.util.Map; import io.lbry.browser.MainActivity; import io.lbry.browser.R; -import io.lbry.browser.dialog.SendTipDialogFragment; +import io.lbry.browser.dialog.CreateSupportDialogFragment; import io.lbry.browser.exceptions.LbryUriException; import io.lbry.browser.listener.FetchChannelsListener; import io.lbry.browser.model.Claim; @@ -174,16 +173,16 @@ public class ChannelFragment extends BaseFragment implements FetchChannelsListen } if (claim != null) { - SendTipDialogFragment dialog = SendTipDialogFragment.newInstance(); + CreateSupportDialogFragment dialog = CreateSupportDialogFragment.newInstance(); dialog.setClaim(claim); - dialog.setListener(new SendTipDialogFragment.SendTipListener() { + dialog.setListener(new CreateSupportDialogFragment.CreateSupportListener() { @Override - public void onTipSent(BigDecimal amount) { + public void onSupportCreated(BigDecimal amount, boolean isTip) { double sentAmount = amount.doubleValue(); View view = getView(); if (view != null) { String message = getResources().getQuantityString( - R.plurals.you_sent_a_tip, sentAmount == 1.0 ? 1 : 2, + isTip ? R.plurals.you_sent_a_tip : R.plurals.you_sent_a_support, sentAmount == 1.0 ? 1 : 2, new DecimalFormat("#,###.##").format(sentAmount)); Snackbar.make(view, message, Snackbar.LENGTH_LONG).show(); } @@ -191,7 +190,7 @@ public class ChannelFragment extends BaseFragment implements FetchChannelsListen }); Context context = getContext(); if (context instanceof MainActivity) { - dialog.show(((MainActivity) context).getSupportFragmentManager(), SendTipDialogFragment.TAG); + dialog.show(((MainActivity) context).getSupportFragmentManager(), CreateSupportDialogFragment.TAG); } } } diff --git a/app/src/main/java/io/lbry/browser/ui/findcontent/FileViewFragment.java b/app/src/main/java/io/lbry/browser/ui/findcontent/FileViewFragment.java index efb61061..561da67c 100644 --- a/app/src/main/java/io/lbry/browser/ui/findcontent/FileViewFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/findcontent/FileViewFragment.java @@ -99,7 +99,7 @@ import io.lbry.browser.adapter.CommentListAdapter; import io.lbry.browser.adapter.InlineChannelSpinnerAdapter; import io.lbry.browser.adapter.TagListAdapter; import io.lbry.browser.dialog.RepostClaimDialogFragment; -import io.lbry.browser.dialog.SendTipDialogFragment; +import io.lbry.browser.dialog.CreateSupportDialogFragment; import io.lbry.browser.exceptions.LbryUriException; import io.lbry.browser.listener.DownloadActionListener; import io.lbry.browser.listener.FetchClaimsListener; @@ -845,21 +845,21 @@ public class FileViewFragment extends BaseFragment implements } if (claim != null) { - SendTipDialogFragment dialog = SendTipDialogFragment.newInstance(); + CreateSupportDialogFragment dialog = CreateSupportDialogFragment.newInstance(); dialog.setClaim(claim); - dialog.setListener(new SendTipDialogFragment.SendTipListener() { + dialog.setListener(new CreateSupportDialogFragment.CreateSupportListener() { @Override - public void onTipSent(BigDecimal amount) { + public void onSupportCreated(BigDecimal amount, boolean isTip) { double sentAmount = amount.doubleValue(); String message = getResources().getQuantityString( - R.plurals.you_sent_a_tip, sentAmount == 1.0 ? 1 : 2, + isTip ? R.plurals.you_sent_a_tip : R.plurals.you_sent_a_support, sentAmount == 1.0 ? 1 : 2, new DecimalFormat("#,###.##").format(sentAmount)); Snackbar.make(root.findViewById(R.id.file_view_claim_display_area), message, Snackbar.LENGTH_LONG).show(); } }); Context context = getContext(); if (context instanceof MainActivity) { - dialog.show(((MainActivity) context).getSupportFragmentManager(), SendTipDialogFragment.TAG); + dialog.show(((MainActivity) context).getSupportFragmentManager(), CreateSupportDialogFragment.TAG); } } } diff --git a/app/src/main/res/layout/dialog_send_tip.xml b/app/src/main/res/layout/dialog_create_support.xml similarity index 63% rename from app/src/main/res/layout/dialog_send_tip.xml rename to app/src/main/res/layout/dialog_create_support.xml index 04c0168d..db693d94 100644 --- a/app/src/main/res/layout/dialog_send_tip.xml +++ b/app/src/main/res/layout/dialog_create_support.xml @@ -9,7 +9,7 @@ android:orientation="vertical" android:padding="16dp"> + android:layout_marginBottom="12dp" /> + + + + + + + + + + + - @@ -93,7 +133,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content"> diff --git a/app/src/main/res/layout/fragment_file_view.xml b/app/src/main/res/layout/fragment_file_view.xml index dc6b1467..ebac1449 100644 --- a/app/src/main/res/layout/fragment_file_view.xml +++ b/app/src/main/res/layout/fragment_file_view.xml @@ -295,7 +295,7 @@ diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f0ce3b7b..637c2a6a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -363,7 +363,7 @@ Filter for Everyone Tags you follow - Customize + CustomizeSend a tip The selected view is not yet available. It looks like you have not followed any tags yet. Search for more tags @@ -373,6 +373,12 @@ You cannot add more than 5 tags. Send a tip Send a tip to %1$s + Support this content + This will increase the overall bid amount for this content, which will boost its ability to be discovered while active. <a href="https://lbry.com/faq/tipping">Learn more</a>. + Channel to show support as + Make this a tip + Send Revocable Support + Send a %1$s LBC Tip This will appear as a tip for %1$s, which will boost its ability to be discovered while active. <a href="https://lbry.com/faq/tipping">Learn more</a>. This will appear as a tip for %1$s, which will boost the channel\'s ability to be discovered while active. <a href="https://lbry.com/faq/tipping">Learn more</a>. Cancel @@ -389,6 +395,10 @@ You sent %1$s credit as a tip, Mahalo! You sent %1$s credits as a tip, Mahalo! + + You staked %1$s credit as a support. You can revoke your support at any time. + You staked %1$s credits as a support. You can revoke your support at any time. + Please provide an email address.