fix channel list adapters

This commit is contained in:
Akinwale Ariwodola 2020-05-14 04:14:06 +01:00
parent d1faaa9362
commit 7cf97feb9e
4 changed files with 25 additions and 9 deletions

View file

@ -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<Void, Void, Boolean>() {
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

View file

@ -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

View file

@ -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<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();
@ -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
);

View file

@ -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);