implement commenting with tips #922

Merged
akinwale merged 4 commits from commenting into master 2020-05-31 22:06:04 +02:00
12 changed files with 193 additions and 109 deletions
Showing only changes of commit a7101778d2 - Show all commits

View file

@ -353,7 +353,11 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
// workaround to fix dark theme because https://issuetracker.google.com/issues/37124582 // workaround to fix dark theme because https://issuetracker.google.com/issues/37124582
try {
new WebView(this); new WebView(this);
} catch (Exception ex) {
// pass (don't fail initialization on some _weird_ device implementations)
}
AppCompatDelegate.setDefaultNightMode(isDarkMode() ? AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_NO); AppCompatDelegate.setDefaultNightMode(isDarkMode() ? AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_NO);
initKeyStore(); initKeyStore();
@ -365,17 +369,20 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
initSpecialRouteMap(); initSpecialRouteMap();
LbryAnalytics.init(this); LbryAnalytics.init(this);
try {
FirebaseInstanceId.getInstance().getInstanceId().addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() { FirebaseInstanceId.getInstance().getInstanceId().addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
@Override @Override
public void onComplete(Task<InstanceIdResult> task) { public void onComplete(Task<InstanceIdResult> task) {
if (!task.isSuccessful()) { if (!task.isSuccessful()) {
return; return;
} }
// Get new Instance ID token // Get new Instance ID token
firebaseMessagingToken = task.getResult().getToken(); firebaseMessagingToken = task.getResult().getToken();
} }
}); });
} catch (IllegalStateException ex) {
// pass
}
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
dbHelper = new DatabaseHelper(this); dbHelper = new DatabaseHelper(this);
@ -739,8 +746,13 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
public void openPublishesOnSuccessfulPublish() { public void openPublishesOnSuccessfulPublish() {
// close publish form // close publish form
try {
getSupportFragmentManager().popBackStack(); getSupportFragmentManager().popBackStack();
openFragment(PublishesFragment.class, true, NavMenuItem.ID_ITEM_PUBLISHES); openFragment(PublishesFragment.class, true, NavMenuItem.ID_ITEM_PUBLISHES);
} catch (IllegalStateException ex) {
// pass
onBackPressed();
}
} }
public void openPublishForm(Claim claim) { public void openPublishForm(Claim claim) {
@ -2486,8 +2498,14 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
!startingSignInFlowActivity) { !startingSignInFlowActivity) {
enteringPIPMode = true; enteringPIPMode = true;
PictureInPictureParams params = new PictureInPictureParams.Builder().build(); PictureInPictureParams params = new PictureInPictureParams.Builder().build();
try {
enterPictureInPictureMode(params); enterPictureInPictureMode(params);
return true; return true;
} catch (IllegalStateException ex) {
// pass
enteringPIPMode = false;
}
} }
return false; return false;
@ -2933,6 +2951,9 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
} }
public static boolean hasPermission(String permission, Context context) { public static boolean hasPermission(String permission, Context context) {
if (context == null) {
return false;
}
return (ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED); return (ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED);
} }

View file

@ -177,7 +177,7 @@ public class VerificationActivity extends FragmentActivity implements SignInList
@Override @Override
public void onError(Exception error) { public void onError(Exception error) {
showFetchUserError(error.getMessage()); showFetchUserError(error != null ? error.getMessage() : getString(R.string.fetch_current_user_error));
hideLoading(); hideLoading();
} }
}); });
@ -213,7 +213,7 @@ public class VerificationActivity extends FragmentActivity implements SignInList
} }
@Override @Override
public void onError(Exception error) { public void onError(Exception error) {
showFetchUserError(error.getMessage()); showFetchUserError(error != null ? error.getMessage() : getString(R.string.fetch_current_user_error));
hideLoading(); hideLoading();
} }
}); });
@ -250,7 +250,7 @@ public class VerificationActivity extends FragmentActivity implements SignInList
@Override @Override
public void onError(Exception error) { public void onError(Exception error) {
showFetchUserError(error.getMessage()); showFetchUserError(error != null ? error.getMessage() : getString(R.string.fetch_current_user_error));
hideLoading(); hideLoading();
} }
}); });

View file

@ -231,6 +231,11 @@ public class RepostClaimDialogFragment extends BottomSheetDialogFragment impleme
} }
Claim channel = (Claim) channelSpinner.getSelectedItem(); Claim channel = (Claim) channelSpinner.getSelectedItem();
if (channel == null) {
showError(getString(R.string.please_select_repost_channel));
return;
}
StreamRepostTask task = new StreamRepostTask(name, bid, claim.getClaimId(), channel.getClaimId(), repostProgress, new ClaimResultHandler() { StreamRepostTask task = new StreamRepostTask(name, bid, claim.getClaimId(), channel.getClaimId(), repostProgress, new ClaimResultHandler() {
@Override @Override
public void beforeStart() { public void beforeStart() {
@ -256,11 +261,14 @@ public class RepostClaimDialogFragment extends BottomSheetDialogFragment impleme
} }
private void showError(String message) { private void showError(String message) {
Snackbar.make(getView(), message, Snackbar.LENGTH_LONG). View view = getView();
if (view != null && !Helper.isNullOrEmpty(message)) {
Snackbar.make(view, message, Snackbar.LENGTH_LONG).
setBackgroundTint(Color.RED). setBackgroundTint(Color.RED).
setTextColor(Color.WHITE). setTextColor(Color.WHITE).
show(); show();
} }
}
private void startLoading() { private void startLoading() {
Dialog dialog = getDialog(); Dialog dialog = getDialog();

View file

@ -91,11 +91,13 @@ public class SendTipDialogFragment extends BottomSheetDialogFragment implements
TextView infoText = view.findViewById(R.id.tip_info); TextView infoText = view.findViewById(R.id.tip_info);
infoText.setMovementMethod(LinkMovementMethod.getInstance()); infoText.setMovementMethod(LinkMovementMethod.getInstance());
if (claim != null) {
infoText.setText(HtmlCompat.fromHtml( infoText.setText(HtmlCompat.fromHtml(
Claim.TYPE_CHANNEL.equalsIgnoreCase(claim.getValueType()) ? Claim.TYPE_CHANNEL.equalsIgnoreCase(claim.getValueType()) ?
getString(R.string.send_tip_info_channel, claim.getTitleOrName()) : getString(R.string.send_tip_info_channel, claim.getTitleOrName()) :
getString(R.string.send_tip_info_content, claim.getTitleOrName()), getString(R.string.send_tip_info_content, claim.getTitleOrName()),
HtmlCompat.FROM_HTML_MODE_LEGACY)); HtmlCompat.FROM_HTML_MODE_LEGACY));
}
sendButton.setOnClickListener(new View.OnClickListener() { sendButton.setOnClickListener(new View.OnClickListener() {
@Override @Override

View file

@ -55,6 +55,7 @@ public class LoadGalleryItemsTask extends AsyncTask<Void, GalleryItem, List<Gall
MediaStore.Video.Media.EXTERNAL_CONTENT_URI, MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
projection, null, null, projection, null, null,
String.format("%s DESC LIMIT 150", MediaStore.MediaColumns.DATE_MODIFIED)); String.format("%s DESC LIMIT 150", MediaStore.MediaColumns.DATE_MODIFIED));
if (cursor != null) {
while (cursor.moveToNext()) { while (cursor.moveToNext()) {
int idColumn = cursor.getColumnIndex(MediaStore.MediaColumns._ID); int idColumn = cursor.getColumnIndex(MediaStore.MediaColumns._ID);
int nameColumn = cursor.getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME); int nameColumn = cursor.getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME);
@ -70,6 +71,7 @@ public class LoadGalleryItemsTask extends AsyncTask<Void, GalleryItem, List<Gall
item.setDuration(cursor.getLong(durationColumn)); item.setDuration(cursor.getLong(durationColumn));
items.add(item); items.add(item);
} }
}
} catch (SQLiteException ex) { } catch (SQLiteException ex) {
// failed to load videos. log and pass // failed to load videos. log and pass
Log.e(TAG, ex.getMessage(), ex); Log.e(TAG, ex.getMessage(), ex);

View file

@ -254,7 +254,13 @@ public class ChannelFormFragment extends BaseFragment implements
private void checkParams() { private void checkParams() {
Map<String, Object> params = getParams(); Map<String, Object> params = getParams();
if (params.containsKey("claim")) { if (params == null) {
Context context = getContext();
if (context instanceof MainActivity) {
((MainActivity) context).onBackPressed();
return;
}
} else if (params.containsKey("claim")) {
Claim claim = (Claim) params.get("claim"); Claim claim = (Claim) params.get("claim");
if (claim != null && !claim.equals(this.currentClaim)) { if (claim != null && !claim.equals(this.currentClaim)) {
this.currentClaim = claim; this.currentClaim = claim;

View file

@ -835,7 +835,10 @@ public class FileViewFragment extends BaseFragment implements
dialog.setListener(new RepostClaimDialogFragment.RepostClaimListener() { dialog.setListener(new RepostClaimDialogFragment.RepostClaimListener() {
@Override @Override
public void onClaimReposted(Claim claim) { public void onClaimReposted(Claim claim) {
Snackbar.make(root.findViewById(R.id.file_view_claim_display_area), R.string.content_successfully_reposted, Snackbar.LENGTH_LONG).show(); Context context = getContext();
if (context instanceof MainActivity) {
((MainActivity) context).showMessage(R.string.content_successfully_reposted);
}
} }
}); });
Context context = getContext(); Context context = getContext();
@ -1416,7 +1419,7 @@ public class FileViewFragment extends BaseFragment implements
root.findViewById(R.id.file_view_exoplayer_container).setVisibility(View.GONE); root.findViewById(R.id.file_view_exoplayer_container).setVisibility(View.GONE);
root.findViewById(R.id.file_view_unsupported_container).setVisibility(View.VISIBLE); root.findViewById(R.id.file_view_unsupported_container).setVisibility(View.VISIBLE);
String fileNameString = ""; String fileNameString = "";
if (claim.getFile() != null) { if (claim.getFile() != null && !Helper.isNullOrEmpty(claim.getFile().getDownloadPath())) {
LbryFile lbryFile = claim.getFile(); LbryFile lbryFile = claim.getFile();
File file = new File(lbryFile.getDownloadPath()); File file = new File(lbryFile.getDownloadPath());
fileNameString = String.format("\"%s\" ", file.getName()); fileNameString = String.format("\"%s\" ", file.getName());

View file

@ -585,6 +585,7 @@ public class PublishFormFragment extends BaseFragment implements
private void updateFieldsFromCurrentClaim() { private void updateFieldsFromCurrentClaim() {
if (currentClaim != null && !editFieldsLoaded) { if (currentClaim != null && !editFieldsLoaded) {
Context context = getContext(); Context context = getContext();
try {
Claim.StreamMetadata metadata = (Claim.StreamMetadata) currentClaim.getValue(); Claim.StreamMetadata metadata = (Claim.StreamMetadata) currentClaim.getValue();
uploadedThumbnailUrl = currentClaim.getThumbnailUrl(); uploadedThumbnailUrl = currentClaim.getThumbnailUrl();
if (context != null && !Helper.isNullOrEmpty(uploadedThumbnailUrl)) { if (context != null && !Helper.isNullOrEmpty(uploadedThumbnailUrl)) {
@ -637,6 +638,10 @@ public class PublishFormFragment extends BaseFragment implements
inputAddress.setEnabled(false); inputAddress.setEnabled(false);
editMode = true; editMode = true;
editFieldsLoaded = true; editFieldsLoaded = true;
} catch (ClassCastException ex) {
// invalid claim value type
cancelOnFatalCondition(getString(R.string.publish_invalid_claim_type));
}
} }
} }
@ -1297,8 +1302,11 @@ public class PublishFormFragment extends BaseFragment implements
@Override @Override
public void onFilePicked(String filePath) { public void onFilePicked(String filePath) {
if (Helper.isNullOrEmpty(filePath)) { if (Helper.isNullOrEmpty(filePath)) {
Snackbar.make(getView(), R.string.undetermined_image_filepath, Snackbar.LENGTH_LONG).setBackgroundTint( View view = getView();
ContextCompat.getColor(getContext(), R.color.red)).show(); if (view != null) {
Snackbar.make(view, R.string.undetermined_image_filepath, Snackbar.LENGTH_LONG).
setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show();
}
return; return;
} }

View file

@ -70,8 +70,12 @@ public class EmailVerificationFragment extends Fragment {
inputEmail.setOnFocusChangeListener(new View.OnFocusChangeListener() { inputEmail.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override @Override
public void onFocusChange(View view, boolean hasFocus) { public void onFocusChange(View view, boolean hasFocus) {
try {
String layoutHint = !hasFocus ? "" : getString(R.string.email); String layoutHint = !hasFocus ? "" : getString(R.string.email);
inputLayoutEmail.setHint(layoutHint); inputLayoutEmail.setHint(layoutHint);
} catch (IllegalStateException ex) {
// pass
}
} }
}); });
buttonContinue.setOnClickListener(new View.OnClickListener() { buttonContinue.setOnClickListener(new View.OnClickListener() {
@ -98,9 +102,12 @@ public class EmailVerificationFragment extends Fragment {
private void addEmail() { private void addEmail() {
currentEmail = Helper.getValue(inputEmail.getText()); currentEmail = Helper.getValue(inputEmail.getText());
if (Helper.isNullOrEmpty(currentEmail) || currentEmail.indexOf("@") == -1) { if (Helper.isNullOrEmpty(currentEmail) || !currentEmail.contains("@")) {
Snackbar.make(getView(), R.string.provide_valid_email, Snackbar.LENGTH_LONG). View view = getView();
if (view != null) {
Snackbar.make(view, R.string.provide_valid_email, Snackbar.LENGTH_LONG).
setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show(); setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show();
}
return; return;
} }
@ -136,8 +143,11 @@ public class EmailVerificationFragment extends Fragment {
@Override @Override
public void onError(Exception error) { public void onError(Exception error) {
View view = getView();
if (view != null && error != null) {
Snackbar.make(getView(), error.getMessage(), Snackbar.LENGTH_LONG). Snackbar.make(getView(), error.getMessage(), Snackbar.LENGTH_LONG).
setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show(); setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show();
};
Helper.setViewVisibility(buttonContinue, View.VISIBLE); Helper.setViewVisibility(buttonContinue, View.VISIBLE);
} }
}); });
@ -194,14 +204,20 @@ public class EmailVerificationFragment extends Fragment {
@Override @Override
public void onSuccess() { public void onSuccess() {
Snackbar.make(getView(), R.string.please_follow_instructions, Snackbar.LENGTH_LONG).show(); View view = getView();
if (view != null) {
Snackbar.make(view, R.string.please_follow_instructions, Snackbar.LENGTH_LONG).show();
}
Helper.setViewEnabled(buttonResend, true); Helper.setViewEnabled(buttonResend, true);
} }
@Override @Override
public void onError(Exception error) { public void onError(Exception error) {
Snackbar.make(getView(), error.getMessage(), Snackbar.LENGTH_LONG). View view = getView();
if (view != null && error != null) {
Snackbar.make(view, error.getMessage(), Snackbar.LENGTH_LONG).
setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show(); setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show();
}
Helper.setViewEnabled(buttonResend, true); Helper.setViewEnabled(buttonResend, true);
} }
}); });

View file

@ -409,14 +409,22 @@ public class WalletFragment extends BaseFragment implements SdkStatusListener, W
// wallet_send task // wallet_send task
String recipientAddress = Helper.getValue(inputSendAddress.getText()); String recipientAddress = Helper.getValue(inputSendAddress.getText());
String amountString = Helper.getValue(inputSendAmount.getText()); String amountString = Helper.getValue(inputSendAmount.getText());
String amount = new DecimalFormat(Helper.SDK_AMOUNT_FORMAT, new DecimalFormatSymbols(Locale.US)). String amount = null;
try {
amount = new DecimalFormat(Helper.SDK_AMOUNT_FORMAT, new DecimalFormatSymbols(Locale.US)).
format(new BigDecimal(amountString).doubleValue()); format(new BigDecimal(amountString).doubleValue());
} catch (NumberFormatException ex) {
Snackbar.make(getView(), R.string.invalid_amount, Snackbar.LENGTH_LONG).
setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show();
return;
}
disableSendControls(); disableSendControls();
double actualSendAmount = Double.valueOf(amount);
WalletSendTask task = new WalletSendTask(recipientAddress, amount, walletSendProgress, new WalletSendTask.WalletSendHandler() { WalletSendTask task = new WalletSendTask(recipientAddress, amount, walletSendProgress, new WalletSendTask.WalletSendHandler() {
@Override @Override
public void onSuccess() { public void onSuccess() {
double sentAmount = Double.valueOf(amount); double sentAmount = actualSendAmount;
String message = getResources().getQuantityString( String message = getResources().getQuantityString(
R.plurals.you_sent_credits, sentAmount == 1.0 ? 1 : 2, R.plurals.you_sent_credits, sentAmount == 1.0 ? 1 : 2,
new DecimalFormat("#,###.##").format(sentAmount)); new DecimalFormat("#,###.##").format(sentAmount));
@ -530,8 +538,11 @@ public class WalletFragment extends BaseFragment implements SdkStatusListener, W
} }
@Override @Override
public void onSuccess(String newAddress) { public void onSuccess(String newAddress) {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext()); Context context = getContext();
if (context != null) {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
sp.edit().putString(MainActivity.PREFERENCE_KEY_INTERNAL_WALLET_RECEIVE_ADDRESS, newAddress).apply(); sp.edit().putString(MainActivity.PREFERENCE_KEY_INTERNAL_WALLET_RECEIVE_ADDRESS, newAddress).apply();
}
Helper.setViewText(textWalletReceiveAddress, newAddress); Helper.setViewText(textWalletReceiveAddress, newAddress);
Helper.setViewEnabled(buttonGetNewAddress, true); Helper.setViewEnabled(buttonGetNewAddress, true);
} }

View file

@ -66,6 +66,10 @@ public class LbryUri {
REGEX_PART_MODIFIER_SEPARATOR)); REGEX_PART_MODIFIER_SEPARATOR));
String cleanUrl = url, queryString = null; String cleanUrl = url, queryString = null;
if (Helper.isNullOrEmpty(url)) {
throw new LbryUriException("Invalid url parameter.");
}
Matcher qsMatcher = PATTERN_SEPARATE_QUERY_STRING.matcher(url); Matcher qsMatcher = PATTERN_SEPARATE_QUERY_STRING.matcher(url);
if (qsMatcher.matches()) { if (qsMatcher.matches()) {
queryString = qsMatcher.group(2); queryString = qsMatcher.group(2);

View file

@ -87,6 +87,7 @@
<string name="please_select_channel">Please select a channel to post your comment as.</string> <string name="please_select_channel">Please select a channel to post your comment as.</string>
<string name="post_comment">Post comment with tip?</string> <string name="post_comment">Post comment with tip?</string>
<string name="comment_posted">Your comment was successfully posted.</string> <string name="comment_posted">Your comment was successfully posted.</string>
<string name="please_select_repost_channel">Please select a channel to repost on.</string>
<plurals name="post_for_credits"> <plurals name="post_for_credits">
<item quantity="one">Post for %1$s credit</item> <item quantity="one">Post for %1$s credit</item>
<item quantity="other">Post for %1$s credits</item> <item quantity="other">Post for %1$s credits</item>
@ -137,6 +138,7 @@
<string name="show_extra_fields">Show extra fields</string> <string name="show_extra_fields">Show extra fields</string>
<string name="hide_extra_fields">Hide extra fields</string> <string name="hide_extra_fields">Hide extra fields</string>
<string name="no_file_found">No file found to publish.</string> <string name="no_file_found">No file found to publish.</string>
<string name="publish_invalid_claim_type">Invalid claim specified for editing.</string>
<string name="video_optimization">Video optimization</string> <string name="video_optimization">Video optimization</string>
<string name="thumbnail_creation_failed">A thumbnail could not be automatically created from your content file.</string> <string name="thumbnail_creation_failed">A thumbnail could not be automatically created from your content file.</string>
<string name="video_being_optimized">Your video is being optimized for better support on a wide range of devices. You can fill out the remaining fields below while this is in progress.</string> <string name="video_being_optimized">Your video is being optimized for better support on a wide range of devices. You can fill out the remaining fields below while this is in progress.</string>
@ -405,6 +407,7 @@
<string name="verify">Verify</string> <string name="verify">Verify</string>
<string name="please_enter_valid_phone">Please enter a valid phone number.</string> <string name="please_enter_valid_phone">Please enter a valid phone number.</string>
<string name="please_enter_verification_code">Please enter the verification code sent to your phone number.</string> <string name="please_enter_verification_code">Please enter the verification code sent to your phone number.</string>
<string name="fetch_current_user_error">User account could not be retrieved at this time. Please try again later.</string>
<!-- Forms --> <!-- Forms -->
<string name="no_added_tags">You have not added any tags yet. Add tags to improve discovery.</string> <string name="no_added_tags">You have not added any tags yet. Add tags to improve discovery.</string>