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
defaultConfig {
applicationId "net.schueller.peertube"
minSdkVersion 24
minSdkVersion 23
targetSdkVersion 27
versionCode 100
versionName "1.0.0"

View File

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

View File

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

View File

@ -1,13 +1,16 @@
package net.schueller.peertube.activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.Surface;
import android.widget.ProgressBar;
import android.widget.TextView;
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.listeners.TorrentListener;
import com.google.android.exoplayer2.ExoPlayerFactory;
import com.google.android.exoplayer2.Format;
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.MediaSource;
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.DefaultDataSourceFactory;
import com.google.android.exoplayer2.util.Util;
import com.google.android.exoplayer2.video.VideoRendererEventListener;
import net.schueller.peertube.R;
import net.schueller.peertube.helper.APIUrlHelper;
@ -44,17 +50,18 @@ import retrofit2.Call;
import retrofit2.Callback;
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 PlayerView simpleExoPlayerView;
private SimpleExoPlayer player;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_torrent_video_play);
setContentView(R.layout.activity_video_play);
// get video ID
Intent intent = getIntent();
@ -64,7 +71,9 @@ public class TorrentVideoPlayActivity extends AppCompatActivity {
progressBar = findViewById(R.id.progress);
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
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
@ -75,8 +84,68 @@ public class TorrentVideoPlayActivity extends AppCompatActivity {
// 2. Create the player
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()
.saveLocation(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS))
@ -90,7 +159,7 @@ public class TorrentVideoPlayActivity extends AppCompatActivity {
public void onStreamReady(Torrent torrent) {
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
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();
return torrentStream;
}
Log.v(TAG, streamUrl);
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) {
private void setupVideoView(Uri videoStream) {
Log.d(TAG, "Play Video");
@ -186,32 +206,80 @@ public class TorrentVideoPlayActivity extends AppCompatActivity {
// This is the MediaSource representing the media to be played.
MediaSource videoSource = new ExtractorMediaSource.Factory(dataSourceFactory)
.createMediaSource(Uri.fromFile(torrent.getVideoFile()));
// Auto play
player.setPlayWhenReady(true);
.createMediaSource(videoStream);
// Prepare the player with the source.
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
protected void onDestroy() {
super.onDestroy();
Log.v(TAG, "onDestroy()...");
player.release();
}
@Override
protected void onPause() {
super.onPause();
player.stop();
Log.v(TAG, "onPause()...");
}
@Override
protected void 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.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
@ -13,7 +15,7 @@ import android.widget.TextView;
import com.squareup.picasso.Picasso;
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.MetaDataHelper;
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());
Intent intent = new Intent(context, TorrentVideoPlayActivity.class);
Intent intent = new Intent(context,VideoPlayActivity.class);
intent.putExtra(EXTRA_VIDEOID, videoList.get(position).getUuid());
context.startActivity(intent);

View File

@ -13,11 +13,21 @@ public interface GetVideoDataService {
Call<VideoList> getVideosData(
@Query("start") int start,
@Query("count") int count,
@Query("sort") String sort
@Query("sort") String sort,
@Query("filter") String filter
);
@GET("videos/{id}")
Call<Video> getVideoData(
@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"
android:layout_width="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"
@ -21,11 +21,7 @@
app:layout_constraintDimensionRatio="H,3:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
>
</com.google.android.exoplayer2.ui.PlayerView>
app:layout_constraintTop_toTopOf="parent" />
<ProgressBar
android:id="@+id/progress"

View File

@ -1,7 +1,7 @@
<resources>
<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_login">تسجيل الدخول</string>

View File

@ -1,7 +1,7 @@
<resources>
<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_login">Sign in</string>
@ -46,4 +46,10 @@
<string name="video_row_video_thumbnail">Video Thumbnail</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>

View File

@ -10,4 +10,17 @@
android:singleLine="true"
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>

View File

@ -7,7 +7,7 @@ buildscript {
jcenter()
}
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

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
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
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