publish editing

This commit is contained in:
Akinwale Ariwodola 2020-05-21 16:24:37 +01:00
parent 4d2656f676
commit fafb20b39a
13 changed files with 285 additions and 39 deletions

View file

@ -14,8 +14,8 @@ android {
applicationId "io.lbry.browser"
minSdkVersion 21
targetSdkVersion 29
versionCode 1502
versionName "0.15.2"
versionCode 1503
versionName "0.15.3"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

View file

@ -41,6 +41,16 @@ public class InlineChannelSpinnerAdapter extends ArrayAdapter<Claim> {
}
}
public int getItemPosition(Claim item) {
for (int i = 0; i < channels.size(); i++) {
Claim channel = channels.get(i);
if (item.getClaimId().equalsIgnoreCase(channel.getClaimId())) {
return i;
}
}
return -1;
}
@Override
public View getDropDownView(int position, View view, ViewGroup parent) {
return createView(position, view, parent);

View file

@ -0,0 +1,42 @@
package io.lbry.browser.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import androidx.annotation.NonNull;
import io.lbry.browser.R;
import io.lbry.browser.model.Language;
import io.lbry.browser.utils.Predefined;
public class LanguageSpinnerAdapter extends ArrayAdapter<Language> {
private int layoutResourceId;
private LayoutInflater inflater;
public LanguageSpinnerAdapter(Context context, int resource) {
super(context, resource, 0, Predefined.PUBLISH_LANGUAGES);
inflater = LayoutInflater.from(context);
layoutResourceId = resource;
}
@Override
public View getDropDownView(int position, View view, @NonNull ViewGroup parent) {
return createView(position, view, parent);
}
@Override
public View getView(int position, View view, @NonNull ViewGroup parent) {
return createView(position, view, parent);
}
private View createView(int position, View convertView, ViewGroup parent) {
Language item = getItem(position);
View view = inflater.inflate(layoutResourceId, parent, false);
TextView label = view.findViewById(R.id.item_display_name);
label.setText(item != null ? item.getStringResourceId() : 0);
return view;
}
}

View file

@ -0,0 +1,42 @@
package io.lbry.browser.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import androidx.annotation.NonNull;
import io.lbry.browser.R;
import io.lbry.browser.model.License;
import io.lbry.browser.utils.Predefined;
public class LicenseSpinnerAdapter extends ArrayAdapter<License> {
private int layoutResourceId;
private LayoutInflater inflater;
public LicenseSpinnerAdapter(Context context, int resource) {
super(context, resource, 0, Predefined.LICENSES);
inflater = LayoutInflater.from(context);
layoutResourceId = resource;
}
@Override
public View getDropDownView(int position, View view, @NonNull ViewGroup parent) {
return createView(position, view, parent);
}
@Override
public View getView(int position, View view, @NonNull ViewGroup parent) {
return createView(position, view, parent);
}
private View createView(int position, View convertView, ViewGroup parent) {
License item = getItem(position);
View view = inflater.inflate(layoutResourceId, parent, false);
TextView label = view.findViewById(R.id.item_display_name);
label.setText(item != null ? item.getStringResourceId() : 0);
return view;
}
}

View file

@ -21,14 +21,12 @@ import io.lbry.browser.utils.Lbry;
public class PublishClaimTask extends AsyncTask<Void, Void, Claim> {
private Claim claim;
private String filePath;
private boolean update;
private View progressView;
private ClaimResultHandler handler;
private Exception error;
public PublishClaimTask(Claim claim, String filePath, boolean update, View progressView, ClaimResultHandler handler) {
public PublishClaimTask(Claim claim, String filePath, View progressView, ClaimResultHandler handler) {
this.claim = claim;
this.filePath = filePath;
this.update = update;
this.progressView = progressView;
this.handler = handler;
}
@ -63,8 +61,15 @@ public class PublishClaimTask extends AsyncTask<Void, Void, Claim> {
if (claim.getSigningChannel() != null) {
options.put("channel_id", claim.getSigningChannel().getClaimId());
}
// TODO: license, license_url, languages
if (metadata.getLanguages() != null && metadata.getLanguages().size() > 0) {
options.put("languages", metadata.getLanguages());
}
if (!Helper.isNullOrEmpty(metadata.getLicense())) {
options.put("license", metadata.getLicense());
}
if (!Helper.isNullOrEmpty(metadata.getLicenseUrl())) {
options.put("license_url", metadata.getLicenseUrl());
}
Claim claimResult = null;
try {

View file

@ -377,11 +377,12 @@ public class ChannelFragment extends BaseFragment implements FetchChannelsListen
String coverUrl = claim.getCoverUrl();
textTitle.setText(Helper.isNullOrEmpty(claim.getTitle()) ? claim.getName() : claim.getTitle());
if (!Helper.isNullOrEmpty(coverUrl)) {
Glide.with(getContext().getApplicationContext()).load(coverUrl).centerCrop().into(imageCover);
Context context = getContext();
if (context != null && !Helper.isNullOrEmpty(coverUrl)) {
Glide.with(context.getApplicationContext()).load(coverUrl).centerCrop().into(imageCover);
}
if (!Helper.isNullOrEmpty(thumbnailUrl)) {
Glide.with(getContext().getApplicationContext()).load(thumbnailUrl).apply(RequestOptions.circleCropTransform()).into(imageThumbnail);
if (context != null && !Helper.isNullOrEmpty(thumbnailUrl)) {
Glide.with(context.getApplicationContext()).load(thumbnailUrl).apply(RequestOptions.circleCropTransform()).into(imageThumbnail);
noThumbnailView.setVisibility(View.GONE);
} else {
imageThumbnail.setVisibility(View.GONE);

View file

@ -574,8 +574,14 @@ public class FileViewFragment extends BaseFragment implements
public void onClick(View view) {
ImageView descIndicator = root.findViewById(R.id.file_view_desc_toggle_arrow);
View descriptionArea = root.findViewById(R.id.file_view_description_area);
boolean hasDescription = claim != null && !Helper.isNullOrEmpty(claim.getDescription());
boolean hasTags = claim != null && claim.getTags() != null && claim.getTags().size() > 0;
if (descriptionArea.getVisibility() != View.VISIBLE) {
descriptionArea.setVisibility(View.VISIBLE);
if (hasDescription || hasTags) {
descriptionArea.setVisibility(View.VISIBLE);
}
descIndicator.setImageResource(R.drawable.ic_arrow_dropup);
} else {
descriptionArea.setVisibility(View.GONE);

View file

@ -44,6 +44,7 @@ import com.google.android.material.button.MaterialButton;
import com.google.android.material.snackbar.Snackbar;
import com.google.android.material.switchmaterial.SwitchMaterial;
import com.google.android.material.textfield.TextInputEditText;
import com.google.android.material.textfield.TextInputLayout;
import org.json.JSONArray;
import org.json.JSONException;
@ -53,6 +54,7 @@ import java.io.File;
import java.io.FileOutputStream;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@ -60,6 +62,8 @@ import io.lbry.browser.BuildConfig;
import io.lbry.browser.MainActivity;
import io.lbry.browser.R;
import io.lbry.browser.adapter.InlineChannelSpinnerAdapter;
import io.lbry.browser.adapter.LanguageSpinnerAdapter;
import io.lbry.browser.adapter.LicenseSpinnerAdapter;
import io.lbry.browser.adapter.TagListAdapter;
import io.lbry.browser.listener.FilePickerListener;
import io.lbry.browser.listener.SdkStatusListener;
@ -68,6 +72,8 @@ import io.lbry.browser.listener.WalletBalanceListener;
import io.lbry.browser.model.Claim;
import io.lbry.browser.model.Fee;
import io.lbry.browser.model.GalleryItem;
import io.lbry.browser.model.Language;
import io.lbry.browser.model.License;
import io.lbry.browser.model.NavMenuItem;
import io.lbry.browser.model.Tag;
import io.lbry.browser.model.WalletBalance;
@ -142,6 +148,8 @@ public class PublishFormFragment extends BaseFragment implements
private TextInputEditText inputPrice;
private TextInputEditText inputAddress;
private TextInputEditText inputDeposit;
private TextInputEditText inputOtherLicenseDescription;
private TextInputLayout layoutOtherLicenseDescription;
private View inlineDepositBalanceContainer;
private TextView inlineDepositBalanceValue;
@ -161,11 +169,11 @@ public class PublishFormFragment extends BaseFragment implements
private String lastSelectedThumbnailFile;
private String uploadedThumbnailUrl;
private boolean editFieldsLoaded;
private boolean editChannelSpinnerLoaded;
private Claim currentClaim;
private GalleryItem currentGalleryItem;
private String currentFilePath;
private String transcodedFilePath;
private boolean fileLoaded;
private View mediaContainer;
private View uploadProgress;
@ -176,7 +184,6 @@ public class PublishFormFragment extends BaseFragment implements
private TextView textOptimizationStatus;
private TextView textOptimizationElapsed;
public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_publish_form, container, false);
@ -215,7 +222,11 @@ public class PublishFormFragment extends BaseFragment implements
inputPrice = root.findViewById(R.id.publish_form_input_price);
inputAddress = root.findViewById(R.id.publish_form_input_address);
inputDeposit = root.findViewById(R.id.publish_form_input_deposit);
inputOtherLicenseDescription = root.findViewById(R.id.publish_form_input_license_other);
layoutOtherLicenseDescription = root.findViewById(R.id.publish_form_license_other_layout);
priceCurrencySpinner = root.findViewById(R.id.publish_form_currency_spinner);
languageSpinner = root.findViewById(R.id.publish_form_language_spinner);
licenseSpinner = root.findViewById(R.id.publish_form_license_spinner);
linkPublishCancel = root.findViewById(R.id.publish_form_cancel);
buttonPublish = root.findViewById(R.id.publish_form_publish_button);
@ -263,11 +274,35 @@ public class PublishFormFragment extends BaseFragment implements
}
private void initUi() {
Context context = getContext();
languageSpinner.setAdapter(new LanguageSpinnerAdapter(context, R.layout.spinner_item_generic));
licenseSpinner.setAdapter(new LicenseSpinnerAdapter(context, R.layout.spinner_item_generic));
licenseSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long l) {
License license = (License) adapterView.getAdapter().getItem(position);
boolean otherLicense = Arrays.asList(
Predefined.LICENSE_COPYRIGHTED.toLowerCase(),
Predefined.LICENSE_OTHER.toLowerCase()).contains(license.getName().toLowerCase());
Helper.setViewVisibility(layoutOtherLicenseDescription, otherLicense ? View.VISIBLE : View.GONE);
if (!otherLicense) {
inputOtherLicenseDescription.setText(null);
}
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
linkGenerateAddress.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
inputAddress.setText(Helper.generateUrl());
if (!editMode) {
inputAddress.setText(Helper.generateUrl());
}
}
});
@ -474,9 +509,7 @@ public class PublishFormFragment extends BaseFragment implements
this.currentClaim = claim;
editFieldsLoaded = false;
}
}
if (params.containsKey("galleryItem")) {
} else if (params.containsKey("galleryItem")) {
currentGalleryItem = (GalleryItem) params.get("galleryItem");
} else if (params.containsKey("directFilePath")) {
currentFilePath = (String) params.get("directFilePath");
@ -516,8 +549,33 @@ public class PublishFormFragment extends BaseFragment implements
private void updateFieldsFromCurrentClaim() {
if (currentClaim != null && !editFieldsLoaded) {
Context context = getContext();
Claim.StreamMetadata metadata = (Claim.StreamMetadata) currentClaim.getValue();
uploadedThumbnailUrl = currentClaim.getThumbnailUrl();
if (context != null && !Helper.isNullOrEmpty(uploadedThumbnailUrl)) {
Glide.with(context.getApplicationContext()).load(uploadedThumbnailUrl).centerCrop().into(imageThumbnail);
}
inputTitle.setText(currentClaim.getTitle());
inputDescription.setText(currentClaim.getDescription());
if (addedTagsAdapter != null && currentClaim.getTagObjects() != null) {
addedTagsAdapter.addTags(currentClaim.getTagObjects());
updateSuggestedTags(currentFilter, SUGGESTED_LIMIT, true);
}
if (metadata.getFee() != null) {
Fee fee = metadata.getFee();
switchPrice.setChecked(true);
inputPrice.setText(fee.getAmount());
priceCurrencySpinner.setSelection("lbc".equalsIgnoreCase(fee.getCurrency()) ? 0 : 1);
}
inputAddress.setText(currentClaim.getName());
inputDeposit.setText(currentClaim.getAmount());
inputAddress.setEnabled(false);
editMode = true;
editFieldsLoaded = true;
}
}
@ -858,12 +916,20 @@ public class PublishFormFragment extends BaseFragment implements
}
if (channelSpinnerAdapter != null && channelSpinner != null) {
if (channelSpinnerAdapter.getCount() > 2) {
// if anonymous displayed, select first channel if available
channelSpinner.setSelection(2);
} else if (channelSpinnerAdapter.getCount() > 1) {
// select anonymous
channelSpinner.setSelection(1);
if (editMode && 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
channelSpinner.setSelection(2);
} else if (channelSpinnerAdapter.getCount() > 1) {
// select anonymous
channelSpinner.setSelection(1);
}
}
}
}
@ -889,14 +955,26 @@ public class PublishFormFragment extends BaseFragment implements
fee.setAmount(Helper.getValue(inputPrice.getText()));
metadata.setFee(fee);
}
if (!Helper.isNullOrEmpty(uploadedThumbnailUrl)) {
Claim.Resource thumbnail = new Claim.Resource();
thumbnail.setUrl(uploadedThumbnailUrl);
metadata.setThumbnail(thumbnail);
}
// TODO: License, LicenseDescription, LicenseUrl, Language
Language selectedLanguage = (Language) languageSpinner.getSelectedItem();
if (selectedLanguage != null) {
metadata.setLanguages(Arrays.asList(selectedLanguage.getCode()));
}
License selectedLicense = (License) licenseSpinner.getSelectedItem();
if (selectedLicense != null) {
boolean otherLicense = Arrays.asList(
Predefined.LICENSE_COPYRIGHTED.toLowerCase(),
Predefined.LICENSE_OTHER.toLowerCase()).contains(selectedLicense.getName().toLowerCase());
metadata.setLicense(otherLicense ? Helper.getValue(inputOtherLicenseDescription.getText()) : selectedLicense.getName());
metadata.setLicenseUrl(selectedLicense.getUrl());
}
claim.setValueType(Claim.TYPE_STREAM);
claim.setValue(metadata);
@ -916,13 +994,13 @@ public class PublishFormFragment extends BaseFragment implements
showError(getString(R.string.address_invalid_characters));
return false;
}
if (Helper.claimNameExists(claim.getName())) {
if (!editMode && Helper.claimNameExists(claim.getName())) {
showError(getString(R.string.address_already_used));
return false;
}
String publishFilePath = currentGalleryItem != null ? currentGalleryItem.getFilePath() : currentFilePath;
if (Helper.isNullOrEmpty(publishFilePath) && Helper.isNullOrEmpty(transcodedFilePath)) {
if (!editMode && Helper.isNullOrEmpty(publishFilePath) && Helper.isNullOrEmpty(transcodedFilePath)) {
showError(getString(R.string.no_file_selected));
return false;
}
@ -936,7 +1014,7 @@ public class PublishFormFragment extends BaseFragment implements
finalFilePath = currentGalleryItem != null ? currentGalleryItem.getFilePath() : currentFilePath;
}
saveInProgress = true;
PublishClaimTask task = new PublishClaimTask(claim, finalFilePath, editMode, progressPublish, new ClaimResultHandler() {
PublishClaimTask task = new PublishClaimTask(claim, finalFilePath, progressPublish, new ClaimResultHandler() {
@Override
public void beforeStart() {
preSave();
@ -946,8 +1024,6 @@ public class PublishFormFragment extends BaseFragment implements
public void onSuccess(Claim claimResult) {
postSave();
android.util.Log.d("#HELP", claimResult.toString());
// Run the logPublish task
if (!BuildConfig.DEBUG) {
LogPublishTask logPublish = new LogPublishTask(claimResult);

View file

@ -34,6 +34,7 @@ import io.lbry.browser.adapter.ClaimListAdapter;
import io.lbry.browser.listener.SdkStatusListener;
import io.lbry.browser.listener.SelectionModeListener;
import io.lbry.browser.model.Claim;
import io.lbry.browser.model.NavMenuItem;
import io.lbry.browser.tasks.claim.AbandonHandler;
import io.lbry.browser.tasks.claim.AbandonStreamTask;
import io.lbry.browser.tasks.claim.ClaimListResultHandler;
@ -82,7 +83,7 @@ public class PublishesFragment extends BaseFragment implements ActionMode.Callba
public void onClick(View view) {
Context context = getContext();
if (context instanceof MainActivity) {
//((MainActivity) context).openPublishForm(null);
((MainActivity) context).openFragment(PublishFragment.class, true, NavMenuItem.ID_ITEM_NEW_PUBLISH);
}
}
};
@ -245,9 +246,7 @@ public class PublishesFragment extends BaseFragment implements ActionMode.Callba
// start channel editor with the claim
Context context = getContext();
if (context instanceof MainActivity) {
Map<String, Object> params = new HashMap<>();
params.put("claim", claim);
/*((MainActivity) context).openFragment(PublishFormFragment.class, true, NavMenuItem.ID_ITEM_NEW_PUBLISH, params);*/
((MainActivity) context).openPublishForm(claim);
}
actionMode.finish();

View file

@ -2,6 +2,11 @@ package io.lbry.browser.utils;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import io.lbry.browser.R;
import io.lbry.browser.model.Language;
import io.lbry.browser.model.License;
public final class Predefined {
public static final List<String> DEFAULT_KNOWN_TAGS = Arrays.asList(
@ -1847,4 +1852,47 @@ public final class Predefined {
"Yak",
"Zebra"
);
public static final List<Language> PUBLISH_LANGUAGES = Arrays.asList(
new Language("en", "English", R.string.english),
new Language("zh", "Chinese", R.string.chinese),
new Language("fr", "French", R.string.french),
new Language("de", "German", R.string.german),
new Language("jp", "Japanese", R.string.japanese),
new Language("ru", "Russian", R.string.russian),
new Language("es", "Spanish", R.string.spanish),
new Language("id", "Indonesian", R.string.indonesian),
new Language("it", "Italian", R.string.italian),
new Language("nl", "Dutch", R.string.dutch),
new Language("tr", "Turkish", R.string.turkish),
new Language("pl", "Polish", R.string.polish),
new Language("ms", "Malay", R.string.malay),
new Language("pt", "Portuguese", R.string.portuguese),
new Language("vi", "Vietnamese", R.string.vietnamese),
new Language("th", "Thai", R.string.thai),
new Language("ar", "Arabic", R.string.arabic),
new Language("cs", "Czech", R.string.czech),
new Language("hr", "Croatian", R.string.croatian),
new Language("km", "Cambodian", R.string.cambodian),
new Language("ko", "Korean", R.string.korean),
new Language("no", "Norwegian", R.string.norwegian),
new Language("ro", "Romanian", R.string.romanian),
new Language("hi", "Hindi", R.string.hindi),
new Language("el", "Greek", R.string.greek)
);
public static final String LICENSE_COPYRIGHTED = "Copyrighted";
public static final String LICENSE_OTHER = "Other";
public static final List<License> LICENSES = Arrays.asList(
new License("None", R.string.none),
new License("Public Domain", R.string.public_domain),
new License("Creative Commons Attribution 4.0 International", "https://creativecommons.org/licenses/by/4.0/legalcode", R.string.cca_4_0_international),
new License("Creative Commons Attribution-ShareAlike 4.0 International", "https://creativecommons.org/licenses/by-sa/4.0/legalcode", R.string.cca_sa_4_0_international),
new License("Creative Commons Attribution-NoDerivatives 4.0 International", "https://creativecommons.org/licenses/by-nd/4.0/legalcode", R.string.cca_nd_4_0_international),
new License("Creative Commons Attribution-NonCommercial 4.0 International", "https://creativecommons.org/licenses/by-nc/4.0/legalcode", R.string.cca_nc_4_0_international),
new License("Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International", "https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode", R.string.cca_nc_sa_4_0_international),
new License("Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International", "https://creativecommons.org/licenses/by-nc-nd/4.0/legalcode", R.string.cca_nc_nd_4_0_international),
new License(LICENSE_COPYRIGHTED, R.string.copyrighted),
new License(LICENSE_OTHER, R.string.other)
);
}

View file

@ -121,7 +121,8 @@
android:id="@+id/publish_form_video_opt_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp">
android:layout_marginTop="16dp"
android:visibility="gone">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -492,14 +493,14 @@
android:layout_marginTop="4dp" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/publish_form_license_desc_input_layout"
android:id="@+id/publish_form_license_other_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:hint="@string/license_desc"
android:visibility="gone">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/publish_form_license_desc_input"
android:id="@+id/publish_form_input_license_other"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="@font/inter"

View file

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="12dp">
<TextView
android:id="@+id/item_display_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:fontFamily="@font/inter"
android:singleLine="true"
android:textSize="14sp"
android:textFontWeight="300" />
</LinearLayout>

View file

@ -166,7 +166,7 @@
<string name="none">None</string>
<string name="public_domain">Public Domain</string>
<string name="copyright">Copyright</string>
<string name="copyrighted">Copyrighted</string>
<string name="cca_4_0_international">Creative Commons Attribution 4.0 International</string>
<string name="cca_sa_4_0_international">Creative Commons Attribution-ShareAlike 4.0 International</string>
<string name="cca_nd_4_0_international">Creative Commons Attribution-NoDerivatives 4.0 International</string>