Merge branch 'issue#228' of https://github.com/torrentcome/Tusky into torrentcome-issue#228
This commit is contained in:
commit
12571a7556
4 changed files with 72 additions and 34 deletions
|
@ -15,10 +15,8 @@
|
|||
|
||||
package com.keylesspalace.tusky.fragment;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.DownloadManager;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
|
@ -30,18 +28,20 @@ import android.support.annotation.StringRes;
|
|||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.keylesspalace.tusky.R;
|
||||
import com.github.chrisbanes.photoview.OnOutsidePhotoTapListener;
|
||||
import com.github.chrisbanes.photoview.OnSingleFlingListener;
|
||||
import com.github.chrisbanes.photoview.PhotoView;
|
||||
import com.github.chrisbanes.photoview.PhotoViewAttacher;
|
||||
import com.keylesspalace.tusky.R;
|
||||
import com.squareup.picasso.Callback;
|
||||
import com.squareup.picasso.Picasso;
|
||||
|
||||
|
@ -50,7 +50,7 @@ import java.io.File;
|
|||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public class ViewMediaFragment extends DialogFragment {
|
||||
public class ViewMediaFragment extends DialogFragment implements Toolbar.OnMenuItemClickListener {
|
||||
|
||||
private PhotoViewAttacher attacher;
|
||||
|
||||
|
@ -59,6 +59,9 @@ public class ViewMediaFragment extends DialogFragment {
|
|||
@BindView(R.id.view_media_image)
|
||||
PhotoView photoView;
|
||||
|
||||
@BindView(R.id.toolbar)
|
||||
Toolbar toolbar;
|
||||
|
||||
public static ViewMediaFragment newInstance(String url) {
|
||||
Bundle arguments = new Bundle();
|
||||
ViewMediaFragment fragment = new ViewMediaFragment();
|
||||
|
@ -115,22 +118,10 @@ public class ViewMediaFragment extends DialogFragment {
|
|||
}
|
||||
});
|
||||
|
||||
attacher.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
|
||||
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;
|
||||
public void onClick(View v) {
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -140,6 +131,9 @@ public class ViewMediaFragment extends DialogFragment {
|
|||
@Override
|
||||
public void onSuccess() {
|
||||
rootView.findViewById(R.id.view_media_progress).setVisibility(View.GONE);
|
||||
toolbar.setOnMenuItemClickListener(ViewMediaFragment.this);
|
||||
toolbar.inflateMenu(R.menu.view_media_tooblar);
|
||||
|
||||
attacher.update();
|
||||
}
|
||||
|
||||
|
@ -204,9 +198,24 @@ public class ViewMediaFragment extends DialogFragment {
|
|||
|
||||
private void doErrorDialog(@StringRes int descriptionId, @StringRes int actionId,
|
||||
View.OnClickListener listener) {
|
||||
Snackbar bar = Snackbar.make(getView(), getString(descriptionId),
|
||||
Snackbar.LENGTH_SHORT);
|
||||
bar.setAction(actionId, listener);
|
||||
bar.show();
|
||||
if(getView() != null) {
|
||||
Snackbar bar = Snackbar.make(getView(), getString(descriptionId),
|
||||
Snackbar.LENGTH_SHORT);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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>
|
|
@ -1,20 +1,31 @@
|
|||
<?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_height="match_parent"
|
||||
android:clickable="true"
|
||||
android:layout_gravity="center"
|
||||
android:background="@android:color/black">
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/view_media_progress"
|
||||
android:layout_gravity="center"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
android:background="@android:color/black"
|
||||
android:clickable="true">
|
||||
|
||||
<com.github.chrisbanes.photoview.PhotoView
|
||||
android:id="@+id/view_media_image"
|
||||
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>
|
9
app/src/main/res/menu/view_media_tooblar.xml
Normal file
9
app/src/main/res/menu/view_media_tooblar.xml
Normal 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>
|
Loading…
Reference in a new issue