refactor some more items, reimplement context menus for gallery

This commit is contained in:
Andrew Dolgov 2017-06-02 15:19:30 +03:00
parent 6f1afb1ef0
commit 2c676e263f
13 changed files with 108 additions and 118 deletions

View File

@ -135,7 +135,7 @@ public class ArticleFragment extends Fragment {
if (result != null && (result.getType() == HitTestResult.IMAGE_TYPE || result.getType() == HitTestResult.SRC_IMAGE_ANCHOR_TYPE)) {
menu.setHeaderTitle(result.getExtra());
getActivity().getMenuInflater().inflate(R.menu.context_article_content_img, menu);
getActivity().getMenuInflater().inflate(R.menu.content_gallery_entry, menu);
/* FIXME I have no idea how to do this correctly ;( */

View File

@ -1,5 +1,6 @@
package org.fox.ttrss;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.ActivityCompat;
@ -8,8 +9,11 @@ import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.view.ContextMenu;
import android.util.Log;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.PopupMenu;
import android.widget.ProgressBar;
import com.ToxicBakery.viewpager.transforms.DepthPageTransformer;
@ -239,6 +243,28 @@ public class GalleryActivity extends CommonActivity {
m_content = savedInstanceState.getString("content");
}
findViewById(R.id.gallery_overflow).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PopupMenu popup = new PopupMenu(GalleryActivity.this, v);
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu.content_gallery_entry, popup.getMenu());
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
String url = m_items.get(m_pager.getCurrentItem()).url;
return onImageMenuItemSelected(item, url);
}
});
popup.show();
}
});
/*if (m_items.size() > 1) {
m_progress.setProgress(0);
m_progress.setMax(m_items.size());
@ -260,20 +286,12 @@ public class GalleryActivity extends CommonActivity {
m_adapter = new ArticleImagesPagerAdapter(getSupportFragmentManager(), m_items);
m_pager = (ViewPager) findViewById(R.id.article_images_pager);
m_pager = (ViewPager) findViewById(R.id.gallery_pager);
m_pager.setAdapter(m_adapter);
m_pager.setPageTransformer(true, new DepthPageTransformer());
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenu.ContextMenuInfo menuInfo) {
getMenuInflater().inflate(R.menu.context_article_content_img, menu);
super.onCreateContextMenu(menu, v, menuInfo);
}
@Override
public void onSaveInstanceState(Bundle out) {
@ -284,5 +302,48 @@ public class GalleryActivity extends CommonActivity {
out.putString("content", m_content);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
int position = m_pager.getCurrentItem();
String url = m_items.get(position).url;
if (onImageMenuItemSelected(item, url))
return true;
return super.onContextItemSelected(item);
}
public boolean onImageMenuItemSelected(MenuItem item, String url) {
switch (item.getItemId()) {
case R.id.article_img_open:
if (url != null) {
try {
openUri(Uri.parse(url));
} catch (Exception e) {
e.printStackTrace();
toast(R.string.error_other_error);
}
}
return true;
case R.id.article_img_copy:
if (url != null) {
copyToClipboard(url);
}
return true;
case R.id.article_img_share:
if (url != null) {
shareText(url);
}
return true;
case R.id.article_img_view_caption:
if (url != null) {
displayImageCaption(url, m_content);
}
return true;
default:
Log.d(TAG, "onImageMenuItemSelected, unhandled id=" + item.getItemId());
return false;
}
}
}

View File

@ -5,7 +5,9 @@ import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.ContextMenu;
import android.view.MenuItem;
import android.view.View;
public class GalleryBaseFragment extends Fragment {
private final String TAG = this.getClass().getSimpleName();
@ -18,39 +20,6 @@ public class GalleryBaseFragment extends Fragment {
setRetainInstance(true);
}
public boolean onImageMenuItemSelected(MenuItem item, String url) {
switch (item.getItemId()) {
case R.id.article_img_open:
if (url != null) {
try {
m_activity.openUri(Uri.parse(url));
} catch (Exception e) {
e.printStackTrace();
m_activity.toast(R.string.error_other_error);
}
}
return true;
case R.id.article_img_copy:
if (url != null) {
m_activity.copyToClipboard(url);
}
return true;
case R.id.article_img_share:
if (url != null) {
m_activity.shareText(url);
}
return true;
case R.id.article_img_view_caption:
if (url != null) {
m_activity.displayImageCaption(url, m_activity.m_content);
}
return true;
default:
Log.d(TAG, "onImageMenuItemSelected, unhandled id=" + item.getItemId());
return false;
}
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
@ -60,5 +29,12 @@ public class GalleryBaseFragment extends Fragment {
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenu.ContextMenuInfo menuInfo) {
m_activity.getMenuInflater().inflate(R.menu.content_gallery_entry, menu);
super.onCreateContextMenu(menu, v, menuInfo);
}
}

View File

@ -40,33 +40,14 @@ public class GalleryImageFragment extends GalleryBaseFragment {
ImageMatrixTouchHandler touchHandler = new ImageMatrixTouchHandler(view.getContext());
imgView.setOnTouchListener(touchHandler);
//imgView.setOnTouchListener(touchHandler);
// shared element transitions stop GIFs from playing
if (m_url.toLowerCase().indexOf(".gif") == -1) {
ViewCompat.setTransitionName(imgView, "gallery:" + m_url);
}
//registerForContextMenu(imgView);
view.findViewById(R.id.flavor_image_overflow).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PopupMenu popup = new PopupMenu(getContext(), v);
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu.context_article_content_img, popup.getMenu());
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
return onImageMenuItemSelected(item, m_url);
}
});
popup.show();
}
});
registerForContextMenu(imgView);
final ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.flavor_image_progress);
final View errorMessage = view.findViewById(R.id.flavor_image_error);

View File

@ -52,26 +52,7 @@ public class GalleryVideoFragment extends GalleryBaseFragment {
ViewCompat.setTransitionName(imgView, "gallery:" + m_url);
//registerForContextMenu(imgView);
view.findViewById(R.id.flavor_image_overflow).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PopupMenu popup = new PopupMenu(getContext(), v);
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu.context_article_content_img, popup.getMenu());
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
return onImageMenuItemSelected(item, m_url);
}
});
popup.show();
}
});
registerForContextMenu(imgView);
final GlideDrawableImageViewTarget glideImage = new GlideDrawableImageViewTarget(imgView);
@ -133,9 +114,12 @@ public class GalleryVideoFragment extends GalleryBaseFragment {
//Log.d(TAG, "initializeVideoPlayer: " + m_activity + " " + view);
final MediaController m_mediaController = new MediaController(m_activity);
final TextureView textureView = (TextureView) view.findViewById(R.id.flavor_video);
registerForContextMenu(textureView);
textureView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -271,17 +255,6 @@ public class GalleryVideoFragment extends GalleryBaseFragment {
m_coverUrl = coverUrl;
}
/*@Override
public boolean onContextItemSelected(MenuItem item) {
int position = m_pager.getCurrentItem();
String url = m_checkedUrls.get(position);
if (!onImageMenuItemSelected(item, url))
return super.onContextItemSelected(item);
else
return true;
}*/
@Override
public void onSaveInstanceState (Bundle out) {
super.onSaveInstanceState(out);

View File

@ -791,7 +791,7 @@ public class HeadlinesFragment extends Fragment {
textChecked = (ImageView) v.findViewById(R.id.text_checked);
headlineHeader = v.findViewById(R.id.headline_header);
topChangedMessage = v.findViewById(R.id.headlines_row_top_changed);
flavorImageOverflow = v.findViewById(R.id.flavor_image_overflow);
flavorImageOverflow = v.findViewById(R.id.gallery_overflow);
flavorVideoView = (TextureView) v.findViewById(R.id.flavor_video);
}
@ -1086,7 +1086,7 @@ public class HeadlinesFragment extends Fragment {
public void onClick(View v) {
PopupMenu popup = new PopupMenu(getActivity(), holder.flavorImageOverflow);
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu.context_article_content_img, popup.getMenu());
inflater.inflate(R.menu.content_gallery_entry, popup.getMenu());
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override

View File

@ -98,7 +98,7 @@ public class OfflineArticleFragment extends Fragment {
if (result != null && (result.getType() == HitTestResult.IMAGE_TYPE || result.getType() == HitTestResult.SRC_IMAGE_ANCHOR_TYPE)) {
menu.setHeaderTitle(result.getExtra());
getActivity().getMenuInflater().inflate(R.menu.context_article_content_img, menu);
getActivity().getMenuInflater().inflate(R.menu.content_gallery_entry, menu);
/* FIXME I have no idea how to do this correctly ;( */

View File

@ -572,7 +572,7 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
holder.textChecked = (ImageView) v.findViewById(R.id.text_checked);
holder.flavorVideoKindView = (ImageView) v.findViewById(R.id.flavor_video_kind);
holder.headlineHeader = v.findViewById(R.id.headline_header);
holder.flavorImageOverflow = v.findViewById(R.id.flavor_image_overflow);
holder.flavorImageOverflow = v.findViewById(R.id.gallery_overflow);
v.setTag(holder);

View File

@ -7,11 +7,23 @@
android:layout_height="fill_parent">
<com.bogdwellers.pinchtozoom.view.ImageViewPager
android:id="@+id/article_images_pager"
android:id="@+id/gallery_pager"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true" />
<ImageView
android:id="@+id/gallery_overflow"
android:clickable="true"
android:layout_width="wrap_content"
android:layout_height="26dp"
android:layout_weight="0"
android:background="@drawable/ripple"
android:src="@drawable/ic_dots_vertical"
android:layout_alignParentRight="true"
android:layout_marginRight="8dp"
android:layout_marginTop="@dimen/activity_vertical_margin" />
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
@ -20,7 +32,7 @@
android:progress="0"
android:indeterminate="false"
android:visibility="gone"
android:layout_above="@+id/article_images_indicator"
android:layout_above="@+id/gallery_pager_indicator"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
@ -29,7 +41,7 @@
android:layout_marginRight="@dimen/activity_horizontal_margin" />
<me.relex.circleindicator.CircleIndicator
android:id="@+id/article_images_indicator"
android:id="@+id/gallery_pager_indicator"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
@ -37,7 +49,6 @@
android:layout_alignParentStart="true"
android:visibility="invisible" />
<include layout="@layout/toolbar" android:id="@+id/toolbar" />
</RelativeLayout>

View File

@ -34,16 +34,4 @@
android:layout_gravity="center"
android:id="@+id/flavor_image_progress" />
<ImageView
android:id="@+id/flavor_image_overflow"
android:clickable="true"
android:layout_width="wrap_content"
android:layout_height="26dp"
android:layout_weight="0"
android:background="@drawable/ripple"
android:src="@drawable/ic_dots_vertical"
android:layout_gravity="top|right"
android:layout_marginRight="8dp"
android:layout_marginTop="@dimen/activity_vertical_margin" />
</FrameLayout>

View File

@ -151,7 +151,7 @@
android:layout_marginLeft="8dp" />
<ImageView
android:id="@+id/flavor_image_overflow"
android:id="@+id/gallery_overflow"
android:clickable="true"
android:layout_width="wrap_content"
android:layout_height="24dp"

View File

@ -152,7 +152,7 @@
android:layout_marginBottom="8dp" />
<ImageView
android:id="@+id/flavor_image_overflow"
android:id="@+id/gallery_overflow"
android:clickable="true"
android:layout_width="wrap_content"
android:layout_height="24dp"