Merge pull request #935 from lbryio/edit-publish-channel

auto select corresponding channel when editing a publish
This commit is contained in:
Akinwale Ariwodola 2020-06-11 19:38:24 +01:00 committed by GitHub
commit 895ca75506
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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) {
if (currentClaim.getSigningChannel() != null && !editChannelSpinnerLoaded) {
int position = channelSpinnerAdapter.getItemPosition(currentClaim.getSigningChannel()); int position = channelSpinnerAdapter.getItemPosition(currentClaim.getSigningChannel());
if (position > -1) { if (position > -1) {
channelSpinner.setSelection(position); 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