mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Migrated Media Package to View Binding (#5601)
* Migrated Media Detail Fragment to View Binding * Migrated ZoomableActivity and PagerFragment * Improved Java doc * Improved Java doc
This commit is contained in:
parent
8df0055a5a
commit
7e9aa5b72a
7 changed files with 178 additions and 284 deletions
|
|
@ -31,29 +31,20 @@ import android.view.View.OnKeyListener;
|
|||
import android.view.ViewGroup;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
|
||||
import android.webkit.WebView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ListView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.ScrollView;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
import com.facebook.drawee.backends.pipeline.Fresco;
|
||||
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.mapbox.mapboxsdk.camera.CameraPosition;
|
||||
|
|
@ -72,6 +63,7 @@ import fr.free.nrw.commons.category.CategoryDetailsActivity;
|
|||
import fr.free.nrw.commons.category.CategoryEditHelper;
|
||||
import fr.free.nrw.commons.contributions.ContributionsFragment;
|
||||
import fr.free.nrw.commons.coordinates.CoordinateEditHelper;
|
||||
import fr.free.nrw.commons.databinding.FragmentMediaDetailBinding;
|
||||
import fr.free.nrw.commons.delete.DeleteHelper;
|
||||
import fr.free.nrw.commons.delete.ReasonBuilder;
|
||||
import fr.free.nrw.commons.description.DescriptionEditActivity;
|
||||
|
|
@ -178,81 +170,11 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
|||
JsonKvStore applicationKvStore;
|
||||
|
||||
private int initialListTop = 0;
|
||||
@BindView(R.id.description_webview)
|
||||
WebView descriptionWebView;
|
||||
@BindView(R.id.mediaDetailFrameLayout)
|
||||
FrameLayout frameLayout;
|
||||
@BindView(R.id.mediaDetailImageView)
|
||||
SimpleDraweeView image;
|
||||
@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.depictionsEditButton)
|
||||
Button depictEditButton;
|
||||
@BindView(R.id.media_detail_caption)
|
||||
TextView mediaCaption;
|
||||
@BindView(R.id.mediaDetailDesc)
|
||||
HtmlTextView desc;
|
||||
@BindView(R.id.mediaDetailAuthor)
|
||||
TextView author;
|
||||
@BindView(R.id.mediaDetailLicense)
|
||||
TextView license;
|
||||
@BindView(R.id.mediaDetailCoordinates)
|
||||
TextView coordinates;
|
||||
@BindView(R.id.mediaDetailuploadeddate)
|
||||
TextView uploadedDate;
|
||||
@BindView(R.id.mediaDetailDisc)
|
||||
TextView mediaDiscussion;
|
||||
@BindView(R.id.seeMore)
|
||||
TextView seeMore;
|
||||
@BindView(R.id.nominatedDeletionBanner)
|
||||
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.coordinate_edit)
|
||||
Button coordinateEditButton;
|
||||
@BindView(R.id.dummy_caption_description_container)
|
||||
LinearLayout showCaptionAndDescriptionContainer;
|
||||
@BindView(R.id.show_caption_description_textview)
|
||||
TextView showCaptionDescriptionTextView;
|
||||
@BindView(R.id.caption_listview)
|
||||
ListView captionsListView;
|
||||
@BindView(R.id.caption_label)
|
||||
TextView captionLabel;
|
||||
@BindView(R.id.description_label)
|
||||
TextView descriptionLabel;
|
||||
@BindView(R.id.pb_circular)
|
||||
ProgressBar progressBar;
|
||||
private FragmentMediaDetailBinding binding;
|
||||
String descriptionHtmlCode;
|
||||
@BindView(R.id.progressBarDeletion)
|
||||
ProgressBar progressBarDeletion;
|
||||
@BindView(R.id.progressBarEdit)
|
||||
ProgressBar progressBarEditDescription;
|
||||
@BindView(R.id.progressBarEditCategory)
|
||||
ProgressBar progressBarEditCategory;
|
||||
@BindView(R.id.description_edit)
|
||||
Button editDescription;
|
||||
@BindView(R.id.sendThanks)
|
||||
Button sendThanksButton;
|
||||
|
||||
|
||||
|
||||
|
||||
private ArrayList<String> categoryNames = new ArrayList<>();
|
||||
private String categorySearchQuery;
|
||||
|
|
@ -301,7 +223,7 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
|||
}
|
||||
|
||||
private void getScrollPosition() {
|
||||
initialListTop = scrollView.getScrollY();
|
||||
initialListTop = binding.mediaDetailScrollView.getScrollY();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -340,28 +262,45 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
|||
reasonListEnglishMappings.add(getLocalizedResources(getContext(), Locale.ENGLISH).getString(R.string.deletion_reason_no_longer_want_public));
|
||||
reasonListEnglishMappings.add(getLocalizedResources(getContext(), Locale.ENGLISH).getString(R.string.deletion_reason_bad_for_my_privacy));
|
||||
|
||||
final View view = inflater.inflate(R.layout.fragment_media_detail, container, false);
|
||||
binding = FragmentMediaDetailBinding.inflate(inflater, container, false);
|
||||
final View view = binding.getRoot();
|
||||
|
||||
ButterKnife.bind(this,view);
|
||||
Utils.setUnderlinedText(seeMore, R.string.nominated_see_more, requireContext());
|
||||
|
||||
Utils.setUnderlinedText(binding.seeMore, R.string.nominated_see_more, requireContext());
|
||||
|
||||
if (isCategoryImage){
|
||||
authorLayout.setVisibility(VISIBLE);
|
||||
binding.authorLinearLayout.setVisibility(VISIBLE);
|
||||
} else {
|
||||
authorLayout.setVisibility(GONE);
|
||||
binding.authorLinearLayout.setVisibility(GONE);
|
||||
}
|
||||
|
||||
if (!sessionManager.isUserLoggedIn()) {
|
||||
categoryEditButton.setVisibility(GONE);
|
||||
binding.categoryEditButton.setVisibility(GONE);
|
||||
}
|
||||
|
||||
if(applicationKvStore.getBoolean("login_skipped")){
|
||||
delete.setVisibility(GONE);
|
||||
coordinateEditButton.setVisibility(GONE);
|
||||
binding.nominateDeletion.setVisibility(GONE);
|
||||
binding.coordinateEdit.setVisibility(GONE);
|
||||
}
|
||||
|
||||
handleBackEvent(view);
|
||||
|
||||
//set onCLick listeners
|
||||
binding.mediaDetailLicense.setOnClickListener(v -> onMediaDetailLicenceClicked());
|
||||
binding.mediaDetailCoordinates.setOnClickListener(v -> onMediaDetailCoordinatesClicked());
|
||||
binding.sendThanks.setOnClickListener(v -> sendThanksToAuthor());
|
||||
binding.dummyCaptionDescriptionContainer.setOnClickListener(v -> showCaptionAndDescription());
|
||||
binding.mediaDetailImageView.setOnClickListener(v -> launchZoomActivity(binding.mediaDetailImageView));
|
||||
binding.categoryEditButton.setOnClickListener(v -> onCategoryEditButtonClicked());
|
||||
binding.depictionsEditButton.setOnClickListener(v -> onDepictionsEditButtonClicked());
|
||||
binding.seeMore.setOnClickListener(v -> onSeeMoreClicked());
|
||||
binding.mediaDetailAuthor.setOnClickListener(v -> onAuthorViewClicked());
|
||||
binding.nominateDeletion.setOnClickListener(v -> onDeleteButtonClicked());
|
||||
binding.descriptionEdit.setOnClickListener(v -> onDescriptionEditClicked());
|
||||
binding.coordinateEdit.setOnClickListener(v -> onUpdateCoordinatesClicked());
|
||||
binding.copyWikicode.setOnClickListener(v -> onCopyWikicodeClicked());
|
||||
|
||||
|
||||
/**
|
||||
* Gets the height of the frame layout as soon as the view is ready and updates aspect ratio
|
||||
* of the picture.
|
||||
|
|
@ -369,15 +308,14 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
|||
view.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
frameLayoutHeight = frameLayout.getMeasuredHeight();
|
||||
updateAspectRatio(scrollView.getWidth());
|
||||
frameLayoutHeight = binding.mediaDetailFrameLayout.getMeasuredHeight();
|
||||
updateAspectRatio(binding.mediaDetailScrollView.getWidth());
|
||||
}
|
||||
});
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@OnClick(R.id.mediaDetailImageViewSpacer)
|
||||
public void launchZoomActivity(final View view) {
|
||||
final boolean hasPermission = PermissionUtils.hasPermission(getActivity(), PermissionUtils.PERMISSIONS_STORAGE);
|
||||
if (hasPermission) {
|
||||
|
|
@ -445,20 +383,20 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
|||
|
||||
if (AccountUtil.getUserName(getContext()) != null && media != null
|
||||
&& AccountUtil.getUserName(getContext()).equals(media.getAuthor())) {
|
||||
sendThanksButton.setVisibility(GONE);
|
||||
binding.sendThanks.setVisibility(GONE);
|
||||
} else {
|
||||
sendThanksButton.setVisibility(VISIBLE);
|
||||
binding.sendThanks.setVisibility(VISIBLE);
|
||||
}
|
||||
|
||||
scrollView.getViewTreeObserver().addOnGlobalLayoutListener(
|
||||
binding.mediaDetailScrollView.getViewTreeObserver().addOnGlobalLayoutListener(
|
||||
new OnGlobalLayoutListener() {
|
||||
@Override
|
||||
public void onGlobalLayout() {
|
||||
if (getContext() == null) {
|
||||
return;
|
||||
}
|
||||
scrollView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
||||
oldWidthOfImageView = scrollView.getWidth();
|
||||
binding.mediaDetailScrollView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
||||
oldWidthOfImageView = binding.mediaDetailScrollView.getWidth();
|
||||
if(media != null) {
|
||||
displayMediaDetails();
|
||||
}
|
||||
|
|
@ -470,26 +408,26 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
|||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
scrollView.getViewTreeObserver().addOnGlobalLayoutListener(
|
||||
binding.mediaDetailScrollView.getViewTreeObserver().addOnGlobalLayoutListener(
|
||||
new OnGlobalLayoutListener() {
|
||||
@Override
|
||||
public void onGlobalLayout() {
|
||||
/**
|
||||
* We update the height of the frame layout as the configuration changes.
|
||||
*/
|
||||
frameLayout.post(new Runnable() {
|
||||
binding.mediaDetailFrameLayout.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
frameLayoutHeight = frameLayout.getMeasuredHeight();
|
||||
updateAspectRatio(scrollView.getWidth());
|
||||
frameLayoutHeight = binding.mediaDetailFrameLayout.getMeasuredHeight();
|
||||
updateAspectRatio(binding.mediaDetailScrollView.getWidth());
|
||||
}
|
||||
});
|
||||
if (scrollView.getWidth() != oldWidthOfImageView) {
|
||||
if (binding.mediaDetailScrollView.getWidth() != oldWidthOfImageView) {
|
||||
if (newWidthOfImageView == 0) {
|
||||
newWidthOfImageView = scrollView.getWidth();
|
||||
newWidthOfImageView = binding.mediaDetailScrollView.getWidth();
|
||||
updateAspectRatio(newWidthOfImageView);
|
||||
}
|
||||
scrollView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
||||
binding.mediaDetailScrollView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -541,36 +479,36 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
|||
}
|
||||
|
||||
private void onDiscussionLoaded(String discussion) {
|
||||
mediaDiscussion.setText(prettyDiscussion(discussion.trim()));
|
||||
binding.mediaDetailDisc.setText(prettyDiscussion(discussion.trim()));
|
||||
}
|
||||
|
||||
private void onDeletionPageExists(Boolean deletionPageExists) {
|
||||
if (deletionPageExists){
|
||||
if(applicationKvStore.getBoolean(String.format(NOMINATING_FOR_DELETION_MEDIA, media.getImageUrl()), false)) {
|
||||
applicationKvStore.remove(String.format(NOMINATING_FOR_DELETION_MEDIA, media.getImageUrl()));
|
||||
progressBarDeletion.setVisibility(GONE);
|
||||
binding.progressBarDeletion.setVisibility(GONE);
|
||||
}
|
||||
delete.setVisibility(GONE);
|
||||
nominatedForDeletion.setVisibility(VISIBLE);
|
||||
binding.nominateDeletion.setVisibility(GONE);
|
||||
binding.nominatedDeletionBanner.setVisibility(VISIBLE);
|
||||
} else if (!isCategoryImage) {
|
||||
delete.setVisibility(VISIBLE);
|
||||
nominatedForDeletion.setVisibility(GONE);
|
||||
binding.nominateDeletion.setVisibility(VISIBLE);
|
||||
binding.nominatedDeletionBanner.setVisibility(GONE);
|
||||
}
|
||||
}
|
||||
|
||||
private void onDepictionsLoaded(List<IdAndCaptions> idAndCaptions){
|
||||
depictsLayout.setVisibility(idAndCaptions.isEmpty() ? GONE : VISIBLE);
|
||||
depictEditButton.setVisibility(idAndCaptions.isEmpty() ? GONE : VISIBLE);
|
||||
binding.depictsLayout.setVisibility(idAndCaptions.isEmpty() ? GONE : VISIBLE);
|
||||
binding.depictionsEditButton.setVisibility(idAndCaptions.isEmpty() ? GONE : VISIBLE);
|
||||
buildDepictionList(idAndCaptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* By clicking on the edit depictions button, it will send user to depict fragment
|
||||
*/
|
||||
@OnClick(R.id.depictionsEditButton)
|
||||
|
||||
public void onDepictionsEditButtonClicked() {
|
||||
depictionContainer.removeAllViews();
|
||||
depictEditButton.setVisibility(GONE);
|
||||
binding.mediaDetailDepictionContainer.removeAllViews();
|
||||
binding.depictionsEditButton.setVisibility(GONE);
|
||||
final Fragment depictsFragment = new DepictsFragment();
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putParcelable("Existing_Depicts", media);
|
||||
|
|
@ -595,8 +533,8 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
|||
private void updateAspectRatio(int scrollWidth) {
|
||||
if (imageInfoCache != null) {
|
||||
int finalHeight = (scrollWidth*imageInfoCache.getHeight()) / imageInfoCache.getWidth();
|
||||
ViewGroup.LayoutParams params = image.getLayoutParams();
|
||||
ViewGroup.LayoutParams spacerParams = imageSpacer.getLayoutParams();
|
||||
ViewGroup.LayoutParams params = binding.mediaDetailImageView.getLayoutParams();
|
||||
ViewGroup.LayoutParams spacerParams = binding.mediaDetailImageViewSpacer.getLayoutParams();
|
||||
params.width = scrollWidth;
|
||||
if(finalHeight > frameLayoutHeight - minimumHeightOfMetadata) {
|
||||
|
||||
|
|
@ -608,8 +546,8 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
|||
}
|
||||
params.height = finalHeight;
|
||||
spacerParams.height = finalHeight;
|
||||
image.setLayoutParams(params);
|
||||
imageSpacer.setLayoutParams(spacerParams);
|
||||
binding.mediaDetailImageView.setLayoutParams(params);
|
||||
binding.mediaDetailImageViewSpacer.setLayoutParams(spacerParams);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -617,12 +555,12 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
|||
@Override
|
||||
public void onIntermediateImageSet(String id, @Nullable ImageInfo imageInfo) {
|
||||
imageInfoCache = imageInfo;
|
||||
updateAspectRatio(scrollView.getWidth());
|
||||
updateAspectRatio(binding.mediaDetailScrollView.getWidth());
|
||||
}
|
||||
@Override
|
||||
public void onFinalImageSet(String id, @Nullable ImageInfo imageInfo, @Nullable Animatable animatable) {
|
||||
imageInfoCache = imageInfo;
|
||||
updateAspectRatio(scrollView.getWidth());
|
||||
updateAspectRatio(binding.mediaDetailScrollView.getWidth());
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -634,20 +572,20 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
|||
private void setupImageView() {
|
||||
int imageBackgroundColor = getImageBackgroundColor();
|
||||
if (imageBackgroundColor != DEFAULT_IMAGE_BACKGROUND_COLOR) {
|
||||
image.setBackgroundColor(imageBackgroundColor);
|
||||
binding.mediaDetailImageView.setBackgroundColor(imageBackgroundColor);
|
||||
}
|
||||
|
||||
image.getHierarchy().setPlaceholderImage(R.drawable.image_placeholder);
|
||||
image.getHierarchy().setFailureImage(R.drawable.image_placeholder);
|
||||
binding.mediaDetailImageView.getHierarchy().setPlaceholderImage(R.drawable.image_placeholder);
|
||||
binding.mediaDetailImageView.getHierarchy().setFailureImage(R.drawable.image_placeholder);
|
||||
|
||||
DraweeController controller = Fresco.newDraweeControllerBuilder()
|
||||
.setLowResImageRequest(ImageRequest.fromUri(media != null ? media.getThumbUrl() : null))
|
||||
.setRetainImageOnFailure(true)
|
||||
.setImageRequest(ImageRequest.fromUri(media != null ? media.getImageUrl() : null))
|
||||
.setControllerListener(aspectRatioListener)
|
||||
.setOldController(image.getController())
|
||||
.setOldController(binding.mediaDetailImageView.getController())
|
||||
.build();
|
||||
image.setController(controller);
|
||||
binding.mediaDetailImageView.setController(controller);
|
||||
}
|
||||
|
||||
private void updateToDoWarning() {
|
||||
|
|
@ -676,10 +614,10 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
|||
|
||||
if (toDoNeeded) {
|
||||
toDoMessage = getString(R.string.todo_improve) + "\n" + toDoMessage;
|
||||
toDoLayout.setVisibility(VISIBLE);
|
||||
toDoReason.setText(toDoMessage);
|
||||
binding.toDoLayout.setVisibility(VISIBLE);
|
||||
binding.toDoReason.setText(toDoMessage);
|
||||
} else {
|
||||
toDoLayout.setVisibility(GONE);
|
||||
binding.toDoLayout.setVisibility(GONE);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -696,24 +634,24 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
|||
|
||||
private void setTextFields(Media media) {
|
||||
setupImageView();
|
||||
title.setText(media.getDisplayTitle());
|
||||
desc.setHtmlText(prettyDescription(media));
|
||||
license.setText(prettyLicense(media));
|
||||
coordinates.setText(prettyCoordinates(media));
|
||||
uploadedDate.setText(prettyUploadedDate(media));
|
||||
binding.mediaDetailTitle.setText(media.getDisplayTitle());
|
||||
binding.mediaDetailDesc.setHtmlText(prettyDescription(media));
|
||||
binding.mediaDetailLicense.setText(prettyLicense(media));
|
||||
binding.mediaDetailCoordinates.setText(prettyCoordinates(media));
|
||||
binding.mediaDetailuploadeddate.setText(prettyUploadedDate(media));
|
||||
if (prettyCaption(media).equals(getContext().getString(R.string.detail_caption_empty))) {
|
||||
captionLayout.setVisibility(GONE);
|
||||
binding.captionLayout.setVisibility(GONE);
|
||||
} else {
|
||||
mediaCaption.setText(prettyCaption(media));
|
||||
binding.mediaDetailCaption.setText(prettyCaption(media));
|
||||
}
|
||||
|
||||
categoryNames.clear();
|
||||
categoryNames.addAll(media.getCategories());
|
||||
|
||||
if (media.getAuthor() == null || media.getAuthor().equals("")) {
|
||||
authorLayout.setVisibility(GONE);
|
||||
binding.authorLinearLayout.setVisibility(GONE);
|
||||
} else {
|
||||
author.setText(media.getAuthor());
|
||||
binding.mediaDetailAuthor.setText(media.getAuthor());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -736,7 +674,7 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
|||
// Stick in a filler element.
|
||||
allCategories.add(getString(R.string.detail_panel_cats_none));
|
||||
}
|
||||
categoryEditButton.setVisibility(VISIBLE);
|
||||
binding.categoryEditButton.setVisibility(VISIBLE);
|
||||
rebuildCatList(allCategories);
|
||||
}
|
||||
|
||||
|
|
@ -759,13 +697,13 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
|||
* @param idAndCaptions
|
||||
*/
|
||||
private void buildDepictionList(List<IdAndCaptions> idAndCaptions) {
|
||||
depictionContainer.removeAllViews();
|
||||
binding.mediaDetailDepictionContainer.removeAllViews();
|
||||
String locale = Locale.getDefault().getLanguage();
|
||||
for (IdAndCaptions idAndCaption : idAndCaptions) {
|
||||
depictionContainer.addView(buildDepictLabel(
|
||||
binding.mediaDetailDepictionContainer.addView(buildDepictLabel(
|
||||
getDepictionCaption(idAndCaption, locale),
|
||||
idAndCaption.getId(),
|
||||
depictionContainer
|
||||
binding.mediaDetailDepictionContainer
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
@ -781,7 +719,6 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
|||
return idAndCaption.getCaptions().values().iterator().next();
|
||||
}
|
||||
|
||||
@OnClick(R.id.mediaDetailLicense)
|
||||
public void onMediaDetailLicenceClicked(){
|
||||
String url = media.getLicenseUrl();
|
||||
if (!StringUtils.isBlank(url) && getActivity() != null) {
|
||||
|
|
@ -791,14 +728,12 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
|||
}
|
||||
}
|
||||
|
||||
@OnClick(R.id.mediaDetailCoordinates)
|
||||
public void onMediaDetailCoordinatesClicked(){
|
||||
if (media.getCoordinates() != null && getActivity() != null) {
|
||||
Utils.handleGeoCoordinates(getActivity(), media.getCoordinates());
|
||||
}
|
||||
}
|
||||
|
||||
@OnClick(R.id.copyWikicode)
|
||||
public void onCopyWikicodeClicked() {
|
||||
String data =
|
||||
"[[" + media.getFilename() + "|thumb|" + media.getFallbackDescription() + "]]";
|
||||
|
|
@ -812,7 +747,6 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
|||
/**
|
||||
* Sends thanks to author if the author is not the user
|
||||
*/
|
||||
@OnClick(R.id.sendThanks)
|
||||
public void sendThanksToAuthor() {
|
||||
String fileName = media.getFilename();
|
||||
if (TextUtils.isEmpty(fileName)) {
|
||||
|
|
@ -872,10 +806,9 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
|||
ViewUtil.showShortToast(context, message);
|
||||
}
|
||||
|
||||
@OnClick(R.id.categoryEditButton)
|
||||
public void onCategoryEditButtonClicked(){
|
||||
progressBarEditCategory.setVisibility(VISIBLE);
|
||||
categoryEditButton.setVisibility(GONE);
|
||||
binding.progressBarEditCategory.setVisibility(VISIBLE);
|
||||
binding.categoryEditButton.setVisibility(GONE);
|
||||
getWikiText();
|
||||
}
|
||||
|
||||
|
|
@ -896,8 +829,8 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
|||
* @param s WikiText
|
||||
*/
|
||||
private void gotoCategoryEditor(final String s) {
|
||||
categoryEditButton.setVisibility(VISIBLE);
|
||||
progressBarEditCategory.setVisibility(GONE);
|
||||
binding.categoryEditButton.setVisibility(VISIBLE);
|
||||
binding.progressBarEditCategory.setVisibility(GONE);
|
||||
final Fragment categoriesFragment = new UploadCategoriesFragment();
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putParcelable("Existing_Categories", media);
|
||||
|
|
@ -909,7 +842,6 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
|||
transaction.commit();
|
||||
}
|
||||
|
||||
@OnClick(R.id.coordinate_edit)
|
||||
public void onUpdateCoordinatesClicked(){
|
||||
goToLocationPickerActivity();
|
||||
}
|
||||
|
|
@ -948,10 +880,9 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
|||
.build(getActivity()));
|
||||
}
|
||||
|
||||
@OnClick(R.id.description_edit)
|
||||
public void onDescriptionEditClicked() {
|
||||
progressBarEditDescription.setVisibility(VISIBLE);
|
||||
editDescription.setVisibility(GONE);
|
||||
binding.progressBarEdit.setVisibility(VISIBLE);
|
||||
binding.descriptionEdit.setVisibility(GONE);
|
||||
getDescriptionList();
|
||||
}
|
||||
|
||||
|
|
@ -1148,12 +1079,12 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
|||
Timber.d("Caption is added.");
|
||||
}));
|
||||
}
|
||||
progressBarEditDescription.setVisibility(GONE);
|
||||
editDescription.setVisibility(VISIBLE);
|
||||
binding.progressBarEdit.setVisibility(GONE);
|
||||
binding.descriptionEdit.setVisibility(VISIBLE);
|
||||
|
||||
} else if (requestCode == REQUEST_CODE_EDIT_DESCRIPTION && resultCode == RESULT_CANCELED) {
|
||||
progressBarEditDescription.setVisibility(GONE);
|
||||
editDescription.setVisibility(VISIBLE);
|
||||
binding.progressBarEdit.setVisibility(GONE);
|
||||
binding.descriptionEdit.setVisibility(VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1169,7 +1100,6 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
|||
}
|
||||
|
||||
@SuppressLint("StringFormatInvalid")
|
||||
@OnClick(R.id.nominateDeletion)
|
||||
public void onDeleteButtonClicked(){
|
||||
if (AccountUtil.getUserName(getContext()) != null && AccountUtil.getUserName(getContext()).equals(media.getAuthor())) {
|
||||
final ArrayAdapter<String> languageAdapter = new ArrayAdapter<>(getActivity(),
|
||||
|
|
@ -1275,14 +1205,12 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
|||
});
|
||||
}
|
||||
|
||||
@OnClick(R.id.seeMore)
|
||||
public void onSeeMoreClicked(){
|
||||
if (nominatedForDeletion.getVisibility() == VISIBLE && getActivity() != null) {
|
||||
if (binding.nominatedDeletionBanner.getVisibility() == VISIBLE && getActivity() != null) {
|
||||
Utils.handleWebUrl(getActivity(), Uri.parse(media.getPageTitle().getMobileUri()));
|
||||
}
|
||||
}
|
||||
|
||||
@OnClick(R.id.mediaDetailAuthor)
|
||||
public void onAuthorViewClicked() {
|
||||
if (media == null || media.getUser() == null) {
|
||||
return;
|
||||
|
|
@ -1301,15 +1229,15 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
|||
* Enable Progress Bar and Update delete button text.
|
||||
*/
|
||||
private void enableProgressBar() {
|
||||
progressBarDeletion.setVisibility(VISIBLE);
|
||||
delete.setText("Nominating for Deletion");
|
||||
binding.progressBarDeletion.setVisibility(VISIBLE);
|
||||
binding.nominateDeletion.setText("Nominating for Deletion");
|
||||
isDeleted = true;
|
||||
}
|
||||
|
||||
private void rebuildCatList(List<String> categories) {
|
||||
categoryContainer.removeAllViews();
|
||||
binding.mediaDetailCategoryContainer.removeAllViews();
|
||||
for (String category : categories) {
|
||||
categoryContainer.addView(buildCatLabel(sanitise(category), categoryContainer));
|
||||
binding.mediaDetailCategoryContainer.addView(buildCatLabel(sanitise(category), binding.mediaDetailCategoryContainer));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1435,13 +1363,12 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
|||
}
|
||||
}
|
||||
|
||||
@OnClick(R.id.show_caption_description_textview)
|
||||
void showCaptionAndDescription() {
|
||||
if (showCaptionAndDescriptionContainer.getVisibility() == GONE) {
|
||||
showCaptionAndDescriptionContainer.setVisibility(VISIBLE);
|
||||
if (binding.dummyCaptionDescriptionContainer.getVisibility() == GONE) {
|
||||
binding.dummyCaptionDescriptionContainer.setVisibility(VISIBLE);
|
||||
setUpCaptionAndDescriptionLayout();
|
||||
} else {
|
||||
showCaptionAndDescriptionContainer.setVisibility(GONE);
|
||||
binding.dummyCaptionDescriptionContainer.setVisibility(GONE);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1452,12 +1379,12 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
|||
List<Caption> captions = getCaptions();
|
||||
|
||||
if (descriptionHtmlCode == null) {
|
||||
progressBar.setVisibility(VISIBLE);
|
||||
binding.showCaptionsBinding.pbCircular.setVisibility(VISIBLE);
|
||||
}
|
||||
|
||||
getDescription();
|
||||
CaptionListViewAdapter adapter = new CaptionListViewAdapter(captions);
|
||||
captionsListView.setAdapter(adapter);
|
||||
binding.showCaptionsBinding.captionListview.setAdapter(adapter);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1480,7 +1407,8 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
|||
}
|
||||
|
||||
private void getDescription() {
|
||||
compositeDisposable.add(mediaDataExtractor.getHtmlOfPage(media.getFilename())
|
||||
compositeDisposable.add(mediaDataExtractor.getHtmlOfPage(
|
||||
Objects.requireNonNull(media.getFilename()))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(this::extractDescription, Timber::e));
|
||||
|
|
@ -1498,9 +1426,9 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
|||
descriptionHtmlCode = descriptionHtmlCode + s.toCharArray()[i];
|
||||
}
|
||||
|
||||
descriptionWebView
|
||||
binding.showCaptionsBinding.descriptionWebview
|
||||
.loadDataWithBaseURL(null, descriptionHtmlCode, "text/html", "utf-8", null);
|
||||
progressBar.setVisibility(GONE);
|
||||
binding.showCaptionsBinding.pbCircular.setVisibility(GONE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1513,8 +1441,8 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
|||
@Override
|
||||
public boolean onKey(View view, int keycode, KeyEvent keyEvent) {
|
||||
if (keycode == KeyEvent.KEYCODE_BACK) {
|
||||
if (showCaptionAndDescriptionContainer.getVisibility() == VISIBLE) {
|
||||
showCaptionAndDescriptionContainer.setVisibility(GONE);
|
||||
if (binding.dummyCaptionDescriptionContainer.getVisibility() == VISIBLE) {
|
||||
binding.dummyCaptionDescriptionContainer.setVisibility(GONE);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1540,7 +1468,7 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
|||
return;
|
||||
}
|
||||
|
||||
image.setBackgroundColor(color);
|
||||
binding.mediaDetailImageView.setBackgroundColor(color);
|
||||
getImageBackgroundColorPref().edit().putInt(IMAGE_BACKGROUND_COLOR, color).apply();
|
||||
}
|
||||
|
||||
|
|
@ -1552,5 +1480,4 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
|||
SharedPreferences imageBackgroundColorPref = this.getImageBackgroundColorPref();
|
||||
return imageBackgroundColorPref.getInt(IMAGE_BACKGROUND_COLOR, DEFAULT_IMAGE_BACKGROUND_COLOR);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,8 +24,6 @@ import androidx.fragment.app.Fragment;
|
|||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentStatePagerAdapter;
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import fr.free.nrw.commons.CommonsApplication;
|
||||
import fr.free.nrw.commons.Media;
|
||||
|
|
@ -36,6 +34,7 @@ import fr.free.nrw.commons.bookmarks.pictures.BookmarkPicturesContentProvider;
|
|||
import fr.free.nrw.commons.bookmarks.pictures.BookmarkPicturesDao;
|
||||
import fr.free.nrw.commons.contributions.Contribution;
|
||||
import fr.free.nrw.commons.contributions.MainActivity;
|
||||
import fr.free.nrw.commons.databinding.FragmentMediaDetailPagerBinding;
|
||||
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
|
||||
import fr.free.nrw.commons.mwapi.OkHttpJsonApiClient;
|
||||
import fr.free.nrw.commons.profile.ProfileActivity;
|
||||
|
|
@ -66,7 +65,8 @@ public class MediaDetailPagerFragment extends CommonsDaggerSupportFragment imple
|
|||
|
||||
private static CompositeDisposable compositeDisposable = new CompositeDisposable();
|
||||
|
||||
@BindView(R.id.mediaDetailsPager) ViewPager pager;
|
||||
private FragmentMediaDetailPagerBinding binding;
|
||||
|
||||
private boolean editable;
|
||||
private boolean isFeaturedImage;
|
||||
private boolean isWikipediaButtonDisplayed;
|
||||
|
|
@ -114,9 +114,8 @@ public class MediaDetailPagerFragment extends CommonsDaggerSupportFragment imple
|
|||
public View onCreateView(LayoutInflater inflater,
|
||||
ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_media_detail_pager, container, false);
|
||||
ButterKnife.bind(this,view);
|
||||
pager.addOnPageChangeListener(this);
|
||||
binding = FragmentMediaDetailPagerBinding.inflate(inflater, container, false);
|
||||
binding.mediaDetailsPager.addOnPageChangeListener(this);
|
||||
|
||||
adapter = new MediaDetailAdapter(getChildFragmentManager());
|
||||
|
||||
|
|
@ -139,22 +138,22 @@ public class MediaDetailPagerFragment extends CommonsDaggerSupportFragment imple
|
|||
((MainActivity)getActivity()).hideTabs();
|
||||
}
|
||||
|
||||
pager.setAdapter(adapter);
|
||||
binding.mediaDetailsPager.setAdapter(adapter);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
final int pageNumber = savedInstanceState.getInt("current-page");
|
||||
pager.setCurrentItem(pageNumber, false);
|
||||
binding.mediaDetailsPager.setCurrentItem(pageNumber, false);
|
||||
getActivity().invalidateOptionsMenu();
|
||||
}
|
||||
adapter.notifyDataSetChanged();
|
||||
|
||||
return view;
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putInt("current-page", pager.getCurrentItem());
|
||||
outState.putInt("current-page", binding.mediaDetailsPager.getCurrentItem());
|
||||
outState.putBoolean("editable", editable);
|
||||
outState.putBoolean("isFeaturedImage", isFeaturedImage);
|
||||
}
|
||||
|
|
@ -165,8 +164,8 @@ public class MediaDetailPagerFragment extends CommonsDaggerSupportFragment imple
|
|||
if (savedInstanceState != null) {
|
||||
editable = savedInstanceState.getBoolean("editable", false);
|
||||
isFeaturedImage = savedInstanceState.getBoolean("isFeaturedImage", false);
|
||||
if(null != pager) {
|
||||
pager.setCurrentItem(savedInstanceState.getInt("current-page", 0), false);
|
||||
if(null != binding.mediaDetailsPager) {
|
||||
binding.mediaDetailsPager.setCurrentItem(savedInstanceState.getInt("current-page", 0), false);
|
||||
}
|
||||
}
|
||||
setHasOptionsMenu(true);
|
||||
|
|
@ -196,7 +195,7 @@ public class MediaDetailPagerFragment extends CommonsDaggerSupportFragment imple
|
|||
return true;
|
||||
}
|
||||
|
||||
Media m = provider.getMediaAtPosition(pager.getCurrentItem());
|
||||
Media m = provider.getMediaAtPosition(binding.mediaDetailsPager.getCurrentItem());
|
||||
MediaDetailFragment mediaDetailFragment = this.adapter.getCurrentMediaDetailFragment();
|
||||
switch (item.getItemId()) {
|
||||
case R.id.menu_bookmark_current_image:
|
||||
|
|
@ -367,7 +366,7 @@ public class MediaDetailPagerFragment extends CommonsDaggerSupportFragment imple
|
|||
if (!editable) { // Disable menu options for editable views
|
||||
menu.clear(); // see http://stackoverflow.com/a/8495697/17865
|
||||
inflater.inflate(R.menu.fragment_image_detail, menu);
|
||||
if (pager != null) {
|
||||
if (binding.mediaDetailsPager != null) {
|
||||
MediaDetailProvider provider = getMediaDetailProvider();
|
||||
if(provider == null) {
|
||||
return;
|
||||
|
|
@ -376,7 +375,7 @@ public class MediaDetailPagerFragment extends CommonsDaggerSupportFragment imple
|
|||
if (isFromFeaturedRootFragment) {
|
||||
position = this.position;
|
||||
} else {
|
||||
position = pager.getCurrentItem();
|
||||
position = binding.mediaDetailsPager.getCurrentItem();
|
||||
}
|
||||
|
||||
Media m = provider.getMediaAtPosition(position);
|
||||
|
|
@ -473,13 +472,13 @@ public class MediaDetailPagerFragment extends CommonsDaggerSupportFragment imple
|
|||
private void updateBookmarkState(MenuItem item) {
|
||||
boolean isBookmarked = bookmarkDao.findBookmark(bookmark);
|
||||
if(isBookmarked) {
|
||||
if(removedItems.contains(pager.getCurrentItem())) {
|
||||
removedItems.remove(new Integer(pager.getCurrentItem()));
|
||||
if(removedItems.contains(binding.mediaDetailsPager.getCurrentItem())) {
|
||||
removedItems.remove(new Integer(binding.mediaDetailsPager.getCurrentItem()));
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(!removedItems.contains(pager.getCurrentItem())) {
|
||||
removedItems.add(pager.getCurrentItem());
|
||||
if(!removedItems.contains(binding.mediaDetailsPager.getCurrentItem())) {
|
||||
removedItems.add(binding.mediaDetailsPager.getCurrentItem());
|
||||
}
|
||||
}
|
||||
int icon = isBookmarked ? R.drawable.menu_ic_round_star_filled_24px : R.drawable.menu_ic_round_star_border_24px;
|
||||
|
|
@ -506,7 +505,7 @@ public class MediaDetailPagerFragment extends CommonsDaggerSupportFragment imple
|
|||
public void run() {
|
||||
while(currentItemNotShown[0]){
|
||||
if(adapter.getCount() > position){
|
||||
pager.setCurrentItem(position, false);
|
||||
binding.mediaDetailsPager.setCurrentItem(position, false);
|
||||
currentItemNotShown[0] = false;
|
||||
}
|
||||
}
|
||||
|
|
@ -589,7 +588,7 @@ public class MediaDetailPagerFragment extends CommonsDaggerSupportFragment imple
|
|||
Timber.d("Skipping getItem. Returning as activity is destroyed!");
|
||||
return null;
|
||||
}
|
||||
pager.postDelayed(() -> getActivity().invalidateOptionsMenu(), 5);
|
||||
binding.mediaDetailsPager.postDelayed(() -> getActivity().invalidateOptionsMenu(), 5);
|
||||
}
|
||||
if (isFromFeaturedRootFragment) {
|
||||
return MediaDetailFragment.forMedia(position+i, editable, isFeaturedImage, isWikipediaButtonDisplayed);
|
||||
|
|
|
|||
|
|
@ -15,8 +15,6 @@ import android.widget.TextView
|
|||
import android.widget.Toast
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import butterknife.BindView
|
||||
import butterknife.ButterKnife
|
||||
import com.facebook.drawee.backends.pipeline.Fresco
|
||||
import com.facebook.drawee.controller.BaseControllerListener
|
||||
import com.facebook.drawee.controller.ControllerListener
|
||||
|
|
@ -38,6 +36,7 @@ import fr.free.nrw.commons.customselector.model.Image
|
|||
import fr.free.nrw.commons.customselector.model.Result
|
||||
import fr.free.nrw.commons.customselector.ui.selector.CustomSelectorViewModel
|
||||
import fr.free.nrw.commons.customselector.ui.selector.CustomSelectorViewModelFactory
|
||||
import fr.free.nrw.commons.databinding.ActivityZoomableBinding
|
||||
import fr.free.nrw.commons.media.zoomControllers.zoomable.DoubleTapGestureListener
|
||||
import fr.free.nrw.commons.media.zoomControllers.zoomable.ZoomableDraweeView
|
||||
import fr.free.nrw.commons.theme.BaseActivity
|
||||
|
|
@ -67,20 +66,10 @@ class ZoomableActivity : BaseActivity() {
|
|||
*/
|
||||
private lateinit var prefs: SharedPreferences
|
||||
|
||||
@JvmField
|
||||
@BindView(R.id.zoomable)
|
||||
var photo: ZoomableDraweeView? = null
|
||||
private lateinit var binding: ActivityZoomableBinding
|
||||
|
||||
var photoBackgroundColor: Int? = null
|
||||
|
||||
@JvmField
|
||||
@BindView(R.id.zoom_progress_bar)
|
||||
var spinner: ProgressBar? = null
|
||||
|
||||
@JvmField
|
||||
@BindView(R.id.selection_count)
|
||||
var selectedCount: TextView? = null
|
||||
|
||||
/**
|
||||
* Total images present in folder
|
||||
*/
|
||||
|
|
@ -145,8 +134,8 @@ class ZoomableActivity : BaseActivity() {
|
|||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_zoomable)
|
||||
ButterKnife.bind(this)
|
||||
binding = ActivityZoomableBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
prefs = applicationContext.getSharedPreferences(
|
||||
ImageHelper.CUSTOM_SELECTOR_PREFERENCE_KEY,
|
||||
|
|
@ -221,7 +210,7 @@ class ZoomableActivity : BaseActivity() {
|
|||
onSwipe()
|
||||
}
|
||||
}
|
||||
spinner?.let {
|
||||
binding.zoomProgressBar?.let {
|
||||
it.visibility = if (result.status is CallbackStatus.FETCHING) View.VISIBLE else View.GONE
|
||||
}
|
||||
}
|
||||
|
|
@ -236,7 +225,7 @@ class ZoomableActivity : BaseActivity() {
|
|||
sharedPreferences.getBoolean(ImageHelper.SHOW_ALREADY_ACTIONED_IMAGES_PREFERENCE_KEY, true)
|
||||
|
||||
if (!images.isNullOrEmpty()) {
|
||||
photo!!.setOnTouchListener(object : OnSwipeTouchListener(this) {
|
||||
binding.zoomable!!.setOnTouchListener(object : OnSwipeTouchListener(this) {
|
||||
// Swipe left to view next image in the folder. (if available)
|
||||
override fun onSwipeLeft() {
|
||||
super.onSwipeLeft()
|
||||
|
|
@ -271,7 +260,7 @@ class ZoomableActivity : BaseActivity() {
|
|||
* Handles down swipe action
|
||||
*/
|
||||
private fun onDownSwiped() {
|
||||
if (photo?.zoomableController?.isIdentity == false)
|
||||
if (binding.zoomable?.zoomableController?.isIdentity == false)
|
||||
return
|
||||
|
||||
scope.launch {
|
||||
|
|
@ -333,7 +322,7 @@ class ZoomableActivity : BaseActivity() {
|
|||
* Handles up swipe action
|
||||
*/
|
||||
private fun onUpSwiped() {
|
||||
if (photo?.zoomableController?.isIdentity == false)
|
||||
if (binding.zoomable?.zoomableController?.isIdentity == false)
|
||||
return
|
||||
|
||||
scope.launch {
|
||||
|
|
@ -398,7 +387,7 @@ class ZoomableActivity : BaseActivity() {
|
|||
* Handles right swipe action
|
||||
*/
|
||||
private fun onRightSwiped(showAlreadyActionedImages: Boolean) {
|
||||
if (photo?.zoomableController?.isIdentity == false)
|
||||
if (binding.zoomable?.zoomableController?.isIdentity == false)
|
||||
return
|
||||
|
||||
if (showAlreadyActionedImages) {
|
||||
|
|
@ -432,7 +421,7 @@ class ZoomableActivity : BaseActivity() {
|
|||
* Handles left swipe action
|
||||
*/
|
||||
private fun onLeftSwiped(showAlreadyActionedImages: Boolean) {
|
||||
if (photo?.zoomableController?.isIdentity == false)
|
||||
if (binding.zoomable?.zoomableController?.isIdentity == false)
|
||||
return
|
||||
|
||||
if (showAlreadyActionedImages) {
|
||||
|
|
@ -558,15 +547,15 @@ class ZoomableActivity : BaseActivity() {
|
|||
* Unselect item UI
|
||||
*/
|
||||
private fun itemUnselected() {
|
||||
selectedCount!!.visibility = View.INVISIBLE
|
||||
binding.selectionCount.visibility = View.INVISIBLE
|
||||
}
|
||||
|
||||
/**
|
||||
* Select item UI
|
||||
*/
|
||||
private fun itemSelected(i: Int) {
|
||||
selectedCount!!.visibility = View.VISIBLE
|
||||
selectedCount!!.text = i.toString()
|
||||
binding.selectionCount.visibility = View.VISIBLE
|
||||
binding.selectionCount.text = i.toString()
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -586,11 +575,11 @@ class ZoomableActivity : BaseActivity() {
|
|||
object : BaseControllerListener<ImageInfo?>() {
|
||||
override fun onSubmit(id: String, callerContext: Any) {
|
||||
// Sometimes the spinner doesn't appear when rapidly switching between images, this fixes that
|
||||
spinner!!.visibility = View.VISIBLE
|
||||
binding.zoomProgressBar.visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
override fun onIntermediateImageSet(id: String, imageInfo: ImageInfo?) {
|
||||
spinner!!.visibility = View.GONE
|
||||
binding.zoomProgressBar.visibility = View.GONE
|
||||
}
|
||||
|
||||
override fun onFinalImageSet(
|
||||
|
|
@ -598,7 +587,7 @@ class ZoomableActivity : BaseActivity() {
|
|||
imageInfo: ImageInfo?,
|
||||
animatable: Animatable?
|
||||
) {
|
||||
spinner!!.visibility = View.GONE
|
||||
binding.zoomProgressBar.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -609,18 +598,20 @@ class ZoomableActivity : BaseActivity() {
|
|||
.setProgressBarImage(ProgressBarDrawable())
|
||||
.setProgressBarImageScaleType(ScalingUtils.ScaleType.FIT_CENTER)
|
||||
.build()
|
||||
photo!!.hierarchy = hierarchy
|
||||
photo!!.setAllowTouchInterceptionWhileZoomed(true)
|
||||
photo!!.setIsLongpressEnabled(false)
|
||||
photo!!.setTapListener(DoubleTapGestureListener(photo))
|
||||
with(binding.zoomable!!) {
|
||||
setHierarchy(hierarchy)
|
||||
setAllowTouchInterceptionWhileZoomed(true)
|
||||
setIsLongpressEnabled(false)
|
||||
setTapListener(DoubleTapGestureListener(this))
|
||||
}
|
||||
val controller: DraweeController = Fresco.newDraweeControllerBuilder()
|
||||
.setUri(imageUri)
|
||||
.setControllerListener(loadingListener)
|
||||
.build()
|
||||
photo!!.controller = controller
|
||||
binding.zoomable!!.controller = controller
|
||||
|
||||
if (photoBackgroundColor != null) {
|
||||
photo!!.setBackgroundColor(photoBackgroundColor!!)
|
||||
binding.zoomable!!.setBackgroundColor(photoBackgroundColor!!)
|
||||
}
|
||||
|
||||
if (!images.isNullOrEmpty()) {
|
||||
|
|
@ -684,4 +675,4 @@ class ZoomableActivity : BaseActivity() {
|
|||
|
||||
const val PHOTO_BACKGROUND_COLOR = "photo_background_color"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
android:weightSum="10">
|
||||
|
||||
<include
|
||||
android:id="@+id/show_captions_binding"
|
||||
layout="@layout/show_captions_descriptions" />
|
||||
</LinearLayout>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Authors:
|
||||
* Winston Sung
|
||||
-->
|
||||
<resources>
|
||||
<string name="crash_dialog_title">同享壞咗</string>
|
||||
<string name="crash_dialog_text">哎呀。出咗錯!</string>
|
||||
<string name="crash_dialog_ok_toast">多謝你!</string>
|
||||
</resources>
|
||||
|
|
@ -28,6 +28,7 @@ import fr.free.nrw.commons.OkHttpConnectionFactory
|
|||
import fr.free.nrw.commons.R
|
||||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
import fr.free.nrw.commons.createTestClient
|
||||
import fr.free.nrw.commons.databinding.FragmentMediaDetailBinding
|
||||
import fr.free.nrw.commons.delete.DeleteHelper
|
||||
import fr.free.nrw.commons.delete.ReasonBuilder
|
||||
import fr.free.nrw.commons.explore.SearchActivity
|
||||
|
|
@ -65,7 +66,6 @@ class MediaDetailFragmentUnitTests {
|
|||
private lateinit var fragment: MediaDetailFragment
|
||||
private lateinit var fragmentManager: FragmentManager
|
||||
private lateinit var layoutInflater: LayoutInflater
|
||||
private lateinit var view: View
|
||||
private lateinit var context: Context
|
||||
|
||||
@Mock
|
||||
|
|
@ -148,6 +148,8 @@ class MediaDetailFragmentUnitTests {
|
|||
@Mock
|
||||
private lateinit var mockSharedPreferencesEditor: SharedPreferences.Editor
|
||||
|
||||
private lateinit var binding: FragmentMediaDetailBinding
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
|
||||
|
|
@ -170,14 +172,12 @@ class MediaDetailFragmentUnitTests {
|
|||
|
||||
layoutInflater = LayoutInflater.from(activity)
|
||||
|
||||
view = LayoutInflater.from(activity)
|
||||
.inflate(R.layout.fragment_media_detail, null) as View
|
||||
binding = FragmentMediaDetailBinding.inflate(layoutInflater)
|
||||
|
||||
scrollView = view.findViewById(R.id.mediaDetailScrollView)
|
||||
Whitebox.setInternalState(fragment, "scrollView", scrollView)
|
||||
scrollView = binding.mediaDetailScrollView
|
||||
|
||||
progressBarDeletion = view.findViewById(R.id.progressBarDeletion)
|
||||
delete = view.findViewById(R.id.nominateDeletion)
|
||||
progressBarDeletion = binding.progressBarDeletion
|
||||
delete = binding.nominateDeletion
|
||||
|
||||
Whitebox.setInternalState(fragment, "media", media)
|
||||
Whitebox.setInternalState(fragment, "isDeleted", isDeleted)
|
||||
|
|
@ -185,34 +185,13 @@ class MediaDetailFragmentUnitTests {
|
|||
Whitebox.setInternalState(fragment, "reasonListEnglishMappings", reasonListEnglishMappings)
|
||||
Whitebox.setInternalState(fragment, "reasonBuilder", reasonBuilder)
|
||||
Whitebox.setInternalState(fragment, "deleteHelper", deleteHelper)
|
||||
Whitebox.setInternalState(fragment, "progressBar", progressBar)
|
||||
Whitebox.setInternalState(fragment, "progressBarEditDescription", progressBar)
|
||||
Whitebox.setInternalState(fragment, "captionsListView", listView)
|
||||
Whitebox.setInternalState(fragment, "descriptionWebView", webView)
|
||||
Whitebox.setInternalState(fragment, "binding", binding)
|
||||
Whitebox.setInternalState(fragment, "detailProvider", detailProvider)
|
||||
Whitebox.setInternalState(fragment, "image", simpleDraweeView)
|
||||
Whitebox.setInternalState(fragment, "title", textView)
|
||||
Whitebox.setInternalState(fragment, "toDoReason", textView)
|
||||
Whitebox.setInternalState(fragment, "desc", htmlTextView)
|
||||
Whitebox.setInternalState(fragment, "license", textView)
|
||||
Whitebox.setInternalState(fragment, "coordinates", textView)
|
||||
Whitebox.setInternalState(fragment, "seeMore", textView)
|
||||
Whitebox.setInternalState(fragment, "uploadedDate", textView)
|
||||
Whitebox.setInternalState(fragment, "mediaCaption", textView)
|
||||
Whitebox.setInternalState(fragment, "captionLayout", linearLayout)
|
||||
Whitebox.setInternalState(fragment, "depictsLayout", linearLayout)
|
||||
Whitebox.setInternalState(fragment, "delete", delete)
|
||||
Whitebox.setInternalState(fragment, "depictionContainer", linearLayout)
|
||||
Whitebox.setInternalState(fragment, "toDoLayout", linearLayout)
|
||||
Whitebox.setInternalState(fragment, "authorLayout", linearLayout)
|
||||
Whitebox.setInternalState(fragment, "showCaptionAndDescriptionContainer", linearLayout)
|
||||
Whitebox.setInternalState(fragment, "editDescription", button)
|
||||
Whitebox.setInternalState(fragment, "depictEditButton", button)
|
||||
Whitebox.setInternalState(fragment, "categoryEditButton", button)
|
||||
Whitebox.setInternalState(fragment, "categoryContainer", linearLayout)
|
||||
Whitebox.setInternalState(fragment, "progressBarDeletion", progressBarDeletion)
|
||||
Whitebox.setInternalState(fragment, "progressBarEditCategory", progressBarDeletion)
|
||||
Whitebox.setInternalState(fragment, "mediaDiscussion", textView)
|
||||
Whitebox.setInternalState(binding, "mediaDetailImageView", simpleDraweeView)
|
||||
Whitebox.setInternalState(binding, "mediaDetailTitle", textView)
|
||||
Whitebox.setInternalState(binding, "mediaDetailDepictionContainer", linearLayout)
|
||||
Whitebox.setInternalState(binding, "dummyCaptionDescriptionContainer", linearLayout)
|
||||
Whitebox.setInternalState(binding, "depictionsEditButton", button)
|
||||
Whitebox.setInternalState(fragment, "locationManager", locationManager)
|
||||
|
||||
`when`(simpleDraweeView.hierarchy).thenReturn(genericDraweeHierarchy)
|
||||
|
|
@ -267,7 +246,7 @@ class MediaDetailFragmentUnitTests {
|
|||
@Throws(Exception::class)
|
||||
fun testLaunchZoomActivity() {
|
||||
`when`(media.imageUrl).thenReturn("")
|
||||
fragment.launchZoomActivity(view)
|
||||
fragment.launchZoomActivity(binding.root)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import fr.free.nrw.commons.OkHttpConnectionFactory
|
|||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
import fr.free.nrw.commons.createTestClient
|
||||
import fr.free.nrw.commons.auth.SessionManager
|
||||
import fr.free.nrw.commons.databinding.FragmentMediaDetailPagerBinding
|
||||
import fr.free.nrw.commons.explore.SearchActivity
|
||||
import io.reactivex.android.plugins.RxAndroidPlugins
|
||||
import io.reactivex.plugins.RxJavaPlugins
|
||||
|
|
@ -33,6 +34,7 @@ import org.junit.runner.RunWith
|
|||
import org.mockito.Mock
|
||||
import org.mockito.Mockito.`when`
|
||||
import org.mockito.MockitoAnnotations
|
||||
import org.powermock.reflect.Whitebox
|
||||
import org.robolectric.Robolectric
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.Shadows
|
||||
|
|
@ -50,6 +52,8 @@ class MediaDetailPagerFragmentUnitTests {
|
|||
private lateinit var context: Context
|
||||
private lateinit var fragmentManager: FragmentManager
|
||||
|
||||
private lateinit var binding: FragmentMediaDetailPagerBinding
|
||||
|
||||
@Mock
|
||||
private lateinit var outState: Bundle
|
||||
|
||||
|
|
@ -84,8 +88,8 @@ class MediaDetailPagerFragmentUnitTests {
|
|||
Fresco.initialize(context)
|
||||
|
||||
val activity = Robolectric.buildActivity(SearchActivity::class.java).create().get()
|
||||
binding = FragmentMediaDetailPagerBinding.inflate(activity.layoutInflater)
|
||||
|
||||
fragment = MediaDetailPagerFragment.newInstance(false, true)
|
||||
fragment = MediaDetailPagerFragment.newInstance(false, false)
|
||||
fragmentManager = activity.supportFragmentManager
|
||||
val fragmentTransaction: FragmentTransaction = fragmentManager.beginTransaction()
|
||||
|
|
@ -97,6 +101,8 @@ class MediaDetailPagerFragmentUnitTests {
|
|||
fieldContext.isAccessible = true
|
||||
fieldContext.set(sessionManager, context)
|
||||
|
||||
Whitebox.setInternalState(fragment, "binding", binding)
|
||||
|
||||
doReturn(menuItem).`when`(menu).findItem(any())
|
||||
doReturn(menuItem).`when`(menuItem).isEnabled = any()
|
||||
doReturn(menuItem).`when`(menuItem).isVisible = any()
|
||||
|
|
@ -263,4 +269,4 @@ class MediaDetailPagerFragmentUnitTests {
|
|||
verify(menuItem, never()).isEnabled = true
|
||||
verify(menuItem, never()).isVisible = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue