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);
|
||||
categoryRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
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");
|
||||
}
|
||||
|
||||
scrollView.getViewTreeObserver().addOnGlobalLayoutListener(
|
||||
new OnGlobalLayoutListener() {
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -12,10 +12,14 @@ import android.view.MenuItem;
|
|||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.drawerlayout.widget.DrawerLayout;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
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.R;
|
||||
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.utils.DialogUtil;
|
||||
import fr.free.nrw.commons.utils.ViewUtil;
|
||||
|
|
@ -49,6 +54,11 @@ public class ReviewActivity extends BaseActivity {
|
|||
ProgressBar progressBar;
|
||||
@BindView(R.id.tv_image_caption)
|
||||
TextView imageCaption;
|
||||
@BindView(R.id.mediaDetailContainer)
|
||||
FrameLayout mediaDetailContainer;
|
||||
MediaDetailFragment mediaDetailFragment;
|
||||
@BindView(R.id.reviewActivityContainer)
|
||||
LinearLayout reviewContainer;
|
||||
public ReviewPagerAdapter reviewPagerAdapter;
|
||||
public ReviewController reviewController;
|
||||
@Inject
|
||||
|
|
@ -109,9 +119,9 @@ public class ReviewActivity extends BaseActivity {
|
|||
Drawable d[]=btnSkipImage.getCompoundDrawablesRelative();
|
||||
d[2].setColorFilter(getApplicationContext().getResources().getColor(R.color.button_blue), PorterDuff.Mode.SRC_IN);
|
||||
|
||||
|
||||
if (savedInstanceState != null && savedInstanceState.getParcelable(SAVED_MEDIA) != null) {
|
||||
updateImage(savedInstanceState.getParcelable(SAVED_MEDIA)); // Use existing media if we have one
|
||||
setUpMediaDetailOnOrientation();
|
||||
} else {
|
||||
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();
|
||||
});
|
||||
|
||||
simpleDraweeView.setOnClickListener(view ->setUpMediaDetailFragment());
|
||||
|
||||
btnSkipImage.setOnTouchListener((view, event) -> {
|
||||
if (event.getAction() == MotionEvent.ACTION_UP && event.getRawX() >= (
|
||||
btnSkipImage.getRight() - btnSkipImage
|
||||
|
|
@ -242,4 +254,48 @@ public class ReviewActivity extends BaseActivity {
|
|||
reviewImageFragment = (ReviewImageFragment) reviewPagerAdapter.instantiateItem(reviewPager, currentItemOfReviewPager);
|
||||
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,10 +6,18 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
<FrameLayout
|
||||
android:id="@+id/mediaDetailContainer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
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" />
|
||||
|
||||
|
|
@ -17,18 +25,18 @@
|
|||
<androidx.appcompat.widget.AppCompatButton
|
||||
android:id="@+id/skip_image"
|
||||
style="@style/Widget.AppCompat.Button.Borderless"
|
||||
android:textStyle="bold"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
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:paddingLeft="@dimen/medium_height"
|
||||
android:paddingRight="@dimen/medium_height"
|
||||
android:text="@string/skip_image"
|
||||
android:textAllCaps="true"
|
||||
android:textColor="@color/button_blue_dark"
|
||||
android:textAllCaps="true"/>
|
||||
android:textStyle="bold" />
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
|
|
@ -38,15 +46,13 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:weightSum="2"
|
||||
>
|
||||
android:weightSum="2">
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/dimen_0"
|
||||
android:layout_weight="1"
|
||||
android:layout_marginTop="@dimen/tiny_padding"
|
||||
>
|
||||
android:layout_weight="1">
|
||||
|
||||
<com.facebook.drawee.view.SimpleDraweeView
|
||||
android:id="@+id/review_image_view"
|
||||
|
|
@ -98,18 +104,18 @@
|
|||
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">
|
||||
android:elevation="@dimen/miniscule_margin"
|
||||
android:padding="@dimen/medium_height">
|
||||
|
||||
<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"
|
||||
/>
|
||||
android:foregroundGravity="center_vertical" />
|
||||
</RelativeLayout>
|
||||
|
||||
</RelativeLayout>
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import org.robolectric.annotation.Config
|
|||
import org.robolectric.fakes.RoboMenu
|
||||
import org.robolectric.fakes.RoboMenuItem
|
||||
import org.wikipedia.AppAdapter
|
||||
import java.lang.reflect.Method
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
|
|
@ -101,4 +102,28 @@ class ReviewActivityTest {
|
|||
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