mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Show media details fragment when on clicking image of Peer Review (#4374)
* * show MediaDetailFragment in ReviewActivity on image click * Add javadoc * Reformated code of ReviewActivity xml * fix typos * add unit test * made minor changes
This commit is contained in:
parent
e9069d060c
commit
0c8b92c7aa
4 changed files with 189 additions and 97 deletions
|
|
@ -332,8 +332,13 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
||||||
Label.valuesAsList()), categoryRecyclerView, categoryClient, this);
|
Label.valuesAsList()), categoryRecyclerView, categoryClient, this);
|
||||||
categoryRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
categoryRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||||
categoryRecyclerView.setAdapter(categoryEditSearchRecyclerViewAdapter);
|
categoryRecyclerView.setAdapter(categoryEditSearchRecyclerViewAdapter);
|
||||||
|
// detail provider is null when fragment is shown in review activity
|
||||||
|
if (detailProvider != null) {
|
||||||
|
media = detailProvider.getMediaAtPosition(index);
|
||||||
|
} else {
|
||||||
|
media = getArguments().getParcelable("media");
|
||||||
|
}
|
||||||
|
|
||||||
media = detailProvider.getMediaAtPosition(index);
|
|
||||||
scrollView.getViewTreeObserver().addOnGlobalLayoutListener(
|
scrollView.getViewTreeObserver().addOnGlobalLayoutListener(
|
||||||
new OnGlobalLayoutListener() {
|
new OnGlobalLayoutListener() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -12,10 +12,14 @@ import android.view.MenuItem;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
import android.widget.FrameLayout;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import androidx.appcompat.widget.Toolbar;
|
import androidx.appcompat.widget.Toolbar;
|
||||||
import androidx.drawerlayout.widget.DrawerLayout;
|
import androidx.drawerlayout.widget.DrawerLayout;
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.fragment.app.FragmentManager;
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import com.facebook.drawee.view.SimpleDraweeView;
|
import com.facebook.drawee.view.SimpleDraweeView;
|
||||||
|
|
@ -23,6 +27,7 @@ import com.viewpagerindicator.CirclePageIndicator;
|
||||||
import fr.free.nrw.commons.Media;
|
import fr.free.nrw.commons.Media;
|
||||||
import fr.free.nrw.commons.R;
|
import fr.free.nrw.commons.R;
|
||||||
import fr.free.nrw.commons.delete.DeleteHelper;
|
import fr.free.nrw.commons.delete.DeleteHelper;
|
||||||
|
import fr.free.nrw.commons.media.MediaDetailFragment;
|
||||||
import fr.free.nrw.commons.theme.BaseActivity;
|
import fr.free.nrw.commons.theme.BaseActivity;
|
||||||
import fr.free.nrw.commons.utils.DialogUtil;
|
import fr.free.nrw.commons.utils.DialogUtil;
|
||||||
import fr.free.nrw.commons.utils.ViewUtil;
|
import fr.free.nrw.commons.utils.ViewUtil;
|
||||||
|
|
@ -49,6 +54,11 @@ public class ReviewActivity extends BaseActivity {
|
||||||
ProgressBar progressBar;
|
ProgressBar progressBar;
|
||||||
@BindView(R.id.tv_image_caption)
|
@BindView(R.id.tv_image_caption)
|
||||||
TextView imageCaption;
|
TextView imageCaption;
|
||||||
|
@BindView(R.id.mediaDetailContainer)
|
||||||
|
FrameLayout mediaDetailContainer;
|
||||||
|
MediaDetailFragment mediaDetailFragment;
|
||||||
|
@BindView(R.id.reviewActivityContainer)
|
||||||
|
LinearLayout reviewContainer;
|
||||||
public ReviewPagerAdapter reviewPagerAdapter;
|
public ReviewPagerAdapter reviewPagerAdapter;
|
||||||
public ReviewController reviewController;
|
public ReviewController reviewController;
|
||||||
@Inject
|
@Inject
|
||||||
|
|
@ -109,9 +119,9 @@ public class ReviewActivity extends BaseActivity {
|
||||||
Drawable d[]=btnSkipImage.getCompoundDrawablesRelative();
|
Drawable d[]=btnSkipImage.getCompoundDrawablesRelative();
|
||||||
d[2].setColorFilter(getApplicationContext().getResources().getColor(R.color.button_blue), PorterDuff.Mode.SRC_IN);
|
d[2].setColorFilter(getApplicationContext().getResources().getColor(R.color.button_blue), PorterDuff.Mode.SRC_IN);
|
||||||
|
|
||||||
|
if (savedInstanceState != null && savedInstanceState.getParcelable(SAVED_MEDIA) != null) {
|
||||||
if (savedInstanceState != null && savedInstanceState.getParcelable(SAVED_MEDIA)!=null) {
|
|
||||||
updateImage(savedInstanceState.getParcelable(SAVED_MEDIA)); // Use existing media if we have one
|
updateImage(savedInstanceState.getParcelable(SAVED_MEDIA)); // Use existing media if we have one
|
||||||
|
setUpMediaDetailOnOrientation();
|
||||||
} else {
|
} else {
|
||||||
runRandomizer(); //Run randomizer whenever everything is ready so that a first random image will be added
|
runRandomizer(); //Run randomizer whenever everything is ready so that a first random image will be added
|
||||||
}
|
}
|
||||||
|
|
@ -122,6 +132,8 @@ public class ReviewActivity extends BaseActivity {
|
||||||
runRandomizer();
|
runRandomizer();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
simpleDraweeView.setOnClickListener(view ->setUpMediaDetailFragment());
|
||||||
|
|
||||||
btnSkipImage.setOnTouchListener((view, event) -> {
|
btnSkipImage.setOnTouchListener((view, event) -> {
|
||||||
if (event.getAction() == MotionEvent.ACTION_UP && event.getRawX() >= (
|
if (event.getAction() == MotionEvent.ACTION_UP && event.getRawX() >= (
|
||||||
btnSkipImage.getRight() - btnSkipImage
|
btnSkipImage.getRight() - btnSkipImage
|
||||||
|
|
@ -242,4 +254,48 @@ public class ReviewActivity extends BaseActivity {
|
||||||
reviewImageFragment = (ReviewImageFragment) reviewPagerAdapter.instantiateItem(reviewPager, currentItemOfReviewPager);
|
reviewImageFragment = (ReviewImageFragment) reviewPagerAdapter.instantiateItem(reviewPager, currentItemOfReviewPager);
|
||||||
return reviewImageFragment;
|
return reviewImageFragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set up the media detail fragment when click on the review image
|
||||||
|
*/
|
||||||
|
private void setUpMediaDetailFragment() {
|
||||||
|
if (mediaDetailContainer.getVisibility() == View.GONE && media != null) {
|
||||||
|
mediaDetailContainer.setVisibility(View.VISIBLE);
|
||||||
|
reviewContainer.setVisibility(View.INVISIBLE);
|
||||||
|
FragmentManager fragmentManager = getSupportFragmentManager();
|
||||||
|
mediaDetailFragment = new MediaDetailFragment();
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putParcelable("media", media);
|
||||||
|
mediaDetailFragment.setArguments(bundle);
|
||||||
|
fragmentManager.beginTransaction().add(R.id.mediaDetailContainer, mediaDetailFragment).
|
||||||
|
addToBackStack("MediaDetail").commit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* handle the back pressed event of this activity
|
||||||
|
* this function call every time when back button is pressed
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onBackPressed() {
|
||||||
|
if (mediaDetailContainer.getVisibility() == View.VISIBLE) {
|
||||||
|
mediaDetailContainer.setVisibility(View.GONE);
|
||||||
|
reviewContainer.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
super.onBackPressed();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set up media detail fragment after orientation change
|
||||||
|
*/
|
||||||
|
private void setUpMediaDetailOnOrientation() {
|
||||||
|
Fragment mediaDetailFragment = getSupportFragmentManager()
|
||||||
|
.findFragmentById(R.id.mediaDetailContainer);
|
||||||
|
if (mediaDetailFragment != null) {
|
||||||
|
mediaDetailContainer.setVisibility(View.VISIBLE);
|
||||||
|
reviewContainer.setVisibility(View.INVISIBLE);
|
||||||
|
getSupportFragmentManager().beginTransaction()
|
||||||
|
.replace(R.id.mediaDetailContainer, mediaDetailFragment).commit();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,114 +6,120 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<LinearLayout
|
<FrameLayout
|
||||||
|
android:id="@+id/mediaDetailContainer"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/reviewActivityContainer"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:visibility="visible">
|
||||||
|
|
||||||
|
<include layout="@layout/toolbar" />
|
||||||
|
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatButton
|
||||||
|
android:id="@+id/skip_image"
|
||||||
|
style="@style/Widget.AppCompat.Button.Borderless"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:drawableEnd="@drawable/ic_info_outline_24dp"
|
||||||
|
android:drawablePadding="@dimen/medium_height"
|
||||||
|
android:drawableTint="@color/button_blue_dark"
|
||||||
|
android:paddingLeft="@dimen/medium_height"
|
||||||
|
android:paddingRight="@dimen/medium_height"
|
||||||
|
android:text="@string/skip_image"
|
||||||
|
android:textAllCaps="true"
|
||||||
|
android:textColor="@color/button_blue_dark"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<RelativeLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:weightSum="2">
|
||||||
|
|
||||||
|
<RelativeLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="@dimen/dimen_0"
|
||||||
|
android:layout_marginTop="@dimen/tiny_padding"
|
||||||
|
android:layout_weight="1">
|
||||||
|
|
||||||
|
<com.facebook.drawee.view.SimpleDraweeView
|
||||||
|
android:id="@+id/review_image_view"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical">
|
android:layout_alignParentTop="true"
|
||||||
|
android:layout_marginTop="@dimen/dimen_0"
|
||||||
|
app:srcCompat="@drawable/commons_logo" />
|
||||||
|
|
||||||
<include layout="@layout/toolbar" />
|
<RelativeLayout
|
||||||
|
android:id="@+id/rl_container_upload_overlay"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentBottom="true"
|
||||||
|
android:layout_gravity="center|bottom"
|
||||||
|
android:background="#77000000"
|
||||||
|
android:gravity="center"
|
||||||
|
android:padding="@dimen/tiny_gap">
|
||||||
|
|
||||||
|
<TextView
|
||||||
<androidx.appcompat.widget.AppCompatButton
|
android:id="@+id/tv_image_caption"
|
||||||
android:id="@+id/skip_image"
|
style="?android:textAppearanceMedium"
|
||||||
style="@style/Widget.AppCompat.Button.Borderless"
|
|
||||||
android:textStyle="bold"
|
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center_horizontal"
|
android:textColor="#FFFFFFFF" />
|
||||||
android:paddingLeft="@dimen/medium_height"
|
|
||||||
android:paddingRight="@dimen/medium_height"
|
|
||||||
android:drawableEnd="@drawable/ic_info_outline_24dp"
|
|
||||||
android:drawablePadding="@dimen/medium_height"
|
|
||||||
android:drawableTint="@color/button_blue_dark"
|
|
||||||
android:text="@string/skip_image"
|
|
||||||
android:textColor="@color/button_blue_dark"
|
|
||||||
android:textAllCaps="true"/>
|
|
||||||
|
|
||||||
<RelativeLayout
|
</RelativeLayout>
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent">
|
|
||||||
|
|
||||||
<LinearLayout
|
<ProgressBar
|
||||||
android:layout_width="match_parent"
|
android:id="@+id/pb_review_image"
|
||||||
android:layout_height="match_parent"
|
android:layout_width="wrap_content"
|
||||||
android:orientation="vertical"
|
android:layout_height="wrap_content"
|
||||||
android:weightSum="2"
|
android:layout_centerInParent="true"
|
||||||
>
|
android:visibility="gone"
|
||||||
|
tools:visibility="visible" />
|
||||||
|
|
||||||
<RelativeLayout
|
</RelativeLayout>
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="@dimen/dimen_0"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:layout_marginTop="@dimen/tiny_padding"
|
|
||||||
>
|
|
||||||
|
|
||||||
<com.facebook.drawee.view.SimpleDraweeView
|
<fr.free.nrw.commons.review.ReviewViewPager
|
||||||
android:id="@+id/review_image_view"
|
android:id="@+id/view_pager_review"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="@dimen/dimen_0"
|
||||||
android:layout_alignParentTop="true"
|
android:layout_weight="1"
|
||||||
android:layout_marginTop="@dimen/dimen_0"
|
android:fadingEdge="none" />
|
||||||
app:srcCompat="@drawable/commons_logo" />
|
|
||||||
|
|
||||||
<RelativeLayout
|
</LinearLayout>
|
||||||
android:id="@+id/rl_container_upload_overlay"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_alignParentBottom="true"
|
|
||||||
android:layout_gravity="center|bottom"
|
|
||||||
android:background="#77000000"
|
|
||||||
android:gravity="center"
|
|
||||||
android:padding="@dimen/tiny_gap">
|
|
||||||
|
|
||||||
<TextView
|
<RelativeLayout
|
||||||
android:id="@+id/tv_image_caption"
|
android:id="@+id/rl_container_bottom_view"
|
||||||
style="?android:textAppearanceMedium"
|
android:layout_width="match_parent"
|
||||||
android:layout_width="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_alignParentBottom="true"
|
||||||
android:textColor="#FFFFFFFF" />
|
android:background="?attr/colorPrimaryDark"
|
||||||
|
android:elevation="@dimen/miniscule_margin"
|
||||||
|
android:padding="@dimen/medium_height">
|
||||||
|
|
||||||
</RelativeLayout>
|
<com.viewpagerindicator.CirclePageIndicator
|
||||||
|
android:id="@+id/pager_indicator_review"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:background="?attr/colorPrimaryDark"
|
||||||
|
android:foregroundGravity="center_vertical" />
|
||||||
|
</RelativeLayout>
|
||||||
|
|
||||||
<ProgressBar
|
</RelativeLayout>
|
||||||
android:id="@+id/pb_review_image"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_centerInParent="true"
|
|
||||||
android:visibility="gone"
|
|
||||||
tools:visibility="visible"/>
|
|
||||||
|
|
||||||
</RelativeLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<fr.free.nrw.commons.review.ReviewViewPager
|
|
||||||
android:id="@+id/view_pager_review"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="@dimen/dimen_0"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:fadingEdge="none"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<RelativeLayout
|
|
||||||
android:id="@+id/rl_container_bottom_view"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:padding="@dimen/medium_height"
|
|
||||||
android:layout_alignParentBottom="true"
|
|
||||||
android:background="?attr/colorPrimaryDark"
|
|
||||||
android:elevation="@dimen/miniscule_margin">
|
|
||||||
<com.viewpagerindicator.CirclePageIndicator
|
|
||||||
android:id="@+id/pager_indicator_review"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:background="?attr/colorPrimaryDark"
|
|
||||||
android:foregroundGravity="center_vertical"
|
|
||||||
/>
|
|
||||||
</RelativeLayout>
|
|
||||||
|
|
||||||
</RelativeLayout>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</androidx.drawerlayout.widget.DrawerLayout>
|
</androidx.drawerlayout.widget.DrawerLayout>
|
||||||
|
|
@ -19,6 +19,7 @@ import org.robolectric.annotation.Config
|
||||||
import org.robolectric.fakes.RoboMenu
|
import org.robolectric.fakes.RoboMenu
|
||||||
import org.robolectric.fakes.RoboMenuItem
|
import org.robolectric.fakes.RoboMenuItem
|
||||||
import org.wikipedia.AppAdapter
|
import org.wikipedia.AppAdapter
|
||||||
|
import java.lang.reflect.Method
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner::class)
|
@RunWith(RobolectricTestRunner::class)
|
||||||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||||
|
|
@ -101,4 +102,28 @@ class ReviewActivityTest {
|
||||||
activity.onOptionsItemSelected(menuItem)
|
activity.onOptionsItemSelected(menuItem)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Throws(Exception::class)
|
||||||
|
fun testSetUpMediaDetailFragment() {
|
||||||
|
var setUpMediaDetailFragment: Method =
|
||||||
|
ReviewActivity::class.java.getDeclaredMethod("setUpMediaDetailFragment")
|
||||||
|
setUpMediaDetailFragment.isAccessible = true
|
||||||
|
setUpMediaDetailFragment.invoke(activity)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Throws(Exception::class)
|
||||||
|
fun testSetUpMediaDetailOnOrientation() {
|
||||||
|
var setUpMediaDetailFragment: Method =
|
||||||
|
ReviewActivity::class.java.getDeclaredMethod("setUpMediaDetailOnOrientation")
|
||||||
|
setUpMediaDetailFragment.isAccessible = true
|
||||||
|
setUpMediaDetailFragment.invoke(activity)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Throws(Exception::class)
|
||||||
|
fun testOnBackPressed() {
|
||||||
|
activity.onBackPressed()
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue