Skip to content

Commit

Permalink
fix channel list adapters
Browse files Browse the repository at this point in the history
  • Loading branch information
akinwale committed May 14, 2020
1 parent d1faaa9 commit 7cf97fe
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
3 changes: 2 additions & 1 deletion app/src/main/java/io/lbry/browser/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -1598,6 +1598,8 @@ public void showActionBar() {

private void startup() {
final Context context = this;
Lbry.startupInit();

// perform some tasks before launching
(new AsyncTask<Void, Void, Boolean>() {
protected void onPreExecute() {
Expand Down Expand Up @@ -1638,7 +1640,6 @@ protected Boolean doInBackground(Void... params) {
throw new Exception("Did not retrieve authenticated user.");
}


Lbryio.newInstall(context);

// (light) fetch subscriptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,15 @@ private void loadChannels(List<Claim> channels) {
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
Expand Down
20 changes: 13 additions & 7 deletions app/src/main/java/io/lbry/browser/ui/wallet/InvitesFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,6 @@ public void onClick(View view) {
}
});

if (Lbry.ownChannels != null) {
updateChannelList(Lbry.ownChannels);
}

channelSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long l) {
Expand Down Expand Up @@ -268,9 +264,8 @@ private void copyInviteLink() {
private void updateChannelList(List<Claim> 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();
Expand All @@ -279,6 +274,10 @@ private void updateChannelList(List<Claim> channels) {
channelSpinnerAdapter.notifyDataSetChanged();
}

if (channelSpinner != null) {
channelSpinner.setAdapter(channelSpinnerAdapter);
}

if (channelSpinnerAdapter.getCount() > 1) {
channelSpinner.setSelection(1);
}
Expand Down Expand Up @@ -382,6 +381,11 @@ private void enableChannelSpinner() {
}

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() {
Expand Down Expand Up @@ -413,10 +417,12 @@ public void onSuccess(List<Invitee> invitees) {
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
);
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/io/lbry/browser/utils/Lbry.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 7cf97fe

Please sign in to comment.