diff --git a/app/src/main/java/fr/free/nrw/commons/media/MediaDetailFragment.java b/app/src/main/java/fr/free/nrw/commons/media/MediaDetailFragment.java index addc9f67c51..de4bf762b00 100644 --- a/app/src/main/java/fr/free/nrw/commons/media/MediaDetailFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/media/MediaDetailFragment.java @@ -1,23 +1,14 @@ package fr.free.nrw.commons.media; -import static android.view.View.GONE; -import static android.view.View.VISIBLE; -import static fr.free.nrw.commons.category.CategoryClientKt.CATEGORY_NEEDING_CATEGORIES; -import static fr.free.nrw.commons.category.CategoryClientKt.CATEGORY_PREFIX; -import static fr.free.nrw.commons.category.CategoryClientKt.CATEGORY_UNCATEGORISED; - import android.annotation.SuppressLint; +import android.graphics.drawable.Animatable; import android.app.AlertDialog; -import android.content.Context; import android.content.Intent; -import android.content.res.Configuration; -import android.graphics.drawable.Animatable; +import android.content.Context; import android.net.Uri; import android.os.Bundle; import android.text.Editable; -import android.text.TextUtils; import android.text.TextWatcher; -import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -27,72 +18,65 @@ import android.widget.Button; import android.widget.EditText; import android.widget.LinearLayout; -import android.widget.ProgressBar; import android.widget.ScrollView; -import android.widget.SearchView; import android.widget.Spinner; import android.widget.TextView; import android.widget.Toast; -import androidx.annotation.Nullable; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.OnClick; + import com.facebook.drawee.backends.pipeline.Fresco; +import com.facebook.drawee.interfaces.DraweeController; import com.facebook.drawee.controller.BaseControllerListener; import com.facebook.drawee.controller.ControllerListener; -import com.facebook.drawee.interfaces.DraweeController; import com.facebook.drawee.view.SimpleDraweeView; import com.facebook.imagepipeline.image.ImageInfo; import com.facebook.imagepipeline.request.ImageRequest; -import com.jakewharton.rxbinding2.view.RxView; -import com.jakewharton.rxbinding2.widget.RxSearchView; + +import org.apache.commons.lang3.StringUtils; +import org.wikipedia.util.DateUtil; + +import java.util.ArrayList; +import java.util.Date; +import java.util.Locale; + +import javax.inject.Inject; + +import butterknife.BindView; +import butterknife.ButterKnife; +import butterknife.OnClick; +import androidx.annotation.Nullable; import fr.free.nrw.commons.Media; import fr.free.nrw.commons.MediaDataExtractor; import fr.free.nrw.commons.R; import fr.free.nrw.commons.Utils; import fr.free.nrw.commons.auth.AccountUtil; -import fr.free.nrw.commons.category.CategoryClient; import fr.free.nrw.commons.category.CategoryDetailsActivity; -import fr.free.nrw.commons.category.CategoryEditHelper; -import fr.free.nrw.commons.category.CategoryEditSearchRecyclerViewAdapter; -import fr.free.nrw.commons.category.CategoryEditSearchRecyclerViewAdapter.Callback; import fr.free.nrw.commons.contributions.ContributionsFragment; import fr.free.nrw.commons.delete.DeleteHelper; import fr.free.nrw.commons.delete.ReasonBuilder; -import fr.free.nrw.commons.explore.depictions.WikidataItemDetailsActivity; import fr.free.nrw.commons.di.CommonsDaggerSupportFragment; -import fr.free.nrw.commons.nearby.Label; +import fr.free.nrw.commons.ui.widget.CompatTextView; import fr.free.nrw.commons.ui.widget.HtmlTextView; import fr.free.nrw.commons.utils.ViewUtilWrapper; -import io.reactivex.Observable; import io.reactivex.Single; import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.disposables.Disposable; import io.reactivex.schedulers.Schedulers; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Locale; -import java.util.concurrent.TimeUnit; -import java.util.Map; -import javax.inject.Inject; -import org.apache.commons.lang3.StringUtils; -import org.wikipedia.util.DateUtil; import timber.log.Timber; -public class MediaDetailFragment extends CommonsDaggerSupportFragment implements Callback, - CategoryEditHelper.Callback { +import static android.view.View.GONE; +import static android.view.View.VISIBLE; + +public class MediaDetailFragment extends CommonsDaggerSupportFragment { private boolean editable; private boolean isCategoryImage; private MediaDetailPagerFragment.MediaDetailProvider detailProvider; private int index; + private Locale locale; private boolean isDeleted = false; - private boolean isWikipediaButtonDisplayed; - public static MediaDetailFragment forMedia(int index, boolean editable, boolean isCategoryImage, boolean isWikipediaButtonDisplayed) { + public static MediaDetailFragment forMedia(int index, boolean editable, boolean isCategoryImage) { MediaDetailFragment mf = new MediaDetailFragment(); Bundle state = new Bundle(); @@ -101,7 +85,6 @@ public static MediaDetailFragment forMedia(int index, boolean editable, boolean state.putInt("index", index); state.putInt("listIndex", 0); state.putInt("listTop", 0); - state.putBoolean("isWikipediaButtonDisplayed", isWikipediaButtonDisplayed); mf.setArguments(state); @@ -115,28 +98,14 @@ public static MediaDetailFragment forMedia(int index, boolean editable, boolean @Inject DeleteHelper deleteHelper; @Inject - CategoryEditHelper categoryEditHelper; - @Inject ViewUtilWrapper viewUtil; - @Inject - CategoryClient categoryClient; private int initialListTop = 0; @BindView(R.id.mediaDetailImageView) SimpleDraweeView image; - @BindView(R.id.mediaDetailImageViewLandscape) - SimpleDraweeView imageLandscape; - @BindView(R.id.mediaDetailImageViewSpacer) - LinearLayout imageSpacer; @BindView(R.id.mediaDetailTitle) TextView title; - @BindView(R.id.caption_layout) - LinearLayout captionLayout; - @BindView(R.id.depicts_layout) - LinearLayout depictsLayout; - @BindView(R.id.media_detail_caption) - TextView mediaCaption; @BindView(R.id.mediaDetailDesc) HtmlTextView desc; @BindView(R.id.mediaDetailAuthor) @@ -155,51 +124,18 @@ public static MediaDetailFragment forMedia(int index, boolean editable, boolean LinearLayout nominatedForDeletion; @BindView(R.id.mediaDetailCategoryContainer) LinearLayout categoryContainer; - @BindView(R.id.categoryEditButton) - Button categoryEditButton; - @BindView(R.id.media_detail_depiction_container) - LinearLayout depictionContainer; @BindView(R.id.authorLinearLayout) LinearLayout authorLayout; @BindView(R.id.nominateDeletion) Button delete; @BindView(R.id.mediaDetailScrollView) ScrollView scrollView; - @BindView(R.id.toDoLayout) - LinearLayout toDoLayout; - @BindView(R.id.toDoReason) - TextView toDoReason; - @BindView(R.id.category_edit_layout) - LinearLayout categoryEditLayout; - @BindView(R.id.et_search) - SearchView categorySearchView; - @BindView(R.id.rv_categories) - RecyclerView categoryRecyclerView; - @BindView(R.id.update_categories_button) - Button updateCategoriesButton; - @BindView(R.id.dummy_category_edit_container) - LinearLayout dummyCategoryEditContainer; - @BindView(R.id.pb_categories) - ProgressBar progressbarCategories; - @BindView(R.id.existing_categories) - TextView existingCategories; - @BindView(R.id.no_results_found) - TextView noResultsFound; - - private ArrayList categoryNames = new ArrayList<>(); - private String categorySearchQuery; - /** - * Depicts is a feature part of Structured data. Multiple Depictions can be added for an image just like categories. - * However unlike categories depictions is multi-lingual - * Ex: key: en value: monument - */ - private ImageInfo imageInfoCache; - private int oldWidthOfImageView; - private int newWidthOfImageView; - private boolean heightVerifyingBoolean = true; // helps in maintaining aspect ratio + private ArrayList categoryNames; + private boolean categoriesLoaded = false; + private boolean categoriesPresent = false; private ViewTreeObserver.OnGlobalLayoutListener layoutListener; // for layout stuff, only used once! - private CategoryEditSearchRecyclerViewAdapter categoryEditSearchRecyclerViewAdapter; + private ViewTreeObserver.OnScrollChangedListener scrollListener; //Had to make this class variable, to implement various onClicks, which access the media, also I fell why make separate variables when one can serve the purpose private Media media; @@ -212,7 +148,6 @@ public void onSaveInstanceState(Bundle outState) { outState.putInt("index", index); outState.putBoolean("editable", editable); outState.putBoolean("isCategoryImage", isCategoryImage); - outState.putBoolean("isWikipediaButtonDisplayed", isWikipediaButtonDisplayed); getScrollPosition(); outState.putInt("listTop", initialListTop); @@ -232,13 +167,11 @@ && getParentFragment() instanceof MediaDetailPagerFragment) { if (savedInstanceState != null) { editable = savedInstanceState.getBoolean("editable"); isCategoryImage = savedInstanceState.getBoolean("isCategoryImage"); - isWikipediaButtonDisplayed = savedInstanceState.getBoolean("isWikipediaButtonDisplayed"); index = savedInstanceState.getInt("index"); initialListTop = savedInstanceState.getInt("listTop"); } else { editable = getArguments().getBoolean("editable"); isCategoryImage = getArguments().getBoolean("isCategoryImage"); - isWikipediaButtonDisplayed = getArguments().getBoolean("isWikipediaButtonDisplayed"); index = getArguments().getInt("index"); initialListTop = 0; } @@ -250,6 +183,9 @@ && getParentFragment() instanceof MediaDetailPagerFragment) { reasonList.add(getString(R.string.deletion_reason_no_longer_want_public)); reasonList.add(getString(R.string.deletion_reason_bad_for_my_privacy)); + categoryNames = new ArrayList<>(); + categoryNames.add(getString(R.string.detail_panel_cats_loading)); + final View view = inflater.inflate(R.layout.fragment_media_detail, container, false); ButterKnife.bind(this,view); @@ -261,17 +197,19 @@ && getParentFragment() instanceof MediaDetailPagerFragment) { authorLayout.setVisibility(GONE); } + // Progressively darken the image in the background when we scroll detail pane up + scrollListener = this::updateTheDarkness; + view.getViewTreeObserver().addOnScrollChangedListener(scrollListener); + locale = getResources().getConfiguration().locale; return view; } - @OnClick(R.id.mediaDetailImageViewSpacer) + @OnClick(R.id.mediaDetailImageView) public void launchZoomActivity(View view) { - if (media.getImageUrl() != null) { - Context ctx = view.getContext(); - ctx.startActivity( - new Intent(ctx, ZoomableActivity.class).setData(Uri.parse(media.getImageUrl())) - ); - } + Context ctx = view.getContext(); + ctx.startActivity( + new Intent(ctx,ZoomableActivity.class).setData(Uri.parse(media.getImageUrl())) + ); } @Override @@ -284,142 +222,50 @@ public void onResume() { .getParentFragment())).nearbyNotificationCardView .setVisibility(View.GONE); } - categoryEditSearchRecyclerViewAdapter = - new CategoryEditSearchRecyclerViewAdapter(getContext(), new ArrayList<>( - Label.valuesAsList()), categoryRecyclerView, categoryClient, this); - categoryRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); - categoryRecyclerView.setAdapter(categoryEditSearchRecyclerViewAdapter); - media = detailProvider.getMediaAtPosition(index); scrollView.getViewTreeObserver().addOnGlobalLayoutListener( new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { scrollView.getViewTreeObserver().removeOnGlobalLayoutListener(this); - if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { - imageLandscape.setVisibility(VISIBLE); - } - oldWidthOfImageView = scrollView.getWidth(); displayMediaDetails(); } } ); } - @Override - public void onConfigurationChanged(Configuration newConfig) { - super.onConfigurationChanged(newConfig); - scrollView.getViewTreeObserver().addOnGlobalLayoutListener( - new OnGlobalLayoutListener() { - @Override - public void onGlobalLayout() { - if (scrollView.getWidth() != oldWidthOfImageView) { - if (newWidthOfImageView == 0) { - newWidthOfImageView = scrollView.getWidth(); - updateAspectRatio(newWidthOfImageView); - } - scrollView.getViewTreeObserver().removeOnGlobalLayoutListener(this); - } - } - } - ); - // check orientation - if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { - imageLandscape.setVisibility(VISIBLE); - } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) { - imageLandscape.setVisibility(GONE); - } - // ensuring correct aspect ratio for landscape mode - if (heightVerifyingBoolean) { - updateAspectRatio(newWidthOfImageView); - heightVerifyingBoolean = false; - } else { - updateAspectRatio(oldWidthOfImageView); - heightVerifyingBoolean = true; - } - } - private void displayMediaDetails() { - setTextFields(media); - compositeDisposable.addAll( - mediaDataExtractor.fetchDepictionIdsAndLabels(media) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(this::onDepictionsLoaded, Timber::e), - mediaDataExtractor.checkDeletionRequestExists(media) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(this::onDeletionPageExists, Timber::e), - mediaDataExtractor.fetchDiscussion(media) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(this::onDiscussionLoaded, Timber::e), - mediaDataExtractor.refresh(media) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(this::onMediaRefreshed, Timber::e) - ); - } + //Always load image from Internet to allow viewing the desc, license, and cats + setupImageView(); + title.setText(media.getDisplayTitle()); + desc.setHtmlText(media.getDescription()); + license.setText(media.getLicense()); - private void onMediaRefreshed(Media media) { - setTextFields(media); - compositeDisposable.addAll( - mediaDataExtractor.fetchDepictionIdsAndLabels(media) + Disposable disposable = mediaDataExtractor.fetchMediaDetails(media.getFilename()) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) - .subscribe(this::onDepictionsLoaded, Timber::e) - ); - // compositeDisposable.add(disposable); - setupToDo(); - } - - private void onDiscussionLoaded(String discussion) { - mediaDiscussion.setText(prettyDiscussion(discussion.trim())); - } - - private void onDeletionPageExists(Boolean deletionPageExists) { - if (deletionPageExists){ - delete.setVisibility(GONE); - nominatedForDeletion.setVisibility(VISIBLE); - } else if (!isCategoryImage) { - delete.setVisibility(VISIBLE); - nominatedForDeletion.setVisibility(GONE); - } + .subscribe(this::setTextFields); + compositeDisposable.add(disposable); } - private void onDepictionsLoaded(List idAndCaptions){ - depictsLayout.setVisibility(idAndCaptions.isEmpty() ? GONE : VISIBLE); - buildDepictionList(idAndCaptions); - } - /** - * The imageSpacer is Basically a transparent overlay for the SimpleDraweeView - * which holds the image to be displayed( moreover this image is out of - * the scroll view ) - * @param scrollWidth the current width of the scrollView - */ - private void updateAspectRatio(int scrollWidth) { - if (imageInfoCache != null) { - int finalHeight = (scrollWidth*imageInfoCache.getHeight()) / imageInfoCache.getWidth(); + private void updateAspectRatio(ImageInfo imageInfo) { + if (imageInfo != null) { + int screenWidth = scrollView.getWidth(); + int finalHeight = (screenWidth*imageInfo.getHeight()) / imageInfo.getWidth(); ViewGroup.LayoutParams params = image.getLayoutParams(); - ViewGroup.LayoutParams spacerParams = imageSpacer.getLayoutParams(); params.height = finalHeight; - spacerParams.height = finalHeight; image.setLayoutParams(params); - imageSpacer.setLayoutParams(spacerParams); - imageLandscape.setLayoutParams(params); } } private final ControllerListener aspectRatioListener = new BaseControllerListener() { @Override public void onIntermediateImageSet(String id, @Nullable ImageInfo imageInfo) { - imageInfoCache = imageInfo; - updateAspectRatio(scrollView.getWidth()); + updateAspectRatio(imageInfo); } @Override public void onFinalImageSet(String id, @Nullable ImageInfo imageInfo, @Nullable Animatable animatable) { - imageInfoCache = imageInfo; - updateAspectRatio(scrollView.getWidth()); + updateAspectRatio(imageInfo); } }; @@ -429,84 +275,13 @@ public void onFinalImageSet(String id, @Nullable ImageInfo imageInfo, @Nullable * - when the high resolution image is available, it replaces the low resolution image */ private void setupImageView() { - - image.getHierarchy().setPlaceholderImage(R.drawable.image_placeholder); - image.getHierarchy().setFailureImage(R.drawable.image_placeholder); - - imageLandscape.getHierarchy().setPlaceholderImage(R.drawable.image_placeholder); - imageLandscape.getHierarchy().setFailureImage(R.drawable.image_placeholder); - DraweeController controller = Fresco.newDraweeControllerBuilder() .setLowResImageRequest(ImageRequest.fromUri(media.getThumbUrl())) .setImageRequest(ImageRequest.fromUri(media.getImageUrl())) .setControllerListener(aspectRatioListener) .setOldController(image.getController()) .build(); - DraweeController controllerLandscape = Fresco.newDraweeControllerBuilder() - .setLowResImageRequest(ImageRequest.fromUri(media.getThumbUrl())) - .setImageRequest(ImageRequest.fromUri(media.getImageUrl())) - .setControllerListener(aspectRatioListener) - .setOldController(imageLandscape.getController()) - .build(); image.setController(controller); - imageLandscape.setController(controllerLandscape); - } - - /** - * Displays layout about missing actions to inform user - * - Images that they uploaded with no categories/descriptions, so that they can add them - * - Images that can be added to associated Wikipedia articles that have no pictures - */ - private void setupToDo() { - updateToDoWarning(); - compositeDisposable.add(RxSearchView.queryTextChanges(categorySearchView) - .takeUntil(RxView.detaches(categorySearchView)) - .debounce(500, TimeUnit.MILLISECONDS) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(query -> { - this.categorySearchQuery = query.toString(); - //update image list - if (!TextUtils.isEmpty(query)) { - if (categoryEditLayout.getVisibility() == VISIBLE) { - ((CategoryEditSearchRecyclerViewAdapter) categoryRecyclerView.getAdapter()). - getFilter().filter(query.toString()); - } - } - }, Timber::e - )); - } - - private void updateToDoWarning() { - String toDoMessage = ""; - boolean toDoNeeded = false; - boolean categoriesPresent = media.getCategories() == null ? false : (media.getCategories().size() == 0 ? false : true); - - // Check if the presented category is about need of category - if (categoriesPresent) { - for (String category : media.getCategories()) { - if (category.toLowerCase().contains(CATEGORY_NEEDING_CATEGORIES) || - category.toLowerCase().contains(CATEGORY_UNCATEGORISED)) { - categoriesPresent = false; - } - break; - } - } - if (!categoriesPresent) { - toDoNeeded = true; - toDoMessage += getString(R.string.missing_category); - } - if (isWikipediaButtonDisplayed) { - toDoNeeded = true; - toDoMessage += (toDoMessage.isEmpty()) ? "" : "\n" + getString(R.string.missing_article); - } - - if (toDoNeeded) { - toDoMessage = getString(R.string.todo_improve) + "\n" + toDoMessage; - toDoLayout.setVisibility(VISIBLE); - toDoReason.setText(toDoMessage); - } else { - toDoLayout.setVisibility(GONE); - } } @Override @@ -515,94 +290,42 @@ public void onDestroyView() { getView().getViewTreeObserver().removeGlobalOnLayoutListener(layoutListener); // old Android was on crack. CRACK IS WHACK layoutListener = null; } + if (scrollListener != null && getView() != null) { + getView().getViewTreeObserver().removeOnScrollChangedListener(scrollListener); + scrollListener = null; + } compositeDisposable.clear(); super.onDestroyView(); } private void setTextFields(Media media) { + this.media = media; setupImageView(); - title.setText(media.getDisplayTitle()); desc.setHtmlText(prettyDescription(media)); license.setText(prettyLicense(media)); coordinates.setText(prettyCoordinates(media)); uploadedDate.setText(prettyUploadedDate(media)); - if (prettyCaption(media).equals(getContext().getString(R.string.detail_caption_empty))) { - captionLayout.setVisibility(GONE); - } else { - mediaCaption.setText(prettyCaption(media)); - } + mediaDiscussion.setText(prettyDiscussion(media)); categoryNames.clear(); categoryNames.addAll(media.getCategories()); - categoryEditSearchRecyclerViewAdapter.addToCategories(media.getCategories()); - updateSelectedCategoriesTextView(categoryEditSearchRecyclerViewAdapter.getCategories()); - updateCategoryList(); + categoriesLoaded = true; + categoriesPresent = (categoryNames.size() > 0); + if (!categoriesPresent) { + // Stick in a filler element. + categoryNames.add(getString(R.string.detail_panel_cats_none)); + } + rebuildCatList(); if (media.getCreator() == null || media.getCreator().equals("")) { authorLayout.setVisibility(GONE); } else { author.setText(media.getCreator()); } - } - - private void updateCategoryList() { - List allCategories = new ArrayList( media.getCategories()); - if (media.getAddedCategories() != null) { - // TODO this added categories logic should be removed. - // It is just a short term hack. Categories should be fetch everytime they are updated. - // if media.getCategories contains addedCategory, then do not re-add them - for (String addedCategory : media.getAddedCategories()) { - if (allCategories.contains(addedCategory)) { - media.setAddedCategories(null); - break; - } - } - allCategories.addAll(media.getAddedCategories()); - } - if (allCategories.isEmpty()) { - // Stick in a filler element. - allCategories.add(getString(R.string.detail_panel_cats_none)); - } - - rebuildCatList(allCategories); - } - - @Override - public void updateSelectedCategoriesTextView(List selectedCategories) { - if (selectedCategories == null || selectedCategories.size() == 0) { - updateCategoriesButton.setClickable(false); - } - if (selectedCategories != null) { - existingCategories.setText(StringUtils.join(selectedCategories,", ")); - updateCategoriesButton.setClickable(true); - } - } - @Override - public void noResultsFound() { - noResultsFound.setVisibility(VISIBLE); - } - - @Override - public void someResultsFound() { - noResultsFound.setVisibility(GONE); - } - - /** - * Populates media details fragment with depiction list - * @param idAndCaptions - */ - private void buildDepictionList(List idAndCaptions) { - depictionContainer.removeAllViews(); - for (IdAndCaptions idAndCaption : idAndCaptions) { - depictionContainer.addView(buildDepictLabel( - idAndCaption.getCaptions().values().iterator().next(), - idAndCaption.getId(), - depictionContainer - )); - } + checkDeletion(media); } @OnClick(R.id.mediaDetailLicense) @@ -624,57 +347,13 @@ public void onMediaDetailCoordinatesClicked(){ @OnClick(R.id.copyWikicode) public void onCopyWikicodeClicked(){ - String data = "[[" + media.getFilename() + "|thumb|" + media.getFallbackDescription() + "]]"; + String data = "[[" + media.getFilename() + "|thumb|" + media.getDescription() + "]]"; Utils.copy("wikiCode",data,getContext()); Timber.d("Generated wikidata copy code: %s", data); Toast.makeText(getContext(), getString(R.string.wikicode_copied), Toast.LENGTH_SHORT).show(); } - @OnClick(R.id.dummy_category_edit_container) - public void onOutsideOfCategoryEditClicked() { - if (dummyCategoryEditContainer.getVisibility() == VISIBLE) { - dummyCategoryEditContainer.setVisibility(GONE); - } - } - - @OnClick(R.id.categoryEditButton) - public void onCategoryEditButtonClicked(){ - displayHideCategorySearch(); - } - - public void displayHideCategorySearch() { - if (dummyCategoryEditContainer.getVisibility() != VISIBLE) { - dummyCategoryEditContainer.setVisibility(VISIBLE); - } else { - dummyCategoryEditContainer.setVisibility(GONE); - } - } - - @OnClick(R.id.update_categories_button) - public void onUpdateCategoriesClicked() { - updateCategories(categoryEditSearchRecyclerViewAdapter.getNewCategories()); - displayHideCategorySearch(); - } - - @OnClick(R.id.cancel_categories_button) - public void onCancelCategoriesClicked() { - displayHideCategorySearch(); - } - - public void updateCategories(List selectedCategories) { - compositeDisposable.add(categoryEditHelper.makeCategoryEdit(getContext(), media, selectedCategories, this) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(s -> { - Timber.d("Categories are added."); - onOutsideOfCategoryEditClicked(); - media.setAddedCategories(selectedCategories); - updateCategoryList(); - })); - } - - @SuppressLint("StringFormatInvalid") @OnClick(R.id.nominateDeletion) public void onDeleteButtonClicked(){ if (AccountUtil.getUserName(getContext()) != null && AccountUtil.getUserName(getContext()).equals(media.getCreator())) { @@ -745,6 +424,7 @@ public void onTextChanged(CharSequence s, int start, int before, int count) { } } + @SuppressLint("CheckResult") private void onDeleteClicked(Spinner spinner) { String reason = spinner.getSelectedItem().toString(); @@ -794,50 +474,35 @@ private void enableDeleteButton(boolean visibility) { } } - private void rebuildCatList(List categories) { - Log.d("deneme","rebuild cat list size:"+categories.size()); + private void rebuildCatList() { categoryContainer.removeAllViews(); - for (String category : categories) { - categoryContainer.addView(buildCatLabel(sanitise(category), categoryContainer)); - } - } + // @fixme add the category items - //As per issue #1826(see https://github.com/commons-app/apps-android-commons/issues/1826), some categories come suffixed with strings prefixed with |. As per the discussion - //that was meant for alphabetical sorting of the categories and can be safely removed. - private String sanitise(String category) { - int indexOfPipe = category.indexOf('|'); - if (indexOfPipe != -1) { + //As per issue #1826(see https://github.com/commons-app/apps-android-commons/issues/1826), some categories come suffixed with strings prefixed with |. As per the discussion + //that was meant for alphabetical sorting of the categories and can be safely removed. + for (int i = 0; i < categoryNames.size(); i++) { + String categoryName = categoryNames.get(i); //Removed everything after '|' - return category.substring(0, indexOfPipe); + int indexOfPipe = categoryName.indexOf('|'); + if (indexOfPipe != -1) { + categoryName = categoryName.substring(0, indexOfPipe); + //Set the updated category to the list as well + categoryNames.set(i, categoryName); + } + View catLabel = buildCatLabel(categoryName, categoryContainer); + categoryContainer.addView(catLabel); } - return category; - } - - /** - * Add view to depictions obtained also tapping on depictions should open the url - */ - private View buildDepictLabel(String depictionName, String entityId, LinearLayout depictionContainer) { - final View item = LayoutInflater.from(getContext()).inflate(R.layout.detail_category_item, depictionContainer,false); - final TextView textView = item.findViewById(R.id.mediaDetailCategoryItemText); - textView.setText(depictionName); - item.setOnClickListener(view -> { - Intent intent = new Intent(getContext(), WikidataItemDetailsActivity.class); - intent.putExtra("wikidataItemName", depictionName); - intent.putExtra("entityId", entityId); - getContext().startActivity(intent); - }); - return item; } private View buildCatLabel(final String catName, ViewGroup categoryContainer) { final View item = LayoutInflater.from(getContext()).inflate(R.layout.detail_category_item, categoryContainer, false); - final TextView textView = item.findViewById(R.id.mediaDetailCategoryItemText); + final CompatTextView textView = item.findViewById(R.id.mediaDetailCategoryItemText); textView.setText(catName); - if(!getString(R.string.detail_panel_cats_none).equals(catName)) { + if (categoriesLoaded && categoriesPresent) { textView.setOnClickListener(view -> { // Open Category Details page - String selectedCategoryTitle = CATEGORY_PREFIX + catName; + String selectedCategoryTitle = "Category:" + catName; Intent intent = new Intent(getContext(), CategoryDetailsActivity.class); intent.putExtra("categoryName", selectedCategoryTitle); getContext().startActivity(intent); @@ -846,43 +511,34 @@ private View buildCatLabel(final String catName, ViewGroup categoryContainer) { return item; } - /** - * Returns captions for media details - * - * @param media object of class media - * @return caption as string - */ - private String prettyCaption(Media media) { - for (String caption : media.getCaptions().values()) { - if (caption.equals("")) { - return getString(R.string.detail_caption_empty); - } else { - return caption; - } + private void updateTheDarkness() { + // You must face the darkness alone + int scrollY = scrollView.getScrollY(); + int scrollMax = getView().getHeight(); + float scrollPercentage = (float) scrollY / (float) scrollMax; + final float transparencyMax = 0.75f; + if (scrollPercentage > transparencyMax) { + scrollPercentage = transparencyMax; } - return getString(R.string.detail_caption_empty); + image.setAlpha(1.0f - scrollPercentage); } private String prettyDescription(Media media) { - final String description = chooseDescription(media); - return description.isEmpty() ? getString(R.string.detail_description_empty) - : description; - } - - private String chooseDescription(Media media) { - final Map descriptions = media.getDescriptions(); - final String multilingualDesc = descriptions.get(Locale.getDefault().getLanguage()); - if (multilingualDesc != null) { - return multilingualDesc; - } - for (String description : descriptions.values()) { - return description; + // @todo use UI language when multilingual descs are available + String desc = media.getDescription(locale.getLanguage()).trim(); + if (desc.equals("")) { + return getString(R.string.detail_description_empty); + } else { + return desc; } - return media.getFallbackDescription(); } - - private String prettyDiscussion(String discussion) { - return discussion.isEmpty() ? getString(R.string.detail_discussion_empty) : discussion; + private String prettyDiscussion(Media media) { + String disc = media.getDiscussion().trim(); + if (disc.equals("")) { + return getString(R.string.detail_discussion_empty); + } else { + return disc; + } } private String prettyLicense(Media media) { @@ -914,13 +570,14 @@ private String prettyCoordinates(Media media) { return media.getCoordinates().getPrettyCoordinateString(); } - @Override - public boolean updateCategoryDisplay(List categories) { - if (categories == null) { - return false; - } else { - rebuildCatList(categories); - return true; + private void checkDeletion(Media media){ + if (media.getRequestedDeletion()){ + delete.setVisibility(GONE); + nominatedForDeletion.setVisibility(VISIBLE); + } else if (!isCategoryImage) { + delete.setVisibility(VISIBLE); + nominatedForDeletion.setVisibility(GONE); } } + }