Merge pull request #921 from lbryio/crash-fixes

fixes for Play Store crash reports
This commit is contained in:
Akinwale Ariwodola 2020-05-31 16:20:59 +01:00 committed by GitHub
commit e85ca9114c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 193 additions and 109 deletions

View file

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

View file

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

View file

@ -231,6 +231,11 @@ public class RepostClaimDialogFragment extends BottomSheetDialogFragment impleme
}
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() {
@Override
public void beforeStart() {
@ -256,10 +261,13 @@ public class RepostClaimDialogFragment extends BottomSheetDialogFragment impleme
}
private void showError(String message) {
Snackbar.make(getView(), message, Snackbar.LENGTH_LONG).
setBackgroundTint(Color.RED).
setTextColor(Color.WHITE).
show();
View view = getView();
if (view != null && !Helper.isNullOrEmpty(message)) {
Snackbar.make(view, message, Snackbar.LENGTH_LONG).
setBackgroundTint(Color.RED).
setTextColor(Color.WHITE).
show();
}
}
private void startLoading() {

View file

@ -91,11 +91,13 @@ public class SendTipDialogFragment extends BottomSheetDialogFragment implements
TextView infoText = view.findViewById(R.id.tip_info);
infoText.setMovementMethod(LinkMovementMethod.getInstance());
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));
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

View file

@ -55,20 +55,22 @@ public class LoadGalleryItemsTask extends AsyncTask<Void, GalleryItem, List<Gall
MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
projection, null, null,
String.format("%s DESC LIMIT 150", MediaStore.MediaColumns.DATE_MODIFIED));
while (cursor.moveToNext()) {
int idColumn = cursor.getColumnIndex(MediaStore.MediaColumns._ID);
int nameColumn = cursor.getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME);
int typeColumn = cursor.getColumnIndex(MediaStore.MediaColumns.MIME_TYPE);
int pathColumn = cursor.getColumnIndex(MediaStore.MediaColumns.DATA);
int durationColumn = cursor.getColumnIndex(MediaStore.Video.Media.DURATION);
if (cursor != null) {
while (cursor.moveToNext()) {
int idColumn = cursor.getColumnIndex(MediaStore.MediaColumns._ID);
int nameColumn = cursor.getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME);
int typeColumn = cursor.getColumnIndex(MediaStore.MediaColumns.MIME_TYPE);
int pathColumn = cursor.getColumnIndex(MediaStore.MediaColumns.DATA);
int durationColumn = cursor.getColumnIndex(MediaStore.Video.Media.DURATION);
GalleryItem item = new GalleryItem();
item.setId(cursor.getString(idColumn));
item.setName(cursor.getString(nameColumn));
item.setType(cursor.getString(typeColumn));
item.setFilePath(cursor.getString(pathColumn));
item.setDuration(cursor.getLong(durationColumn));
items.add(item);
GalleryItem item = new GalleryItem();
item.setId(cursor.getString(idColumn));
item.setName(cursor.getString(nameColumn));
item.setType(cursor.getString(typeColumn));
item.setFilePath(cursor.getString(pathColumn));
item.setDuration(cursor.getLong(durationColumn));
items.add(item);
}
}
} catch (SQLiteException ex) {
// failed to load videos. log and pass

View file

@ -254,7 +254,13 @@ public class ChannelFormFragment extends BaseFragment implements
private void checkParams() {
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");
if (claim != null && !claim.equals(this.currentClaim)) {
this.currentClaim = claim;

View file

@ -780,7 +780,10 @@ public class FileViewFragment extends BaseFragment implements
dialog.setListener(new RepostClaimDialogFragment.RepostClaimListener() {
@Override
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();
@ -1352,7 +1355,7 @@ public class FileViewFragment extends BaseFragment implements
root.findViewById(R.id.file_view_exoplayer_container).setVisibility(View.GONE);
root.findViewById(R.id.file_view_unsupported_container).setVisibility(View.VISIBLE);
String fileNameString = "";
if (claim.getFile() != null) {
if (claim.getFile() != null && !Helper.isNullOrEmpty(claim.getFile().getDownloadPath())) {
LbryFile lbryFile = claim.getFile();
File file = new File(lbryFile.getDownloadPath());
fileNameString = String.format("\"%s\" ", file.getName());

View file

@ -581,58 +581,63 @@ public class PublishFormFragment extends BaseFragment implements
private void updateFieldsFromCurrentClaim() {
if (currentClaim != null && !editFieldsLoaded) {
Context context = getContext();
Claim.StreamMetadata metadata = (Claim.StreamMetadata) currentClaim.getValue();
uploadedThumbnailUrl = currentClaim.getThumbnailUrl();
if (context != null && !Helper.isNullOrEmpty(uploadedThumbnailUrl)) {
Glide.with(context.getApplicationContext()).load(uploadedThumbnailUrl).centerCrop().into(imageThumbnail);
}
inputTitle.setText(currentClaim.getTitle());
inputDescription.setText(currentClaim.getDescription());
if (addedTagsAdapter != null && currentClaim.getTagObjects() != null) {
addedTagsAdapter.addTags(currentClaim.getTagObjects());
updateSuggestedTags(currentFilter, SUGGESTED_LIMIT, true);
}
if (metadata.getFee() != null) {
Fee fee = metadata.getFee();
switchPrice.setChecked(true);
inputPrice.setText(fee.getAmount());
priceCurrencySpinner.setSelection("lbc".equalsIgnoreCase(fee.getCurrency()) ? 0 : 1);
}
inputAddress.setText(currentClaim.getName());
inputDeposit.setText(currentClaim.getAmount());
if (metadata.getLanguages() != null && metadata.getLanguages().size() > 0) {
// get the first language
String langCode = metadata.getLanguages().get(0);
int langCodePosition = ((LanguageSpinnerAdapter) languageSpinner.getAdapter()).getItemPosition(langCode);
if (langCodePosition > -1) {
languageSpinner.setSelection(langCodePosition);
}
}
if (!Helper.isNullOrEmpty(metadata.getLicense())) {
LicenseSpinnerAdapter adapter = (LicenseSpinnerAdapter) licenseSpinner.getAdapter();
int licPosition = adapter.getItemPosition(metadata.getLicense());
if (licPosition == -1) {
licPosition = adapter.getItemPosition(Predefined.LICENSE_OTHER);
}
if (licPosition > -1) {
licenseSpinner.setSelection(licPosition);
try {
Claim.StreamMetadata metadata = (Claim.StreamMetadata) currentClaim.getValue();
uploadedThumbnailUrl = currentClaim.getThumbnailUrl();
if (context != null && !Helper.isNullOrEmpty(uploadedThumbnailUrl)) {
Glide.with(context.getApplicationContext()).load(uploadedThumbnailUrl).centerCrop().into(imageThumbnail);
}
License selectedLicense = (License) licenseSpinner.getSelectedItem();
boolean otherLicense = Arrays.asList(
Predefined.LICENSE_COPYRIGHTED.toLowerCase(),
Predefined.LICENSE_OTHER.toLowerCase()).contains(selectedLicense.getName().toLowerCase());
inputOtherLicenseDescription.setText(otherLicense ? metadata.getLicense() : null);
}
inputTitle.setText(currentClaim.getTitle());
inputDescription.setText(currentClaim.getDescription());
if (addedTagsAdapter != null && currentClaim.getTagObjects() != null) {
addedTagsAdapter.addTags(currentClaim.getTagObjects());
updateSuggestedTags(currentFilter, SUGGESTED_LIMIT, true);
}
inputAddress.setEnabled(false);
editMode = true;
editFieldsLoaded = true;
if (metadata.getFee() != null) {
Fee fee = metadata.getFee();
switchPrice.setChecked(true);
inputPrice.setText(fee.getAmount());
priceCurrencySpinner.setSelection("lbc".equalsIgnoreCase(fee.getCurrency()) ? 0 : 1);
}
inputAddress.setText(currentClaim.getName());
inputDeposit.setText(currentClaim.getAmount());
if (metadata.getLanguages() != null && metadata.getLanguages().size() > 0) {
// get the first language
String langCode = metadata.getLanguages().get(0);
int langCodePosition = ((LanguageSpinnerAdapter) languageSpinner.getAdapter()).getItemPosition(langCode);
if (langCodePosition > -1) {
languageSpinner.setSelection(langCodePosition);
}
}
if (!Helper.isNullOrEmpty(metadata.getLicense())) {
LicenseSpinnerAdapter adapter = (LicenseSpinnerAdapter) licenseSpinner.getAdapter();
int licPosition = adapter.getItemPosition(metadata.getLicense());
if (licPosition == -1) {
licPosition = adapter.getItemPosition(Predefined.LICENSE_OTHER);
}
if (licPosition > -1) {
licenseSpinner.setSelection(licPosition);
}
License selectedLicense = (License) licenseSpinner.getSelectedItem();
boolean otherLicense = Arrays.asList(
Predefined.LICENSE_COPYRIGHTED.toLowerCase(),
Predefined.LICENSE_OTHER.toLowerCase()).contains(selectedLicense.getName().toLowerCase());
inputOtherLicenseDescription.setText(otherLicense ? metadata.getLicense() : null);
}
inputAddress.setEnabled(false);
editMode = true;
editFieldsLoaded = true;
} catch (ClassCastException ex) {
// invalid claim value type
cancelOnFatalCondition(getString(R.string.publish_invalid_claim_type));
}
}
}
@ -1415,8 +1420,11 @@ public class PublishFormFragment extends BaseFragment implements
@Override
public void onFilePicked(String filePath) {
if (Helper.isNullOrEmpty(filePath)) {
Snackbar.make(getView(), R.string.undetermined_image_filepath, Snackbar.LENGTH_LONG).setBackgroundTint(
ContextCompat.getColor(getContext(), R.color.red)).show();
View view = getView();
if (view != null) {
Snackbar.make(view, R.string.undetermined_image_filepath, Snackbar.LENGTH_LONG).
setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show();
}
return;
}

View file

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

View file

@ -409,14 +409,22 @@ public class WalletFragment extends BaseFragment implements SdkStatusListener, W
// wallet_send task
String recipientAddress = Helper.getValue(inputSendAddress.getText());
String amountString = Helper.getValue(inputSendAmount.getText());
String amount = new DecimalFormat(Helper.SDK_AMOUNT_FORMAT, new DecimalFormatSymbols(Locale.US)).
format(new BigDecimal(amountString).doubleValue());
String amount = null;
try {
amount = new DecimalFormat(Helper.SDK_AMOUNT_FORMAT, new DecimalFormatSymbols(Locale.US)).
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();
double actualSendAmount = Double.valueOf(amount);
WalletSendTask task = new WalletSendTask(recipientAddress, amount, walletSendProgress, new WalletSendTask.WalletSendHandler() {
@Override
public void onSuccess() {
double sentAmount = Double.valueOf(amount);
double sentAmount = actualSendAmount;
String message = getResources().getQuantityString(
R.plurals.you_sent_credits, sentAmount == 1.0 ? 1 : 2,
new DecimalFormat("#,###.##").format(sentAmount));
@ -530,8 +538,11 @@ public class WalletFragment extends BaseFragment implements SdkStatusListener, W
}
@Override
public void onSuccess(String newAddress) {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
sp.edit().putString(MainActivity.PREFERENCE_KEY_INTERNAL_WALLET_RECEIVE_ADDRESS, newAddress).apply();
Context context = getContext();
if (context != null) {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
sp.edit().putString(MainActivity.PREFERENCE_KEY_INTERNAL_WALLET_RECEIVE_ADDRESS, newAddress).apply();
}
Helper.setViewText(textWalletReceiveAddress, newAddress);
Helper.setViewEnabled(buttonGetNewAddress, true);
}

View file

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

View file

@ -81,6 +81,7 @@
<string name="confirm_delete_content_message">Are you sure you want to unpublish this content? No files will be removed from your device.</string>
<string name="content_deleted">The content was successfully deleted from the blockchain.</string>
<string name="content_failed_delete">The content could not be deleted at this time. Please try again later.</string>
<string name="please_select_repost_channel">Please select a channel to repost on.</string>
<plurals name="view_count">
<item quantity="one">%1$s view</item>
<item quantity="other">%1$s views</item>
@ -123,6 +124,7 @@
<string name="show_extra_fields">Show 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="publish_invalid_claim_type">Invalid claim specified for editing.</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="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>
@ -391,6 +393,7 @@
<string name="verify">Verify</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="fetch_current_user_error">User account could not be retrieved at this time. Please try again later.</string>
<!-- Forms -->
<string name="no_added_tags">You have not added any tags yet. Add tags to improve discovery.</string>