Merge pull request #17 from sschueller/develop

Minor improvements
This commit is contained in:
Stefan Schüller 2018-07-01 17:06:39 +02:00 committed by GitHub
commit 15dbfbfaee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 189 additions and 88 deletions

View File

@ -4,7 +4,7 @@ android {
compileSdkVersion 27 compileSdkVersion 27
defaultConfig { defaultConfig {
applicationId "net.schueller.peertube" applicationId "net.schueller.peertube"
minSdkVersion 24 minSdkVersion 23
targetSdkVersion 27 targetSdkVersion 27
versionCode 100 versionCode 100
versionName "1.0.0" versionName "1.0.0"

View File

@ -27,8 +27,10 @@
android:name=".activity.LoginActivity" android:name=".activity.LoginActivity"
android:label="@string/title_activity_login" /> android:label="@string/title_activity_login" />
<activity <activity
android:name=".activity.TorrentVideoPlayActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenSize|screenLayout|smallestScreenSize|uiMode"
android:label="@string/title_activity_torrent_video_play" android:launchMode="singleTop"
android:name=".activity.VideoPlayActivity"
android:label="@string/title_activity_video_play"
android:theme="@style/AppTheme" /> android:theme="@style/AppTheme" />
<activity <activity
android:name=".activity.SettingsActivity" android:name=".activity.SettingsActivity"

View File

@ -60,6 +60,7 @@ public class VideoListActivity extends AppCompatActivity {
private int currentStart = 0; private int currentStart = 0;
private int count = 12; private int count = 12;
private String sort = "-createdAt"; private String sort = "-createdAt";
private String filter = "";
private boolean isLoading = false; private boolean isLoading = false;
@ -72,7 +73,7 @@ public class VideoListActivity extends AppCompatActivity {
if (!isLoading) { if (!isLoading) {
sort = "-createdAt"; sort = "-createdAt";
currentStart = 0; currentStart = 0;
loadVideos(currentStart, count, sort); loadVideos(currentStart, count, sort, filter);
} }
return true; return true;
@ -82,7 +83,7 @@ public class VideoListActivity extends AppCompatActivity {
if (!isLoading) { if (!isLoading) {
sort = "-views"; sort = "-views";
currentStart = 0; currentStart = 0;
loadVideos(currentStart, count, sort); loadVideos(currentStart, count, sort, filter);
} }
return true; return true;
@ -106,6 +107,9 @@ public class VideoListActivity extends AppCompatActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_list); setContentView(R.layout.activity_video_list);
//SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
filter = ""; //"nsfw:" + sharedPref.getBoolean("pref_show_nsfw", true);
// Init icons // Init icons
Iconify.with(new FontAwesomeModule()); Iconify.with(new FontAwesomeModule());
@ -195,7 +199,7 @@ public class VideoListActivity extends AppCompatActivity {
videoAdapter = new VideoAdapter(new ArrayList<>(), VideoListActivity.this); videoAdapter = new VideoAdapter(new ArrayList<>(), VideoListActivity.this);
recyclerView.setAdapter(videoAdapter); recyclerView.setAdapter(videoAdapter);
loadVideos(currentStart, count, sort); loadVideos(currentStart, count, sort, filter);
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override @Override
@ -211,7 +215,7 @@ public class VideoListActivity extends AppCompatActivity {
if(!recyclerView.canScrollVertically(RecyclerView.FOCUS_DOWN)){ if(!recyclerView.canScrollVertically(RecyclerView.FOCUS_DOWN)){
if (!isLoading) { if (!isLoading) {
currentStart = currentStart + count; currentStart = currentStart + count;
loadVideos(currentStart, count, sort); loadVideos(currentStart, count, sort, filter);
} }
} }
} }
@ -223,13 +227,13 @@ public class VideoListActivity extends AppCompatActivity {
// Refresh items // Refresh items
if (!isLoading) { if (!isLoading) {
currentStart = 0; currentStart = 0;
loadVideos(currentStart, count, sort); loadVideos(currentStart, count, sort, filter);
} }
}); });
} }
private void loadVideos(int start, int count, String sort) { private void loadVideos(int start, int count, String sort, String filter) {
isLoading = true; isLoading = true;
@ -237,7 +241,7 @@ public class VideoListActivity extends AppCompatActivity {
GetVideoDataService service = RetrofitInstance.getRetrofitInstance(apiBaseURL + "/api/v1/").create(GetVideoDataService.class); GetVideoDataService service = RetrofitInstance.getRetrofitInstance(apiBaseURL + "/api/v1/").create(GetVideoDataService.class);
Call<VideoList> call = service.getVideosData(start, count, sort); Call<VideoList> call = service.getVideosData(start, count, sort, filter);
/*Log the URL called*/ /*Log the URL called*/
Log.d("URL Called", call.request().url() + ""); Log.d("URL Called", call.request().url() + "");

View File

@ -1,13 +1,16 @@
package net.schueller.peertube.activity; package net.schueller.peertube.activity;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment; import android.os.Environment;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.util.Log; import android.util.Log;
import android.view.Surface;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
@ -18,7 +21,9 @@ import com.github.se_bastiaan.torrentstream.TorrentOptions;
import com.github.se_bastiaan.torrentstream.TorrentStream; import com.github.se_bastiaan.torrentstream.TorrentStream;
import com.github.se_bastiaan.torrentstream.listeners.TorrentListener; import com.github.se_bastiaan.torrentstream.listeners.TorrentListener;
import com.google.android.exoplayer2.ExoPlayerFactory; import com.google.android.exoplayer2.ExoPlayerFactory;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.SimpleExoPlayer; import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.decoder.DecoderCounters;
import com.google.android.exoplayer2.source.ExtractorMediaSource; import com.google.android.exoplayer2.source.ExtractorMediaSource;
import com.google.android.exoplayer2.source.MediaSource; import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection; import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection;
@ -31,6 +36,7 @@ import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter; import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory; import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
import com.google.android.exoplayer2.video.VideoRendererEventListener;
import net.schueller.peertube.R; import net.schueller.peertube.R;
import net.schueller.peertube.helper.APIUrlHelper; import net.schueller.peertube.helper.APIUrlHelper;
@ -44,17 +50,18 @@ import retrofit2.Call;
import retrofit2.Callback; import retrofit2.Callback;
import retrofit2.Response; import retrofit2.Response;
public class TorrentVideoPlayActivity extends AppCompatActivity { public class VideoPlayActivity extends AppCompatActivity implements VideoRendererEventListener {
private static final String TAG = "TorrentVideoPlayActivity"; private static final String TAG = "VideoPlayActivity";
private ProgressBar progressBar; private ProgressBar progressBar;
private PlayerView simpleExoPlayerView;
private SimpleExoPlayer player; private SimpleExoPlayer player;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_torrent_video_play); setContentView(R.layout.activity_video_play);
// get video ID // get video ID
Intent intent = getIntent(); Intent intent = getIntent();
@ -64,7 +71,9 @@ public class TorrentVideoPlayActivity extends AppCompatActivity {
progressBar = findViewById(R.id.progress); progressBar = findViewById(R.id.progress);
progressBar.setMax(100); progressBar.setMax(100);
PlayerView videoView = findViewById(R.id.video_view); // PlayerView videoView = findViewById(R.id.video_view);
simpleExoPlayerView = new PlayerView(this);
simpleExoPlayerView = findViewById(R.id.video_view);
// 1. Create a default TrackSelector // 1. Create a default TrackSelector
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
@ -75,8 +84,68 @@ public class TorrentVideoPlayActivity extends AppCompatActivity {
// 2. Create the player // 2. Create the player
player = ExoPlayerFactory.newSimpleInstance(getApplicationContext(), trackSelector); player = ExoPlayerFactory.newSimpleInstance(getApplicationContext(), trackSelector);
videoView.setPlayer(player); simpleExoPlayerView.setPlayer(player);
// get video details from api
String apiBaseURL = APIUrlHelper.getUrl(this);
GetVideoDataService service = RetrofitInstance.getRetrofitInstance(apiBaseURL + "/api/v1/").create(GetVideoDataService.class);
Call<Video> call = service.getVideoData(videoID);
call.enqueue(new Callback<Video>() {
@Override
public void onResponse(@NonNull Call<Video> call, @NonNull Response<Video> response) {
// Toast.makeText(TorrentVideoPlayActivity.this, response.body().getDescription(), Toast.LENGTH_SHORT).show();
TextView videoName = findViewById(R.id.name);
TextView videoDescription = findViewById(R.id.description);
TextView videoMeta = findViewById(R.id.videoMeta);
try {
videoName.setText(response.body().getName());
videoDescription.setText(response.body().getDescription());
videoMeta.setText(
MetaDataHelper.getMetaString(
response.body().getCreatedAt(),
response.body().getViews(),
getBaseContext()
)
);
String streamUrl = response.body().getFiles().get(0).getFileUrl();
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
if (sharedPref.getBoolean("pref_torrent_player",false)) {
streamUrl = response.body().getFiles().get(0).getTorrentUrl();
TorrentStream torrentStream = setupTorrentStream();
torrentStream.startStream(streamUrl);
} else {
setupVideoView(Uri.parse(streamUrl));
}
Log.v(TAG, streamUrl);
} catch (NullPointerException e) {
e.getStackTrace();
}
}
@Override
public void onFailure(@NonNull Call<Video> call, @NonNull Throwable t) {
Log.wtf(TAG, t.fillInStackTrace());
Toast.makeText(VideoPlayActivity.this, "Something went wrong...Please try later!", Toast.LENGTH_SHORT).show();
}
});
}
private TorrentStream setupTorrentStream() {
TorrentOptions torrentOptions = new TorrentOptions.Builder() TorrentOptions torrentOptions = new TorrentOptions.Builder()
.saveLocation(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)) .saveLocation(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS))
@ -90,7 +159,7 @@ public class TorrentVideoPlayActivity extends AppCompatActivity {
public void onStreamReady(Torrent torrent) { public void onStreamReady(Torrent torrent) {
Log.d(TAG, "Ready"); Log.d(TAG, "Ready");
setupVideoView(torrent); setupVideoView(Uri.fromFile(torrent.getVideoFile()));
} }
@ -124,59 +193,10 @@ public class TorrentVideoPlayActivity extends AppCompatActivity {
}); });
// get video details from api return torrentStream;
String apiBaseURL = APIUrlHelper.getUrl(this);
GetVideoDataService service = RetrofitInstance.getRetrofitInstance(apiBaseURL + "/api/v1/").create(GetVideoDataService.class);
Call<Video> call = service.getVideoData(videoID);
call.enqueue(new Callback<Video>() {
@Override
public void onResponse(@NonNull Call<Video> call, @NonNull Response<Video> response) {
// Toast.makeText(TorrentVideoPlayActivity.this, response.body().getDescription(), Toast.LENGTH_SHORT).show();
String streamUrl = null;
TextView videoName = findViewById(R.id.name);
TextView videoDescription = findViewById(R.id.description);
TextView videoMeta = findViewById(R.id.videoMeta);
try {
streamUrl = response.body().getFiles().get(0).getTorrentUrl();
videoName.setText(response.body().getName());
videoDescription.setText(response.body().getDescription());
videoMeta.setText(
MetaDataHelper.getMetaString(
response.body().getCreatedAt(),
response.body().getViews(),
getBaseContext()
)
);
} catch (NullPointerException e) {
e.getStackTrace();
} }
Log.v(TAG, streamUrl); private void setupVideoView(Uri videoStream) {
torrentStream.startStream(streamUrl);
}
@Override
public void onFailure(@NonNull Call<Video> call, @NonNull Throwable t) {
Log.wtf(TAG, t.fillInStackTrace());
Toast.makeText(TorrentVideoPlayActivity.this, "Something went wrong...Please try later!", Toast.LENGTH_SHORT).show();
}
});
}
private void setupVideoView(Torrent torrent) {
Log.d(TAG, "Play Video"); Log.d(TAG, "Play Video");
@ -186,32 +206,80 @@ public class TorrentVideoPlayActivity extends AppCompatActivity {
// This is the MediaSource representing the media to be played. // This is the MediaSource representing the media to be played.
MediaSource videoSource = new ExtractorMediaSource.Factory(dataSourceFactory) MediaSource videoSource = new ExtractorMediaSource.Factory(dataSourceFactory)
.createMediaSource(Uri.fromFile(torrent.getVideoFile())); .createMediaSource(videoStream);
// Auto play
player.setPlayWhenReady(true);
// Prepare the player with the source. // Prepare the player with the source.
player.prepare(videoSource); player.prepare(videoSource);
// Auto play
player.setPlayWhenReady(true);
} }
@Override
public void onVideoEnabled(DecoderCounters counters) {
}
@Override
public void onVideoDecoderInitialized(String decoderName, long initializedTimestampMs, long initializationDurationMs) {
}
@Override
public void onVideoInputFormatChanged(Format format) {
}
@Override
public void onDroppedFrames(int count, long elapsedMs) {
}
@Override
public void onVideoSizeChanged(int width, int height, int unappliedRotationDegrees, float pixelWidthHeightRatio) {
}
@Override
public void onRenderedFirstFrame(Surface surface) {
}
@Override
public void onVideoDisabled(DecoderCounters counters) {
}
@Override @Override
protected void onDestroy() { protected void onDestroy() {
super.onDestroy(); super.onDestroy();
Log.v(TAG, "onDestroy()...");
player.release(); player.release();
} }
@Override @Override
protected void onPause() { protected void onPause() {
super.onPause(); super.onPause();
player.stop(); Log.v(TAG, "onPause()...");
} }
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
player.setPlayWhenReady(true); Log.v(TAG, "onResume()...");
}
@Override
protected void onStop() {
super.onStop();
Log.v(TAG, "onStop()...");
}
@Override
protected void onStart() {
super.onStart();
Log.v(TAG, "onStart()...");
} }
} }

View File

@ -2,6 +2,8 @@ package net.schueller.peertube.adapter;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -13,7 +15,7 @@ import android.widget.TextView;
import com.squareup.picasso.Picasso; import com.squareup.picasso.Picasso;
import net.schueller.peertube.R; import net.schueller.peertube.R;
import net.schueller.peertube.activity.TorrentVideoPlayActivity; import net.schueller.peertube.activity.VideoPlayActivity;
import net.schueller.peertube.helper.APIUrlHelper; import net.schueller.peertube.helper.APIUrlHelper;
import net.schueller.peertube.helper.MetaDataHelper; import net.schueller.peertube.helper.MetaDataHelper;
import net.schueller.peertube.model.Avatar; import net.schueller.peertube.model.Avatar;
@ -85,7 +87,7 @@ public class VideoAdapter extends RecyclerView.Adapter<VideoAdapter.VideoViewHol
// Log.v("VideoAdapter", "click: " + videoList.get(position).getName()); // Log.v("VideoAdapter", "click: " + videoList.get(position).getName());
Intent intent = new Intent(context, TorrentVideoPlayActivity.class); Intent intent = new Intent(context,VideoPlayActivity.class);
intent.putExtra(EXTRA_VIDEOID, videoList.get(position).getUuid()); intent.putExtra(EXTRA_VIDEOID, videoList.get(position).getUuid());
context.startActivity(intent); context.startActivity(intent);

View File

@ -13,11 +13,21 @@ public interface GetVideoDataService {
Call<VideoList> getVideosData( Call<VideoList> getVideosData(
@Query("start") int start, @Query("start") int start,
@Query("count") int count, @Query("count") int count,
@Query("sort") String sort @Query("sort") String sort,
@Query("filter") String filter
); );
@GET("videos/{id}") @GET("videos/{id}")
Call<Video> getVideoData( Call<Video> getVideoData(
@Path(value = "id", encoded = true) String id @Path(value = "id", encoded = true) String id
); );
@GET("videos/search/")
Call<VideoList> searchVideosData(
@Query("start") int start,
@Query("count") int count,
@Query("sort") String sort,
@Query("filter") String filter,
@Query("search") String search
);
} }

View File

@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context="net.schueller.peertube.activity.TorrentVideoPlayActivity"> tools:context="net.schueller.peertube.activity.VideoPlayActivity">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
@ -21,11 +21,7 @@
app:layout_constraintDimensionRatio="H,3:1" app:layout_constraintDimensionRatio="H,3:1"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent" />
>
</com.google.android.exoplayer2.ui.PlayerView>
<ProgressBar <ProgressBar
android:id="@+id/progress" android:id="@+id/progress"

View File

@ -1,7 +1,7 @@
<resources> <resources>
<string name="app_name">PeerTube</string> <string name="app_name">PeerTube</string>
<string name="title_activity_torrent_video_play">TorrentVideoPlayActivity</string> <string name="title_activity_video_play">VideoPlayActivity</string>
<string name="title_activity_settings">الإعدادات</string> <string name="title_activity_settings">الإعدادات</string>
<string name="title_activity_login">تسجيل الدخول</string> <string name="title_activity_login">تسجيل الدخول</string>

View File

@ -1,7 +1,7 @@
<resources> <resources>
<string name="app_name">PeerTube</string> <string name="app_name">PeerTube</string>
<string name="title_activity_torrent_video_play">TorrentVideoPlayActivity</string> <string name="title_activity_video_play">VideoPlayActivity</string>
<string name="title_activity_settings">Settings</string> <string name="title_activity_settings">Settings</string>
<string name="title_activity_login">Sign in</string> <string name="title_activity_login">Sign in</string>
@ -46,4 +46,10 @@
<string name="video_row_video_thumbnail">Video Thumbnail</string> <string name="video_row_video_thumbnail">Video Thumbnail</string>
<string name="video_row_account_avatar">Account Avatar</string> <string name="video_row_account_avatar">Account Avatar</string>
<string name="pref_title_show_nsfw">Show NSFW</string>
<string name="pref_description_show_nsfw">NSFW content will be shown if enabled.</string>
<string name="title_activity_url_video_play">UrlVideoPlayActivity</string>
<string name="pref_title_torrent_player">Torrent Video Player</string>
<string name="pref_description_torrent_player">Videos playback via a torrent stream</string>
</resources> </resources>

View File

@ -10,4 +10,17 @@
android:singleLine="true" android:singleLine="true"
android:title="@string/pref_title_peertube_server" /> android:title="@string/pref_title_peertube_server" />
<SwitchPreference
android:key="pref_show_nsfw"
android:title="@string/pref_title_show_nsfw"
android:summary="@string/pref_description_show_nsfw"
android:defaultValue="false" />
<SwitchPreference
android:key="pref_torrent_player"
android:title="@string/pref_title_torrent_player"
android:summary="@string/pref_description_torrent_player"
android:defaultValue="false" />
</PreferenceScreen> </PreferenceScreen>

View File

@ -7,7 +7,7 @@ buildscript {
jcenter() jcenter()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:3.0.1' classpath 'com.android.tools.build:gradle:3.1.3'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong

View File

@ -1,6 +1,6 @@
#Fri Mar 02 18:00:19 CET 2018 #Sun Jul 01 13:53:14 CEST 2018
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip