From 6274e964e465924aefd69a71666452b9dd83b32a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Schu=CC=88ller?= Date: Sat, 2 Mar 2019 20:13:02 +0100 Subject: [PATCH] server selection wip --- .../activity/SelectServerActivity.java | 2 +- .../peertube/adapter/ServerAdapter.java | 31 +++++- .../net/schueller/peertube/model/Server.java | 20 ++++ .../res/layout/activity_server_selection.xml | 94 ++++++++++++++----- app/src/main/res/layout/row_server.xml | 11 +++ app/src/main/res/values/strings.xml | 4 + 6 files changed, 135 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/net/schueller/peertube/activity/SelectServerActivity.java b/app/src/main/java/net/schueller/peertube/activity/SelectServerActivity.java index 539d28f..8715b15 100644 --- a/app/src/main/java/net/schueller/peertube/activity/SelectServerActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/SelectServerActivity.java @@ -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); diff --git a/app/src/main/java/net/schueller/peertube/adapter/ServerAdapter.java b/app/src/main/java/net/schueller/peertube/adapter/ServerAdapter.java index 0772a64..2a4dcb5 100644 --- a/app/src/main/java/net/schueller/peertube/adapter/ServerAdapter.java +++ b/app/src/main/java/net/schueller/peertube/adapter/ServerAdapter.java @@ -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 serverList; - private Context context; + private SelectServerActivity activity; private String baseUrl; - public ServerAdapter(ArrayList serverList, Context context) { + public ServerAdapter(ArrayList serverList, SelectServerActivity activity) { this.serverList = serverList; - this.context = context; + this.activity = activity; } @NonNull @@ -52,7 +55,7 @@ public class ServerAdapter extends RecyclerView.Adapter { + + 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 - - + android:layout_height="wrap_content" + android:orientation="vertical" + > - - - - - - - \ No newline at end of file + + + + + + + + +