combined tip / support dialog and signed supports (#944)
* combined tip / support dialog and signed supports * update button label when amount is updated
This commit is contained in:
parent
0a2769859a
commit
9d6b3ddf81
9 changed files with 441 additions and 235 deletions
|
@ -41,6 +41,12 @@ public class InlineChannelSpinnerAdapter extends ArrayAdapter<Claim> {
|
|||
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<? extends Claim> collection) {
|
||||
for (Claim claim : collection) {
|
||||
|
|
|
@ -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<Claim> 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<Claim> 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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -17,14 +17,16 @@ import io.lbry.browser.utils.Lbry;
|
|||
|
||||
public class SupportCreateTask extends AsyncTask<Void, Void, Boolean> {
|
||||
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<Void, Void, Boolean> {
|
|||
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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
<TextView
|
||||
android:id="@+id/tip_send_title"
|
||||
android:id="@+id/create_support_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
|
@ -22,19 +22,58 @@
|
|||
android:layout_height="0.5dp"
|
||||
android:background="@color/divider"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginBottom="4dp" />
|
||||
android:layout_marginBottom="12dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/create_support_info"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="@font/inter"
|
||||
android:text="@string/send_tip_info_content"
|
||||
android:textFontWeight="300"
|
||||
android:textSize="14sp" />
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0.5dp"
|
||||
android:background="@color/lightDivider"
|
||||
android:layout_marginTop="12dp"
|
||||
android:layout_marginBottom="12dp" />
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:text="@string/channel_to_show_support_as" />
|
||||
<ProgressBar
|
||||
android:id="@+id/create_support_channel_progress"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp"
|
||||
android:visibility="gone" />
|
||||
</RelativeLayout>
|
||||
|
||||
<androidx.appcompat.widget.AppCompatSpinner
|
||||
android:id="@+id/create_support_channel_spinner"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="4dp" />
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/tip_input_layout_amount"
|
||||
android:id="@+id/create_support_input_layout_amount"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/amount">
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/tip_input_amount"
|
||||
android:id="@+id/create_support_input_amount"
|
||||
android:fontFamily="@font/inter"
|
||||
android:textSize="14sp"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -43,8 +82,8 @@
|
|||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tip_input_currency"
|
||||
android:layout_toRightOf="@id/tip_input_layout_amount"
|
||||
android:id="@+id/create_support_input_currency"
|
||||
android:layout_toRightOf="@id/create_support_input_layout_amount"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="8dp"
|
||||
|
@ -56,8 +95,8 @@
|
|||
android:textFontWeight="300" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/tip_inline_balance_container"
|
||||
android:layout_toRightOf="@id/tip_input_currency"
|
||||
android:id="@+id/create_support_inline_balance_container"
|
||||
android:layout_toRightOf="@id/create_support_input_currency"
|
||||
android:layout_marginLeft="24dp"
|
||||
android:layout_marginTop="28dp"
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -69,7 +108,7 @@
|
|||
android:layout_height="18dp"
|
||||
android:text="@string/fa_coins" />
|
||||
<TextView
|
||||
android:id="@+id/tip_inline_balance_value"
|
||||
android:id="@+id/create_support_inline_balance_value"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="@font/inter"
|
||||
|
@ -78,14 +117,15 @@
|
|||
</LinearLayout>
|
||||
</RelativeLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tip_info"
|
||||
<com.google.android.material.switchmaterial.SwitchMaterial
|
||||
android:id="@+id/create_support_make_tip_switch"
|
||||
android:checked="true"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:text="@string/make_this_a_tip"
|
||||
android:fontFamily="@font/inter"
|
||||
android:text="@string/send_tip_info_content"
|
||||
android:textFontWeight="300"
|
||||
android:textSize="14sp" />
|
||||
|
||||
|
@ -93,7 +133,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<TextView
|
||||
android:id="@+id/tip_cancel_link"
|
||||
android:id="@+id/create_support_cancel_link"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:clickable="true"
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -105,20 +145,20 @@
|
|||
android:textSize="14sp" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/tip_send_progress"
|
||||
android:id="@+id/create_support_progress"
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp"
|
||||
android:layout_toLeftOf="@id/tip_send"
|
||||
android:layout_toLeftOf="@id/create_support_send"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginRight="8dp"
|
||||
android:visibility="gone" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/tip_send"
|
||||
android:id="@+id/create_support_send"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="@font/inter"
|
||||
android:text="@string/send"
|
||||
android:text="@string/send_lbc_tip"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_centerVertical="true" />
|
||||
</RelativeLayout>
|
|
@ -295,7 +295,7 @@
|
|||
<TextView
|
||||
android:fontFamily="@font/inter"
|
||||
android:textSize="12sp"
|
||||
android:text="@string/tip"
|
||||
android:text="@string/support"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal" />
|
||||
|
|
|
@ -363,7 +363,7 @@
|
|||
<string name="filter_for">Filter for</string>
|
||||
<string name="everyone">Everyone</string>
|
||||
<string name="tags_you_follow">Tags you follow</string>
|
||||
<string name="customize">Customize</string>
|
||||
<string name="customize">Customize</string>Send a tip
|
||||
<string name="not_yet_implemented">The selected view is not yet available.</string>
|
||||
<string name="customize_tags_hint">It looks like you have not followed any tags yet.</string>
|
||||
<string name="search_for_more_tags">Search for more tags</string>
|
||||
|
@ -373,6 +373,12 @@
|
|||
<string name="tag_limit_reached">You cannot add more than 5 tags.</string>
|
||||
<string name="send_a_tip">Send a tip</string>
|
||||
<string name="send_a_tip_to">Send a tip to %1$s</string>
|
||||
<string name="support_this_content">Support this content</string>
|
||||
<string name="support_info">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>.</string>
|
||||
<string name="channel_to_show_support_as">Channel to show support as</string>
|
||||
<string name="make_this_a_tip">Make this a tip</string>
|
||||
<string name="send_revocable_support">Send Revocable Support</string>
|
||||
<string name="send_lbc_tip">Send a %1$s LBC Tip</string>
|
||||
<string name="send_tip_info_content">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>.</string>
|
||||
<string name="send_tip_info_channel">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>.</string>
|
||||
<string name="cancel">Cancel</string>
|
||||
|
@ -389,6 +395,10 @@
|
|||
<item quantity="one">You sent %1$s credit as a tip, Mahalo!</item>
|
||||
<item quantity="other">You sent %1$s credits as a tip, Mahalo!</item>
|
||||
</plurals>
|
||||
<plurals name="you_sent_a_support">
|
||||
<item quantity="one">You staked %1$s credit as a support. You can revoke your support at any time.</item>
|
||||
<item quantity="other">You staked %1$s credits as a support. You can revoke your support at any time.</item>
|
||||
</plurals>
|
||||
|
||||
<!-- Verification -->
|
||||
<string name="provide_email_address">Please provide an email address.</string>
|
||||
|
|
Loading…
Reference in a new issue