auto select corresponding channel when editing a publish

This commit is contained in:
Akinwale Ariwodola 2020-06-11 19:31:06 +01:00
parent 26ccbf2709
commit a04448ebe8
2 changed files with 22 additions and 6 deletions

View file

@ -10,6 +10,7 @@ import android.widget.SpinnerAdapter;
import android.widget.TextView; import android.widget.TextView;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.List; import java.util.List;
import io.lbry.browser.R; import io.lbry.browser.R;
@ -41,6 +42,19 @@ public class InlineChannelSpinnerAdapter extends ArrayAdapter<Claim> {
} }
} }
public void addAll(Collection<? extends Claim> collection) {
for (Claim claim : collection) {
if (!channels.contains(claim)) {
channels.add(claim);
}
}
super.addAll(collection);
}
public void clear() {
channels.clear();
super.clear();
}
public int getItemPosition(Claim item) { public int getItemPosition(Claim item) {
for (int i = 0; i < channels.size(); i++) { for (int i = 0; i < channels.size(); i++) {
Claim channel = channels.get(i); Claim channel = channels.get(i);

View file

@ -983,8 +983,8 @@ public class PublishFormFragment extends BaseFragment implements
} }
} else { } else {
channelSpinnerAdapter.clear(); channelSpinnerAdapter.clear();
channelSpinnerAdapter.addAll(channels);
channelSpinnerAdapter.addPlaceholder(true); channelSpinnerAdapter.addPlaceholder(true);
channelSpinnerAdapter.addAll(channels);
channelSpinnerAdapter.notifyDataSetChanged(); channelSpinnerAdapter.notifyDataSetChanged();
} }
@ -993,12 +993,14 @@ public class PublishFormFragment extends BaseFragment implements
} }
if (channelSpinnerAdapter != null && channelSpinner != null) { if (channelSpinnerAdapter != null && channelSpinner != null) {
if (editMode && currentClaim.getSigningChannel() != null && !editChannelSpinnerLoaded) { if (editMode) {
int position = channelSpinnerAdapter.getItemPosition(currentClaim.getSigningChannel()); if (currentClaim.getSigningChannel() != null && !editChannelSpinnerLoaded) {
if (position > -1) { int position = channelSpinnerAdapter.getItemPosition(currentClaim.getSigningChannel());
channelSpinner.setSelection(position); if (position > -1) {
channelSpinner.setSelection(position);
}
editChannelSpinnerLoaded = true;
} }
editChannelSpinnerLoaded = true;
} else { } else {
if (channelSpinnerAdapter.getCount() > 2) { if (channelSpinnerAdapter.getCount() > 2) {
// if anonymous displayed, select first channel if available // if anonymous displayed, select first channel if available