finish publish experience

This commit is contained in:
Akinwale Ariwodola 2020-05-21 22:02:50 +01:00
parent fafb20b39a
commit c11e2fcd7a
3 changed files with 81 additions and 0 deletions

View file

@ -10,6 +10,7 @@ import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import io.lbry.browser.R; import io.lbry.browser.R;
import io.lbry.browser.model.Claim;
import io.lbry.browser.model.Language; import io.lbry.browser.model.Language;
import io.lbry.browser.utils.Predefined; import io.lbry.browser.utils.Predefined;
@ -23,6 +24,16 @@ public class LanguageSpinnerAdapter extends ArrayAdapter<Language> {
layoutResourceId = resource; 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 @Override
public View getDropDownView(int position, View view, @NonNull ViewGroup parent) { public View getDropDownView(int position, View view, @NonNull ViewGroup parent) {
return createView(position, view, parent); return createView(position, view, parent);

View file

@ -10,6 +10,7 @@ import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import io.lbry.browser.R; import io.lbry.browser.R;
import io.lbry.browser.model.Language;
import io.lbry.browser.model.License; import io.lbry.browser.model.License;
import io.lbry.browser.utils.Predefined; import io.lbry.browser.utils.Predefined;
@ -22,6 +23,15 @@ public class LicenseSpinnerAdapter extends ArrayAdapter<License> {
inflater = LayoutInflater.from(context); inflater = LayoutInflater.from(context);
layoutResourceId = resource; 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 @Override
public View getDropDownView(int position, View view, @NonNull ViewGroup parent) { public View getDropDownView(int position, View view, @NonNull ViewGroup parent) {

View file

@ -573,6 +573,32 @@ public class PublishFormFragment extends BaseFragment implements
inputAddress.setText(currentClaim.getName()); inputAddress.setText(currentClaim.getName());
inputDeposit.setText(currentClaim.getAmount()); 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); inputAddress.setEnabled(false);
editMode = true; editMode = true;
editFieldsLoaded = true; editFieldsLoaded = true;
@ -1057,6 +1083,19 @@ public class PublishFormFragment extends BaseFragment implements
saveInProgress = true; saveInProgress = true;
// disable input views // 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(linkShowExtraFields, false);
Helper.setViewEnabled(linkPublishCancel, false); Helper.setViewEnabled(linkPublishCancel, false);
@ -1064,6 +1103,20 @@ public class PublishFormFragment extends BaseFragment implements
} }
private void postSave() { 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(linkShowExtraFields, true);
Helper.setViewEnabled(linkPublishCancel, true); Helper.setViewEnabled(linkPublishCancel, true);
Helper.setViewEnabled(buttonPublish, 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); Helper.setViewVisibility(noTagResultsView, suggestedTagsAdapter == null || suggestedTagsAdapter.getItemCount() == 0 ? View.VISIBLE : View.GONE);
} }
public void addTag(Tag tag) { public void addTag(Tag tag) {
if (saveInProgress) {
return;
}
if (addedTagsAdapter.getTags().contains(tag)) { if (addedTagsAdapter.getTags().contains(tag)) {
Snackbar.make(getView(), getString(R.string.tag_already_added, tag.getName()), Snackbar.LENGTH_LONG).show(); Snackbar.make(getView(), getString(R.string.tag_already_added, tag.getName()), Snackbar.LENGTH_LONG).show();
return; return;
@ -1121,6 +1178,9 @@ public class PublishFormFragment extends BaseFragment implements
checkNoTagResults(); checkNoTagResults();
} }
public void removeTag(Tag tag) { public void removeTag(Tag tag) {
if (saveInProgress) {
return;
}
addedTagsAdapter.removeTag(tag); addedTagsAdapter.removeTag(tag);
updateSuggestedTags(currentFilter, SUGGESTED_LIMIT, false); updateSuggestedTags(currentFilter, SUGGESTED_LIMIT, false);
checkNoAddedTags(); checkNoAddedTags();