summaryrefslogtreecommitdiffstats
path: root/app/src/main/java/app/fedilab/android/activities/MastodonRegisterActivity.java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/app/fedilab/android/activities/MastodonRegisterActivity.java')
-rw-r--r--app/src/main/java/app/fedilab/android/activities/MastodonRegisterActivity.java88
1 files changed, 45 insertions, 43 deletions
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 0b4865426..dfb06285a 100644
--- a/app/src/main/java/app/fedilab/android/activities/MastodonRegisterActivity.java
+++ b/app/src/main/java/app/fedilab/android/activities/MastodonRegisterActivity.java
@@ -40,13 +40,16 @@ 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 com.jaredrummler.materialspinner.MaterialSpinner;
+
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.net.HttpURLConnection;
@@ -85,7 +88,7 @@ public class MastodonRegisterActivity extends BaseActivity implements OnRetrieve
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
- switch (theme){
+ switch (theme) {
case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme);
break;
@@ -101,10 +104,10 @@ public class MastodonRegisterActivity extends BaseActivity implements OnRetrieve
setContentView(R.layout.activity_register);
ActionBar actionBar = getSupportActionBar();
- if( actionBar != null ) {
+ if (actionBar != null) {
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
assert inflater != null;
- @SuppressLint("InflateParams") View view = inflater.inflate(R.layout.simple_bar, 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);
@@ -116,14 +119,13 @@ public class MastodonRegisterActivity extends BaseActivity implements OnRetrieve
}
});
toolbar_title.setText(R.string.sign_up);
- if (theme == Helper.THEME_LIGHT){
+ if (theme == Helper.THEME_LIGHT) {
Toolbar toolbar = actionBar.getCustomView().findViewById(R.id.toolbar);
Helper.colorizeToolbar(toolbar, R.color.black, MastodonRegisterActivity.this);
}
}
-
MaterialSpinner reg_category = findViewById(R.id.reg_category);
Helper.changeMaterialSpinnerColor(MastodonRegisterActivity.this, reg_category);
String[] categoriesA = {
@@ -178,27 +180,27 @@ public class MastodonRegisterActivity extends BaseActivity implements OnRetrieve
CheckBox agreement = findViewById(R.id.agreement);
error_message = findViewById(R.id.error_message);
- signup.setOnClickListener(view->{
+ 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(MastodonRegisterActivity.this, getString(R.string.all_field_filled)).show();
+ 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(MastodonRegisterActivity.this, getString(R.string.password_error)).show();
+ 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(MastodonRegisterActivity.this, getString(R.string.email_error)).show();
+ 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(MastodonRegisterActivity.this, getString(R.string.password_too_short)).show();
+ 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(MastodonRegisterActivity.this, getString(R.string.username_error)).show();
+ if (username.getText().toString().matches("[a-zA-Z0-9_]")) {
+ Toasty.error(getApplicationContext(), getString(R.string.username_error)).show();
return;
}
signup.setEnabled(false);
@@ -214,14 +216,14 @@ public class MastodonRegisterActivity extends BaseActivity implements OnRetrieve
}
@Override
- protected void onResume(){
+ protected void onResume() {
super.onResume();
}
@Override
public void onRetrieveInstance(APIResponse apiResponse) {
- if( apiResponse.getError() != null ){
- Toasty.error(MastodonRegisterActivity.this, getString(R.string.toast_error_instance_reg), Toast.LENGTH_LONG).show();
+ if (apiResponse.getError() != null) {
+ Toasty.error(getApplicationContext(), getString(R.string.toast_error_instance_reg), Toast.LENGTH_LONG).show();
return;
}
List<InstanceReg> instanceRegs = apiResponse.getInstanceRegs();
@@ -235,7 +237,7 @@ public class MastodonRegisterActivity extends BaseActivity implements OnRetrieve
}
- public void pickupInstance(String instance){
+ public void pickupInstance(String instance) {
checkInstance(MastodonRegisterActivity.this, instance);
LinearLayout form_container = findViewById(R.id.form_container);
@@ -262,13 +264,13 @@ public class MastodonRegisterActivity extends BaseActivity implements OnRetrieve
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)
+ if (theme == Helper.THEME_DARK)
change.setSpan(new ForegroundColorSpan(ContextCompat.getColor(MastodonRegisterActivity.this, R.color.dark_link_toot)), 0, change.length(),
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
- else if( theme == Helper.THEME_BLACK)
+ else if (theme == Helper.THEME_BLACK)
change.setSpan(new ForegroundColorSpan(ContextCompat.getColor(MastodonRegisterActivity.this, R.color.black_link_toot)), 0, change.length(),
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
- else if( theme == Helper.THEME_LIGHT)
+ else if (theme == Helper.THEME_LIGHT)
change.setSpan(new ForegroundColorSpan(ContextCompat.getColor(MastodonRegisterActivity.this, R.color.mastodonC4)), 0, change.length(),
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
change_instance.setText(change);
@@ -295,35 +297,35 @@ public class MastodonRegisterActivity extends BaseActivity implements OnRetrieve
String tos = getString(R.string.tos);
String serverrules = getString(R.string.server_rules);
String content_agreement = getString(R.string.agreement_check,
- "<a href='https://" + instance + "/about/more' >"+serverrules +"</a>",
- "<a href='https://" + instance + "/terms' >"+tos +"</a>"
- );
+ "<a href='https://" + instance + "/about/more' >" + serverrules + "</a>",
+ "<a href='https://" + instance + "/terms' >" + tos + "</a>"
+ );
agreement_text.setMovementMethod(LinkMovementMethod.getInstance());
agreement_text.setText(Html.fromHtml(content_agreement));
}
- private void checkInstance(Context context, String instance){
+ private void checkInstance(Context context, String instance) {
new checkRegistration(context, instance).executeOnExecutor(THREAD_POOL_EXECUTOR);
}
@Override
public void onPostStatusAction(APIResponse apiResponse) {
- if( apiResponse.getError() != null){
+ if (apiResponse.getError() != null) {
String errorMessage;
- if( apiResponse.getError().getError() != null){
- try{
+ if (apiResponse.getError().getError() != null) {
+ try {
String[] resp = apiResponse.getError().getError().split(":");
- if( resp.length == 2)
+ if (resp.length == 2)
errorMessage = apiResponse.getError().getError().split(":")[1];
- else if( resp.length == 3)
+ else if (resp.length == 3)
errorMessage = apiResponse.getError().getError().split(":")[2];
else
errorMessage = getString(R.string.toast_error);
- }catch (Exception e){
+ } catch (Exception e) {
errorMessage = getString(R.string.toast_error);
}
- }else {
+ } else {
errorMessage = getString(R.string.toast_error);
}
error_message.setText(errorMessage);
@@ -336,16 +338,16 @@ public class MastodonRegisterActivity extends BaseActivity implements OnRetrieve
int style;
if (theme == Helper.THEME_DARK) {
style = R.style.DialogDark;
- } else if (theme == Helper.THEME_BLACK){
+ } else if (theme == Helper.THEME_BLACK) {
style = R.style.DialogBlack;
- }else {
+ } else {
style = R.style.Dialog;
}
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(MastodonRegisterActivity.this, style);
dialogBuilder.setCancelable(false);
dialogBuilder.setPositiveButton(R.string.validate, new DialogInterface.OnClickListener() {
@Override
- public void onClick(DialogInterface dialog,int which) {
+ public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
finish();
}
@@ -363,7 +365,7 @@ public class MastodonRegisterActivity extends BaseActivity implements OnRetrieve
private String instance;
private WeakReference<Context> weakReference;
- checkRegistration(Context context, String instance){
+ checkRegistration(Context context, String instance) {
this.instance = instance;
this.weakReference = new WeakReference<>(context);
}
@@ -376,7 +378,7 @@ public class MastodonRegisterActivity extends BaseActivity implements OnRetrieve
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() : "";
+ response = s.hasNext() ? s.next() : "";
}
} catch (IOException e) {
e.printStackTrace();
@@ -388,9 +390,9 @@ public class MastodonRegisterActivity extends BaseActivity implements OnRetrieve
protected void onPostExecute(String result) {
- if( result != null && result.contains("invite_request_attributes")){
- TextView invitation = ((MastodonRegisterActivity)(weakReference.get())).findViewById(R.id.invitation);
- if( invitation != null){
+ if (result != null && result.contains("invite_request_attributes")) {
+ TextView invitation = ((MastodonRegisterActivity) (weakReference.get())).findViewById(R.id.invitation);
+ if (invitation != null) {
invitation.setVisibility(View.VISIBLE);
}
}