auto select corresponding channel when editing a publish #935

Merged
akinwale merged 1 commit from edit-publish-channel into master 2020-06-11 20:38:24 +02:00
2 changed files with 22 additions and 6 deletions

View file

@ -10,6 +10,7 @@ import android.widget.SpinnerAdapter;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
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) {
for (int i = 0; i < channels.size(); i++) {
Claim channel = channels.get(i);

View file

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