Onboarding/signup improvements, also fixes #14

This commit is contained in:
Grishka 2022-04-15 08:19:59 +03:00
parent 3a9be88ce6
commit 3928eee1df
7 changed files with 55 additions and 6 deletions

View File

@ -283,9 +283,9 @@ public class SettingsFragment extends ToolbarFragment{
private void onLoggedOut(){
AccountSessionManager.getInstance().removeAccount(accountID);
getActivity().finish();
Intent intent=new Intent(getActivity(), MainActivity.class);
startActivity(intent);
getActivity().finish();
}
private void clearImageCache(){

View File

@ -21,6 +21,7 @@ import org.joinmastodon.android.api.requests.accounts.UpdateAccountCredentials;
import org.joinmastodon.android.api.session.AccountSession;
import org.joinmastodon.android.api.session.AccountSessionManager;
import org.joinmastodon.android.fragments.HomeFragment;
import org.joinmastodon.android.fragments.SettingsFragment;
import org.joinmastodon.android.model.Account;
import org.joinmastodon.android.ui.utils.UiUtils;
@ -57,6 +58,12 @@ public class AccountActivationFragment extends AppKitFragment{
btn=view.findViewById(R.id.btn_next);
btn.setOnClickListener(v->onButtonClick());
btn.setOnLongClickListener(v->{
Bundle args=new Bundle();
args.putString("account", accountID);
Nav.go(getActivity(), SettingsFragment.class, args);
return true;
});
buttonBar=view.findViewById(R.id.button_bar);
view.findViewById(R.id.btn_back).setOnClickListener(v->onBackButtonClick());

View File

@ -12,6 +12,7 @@ import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowInsets;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
@ -254,6 +255,7 @@ public class InstanceCatalogFragment extends BaseRecyclerFragment<CatalogInstanc
}
private void proceedWithAuthOrSignup(Instance instance){
getActivity().getSystemService(InputMethodManager.class).hideSoftInputFromWindow(contentView.getWindowToken(), 0);
if(isSignup){
Bundle args=new Bundle();
args.putParcelable("instance", Parcels.wrap(instance));

View File

@ -61,7 +61,8 @@ public class SignupFragment extends AppKitFragment{
private Instance instance;
private EditText displayName, username, email, password;
private EditText displayName, username, email, password, reason;
private TextView reasonExplain;
private Button btn;
private View buttonBar;
private TextWatcher buttonStateUpdater=new SimpleTextWatcher(e->updateButtonState());
@ -95,6 +96,8 @@ public class SignupFragment extends AppKitFragment{
email=view.findViewById(R.id.email);
password=view.findViewById(R.id.password);
avatar=view.findViewById(R.id.avatar);
reason=view.findViewById(R.id.reason);
reasonExplain=view.findViewById(R.id.reason_explain);
View avaWrap=view.findViewById(R.id.ava_wrap);
title.setText(getString(R.string.signup_title, instance.uri));
@ -118,15 +121,22 @@ public class SignupFragment extends AppKitFragment{
username.addTextChangedListener(buttonStateUpdater);
email.addTextChangedListener(buttonStateUpdater);
password.addTextChangedListener(buttonStateUpdater);
reason.addTextChangedListener(buttonStateUpdater);
username.addTextChangedListener(new ErrorClearingListener(username));
email.addTextChangedListener(new ErrorClearingListener(email));
password.addTextChangedListener(new ErrorClearingListener(password));
reason.addTextChangedListener(new ErrorClearingListener(reason));
avaWrap.setOutlineProvider(OutlineProviders.roundedRect(22));
avaWrap.setClipToOutline(true);
avaWrap.setOnClickListener(v->onAvatarClick());
if(!instance.approvalRequired){
reason.setVisibility(View.GONE);
reasonExplain.setVisibility(View.GONE);
}
return view;
}
@ -186,7 +196,7 @@ public class SignupFragment extends AppKitFragment{
edit.setError(null);
}
errorFields.clear();
new RegisterAccount(username, email, password.getText().toString(), getResources().getConfiguration().locale.getLanguage(), null)
new RegisterAccount(username, email, password.getText().toString(), getResources().getConfiguration().locale.getLanguage(), reason.getText().toString())
.setCallback(new Callback<>(){
@Override
public void onSuccess(Token result){
@ -209,10 +219,13 @@ public class SignupFragment extends AppKitFragment{
if(error instanceof MastodonDetailedErrorResponse){
Map<String, List<MastodonDetailedErrorResponse.FieldError>> fieldErrors=((MastodonDetailedErrorResponse) error).detailedErrors;
boolean first=true;
boolean anyFieldsSkipped=false;
for(String fieldName:fieldErrors.keySet()){
EditText field=getFieldByName(fieldName);
if(field==null)
if(field==null){
anyFieldsSkipped=true;
continue;
}
field.setError(fieldErrors.get(fieldName).stream().map(err->err.description).collect(Collectors.joining("\n")));
errorFields.add(field);
if(first){
@ -220,6 +233,8 @@ public class SignupFragment extends AppKitFragment{
field.requestFocus();
}
}
if(anyFieldsSkipped)
error.showToast(getActivity());
}else{
error.showToast(getActivity());
}
@ -235,6 +250,7 @@ public class SignupFragment extends AppKitFragment{
case "email" -> email;
case "username" -> username;
case "password" -> password;
case "reason" -> reason;
default -> null;
};
}
@ -247,7 +263,7 @@ public class SignupFragment extends AppKitFragment{
}
private void updateButtonState(){
btn.setEnabled(username.length()>0 && email.length()>0 && email.getText().toString().contains("@") && password.length()>=8);
btn.setEnabled(username.length()>0 && email.length()>0 && email.getText().toString().contains("@") && password.length()>=8 && (!instance.approvalRequired || reason.length()>0));
}
private void createAppAndGetToken(){

View File

@ -133,6 +133,28 @@
android:textColor="?android:textColorSecondary"
android:text="@string/password_note"/>
<EditText
android:id="@+id/reason"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:inputType="textCapSentences|textMultiLine"
android:hint="@string/signup_reason"/>
<TextView
android:id="@+id/reason_explain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
android:textAppearance="@style/m3_body_medium"
android:textColor="?android:textColorSecondary"
android:text="@string/signup_reason_note"/>
</LinearLayout>
</ScrollView>

View File

@ -46,7 +46,7 @@
android:id="@+id/search_edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textFilter"
android:inputType="textFilter|textNoSuggestions"
android:singleLine="true"
android:imeOptions="actionGo"
android:layout_marginLeft="16dp"

View File

@ -292,4 +292,6 @@
<string name="open_in_browser">Open in browser</string>
<string name="hide_boosts_from_user">Hide boosts from %s</string>
<string name="show_boosts_from_user">Show boosts from %s</string>
<string name="signup_reason">why do you want to join?</string>
<string name="signup_reason_note">This will help us review your application.</string>
</resources>