fix crash bugs reported in Play Store

This commit is contained in:
Akinwale Ariwodola 2020-05-24 10:11:31 +01:00
parent 52cfe8dc12
commit b60b5d16c3
12 changed files with 108 additions and 66 deletions

View file

@ -63,6 +63,7 @@ dependencies {
implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0' implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'
implementation 'androidx.preference:preference:1.1.1' implementation 'androidx.preference:preference:1.1.1'
implementation 'androidx.webkit:webkit:1.3.0-alpha02' implementation 'androidx.webkit:webkit:1.3.0-alpha02'
implementation 'androidx.camera:camera-core:1.0.0-beta03'
implementation 'androidx.camera:camera-camera2:1.0.0-beta03' implementation 'androidx.camera:camera-camera2:1.0.0-beta03'
implementation 'androidx.camera:camera-lifecycle:1.0.0-beta03' implementation 'androidx.camera:camera-lifecycle:1.0.0-beta03'
implementation 'androidx.camera:camera-view:1.0.0-alpha10' implementation 'androidx.camera:camera-view:1.0.0-alpha10'

View file

@ -84,9 +84,13 @@ public class MergeSubscriptionsTask extends AsyncTask<Void, Void, List<Subscript
try { try {
LbryUri uri = LbryUri.parse(local.getUrl()); LbryUri uri = LbryUri.parse(local.getUrl());
Map<String, String> options = new HashMap<>(); Map<String, String> options = new HashMap<>();
options.put("claim_id", uri.getChannelClaimId()); String channelClaimId = uri.getChannelClaimId();
options.put("channel_name", Helper.normalizeChannelName(local.getChannelName())); String channelName = Helper.normalizeChannelName(local.getChannelName());
Lbryio.parseResponse(Lbryio.call("subscription", "new", options, context)); if (!Helper.isNullOrEmpty(channelClaimId) && !Helper.isNullOrEmpty(channelName)) {
options.put("claim_id", channelClaimId);
options.put("channel_name", channelName);
Lbryio.parseResponse(Lbryio.call("subscription", "new", options, context));
}
} catch (LbryUriException | LbryioRequestException | LbryioResponseException ex) { } catch (LbryUriException | LbryioRequestException | LbryioResponseException ex) {
// pass // pass
Log.e(TAG, String.format("subscription/new failed: %s", ex.getMessage()), ex); Log.e(TAG, String.format("subscription/new failed: %s", ex.getMessage()), ex);

View file

@ -62,7 +62,8 @@ public class ClaimListTask extends AsyncTask<Void, Void, List<Claim>> {
Helper.setViewVisibility(progressView, View.GONE); Helper.setViewVisibility(progressView, View.GONE);
if (handler != null) { if (handler != null) {
if (claims != null) { if (claims != null) {
handler.onSuccess(claims); // TODO: Add fix for handling invalid reposts in ClaimListAdapter
handler.onSuccess(Helper.filterInvalidReposts(claims));
} else { } else {
handler.onError(error); handler.onError(error);
} }

View file

@ -29,7 +29,7 @@ public class ClaimSearchTask extends AsyncTask<Void, Void, List<Claim>> {
} }
protected List<Claim> doInBackground(Void... params) { protected List<Claim> doInBackground(Void... params) {
try { try {
return Helper.filterInvalidReposts(Lbry.claimSearch(options, connectionString)); return Lbry.claimSearch(options, connectionString);
} catch (ApiCallException ex) { } catch (ApiCallException ex) {
error = ex; error = ex;
return null; return null;
@ -39,7 +39,7 @@ public class ClaimSearchTask extends AsyncTask<Void, Void, List<Claim>> {
Helper.setViewVisibility(progressView, View.GONE); Helper.setViewVisibility(progressView, View.GONE);
if (handler != null) { if (handler != null) {
if (claims != null) { if (claims != null) {
handler.onSuccess(claims, claims.size() < Helper.parseInt(options.get("page_size"), 0)); handler.onSuccess(Helper.filterInvalidReposts(claims), claims.size() < Helper.parseInt(options.get("page_size"), 0));
} else { } else {
handler.onError(error); handler.onError(error);
} }

View file

@ -105,7 +105,7 @@ public class LoadSharedUserStateTask extends AsyncTask<Void, Void, Boolean> {
if (db != null) { if (db != null) {
DatabaseHelper.createOrUpdateTag(tag, db); DatabaseHelper.createOrUpdateTag(tag, db);
} }
} catch (SQLiteException ex) { } catch (SQLiteException | IllegalStateException ex) {
// pass // pass
} }
} }

View file

@ -322,19 +322,21 @@ public class ChannelFragment extends BaseFragment implements FetchChannelsListen
boolean updateRequired = false; boolean updateRequired = false;
Map<String, Object> params = getParams(); Map<String, Object> params = getParams();
if (params.containsKey("claim")) { if (params != null) {
Claim claim = (Claim) params.get("claim"); if (params.containsKey("claim")) {
if (claim != null && !claim.equals(this.claim)) { Claim claim = (Claim) params.get("claim");
this.claim = claim; if (claim != null && !claim.equals(this.claim)) {
updateRequired = true; this.claim = claim;
updateRequired = true;
}
} }
} if (params.containsKey("url")) {
if (params.containsKey("url")) { String newUrl = params.get("url").toString();
String newUrl = params.get("url").toString(); if (claim == null || !newUrl.equalsIgnoreCase(url)) {
if (claim == null || !newUrl.equalsIgnoreCase(url)) { this.claim = null;
this.claim = null; this.url = newUrl;
this.url = newUrl; updateRequired = true;
updateRequired = true; }
} }
} }

View file

@ -1104,7 +1104,9 @@ public class FileViewFragment extends BaseFragment implements
@Override @Override
public void onError(Exception error) { public void onError(Exception error) {
actionDelete.setEnabled(true); actionDelete.setEnabled(true);
showError(error.getMessage()); if (error != null) {
showError(error.getMessage());
}
} }
}); });
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
@ -2055,17 +2057,23 @@ public class FileViewFragment extends BaseFragment implements
if (claim != null) { if (claim != null) {
claim.setFile(null); claim.setFile(null);
} }
((ImageView) getView().findViewById(R.id.file_view_action_download_icon)).setImageResource(R.drawable.ic_download); View root = getView();
Helper.setViewVisibility(getView().findViewById(R.id.file_view_download_progress), View.GONE); if (root != null) {
Helper.setViewVisibility(getView().findViewById(R.id.file_view_unsupported_container), View.GONE); ((ImageView) root.findViewById(R.id.file_view_action_download_icon)).setImageResource(R.drawable.ic_download);
Helper.setViewVisibility(root.findViewById(R.id.file_view_download_progress), View.GONE);
Helper.setViewVisibility(root.findViewById(R.id.file_view_unsupported_container), View.GONE);
}
checkIsFileComplete(); checkIsFileComplete();
restoreMainActionButton(); restoreMainActionButton();
} }
private void restoreMainActionButton() { private void restoreMainActionButton() {
getView().findViewById(R.id.file_view_main_action_loading).setVisibility(View.INVISIBLE); View root = getView();
getView().findViewById(R.id.file_view_main_action_button).setVisibility(View.VISIBLE); if (root != null) {
root.findViewById(R.id.file_view_main_action_loading).setVisibility(View.INVISIBLE);
root.findViewById(R.id.file_view_main_action_button).setVisibility(View.VISIBLE);
}
} }
@Override @Override

View file

@ -524,8 +524,9 @@ public class FollowingFragment extends BaseFragment implements
} }
private void updateChannelFilterListAdapter(List<Claim> resolvedSubs, boolean reset) { private void updateChannelFilterListAdapter(List<Claim> resolvedSubs, boolean reset) {
if (channelFilterListAdapter == null) { Context context = getContext();
channelFilterListAdapter = new ChannelFilterListAdapter(getContext()); if (channelFilterListAdapter == null && context != null) {
channelFilterListAdapter = new ChannelFilterListAdapter(context);
channelFilterListAdapter.setListener(new ChannelItemSelectionListener() { channelFilterListAdapter.setListener(new ChannelItemSelectionListener() {
@Override @Override
public void onChannelItemSelected(Claim claim) { public void onChannelItemSelected(Claim claim) {
@ -560,14 +561,16 @@ public class FollowingFragment extends BaseFragment implements
}); });
} }
if (horizontalChannelList != null && horizontalChannelList.getAdapter() == null) { if (channelFilterListAdapter != null) {
horizontalChannelList.setAdapter(channelFilterListAdapter); if (horizontalChannelList != null && horizontalChannelList.getAdapter() == null) {
horizontalChannelList.setAdapter(channelFilterListAdapter);
}
if (reset) {
channelFilterListAdapter.clearClaims();
channelFilterListAdapter.setSelectedItem(null);
}
channelFilterListAdapter.addClaims(resolvedSubs);
} }
if (reset) {
channelFilterListAdapter.clearClaims();
channelFilterListAdapter.setSelectedItem(null);
}
channelFilterListAdapter.addClaims(resolvedSubs);
} }
private void fetchClaimSearchContent() { private void fetchClaimSearchContent() {
@ -626,11 +629,12 @@ public class FollowingFragment extends BaseFragment implements
} }
private void updateSuggestedDoneButtonText() { private void updateSuggestedDoneButtonText() {
int selected = suggestedChannelAdapter == null ? 0 : suggestedChannelAdapter.getSelectedCount(); Context context = getContext();
int remaining = MIN_SUGGESTED_SUBSCRIBE_COUNT - selected; if (context != null) {
String buttonText = remaining <= 0 ? getString(R.string.done) : getString(R.string.n_remaining, remaining); int selected = suggestedChannelAdapter == null ? 0 : suggestedChannelAdapter.getSelectedCount();
if (suggestedDoneButton != null) { int remaining = MIN_SUGGESTED_SUBSCRIBE_COUNT - selected;
suggestedDoneButton.setText(buttonText); String buttonText = remaining <= 0 ? getString(R.string.done) : getString(R.string.n_remaining, remaining);
Helper.setViewText(suggestedDoneButton, buttonText);
} }
} }

View file

@ -239,31 +239,36 @@ public class SearchFragment extends BaseFragment implements
public void onSuccess(List<Claim> claims, boolean hasReachedEnd) { public void onSuccess(List<Claim> claims, boolean hasReachedEnd) {
contentHasReachedEnd = hasReachedEnd; contentHasReachedEnd = hasReachedEnd;
searchLoading = false; searchLoading = false;
Context context = getContext();
if (resultListAdapter == null) { if (context != null) {
resultListAdapter = new ClaimListAdapter(claims, getContext()); if (resultListAdapter == null) {
resultListAdapter.addFeaturedItem(buildFeaturedItem(query)); resultListAdapter = new ClaimListAdapter(claims, context);
resolveFeaturedItem(buildVanityUrl(query)); resultListAdapter.addFeaturedItem(buildFeaturedItem(query));
resultListAdapter.setListener(SearchFragment.this); resolveFeaturedItem(buildVanityUrl(query));
if (resultList != null) { resultListAdapter.setListener(SearchFragment.this);
resultList.setAdapter(resultListAdapter); if (resultList != null) {
resultList.setAdapter(resultListAdapter);
}
} else {
resultListAdapter.addItems(claims);
} }
} else {
resultListAdapter.addItems(claims);
}
int itemCount = resultListAdapter.getItemCount(); int itemCount = resultListAdapter.getItemCount();
noQueryView.setVisibility(View.GONE); Helper.setViewVisibility(noQueryView, View.GONE);
noResultsView.setVisibility(itemCount == 0 ? View.VISIBLE : View.GONE); Helper.setViewVisibility(noResultsView, itemCount == 0 ? View.VISIBLE : View.GONE);
noResultsView.setText(getString(R.string.search_no_results, currentQuery)); Helper.setViewText(noResultsView, getString(R.string.search_no_results, currentQuery));
}
} }
@Override @Override
public void onError(Exception error) { public void onError(Exception error) {
Context context = getContext();
int itemCount = resultListAdapter == null ? 0 : resultListAdapter.getItemCount(); int itemCount = resultListAdapter == null ? 0 : resultListAdapter.getItemCount();
noQueryView.setVisibility(View.GONE); Helper.setViewVisibility(noQueryView, View.GONE);
noResultsView.setVisibility(itemCount == 0 ? View.VISIBLE : View.GONE); Helper.setViewVisibility(noResultsView, itemCount == 0 ? View.VISIBLE : View.GONE);
noResultsView.setText(getString(R.string.search_no_results, currentQuery)); if (context != null) {
Helper.setViewText(noResultsView, getString(R.string.search_no_results, currentQuery));
}
searchLoading = false; searchLoading = false;
} }
}); });

View file

@ -52,6 +52,7 @@ import io.lbry.browser.utils.LbryAnalytics;
public class PublishFragment extends BaseFragment implements public class PublishFragment extends BaseFragment implements
CameraPermissionListener, FilePickerListener, StoragePermissionListener { CameraPermissionListener, FilePickerListener, StoragePermissionListener {
private boolean cameraPreviewInitialized;
private PreviewView cameraPreview; private PreviewView cameraPreview;
private RecyclerView galleryGrid; private RecyclerView galleryGrid;
private GalleryGridAdapter adapter; private GalleryGridAdapter adapter;
@ -122,7 +123,7 @@ public class PublishFragment extends BaseFragment implements
private void displayPreviewWithCameraX() { private void displayPreviewWithCameraX() {
Context context = getContext(); Context context = getContext();
if (context != null) { if (context != null && MainActivity.hasPermission(Manifest.permission.CAMERA, context)) {
cameraProviderFuture = ProcessCameraProvider.getInstance(context); cameraProviderFuture = ProcessCameraProvider.getInstance(context);
cameraProviderFuture.addListener(new Runnable() { cameraProviderFuture.addListener(new Runnable() {
@Override @Override
@ -137,6 +138,7 @@ public class PublishFragment extends BaseFragment implements
Camera camera = cameraProvider.bindToLifecycle((LifecycleOwner) context, cameraSelector, preview); Camera camera = cameraProvider.bindToLifecycle((LifecycleOwner) context, cameraSelector, preview);
preview.setSurfaceProvider(cameraPreview.createSurfaceProvider(camera.getCameraInfo())); preview.setSurfaceProvider(cameraPreview.createSurfaceProvider(camera.getCameraInfo()));
cameraPreviewInitialized = true;
} }
} catch (ExecutionException | InterruptedException ex) { } catch (ExecutionException | InterruptedException ex) {
// pass // pass
@ -267,7 +269,9 @@ public class PublishFragment extends BaseFragment implements
activity.removeFilePickerListener(this); activity.removeFilePickerListener(this);
} }
} }
CameraX.unbindAll(); if (cameraPreviewInitialized) {
CameraX.unbindAll();
}
super.onStop(); super.onStop();
} }
@ -361,13 +365,13 @@ public class PublishFragment extends BaseFragment implements
public void onCameraPermissionRefused() { public void onCameraPermissionRefused() {
if (takePhotoPending) { if (takePhotoPending) {
takePhotoPending = false; takePhotoPending = false;
Snackbar.make(getView(), R.string.camera_permission_rationale_photo, Toast.LENGTH_LONG). Snackbar.make(getView(), R.string.camera_permission_rationale_photo, Snackbar.LENGTH_LONG).
setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show(); setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show();
return; return;
} }
recordPending = false; recordPending = false;
Snackbar.make(getView(), R.string.camera_permission_rationale_record, Toast.LENGTH_LONG). Snackbar.make(getView(), R.string.camera_permission_rationale_record, Snackbar.LENGTH_LONG).
setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show(); setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show();
} }
@ -395,9 +399,8 @@ public class PublishFragment extends BaseFragment implements
@Override @Override
public void onStoragePermissionRefused() { public void onStoragePermissionRefused() {
Snackbar.make(getView(), R.string.storage_permission_rationale_videos, Snackbar.LENGTH_LONG).setBackgroundTint( Snackbar.make(getView(), R.string.storage_permission_rationale_videos, Snackbar.LENGTH_LONG).
ContextCompat.getColor(getContext(), R.color.red) setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show();
).show();
} }
public String getSuggestedPublishUrl() { public String getSuggestedPublishUrl() {

View file

@ -705,6 +705,9 @@ public final class Helper {
} }
} }
public static String normalizeChannelName(String channelName) { public static String normalizeChannelName(String channelName) {
if (Helper.isNullOrEmpty(channelName)) {
return "";
}
if (!channelName.startsWith("@")) { if (!channelName.startsWith("@")) {
return String.format("@%s", channelName); return String.format("@%s", channelName);
} }

View file

@ -32,8 +32,17 @@ public class LbryAnalytics {
analytics = FirebaseAnalytics.getInstance(context); analytics = FirebaseAnalytics.getInstance(context);
} }
public static void checkInitAnalytics(Context context) {
if (analytics == null && context != null) {
analytics = FirebaseAnalytics.getInstance(context);
}
}
public static void setCurrentScreen(Activity activity, String name, String className) { public static void setCurrentScreen(Activity activity, String name, String className) {
analytics.setCurrentScreen(activity, name, className); checkInitAnalytics(activity);
if (analytics != null) {
analytics.setCurrentScreen(activity, name, className);
}
} }
public static void logEvent(String name) { public static void logEvent(String name) {
@ -41,7 +50,9 @@ public class LbryAnalytics {
} }
public static void logEvent(String name, Bundle bundle) { public static void logEvent(String name, Bundle bundle) {
analytics.logEvent(name, bundle); if (analytics != null) {
analytics.logEvent(name, bundle);
}
} }
public static void logException(String message, String exceptionName) { public static void logException(String message, String exceptionName) {