Skip to content

Commit

Permalink
PR cleanup (lbryio#1164)
Browse files Browse the repository at this point in the history
* simplify code for readability
* code-cleanup. Make non-changing variables final
* Bump buildToolsVersion 29.0.1 -> 29.0.2 for FDroid build compability
* Set gradle version to static 3.6.4 instead of dynamic 3.+
* Use StandardCharsets.UTF_8 instead of string UTF8
* Remove unused imports
* Add missing null check

Co-authored-by: Patric Karlström <patric@pkcab.eu>
  • Loading branch information
akinwale and pakar1 authored Mar 8, 2021
1 parent e9d70db commit a655d01
Show file tree
Hide file tree
Showing 130 changed files with 493 additions and 585 deletions.
3 changes: 1 addition & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apply plugin: 'com.android.application'

android {
compileSdkVersion 29
buildToolsVersion "29.0.1"
buildToolsVersion "29.0.2"
flavorDimensions "default"

compileOptions {
Expand All @@ -18,7 +18,6 @@ android {
targetSdkVersion 29
versionCode 1614
versionName "0.16.14"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/io/lbry/browser/FirstRunActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ private void generateIdAndAuthenticate() {
}

private static class CheckInstallIdTask extends AsyncTask<Void, Void, Boolean> {
private Context context;
private InstallIdHandler handler;
private final Context context;
private final InstallIdHandler handler;
public CheckInstallIdTask(Context context, InstallIdHandler handler) {
this.context = context;
this.handler = handler;
Expand Down Expand Up @@ -236,7 +236,7 @@ public interface InstallIdHandler {
}

private static class AuthenticateTask extends AsyncTask<Void, Void, Void> {
private Context context;
private final Context context;
public AuthenticateTask(Context context) {
this.context = context;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void onMessageReceived(RemoteMessage remoteMessage) {
String name = payload.get("name"); // notification name
String hash = payload.get("hash"); // comment hash

if (type != null && getEnabledTypes().indexOf(type) > -1 && body != null && body.trim().length() > 0) {
if (type != null && getEnabledTypes().contains(type) && body != null && body.trim().length() > 0) {
// only log the receive event for valid notifications received
if (firebaseAnalytics != null) {
Bundle bundle = new Bundle();
Expand Down
22 changes: 11 additions & 11 deletions app/src/main/java/io/lbry/browser/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
import java.io.PrintStream;
import java.net.ConnectException;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -262,7 +263,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
public static boolean startingFilePickerActivity = false;
public static boolean startingShareActivity = false;
public static boolean startingPermissionRequest = false;
public static boolean startingSignInFlowActivity = false;
public static final boolean startingSignInFlowActivity = false;

private ActionMode actionMode;
private BillingClient billingClient;
Expand Down Expand Up @@ -406,7 +407,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
private List<FetchClaimsListener> fetchClaimsListeners;
private List<FetchChannelsListener> fetchChannelsListeners;
@Getter
private ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
private boolean walletBalanceUpdateScheduled;
private boolean shouldOpenUserSelectedMenuItem;
private boolean walletSyncScheduled;
Expand Down Expand Up @@ -842,9 +843,7 @@ public void translateFloatingWallet(float initialY) {

public void removeNavFragment(Class fragmentClass, int navItemId) {
String key = buildNavFragmentKey(fragmentClass, navItemId, null);
if (openNavFragments.containsKey(key)) {
openNavFragments.remove(key);
}
openNavFragments.remove(key);
}

public void addFetchChannelsListener(FetchChannelsListener listener) {
Expand Down Expand Up @@ -1038,7 +1037,7 @@ public void openRewards() {
openFragment(RewardsFragment.class, true, NavMenuItem.ID_ITEM_REWARDS);
}

private FragmentManager.OnBackStackChangedListener backStackChangedListener = new FragmentManager.OnBackStackChangedListener() {
private final FragmentManager.OnBackStackChangedListener backStackChangedListener = new FragmentManager.OnBackStackChangedListener() {
@Override
public void onBackStackChanged() {
FragmentManager manager = getSupportFragmentManager();
Expand Down Expand Up @@ -1865,7 +1864,7 @@ private void loadAuthToken() {
if (!Helper.isNullOrEmpty(encryptedAuthToken)) {
try {
Lbryio.AUTH_TOKEN = new String(Utils.decrypt(
Base64.decode(encryptedAuthToken, Base64.NO_WRAP), this, Lbry.KEYSTORE), "UTF8");
Base64.decode(encryptedAuthToken, Base64.NO_WRAP), this, Lbry.KEYSTORE), StandardCharsets.UTF_8);
} catch (Exception ex) {
// pass. A new auth token would have to be generated if the old one cannot be decrypted
Log.e(TAG, "Could not decrypt existing auth token.", ex);
Expand Down Expand Up @@ -3065,10 +3064,11 @@ private void checkUrlIntent(Intent intent) {
} else {
try {
LbryUri uri = LbryUri.parse(url);
String checkedURL = url.startsWith(LbryUri.PROTO_DEFAULT) ? url : uri.toString();
if (uri.isChannel()) {
openChannelUrl(url.startsWith(LbryUri.PROTO_DEFAULT) ? url : uri.toString());
openChannelUrl(checkedURL);
} else {
openFileUrl(url.startsWith(LbryUri.PROTO_DEFAULT) ? url : uri.toString());
openFileUrl(checkedURL);
}
} catch (LbryUriException ex) {
// pass
Expand Down Expand Up @@ -3324,8 +3324,8 @@ public void clearNowPlayingClaim() {
}

private static class CheckSdkReadyTask extends AsyncTask<Void, Void, Boolean> {
private Context context;
private List<SdkStatusListener> listeners;
private final Context context;
private final List<SdkStatusListener> listeners;

public CheckSdkReadyTask(Context context, List<SdkStatusListener> listeners) {
this.context = context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class VerificationActivity extends FragmentActivity implements SignInList
private boolean signedIn;
private int flow;

private PurchasesUpdatedListener purchasesUpdatedListener = new PurchasesUpdatedListener() {
private final PurchasesUpdatedListener purchasesUpdatedListener = new PurchasesUpdatedListener() {
@Override
public void onPurchasesUpdated(@NonNull BillingResult billingResult, @Nullable List<Purchase> purchases) {
int responseCode = billingResult.getResponseCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import lombok.Setter;

public class ChannelFilterListAdapter extends RecyclerView.Adapter<ChannelFilterListAdapter.ViewHolder> {
private Context context;
private final Context context;
private List<Claim> items;
@Getter
@Setter
Expand All @@ -42,12 +42,12 @@ public ChannelFilterListAdapter(Context context) {
}

public static class ViewHolder extends RecyclerView.ViewHolder {
protected View mediaContainer;
protected View alphaContainer;
protected View allView;
protected ImageView thumbnailView;
protected TextView alphaView;
protected TextView titleView;
protected final View mediaContainer;
protected final View alphaContainer;
protected final View allView;
protected final ImageView thumbnailView;
protected final TextView alphaView;
protected final TextView titleView;
public ViewHolder(View v) {
super(v);
mediaContainer = v.findViewById(R.id.channel_filter_media_container);
Expand Down
55 changes: 27 additions & 28 deletions app/src/main/java/io/lbry/browser/adapter/ClaimListAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.util.List;
import java.util.Map;

import io.lbry.browser.MainActivity;
import io.lbry.browser.R;
import io.lbry.browser.listener.SelectionModeListener;
import io.lbry.browser.model.Claim;
Expand All @@ -37,18 +36,18 @@ public class ClaimListAdapter extends RecyclerView.Adapter<ClaimListAdapter.View
private static final int VIEW_TYPE_CHANNEL = 2;
private static final int VIEW_TYPE_FEATURED = 3; // featured search result

private Map<String, Claim> quickClaimIdMap;
private Map<String, Claim> quickClaimUrlMap;
private Map<String, Boolean> notFoundClaimIdMap;
private Map<String, Boolean> notFoundClaimUrlMap;
private final Map<String, Claim> quickClaimIdMap;
private final Map<String, Claim> quickClaimUrlMap;
private final Map<String, Boolean> notFoundClaimIdMap;
private final Map<String, Boolean> notFoundClaimUrlMap;

@Setter
private boolean hideFee;
@Setter
private boolean canEnterSelectionMode;
private Context context;
private final Context context;
private List<Claim> items;
private List<Claim> selectedItems;
private final List<Claim> selectedItems;
@Setter
private ClaimListItemListener listener;
@Getter
Expand Down Expand Up @@ -176,27 +175,27 @@ public void removeItem(Claim claim) {
}

public static class ViewHolder extends RecyclerView.ViewHolder {
protected View feeContainer;
protected TextView feeView;
protected ImageView thumbnailView;
protected View noThumbnailView;
protected TextView alphaView;
protected TextView vanityUrlView;
protected TextView durationView;
protected TextView titleView;
protected TextView publisherView;
protected TextView publishTimeView;
protected TextView pendingTextView;
protected View repostInfoView;
protected TextView repostChannelView;
protected View selectedOverlayView;
protected TextView fileSizeView;
protected ProgressBar downloadProgressView;
protected TextView deviceView;

protected View loadingImagePlaceholder;
protected View loadingTextPlaceholder1;
protected View loadingTextPlaceholder2;
protected final View feeContainer;
protected final TextView feeView;
protected final ImageView thumbnailView;
protected final View noThumbnailView;
protected final TextView alphaView;
protected final TextView vanityUrlView;
protected final TextView durationView;
protected final TextView titleView;
protected final TextView publisherView;
protected final TextView publishTimeView;
protected final TextView pendingTextView;
protected final View repostInfoView;
protected final TextView repostChannelView;
protected final View selectedOverlayView;
protected final TextView fileSizeView;
protected final ProgressBar downloadProgressView;
protected final TextView deviceView;

protected final View loadingImagePlaceholder;
protected final View loadingTextPlaceholder1;
protected final View loadingTextPlaceholder2;
public ViewHolder(View v) {
super(v);
feeContainer = v.findViewById(R.id.claim_fee_container);
Expand Down
22 changes: 11 additions & 11 deletions app/src/main/java/io/lbry/browser/adapter/CommentListAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
import lombok.Setter;

public class CommentListAdapter extends RecyclerView.Adapter<CommentListAdapter.ViewHolder> {
private List<Comment> items;
private Context context;
private boolean nested;
private final List<Comment> items;
private final Context context;
private final boolean nested;
private float scale;
@Setter
private ClaimListAdapter.ClaimListItemListener listener;
Expand Down Expand Up @@ -102,14 +102,14 @@ public List<String> getClaimUrlsToResolve() {
}

public static class ViewHolder extends RecyclerView.ViewHolder {
protected TextView channelName;
protected TextView commentText;
protected ImageView thumbnailView;
protected View noThumbnailView;
protected TextView alphaView;
protected TextView commentTimeView;
protected View replyLink;
protected RecyclerView repliesList;
protected final TextView channelName;
protected final TextView commentText;
protected final ImageView thumbnailView;
protected final View noThumbnailView;
protected final TextView alphaView;
protected final TextView commentTimeView;
protected final View replyLink;
protected final RecyclerView repliesList;

public ViewHolder (View v) {
super(v);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public class EditorsChoiceItemAdapter extends RecyclerView.Adapter<EditorsChoice
private static final int VIEW_TYPE_HEADER = 1;
private static final int VIEW_TYPE_CONTENT = 2;

private Context context;
private List<EditorsChoiceItem> items;
private final Context context;
private final List<EditorsChoiceItem> items;
@Setter
private EditorsChoiceItemListener listener;

Expand All @@ -48,11 +48,11 @@ public void addItems(List<EditorsChoiceItem> items) {
}

public static class ViewHolder extends RecyclerView.ViewHolder {
protected ImageView thumbnailView;
protected TextView descriptionView;
protected TextView headerView;
protected TextView titleView;
protected View cardView;
protected final ImageView thumbnailView;
protected final TextView descriptionView;
protected final TextView headerView;
protected final TextView titleView;
protected final View cardView;

public ViewHolder(View v) {
super(v);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import lombok.Setter;

public class GalleryGridAdapter extends RecyclerView.Adapter<GalleryGridAdapter.ViewHolder> {
private Context context;
private List<GalleryItem> items;
private final Context context;
private final List<GalleryItem> items;
@Setter
private GalleryItemClickListener listener;

Expand All @@ -32,8 +32,8 @@ public GalleryGridAdapter(List<GalleryItem> items, Context context) {
}

public static class ViewHolder extends RecyclerView.ViewHolder {
protected ImageView thumbnailView;
protected TextView durationView;
protected final ImageView thumbnailView;
protected final TextView durationView;
public ViewHolder(View v) {
super(v);
thumbnailView = v.findViewById(R.id.gallery_item_thumbnail);
Expand Down Expand Up @@ -96,8 +96,8 @@ public interface GalleryItemClickListener {

public static class GalleryGridItemDecoration extends RecyclerView.ItemDecoration {

private int spanCount;
private int spacing;
private final int spanCount;
private final int spacing;

public GalleryGridItemDecoration(int spanCount, int spacing) {
this.spanCount = spanCount;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package io.lbry.browser.adapter;

import android.content.Context;
import android.database.DataSetObserver;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.SpinnerAdapter;
import android.widget.TextView;

import java.util.ArrayList;
Expand All @@ -18,9 +16,9 @@

public class InlineChannelSpinnerAdapter extends ArrayAdapter<Claim> {

private List<Claim> channels;
private int layoutResourceId;
private LayoutInflater inflater;
private final List<Claim> channels;
private final int layoutResourceId;
private final LayoutInflater inflater;

public InlineChannelSpinnerAdapter(Context context, int resource, List<Claim> channels) {
super(context, resource, 0, channels);
Expand Down
Loading

0 comments on commit a655d01

Please sign in to comment.