Fix some errors

This commit is contained in:
stom79 2018-10-21 16:18:59 +02:00
parent 75b6b9bb76
commit c33ddd3952
4 changed files with 47 additions and 37 deletions

View File

@ -17,6 +17,7 @@ package fr.gouv.etalab.mastodon.activities;
import android.Manifest;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
@ -27,13 +28,17 @@ import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.PopupMenu;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
@ -258,9 +263,10 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
public void onPrepared(MediaPlayer mp) {
loader.setVisibility(View.GONE);
mediaPlayer = mp;
mp.start();
}
});
videoView.setZOrderOnTop(true);
videoView.start();
peertube_download.setOnClickListener(new View.OnClickListener() {
@ -358,14 +364,35 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
videoView.start();
}
}
public void changeVideoResolution(Peertube peertube, String resolution){
if( mediaPlayer != null) {
int position = videoView.getCurrentPosition();
mediaPlayer.stop();
videoView.setVideoURI(Uri.parse(peertube.getFileUrl(resolution)));
fullScreenMediaController.setResolutionVal(resolution + "p");
videoView.seekTo(position);
mediaPlayer.start();
}
public void displayResolution(){
AlertDialog.Builder builderSingle = new AlertDialog.Builder(PeertubeActivity.this);
builderSingle.setTitle(R.string.pickup_resolution);
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(PeertubeActivity.this, android.R.layout.select_dialog_item);
for(String resolution: peertube.getResolution())
arrayAdapter.add(resolution+"p");
builderSingle.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String res = arrayAdapter.getItem(which).substring(0, arrayAdapter.getItem(which).length() - 1);
if( mediaPlayer != null) {
int position = videoView.getCurrentPosition();
mediaPlayer.stop();
videoView.setVideoURI(Uri.parse(peertube.getFileUrl(res)));
fullScreenMediaController.setResolutionVal(res);
videoView.seekTo(position);
videoView.start();
}
}
});
builderSingle.show();
}
}

View File

@ -18,12 +18,8 @@ package fr.gouv.etalab.mastodon.helper;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Color;
import android.support.v7.widget.PopupMenu;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.MediaController;
@ -88,30 +84,14 @@ public class FullScreenMediaController extends MediaController {
paramsButton.gravity = Gravity.START;
paramsButton.rightMargin = 80;
paramsButton.topMargin = 22;
addView(resolution, paramsButton);
resolution.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
PopupMenu popup = new PopupMenu(context, resolution);
int i = 0;
for(String res: peertube.getResolution()){
MenuItem item = popup.getMenu().add(0, i, Menu.NONE, res);
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
((PeertubeActivity)context).changeVideoResolution(peertube, res);
resolution.setText(String.format("%sp",res));
return false;
}
});
i++;
}
try {
popup.show();
}catch (WindowManager.BadTokenException ignored){}
((PeertubeActivity)getContext()).displayResolution();
}
});
addView(resolution, paramsButton);
if(((PeertubeActivity)getContext()).getFullscreen() == fullscreen.ON){
Resources resources = getResources();
fullScreen.setImageDrawable(resources.getDrawable(R.drawable.ic_fullscreen_exit));
@ -130,7 +110,7 @@ public class FullScreenMediaController extends MediaController {
}else{
((PeertubeActivity)getContext()).setFullscreen(fullscreen.ON);
}
((PeertubeActivity)getContext()).change();
changeIcon();
}
});
@ -138,6 +118,8 @@ public class FullScreenMediaController extends MediaController {
public void setResolutionVal(String resolutionVal){
this.resolutionVal = resolutionVal;
if( resolution != null)
resolution.setText(String.format("%sp",resolutionVal));
}
private void changeIcon(){

View File

@ -2057,9 +2057,9 @@ public class Helper {
public static String secondsToString(int pTime) {
int hour = pTime/3660;
int min = pTime/60;
int sec = pTime-(min*60);
int hour = pTime/3600;
int min = (pTime -(hour*3600))/60;
int sec = pTime -(hour*3600)-(min*60);
String strHour="0", strMin="0", strSec="0";
if( hour > 0 )

View File

@ -641,6 +641,7 @@
<string name="duration_video">Duration: %s</string>
<string name="add_remote_instance">Add an instance</string>
<string name="comment_no_allowed_peertube">Comments are not enabled on this video!</string>
<string name="pickup_resolution">Pick up a resolution</string>
<string-array name="filter_expire">
<item>Never</item>