diff --git a/app/src/main/java/io/lbry/browser/adapter/LanguageSpinnerAdapter.java b/app/src/main/java/io/lbry/browser/adapter/LanguageSpinnerAdapter.java index eb4decf9..1e5c9a44 100644 --- a/app/src/main/java/io/lbry/browser/adapter/LanguageSpinnerAdapter.java +++ b/app/src/main/java/io/lbry/browser/adapter/LanguageSpinnerAdapter.java @@ -10,6 +10,7 @@ import android.widget.TextView; import androidx.annotation.NonNull; import io.lbry.browser.R; +import io.lbry.browser.model.Claim; import io.lbry.browser.model.Language; import io.lbry.browser.utils.Predefined; @@ -23,6 +24,16 @@ public class LanguageSpinnerAdapter extends ArrayAdapter { layoutResourceId = resource; } + public int getItemPosition(String languageCode) { + for (int i = 0; i < Predefined.PUBLISH_LANGUAGES.size(); i++) { + Language lang = Predefined.PUBLISH_LANGUAGES.get(i); + if (lang.getCode().equalsIgnoreCase(languageCode)) { + return i; + } + } + return -1; + } + @Override public View getDropDownView(int position, View view, @NonNull ViewGroup parent) { return createView(position, view, parent); diff --git a/app/src/main/java/io/lbry/browser/adapter/LicenseSpinnerAdapter.java b/app/src/main/java/io/lbry/browser/adapter/LicenseSpinnerAdapter.java index 49f75c13..c6776cf9 100644 --- a/app/src/main/java/io/lbry/browser/adapter/LicenseSpinnerAdapter.java +++ b/app/src/main/java/io/lbry/browser/adapter/LicenseSpinnerAdapter.java @@ -10,6 +10,7 @@ import android.widget.TextView; import androidx.annotation.NonNull; import io.lbry.browser.R; +import io.lbry.browser.model.Language; import io.lbry.browser.model.License; import io.lbry.browser.utils.Predefined; @@ -22,6 +23,15 @@ public class LicenseSpinnerAdapter extends ArrayAdapter { inflater = LayoutInflater.from(context); layoutResourceId = resource; } + public int getItemPosition(String name) { + for (int i = 0; i < Predefined.LICENSES.size(); i++) { + License lic = Predefined.LICENSES.get(i); + if (lic.getName().equalsIgnoreCase(name)) { + return i; + } + } + return -1; + } @Override public View getDropDownView(int position, View view, @NonNull ViewGroup parent) { 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 91bb967c..af3e2f38 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 @@ -573,6 +573,32 @@ public class PublishFormFragment extends BaseFragment implements inputAddress.setText(currentClaim.getName()); inputDeposit.setText(currentClaim.getAmount()); + if (metadata.getLanguages() != null && metadata.getLanguages().size() > 0) { + // get the first language + String langCode = metadata.getLanguages().get(0); + int langCodePosition = ((LanguageSpinnerAdapter) languageSpinner.getAdapter()).getItemPosition(langCode); + if (langCodePosition > -1) { + languageSpinner.setSelection(langCodePosition); + } + } + + if (!Helper.isNullOrEmpty(metadata.getLicense())) { + LicenseSpinnerAdapter adapter = (LicenseSpinnerAdapter) licenseSpinner.getAdapter(); + int licPosition = adapter.getItemPosition(metadata.getLicense()); + if (licPosition == -1) { + licPosition = adapter.getItemPosition(Predefined.LICENSE_OTHER); + } + if (licPosition > -1) { + licenseSpinner.setSelection(licPosition); + } + + License selectedLicense = (License) licenseSpinner.getSelectedItem(); + boolean otherLicense = Arrays.asList( + Predefined.LICENSE_COPYRIGHTED.toLowerCase(), + Predefined.LICENSE_OTHER.toLowerCase()).contains(selectedLicense.getName().toLowerCase()); + inputOtherLicenseDescription.setText(otherLicense ? metadata.getLicense() : null); + } + inputAddress.setEnabled(false); editMode = true; editFieldsLoaded = true; @@ -1057,6 +1083,19 @@ public class PublishFormFragment extends BaseFragment implements saveInProgress = true; // disable input views + Helper.setViewEnabled(channelSpinner, false); + Helper.setViewEnabled(inputTitle, false); + Helper.setViewEnabled(inputDescription, false); + Helper.setViewEnabled(inputTagFilter, false); + Helper.setViewEnabled(inputAddress, false); + Helper.setViewEnabled(inputDeposit, false); + Helper.setViewEnabled(inputPrice, false); + Helper.setViewEnabled(inputOtherLicenseDescription, false); + Helper.setViewEnabled(switchPrice, false); + Helper.setViewEnabled(languageSpinner, false); + Helper.setViewEnabled(licenseSpinner, false); + Helper.setViewEnabled(priceCurrencySpinner, false); + Helper.setViewEnabled(linkGenerateAddress, false); Helper.setViewEnabled(linkShowExtraFields, false); Helper.setViewEnabled(linkPublishCancel, false); @@ -1064,6 +1103,20 @@ public class PublishFormFragment extends BaseFragment implements } private void postSave() { + Helper.setViewEnabled(channelSpinner, true); + Helper.setViewEnabled(inputTitle, true); + Helper.setViewEnabled(inputDescription, true); + Helper.setViewEnabled(inputTagFilter, false); + Helper.setViewEnabled(inputAddress, editMode ? false : true); + Helper.setViewEnabled(inputDeposit, true); + Helper.setViewEnabled(inputPrice, true); + Helper.setViewEnabled(inputOtherLicenseDescription, true); + Helper.setViewEnabled(switchPrice, true); + Helper.setViewEnabled(languageSpinner, true); + Helper.setViewEnabled(licenseSpinner, true); + Helper.setViewEnabled(priceCurrencySpinner, true); + Helper.setViewEnabled(linkGenerateAddress, true); + Helper.setViewEnabled(linkShowExtraFields, true); Helper.setViewEnabled(linkPublishCancel, true); Helper.setViewEnabled(buttonPublish, true); @@ -1102,6 +1155,10 @@ public class PublishFormFragment extends BaseFragment implements Helper.setViewVisibility(noTagResultsView, suggestedTagsAdapter == null || suggestedTagsAdapter.getItemCount() == 0 ? View.VISIBLE : View.GONE); } public void addTag(Tag tag) { + if (saveInProgress) { + return; + } + if (addedTagsAdapter.getTags().contains(tag)) { Snackbar.make(getView(), getString(R.string.tag_already_added, tag.getName()), Snackbar.LENGTH_LONG).show(); return; @@ -1121,6 +1178,9 @@ public class PublishFormFragment extends BaseFragment implements checkNoTagResults(); } public void removeTag(Tag tag) { + if (saveInProgress) { + return; + } addedTagsAdapter.removeTag(tag); updateSuggestedTags(currentFilter, SUGGESTED_LIMIT, false); checkNoAddedTags();