server selection wip

This commit is contained in:
Stefan Schüller 2019-03-02 20:13:02 +01:00
parent 66eb18d1ca
commit 6274e964e4
6 changed files with 135 additions and 27 deletions

View File

@ -59,7 +59,7 @@ public class SelectServerActivity extends AppCompatActivity {
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(SelectServerActivity.this);
recyclerView.setLayoutManager(layoutManager);
serverAdapter = new ServerAdapter(new ArrayList<>(), SelectServerActivity.this);
serverAdapter = new ServerAdapter(new ArrayList<>(), this);
recyclerView.setAdapter(serverAdapter);
loadServers(currentStart, count);

View File

@ -18,6 +18,8 @@
package net.schueller.peertube.adapter;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -25,6 +27,7 @@ import android.widget.TextView;
import net.schueller.peertube.R;
import net.schueller.peertube.activity.SelectServerActivity;
import net.schueller.peertube.helper.APIUrlHelper;
import net.schueller.peertube.model.Server;
@ -38,12 +41,12 @@ public class ServerAdapter extends RecyclerView.Adapter<ServerAdapter.AccountVie
private ArrayList<Server> serverList;
private Context context;
private SelectServerActivity activity;
private String baseUrl;
public ServerAdapter(ArrayList<Server> serverList, Context context) {
public ServerAdapter(ArrayList<Server> serverList, SelectServerActivity activity) {
this.serverList = serverList;
this.context = context;
this.activity = activity;
}
@NonNull
@ -52,7 +55,7 @@ public class ServerAdapter extends RecyclerView.Adapter<ServerAdapter.AccountVie
LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
View view = layoutInflater.inflate(R.layout.row_server, parent, false);
baseUrl = APIUrlHelper.getUrl(context);
baseUrl = APIUrlHelper.getUrl(activity);
return new AccountViewHolder(view);
}
@ -62,7 +65,24 @@ public class ServerAdapter extends RecyclerView.Adapter<ServerAdapter.AccountVie
holder.name.setText(serverList.get(position).getName());
holder.host.setText(serverList.get(position).getHost());
holder.signupAllowed.setText(activity.getString(R.string.server_selection_signup_allowed, activity.getString(
serverList.get(position).getSignupAllowed() ?
R.string.server_selection_signup_allowed_yes :
R.string.server_selection_signup_allowed_no
)));
holder.shortDescription.setText(serverList.get(position).getShortDescription());
holder.itemView.setOnClickListener(v -> {
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(activity);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putString("pref_api_base", "https://" + serverList.get(position).getHost());
editor.apply();
activity.finish();
});
//
//
// holder.moreButton.setText(R.string.video_more_icon);
@ -104,12 +124,13 @@ public class ServerAdapter extends RecyclerView.Adapter<ServerAdapter.AccountVie
class AccountViewHolder extends RecyclerView.ViewHolder {
TextView name, host, shortDescription;
TextView name, host, signupAllowed, shortDescription;
AccountViewHolder(View itemView) {
super(itemView);
name = itemView.findViewById(R.id.name);
host = itemView.findViewById(R.id.host);
signupAllowed = itemView.findViewById(R.id.signupAllowed);
shortDescription = itemView.findViewById(R.id.shortDescription);
}

View File

@ -31,6 +31,10 @@ public class Server {
private Integer totalLocalVideos;
private Integer totalInstanceFollowers;
private Integer totalInstanceFollowing;
private Boolean supportsIPv6;
private String country;
private Integer health;
public Integer getId() {
@ -129,6 +133,22 @@ public class Server {
this.totalInstanceFollowing = totalInstanceFollowing;
}
public Boolean getSupportsIPv6() {
return supportsIPv6;
}
public void setSupportsIPv6(Boolean supportsIPv6) {
this.supportsIPv6 = supportsIPv6;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public Integer getHealth() {
return health;
}

View File

@ -1,34 +1,86 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activity.SelectServerActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<LinearLayout
android:padding="@dimen/fab_margin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:text="Select a Server from the list below or enter it directly." />
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<AutoCompleteTextView
android:hint="PeerTube Server URL"
android:id="@+id/serverSelectedUrl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textUri"
android:maxLines="1"
android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout>
<Button
android:id="@+id/server_selection_set"
style="?android:textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@string/action_set_url"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/empty_server_selection_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:visibility="gone"
android:text="@string/no_data_available" />
android:text="@string/no_data_available"
android:visibility="gone" />
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/serversSwipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/serverRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
android:layout_height="match_parent">
</androidx.recyclerview.widget.RecyclerView>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -31,6 +31,17 @@
android:layout_marginEnd="24dp"
android:paddingTop="0dp"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Subhead" />
<TextView
android:id="@+id/signupAllowed"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="6dp"
android:layout_marginEnd="24dp"
android:paddingTop="0dp"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Subhead" />
<TextView
android:id="@+id/shortDescription"
android:layout_width="match_parent"

View File

@ -302,6 +302,10 @@
<string name="video_download_icon" translatable="false">{faw-download}</string>
<string name="video_save_icon" translatable="false">{faw-save}</string>
<string name="action_set_url">Select Server</string>
<string name="server_selection_signup_allowed">Signup Allowed: %s</string>
<string name="server_selection_signup_allowed_yes">Yes</string>
<string name="server_selection_signup_allowed_no">No</string>
<string name="title_activity_account">Account</string>
<string name="menu_video_more_report">Report</string>