From a04448ebe8e898173f8ce180a503e58ecc1d9b69 Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Thu, 11 Jun 2020 19:31:06 +0100 Subject: [PATCH] auto select corresponding channel when editing a publish --- .../adapter/InlineChannelSpinnerAdapter.java | 14 ++++++++++++++ .../browser/ui/publish/PublishFormFragment.java | 14 ++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/lbry/browser/adapter/InlineChannelSpinnerAdapter.java b/app/src/main/java/io/lbry/browser/adapter/InlineChannelSpinnerAdapter.java index e3713b58..457749ad 100644 --- a/app/src/main/java/io/lbry/browser/adapter/InlineChannelSpinnerAdapter.java +++ b/app/src/main/java/io/lbry/browser/adapter/InlineChannelSpinnerAdapter.java @@ -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 { } } + public void addAll(Collection 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); diff --git a/app/src/main/java/io/lbry/browser/ui/publish/PublishFormFragment.java b/app/src/main/java/io/lbry/browser/ui/publish/PublishFormFragment.java index 5beb0787..7d9a4072 100644 --- a/app/src/main/java/io/lbry/browser/ui/publish/PublishFormFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/publish/PublishFormFragment.java @@ -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) { - int position = channelSpinnerAdapter.getItemPosition(currentClaim.getSigningChannel()); - if (position > -1) { - channelSpinner.setSelection(position); + if (editMode) { + if (currentClaim.getSigningChannel() != null && !editChannelSpinnerLoaded) { + int position = channelSpinnerAdapter.getItemPosition(currentClaim.getSigningChannel()); + if (position > -1) { + channelSpinner.setSelection(position); + } + editChannelSpinnerLoaded = true; } - editChannelSpinnerLoaded = true; } else { if (channelSpinnerAdapter.getCount() > 2) { // if anonymous displayed, select first channel if available -- 2.45.2