From b5c2b62d7a5f4a62d2b581226def2d909dca5efe Mon Sep 17 00:00:00 2001 From: torrentcome Date: Wed, 10 May 2017 15:24:03 +0200 Subject: [PATCH 1/2] (icon) add icon download --- .../main/res/drawable/ic_file_download_black_24dp.xml | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 app/src/main/res/drawable/ic_file_download_black_24dp.xml diff --git a/app/src/main/res/drawable/ic_file_download_black_24dp.xml b/app/src/main/res/drawable/ic_file_download_black_24dp.xml new file mode 100644 index 000000000..f5f7221a9 --- /dev/null +++ b/app/src/main/res/drawable/ic_file_download_black_24dp.xml @@ -0,0 +1,9 @@ + + + From a01563778565bb7754fa20c6d5f3cfd95debf5f4 Mon Sep 17 00:00:00 2001 From: torrentcome Date: Wed, 10 May 2017 15:24:45 +0200 Subject: [PATCH 2/2] (media) add toolbar and download button --- .../tusky/fragment/ViewMediaFragment.java | 55 +++++++++++-------- .../main/res/layout/fragment_view_media.xml | 33 +++++++---- app/src/main/res/menu/view_media_tooblar.xml | 9 +++ 3 files changed, 63 insertions(+), 34 deletions(-) create mode 100644 app/src/main/res/menu/view_media_tooblar.xml diff --git a/app/src/main/java/com/keylesspalace/tusky/fragment/ViewMediaFragment.java b/app/src/main/java/com/keylesspalace/tusky/fragment/ViewMediaFragment.java index aa8d41b99..f53a4ef66 100644 --- a/app/src/main/java/com/keylesspalace/tusky/fragment/ViewMediaFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/fragment/ViewMediaFragment.java @@ -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; } } diff --git a/app/src/main/res/layout/fragment_view_media.xml b/app/src/main/res/layout/fragment_view_media.xml index 0b97166c6..db7833b19 100644 --- a/app/src/main/res/layout/fragment_view_media.xml +++ b/app/src/main/res/layout/fragment_view_media.xml @@ -1,20 +1,31 @@ - - - + android:background="@android:color/black" + android:clickable="true"> + android:layout_height="match_parent" + android:layout_below="@+id/toolbar" /> - \ No newline at end of file + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/view_media_tooblar.xml b/app/src/main/res/menu/view_media_tooblar.xml new file mode 100644 index 000000000..1de914f5f --- /dev/null +++ b/app/src/main/res/menu/view_media_tooblar.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file