From 7cf97feb9e606de62913dbb1535c6ad6c129ff03 Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Thu, 14 May 2020 04:14:06 +0100 Subject: [PATCH] fix channel list adapters --- .../java/io/lbry/browser/MainActivity.java | 3 ++- .../dialog/RepostClaimDialogFragment.java | 4 +++- .../browser/ui/wallet/InvitesFragment.java | 20 ++++++++++++------- .../main/java/io/lbry/browser/utils/Lbry.java | 7 +++++++ 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/io/lbry/browser/MainActivity.java b/app/src/main/java/io/lbry/browser/MainActivity.java index 2d11bd13..c59d560b 100644 --- a/app/src/main/java/io/lbry/browser/MainActivity.java +++ b/app/src/main/java/io/lbry/browser/MainActivity.java @@ -1598,6 +1598,8 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener private void startup() { final Context context = this; + Lbry.startupInit(); + // perform some tasks before launching (new AsyncTask() { protected void onPreExecute() { @@ -1638,7 +1640,6 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener throw new Exception("Did not retrieve authenticated user."); } - Lbryio.newInstall(context); // (light) fetch subscriptions diff --git a/app/src/main/java/io/lbry/browser/dialog/RepostClaimDialogFragment.java b/app/src/main/java/io/lbry/browser/dialog/RepostClaimDialogFragment.java index a2d56373..caa02c4d 100644 --- a/app/src/main/java/io/lbry/browser/dialog/RepostClaimDialogFragment.java +++ b/app/src/main/java/io/lbry/browser/dialog/RepostClaimDialogFragment.java @@ -194,13 +194,15 @@ public class RepostClaimDialogFragment extends BottomSheetDialogFragment impleme if (channelSpinnerAdapter == null) { Context context = getContext(); channelSpinnerAdapter = new InlineChannelSpinnerAdapter(context, R.layout.spinner_item_channel, channels); - channelSpinner.setAdapter(channelSpinnerAdapter); channelSpinnerAdapter.notifyDataSetChanged(); } else { channelSpinnerAdapter.clear(); channelSpinnerAdapter.addAll(channels); channelSpinnerAdapter.notifyDataSetChanged(); } + if (channelSpinner != null) { + channelSpinner.setAdapter(channelSpinnerAdapter); + } } @Override diff --git a/app/src/main/java/io/lbry/browser/ui/wallet/InvitesFragment.java b/app/src/main/java/io/lbry/browser/ui/wallet/InvitesFragment.java index 362d809b..ad19fb8f 100644 --- a/app/src/main/java/io/lbry/browser/ui/wallet/InvitesFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/wallet/InvitesFragment.java @@ -198,10 +198,6 @@ public class InvitesFragment extends BaseFragment implements SdkStatusListener, } }); - if (Lbry.ownChannels != null) { - updateChannelList(Lbry.ownChannels); - } - channelSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView adapterView, View view, int position, long l) { @@ -268,9 +264,8 @@ public class InvitesFragment extends BaseFragment implements SdkStatusListener, private void updateChannelList(List channels) { if (channelSpinnerAdapter == null) { Context context = getContext(); - channelSpinnerAdapter = new InlineChannelSpinnerAdapter(context, R.layout.spinner_item_channel, channels); + channelSpinnerAdapter = new InlineChannelSpinnerAdapter(context, R.layout.spinner_item_channel, new ArrayList<>(channels)); channelSpinnerAdapter.addPlaceholder(false); - channelSpinner.setAdapter(channelSpinnerAdapter); channelSpinnerAdapter.notifyDataSetChanged(); } else { channelSpinnerAdapter.clear(); @@ -279,6 +274,10 @@ public class InvitesFragment extends BaseFragment implements SdkStatusListener, channelSpinnerAdapter.notifyDataSetChanged(); } + if (channelSpinner != null) { + channelSpinner.setAdapter(channelSpinnerAdapter); + } + if (channelSpinnerAdapter.getCount() > 1) { channelSpinner.setSelection(1); } @@ -382,6 +381,11 @@ public class InvitesFragment extends BaseFragment implements SdkStatusListener, } private void fetchChannels() { + if (Lbry.ownChannels != null && Lbry.ownChannels.size() > 0) { + updateChannelList(Lbry.ownChannels); + return; + } + fetchingChannels = true; disableChannelSpinner(); ClaimListTask task = new ClaimListTask(Claim.TYPE_CHANNEL, progressLoadingChannels, new ClaimListResultHandler() { @@ -413,10 +417,12 @@ public class InvitesFragment extends BaseFragment implements SdkStatusListener, if (inviteHistoryAdapter == null) { inviteHistoryAdapter = new InviteeListAdapter(invitees, getContext()); inviteHistoryAdapter.addHeader(); - inviteHistoryList.setAdapter(inviteHistoryAdapter); } else { inviteHistoryAdapter.addInvitees(invitees); } + if (inviteHistoryList != null) { + inviteHistoryList.setAdapter(inviteHistoryAdapter); + } Helper.setViewVisibility(inviteHistoryList, inviteHistoryAdapter == null || inviteHistoryAdapter.getItemCount() < 2 ? View.GONE : View.VISIBLE ); diff --git a/app/src/main/java/io/lbry/browser/utils/Lbry.java b/app/src/main/java/io/lbry/browser/utils/Lbry.java index 3c2117c8..3b793d6d 100644 --- a/app/src/main/java/io/lbry/browser/utils/Lbry.java +++ b/app/src/main/java/io/lbry/browser/utils/Lbry.java @@ -92,6 +92,13 @@ public final class Lbry { public static KeyStore KEYSTORE; public static boolean SDK_READY = false; + public static void startupInit() { + ownChannels = new ArrayList<>(); + ownClaims = new ArrayList<>(); + knownTags = new ArrayList<>(); + followedTags = new ArrayList<>(); + } + public static void parseStatus(String response) { try { JSONObject json = parseSdkResponse(response);