diff --git a/README.md b/README.md index 0d152064..8f7b0387 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,17 @@ The minimum supported Android version is 5.0 Lollipop. There are two ways to ins The app can be launched by opening **LBRY** from the device's app drawer or via the shortcut on the home screen if that was created upon installation. ## Running from Source -Clone the repository and open the project in Android Studio. Android Studio will automatically run the initial build process. Click the Run button to launch the app on your simulator or connected debugging device after the build process is complete. +Clone the repository and open the project in Android Studio. Android Studio will automatically run the initial build process. + +Create file 'twitter.properties' in app/ folder with the following content: + +``` +twitterConsumerKey=XXXXXX + +twitterConsumerSecret=XXXXXX +``` + +Click the Sync button and when process finishes, the Run button to launch the app on your simulator or connected debugging device after the build process is complete. ## Contributing Contributions to this project are welcome, encouraged, and compensated. For more details, see https://lbry.io/faq/contributing diff --git a/app/build.gradle b/app/build.gradle index 874ae3d2..4e209d22 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -101,10 +101,8 @@ dependencies { implementation 'com.arthenica:mobile-ffmpeg-full-gpl:4.3.1.LTS' - implementation('org.bitcoinj:bitcoinj-tools:0.14.7') { - exclude group: 'com.google.protobuf', module: 'protobuf-java' - exclude module: 'guava' - } + implementation 'commons-codec:commons-codec:1.15' + implementation 'org.bitcoinj:bitcoinj-tools:0.14.7' implementation 'org.java-websocket:Java-WebSocket:1.5.1' compileOnly 'org.projectlombok:lombok:1.18.10' diff --git a/app/src/main/java/io/lbry/browser/model/Comment.java b/app/src/main/java/io/lbry/browser/model/Comment.java index 157a2174..2e9a9ae1 100644 --- a/app/src/main/java/io/lbry/browser/model/Comment.java +++ b/app/src/main/java/io/lbry/browser/model/Comment.java @@ -12,7 +12,6 @@ import lombok.Data; @Data public class Comment implements Comparable { - public static final double LBC_COST = 1; public static final int MAX_LENGTH = 2000; private Claim poster; diff --git a/app/src/main/java/io/lbry/browser/tasks/CommentCreateWithTipTask.java b/app/src/main/java/io/lbry/browser/tasks/CommentCreateTask.java similarity index 83% rename from app/src/main/java/io/lbry/browser/tasks/CommentCreateWithTipTask.java rename to app/src/main/java/io/lbry/browser/tasks/CommentCreateTask.java index 05e2fca1..54f810e6 100644 --- a/app/src/main/java/io/lbry/browser/tasks/CommentCreateWithTipTask.java +++ b/app/src/main/java/io/lbry/browser/tasks/CommentCreateTask.java @@ -24,18 +24,16 @@ import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; -public class CommentCreateWithTipTask extends AsyncTask { +public class CommentCreateTask extends AsyncTask { 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; } @@ -62,13 +60,6 @@ public class CommentCreateWithTipTask extends AsyncTask { } Map 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()); diff --git a/app/src/main/java/io/lbry/browser/ui/channel/ChannelCommentsFragment.java b/app/src/main/java/io/lbry/browser/ui/channel/ChannelCommentsFragment.java index 3189cc5e..ce6dc6c3 100644 --- a/app/src/main/java/io/lbry/browser/ui/channel/ChannelCommentsFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/channel/ChannelCommentsFragment.java @@ -30,7 +30,6 @@ import com.google.android.material.snackbar.Snackbar; import com.google.android.material.textfield.TextInputEditText; import java.math.BigDecimal; -import java.text.DecimalFormat; import java.util.ArrayList; import java.util.List; @@ -45,7 +44,7 @@ import io.lbry.browser.listener.WalletBalanceListener; 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; @@ -58,7 +57,6 @@ import io.lbry.browser.utils.Helper; 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 { @@ -367,9 +365,6 @@ public class ChannelCommentsFragment extends Fragment implements SdkStatusListen } 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() { @@ -387,7 +382,7 @@ public class ChannelCommentsFragment extends Fragment implements SdkStatusListen return; } - validateAndCheckPostComment(amount); + validateAndCheckPostComment(); } }); @@ -433,7 +428,7 @@ public class ChannelCommentsFragment extends Fragment implements SdkStatusListen }); } - private void validateAndCheckPostComment(double amount) { + private void validateAndCheckPostComment() { String comment = Helper.getValue(inputComment.getText()); Claim channel = (Claim) commentChannelSpinner.getSelectedItem(); @@ -445,29 +440,18 @@ public class ChannelCommentsFragment extends Fragment implements SdkStatusListen 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(); @@ -545,17 +529,15 @@ public class ChannelCommentsFragment extends Fragment implements SdkStatusListen 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); @@ -573,7 +555,6 @@ public class ChannelCommentsFragment extends Fragment implements SdkStatusListen 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); 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 b4c8a4fc..3efcd1e8 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 @@ -123,7 +123,7 @@ import io.lbry.browser.model.WalletBalance; 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; @@ -2989,9 +2989,6 @@ public class FileViewFragment extends BaseFragment implements } 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() { @@ -3009,7 +3006,7 @@ public class FileViewFragment extends BaseFragment implements return; } - validateAndCheckPostComment(amount); + validateAndCheckPostComment(); } }); @@ -3055,7 +3052,7 @@ public class FileViewFragment extends BaseFragment implements }); } - private void validateAndCheckPostComment(double amount) { + private void validateAndCheckPostComment() { String comment = Helper.getValue(inputComment.getText()); Claim channel = (Claim) commentChannelSpinner.getSelectedItem(); @@ -3067,29 +3064,18 @@ public class FileViewFragment extends BaseFragment implements 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(); @@ -3167,17 +3153,15 @@ public class FileViewFragment extends BaseFragment implements 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); @@ -3195,7 +3179,6 @@ public class FileViewFragment extends BaseFragment implements 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); diff --git a/app/src/main/java/io/lbry/browser/utils/Helper.java b/app/src/main/java/io/lbry/browser/utils/Helper.java index 6d6a3862..73bfa10f 100644 --- a/app/src/main/java/io/lbry/browser/utils/Helper.java +++ b/app/src/main/java/io/lbry/browser/utils/Helper.java @@ -29,9 +29,8 @@ import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; -import com.google.android.gms.common.util.Hex; +import org.apache.commons.codec.binary.Hex; -import org.bitcoinj.core.Base58; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -39,7 +38,7 @@ import org.json.JSONObject; import java.io.Closeable; import java.io.File; import java.io.IOException; -import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.text.DecimalFormat; @@ -795,9 +794,9 @@ public final class Helper { public static String SHA256(String value) { try { MessageDigest digest = MessageDigest.getInstance("SHA-256"); - byte[] hash = digest.digest(value.getBytes("UTF-8")); - return Hex.bytesToStringLowercase(hash); - } catch (NoSuchAlgorithmException | UnsupportedEncodingException ex) { + byte[] hash = digest.digest(value.getBytes(StandardCharsets.UTF_8)); + return Hex.encodeHexString(hash, true); + } catch (NoSuchAlgorithmException ex) { return null; } } diff --git a/app/src/main/res/layout/container_comment_form.xml b/app/src/main/res/layout/container_comment_form.xml index d92f96af..cca903d3 100644 --- a/app/src/main/res/layout/container_comment_form.xml +++ b/app/src/main/res/layout/container_comment_form.xml @@ -47,22 +47,25 @@ android:layout_marginBottom="8dp" android:orientation="horizontal" android:visibility="gone"> + + android:background="@color/nextLbryGreen" + android:orientation="vertical" /> + + android:layout_marginEnd="40dp" + android:orientation="vertical"> + + android:layout_height="36dp" + android:layout_alignParentEnd="true" + android:background="?attr/selectableItemBackground" + android:clickable="true"> + + + android:layout_centerVertical="true" + android:fontFamily="@font/inter" + android:text="@string/comment_form_post" /> + + android:layout_height="246dp" + android:background="@color/mediaContainerBackground"> + + android:layout_height="match_parent" + android:clickable="true" + android:foreground="?attr/selectableItemBackground"> + + + + android:visibility="invisible" /> + + + + android:textFontWeight="300" + android:textSize="14sp" /> + + app:controller_layout_id="@layout/exo_playback_control_view" /> + + + android:src="@drawable/gerbil_happy" /> + + android:layout_toEndOf="@id/file_view_unsupported_gerbil" + android:orientation="vertical"> + + android:textSize="18sp" /> + + android:textSize="14sp" /> + + android:text="@string/open" + android:textSize="14sp" /> @@ -173,31 +188,37 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:clipToPadding="false"> + - + + + android:layout_height="wrap_content" + android:visibility="gone" /> + + android:paddingTop="8dp" + android:paddingEnd="4dp" + android:paddingBottom="8dp"> + + android:layout_centerVertical="true" + android:layout_marginEnd="48dp" + android:orientation="vertical"> + + + android:layout_height="wrap_content" + android:layout_marginTop="4dp" + android:orientation="horizontal"> + + + android:textFontWeight="300" + android:textSize="12sp" /> @@ -246,280 +270,308 @@ android:layout_height="wrap_content" android:orientation="horizontal" android:weightSum="5"> + + + + android:src="@drawable/ic_share" + android:tint="@color/foreground" /> + + android:layout_gravity="center_horizontal" + android:fontFamily="@font/inter" + android:text="@string/share" + android:textSize="12sp" /> + + + android:text="@string/fa_gift" + android:textColor="@color/foreground" + android:textSize="20dp" /> + + android:layout_gravity="center_horizontal" + android:fontFamily="@font/inter" + android:text="@string/support" + android:textSize="12sp" /> + + + android:text="@string/fa_repost" + android:textColor="@color/foreground" + android:textSize="20dp" /> + + android:layout_gravity="center_horizontal" + android:fontFamily="@font/inter" + android:text="@string/repost" + android:textSize="12sp" /> + + + android:src="@drawable/ic_edit" + android:tint="@color/foreground" /> + + android:layout_gravity="center_horizontal" + android:fontFamily="@font/inter" + android:text="@string/edit" + android:textSize="12sp" /> + + + + android:src="@drawable/ic_download" + android:tint="@color/foreground" /> + + android:layout_gravity="center_horizontal" + android:fontFamily="@font/inter" + android:text="@string/download" + android:textSize="12sp" /> + + + android:src="@drawable/ic_delete" + android:tint="@color/foreground" /> + + android:layout_gravity="center_horizontal" + android:fontFamily="@font/inter" + android:text="@string/delete" + android:textSize="12sp" /> + + + android:src="@drawable/ic_unpublish" + android:tint="@color/foreground" /> + + android:layout_gravity="center_horizontal" + android:fontFamily="@font/inter" + android:text="@string/unpublish" + android:textSize="12sp" /> + + + android:src="@drawable/ic_report" + android:tint="@color/foreground" /> + + android:layout_gravity="center_horizontal" + android:fontFamily="@font/inter" + android:text="@string/report" + android:textSize="12sp" /> + android:background="@color/divider" /> + + android:paddingTop="12dp" + android:paddingBottom="12dp"> + + + android:layout_height="50dp" + android:layout_centerHorizontal="true" + android:background="@drawable/bg_channel_icon"> + + android:textFontWeight="300" + android:textSize="24sp" /> + + android:layout_height="50dp" + android:layout_centerHorizontal="true" /> + + + android:orientation="horizontal"> + + android:paddingTop="8dp" + android:paddingBottom="8dp"> + + android:textStyle="bold" /> + android:visibility="gone" /> + android:background="@color/divider" /> + android:layout_marginBottom="8dp" + android:orientation="vertical"> + + + android:text="@string/related_content" + android:textSize="16sp" /> + + + + android:layout_height="wrap_content" + android:overScrollMode="never" /> + android:orientation="vertical" + android:paddingBottom="16dp"> + Comment as Please enter a comment to post. Please select a channel to post your comment as. + Post + Confirm your comment + This will post your comment Your comment was successfully posted. Please select a channel to repost on. Reply Replying to %1$s Choose app - - Post and tip %1$s credit? - Post and tip %1$s credits? - - - Post for %1$s credit - Post for %1$s credits - - - This will post your comment with a tip of %1$s credit for %2$s - This will post your comment with a tip of %1$s credits for %2$s - %1$s view %1$s views diff --git a/app/src/test/java/io/lbry/browser/utils/HelperTest.java b/app/src/test/java/io/lbry/browser/utils/HelperTest.java new file mode 100644 index 00000000..c43b7291 --- /dev/null +++ b/app/src/test/java/io/lbry/browser/utils/HelperTest.java @@ -0,0 +1,11 @@ +package io.lbry.browser.utils; + +import junit.framework.TestCase; + +public class HelperTest extends TestCase { + + public void testSHA256() { + // Using a fake user id, which is a long. + assertEquals("de9edb2044d012f04553e49b04d54cbec8e8a46a40ad5a19bc5dcce1da00ecfd", Helper.SHA256(String.valueOf(12345678912345L))); + } +} \ No newline at end of file