Some fixes

This commit is contained in:
stom79 2018-10-20 14:39:24 +02:00
parent c6edd8f1e9
commit cef5a2307a
5 changed files with 35 additions and 20 deletions

View File

@ -196,7 +196,7 @@ public abstract class BaseMainActivity extends BaseActivity
private String oldSearch;
boolean isLoadingInstance = false;
private ImageView delete_instance;
public static boolean displayPeertube = false;
public static String displayPeertube = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -874,7 +874,7 @@ public abstract class BaseMainActivity extends BaseActivity
query= query.replaceAll("^#+", "");
//It's not a peertube search
if(!displayPeertube){
if(displayPeertube == null){
Intent intent = new Intent(BaseMainActivity.this, SearchResultActivity.class);
intent.putExtra("search", query);
startActivity(intent);
@ -884,7 +884,7 @@ public abstract class BaseMainActivity extends BaseActivity
Bundle bundle = new Bundle();
statusFragment = new DisplayStatusFragment();
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE);
bundle.putString("remote_instance", toolbarTitle.getText().toString().trim());
bundle.putString("remote_instance", displayPeertube);
bundle.putString("search_peertube", query);
statusFragment.setArguments(bundle);
String fragmentTag = "REMOTE_INSTANCE";
@ -896,13 +896,12 @@ public abstract class BaseMainActivity extends BaseActivity
delete_instance.setVisibility(View.VISIBLE);
viewPager.setVisibility(View.GONE);
tabLayout.setVisibility(View.GONE);
toolbarTitle.setText(instance);
}else{
DisplayStatusFragment statusFragment;
Bundle bundle = new Bundle();
statusFragment = new DisplayStatusFragment();
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE);
bundle.putString("remote_instance", toolbarTitle.getText().toString().trim());
bundle.putString("remote_instance", displayPeertube);
bundle.putString("search_peertube", query);
statusFragment.setArguments(bundle);
String fragmentTag = "REMOTE_INSTANCE";
@ -910,7 +909,6 @@ public abstract class BaseMainActivity extends BaseActivity
fragmentManager.beginTransaction()
.replace(R.id.main_app_container, statusFragment, fragmentTag).commit();
}
toolbarTitle.setText(query + " - " + instance);
}
toolbar_search.setQuery("", false);
toolbar_search.setIconified(true);
@ -1668,7 +1666,7 @@ public abstract class BaseMainActivity extends BaseActivity
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
displayPeertube = false;
displayPeertube = null;
//Hide search bar on back pressed
if( !toolbar_search.isIconified()){
toolbar_search.setIconified(true);

View File

@ -219,7 +219,7 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
loader.setVisibility(View.GONE);
return;
}
if( apiResponse.getPeertubes().get(0).getFileUrl(null) == null){
if( apiResponse.getPeertubes() == null || apiResponse.getPeertubes().get(0) == null || apiResponse.getPeertubes().get(0).getFileUrl(null) == null){
Toast.makeText(PeertubeActivity.this, R.string.toast_error,Toast.LENGTH_LONG).show();
loader.setVisibility(View.GONE);
return;
@ -247,11 +247,11 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
fullScreenMediaController = new FullScreenMediaController(PeertubeActivity.this, peertube);
fullScreenMediaController.setAnchorView(videoView);
videoView.setMediaController(fullScreenMediaController);
mediaPlayer = MediaPlayer.create(PeertubeActivity.this, uri);
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
loader.setVisibility(View.GONE);
mediaPlayer = mp;
}
});
videoView.setZOrderOnTop(true);
@ -354,11 +354,13 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
}
}
public void changeVideoResolution(Peertube peertube, String resolution){
int position = videoView.getCurrentPosition();
mediaPlayer.stop();
videoView.setVideoURI(Uri.parse(peertube.getFileUrl(resolution)));
fullScreenMediaController.setResolutionVal(resolution + "p");
videoView.seekTo(position);
mediaPlayer.start();
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();
}
}
}

View File

@ -650,6 +650,7 @@ public class API {
try {
HttpsConnection httpsConnection = new HttpsConnection(context);
String response = httpsConnection.get(String.format("https://"+instance+"/api/v1/videos/%s", videoId), 60, null, null);
Log.v(Helper.TAG,"response: " + response);
JSONObject jsonObject = new JSONObject(response);
peertube = parseSinglePeertube(context, instance, jsonObject);
} catch (HttpsConnection.HttpsConnectionException e) {
@ -2434,6 +2435,7 @@ public class API {
peertube.setUuid(resobj.get("uuid").toString());
peertube.setName(resobj.get("name").toString());
peertube.setInstance(instance);
peertube.setHost(resobj.getJSONObject("account").get("host").toString());
peertube.setDescription(resobj.get("description").toString());
peertube.setEmbedPath(resobj.get("embedPath").toString());
peertube.setPreviewPath(resobj.get("previewPath").toString());

View File

@ -27,6 +27,7 @@ public class Peertube {
private String uuid;
private String name;
private String description;
private String host;
private String thumbnailPath;
private String previewPath;
private String embedPath;
@ -162,7 +163,7 @@ public class Peertube {
resolution = this.getResolution().get(0);
if(resolution == null)
return null;
return "https://" + this.instance + "/static/webseed/" + getUuid()+ "-" + resolution + ".mp4";
return "https://" + this.host + "/static/webseed/" + getUuid()+ "-" + resolution + ".mp4";
}
@ -171,7 +172,7 @@ public class Peertube {
resolution = this.getResolution().get(0);
if(resolution == null)
return null;
return "https://" + this.instance + "/download/torrents/" + getUuid()+ "-" + resolution + ".torrent";
return "https://" + this.host + "/download/torrents/" + getUuid()+ "-" + resolution + ".torrent";
}
public String getFileDownloadUrl(String resolution) {
@ -179,7 +180,7 @@ public class Peertube {
resolution = this.getResolution().get(0);
if(resolution == null)
return null;
return "https://" + this.instance + "/download/videos/" + getUuid()+ "-" + resolution + ".mp4";
return "https://" + this.host + "/download/videos/" + getUuid()+ "-" + resolution + ".mp4";
}
public List<String> getResolution() {
@ -189,4 +190,12 @@ public class Peertube {
public void setResolution(List<String> resolution) {
this.resolution = resolution;
}
public String getHost() {
return host;
}
public void setHost(String host) {
this.host = host;
}
}

View File

@ -13,6 +13,7 @@ package fr.gouv.etalab.mastodon.fragments;
*
* You should have received a copy of the GNU General Public License along with Mastalab; if not,
* see <http://www.gnu.org/licenses>. */
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
@ -148,11 +149,11 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
if( search_peertube == null && (instanceType == null || instanceType.equals("MASTODON"))) {
BaseMainActivity.displayPeertube = false;
BaseMainActivity.displayPeertube = null;
statusListAdapter = new StatusListAdapter(context, type, targetedId, isOnWifi, behaviorWithAttachments, positionSpinnerTrans, this.statuses);
lv_status.setAdapter(statusListAdapter);
}else {
BaseMainActivity.displayPeertube = true;
BaseMainActivity.displayPeertube = remoteInstance;
peertubeAdapater = new PeertubeAdapter(context, remoteInstance, this.peertubes);
lv_status.setAdapter(peertubeAdapater);
}
@ -162,6 +163,9 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
instance = sharedpreferences.getString(Helper.PREF_INSTANCE, context!=null?Helper.getLiveInstance(context):null);
if( type == RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE && search_peertube != null)
((Activity)context).setTitle(remoteInstance + " - " + search_peertube);
lv_status.addOnScrollListener(new RecyclerView.OnScrollListener() {
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy)
{