Yuito-app-android/app/src/main/java/com/keylesspalace/tusky/ViewMediaFragment.java

83 lines
2.6 KiB
Java
Raw Normal View History

2017-01-20 09:09:10 +01:00
/* Copyright 2017 Andrew Dawson
*
* This file is part of Tusky.
*
* Tusky 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.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
2017-03-09 21:21:55 +01:00
import com.squareup.picasso.Callback;
import com.squareup.picasso.Picasso;
import uk.co.senab.photoview.PhotoView;
import uk.co.senab.photoview.PhotoViewAttacher;
public class ViewMediaFragment extends Fragment {
public static ViewMediaFragment newInstance(String url) {
Bundle arguments = new Bundle();
ViewMediaFragment fragment = new ViewMediaFragment();
arguments.putString("url", url);
fragment.setArguments(arguments);
return fragment;
}
@Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_view_media, container, false);
Bundle arguments = getArguments();
String url = arguments.getString("url");
2017-03-09 21:21:55 +01:00
PhotoView photoView = (PhotoView) rootView.findViewById(R.id.view_media_image);
final PhotoViewAttacher attacher = new PhotoViewAttacher(photoView);
2017-03-09 21:21:55 +01:00
attacher.setOnPhotoTapListener(new PhotoViewAttacher.OnPhotoTapListener() {
@Override
2017-03-09 21:21:55 +01:00
public void onPhotoTap(View view, float x, float y) {
}
@Override
public void onOutsidePhotoTap() {
dismiss();
}
});
2017-03-09 21:21:55 +01:00
Picasso.with(getContext())
.load(url)
.into(photoView, new Callback() {
@Override
public void onSuccess() {
attacher.update();
}
@Override
public void onError() {
}
});
return rootView;
}
private void dismiss() {
getFragmentManager().popBackStack();
}
}