Skip to content

Commit

Permalink
Removed comment tips
Browse files Browse the repository at this point in the history
  • Loading branch information
clay53 committed Dec 13, 2020
1 parent 0647deb commit 0f10e9d
Show file tree
Hide file tree
Showing 7 changed files with 272 additions and 256 deletions.
1 change: 0 additions & 1 deletion app/src/main/java/io/lbry/browser/model/Comment.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

@Data
public class Comment implements Comparable<Comment> {
public static final double LBC_COST = 1;
public static final int MAX_LENGTH = 2000;

private Claim poster;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,16 @@
import okhttp3.Request;
import okhttp3.Response;

public class CommentCreateWithTipTask extends AsyncTask<Void, Void, Comment> {
public class CommentCreateTask extends AsyncTask<Void, Void, Comment> {
private static final String STATUS_ENDPOINT = "https://comments.lbry.com";

private Comment comment;
private BigDecimal amount;
private View progressView;
private CommentCreateWithTipHandler handler;
private Exception error;

public CommentCreateWithTipTask(Comment comment, BigDecimal amount, View progressView, CommentCreateWithTipHandler handler) {
public CommentCreateTask(Comment comment, View progressView, CommentCreateWithTipHandler handler) {
this.comment = comment;
this.amount = amount;
this.progressView = progressView;
this.handler = handler;
}
Expand All @@ -62,13 +60,6 @@ public Comment doInBackground(Void... params) {
}

Map<String, Object> options = new HashMap<>();
options.put("blocking", true);
options.put("claim_id", comment.getClaimId());
options.put("amount", new DecimalFormat(Helper.SDK_AMOUNT_FORMAT, new DecimalFormatSymbols(Locale.US)).format(amount.doubleValue()));
options.put("tip", true);
Lbry.genericApiCall(Lbry.METHOD_SUPPORT_CREATE, options);

options = new HashMap<>();
options.put("comment", comment.getText());
options.put("claim_id", comment.getClaimId());
options.put("channel_id", comment.getChannelId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import com.google.android.material.textfield.TextInputEditText;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -45,7 +44,7 @@
import io.lbry.browser.model.Claim;
import io.lbry.browser.model.Comment;
import io.lbry.browser.model.WalletBalance;
import io.lbry.browser.tasks.CommentCreateWithTipTask;
import io.lbry.browser.tasks.CommentCreateTask;
import io.lbry.browser.tasks.CommentListHandler;
import io.lbry.browser.tasks.CommentListTask;
import io.lbry.browser.tasks.claim.ChannelCreateUpdateTask;
Expand All @@ -58,7 +57,6 @@
import io.lbry.browser.utils.Lbry;
import io.lbry.browser.utils.LbryAnalytics;
import io.lbry.browser.utils.LbryUri;
import io.lbry.browser.utils.Lbryio;
import lombok.Setter;

public class ChannelCommentsFragment extends Fragment implements SdkStatusListener, WalletBalanceListener {
Expand Down Expand Up @@ -367,9 +365,6 @@ private void updateChannelList(List<Claim> channels) {
}

private void initCommentForm(View root) {
double amount = Comment.LBC_COST;
String buttonText = getResources().getQuantityString(R.plurals.post_for_credits, amount == 1 ? 1 : 2, Helper.LBC_CURRENCY_FORMAT.format(amount));
buttonPostComment.setText(buttonText);
textCommentLimit.setText(String.format("%d / %d", Helper.getValue(inputComment.getText()).length(), Comment.MAX_LENGTH));

buttonClearReplyToComment.setOnClickListener(new View.OnClickListener() {
Expand All @@ -387,7 +382,7 @@ public void onClick(View view) {
return;
}

validateAndCheckPostComment(amount);
validateAndCheckPostComment();
}
});

Expand Down Expand Up @@ -433,7 +428,7 @@ public void onNothingSelected(AdapterView<?> adapterView) {
});
}

private void validateAndCheckPostComment(double amount) {
private void validateAndCheckPostComment() {
String comment = Helper.getValue(inputComment.getText());
Claim channel = (Claim) commentChannelSpinner.getSelectedItem();

Expand All @@ -445,29 +440,18 @@ private void validateAndCheckPostComment(double amount) {
showError(getString(R.string.please_select_channel));
return;
}
if (Lbry.walletBalance == null || amount > Lbry.walletBalance.getAvailable().doubleValue()) {
showError(getString(R.string.insufficient_balance));
return;
}

Context context = getContext();
if (context != null) {
String titleText = getResources().getQuantityString(
R.plurals.post_and_tip,
amount == 1 ? 1 : 2,
Helper.LBC_CURRENCY_FORMAT.format(amount));
String confirmText = getResources().getQuantityString(
R.plurals.confirm_post_comment,
amount == 1 ? 1 : 2,
Helper.LBC_CURRENCY_FORMAT.format(amount),
claim.getTitleOrName());
String titleText = getResources().getString(R.string.comment_confirm_post);
String confirmText = getResources().getString(R.string.confirm_post_comment);
AlertDialog.Builder builder = new AlertDialog.Builder(context).
setTitle(titleText).
setMessage(confirmText)
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
postComment(amount);
postComment();
}
}).setNegativeButton(R.string.no, null);
builder.show();
Expand Down Expand Up @@ -545,17 +529,15 @@ private void clearReplyToComment() {
replyToComment = null;
}

private void postComment(double tipAmount) {
private void postComment() {
if (postingComment) {
return;
}

Comment comment = buildPostComment();
// only use 2 decimal places
BigDecimal amount = new BigDecimal(String.valueOf(tipAmount));

beforePostComment();
CommentCreateWithTipTask task = new CommentCreateWithTipTask(comment, amount, progressPostComment, new CommentCreateWithTipTask.CommentCreateWithTipHandler() {
CommentCreateTask task = new CommentCreateTask(comment, progressPostComment, new CommentCreateTask.CommentCreateWithTipHandler() {
@Override
public void onSuccess(Comment createdComment) {
inputComment.setText(null);
Expand All @@ -573,7 +555,6 @@ public void onSuccess(Comment createdComment) {
checkNoComments();

Bundle bundle = new Bundle();
bundle.putDouble("amount", amount.doubleValue());
bundle.putString("claim_id", claim != null ? claim.getClaimId() : null);
bundle.putString("claim_name", claim != null ? claim.getName() : null);
LbryAnalytics.logEvent(LbryAnalytics.EVENT_COMMENT_CREATE, bundle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
import io.lbry.browser.model.lbryinc.Reward;
import io.lbry.browser.model.lbryinc.Subscription;
import io.lbry.browser.tasks.BufferEventTask;
import io.lbry.browser.tasks.CommentCreateWithTipTask;
import io.lbry.browser.tasks.CommentCreateTask;
import io.lbry.browser.tasks.CommentListHandler;
import io.lbry.browser.tasks.CommentListTask;
import io.lbry.browser.tasks.GenericTaskHandler;
Expand Down Expand Up @@ -2989,9 +2989,6 @@ private void updateChannelList(List<Claim> channels) {
}

private void initCommentForm(View root) {
double amount = Comment.LBC_COST;
String buttonText = getResources().getQuantityString(R.plurals.post_for_credits, amount == 1 ? 1 : 2, Helper.LBC_CURRENCY_FORMAT.format(amount));
buttonPostComment.setText(buttonText);
textCommentLimit.setText(String.format("%d / %d", Helper.getValue(inputComment.getText()).length(), Comment.MAX_LENGTH));

buttonClearReplyToComment.setOnClickListener(new View.OnClickListener() {
Expand All @@ -3009,7 +3006,7 @@ public void onClick(View view) {
return;
}

validateAndCheckPostComment(amount);
validateAndCheckPostComment();
}
});

Expand Down Expand Up @@ -3055,7 +3052,7 @@ public void onNothingSelected(AdapterView<?> adapterView) {
});
}

private void validateAndCheckPostComment(double amount) {
private void validateAndCheckPostComment() {
String comment = Helper.getValue(inputComment.getText());
Claim channel = (Claim) commentChannelSpinner.getSelectedItem();

Expand All @@ -3067,29 +3064,18 @@ private void validateAndCheckPostComment(double amount) {
showError(getString(R.string.please_select_channel));
return;
}
if (Lbry.walletBalance == null || amount > Lbry.walletBalance.getAvailable().doubleValue()) {
showError(getString(R.string.insufficient_balance));
return;
}

Context context = getContext();
if (context != null) {
String titleText = getResources().getQuantityString(
R.plurals.post_and_tip,
amount == 1 ? 1 : 2,
Helper.LBC_CURRENCY_FORMAT.format(amount));
String confirmText = getResources().getQuantityString(
R.plurals.confirm_post_comment,
amount == 1 ? 1 : 2,
Helper.LBC_CURRENCY_FORMAT.format(amount),
claim.getTitleOrName());
String titleText = getResources().getString(R.string.comment_confirm_post);
String confirmText = getResources().getString(R.string.confirm_post_comment);
AlertDialog.Builder builder = new AlertDialog.Builder(context).
setTitle(titleText).
setMessage(confirmText)
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
postComment(amount);
postComment();
}
}).setNegativeButton(R.string.no, null);
builder.show();
Expand Down Expand Up @@ -3167,17 +3153,15 @@ private void clearReplyToComment() {
replyToComment = null;
}

private void postComment(double tipAmount) {
private void postComment() {
if (postingComment) {
return;
}

Comment comment = buildPostComment();
// only use 2 decimal places
BigDecimal amount = new BigDecimal(String.valueOf(tipAmount));

beforePostComment();
CommentCreateWithTipTask task = new CommentCreateWithTipTask(comment, amount, progressPostComment, new CommentCreateWithTipTask.CommentCreateWithTipHandler() {
CommentCreateTask task = new CommentCreateTask(comment, progressPostComment, new CommentCreateTask.CommentCreateWithTipHandler() {
@Override
public void onSuccess(Comment createdComment) {
inputComment.setText(null);
Expand All @@ -3195,7 +3179,6 @@ public void onSuccess(Comment createdComment) {
checkNoComments();

Bundle bundle = new Bundle();
bundle.putDouble("amount", amount.doubleValue());
bundle.putString("claim_id", claim != null ? claim.getClaimId() : null);
bundle.putString("claim_name", claim != null ? claim.getName() : null);
LbryAnalytics.logEvent(LbryAnalytics.EVENT_COMMENT_CREATE, bundle);
Expand Down
28 changes: 17 additions & 11 deletions app/src/main/res/layout/container_comment_form.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,25 @@
android:layout_marginBottom="8dp"
android:orientation="horizontal"
android:visibility="gone">

<View
android:id="@+id/comment_form_reply_to_vertical_bar"
android:layout_width="3dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/nextLbryGreen" />
android:background="@color/nextLbryGreen"
android:orientation="vertical" />

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginEnd="40dp">
android:layout_marginEnd="40dp"
android:orientation="vertical">

<TextView
android:id="@+id/comment_form_replying_to_text"
android:layout_width="wrap_content"
Expand All @@ -77,19 +80,20 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:lineSpacingMultiplier="1.05"
android:fontFamily="@font/inter"
android:lineSpacingMultiplier="1.05"
android:textFontWeight="300"
android:textSize="14sp" />
</LinearLayout>

<RelativeLayout
android:id="@+id/comment_form_clear_reply_to"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:layout_alignParentEnd="true"
android:layout_width="36dp"
android:layout_height="36dp">
android:layout_height="36dp"
android:layout_alignParentEnd="true"
android:background="?attr/selectableItemBackground"
android:clickable="true">

<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
Expand Down Expand Up @@ -168,12 +172,14 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp">

<com.google.android.material.button.MaterialButton
android:id="@+id/comment_form_post"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/inter" />
android:layout_centerVertical="true"
android:fontFamily="@font/inter"
android:text="@string/comment_form_post" />
<ProgressBar
android:id="@+id/comment_form_post_progress"
android:layout_width="20dp"
Expand Down
Loading

0 comments on commit 0f10e9d

Please sign in to comment.