Added more fields to server list

This commit is contained in:
Stefan Schueller 2020-07-04 20:46:32 +02:00
parent b9d6aff740
commit 9ffea41df5
14 changed files with 172 additions and 46 deletions

View File

@ -65,6 +65,9 @@ android {
// date formatter // date formatter
implementation 'org.ocpsoft.prettytime:prettytime:4.0.4.Final' implementation 'org.ocpsoft.prettytime:prettytime:4.0.4.Final'
// Version comparison
implementation 'org.apache.maven:maven-artifact:3.0.3'
// testing // testing
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0' androidTestImplementation 'androidx.test:runner:1.2.0'

View File

@ -160,7 +160,7 @@ public class ChannelAdapter extends RecyclerView.Adapter<ChannelAdapter.AccountV
AccountViewHolder(View itemView) { AccountViewHolder(View itemView) {
super(itemView); super(itemView);
name = itemView.findViewById(R.id.name); name = itemView.findViewById(R.id.sl_row_name);
thumb = itemView.findViewById(R.id.thumb); thumb = itemView.findViewById(R.id.thumb);
avatar = itemView.findViewById(R.id.avatar); avatar = itemView.findViewById(R.id.avatar);
videoMeta = itemView.findViewById(R.id.videoMeta); videoMeta = itemView.findViewById(R.id.videoMeta);

View File

@ -17,13 +17,11 @@
*/ */
package net.schueller.peertube.adapter; package net.schueller.peertube.adapter;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
@ -38,6 +36,8 @@ import java.util.ArrayList;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import static android.app.Activity.RESULT_OK; import static android.app.Activity.RESULT_OK;
@ -74,20 +74,38 @@ public class ServerAdapter extends RecyclerView.Adapter<ServerAdapter.AccountVie
R.string.server_selection_signup_allowed_yes : R.string.server_selection_signup_allowed_yes :
R.string.server_selection_signup_allowed_no R.string.server_selection_signup_allowed_no
))); )));
holder.shortDescription.setText(serverList.get(position).getShortDescription());
holder.videoTotals.setText(
activity.getString(R.string.server_selection_video_totals,
serverList.get(position).getTotalVideos().toString(),
serverList.get(position).getTotalLocalVideos().toString()
));
// don't show description if it hasn't been changes from the default
if (!activity.getString(R.string.peertube_instance_search_default_description).equals(serverList.get(position).getShortDescription())) {
holder.shortDescription.setText(serverList.get(position).getShortDescription());
holder.shortDescription.setVisibility(View.VISIBLE);
} else {
holder.shortDescription.setVisibility(View.GONE);
}
DefaultArtifactVersion serverVersion = new DefaultArtifactVersion(serverList.get(position).getVersion());
// at least version 2.2
DefaultArtifactVersion minVersion22 = new DefaultArtifactVersion("2.2.0");
if (serverVersion.compareTo(minVersion22) >= 0) {
// show NSFW Icon
if (serverList.get(position).getNSFW()) {
holder.isNSFW.setVisibility(View.VISIBLE);
}
}
// select server
holder.itemView.setOnClickListener(v -> { holder.itemView.setOnClickListener(v -> {
// SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(activity);
// SharedPreferences.Editor editor = sharedPref.edit();
String serverUrl = APIUrlHelper.cleanServerUrl(serverList.get(position).getHost()); String serverUrl = APIUrlHelper.cleanServerUrl(serverList.get(position).getHost());
// editor.putString("pref_api_base", serverUrl);
// editor.apply();
//
//
Toast.makeText(activity, activity.getString(R.string.server_selection_set_server, serverUrl), Toast.LENGTH_LONG).show(); Toast.makeText(activity, activity.getString(R.string.server_selection_set_server, serverUrl), Toast.LENGTH_LONG).show();
Intent intent = new Intent(); Intent intent = new Intent();
@ -138,17 +156,19 @@ public class ServerAdapter extends RecyclerView.Adapter<ServerAdapter.AccountVie
return serverList.size(); return serverList.size();
} }
class AccountViewHolder extends RecyclerView.ViewHolder { static class AccountViewHolder extends RecyclerView.ViewHolder {
TextView name, host, signupAllowed, shortDescription; TextView name, host, signupAllowed, shortDescription, videoTotals;
ImageView isNSFW;
AccountViewHolder(View itemView) { AccountViewHolder(View itemView) {
super(itemView); super(itemView);
name = itemView.findViewById(R.id.name); name = itemView.findViewById(R.id.sl_row_name);
host = itemView.findViewById(R.id.host); host = itemView.findViewById(R.id.sl_row_host);
signupAllowed = itemView.findViewById(R.id.signupAllowed); signupAllowed = itemView.findViewById(R.id.sl_row_signup_allowed);
shortDescription = itemView.findViewById(R.id.shortDescription); shortDescription = itemView.findViewById(R.id.sl_row_short_description);
isNSFW = itemView.findViewById(R.id.sl_row_is_nsfw);
videoTotals = itemView.findViewById(R.id.sl_row_video_totals);
} }
} }

View File

@ -176,7 +176,7 @@ public class VideoAdapter extends RecyclerView.Adapter<VideoAdapter.VideoViewHol
VideoViewHolder(View itemView) { VideoViewHolder(View itemView) {
super(itemView); super(itemView);
name = itemView.findViewById(R.id.name); name = itemView.findViewById(R.id.sl_row_name);
thumb = itemView.findViewById(R.id.thumb); thumb = itemView.findViewById(R.id.thumb);
avatar = itemView.findViewById(R.id.avatar); avatar = itemView.findViewById(R.id.avatar);
videoMeta = itemView.findViewById(R.id.videoMeta); videoMeta = itemView.findViewById(R.id.videoMeta);

View File

@ -172,7 +172,7 @@ public class VideoMetaDataFragment extends Fragment {
// title / name // title / name
TextView videoName = activity.findViewById(R.id.name); TextView videoName = activity.findViewById(R.id.sl_row_name);
videoName.setText(video.getName()); videoName.setText(video.getName());
// created at / views // created at / views

View File

@ -17,6 +17,9 @@
*/ */
package net.schueller.peertube.model; package net.schueller.peertube.model;
import java.util.ArrayList;
import java.util.Date;
public class Server { public class Server {
private Integer id; private Integer id;
@ -26,16 +29,20 @@ public class Server {
private String version; private String version;
private Boolean signupAllowed; private Boolean signupAllowed;
private Double userVideoQuota; private Double userVideoQuota;
private Category category;
private ArrayList<String> languages;
private Boolean autoBlacklistUserVideosEnabled;
private String defaultNSFWPolicy;
private Boolean isNSFW;
private Integer totalUsers; private Integer totalUsers;
private Integer totalVideos; private Integer totalVideos;
private Integer totalLocalVideos; private Integer totalLocalVideos;
private Integer totalInstanceFollowers; private Integer totalInstanceFollowers;
private Integer totalInstanceFollowing; private Integer totalInstanceFollowing;
private Boolean supportsIPv6; private Boolean supportsIPv6;
private String country; private String country;
private Integer health; private Integer health;
private Date createdAt;
public Integer getId() { public Integer getId() {
return id; return id;
@ -93,6 +100,46 @@ public class Server {
this.userVideoQuota = userVideoQuota; this.userVideoQuota = userVideoQuota;
} }
public Category getCategory() {
return category;
}
public void setCategory(Category category) {
this.category = category;
}
public ArrayList<String> getLanguages() {
return languages;
}
public void setLanguages(ArrayList<String> languages) {
this.languages = languages;
}
public Boolean getAutoBlacklistUserVideosEnabled() {
return autoBlacklistUserVideosEnabled;
}
public void setAutoBlacklistUserVideosEnabled(Boolean autoBlacklistUserVideosEnabled) {
this.autoBlacklistUserVideosEnabled = autoBlacklistUserVideosEnabled;
}
public String getDefaultNSFWPolicy() {
return defaultNSFWPolicy;
}
public void setDefaultNSFWPolicy(String defaultNSFWPolicy) {
this.defaultNSFWPolicy = defaultNSFWPolicy;
}
public Boolean getNSFW() {
return isNSFW;
}
public void setNSFW(Boolean NSFW) {
isNSFW = NSFW;
}
public Integer getTotalUsers() { public Integer getTotalUsers() {
return totalUsers; return totalUsers;
} }
@ -156,4 +203,12 @@ public class Server {
public void setHealth(Integer health) { public void setHealth(Integer health) {
this.health = health; this.health = health;
} }
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
} }

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M12,4.5C7,4.5 2.73,7.61 1,12c1.73,4.39 6,7.5 11,7.5s9.27,-3.11 11,-7.5c-1.73,-4.39 -6,-7.5 -11,-7.5zM12,17c-2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5 -2.24,5 -5,5zM12,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3 3,-1.34 3,-3 -1.34,-3 -3,-3z"/>
</vector>

View File

@ -16,7 +16,7 @@
android:paddingEnd="12dp" /> android:paddingEnd="12dp" />
<TextView <TextView
android:id="@+id/name" android:id="@+id/sl_row_name"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentTop="true" android:layout_alignParentTop="true"
@ -31,7 +31,7 @@
android:id="@+id/videoMeta" android:id="@+id/videoMeta"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/name" android:layout_below="@+id/sl_row_name"
android:layout_alignParentEnd="true" android:layout_alignParentEnd="true"
android:layout_marginStart="6dp" android:layout_marginStart="6dp"
android:layout_marginTop="0dp" android:layout_marginTop="0dp"
@ -58,7 +58,7 @@
android:layout_marginStart="-16dp" android:layout_marginStart="-16dp"
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
android:layout_marginEnd="0dp" android:layout_marginEnd="0dp"
android:layout_toEndOf="@+id/name" android:layout_toEndOf="@+id/sl_row_name"
android:background="@null" android:background="@null"
android:contentDescription="@string/descr_overflow_button" android:contentDescription="@string/descr_overflow_button"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Caption" /> android:textAppearance="@style/Base.TextAppearance.AppCompat.Caption" />

View File

@ -50,7 +50,7 @@
android:paddingEnd="12dp" /> android:paddingEnd="12dp" />
<TextView <TextView
android:id="@+id/name" android:id="@+id/sl_row_name"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/thumb" android:layout_below="@id/thumb"
@ -66,7 +66,7 @@
android:id="@+id/videoMeta" android:id="@+id/videoMeta"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/name" android:layout_below="@+id/sl_row_name"
android:layout_marginStart="6dp" android:layout_marginStart="6dp"
android:layout_marginTop="0dp" android:layout_marginTop="0dp"
android:layout_marginEnd="6dp" android:layout_marginEnd="6dp"
@ -93,7 +93,7 @@
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
android:layout_marginStart="-16dp" android:layout_marginStart="-16dp"
android:layout_marginEnd="0dp" android:layout_marginEnd="0dp"
android:layout_toEndOf="@+id/name" android:layout_toEndOf="@+id/sl_row_name"
android:background="@null" android:background="@null"
android:contentDescription="@string/descr_overflow_button" android:contentDescription="@string/descr_overflow_button"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Caption" android:textAppearance="@style/Base.TextAppearance.AppCompat.Caption"

View File

@ -50,7 +50,7 @@
android:paddingEnd="12dp" /> android:paddingEnd="12dp" />
<TextView <TextView
android:id="@+id/name" android:id="@+id/sl_row_name"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/thumb" android:layout_below="@id/thumb"
@ -66,7 +66,7 @@
android:id="@+id/videoMeta" android:id="@+id/videoMeta"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/name" android:layout_below="@+id/sl_row_name"
android:layout_marginStart="6dp" android:layout_marginStart="6dp"
android:layout_marginTop="0dp" android:layout_marginTop="0dp"
android:layout_marginEnd="6dp" android:layout_marginEnd="6dp"
@ -93,7 +93,7 @@
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
android:layout_marginStart="-16dp" android:layout_marginStart="-16dp"
android:layout_marginEnd="0dp" android:layout_marginEnd="0dp"
android:layout_toEndOf="@+id/name" android:layout_toEndOf="@+id/sl_row_name"
android:background="@null" android:background="@null"
android:contentDescription="@string/descr_overflow_button" android:contentDescription="@string/descr_overflow_button"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Caption" android:textAppearance="@style/Base.TextAppearance.AppCompat.Caption"

View File

@ -50,7 +50,7 @@
android:paddingEnd="12dp" /> android:paddingEnd="12dp" />
<TextView <TextView
android:id="@+id/name" android:id="@+id/sl_row_name"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/thumb" android:layout_below="@id/thumb"
@ -66,7 +66,7 @@
android:id="@+id/videoMeta" android:id="@+id/videoMeta"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/name" android:layout_below="@+id/sl_row_name"
android:layout_marginStart="6dp" android:layout_marginStart="6dp"
android:layout_marginTop="0dp" android:layout_marginTop="0dp"
android:layout_marginEnd="6dp" android:layout_marginEnd="6dp"
@ -93,7 +93,7 @@
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
android:layout_marginStart="-16dp" android:layout_marginStart="-16dp"
android:layout_marginEnd="0dp" android:layout_marginEnd="0dp"
android:layout_toEndOf="@+id/name" android:layout_toEndOf="@+id/sl_row_name"
android:background="@null" android:background="@null"
android:contentDescription="@string/descr_overflow_button" android:contentDescription="@string/descr_overflow_button"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Caption" android:textAppearance="@style/Base.TextAppearance.AppCompat.Caption"

View File

@ -7,15 +7,18 @@
card_view:cardElevation="0dp" card_view:cardElevation="0dp"
card_view:cardUseCompatPadding="true"> card_view:cardUseCompatPadding="true">
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:padding="12dp">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="vertical">
android:padding="12dp">
<TextView <TextView
android:id="@+id/name" android:id="@+id/sl_row_name"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="6dp" android:layout_marginStart="6dp"
@ -24,7 +27,7 @@
android:textAppearance="@style/Base.TextAppearance.AppCompat.Headline" /> android:textAppearance="@style/Base.TextAppearance.AppCompat.Headline" />
<TextView <TextView
android:id="@+id/host" android:id="@+id/sl_row_host"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="6dp" android:layout_marginStart="6dp"
@ -33,7 +36,7 @@
android:textAppearance="@style/Base.TextAppearance.AppCompat.Subhead" /> android:textAppearance="@style/Base.TextAppearance.AppCompat.Subhead" />
<TextView <TextView
android:id="@+id/signupAllowed" android:id="@+id/sl_row_signup_allowed"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="6dp" android:layout_marginStart="6dp"
@ -43,14 +46,45 @@
<TextView <TextView
android:id="@+id/shortDescription" android:id="@+id/sl_row_short_description"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="6dp" android:layout_marginStart="6dp"
android:layout_marginEnd="24dp" android:layout_marginEnd="24dp"
android:paddingTop="0dp" android:paddingTop="0dp"
android:visibility="gone"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Subhead" /> android:textAppearance="@style/Base.TextAppearance.AppCompat.Subhead" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="0dp"
android:layout_marginStart="6dp"
android:layout_marginEnd="24dp"
android:orientation="horizontal">
<TextView
android:id="@+id/sl_row_video_totals"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Subhead" />
</LinearLayout>
</LinearLayout> </LinearLayout>
<ImageView
android:id="@+id/sl_row_is_nsfw"
android:src="@drawable/ic_baseline_remove_red_eye_24"
android:visibility="gone"
android:layout_width="24dp"
android:layout_alignParentEnd="true"
android:layout_height="wrap_content"
android:contentDescription="@string/server_selection_nsfw_instance" />
</RelativeLayout>
</androidx.cardview.widget.CardView> </androidx.cardview.widget.CardView>

View File

@ -58,7 +58,7 @@
android:paddingEnd="12dp" /> android:paddingEnd="12dp" />
<TextView <TextView
android:id="@+id/name" android:id="@+id/sl_row_name"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/thumb" android:layout_below="@id/thumb"
@ -74,7 +74,7 @@
android:id="@+id/videoMeta" android:id="@+id/videoMeta"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/name" android:layout_below="@+id/sl_row_name"
android:layout_marginStart="6dp" android:layout_marginStart="6dp"
android:layout_marginTop="0dp" android:layout_marginTop="0dp"
android:layout_marginEnd="6dp" android:layout_marginEnd="6dp"
@ -101,7 +101,7 @@
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
android:layout_marginStart="-16dp" android:layout_marginStart="-16dp"
android:layout_marginEnd="0dp" android:layout_marginEnd="0dp"
android:layout_toEndOf="@+id/name" android:layout_toEndOf="@+id/sl_row_name"
android:background="@null" android:background="@null"
android:contentDescription="@string/descr_overflow_button" android:contentDescription="@string/descr_overflow_button"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Caption" android:textAppearance="@style/Base.TextAppearance.AppCompat.Caption"

View File

@ -372,6 +372,10 @@
<string name="settings_activity_about_category_title">About</string> <string name="settings_activity_about_category_title">About</string>
<string name="settings_activity_look_and_feel_category_title"><![CDATA[Look & Feel]]></string> <string name="settings_activity_look_and_feel_category_title"><![CDATA[Look & Feel]]></string>
<string name="peertube_instance_search_default_description" translatable="false">PeerTube, a federated (ActivityPub) video streaming platform using P2P (BitTorrent) directly in the web browser with WebTorrent and Angular.</string>
<string name="server_selection_nsfw_instance">NSFW Instance</string>
<string name="server_selection_video_totals">Videos: %s, Local Videos: %s</string>
<!-- Constants, Don't translate --> <!-- Constants, Don't translate -->
<string name="pref_token_access" translatable="false">pref_token_access</string> <string name="pref_token_access" translatable="false">pref_token_access</string>