2019-06-13 17:55:21 +02:00
|
|
|
/* 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 <http://www.gnu.org/licenses>. */
|
|
|
|
package app.fedilab.android.activities;
|
|
|
|
|
2019-06-14 19:31:51 +02:00
|
|
|
import android.animation.Animator;
|
|
|
|
import android.animation.AnimatorListenerAdapter;
|
2019-06-15 11:43:32 +02:00
|
|
|
import android.content.Context;
|
2019-06-13 17:55:21 +02:00
|
|
|
import android.content.SharedPreferences;
|
2019-11-13 12:54:01 +01:00
|
|
|
import android.graphics.drawable.ColorDrawable;
|
2019-06-13 17:55:21 +02:00
|
|
|
import android.os.Bundle;
|
2021-01-19 17:43:51 +01:00
|
|
|
import android.os.Handler;
|
|
|
|
import android.os.Looper;
|
2019-06-14 19:31:51 +02:00
|
|
|
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;
|
2019-06-13 17:55:21 +02:00
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2019-11-20 10:31:33 +01:00
|
|
|
import android.widget.AdapterView;
|
2019-06-14 14:36:13 +02:00
|
|
|
import android.widget.ArrayAdapter;
|
2019-06-15 11:43:32 +02:00
|
|
|
import android.widget.Button;
|
|
|
|
import android.widget.CheckBox;
|
|
|
|
import android.widget.EditText;
|
2019-06-13 17:55:21 +02:00
|
|
|
import android.widget.ImageView;
|
2019-06-14 19:31:51 +02:00
|
|
|
import android.widget.LinearLayout;
|
2019-11-20 10:31:33 +01:00
|
|
|
import android.widget.Spinner;
|
2019-06-13 17:55:21 +02:00
|
|
|
import android.widget.TextView;
|
2019-06-14 14:36:13 +02:00
|
|
|
import android.widget.Toast;
|
2019-09-06 17:55:14 +02:00
|
|
|
|
2019-06-13 17:55:21 +02:00
|
|
|
import androidx.appcompat.app.ActionBar;
|
2019-06-15 11:43:32 +02:00
|
|
|
import androidx.appcompat.app.AlertDialog;
|
2019-06-14 19:31:51 +02:00
|
|
|
import androidx.core.content.ContextCompat;
|
2019-06-14 14:36:13 +02:00
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
2019-09-06 17:55:14 +02:00
|
|
|
|
2019-06-15 11:43:32 +02:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.lang.ref.WeakReference;
|
|
|
|
import java.net.HttpURLConnection;
|
|
|
|
import java.net.URL;
|
2019-06-14 14:36:13 +02:00
|
|
|
import java.util.List;
|
2019-06-15 11:43:32 +02:00
|
|
|
|
2019-06-13 17:55:21 +02:00
|
|
|
import app.fedilab.android.R;
|
2019-06-15 11:43:32 +02:00
|
|
|
import app.fedilab.android.asynctasks.CreateMastodonAccountAsyncTask;
|
2019-06-14 14:36:13 +02:00
|
|
|
import app.fedilab.android.asynctasks.RetrieveInstanceRegAsyncTask;
|
|
|
|
import app.fedilab.android.client.APIResponse;
|
2019-06-15 11:43:32 +02:00
|
|
|
import app.fedilab.android.client.Entities.AccountCreation;
|
2019-06-14 14:36:13 +02:00
|
|
|
import app.fedilab.android.client.Entities.InstanceReg;
|
|
|
|
import app.fedilab.android.drawers.InstanceRegAdapter;
|
2019-06-13 17:55:21 +02:00
|
|
|
import app.fedilab.android.helper.Helper;
|
2019-06-15 11:43:32 +02:00
|
|
|
import app.fedilab.android.interfaces.OnPostStatusActionInterface;
|
2019-06-14 14:36:13 +02:00
|
|
|
import app.fedilab.android.interfaces.OnRetrieveInstanceInterface;
|
|
|
|
import es.dmoral.toasty.Toasty;
|
|
|
|
|
2019-06-13 17:55:21 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by Thomas on 13/06/2019.
|
|
|
|
* Register activity class
|
|
|
|
*/
|
|
|
|
|
2019-06-15 11:43:32 +02:00
|
|
|
public class MastodonRegisterActivity extends BaseActivity implements OnRetrieveInstanceInterface, OnPostStatusActionInterface {
|
2019-06-13 17:55:21 +02:00
|
|
|
|
|
|
|
|
2019-06-15 11:43:32 +02:00
|
|
|
private Button signup;
|
|
|
|
private String instance;
|
2019-06-15 12:49:38 +02:00
|
|
|
private TextView error_message;
|
2019-06-13 17:55:21 +02:00
|
|
|
|
|
|
|
@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);
|
2019-09-06 17:55:14 +02:00
|
|
|
switch (theme) {
|
2019-06-13 17:55:21 +02:00
|
|
|
case Helper.THEME_LIGHT:
|
2019-11-09 15:47:38 +01:00
|
|
|
setTheme(R.style.AppTheme_Fedilab);
|
2019-06-13 17:55:21 +02:00
|
|
|
break;
|
|
|
|
case Helper.THEME_BLACK:
|
|
|
|
setTheme(R.style.AppThemeBlack);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
setTheme(R.style.AppThemeDark);
|
|
|
|
}
|
2019-06-14 16:01:58 +02:00
|
|
|
|
2019-06-14 14:36:13 +02:00
|
|
|
setContentView(R.layout.activity_register);
|
2019-06-13 17:55:21 +02:00
|
|
|
ActionBar actionBar = getSupportActionBar();
|
2019-09-06 17:55:14 +02:00
|
|
|
if (actionBar != null) {
|
2019-06-13 17:55:21 +02:00
|
|
|
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
|
|
|
|
assert inflater != null;
|
2020-04-08 12:42:15 +02:00
|
|
|
View view = inflater.inflate(R.layout.simple_bar, new LinearLayout(MastodonRegisterActivity.this), false);
|
2019-11-15 19:36:39 +01:00
|
|
|
view.setBackground(new ColorDrawable(ContextCompat.getColor(MastodonRegisterActivity.this, R.color.cyanea_primary)));
|
2019-06-13 17:55:21 +02:00
|
|
|
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);
|
2020-03-08 09:15:12 +01:00
|
|
|
toolbar_close.setOnClickListener(v -> finish());
|
2019-06-14 19:31:51 +02:00
|
|
|
toolbar_title.setText(R.string.sign_up);
|
2019-06-13 17:55:21 +02:00
|
|
|
}
|
2019-06-14 14:36:13 +02:00
|
|
|
|
2019-06-14 19:31:51 +02:00
|
|
|
|
2019-11-20 10:31:33 +01:00
|
|
|
Spinner reg_category = findViewById(R.id.reg_category);
|
2019-06-14 16:01:58 +02:00
|
|
|
String[] categoriesA = {
|
|
|
|
getString(R.string.category_general),
|
|
|
|
getString(R.string.category_regional),
|
|
|
|
getString(R.string.category_art),
|
|
|
|
getString(R.string.category_journalism),
|
|
|
|
getString(R.string.category_activism),
|
|
|
|
"LGBTQ+",
|
|
|
|
getString(R.string.category_games),
|
|
|
|
getString(R.string.category_tech),
|
|
|
|
getString(R.string.category_adult),
|
|
|
|
getString(R.string.category_furry),
|
|
|
|
getString(R.string.category_food)
|
|
|
|
|
|
|
|
};
|
|
|
|
String[] itemA = {
|
|
|
|
"general",
|
|
|
|
"regional",
|
|
|
|
"art",
|
|
|
|
"journalism",
|
|
|
|
"activism",
|
|
|
|
"lgbt",
|
|
|
|
"games",
|
|
|
|
"tech",
|
|
|
|
"adult",
|
|
|
|
"furry",
|
|
|
|
"food",
|
|
|
|
};
|
2019-06-14 14:36:13 +02:00
|
|
|
ArrayAdapter<String> adcategories = new ArrayAdapter<>(MastodonRegisterActivity.this,
|
|
|
|
android.R.layout.simple_spinner_dropdown_item, categoriesA);
|
|
|
|
|
|
|
|
reg_category.setAdapter(adcategories);
|
|
|
|
|
2019-11-20 10:31:33 +01:00
|
|
|
reg_category.setSelection(0);
|
2019-06-14 14:36:13 +02:00
|
|
|
//Manage privacies
|
2019-11-20 10:31:33 +01:00
|
|
|
reg_category.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
2019-06-14 14:36:13 +02:00
|
|
|
@Override
|
2019-11-20 10:31:33 +01:00
|
|
|
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
2021-01-19 17:43:51 +01:00
|
|
|
new RetrieveInstanceRegAsyncTask(MastodonRegisterActivity.this, RetrieveInstanceRegAsyncTask.instanceType.MASTODON, itemA[position], MastodonRegisterActivity.this);
|
2019-11-20 10:31:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onNothingSelected(AdapterView<?> parent) {
|
2019-06-14 14:36:13 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-01-19 17:43:51 +01:00
|
|
|
new RetrieveInstanceRegAsyncTask(MastodonRegisterActivity.this, RetrieveInstanceRegAsyncTask.instanceType.MASTODON, "general", MastodonRegisterActivity.this);
|
2019-06-15 11:43:32 +02:00
|
|
|
|
|
|
|
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);
|
2019-06-15 12:49:38 +02:00
|
|
|
error_message = findViewById(R.id.error_message);
|
2019-06-15 11:43:32 +02:00
|
|
|
|
2019-09-06 17:55:14 +02:00
|
|
|
signup.setOnClickListener(view -> {
|
2019-06-15 12:49:38 +02:00
|
|
|
error_message.setVisibility(View.GONE);
|
2019-09-06 17:55:14 +02:00
|
|
|
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()) {
|
2020-04-08 12:42:15 +02:00
|
|
|
Toasty.error(MastodonRegisterActivity.this, getString(R.string.all_field_filled)).show();
|
2019-06-15 11:43:32 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-09-06 17:55:14 +02:00
|
|
|
if (!password.getText().toString().trim().equals(password_confirm.getText().toString().trim())) {
|
2020-04-08 12:42:15 +02:00
|
|
|
Toasty.error(MastodonRegisterActivity.this, getString(R.string.password_error)).show();
|
2019-06-15 11:43:32 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-09-06 17:55:14 +02:00
|
|
|
if (!android.util.Patterns.EMAIL_ADDRESS.matcher(email.getText().toString().trim()).matches()) {
|
2020-04-08 12:42:15 +02:00
|
|
|
Toasty.error(MastodonRegisterActivity.this, getString(R.string.email_error)).show();
|
2019-06-15 11:43:32 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-09-06 17:55:14 +02:00
|
|
|
if (password.getText().toString().trim().length() < 8) {
|
2020-04-08 12:42:15 +02:00
|
|
|
Toasty.error(MastodonRegisterActivity.this, getString(R.string.password_too_short)).show();
|
2019-06-15 11:43:32 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-09-06 17:55:14 +02:00
|
|
|
if (username.getText().toString().matches("[a-zA-Z0-9_]")) {
|
2020-04-08 12:42:15 +02:00
|
|
|
Toasty.error(MastodonRegisterActivity.this, getString(R.string.username_error)).show();
|
2019-06-15 11:43:32 +02:00
|
|
|
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());
|
2021-01-19 17:43:51 +01:00
|
|
|
new CreateMastodonAccountAsyncTask(MastodonRegisterActivity.this, RetrieveInstanceRegAsyncTask.instanceType.MASTODON, accountCreation, instance, MastodonRegisterActivity.this);
|
2019-06-15 11:43:32 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2019-06-13 17:55:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-09-06 17:55:14 +02:00
|
|
|
protected void onResume() {
|
2019-06-13 17:55:21 +02:00
|
|
|
super.onResume();
|
|
|
|
}
|
|
|
|
|
2019-06-14 14:36:13 +02:00
|
|
|
@Override
|
|
|
|
public void onRetrieveInstance(APIResponse apiResponse) {
|
2020-01-17 19:29:43 +01:00
|
|
|
if (apiResponse.getError() != null || apiResponse.getInstanceRegs() == null) {
|
2020-04-08 12:42:15 +02:00
|
|
|
Toasty.error(MastodonRegisterActivity.this, getString(R.string.toast_error_instance_reg), Toast.LENGTH_LONG).show();
|
2019-06-14 14:36:13 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
List<InstanceReg> instanceRegs = apiResponse.getInstanceRegs();
|
|
|
|
RecyclerView lv_instances = findViewById(R.id.reg_category_view);
|
|
|
|
InstanceRegAdapter instanceRegAdapter = new InstanceRegAdapter(MastodonRegisterActivity.this, instanceRegs);
|
|
|
|
LinearLayoutManager mLayoutManager = new LinearLayoutManager(MastodonRegisterActivity.this);
|
|
|
|
lv_instances.setLayoutManager(mLayoutManager);
|
|
|
|
lv_instances.setNestedScrollingEnabled(false);
|
|
|
|
lv_instances.setAdapter(instanceRegAdapter);
|
|
|
|
|
|
|
|
|
2019-06-14 19:31:51 +02:00
|
|
|
}
|
|
|
|
|
2019-09-06 17:55:14 +02:00
|
|
|
public void pickupInstance(String instance) {
|
2019-06-14 19:31:51 +02:00
|
|
|
|
2019-06-15 11:43:32 +02:00
|
|
|
checkInstance(MastodonRegisterActivity.this, instance);
|
2019-06-14 19:31:51 +02:00
|
|
|
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);
|
2019-06-15 11:43:32 +02:00
|
|
|
this.instance = instance;
|
2019-06-14 19:31:51 +02:00
|
|
|
|
|
|
|
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);
|
2019-11-10 14:39:26 +01:00
|
|
|
change.setSpan(new ForegroundColorSpan(ContextCompat.getColor(MastodonRegisterActivity.this, R.color.cyanea_accent_reference)), 0, change.length(),
|
2019-11-07 20:23:07 +01:00
|
|
|
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
|
|
|
|
2019-06-14 19:31:51 +02:00
|
|
|
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);
|
2019-06-15 11:43:32 +02:00
|
|
|
findViewById(R.id.invitation).setVisibility(View.GONE);
|
2019-06-14 19:31:51 +02:00
|
|
|
form_container.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
TextView agreement_text = findViewById(R.id.agreement_text);
|
|
|
|
|
2019-06-15 11:43:32 +02:00
|
|
|
TextView username_indicator = findViewById(R.id.username_indicator);
|
|
|
|
username_indicator.setText(getString(R.string.username_indicator, instance));
|
|
|
|
|
2019-06-14 19:31:51 +02:00
|
|
|
String tos = getString(R.string.tos);
|
|
|
|
String serverrules = getString(R.string.server_rules);
|
|
|
|
String content_agreement = getString(R.string.agreement_check,
|
2019-09-06 17:55:14 +02:00
|
|
|
"<a href='https://" + instance + "/about/more' >" + serverrules + "</a>",
|
|
|
|
"<a href='https://" + instance + "/terms' >" + tos + "</a>"
|
|
|
|
);
|
2019-06-14 19:31:51 +02:00
|
|
|
agreement_text.setMovementMethod(LinkMovementMethod.getInstance());
|
|
|
|
agreement_text.setText(Html.fromHtml(content_agreement));
|
2019-06-15 11:43:32 +02:00
|
|
|
}
|
|
|
|
|
2019-06-14 19:31:51 +02:00
|
|
|
|
2019-09-06 17:55:14 +02:00
|
|
|
private void checkInstance(Context context, String instance) {
|
2021-01-19 17:43:51 +01:00
|
|
|
new checkRegistration(context, instance);
|
2019-06-15 11:43:32 +02:00
|
|
|
}
|
2019-06-14 19:31:51 +02:00
|
|
|
|
2019-06-15 11:43:32 +02:00
|
|
|
@Override
|
|
|
|
public void onPostStatusAction(APIResponse apiResponse) {
|
2019-09-06 17:55:14 +02:00
|
|
|
if (apiResponse.getError() != null) {
|
2019-06-15 12:49:38 +02:00
|
|
|
String errorMessage;
|
2019-09-06 17:55:14 +02:00
|
|
|
if (apiResponse.getError().getError() != null) {
|
|
|
|
try {
|
2019-06-15 12:49:38 +02:00
|
|
|
String[] resp = apiResponse.getError().getError().split(":");
|
2019-09-06 17:55:14 +02:00
|
|
|
if (resp.length == 2)
|
2019-06-15 12:49:38 +02:00
|
|
|
errorMessage = apiResponse.getError().getError().split(":")[1];
|
2019-09-06 17:55:14 +02:00
|
|
|
else if (resp.length == 3)
|
2019-06-15 12:49:38 +02:00
|
|
|
errorMessage = apiResponse.getError().getError().split(":")[2];
|
|
|
|
else
|
|
|
|
errorMessage = getString(R.string.toast_error);
|
2019-09-06 17:55:14 +02:00
|
|
|
} catch (Exception e) {
|
2019-06-15 12:49:38 +02:00
|
|
|
errorMessage = getString(R.string.toast_error);
|
|
|
|
}
|
2019-09-06 17:55:14 +02:00
|
|
|
} else {
|
2019-06-15 12:49:38 +02:00
|
|
|
errorMessage = getString(R.string.toast_error);
|
2019-06-15 11:43:32 +02:00
|
|
|
}
|
2019-06-15 12:49:38 +02:00
|
|
|
error_message.setText(errorMessage);
|
|
|
|
error_message.setVisibility(View.VISIBLE);
|
2019-06-15 11:43:32 +02:00
|
|
|
signup.setEnabled(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
|
|
|
|
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
|
|
|
int style;
|
|
|
|
if (theme == Helper.THEME_DARK) {
|
|
|
|
style = R.style.DialogDark;
|
2019-09-06 17:55:14 +02:00
|
|
|
} else if (theme == Helper.THEME_BLACK) {
|
2019-06-15 11:43:32 +02:00
|
|
|
style = R.style.DialogBlack;
|
2019-09-06 17:55:14 +02:00
|
|
|
} else {
|
2019-06-15 11:43:32 +02:00
|
|
|
style = R.style.Dialog;
|
|
|
|
}
|
|
|
|
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(MastodonRegisterActivity.this, style);
|
|
|
|
dialogBuilder.setCancelable(false);
|
2020-03-08 09:15:12 +01:00
|
|
|
dialogBuilder.setPositiveButton(R.string.validate, (dialog, which) -> {
|
|
|
|
dialog.dismiss();
|
|
|
|
finish();
|
2019-06-15 11:43:32 +02:00
|
|
|
});
|
2019-06-15 12:49:38 +02:00
|
|
|
AlertDialog alertDialog = dialogBuilder.create();
|
|
|
|
alertDialog.setTitle(getString(R.string.account_created));
|
|
|
|
alertDialog.setMessage(getString(R.string.account_created_message, this.instance));
|
2019-06-15 11:43:32 +02:00
|
|
|
alertDialog.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-19 17:43:51 +01:00
|
|
|
private static class checkRegistration {
|
2019-06-15 11:43:32 +02:00
|
|
|
|
2021-01-10 18:41:50 +01:00
|
|
|
private final String instance;
|
|
|
|
private final WeakReference<Context> weakReference;
|
2019-06-15 11:43:32 +02:00
|
|
|
|
2019-09-06 17:55:14 +02:00
|
|
|
checkRegistration(Context context, String instance) {
|
2019-06-15 11:43:32 +02:00
|
|
|
this.instance = instance;
|
|
|
|
this.weakReference = new WeakReference<>(context);
|
2021-01-19 17:43:51 +01:00
|
|
|
doInBackground();
|
2019-06-15 11:43:32 +02:00
|
|
|
}
|
|
|
|
|
2021-01-19 17:43:51 +01:00
|
|
|
protected void doInBackground() {
|
|
|
|
new Thread(() -> {
|
|
|
|
String response = null;
|
|
|
|
try {
|
|
|
|
URL url = new URL("https://" + instance + "/auth/sign_up");
|
|
|
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
|
|
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
|
|
|
|
java.util.Scanner s = new java.util.Scanner(connection.getInputStream()).useDelimiter("\\A");
|
|
|
|
response = s.hasNext() ? s.next() : "";
|
|
|
|
}
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
2019-06-15 11:43:32 +02:00
|
|
|
}
|
2021-01-19 17:43:51 +01:00
|
|
|
Handler mainHandler = new Handler(Looper.getMainLooper());
|
|
|
|
String finalResponse = response;
|
|
|
|
Runnable myRunnable = () -> {
|
|
|
|
if (finalResponse != null && finalResponse.contains("invite_request_attributes")) {
|
|
|
|
TextView invitation = ((MastodonRegisterActivity) (weakReference.get())).findViewById(R.id.invitation);
|
|
|
|
if (invitation != null) {
|
|
|
|
invitation.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
mainHandler.post(myRunnable);
|
|
|
|
}).start();
|
2019-06-15 11:43:32 +02:00
|
|
|
}
|
|
|
|
|
2019-06-14 14:36:13 +02:00
|
|
|
}
|
2019-06-13 17:55:21 +02:00
|
|
|
}
|