Adds ability to page between multiple images in a status by swiping from left to right. Closes #66
This commit is contained in:
parent
b9d6f489d1
commit
e3745ebd6b
15 changed files with 361 additions and 147 deletions
app/src/main
AndroidManifest.xml
java/com/keylesspalace/tusky
ViewMediaActivity.java
adapter
fragment
NotificationsFragment.javaSFragment.javaTimelineFragment.javaViewMediaFragment.javaViewThreadFragment.java
interfaces
pager
view
res
|
@ -70,6 +70,7 @@
|
|||
android:name=".ViewThreadActivity"
|
||||
android:configChanges="orientation|screenSize" />
|
||||
<activity android:name=".ViewTagActivity" />
|
||||
<activity android:name=".ViewMediaActivity" />
|
||||
<activity android:name=".AccountActivity" />
|
||||
<activity android:name=".EditProfileActivity" />
|
||||
<activity android:name=".PreferencesActivity" />
|
||||
|
|
194
app/src/main/java/com/keylesspalace/tusky/ViewMediaActivity.java
Normal file
194
app/src/main/java/com/keylesspalace/tusky/ViewMediaActivity.java
Normal file
|
@ -0,0 +1,194 @@
|
|||
/* Copyright 2017 Andrew Dawson
|
||||
*
|
||||
* This file is a part of Tusky.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with Tusky; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
package com.keylesspalace.tusky;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.DownloadManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
||||
import com.keylesspalace.tusky.fragment.ViewMediaFragment;
|
||||
import com.keylesspalace.tusky.pager.ImagePagerAdapter;
|
||||
import com.keylesspalace.tusky.view.ImageViewPager;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class ViewMediaActivity extends BaseActivity implements ViewMediaFragment.OnDismissListener {
|
||||
private static final int PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE = 1;
|
||||
|
||||
private ImageViewPager viewPager;
|
||||
private View anyView;
|
||||
private String[] imageUrls;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_view_media);
|
||||
|
||||
// Obtain the views.
|
||||
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
viewPager = (ImageViewPager) findViewById(R.id.view_pager);
|
||||
anyView = toolbar;
|
||||
|
||||
// Gather the parameters.
|
||||
Intent intent = getIntent();
|
||||
imageUrls = intent.getStringArrayExtra("urls");
|
||||
int initialPosition = intent.getIntExtra("urlIndex", 0);
|
||||
|
||||
// Setup the view pager.
|
||||
final ImagePagerAdapter adapter = new ImagePagerAdapter(getSupportFragmentManager(),
|
||||
imageUrls);
|
||||
viewPager.setAdapter(adapter);
|
||||
viewPager.setCurrentItem(initialPosition);
|
||||
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
||||
@Override
|
||||
public void onPageScrolled(int position, float positionOffset,
|
||||
int positionOffsetPixels) {}
|
||||
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
CharSequence title = adapter.getPageTitle(position);
|
||||
toolbar.setTitle(title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int state) {}
|
||||
});
|
||||
|
||||
// Setup the toolbar.
|
||||
setSupportActionBar(toolbar);
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
if (actionBar != null) {
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
actionBar.setDisplayShowHomeEnabled(true);
|
||||
actionBar.setTitle(adapter.getPageTitle(initialPosition));
|
||||
}
|
||||
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
int id = item.getItemId();
|
||||
switch (id) {
|
||||
case R.id.action_download:
|
||||
downloadImage();
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.view_media_toolbar, menu);
|
||||
// Manually tint all action buttons, because the theme overlay doesn't handle them properly.
|
||||
for (int i = 0; i < menu.size(); i++) {
|
||||
Drawable drawable = menu.getItem(i).getIcon();
|
||||
if (drawable != null) {
|
||||
drawable.mutate();
|
||||
int color = ContextCompat.getColor(this, R.color.text_color_primary_dark);
|
||||
drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDismiss() {
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[],
|
||||
@NonNull int[] grantResults) {
|
||||
switch (requestCode) {
|
||||
case PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE: {
|
||||
if (grantResults.length > 0
|
||||
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
downloadImage();
|
||||
} else {
|
||||
doErrorDialog(R.string.error_media_download_permission, R.string.action_retry,
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
downloadImage();
|
||||
}
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void doErrorDialog(@StringRes int descriptionId, @StringRes int actionId,
|
||||
View.OnClickListener listener) {
|
||||
if (anyView != null) {
|
||||
Snackbar bar = Snackbar.make(anyView, getString(descriptionId),
|
||||
Snackbar.LENGTH_SHORT);
|
||||
bar.setAction(actionId, listener);
|
||||
bar.show();
|
||||
}
|
||||
}
|
||||
|
||||
private void downloadImage() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN &&
|
||||
ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||
!= PackageManager.PERMISSION_GRANTED) {
|
||||
ActivityCompat.requestPermissions(this,
|
||||
new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
|
||||
PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE);
|
||||
} else {
|
||||
String url = imageUrls[viewPager.getCurrentItem()];
|
||||
Uri uri = Uri.parse(url);
|
||||
|
||||
String filename = new File(url).getName();
|
||||
|
||||
DownloadManager downloadManager =
|
||||
(DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
|
||||
|
||||
DownloadManager.Request request = new DownloadManager.Request(uri);
|
||||
request.allowScanningByMediaScanner();
|
||||
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES,
|
||||
getString(R.string.app_name) + "/" + filename);
|
||||
|
||||
downloadManager.enqueue(request);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -202,6 +202,11 @@ class StatusViewHolder extends RecyclerView.ViewHolder {
|
|||
|
||||
final int n = Math.min(attachments.length, Status.MAX_MEDIA_ATTACHMENTS);
|
||||
|
||||
final String[] urls = new String[n];
|
||||
for (int i = 0; i < n; i++) {
|
||||
urls[i] = attachments[i].url;
|
||||
}
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
String previewUrl = attachments[i].previewUrl;
|
||||
|
||||
|
@ -218,16 +223,15 @@ class StatusViewHolder extends RecyclerView.ViewHolder {
|
|||
.into(previews[i]);
|
||||
}
|
||||
|
||||
final String url = attachments[i].url;
|
||||
final Status.MediaAttachment.Type type = attachments[i].type;
|
||||
|
||||
if(url == null || url.isEmpty()) {
|
||||
if (urls[i] == null || urls[i].isEmpty()) {
|
||||
previews[i].setOnClickListener(null);
|
||||
} else {
|
||||
final int urlIndex = i;
|
||||
final Status.MediaAttachment.Type type = attachments[i].type;
|
||||
previews[i].setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
listener.onViewMedia(url, type);
|
||||
listener.onViewMedia(urls, urlIndex, type);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -252,6 +252,7 @@ public class NotificationsFragment extends SFragment implements
|
|||
Log.e(TAG, "Fetch failure: " + exception.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
Notification notification = adapter.getItem(0);
|
||||
if (notification != null) {
|
||||
|
@ -261,39 +262,47 @@ public class NotificationsFragment extends SFragment implements
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReply(int position) {
|
||||
Notification notification = adapter.getItem(position);
|
||||
super.reply(notification.status);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReblog(boolean reblog, int position) {
|
||||
Notification notification = adapter.getItem(position);
|
||||
super.reblog(notification.status, reblog, adapter, position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFavourite(boolean favourite, int position) {
|
||||
Notification notification = adapter.getItem(position);
|
||||
super.favourite(notification.status, favourite, adapter, position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMore(View view, int position) {
|
||||
Notification notification = adapter.getItem(position);
|
||||
super.more(notification.status, view, adapter, position);
|
||||
}
|
||||
|
||||
public void onViewMedia(String url, Status.MediaAttachment.Type type) {
|
||||
super.viewMedia(url, type);
|
||||
@Override
|
||||
public void onViewMedia(String[] urls, int urlIndex, Status.MediaAttachment.Type type) {
|
||||
super.viewMedia(urls, urlIndex, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewThread(int position) {
|
||||
Notification notification = adapter.getItem(position);
|
||||
super.viewThread(notification.status);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewTag(String tag) {
|
||||
super.viewTag(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewAccount(String id) {
|
||||
super.viewAccount(id);
|
||||
}
|
||||
|
|
|
@ -19,8 +19,6 @@ import android.content.Intent;
|
|||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.support.v7.widget.PopupMenu;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
|
@ -33,6 +31,7 @@ import com.keylesspalace.tusky.BaseActivity;
|
|||
import com.keylesspalace.tusky.ComposeActivity;
|
||||
import com.keylesspalace.tusky.R;
|
||||
import com.keylesspalace.tusky.ReportActivity;
|
||||
import com.keylesspalace.tusky.ViewMediaActivity;
|
||||
import com.keylesspalace.tusky.ViewTagActivity;
|
||||
import com.keylesspalace.tusky.ViewThreadActivity;
|
||||
import com.keylesspalace.tusky.ViewVideoActivity;
|
||||
|
@ -271,18 +270,19 @@ public abstract class SFragment extends BaseFragment {
|
|||
popup.show();
|
||||
}
|
||||
|
||||
protected void viewMedia(String url, Status.MediaAttachment.Type type) {
|
||||
protected void viewMedia(String[] urls, int urlIndex, Status.MediaAttachment.Type type) {
|
||||
switch (type) {
|
||||
case IMAGE: {
|
||||
DialogFragment newFragment = ViewMediaFragment.newInstance(url);
|
||||
FragmentTransaction ft = getFragmentManager().beginTransaction();
|
||||
newFragment.show(ft, "view_media");
|
||||
Intent intent = new Intent(getContext(), ViewMediaActivity.class);
|
||||
intent.putExtra("urls", urls);
|
||||
intent.putExtra("urlIndex", urlIndex);
|
||||
startActivity(intent);
|
||||
break;
|
||||
}
|
||||
case GIFV:
|
||||
case VIDEO: {
|
||||
Intent intent = new Intent(getContext(), ViewVideoActivity.class);
|
||||
intent.putExtra("url", url);
|
||||
intent.putExtra("url", urls[urlIndex]);
|
||||
startActivity(intent);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -343,6 +343,7 @@ public class TimelineFragment extends SFragment implements
|
|||
Log.e(TAG, "Fetch Failure: " + exception.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
Status status = adapter.getItem(0);
|
||||
if (status != null) {
|
||||
|
@ -352,30 +353,37 @@ public class TimelineFragment extends SFragment implements
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReply(int position) {
|
||||
super.reply(adapter.getItem(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReblog(final boolean reblog, final int position) {
|
||||
super.reblog(adapter.getItem(position), reblog, adapter, position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFavourite(final boolean favourite, final int position) {
|
||||
super.favourite(adapter.getItem(position), favourite, adapter, position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMore(View view, final int position) {
|
||||
super.more(adapter.getItem(position), view, adapter, position);
|
||||
}
|
||||
|
||||
public void onViewMedia(String url, Status.MediaAttachment.Type type) {
|
||||
super.viewMedia(url, type);
|
||||
@Override
|
||||
public void onViewMedia(String[] urls, int urlIndex, Status.MediaAttachment.Type type) {
|
||||
super.viewMedia(urls, urlIndex, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewThread(int position) {
|
||||
super.viewThread(adapter.getItem(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewTag(String tag) {
|
||||
if (kind == Kind.TAG && hashtagOrId.equals(tag)) {
|
||||
// If already viewing a tag page, then ignore any request to view that tag again.
|
||||
|
@ -384,6 +392,7 @@ public class TimelineFragment extends SFragment implements
|
|||
super.viewTag(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewAccount(String id) {
|
||||
if (kind == Kind.USER && hashtagOrId.equals(id)) {
|
||||
/* If already viewing an account page, then any requests to view that account page
|
||||
|
|
|
@ -15,28 +15,12 @@
|
|||
|
||||
package com.keylesspalace.tusky.fragment;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.DownloadManager;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
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.github.chrisbanes.photoview.OnOutsidePhotoTapListener;
|
||||
|
@ -47,12 +31,13 @@ import com.keylesspalace.tusky.R;
|
|||
import com.squareup.picasso.Callback;
|
||||
import com.squareup.picasso.Picasso;
|
||||
|
||||
import java.io.File;
|
||||
public class ViewMediaFragment extends BaseFragment {
|
||||
public interface OnDismissListener {
|
||||
void onDismiss();
|
||||
}
|
||||
|
||||
public class ViewMediaFragment extends DialogFragment implements Toolbar.OnMenuItemClickListener {
|
||||
private PhotoViewAttacher attacher;
|
||||
|
||||
private static final int PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE = 1;
|
||||
private OnDismissListener onDismissListener;
|
||||
|
||||
public static ViewMediaFragment newInstance(String url) {
|
||||
Bundle arguments = new Bundle();
|
||||
|
@ -63,26 +48,16 @@ public class ViewMediaFragment extends DialogFragment implements Toolbar.OnMenuI
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setStyle(DialogFragment.STYLE_NORMAL, R.style.Dialog_FullScreen);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
ViewGroup.LayoutParams params = getDialog().getWindow().getAttributes();
|
||||
params.width = WindowManager.LayoutParams.MATCH_PARENT;
|
||||
params.height = WindowManager.LayoutParams.MATCH_PARENT;
|
||||
getDialog().getWindow().setAttributes((android.view.WindowManager.LayoutParams) params);
|
||||
super.onResume();
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
onDismissListener = (OnDismissListener) context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, final ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
Bundle savedInstanceState) {
|
||||
final View rootView = inflater.inflate(R.layout.fragment_view_media, container, false);
|
||||
|
||||
final Toolbar toolbar = (Toolbar) rootView.findViewById(R.id.toolbar);
|
||||
PhotoView photoView = (PhotoView) rootView.findViewById(R.id.view_media_image);
|
||||
|
||||
Bundle arguments = getArguments();
|
||||
|
@ -94,7 +69,7 @@ public class ViewMediaFragment extends DialogFragment implements Toolbar.OnMenuI
|
|||
attacher.setOnOutsidePhotoTapListener(new OnOutsidePhotoTapListener() {
|
||||
@Override
|
||||
public void onOutsidePhotoTap(ImageView imageView) {
|
||||
dismiss();
|
||||
onDismissListener.onDismiss();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -105,29 +80,19 @@ public class ViewMediaFragment extends DialogFragment implements Toolbar.OnMenuI
|
|||
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
|
||||
float velocityY) {
|
||||
if (Math.abs(velocityY) > Math.abs(velocityX)) {
|
||||
dismiss();
|
||||
onDismissListener.onDismiss();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
Picasso.with(getContext())
|
||||
.load(url)
|
||||
.into(photoView, new Callback() {
|
||||
@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();
|
||||
}
|
||||
|
||||
|
@ -137,76 +102,4 @@ public class ViewMediaFragment extends DialogFragment implements Toolbar.OnMenuI
|
|||
|
||||
return rootView;
|
||||
}
|
||||
|
||||
private void downloadImage() {
|
||||
//Permission stuff
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN
|
||||
&& ContextCompat.checkSelfPermission(getContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||
!= PackageManager.PERMISSION_GRANTED) {
|
||||
ActivityCompat.requestPermissions(getActivity(),
|
||||
new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
|
||||
PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE);
|
||||
} else {
|
||||
//download stuff
|
||||
String url = getArguments().getString("url");
|
||||
Uri uri = Uri.parse(url);
|
||||
|
||||
String filename = new File(url).getName();
|
||||
|
||||
DownloadManager downloadManager = (DownloadManager) getContext()
|
||||
.getSystemService(Context.DOWNLOAD_SERVICE);
|
||||
|
||||
DownloadManager.Request request = new DownloadManager.Request(uri);
|
||||
request.allowScanningByMediaScanner();
|
||||
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES,
|
||||
getString(R.string.app_name) + "/" + filename);
|
||||
|
||||
downloadManager.enqueue(request);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[],
|
||||
@NonNull int[] grantResults) {
|
||||
switch (requestCode) {
|
||||
case PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE: {
|
||||
if (grantResults.length > 0
|
||||
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
downloadImage();
|
||||
} else {
|
||||
doErrorDialog(R.string.error_media_download_permission, R.string.action_retry,
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
downloadImage();
|
||||
}
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void doErrorDialog(@StringRes int descriptionId, @StringRes int actionId,
|
||||
View.OnClickListener listener) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -182,31 +182,38 @@ public class ViewThreadFragment extends SFragment implements
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
sendStatusRequest(thisThreadsStatusId);
|
||||
sendThreadRequest(thisThreadsStatusId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReply(int position) {
|
||||
super.reply(adapter.getItem(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReblog(boolean reblog, int position) {
|
||||
super.reblog(adapter.getItem(position), reblog, adapter, position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFavourite(boolean favourite, int position) {
|
||||
super.favourite(adapter.getItem(position), favourite, adapter, position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMore(View view, int position) {
|
||||
super.more(adapter.getItem(position), view, adapter, position);
|
||||
}
|
||||
|
||||
public void onViewMedia(String url, Status.MediaAttachment.Type type) {
|
||||
super.viewMedia(url, type);
|
||||
@Override
|
||||
public void onViewMedia(String[] urls, int urlIndex, Status.MediaAttachment.Type type) {
|
||||
super.viewMedia(urls, urlIndex, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewThread(int position) {
|
||||
Status status = adapter.getItem(position);
|
||||
if (thisThreadsStatusId.equals(status.id)) {
|
||||
|
@ -216,10 +223,12 @@ public class ViewThreadFragment extends SFragment implements
|
|||
super.viewThread(status);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewTag(String tag) {
|
||||
super.viewTag(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewAccount(String id) {
|
||||
super.viewAccount(id);
|
||||
}
|
||||
|
|
|
@ -24,6 +24,6 @@ public interface StatusActionListener extends LinkListener {
|
|||
void onReblog(final boolean reblog, final int position);
|
||||
void onFavourite(final boolean favourite, final int position);
|
||||
void onMore(View view, final int position);
|
||||
void onViewMedia(String url, Status.MediaAttachment.Type type);
|
||||
void onViewMedia(String[] urls, int index, Status.MediaAttachment.Type type);
|
||||
void onViewThread(int position);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
package com.keylesspalace.tusky.pager;
|
||||
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
|
||||
import com.keylesspalace.tusky.fragment.ViewMediaFragment;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class ImagePagerAdapter extends FragmentPagerAdapter {
|
||||
private String[] urls;
|
||||
|
||||
public ImagePagerAdapter(FragmentManager fragmentManager, String[] urls) {
|
||||
super(fragmentManager);
|
||||
this.urls = urls;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
if (position >= 0 && position < urls.length) {
|
||||
return ViewMediaFragment.newInstance(urls[position]);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return urls.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getPageTitle(int position) {
|
||||
return String.format(Locale.getDefault(), "%d/%d", position + 1, urls.length);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
/* Copyright 2017 Andrew Dawson
|
||||
*
|
||||
* This file is a part of Tusky.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with Tusky; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
package com.keylesspalace.tusky.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
/**
|
||||
* This class is entirely to address a known issue with com.github.chrisbanes.photoview.PhotoView.
|
||||
* ViewPager will throw exceptions when a PhotoView is placed within it, so this subclass eats those
|
||||
* exceptions.
|
||||
*/
|
||||
public class ImageViewPager extends ViewPager {
|
||||
public ImageViewPager(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public ImageViewPager(Context context, AttributeSet attributeSet) {
|
||||
super(context, attributeSet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
||||
try {
|
||||
return super.onInterceptTouchEvent(ev);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -67,7 +67,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/tab_layout"
|
||||
android:layout_alignParentBottom="true"/>
|
||||
android:layout_alignParentBottom="true" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
|
|
22
app/src/main/res/layout/activity_view_media.xml
Normal file
22
app/src/main/res/layout/activity_view_media.xml
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@android:color/black">
|
||||
|
||||
<com.keylesspalace.tusky.view.ImageViewPager
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/view_pager" />
|
||||
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:theme="@style/AppTheme.Account.AppBarLayout"
|
||||
app:popupTheme="@style/AppTheme.Account.ToolbarPopupTheme.Dark"
|
||||
android:background="@color/toolbar_view_media" />
|
||||
|
||||
</FrameLayout>
|
|
@ -1,10 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<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:layout_gravity="center"
|
||||
android:background="@android:color/black"
|
||||
android:clickable="true">
|
||||
|
||||
<com.github.chrisbanes.photoview.PhotoView
|
||||
|
@ -12,13 +10,6 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:background="@color/toolbar_view_media"
|
||||
app:navigationIcon="?attr/homeAsUpIndicator" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/view_media_progress"
|
||||
android:layout_width="wrap_content"
|
||||
|
|
Loading…
Add table
Reference in a new issue