Fixed account model, update video meta data

This commit is contained in:
Stefan Schueller 2018-03-11 17:21:30 +01:00
parent 2dd409d68e
commit 4e95a44b77
8 changed files with 100 additions and 16 deletions

View File

@ -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();
}

View File

@ -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<VideoAdapter.VideoViewHol
holder.name.setText(videoList.get(position).getName());
// TODO: clean this up
// set age and view count
holder.videoMeta.setText(videoList.get(position).getCreatedAt().toString().concat(" - ")
.concat(videoList.get(position).getViews()+" Views"));
holder.videoMeta.setText(
MetaDataHelper.getMetaString(videoList.get(position).getCreatedAt(),
videoList.get(position).getViews(),
context
)
);
// set owner
holder.videoOwner.setText(videoList.get(position).getAccountName()
.concat("@")
.concat(videoList.get(position).getServerHost()));
holder.videoOwner.setText(
MetaDataHelper.getOwnerString(videoList.get(position).getAccountName(),
videoList.get(position).getServerHost(),
context
)
);
holder.mView.setOnClickListener(v -> {

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -50,6 +50,12 @@
android:layout_height="wrap_content"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Title" />
<TextView
android:id="@+id/videoMeta"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Caption" />
<TextView
android:id="@+id/description"
android:layout_width="match_parent"

View File

@ -32,4 +32,10 @@
<string name="pref_default_api_base_url" formatted="false">https://troll.tv</string>
<string name="pref_title_peertube_server">PeerTube Server</string>
<!-- Strings related to Video meta data -->
<string name="meta_data_seperator">\u0020-\u0020</string>
<string name="meta_data_views">\u0020Views</string>
<string name="meta_data_owner_seperator">\@</string>
</resources>