diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index d8b93aec3..5b347510a 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -235,6 +235,11 @@
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name" />
+
{
+ Intent mainActivity = new Intent(LoginActivity.this, PeertubeRegisterActivity.class);
+ startActivity(mainActivity);
+ });
+
+
login_instance = findViewById(R.id.login_instance);
login_uid = findViewById(R.id.login_uid);
login_passwd = findViewById(R.id.login_passwd);
diff --git a/app/src/main/java/app/fedilab/android/activities/MastodonRegisterActivity.java b/app/src/main/java/app/fedilab/android/activities/MastodonRegisterActivity.java
index dfb06285a..6cacae87a 100644
--- a/app/src/main/java/app/fedilab/android/activities/MastodonRegisterActivity.java
+++ b/app/src/main/java/app/fedilab/android/activities/MastodonRegisterActivity.java
@@ -165,12 +165,12 @@ public class MastodonRegisterActivity extends BaseActivity implements OnRetrieve
reg_category.setOnItemSelectedListener(new MaterialSpinner.OnItemSelectedListener() {
@Override
public void onItemSelected(MaterialSpinner view, int position, long id, String item) {
- new RetrieveInstanceRegAsyncTask(MastodonRegisterActivity.this, itemA[position], MastodonRegisterActivity.this).executeOnExecutor(THREAD_POOL_EXECUTOR);
+ new RetrieveInstanceRegAsyncTask(MastodonRegisterActivity.this, RetrieveInstanceRegAsyncTask.instanceType.MASTODON, itemA[position], MastodonRegisterActivity.this).executeOnExecutor(THREAD_POOL_EXECUTOR);
}
});
- new RetrieveInstanceRegAsyncTask(MastodonRegisterActivity.this, "general", MastodonRegisterActivity.this).executeOnExecutor(THREAD_POOL_EXECUTOR);
+ new RetrieveInstanceRegAsyncTask(MastodonRegisterActivity.this, RetrieveInstanceRegAsyncTask.instanceType.MASTODON,"general", MastodonRegisterActivity.this).executeOnExecutor(THREAD_POOL_EXECUTOR);
signup = findViewById(R.id.signup);
EditText username = findViewById(R.id.username);
diff --git a/app/src/main/java/app/fedilab/android/activities/PeertubeRegisterActivity.java b/app/src/main/java/app/fedilab/android/activities/PeertubeRegisterActivity.java
new file mode 100644
index 000000000..dd00bfda6
--- /dev/null
+++ b/app/src/main/java/app/fedilab/android/activities/PeertubeRegisterActivity.java
@@ -0,0 +1,308 @@
+/* Copyright 2017 Thomas Schneider
+ *
+ * This file is a part of Fedilab
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
+ * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+ * Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with Fedilab; if not,
+ * see . */
+package app.fedilab.android.activities;
+
+import android.animation.Animator;
+import android.animation.AnimatorListenerAdapter;
+import android.annotation.SuppressLint;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.SharedPreferences;
+import android.os.AsyncTask;
+import android.os.Bundle;
+import android.text.Html;
+import android.text.SpannableString;
+import android.text.Spanned;
+import android.text.method.LinkMovementMethod;
+import android.text.style.ForegroundColorSpan;
+import android.text.style.UnderlineSpan;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.CheckBox;
+import android.widget.EditText;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import androidx.appcompat.app.ActionBar;
+import androidx.appcompat.app.AlertDialog;
+import androidx.appcompat.widget.Toolbar;
+import androidx.core.content.ContextCompat;
+import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
+
+
+import java.io.IOException;
+import java.lang.ref.WeakReference;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.List;
+
+import app.fedilab.android.R;
+import app.fedilab.android.asynctasks.CreateMastodonAccountAsyncTask;
+import app.fedilab.android.asynctasks.RetrieveInstanceRegAsyncTask;
+import app.fedilab.android.client.APIResponse;
+import app.fedilab.android.client.Entities.AccountCreation;
+import app.fedilab.android.client.Entities.InstanceReg;
+import app.fedilab.android.drawers.InstancePeertubeRegAdapter;
+import app.fedilab.android.helper.Helper;
+import app.fedilab.android.interfaces.OnPostStatusActionInterface;
+import app.fedilab.android.interfaces.OnRetrieveInstanceInterface;
+import es.dmoral.toasty.Toasty;
+
+import static android.os.AsyncTask.THREAD_POOL_EXECUTOR;
+
+/**
+ * Created by Thomas on 04/11/2019.
+ * Register activity class
+ */
+
+public class PeertubeRegisterActivity extends BaseActivity implements OnRetrieveInstanceInterface, OnPostStatusActionInterface {
+
+
+ private Button signup;
+ private String instance;
+ private TextView error_message;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
+ int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
+ switch (theme) {
+ case Helper.THEME_LIGHT:
+ setTheme(R.style.AppTheme);
+ break;
+ case Helper.THEME_DARK:
+ setTheme(R.style.AppThemeDark);
+ break;
+ case Helper.THEME_BLACK:
+ setTheme(R.style.AppThemeBlack);
+ break;
+ default:
+ setTheme(R.style.AppThemeDark);
+ }
+
+ setContentView(R.layout.activity_register_peertube);
+ ActionBar actionBar = getSupportActionBar();
+ if (actionBar != null) {
+ LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
+ assert inflater != null;
+ View view = inflater.inflate(R.layout.simple_bar, new LinearLayout(getApplicationContext()), false);
+ actionBar.setCustomView(view, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
+ actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
+ ImageView toolbar_close = actionBar.getCustomView().findViewById(R.id.toolbar_close);
+ TextView toolbar_title = actionBar.getCustomView().findViewById(R.id.toolbar_title);
+ toolbar_close.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ finish();
+ }
+ });
+ toolbar_title.setText(R.string.sign_up);
+ if (theme == Helper.THEME_LIGHT) {
+ Toolbar toolbar = actionBar.getCustomView().findViewById(R.id.toolbar);
+ Helper.colorizeToolbar(toolbar, R.color.black, PeertubeRegisterActivity.this);
+ }
+ }
+
+
+ new RetrieveInstanceRegAsyncTask(PeertubeRegisterActivity.this,RetrieveInstanceRegAsyncTask.instanceType.PEERTUBE, null, PeertubeRegisterActivity.this).executeOnExecutor(THREAD_POOL_EXECUTOR);
+
+ signup = findViewById(R.id.signup);
+ EditText username = findViewById(R.id.username);
+ EditText email = findViewById(R.id.email);
+ EditText password = findViewById(R.id.password);
+ EditText password_confirm = findViewById(R.id.password_confirm);
+ CheckBox agreement = findViewById(R.id.agreement);
+ error_message = findViewById(R.id.error_message);
+
+ signup.setOnClickListener(view -> {
+ error_message.setVisibility(View.GONE);
+ if (username.getText().toString().trim().length() == 0 || email.getText().toString().trim().length() == 0 ||
+ password.getText().toString().trim().length() == 0 || password_confirm.getText().toString().trim().length() == 0 || !agreement.isChecked()) {
+ Toasty.error(getApplicationContext(), getString(R.string.all_field_filled)).show();
+ return;
+ }
+ if (!password.getText().toString().trim().equals(password_confirm.getText().toString().trim())) {
+ Toasty.error(getApplicationContext(), getString(R.string.password_error)).show();
+ return;
+ }
+ if (!android.util.Patterns.EMAIL_ADDRESS.matcher(email.getText().toString().trim()).matches()) {
+ Toasty.error(getApplicationContext(), getString(R.string.email_error)).show();
+ return;
+ }
+ if (password.getText().toString().trim().length() < 8) {
+ Toasty.error(getApplicationContext(), getString(R.string.password_too_short)).show();
+ return;
+ }
+ if (username.getText().toString().matches("[a-zA-Z0-9_]")) {
+ Toasty.error(getApplicationContext(), getString(R.string.username_error)).show();
+ return;
+ }
+ signup.setEnabled(false);
+ AccountCreation accountCreation = new AccountCreation();
+ accountCreation.setEmail(email.getText().toString().trim());
+ accountCreation.setPassword(password.getText().toString().trim());
+ accountCreation.setPasswordConfirm(password_confirm.getText().toString().trim());
+ accountCreation.setUsername(username.getText().toString().trim());
+ new CreateMastodonAccountAsyncTask(PeertubeRegisterActivity.this, accountCreation, instance, PeertubeRegisterActivity.this).executeOnExecutor(THREAD_POOL_EXECUTOR);
+ });
+
+
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ }
+
+ @Override
+ public void onRetrieveInstance(APIResponse apiResponse) {
+ if (apiResponse.getError() != null) {
+ Toasty.error(getApplicationContext(), getString(R.string.toast_error_instance_reg), Toast.LENGTH_LONG).show();
+ return;
+ }
+ List instanceRegs = apiResponse.getInstanceRegs();
+ RecyclerView lv_instances = findViewById(R.id.reg_category_view);
+ InstancePeertubeRegAdapter instanceRegAdapter = new InstancePeertubeRegAdapter(PeertubeRegisterActivity.this, instanceRegs);
+ LinearLayoutManager mLayoutManager = new LinearLayoutManager(PeertubeRegisterActivity.this);
+ lv_instances.setLayoutManager(mLayoutManager);
+ lv_instances.setNestedScrollingEnabled(false);
+ lv_instances.setAdapter(instanceRegAdapter);
+
+
+ }
+
+ public void pickupInstance(String instance) {
+
+ LinearLayout form_container = findViewById(R.id.form_container);
+ LinearLayout drawer_layout = findViewById(R.id.drawer_layout);
+
+ TextView host_reg = findViewById(R.id.host_reg);
+ host_reg.setText(instance);
+ this.instance = instance;
+
+ drawer_layout.animate()
+ .translationY(0)
+ .alpha(0.0f)
+ .setListener(new AnimatorListenerAdapter() {
+ @Override
+ public void onAnimationEnd(Animator animation) {
+ super.onAnimationEnd(animation);
+ drawer_layout.setVisibility(View.GONE);
+ form_container.setVisibility(View.VISIBLE);
+ }
+ });
+
+ TextView change_instance = findViewById(R.id.change_instance);
+ final SpannableString change = new SpannableString(String.format("(%s)", getString(R.string.change)));
+ change.setSpan(new UnderlineSpan(), 0, change.length(), 0);
+ SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
+ int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
+ if (theme == Helper.THEME_DARK)
+ change.setSpan(new ForegroundColorSpan(ContextCompat.getColor(PeertubeRegisterActivity.this, R.color.dark_link_toot)), 0, change.length(),
+ Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
+ else if (theme == Helper.THEME_BLACK)
+ change.setSpan(new ForegroundColorSpan(ContextCompat.getColor(PeertubeRegisterActivity.this, R.color.black_link_toot)), 0, change.length(),
+ Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
+ else if (theme == Helper.THEME_LIGHT)
+ change.setSpan(new ForegroundColorSpan(ContextCompat.getColor(PeertubeRegisterActivity.this, R.color.mastodonC4)), 0, change.length(),
+ Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
+ change_instance.setText(change);
+ change_instance.setOnClickListener(view -> {
+ drawer_layout.setVisibility(View.VISIBLE);
+ drawer_layout.animate()
+ .translationY(0)
+ .alpha(1.f)
+ .setListener(new AnimatorListenerAdapter() {
+ @Override
+ public void onAnimationEnd(Animator animation) {
+ super.onAnimationEnd(animation);
+ form_container.setVisibility(View.GONE);
+ }
+ });
+ });
+
+ TextView agreement_text = findViewById(R.id.agreement_text);
+
+ TextView username_indicator = findViewById(R.id.username_indicator);
+ username_indicator.setText(getString(R.string.username_indicator, instance));
+
+ String tos = getString(R.string.tos);
+ String serverrules = getString(R.string.server_rules);
+ String content_agreement = getString(R.string.agreement_check,
+ "" + serverrules + "",
+ "" + tos + ""
+ );
+ agreement_text.setMovementMethod(LinkMovementMethod.getInstance());
+ agreement_text.setText(Html.fromHtml(content_agreement));
+ }
+
+
+ @Override
+ public void onPostStatusAction(APIResponse apiResponse) {
+ if (apiResponse.getError() != null) {
+ String errorMessage;
+ if (apiResponse.getError().getError() != null) {
+ try {
+ String[] resp = apiResponse.getError().getError().split(":");
+ if (resp.length == 2)
+ errorMessage = apiResponse.getError().getError().split(":")[1];
+ else if (resp.length == 3)
+ errorMessage = apiResponse.getError().getError().split(":")[2];
+ else
+ errorMessage = getString(R.string.toast_error);
+ } catch (Exception e) {
+ errorMessage = getString(R.string.toast_error);
+ }
+ } else {
+ errorMessage = getString(R.string.toast_error);
+ }
+ error_message.setText(errorMessage);
+ error_message.setVisibility(View.VISIBLE);
+ signup.setEnabled(true);
+ return;
+ }
+ SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
+ int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
+ int style;
+ if (theme == Helper.THEME_DARK) {
+ style = R.style.DialogDark;
+ } else if (theme == Helper.THEME_BLACK) {
+ style = R.style.DialogBlack;
+ } else {
+ style = R.style.Dialog;
+ }
+ AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(PeertubeRegisterActivity.this, style);
+ dialogBuilder.setCancelable(false);
+ dialogBuilder.setPositiveButton(R.string.validate, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ dialog.dismiss();
+ finish();
+ }
+ });
+ AlertDialog alertDialog = dialogBuilder.create();
+ alertDialog.setTitle(getString(R.string.account_created));
+ alertDialog.setMessage(getString(R.string.account_created_message, this.instance));
+ alertDialog.show();
+ }
+
+}
\ No newline at end of file
diff --git a/app/src/main/java/app/fedilab/android/asynctasks/RetrieveInstanceRegAsyncTask.java b/app/src/main/java/app/fedilab/android/asynctasks/RetrieveInstanceRegAsyncTask.java
index 7a1e74704..af276d6dd 100644
--- a/app/src/main/java/app/fedilab/android/asynctasks/RetrieveInstanceRegAsyncTask.java
+++ b/app/src/main/java/app/fedilab/android/asynctasks/RetrieveInstanceRegAsyncTask.java
@@ -21,6 +21,7 @@ import java.lang.ref.WeakReference;
import app.fedilab.android.client.API;
import app.fedilab.android.client.APIResponse;
+import app.fedilab.android.client.PeertubeAPI;
import app.fedilab.android.interfaces.OnRetrieveInstanceInterface;
@@ -35,16 +36,27 @@ public class RetrieveInstanceRegAsyncTask extends AsyncTask {
private APIResponse apiResponse;
private WeakReference contextReference;
private String category;
+ private instanceType type;
- public RetrieveInstanceRegAsyncTask(Context context, String category, OnRetrieveInstanceInterface onRetrieveInstanceInterface) {
+ public enum instanceType{
+ MASTODON,
+ PEERTUBE
+ }
+
+ public RetrieveInstanceRegAsyncTask(Context context, instanceType type, String category, OnRetrieveInstanceInterface onRetrieveInstanceInterface) {
this.contextReference = new WeakReference<>(context);
this.listener = onRetrieveInstanceInterface;
this.category = category;
+ this.type = type;
}
@Override
protected Void doInBackground(Void... params) {
- apiResponse = new API(this.contextReference.get()).getInstanceReg(category);
+ if( type == instanceType.MASTODON) {
+ apiResponse = new API(this.contextReference.get()).getInstanceReg(category);
+ }else if( type == instanceType.PEERTUBE){
+ apiResponse = new PeertubeAPI(this.contextReference.get()).getInstanceReg();
+ }
return null;
}
diff --git a/app/src/main/java/app/fedilab/android/client/Entities/InstanceReg.java b/app/src/main/java/app/fedilab/android/client/Entities/InstanceReg.java
index 36c1f05fc..cf89a4b2a 100644
--- a/app/src/main/java/app/fedilab/android/client/Entities/InstanceReg.java
+++ b/app/src/main/java/app/fedilab/android/client/Entities/InstanceReg.java
@@ -25,6 +25,10 @@ public class InstanceReg {
private int total_users;
private int last_week_users;
private boolean selected = false;
+ private int totalVideos;
+ private String country;
+ private int totalInstanceFollowers;
+ private int totalInstanceFollowing;
public String getDomain() {
return domain;
@@ -97,4 +101,36 @@ public class InstanceReg {
public void setSelected(boolean selected) {
this.selected = selected;
}
+
+ public int getTotalVideos() {
+ return totalVideos;
+ }
+
+ public void setTotalVideos(int totalVideos) {
+ this.totalVideos = totalVideos;
+ }
+
+ public String getCountry() {
+ return country;
+ }
+
+ public void setCountry(String country) {
+ this.country = country;
+ }
+
+ public int getTotalInstanceFollowers() {
+ return totalInstanceFollowers;
+ }
+
+ public void setTotalInstanceFollowers(int totalInstanceFollowers) {
+ this.totalInstanceFollowers = totalInstanceFollowers;
+ }
+
+ public int getTotalInstanceFollowing() {
+ return totalInstanceFollowing;
+ }
+
+ public void setTotalInstanceFollowing(int totalInstanceFollowing) {
+ this.totalInstanceFollowing = totalInstanceFollowing;
+ }
}
diff --git a/app/src/main/java/app/fedilab/android/client/PeertubeAPI.java b/app/src/main/java/app/fedilab/android/client/PeertubeAPI.java
index 9b1195f69..3d81edc5e 100644
--- a/app/src/main/java/app/fedilab/android/client/PeertubeAPI.java
+++ b/app/src/main/java/app/fedilab/android/client/PeertubeAPI.java
@@ -47,6 +47,7 @@ import app.fedilab.android.client.Entities.Filters;
import app.fedilab.android.client.Entities.HowToVideo;
import app.fedilab.android.client.Entities.Instance;
import app.fedilab.android.client.Entities.InstanceNodeInfo;
+import app.fedilab.android.client.Entities.InstanceReg;
import app.fedilab.android.client.Entities.Peertube;
import app.fedilab.android.client.Entities.PeertubeAccountNotification;
import app.fedilab.android.client.Entities.PeertubeActorFollow;
@@ -381,6 +382,27 @@ public class PeertubeAPI {
return account;
}
+
+ /***
+ * Get instance for registering an account *synchronously*
+ * @return APIResponse
+ */
+ public APIResponse getInstanceReg() {
+ apiResponse = new APIResponse();
+ try {
+ String response = new HttpsConnection(context, null).get("https://instances.joinpeertube.org/api/v1/instances?start=0&count=50&signup=true&health=100&sort=-totalUsers");
+ JSONObject result = new JSONObject(response);
+ List instanceRegs = parseInstanceReg(result.getJSONArray("data"));
+ apiResponse.setInstanceRegs(instanceRegs);
+ } catch (HttpsConnection.HttpsConnectionException e) {
+ setError(e.getStatusCode(), e);
+ } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
+ e.printStackTrace();
+ }
+ return apiResponse;
+ }
+
+
/***
* Verifiy credential of the authenticated user *synchronously*
* @return Account
@@ -1644,6 +1666,56 @@ public class PeertubeAPI {
}
+ /**
+ * Parse json response for several instance reg
+ *
+ * @param jsonArray JSONArray
+ * @return List
+ */
+ public List parseInstanceReg(JSONArray jsonArray) {
+
+ List instanceRegs = new ArrayList<>();
+ try {
+ int i = 0;
+ while (i < jsonArray.length()) {
+ JSONObject resobj = jsonArray.getJSONObject(i);
+ InstanceReg instanceReg = parseInstanceReg(resobj);
+ i++;
+ instanceRegs.add(instanceReg);
+ }
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ return instanceRegs;
+ }
+
+ /**
+ * Parse json response an unique instance for registering
+ *
+ * @param resobj JSONObject
+ * @return InstanceReg
+ */
+ private InstanceReg parseInstanceReg(JSONObject resobj) {
+ InstanceReg instanceReg = new InstanceReg();
+ try {
+ instanceReg.setDomain(resobj.getString("host"));
+ instanceReg.setVersion(resobj.getString("version"));
+ instanceReg.setDescription(resobj.getString("shortDescription"));
+ instanceReg.setLanguage(resobj.getString("country"));
+ instanceReg.setCategory("");
+ instanceReg.setProxied_thumbnail("");
+ instanceReg.setTotal_users(resobj.getInt("totalUsers"));
+ instanceReg.setTotalInstanceFollowers(resobj.getInt("totalInstanceFollowers"));
+ instanceReg.setTotalInstanceFollowing(resobj.getInt("totalInstanceFollowing"));
+ instanceReg.setLast_week_users(0);
+ instanceReg.setCountry(resobj.getString("country"));
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ return instanceReg;
+ }
+
+
/**
* Parse json response for several howto
*
@@ -1661,7 +1733,6 @@ public class PeertubeAPI {
i++;
peertubes.add(peertube);
}
-
} catch (JSONException e) {
setDefaultError(e);
}
diff --git a/app/src/main/java/app/fedilab/android/drawers/InstancePeertubeRegAdapter.java b/app/src/main/java/app/fedilab/android/drawers/InstancePeertubeRegAdapter.java
new file mode 100644
index 000000000..866f4e169
--- /dev/null
+++ b/app/src/main/java/app/fedilab/android/drawers/InstancePeertubeRegAdapter.java
@@ -0,0 +1,116 @@
+package app.fedilab.android.drawers;
+/* Copyright 2019 Thomas Schneider
+ *
+ * This file is a part of Fedilab
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
+ * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+ * Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with Fedilab; if not,
+ * see . */
+
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ImageButton;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import androidx.annotation.NonNull;
+import androidx.recyclerview.widget.RecyclerView;
+
+import com.bumptech.glide.Glide;
+import com.bumptech.glide.load.resource.bitmap.FitCenter;
+import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
+import com.bumptech.glide.request.RequestOptions;
+
+import java.util.List;
+
+import app.fedilab.android.R;
+import app.fedilab.android.activities.PeertubeRegisterActivity;
+import app.fedilab.android.client.Entities.InstanceReg;
+import app.fedilab.android.helper.Helper;
+
+
+/**
+ * Created by Thomas on 04/11/2019.
+ * Adapter to display instances
+ */
+
+public class InstancePeertubeRegAdapter extends RecyclerView.Adapter {
+ private Context context;
+ private List instanceRegs;
+ private LayoutInflater layoutInflater;
+
+ public InstancePeertubeRegAdapter(Context context, List instanceRegs) {
+ this.context = context;
+ this.instanceRegs = instanceRegs;
+ this.layoutInflater = LayoutInflater.from(this.context);
+ }
+
+ public int getCount() {
+ return instanceRegs.size();
+ }
+
+ public InstanceReg getItem(int position) {
+ return instanceRegs.get(position);
+ }
+
+ @NonNull
+ @Override
+ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
+ return new ViewHolder(layoutInflater.inflate(R.layout.drawer_instance_reg_peertube, parent, false));
+ }
+
+ @Override
+ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
+ InstanceReg instanceReg = instanceRegs.get(position);
+
+ final InstancePeertubeRegAdapter.ViewHolder holder = (InstancePeertubeRegAdapter.ViewHolder) viewHolder;
+
+ holder.instance_choose.setOnClickListener(v -> {
+ ((PeertubeRegisterActivity) context).pickupInstance(instanceReg.getDomain());
+ });
+
+ holder.instance_count_user.setText(context.getString(R.string.users, Helper.withSuffix(instanceReg.getTotal_users())));
+ holder.instance_description.setText(instanceReg.getDescription());
+ holder.instance_host.setText(instanceReg.getDomain());
+ holder.instance_version.setText(String.format("%s - %s", instanceReg.getCategory(), instanceReg.getVersion()));
+ Glide.with(context)
+ .load(instanceReg.getProxied_thumbnail())
+ .apply(new RequestOptions().transforms(new FitCenter(), new RoundedCorners(10)))
+ .into(holder.instance_pp);
+ }
+
+ public long getItemId(int position) {
+ return position;
+ }
+
+ @Override
+ public int getItemCount() {
+ return instanceRegs.size();
+ }
+
+
+ class ViewHolder extends RecyclerView.ViewHolder {
+ ImageView instance_pp;
+ TextView instance_host, instance_version, instance_description, instance_count_user;
+ ImageButton instance_choose;
+
+ public ViewHolder(View itemView) {
+ super(itemView);
+ instance_pp = itemView.findViewById(R.id.instance_pp);
+ instance_host = itemView.findViewById(R.id.instance_host);
+ instance_version = itemView.findViewById(R.id.instance_version);
+ instance_description = itemView.findViewById(R.id.instance_description);
+ instance_count_user = itemView.findViewById(R.id.instance_count_user);
+ instance_choose = itemView.findViewById(R.id.instance_choose);
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml
index f9f959fc3..6e3d77c43 100644
--- a/app/src/main/res/layout/activity_login.xml
+++ b/app/src/main/res/layout/activity_login.xml
@@ -115,6 +115,15 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/drawer_instance_reg_peertube.xml b/app/src/main/res/layout/drawer_instance_reg_peertube.xml
new file mode 100644
index 000000000..07fc1bed8
--- /dev/null
+++ b/app/src/main/res/layout/drawer_instance_reg_peertube.xml
@@ -0,0 +1,98 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index cc77bcaa8..946ca24e5 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1004,6 +1004,7 @@
Something went wrong when checking available instances!
Join Mastodon
Choose an instance by picking up a category, then tap on a check button.
+ Choose an instance by tapping on a check button.
%1$s users
Confirm password
I agree to %1$s and %2$s
@@ -1244,4 +1245,5 @@
Fetching conversation
Order by
Title for the video
+ Join Peertube
\ No newline at end of file