From 4e95a44b77317ff8528ae8a8ad6affa056d7c27e Mon Sep 17 00:00:00 2001 From: Stefan Schueller Date: Sun, 11 Mar 2018 17:21:30 +0100 Subject: [PATCH] Fixed account model, update video meta data --- .../activity/TorrentVideoPlayActivity.java | 15 +++++--- .../peertube/adapter/VideoAdapter.java | 20 +++++++---- .../peertube/helper/MetaDataHelper.java | 23 +++++++++++++ .../net/schueller/peertube/model/Account.java | 6 ++-- .../net/schueller/peertube/model/Avatar.java | 34 +++++++++++++++++++ .../net/schueller/peertube/model/Channel.java | 6 ++-- .../layout/activity_torrent_video_play.xml | 6 ++++ app/src/main/res/values/strings.xml | 6 ++++ 8 files changed, 100 insertions(+), 16 deletions(-) create mode 100644 app/src/main/java/net/schueller/peertube/helper/MetaDataHelper.java create mode 100644 app/src/main/java/net/schueller/peertube/model/Avatar.java diff --git a/app/src/main/java/net/schueller/peertube/activity/TorrentVideoPlayActivity.java b/app/src/main/java/net/schueller/peertube/activity/TorrentVideoPlayActivity.java index 97c2479..3cb6451 100644 --- a/app/src/main/java/net/schueller/peertube/activity/TorrentVideoPlayActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/TorrentVideoPlayActivity.java @@ -1,12 +1,10 @@ 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; @@ -36,6 +34,7 @@ import com.google.android.exoplayer2.util.Util; import net.schueller.peertube.R; import net.schueller.peertube.helper.APIUrlHelper; +import net.schueller.peertube.helper.MetaDataHelper; import net.schueller.peertube.model.Video; import net.schueller.peertube.network.GetVideoDataService; @@ -50,7 +49,6 @@ public class TorrentVideoPlayActivity extends AppCompatActivity { private static final String TAG = "TorrentVideoPlayActivity"; private ProgressBar progressBar; - private PlayerView videoView; private SimpleExoPlayer player; @Override @@ -66,7 +64,7 @@ public class TorrentVideoPlayActivity extends AppCompatActivity { progressBar = findViewById(R.id.progress); progressBar.setMax(100); - videoView = findViewById(R.id.video_view); + PlayerView videoView = findViewById(R.id.video_view); // 1. Create a default TrackSelector BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); @@ -142,6 +140,7 @@ public class TorrentVideoPlayActivity extends AppCompatActivity { 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(); @@ -149,6 +148,14 @@ public class TorrentVideoPlayActivity extends AppCompatActivity { 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(); } diff --git a/app/src/main/java/net/schueller/peertube/adapter/VideoAdapter.java b/app/src/main/java/net/schueller/peertube/adapter/VideoAdapter.java index 00c2e01..21f492f 100644 --- a/app/src/main/java/net/schueller/peertube/adapter/VideoAdapter.java +++ b/app/src/main/java/net/schueller/peertube/adapter/VideoAdapter.java @@ -6,6 +6,7 @@ import android.content.SharedPreferences; import android.preference.PreferenceManager; import android.support.annotation.NonNull; import android.support.v7.widget.RecyclerView; +import android.text.format.DateUtils; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -17,6 +18,7 @@ import com.squareup.picasso.Picasso; import net.schueller.peertube.R; import net.schueller.peertube.activity.TorrentVideoPlayActivity; import net.schueller.peertube.helper.APIUrlHelper; +import net.schueller.peertube.helper.MetaDataHelper; import net.schueller.peertube.model.Video; import java.util.ArrayList; @@ -55,15 +57,21 @@ public class VideoAdapter extends RecyclerView.Adapter { diff --git a/app/src/main/java/net/schueller/peertube/helper/MetaDataHelper.java b/app/src/main/java/net/schueller/peertube/helper/MetaDataHelper.java new file mode 100644 index 0000000..c0bc26d --- /dev/null +++ b/app/src/main/java/net/schueller/peertube/helper/MetaDataHelper.java @@ -0,0 +1,23 @@ +package net.schueller.peertube.helper; + +import android.content.Context; +import android.text.format.DateUtils; +import net.schueller.peertube.R; +import java.util.Date; + +public class MetaDataHelper { + + public static String getMetaString(Date getCreatedAt, Integer viewCount, Context context) { + return DateUtils. + getRelativeTimeSpanString(getCreatedAt.getTime()).toString() + + context.getResources().getString(R.string.meta_data_seperator) + + viewCount + context.getResources().getString(R.string.meta_data_views); + } + + public static String getOwnerString(String accountName, String serverHost, Context context) { + return accountName + + context.getResources().getString(R.string.meta_data_owner_seperator) + + serverHost; + } + +} diff --git a/app/src/main/java/net/schueller/peertube/model/Account.java b/app/src/main/java/net/schueller/peertube/model/Account.java index d10f1f8..4b08406 100644 --- a/app/src/main/java/net/schueller/peertube/model/Account.java +++ b/app/src/main/java/net/schueller/peertube/model/Account.java @@ -10,7 +10,7 @@ public class Account { private String host; private Integer followingCount; private Integer followersCount; - private String avatar; + private Avatar avatar; private Date createdAt; private Date updatedAt; private String displayName; @@ -72,11 +72,11 @@ public class Account { this.followersCount = followersCount; } - public String getAvatar() { + public Avatar getAvatar() { return avatar; } - public void setAvatar(String avatar) { + public void setAvatar(Avatar avatar) { this.avatar = avatar; } diff --git a/app/src/main/java/net/schueller/peertube/model/Avatar.java b/app/src/main/java/net/schueller/peertube/model/Avatar.java new file mode 100644 index 0000000..791e411 --- /dev/null +++ b/app/src/main/java/net/schueller/peertube/model/Avatar.java @@ -0,0 +1,34 @@ +package net.schueller.peertube.model; + +import java.util.Date; + +public class Avatar { + + private String path; + private Date createdAt; + private Date updatedAt; + + public String getPath() { + return path; + } + + public void setPath(String path) { + this.path = path; + } + + public Date getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(Date createdAt) { + this.createdAt = createdAt; + } + + public Date getUpdatedAt() { + return updatedAt; + } + + public void setUpdatedAt(Date updatedAt) { + this.updatedAt = updatedAt; + } +} diff --git a/app/src/main/java/net/schueller/peertube/model/Channel.java b/app/src/main/java/net/schueller/peertube/model/Channel.java index d6dcb9f..c001e05 100644 --- a/app/src/main/java/net/schueller/peertube/model/Channel.java +++ b/app/src/main/java/net/schueller/peertube/model/Channel.java @@ -10,7 +10,7 @@ public class Channel { private String host; private Integer followingCount; private Integer followersCount; - private String avatar; + private Avatar avatar; private Date createdAt; private Date updatedAt; private String displayName; @@ -74,11 +74,11 @@ public class Channel { this.followersCount = followersCount; } - public String getAvatar() { + public Avatar getAvatar() { return avatar; } - public void setAvatar(String avatar) { + public void setAvatar(Avatar avatar) { this.avatar = avatar; } diff --git a/app/src/main/res/layout/activity_torrent_video_play.xml b/app/src/main/res/layout/activity_torrent_video_play.xml index 4bfa014..87559d9 100644 --- a/app/src/main/res/layout/activity_torrent_video_play.xml +++ b/app/src/main/res/layout/activity_torrent_video_play.xml @@ -50,6 +50,12 @@ android:layout_height="wrap_content" android:textAppearance="@style/Base.TextAppearance.AppCompat.Title" /> + + https://troll.tv PeerTube Server + + + \u0020-\u0020 + \u0020Views + \@ +