Merge branch 'torrentcome-issue#228' Closes #228

This commit is contained in:
Vavassor 2017-05-11 18:15:10 -04:00
commit 08a6095251
4 changed files with 72 additions and 34 deletions

View File

@ -15,10 +15,8 @@
package com.keylesspalace.tusky.fragment; package com.keylesspalace.tusky.fragment;
import android.app.AlertDialog;
import android.app.DownloadManager; import android.app.DownloadManager;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
@ -30,18 +28,20 @@ import android.support.annotation.StringRes;
import android.support.design.widget.Snackbar; import android.support.design.widget.Snackbar;
import android.support.v4.app.DialogFragment; import android.support.v4.app.DialogFragment;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.ImageView; import android.widget.ImageView;
import com.keylesspalace.tusky.R;
import com.github.chrisbanes.photoview.OnOutsidePhotoTapListener; import com.github.chrisbanes.photoview.OnOutsidePhotoTapListener;
import com.github.chrisbanes.photoview.OnSingleFlingListener; import com.github.chrisbanes.photoview.OnSingleFlingListener;
import com.github.chrisbanes.photoview.PhotoView; import com.github.chrisbanes.photoview.PhotoView;
import com.github.chrisbanes.photoview.PhotoViewAttacher; import com.github.chrisbanes.photoview.PhotoViewAttacher;
import com.keylesspalace.tusky.R;
import com.squareup.picasso.Callback; import com.squareup.picasso.Callback;
import com.squareup.picasso.Picasso; import com.squareup.picasso.Picasso;
@ -50,7 +50,7 @@ import java.io.File;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
public class ViewMediaFragment extends DialogFragment { public class ViewMediaFragment extends DialogFragment implements Toolbar.OnMenuItemClickListener {
private PhotoViewAttacher attacher; private PhotoViewAttacher attacher;
@ -59,6 +59,9 @@ public class ViewMediaFragment extends DialogFragment {
@BindView(R.id.view_media_image) @BindView(R.id.view_media_image)
PhotoView photoView; PhotoView photoView;
@BindView(R.id.toolbar)
Toolbar toolbar;
public static ViewMediaFragment newInstance(String url) { public static ViewMediaFragment newInstance(String url) {
Bundle arguments = new Bundle(); Bundle arguments = new Bundle();
ViewMediaFragment fragment = new ViewMediaFragment(); ViewMediaFragment fragment = new ViewMediaFragment();
@ -115,22 +118,10 @@ public class ViewMediaFragment extends DialogFragment {
} }
}); });
attacher.setOnLongClickListener(new View.OnLongClickListener() { toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override @Override
public boolean onLongClick(View v) { public void onClick(View v) {
dismiss();
AlertDialog downloadDialog = new AlertDialog.Builder(getContext()).create();
downloadDialog.setButton(AlertDialog.BUTTON_NEUTRAL, getString(R.string.dialog_download_image),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
downloadImage();
}
});
downloadDialog.show();
return false;
} }
}); });
@ -140,6 +131,9 @@ public class ViewMediaFragment extends DialogFragment {
@Override @Override
public void onSuccess() { public void onSuccess() {
rootView.findViewById(R.id.view_media_progress).setVisibility(View.GONE); rootView.findViewById(R.id.view_media_progress).setVisibility(View.GONE);
toolbar.setOnMenuItemClickListener(ViewMediaFragment.this);
toolbar.inflateMenu(R.menu.view_media_tooblar);
attacher.update(); attacher.update();
} }
@ -204,9 +198,24 @@ public class ViewMediaFragment extends DialogFragment {
private void doErrorDialog(@StringRes int descriptionId, @StringRes int actionId, private void doErrorDialog(@StringRes int descriptionId, @StringRes int actionId,
View.OnClickListener listener) { View.OnClickListener listener) {
Snackbar bar = Snackbar.make(getView(), getString(descriptionId), if(getView() != null) {
Snackbar.LENGTH_SHORT); Snackbar bar = Snackbar.make(getView(), getString(descriptionId),
bar.setAction(actionId, listener); Snackbar.LENGTH_SHORT);
bar.show(); bar.setAction(actionId, listener);
bar.show();
}
}
@Override
public boolean onMenuItemClick(MenuItem item) {
int id = item.getItemId();
switch (id) {
case R.id.action_download:
downloadImage();
break;
default:
break;
}
return true;
} }
} }

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFF"
android:pathData="M19,9h-4V3H9v6H5l7,7 7,-7zM5,18v2h14v-2H5z"/>
</vector>

View File

@ -1,20 +1,31 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:clickable="true"
android:layout_gravity="center" android:layout_gravity="center"
android:background="@android:color/black"> android:background="@android:color/black"
android:clickable="true">
<ProgressBar
android:id="@+id/view_media_progress"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<com.github.chrisbanes.photoview.PhotoView <com.github.chrisbanes.photoview.PhotoView
android:id="@+id/view_media_image" android:id="@+id/view_media_image"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="match_parent"
android:layout_below="@+id/toolbar" />
</FrameLayout> <android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:navigationIcon="?attr/homeAsUpIndicator" />
<ProgressBar
android:id="@+id/view_media_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_gravity="center" />
</RelativeLayout>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_download"
android:icon="@drawable/ic_file_download_black_24dp"
android:title="@string/dialog_download_image"
app:showAsAction="always" />
</menu>