Some changes
This commit is contained in:
parent
c3673b57ae
commit
42c782a841
|
@ -16,15 +16,25 @@ package app.fedilab.android.activities;
|
|||
|
||||
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.DownloadManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.GestureDetector;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
||||
import android.widget.ImageButton;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentStatePagerAdapter;
|
||||
|
@ -32,27 +42,33 @@ import androidx.viewpager.widget.PagerAdapter;
|
|||
import androidx.viewpager.widget.ViewPager;
|
||||
|
||||
|
||||
import com.gw.swipeback.SwipeBackLayout;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import app.fedilab.android.R;
|
||||
import app.fedilab.android.client.Entities.Attachment;
|
||||
import app.fedilab.android.client.Entities.Error;
|
||||
import app.fedilab.android.client.HttpsConnection;
|
||||
import app.fedilab.android.fragments.MediaSliderFragment;
|
||||
import app.fedilab.android.helper.Helper;
|
||||
|
||||
import app.fedilab.android.interfaces.OnDownloadInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Created by Thomas on 25/06/2017.
|
||||
* Created by Thomas on 10/10/2019.
|
||||
* Media Activity
|
||||
*/
|
||||
|
||||
public class SlideMediaActivity extends BaseActivity {
|
||||
public class SlideMediaActivity extends BaseActivity implements OnDownloadInterface {
|
||||
|
||||
private ArrayList<Attachment> attachments;
|
||||
private int mediaPosition;
|
||||
private ViewPager mPager;
|
||||
private long downloadID;
|
||||
public SwipeBackLayout mSwipeBackLayout;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -64,13 +80,13 @@ public class SlideMediaActivity extends BaseActivity {
|
|||
setContentView(R.layout.activity_media_pager);
|
||||
supportPostponeEnterTransition();
|
||||
supportStartPostponedEnterTransition();
|
||||
CoordinatorLayout main_container_media = findViewById(R.id.main_container_media);
|
||||
SwipeBackLayout swipeBackLayout = findViewById(R.id.swipeBackLayout);
|
||||
if (theme == Helper.THEME_LIGHT) {
|
||||
main_container_media.setBackgroundResource(R.color.mastodonC2);
|
||||
swipeBackLayout.setBackgroundResource(R.color.white);
|
||||
} else if (theme == Helper.THEME_BLACK) {
|
||||
main_container_media.setBackgroundResource(R.color.black);
|
||||
swipeBackLayout.setBackgroundResource(R.color.black);
|
||||
} else if (theme == Helper.THEME_DARK) {
|
||||
main_container_media.setBackgroundResource(R.color.mastodonC1_);
|
||||
swipeBackLayout.setBackgroundResource(R.color.mastodonC1);
|
||||
}
|
||||
attachments = getIntent().getParcelableArrayListExtra("mediaArray");
|
||||
if (getIntent().getExtras() != null)
|
||||
|
@ -86,6 +102,104 @@ public class SlideMediaActivity extends BaseActivity {
|
|||
|
||||
mPager.setCurrentItem(mediaPosition-1);
|
||||
|
||||
registerReceiver(onDownloadComplete,new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
|
||||
ImageButton media_save = findViewById(R.id.media_save);
|
||||
ImageButton media_share = findViewById(R.id.media_share);
|
||||
ImageButton media_close = findViewById(R.id.media_close);
|
||||
|
||||
|
||||
media_save.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
int position = mPager.getCurrentItem();
|
||||
Attachment attachment = attachments.get(position);
|
||||
if (attachment.getType().toLowerCase().equals("video") || attachment.getType().toLowerCase().equals("audio") || attachment.getType().toLowerCase().equals("gifv") || attachment.getType().toLowerCase().equals("web")) { ;
|
||||
new HttpsConnection(getApplicationContext(), Helper.getLiveInstance(getApplicationContext())).download(attachment.getUrl(), SlideMediaActivity.this);
|
||||
} else {
|
||||
if (Build.VERSION.SDK_INT >= 23) {
|
||||
if (ContextCompat.checkSelfPermission(SlideMediaActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(SlideMediaActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
||||
ActivityCompat.requestPermissions(SlideMediaActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, Helper.EXTERNAL_STORAGE_REQUEST_CODE);
|
||||
} else {
|
||||
Helper.manageDownloadsNoPopup(SlideMediaActivity.this, attachment.getUrl());
|
||||
downloadID = -1;
|
||||
}
|
||||
} else {
|
||||
Helper.manageDownloadsNoPopup(SlideMediaActivity.this, attachment.getUrl());
|
||||
downloadID = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
media_share.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
int position = mPager.getCurrentItem();
|
||||
Attachment attachment = attachments.get(position);
|
||||
if (attachment.getType().toLowerCase().equals("video") || attachment.getType().toLowerCase().equals("audio") || attachment.getType().toLowerCase().equals("gifv")) {
|
||||
new HttpsConnection(getApplicationContext(), Helper.getLiveInstance(getApplicationContext())).download(attachment.getUrl(), SlideMediaActivity.this);
|
||||
} else {
|
||||
if (Build.VERSION.SDK_INT >= 23) {
|
||||
if (ContextCompat.checkSelfPermission(SlideMediaActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(SlideMediaActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
||||
ActivityCompat.requestPermissions(SlideMediaActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, Helper.EXTERNAL_STORAGE_REQUEST_CODE);
|
||||
} else {
|
||||
downloadID = Helper.manageDownloadsNoPopup(SlideMediaActivity.this, attachment.getUrl());
|
||||
}
|
||||
} else {
|
||||
downloadID = Helper.manageDownloadsNoPopup(SlideMediaActivity.this, attachment.getUrl());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
media_close.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
mSwipeBackLayout = new SwipeBackLayout(SlideMediaActivity.this);
|
||||
mSwipeBackLayout.setDirectionMode(SwipeBackLayout.FROM_TOP);
|
||||
mSwipeBackLayout.setMaskAlpha(125);
|
||||
mSwipeBackLayout.setSwipeBackFactor(0.5f);
|
||||
mSwipeBackLayout.setSwipeBackListener(new SwipeBackLayout.OnSwipeBackListener() {
|
||||
@Override
|
||||
public void onViewPositionChanged(View mView, float swipeBackFraction, float SWIPE_BACK_FACTOR) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewSwipeFinished(View mView, boolean isEnd) {
|
||||
if (isEnd){
|
||||
finish();
|
||||
overridePendingTransition(0, 0);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
mSwipeBackLayout.attachToActivity(this);
|
||||
|
||||
}
|
||||
|
||||
|
||||
private BroadcastReceiver onDownloadComplete = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
long id = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);
|
||||
if (downloadID == id) {
|
||||
DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
|
||||
assert manager != null;
|
||||
Uri uri = manager.getUriForDownloadedFile(downloadID);
|
||||
Intent shareIntent = new Intent(Intent.ACTION_SEND);
|
||||
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
|
||||
shareIntent.putExtra(Intent.EXTRA_TEXT, R.string.share_with);
|
||||
context.startActivity(shareIntent);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
unregisterReceiver(onDownloadComplete);
|
||||
}
|
||||
|
||||
private MediaSliderFragment mCurrentFragment;
|
||||
|
@ -95,6 +209,16 @@ public class SlideMediaActivity extends BaseActivity {
|
|||
return mCurrentFragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDownloaded(String saveFilePath, String downloadUrl, Error error) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdateProgress(int progress) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Media Pager
|
||||
*/
|
||||
|
|
|
@ -23,11 +23,8 @@ import android.graphics.Bitmap;
|
|||
import android.graphics.RectF;
|
||||
import android.media.MediaPlayer;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
@ -40,15 +37,9 @@ import android.widget.ImageView;
|
|||
import android.widget.ProgressBar;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.request.target.SimpleTarget;
|
||||
import com.bumptech.glide.request.transition.Transition;
|
||||
|
@ -64,37 +55,20 @@ import com.google.android.exoplayer2.ui.SimpleExoPlayerView;
|
|||
import com.google.android.exoplayer2.upstream.DataSource;
|
||||
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
import com.gw.swipeback.SwipeBackLayout;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
|
||||
import app.fedilab.android.R;
|
||||
import app.fedilab.android.activities.MediaActivity;
|
||||
import app.fedilab.android.asynctasks.RetrieveFeedsAsyncTask;
|
||||
import app.fedilab.android.client.APIResponse;
|
||||
import app.fedilab.android.activities.SlideMediaActivity;
|
||||
import app.fedilab.android.client.Entities.Attachment;
|
||||
import app.fedilab.android.client.Entities.Error;
|
||||
import app.fedilab.android.client.Entities.Status;
|
||||
import app.fedilab.android.client.HttpsConnection;
|
||||
import app.fedilab.android.client.TLSSocketFactory;
|
||||
import app.fedilab.android.drawers.ImageAdapter;
|
||||
import app.fedilab.android.helper.Helper;
|
||||
import app.fedilab.android.interfaces.OnDownloadInterface;
|
||||
import app.fedilab.android.interfaces.OnRetrieveFeedsInterface;
|
||||
import app.fedilab.android.webview.MastalabWebChromeClient;
|
||||
import app.fedilab.android.webview.MastalabWebViewClient;
|
||||
import cafe.adriel.androidaudiorecorder.VisualizerHandler;
|
||||
import es.dmoral.toasty.Toasty;
|
||||
|
||||
import static android.content.Context.MODE_PRIVATE;
|
||||
import static app.fedilab.android.helper.Helper.changeDrawableColor;
|
||||
|
@ -106,65 +80,30 @@ import static cafe.adriel.androidaudiorecorder.Util.getDarkerColor;
|
|||
* Created by Thomas on 09/10/2019.
|
||||
* Fragment to display media from SlideMediaActivity
|
||||
*/
|
||||
public class MediaSliderFragment extends Fragment implements OnDownloadInterface, MediaPlayer.OnCompletionListener {
|
||||
public class MediaSliderFragment extends Fragment implements MediaPlayer.OnCompletionListener {
|
||||
|
||||
|
||||
|
||||
private boolean flag_loading;
|
||||
private Context context;
|
||||
private AsyncTask<Void, Void, Void> asyncTask;
|
||||
private String max_id;
|
||||
private RelativeLayout mainLoader, nextElementLoader, textviewNoAction;
|
||||
private boolean firstLoad;
|
||||
private String targetedId;
|
||||
private boolean showMediaOnly, showPinned, showReply;
|
||||
boolean firstTootsLoaded;
|
||||
private SharedPreferences sharedpreferences;
|
||||
private ArrayList<Status> statuses;
|
||||
private ImageAdapter gridAdaper;
|
||||
private RecyclerView gridview;
|
||||
private int mediaPosition;
|
||||
|
||||
|
||||
|
||||
private WebView webview_video;
|
||||
private ImageButton media_save, media_share, media_close;
|
||||
private boolean scheduleHidden, scheduleHiddenDescription;
|
||||
private SimpleExoPlayer player;
|
||||
private boolean isSHaring;
|
||||
private String instance;
|
||||
private RelativeLayout content_audio;
|
||||
private MediaPlayer playeraudio;
|
||||
private Timer timer;
|
||||
private int playerSecondsElapsed;
|
||||
private static final Handler HANDLER = new Handler();
|
||||
private String url;
|
||||
|
||||
private RelativeLayout loader;
|
||||
private ArrayList<Attachment> attachments;
|
||||
private PhotoView imageView;
|
||||
private SimpleExoPlayerView videoView;
|
||||
private float downX;
|
||||
private float downY;
|
||||
static final int MIN_DISTANCE = 100;
|
||||
private String finalUrlDownload;
|
||||
private String preview_url;
|
||||
private ImageView prev, next;
|
||||
private boolean isControlElementShown = true;
|
||||
private Bitmap downloadedImage;
|
||||
private File fileVideo;
|
||||
private TextView progress;
|
||||
private ProgressBar pbar_inf;
|
||||
private TextView message_ready;
|
||||
private boolean canSwipe;
|
||||
private TextView media_description;
|
||||
private Attachment attachment;
|
||||
private float imageScale = 0;
|
||||
private RelativeLayout action_bar_container;
|
||||
private VisualizerHandler visualizerHandler;
|
||||
private TextView statusView;
|
||||
private TextView timerView;
|
||||
private ImageButton playView;
|
||||
private GLAudioVisualizationView visualizerView;
|
||||
|
||||
public MediaSliderFragment() {
|
||||
}
|
||||
|
||||
|
@ -180,74 +119,22 @@ public class MediaSliderFragment extends Fragment implements OnDownloadInterface
|
|||
attachment = bundle.getParcelable("attachment");
|
||||
}
|
||||
Log.v(Helper.TAG,mediaPosition + " -> " + attachment);
|
||||
media_description = rootView.findViewById(R.id.media_description);
|
||||
TextView media_description = rootView.findViewById(R.id.media_description);
|
||||
message_ready = rootView.findViewById(R.id.message_ready);
|
||||
media_save = rootView.findViewById(R.id.media_save);
|
||||
media_share = rootView.findViewById(R.id.media_share);
|
||||
media_close = rootView.findViewById(R.id.media_close);
|
||||
progress = rootView.findViewById(R.id.loader_progress);
|
||||
webview_video = rootView.findViewById(R.id.webview_video);
|
||||
content_audio = rootView.findViewById(R.id.content_audio);
|
||||
media_save.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
isSHaring = false;
|
||||
if (attachment.getType().toLowerCase().equals("video") || attachment.getType().toLowerCase().equals("audio") || attachment.getType().toLowerCase().equals("gifv") || attachment.getType().toLowerCase().equals("web")) {
|
||||
if (attachment != null) {
|
||||
progress.setText("0 %");
|
||||
progress.setVisibility(View.VISIBLE);
|
||||
new HttpsConnection(context, instance).download(attachment.getUrl(), MediaSliderFragment.this);
|
||||
}
|
||||
} else {
|
||||
if (Build.VERSION.SDK_INT >= 23) {
|
||||
if (ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
||||
ActivityCompat.requestPermissions((Activity)context, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, Helper.EXTERNAL_STORAGE_REQUEST_CODE);
|
||||
} else {
|
||||
Helper.manageMoveFileDownload(context, preview_url, finalUrlDownload, downloadedImage, fileVideo, false);
|
||||
}
|
||||
} else {
|
||||
Helper.manageMoveFileDownload(context, preview_url, finalUrlDownload, downloadedImage, fileVideo, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
media_share.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
isSHaring = true;
|
||||
if (attachment.getType().toLowerCase().equals("video") || attachment.getType().toLowerCase().equals("audio") || attachment.getType().toLowerCase().equals("gifv")) {
|
||||
if (attachment != null) {
|
||||
progress.setText("0 %");
|
||||
progress.setVisibility(View.VISIBLE);
|
||||
new HttpsConnection(context, instance).download(attachment.getUrl(), MediaSliderFragment.this);
|
||||
}
|
||||
} else {
|
||||
if (Build.VERSION.SDK_INT >= 23) {
|
||||
if (ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
||||
ActivityCompat.requestPermissions((Activity)context, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, Helper.EXTERNAL_STORAGE_REQUEST_CODE);
|
||||
} else {
|
||||
Helper.manageMoveFileDownload(context, preview_url, finalUrlDownload, downloadedImage, fileVideo, true);
|
||||
}
|
||||
} else {
|
||||
Helper.manageMoveFileDownload(context, preview_url, finalUrlDownload, downloadedImage, fileVideo, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
media_close.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
((Activity)context).finish();
|
||||
}
|
||||
});
|
||||
sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
||||
|
||||
TextView progress = rootView.findViewById(R.id.loader_progress);
|
||||
WebView webview_video = rootView.findViewById(R.id.webview_video);
|
||||
RelativeLayout content_audio = rootView.findViewById(R.id.content_audio);
|
||||
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
||||
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
||||
|
||||
loader = rootView.findViewById(R.id.loader);
|
||||
ImageView prev = rootView.findViewById(R.id.media_prev);
|
||||
ImageView next = rootView.findViewById(R.id.media_next);
|
||||
|
||||
imageView = rootView.findViewById(R.id.media_picture);
|
||||
videoView = rootView.findViewById(R.id.media_video);
|
||||
prev = rootView.findViewById(R.id.media_prev);
|
||||
next = rootView.findViewById(R.id.media_next);
|
||||
SimpleExoPlayerView videoView = rootView.findViewById(R.id.media_video);
|
||||
if (theme == Helper.THEME_BLACK) {
|
||||
changeDrawableColor(context, prev, R.color.dark_icon);
|
||||
changeDrawableColor(context, next, R.color.dark_icon);
|
||||
|
@ -275,17 +162,13 @@ public class MediaSliderFragment extends Fragment implements OnDownloadInterface
|
|||
imageView.setOnMatrixChangeListener(new OnMatrixChangedListener() {
|
||||
@Override
|
||||
public void onMatrixChanged(RectF rect) {
|
||||
imageScale = imageView.getScale();
|
||||
canSwipe = (imageView.getScale() == 1);
|
||||
((SlideMediaActivity)context).mSwipeBackLayout.isDisabled(imageView.getScale() != 1);
|
||||
}
|
||||
});
|
||||
if (attachments != null && attachments.size() > 1) {
|
||||
prev.setVisibility(View.VISIBLE);
|
||||
next.setVisibility(View.VISIBLE);
|
||||
}
|
||||
pbar_inf = rootView.findViewById(R.id.pbar_inf);
|
||||
ProgressBar pbar_inf = rootView.findViewById(R.id.pbar_inf);
|
||||
String type = attachment.getType();
|
||||
preview_url = attachment.getPreview_url();
|
||||
String preview_url = attachment.getPreview_url();
|
||||
if (type.equals("unknown")) {
|
||||
preview_url = attachment.getRemote_url();
|
||||
if (preview_url.endsWith(".png") || preview_url.endsWith(".jpg") || preview_url.endsWith(".jpeg") || preview_url.endsWith(".gif")) {
|
||||
|
@ -301,7 +184,7 @@ public class MediaSliderFragment extends Fragment implements OnDownloadInterface
|
|||
case "image":
|
||||
pbar_inf.setScaleY(1f);
|
||||
imageView.setVisibility(View.VISIBLE);
|
||||
fileVideo = null;
|
||||
File fileVideo = null;
|
||||
pbar_inf.setIndeterminate(true);
|
||||
loader.setVisibility(View.VISIBLE);
|
||||
fileVideo = null;
|
||||
|
@ -323,7 +206,6 @@ public class MediaSliderFragment extends Fragment implements OnDownloadInterface
|
|||
loader.setVisibility(View.GONE);
|
||||
Bitmap imageCompressed = Helper.compressImageIfNeeded(context, resource);
|
||||
if (imageView.getScale() < 1.1) {
|
||||
downloadedImage = resource;
|
||||
imageView.setImageBitmap(imageCompressed);
|
||||
} else {
|
||||
message_ready.setVisibility(View.VISIBLE);
|
||||
|
@ -331,7 +213,6 @@ public class MediaSliderFragment extends Fragment implements OnDownloadInterface
|
|||
message_ready.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
downloadedImage = resource;
|
||||
imageView.setImageBitmap(imageCompressed);
|
||||
message_ready.setVisibility(View.GONE);
|
||||
}
|
||||
|
@ -353,7 +234,7 @@ public class MediaSliderFragment extends Fragment implements OnDownloadInterface
|
|||
pbar_inf.setIndeterminate(false);
|
||||
pbar_inf.setScaleY(3f);
|
||||
try {
|
||||
HttpsURLConnection.setDefaultSSLSocketFactory(new TLSSocketFactory(instance));
|
||||
HttpsURLConnection.setDefaultSSLSocketFactory(new TLSSocketFactory(Helper.getLiveInstance(context)));
|
||||
} catch (KeyManagementException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
|
@ -485,9 +366,6 @@ public class MediaSliderFragment extends Fragment implements OnDownloadInterface
|
|||
playView.setImageResource(R.drawable.aar_ic_play);
|
||||
|
||||
visualizerView.release();
|
||||
if (visualizerHandler != null) {
|
||||
visualizerHandler.stop();
|
||||
}
|
||||
|
||||
if (playeraudio != null) {
|
||||
try {
|
||||
|
@ -599,46 +477,10 @@ public class MediaSliderFragment extends Fragment implements OnDownloadInterface
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onDownloaded(String path, String originUrl, Error error) {
|
||||
if (path != null) {
|
||||
File response = new File(path);
|
||||
File dir = context.getCacheDir();
|
||||
File from = new File(dir, response.getName());
|
||||
File to = new File(dir, Helper.md5(originUrl) + ".mp4");
|
||||
if (from.exists())
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
from.renameTo(to);
|
||||
fileVideo = to;
|
||||
downloadedImage = null;
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= 23) {
|
||||
if (ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
||||
ActivityCompat.requestPermissions((Activity)context, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, Helper.EXTERNAL_STORAGE_REQUEST_CODE);
|
||||
} else {
|
||||
Helper.manageMoveFileDownload(context, preview_url, finalUrlDownload, downloadedImage, fileVideo, isSHaring);
|
||||
}
|
||||
} else {
|
||||
Helper.manageMoveFileDownload(context, preview_url, finalUrlDownload, downloadedImage, fileVideo, isSHaring);
|
||||
}
|
||||
if (progress != null)
|
||||
progress.setVisibility(View.GONE);
|
||||
if (loader != null)
|
||||
loader.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
|
||||
public boolean canSwipe(){
|
||||
return canSwipe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdateProgress(int progressPercentage) {
|
||||
progress.setText(String.format("%s%%", String.valueOf(progressPercentage)));
|
||||
pbar_inf.setProgress(progressPercentage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCompletion(MediaPlayer mp) {
|
||||
|
|
|
@ -1106,6 +1106,35 @@ public class Helper {
|
|||
alert.show();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Manage downloads with URLs
|
||||
*
|
||||
* @param context Context
|
||||
* @param url String download url
|
||||
*/
|
||||
public static long manageDownloadsNoPopup(final Context context, final String url) {
|
||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
|
||||
final DownloadManager.Request request;
|
||||
try {
|
||||
request = new DownloadManager.Request(Uri.parse(url.trim()));
|
||||
} catch (Exception e) {
|
||||
Toasty.error(context, context.getString(R.string.toast_error), Toast.LENGTH_LONG).show();
|
||||
return -1;
|
||||
}
|
||||
final String fileName = URLUtil.guessFileName(url, null, null);
|
||||
request.allowScanningByMediaScanner();
|
||||
String myDir = sharedpreferences.getString(Helper.SET_FOLDER_RECORD, Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath());
|
||||
request.setDestinationInExternalPublicDir(myDir, fileName);
|
||||
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
|
||||
DownloadManager dm = (DownloadManager) context.getSystemService(DOWNLOAD_SERVICE);
|
||||
assert dm != null;
|
||||
return dm.enqueue(request);
|
||||
}
|
||||
|
||||
|
||||
public static String getMimeType(String url) {
|
||||
String type = null;
|
||||
String extension = MimeTypeMap.getFileExtensionFromUrl(url);
|
||||
|
|
|
@ -14,18 +14,81 @@
|
|||
You should have received a copy of the GNU General Public License along with Fedilab; if not,
|
||||
see <http://www.gnu.org/licenses>.
|
||||
-->
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
<com.gw.swipeback.SwipeBackLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/swipeBackLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:fitsSystemWindows="true"
|
||||
android:id="@+id/main_container_media"
|
||||
tools:context="app.fedilab.android.activities.SlideMediaActivity">
|
||||
<androidx.viewpager.widget.ViewPager
|
||||
android:id="@+id/media_viewpager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
|
||||
app:directionMode="bottom"
|
||||
app:isSwipeFromEdge="true"
|
||||
app:maskAlpha="125"
|
||||
app:swipeBackFactor="0.5">
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/main_container_media">
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/transparent_grey"
|
||||
android:id="@+id/action_bar_container"
|
||||
android:paddingTop="16dp">
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/media_close"
|
||||
android:layout_width="35dp"
|
||||
android:layout_height="35dp"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:background="@color/transparent"
|
||||
android:contentDescription="@string/close"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/ic_close"
|
||||
app:layout_anchorGravity="top|left" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_alignParentEnd="true"
|
||||
app:layout_anchorGravity="top|left"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
<ImageButton
|
||||
android:id="@+id/media_save"
|
||||
android:scaleType="fitXY"
|
||||
android:layout_marginStart="20dp"
|
||||
android:background="@color/transparent"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="30dp"
|
||||
android:src="@drawable/ic_save_white"
|
||||
android:contentDescription="@string/download" />
|
||||
<ImageButton
|
||||
android:id="@+id/media_share"
|
||||
app:layout_anchorGravity="top|left"
|
||||
android:layout_marginStart="10dp"
|
||||
android:background="@color/transparent"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="30dp"
|
||||
android:src="@drawable/ic_share_media"
|
||||
android:scaleType="fitXY"
|
||||
android:contentDescription="@string/share" />
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
||||
<androidx.viewpager.widget.ViewPager
|
||||
android:id="@+id/media_viewpager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
|
||||
|
||||
</RelativeLayout>
|
||||
</com.gw.swipeback.SwipeBackLayout>
|
|
@ -1,8 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/main_container_media">
|
||||
|
||||
|
||||
|
@ -105,7 +105,8 @@
|
|||
android:textSize="60sp"
|
||||
android:textColor="@android:color/white"
|
||||
android:fontFamily="sans-serif-thin"
|
||||
android:text="00:00:00" />
|
||||
android:text="00:00:00"
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
@ -125,7 +126,8 @@
|
|||
android:scaleType="fitCenter"
|
||||
android:src="@drawable/aar_ic_play"
|
||||
android:onClick="togglePlaying"
|
||||
style="@style/Widget.AppCompat.Button.Borderless" />
|
||||
style="@style/Widget.AppCompat.Button.Borderless"
|
||||
android:contentDescription="@string/play_video" />
|
||||
</RelativeLayout>
|
||||
|
||||
</RelativeLayout>
|
||||
|
@ -137,77 +139,13 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/transparent_grey"
|
||||
android:id="@+id/action_bar_container"
|
||||
android:paddingTop="16dp">
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/media_close"
|
||||
android:layout_width="35dp"
|
||||
android:layout_height="35dp"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:background="@color/transparent"
|
||||
android:contentDescription="@string/close"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/ic_close"
|
||||
app:layout_anchorGravity="top|left" />
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignParentEnd="true"
|
||||
app:layout_anchorGravity="top|left"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/media_save"
|
||||
android:scaleType="fitXY"
|
||||
android:layout_marginStart="20dp"
|
||||
android:background="@color/transparent"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="30dp"
|
||||
android:src="@drawable/ic_save_white"
|
||||
android:contentDescription="@string/download" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/media_share"
|
||||
app:layout_anchorGravity="top|left"
|
||||
android:layout_marginStart="10dp"
|
||||
android:background="@color/transparent"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginRight="15dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="30dp"
|
||||
android:src="@drawable/ic_share_media"
|
||||
android:scaleType="fitXY"
|
||||
android:contentDescription="@string/share" />
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/media_prev"
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="50dp"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginStart="5dp"
|
||||
android:layout_marginLeft="5dp"
|
||||
|
@ -226,7 +164,6 @@
|
|||
android:layout_width="30dp"
|
||||
android:layout_height="50dp"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginStart="5dp"
|
||||
android:layout_marginLeft="5dp"
|
||||
|
|
Loading…
Reference in New Issue