forked from organicmaps/organicmaps
Code formatting
Signed-off-by: Sergiy Kozyr <s.trump@gmail.com>
This commit is contained in:
parent
6371fe09ef
commit
7b2fedb93a
4 changed files with 190 additions and 182 deletions
|
@ -26,91 +26,99 @@ import app.organicmaps.util.concurrency.UiThread;
|
|||
|
||||
public class OsmLoginBottomFragment extends BottomSheetDialogFragment
|
||||
{
|
||||
final private OsmLoginFragment parentFragment;
|
||||
private TextInputEditText mLoginInput;
|
||||
private TextInputEditText mPasswordInput;
|
||||
private Button mLoginButton;
|
||||
private Button mLostPasswordButton;
|
||||
private Button mRegisterButton;
|
||||
private ProgressBar mProgress;
|
||||
final private OsmLoginFragment parentFragment;
|
||||
private TextInputEditText mLoginInput;
|
||||
private TextInputEditText mPasswordInput;
|
||||
private Button mLoginButton;
|
||||
private Button mLostPasswordButton;
|
||||
private Button mRegisterButton;
|
||||
private ProgressBar mProgress;
|
||||
|
||||
public OsmLoginBottomFragment(OsmLoginFragment parentFragment) {
|
||||
super();
|
||||
this.parentFragment = parentFragment;
|
||||
}
|
||||
public OsmLoginBottomFragment(OsmLoginFragment parentFragment)
|
||||
{
|
||||
super();
|
||||
this.parentFragment = parentFragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.fragment_osm_login_bottom, container, false);
|
||||
}
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
|
||||
{
|
||||
return inflater.inflate(R.layout.fragment_osm_login_bottom, container, false);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
BottomSheetDialog dialog = (BottomSheetDialog) super.onCreateDialog(savedInstanceState);
|
||||
dialog.getBehavior().setState(BottomSheetBehavior.STATE_EXPANDED);
|
||||
return dialog;
|
||||
}
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState)
|
||||
{
|
||||
BottomSheetDialog dialog = (BottomSheetDialog) super.onCreateDialog(savedInstanceState);
|
||||
dialog.getBehavior().setState(BottomSheetBehavior.STATE_EXPANDED);
|
||||
return dialog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
mLoginInput = view.findViewById(R.id.osm_username);
|
||||
mPasswordInput = view.findViewById(R.id.osm_password);
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState)
|
||||
{
|
||||
mLoginInput = view.findViewById(R.id.osm_username);
|
||||
mPasswordInput = view.findViewById(R.id.osm_password);
|
||||
|
||||
mLoginButton = view.findViewById(R.id.login);
|
||||
mLoginButton.setOnClickListener((v) -> doLogin());
|
||||
mLoginButton = view.findViewById(R.id.login);
|
||||
mLoginButton.setOnClickListener((v) -> doLogin());
|
||||
|
||||
mLostPasswordButton = view.findViewById(R.id.lost_password);
|
||||
mLostPasswordButton.setOnClickListener((v) -> Utils.openUrl(requireActivity(), Constants.Url.OSM_RECOVER_PASSWORD));
|
||||
mRegisterButton = view.findViewById(R.id.register);
|
||||
mRegisterButton.setOnClickListener((v) -> Utils.openUrl(requireActivity(), Constants.Url.OSM_REGISTER));
|
||||
mProgress = view.findViewById(R.id.osm_login_progress);
|
||||
}
|
||||
mLostPasswordButton = view.findViewById(R.id.lost_password);
|
||||
mLostPasswordButton.setOnClickListener((v) -> Utils.openUrl(requireActivity(), Constants.Url.OSM_RECOVER_PASSWORD));
|
||||
mRegisterButton = view.findViewById(R.id.register);
|
||||
mRegisterButton.setOnClickListener((v) -> Utils.openUrl(requireActivity(), Constants.Url.OSM_REGISTER));
|
||||
mProgress = view.findViewById(R.id.osm_login_progress);
|
||||
}
|
||||
|
||||
private void doLogin() {
|
||||
InputUtils.hideKeyboard(mLoginInput);
|
||||
final String username = mLoginInput.getText().toString().trim();
|
||||
final String password = mPasswordInput.getText().toString();
|
||||
enableInput(false);
|
||||
UiUtils.show(mProgress);
|
||||
mLoginButton.setText("");
|
||||
private void doLogin()
|
||||
{
|
||||
InputUtils.hideKeyboard(mLoginInput);
|
||||
final String username = mLoginInput.getText().toString().trim();
|
||||
final String password = mPasswordInput.getText().toString();
|
||||
enableInput(false);
|
||||
UiUtils.show(mProgress);
|
||||
mLoginButton.setText("");
|
||||
|
||||
ThreadPool.getWorker().execute(() -> {
|
||||
final String oauthToken = OsmOAuth.nativeAuthWithPassword(username, password);
|
||||
final String username1 = (oauthToken == null) ? null : OsmOAuth.nativeGetOsmUsername(oauthToken);
|
||||
UiThread.run(() -> processAuth(oauthToken, username1));
|
||||
});
|
||||
}
|
||||
|
||||
private void processAuth(String oauthToken, String username)
|
||||
ThreadPool.getWorker().execute(() ->
|
||||
{
|
||||
if (!isAdded())
|
||||
return;
|
||||
final String oauthToken = OsmOAuth.nativeAuthWithPassword(username, password);
|
||||
final String username1 = (oauthToken == null) ? null : OsmOAuth.nativeGetOsmUsername(oauthToken);
|
||||
UiThread.run(() -> processAuth(oauthToken, username1));
|
||||
});
|
||||
}
|
||||
|
||||
enableInput(true);
|
||||
UiUtils.hide(mProgress);
|
||||
mLoginButton.setText(R.string.login_osm);
|
||||
private void processAuth(String oauthToken, String username)
|
||||
{
|
||||
if (!isAdded())
|
||||
return;
|
||||
|
||||
if (oauthToken == null)
|
||||
parentFragment.onAuthFail();
|
||||
else {
|
||||
this.dismiss();
|
||||
parentFragment.onAuthSuccess(oauthToken, username);
|
||||
}
|
||||
}
|
||||
enableInput(true);
|
||||
UiUtils.hide(mProgress);
|
||||
mLoginButton.setText(R.string.login_osm);
|
||||
|
||||
private void enableInput(boolean enable)
|
||||
if (oauthToken == null)
|
||||
parentFragment.onAuthFail();
|
||||
else
|
||||
{
|
||||
mPasswordInput.setEnabled(enable);
|
||||
mLoginInput.setEnabled(enable);
|
||||
mLoginButton.setEnabled(enable);
|
||||
mLostPasswordButton.setEnabled(enable);
|
||||
mRegisterButton.setEnabled(enable);
|
||||
this.dismiss();
|
||||
parentFragment.onAuthSuccess(oauthToken, username);
|
||||
}
|
||||
}
|
||||
|
||||
private void enableInput(boolean enable)
|
||||
{
|
||||
mPasswordInput.setEnabled(enable);
|
||||
mLoginInput.setEnabled(enable);
|
||||
mLoginButton.setEnabled(enable);
|
||||
mLostPasswordButton.setEnabled(enable);
|
||||
mRegisterButton.setEnabled(enable);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,41 +22,41 @@
|
|||
android:padding="@dimen/margin_base"
|
||||
tools:ignore="ScrollViewSize">
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/margin_half">
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/margin_half">
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/osm_username_container"
|
||||
style="@style/MwmWidget.Editor.CustomTextInput"
|
||||
android:layout_width="0dp"
|
||||
android:layout_marginEnd="@dimen/margin_half"
|
||||
android:textColorHint="?android:textColorSecondary"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@id/osm_password_container"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:endIconMode="custom">
|
||||
android:id="@+id/osm_username_container"
|
||||
style="@style/MwmWidget.Editor.CustomTextInput"
|
||||
android:layout_width="0dp"
|
||||
android:layout_marginEnd="@dimen/margin_half"
|
||||
android:textColorHint="?android:textColorSecondary"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@id/osm_password_container"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:endIconMode="custom">
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/osm_username"
|
||||
style="@style/MwmWidget.Editor.FieldLayout.EditText"
|
||||
android:autofillHints="emailAddress"
|
||||
android:hint="@string/email_or_username" />
|
||||
android:id="@+id/osm_username"
|
||||
style="@style/MwmWidget.Editor.FieldLayout.EditText"
|
||||
android:autofillHints="emailAddress"
|
||||
android:hint="@string/email_or_username" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/osm_password_container"
|
||||
style="@style/MwmWidget.Editor.CustomTextInput"
|
||||
android:layout_width="0dp"
|
||||
android:textColorHint="?android:textColorSecondary"
|
||||
app:layout_constraintStart_toEndOf="@id/osm_username_container"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:endIconMode="password_toggle"
|
||||
app:endIconTint="?android:textColorSecondary">
|
||||
android:id="@+id/osm_password_container"
|
||||
style="@style/MwmWidget.Editor.CustomTextInput"
|
||||
android:layout_width="0dp"
|
||||
android:textColorHint="?android:textColorSecondary"
|
||||
app:layout_constraintStart_toEndOf="@id/osm_username_container"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:endIconMode="password_toggle"
|
||||
app:endIconTint="?android:textColorSecondary">
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/osm_password"
|
||||
style="@style/MwmWidget.Editor.FieldLayout.EditText"
|
||||
android:autofillHints="password"
|
||||
android:hint="@string/password"
|
||||
android:inputType="textPassword" />
|
||||
android:id="@+id/osm_password"
|
||||
style="@style/MwmWidget.Editor.FieldLayout.EditText"
|
||||
android:autofillHints="password"
|
||||
android:hint="@string/password"
|
||||
android:inputType="textPassword" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
|
@ -71,7 +71,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Login with username"
|
||||
android:layout_marginTop="@dimen/margin_half"
|
||||
android:layout_marginTop="@dimen/margin_half"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body2.Light" />
|
||||
<ProgressBar
|
||||
android:id="@+id/osm_login_progress"
|
||||
|
@ -83,32 +83,32 @@
|
|||
</FrameLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginTop="@dimen/margin_base">
|
||||
<Button
|
||||
android:id="@+id/lost_password"
|
||||
style="@style/MwmWidget.Button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginTop="@dimen/margin_base">
|
||||
android:layout_gravity="start"
|
||||
android:layout_weight="1"
|
||||
android:background="?clickableBackground"
|
||||
android:padding="@dimen/margin_quarter"
|
||||
android:text="@string/forgot_password"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body3" />
|
||||
<Button
|
||||
android:id="@+id/lost_password"
|
||||
style="@style/MwmWidget.Button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="start"
|
||||
android:layout_weight="1"
|
||||
android:background="?clickableBackground"
|
||||
android:padding="@dimen/margin_quarter"
|
||||
android:text="@string/forgot_password"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body3" />
|
||||
<Button
|
||||
android:id="@+id/register"
|
||||
style="@style/MwmWidget.Button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_gravity="end"
|
||||
android:background="?clickableBackground"
|
||||
android:padding="@dimen/margin_quarter"
|
||||
android:text="@string/register_at_openstreetmap"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body3" />
|
||||
android:id="@+id/register"
|
||||
style="@style/MwmWidget.Button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_gravity="end"
|
||||
android:background="?clickableBackground"
|
||||
android:padding="@dimen/margin_quarter"
|
||||
android:text="@string/register_at_openstreetmap"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body3" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
|
|
@ -61,13 +61,13 @@
|
|||
android:textAppearance="@style/MwmTextAppearance.Body2"
|
||||
android:textColor="?android:textColorPrimary" />
|
||||
<Button
|
||||
android:id="@+id/login_website"
|
||||
style="@style/MwmWidget.Button.Accent"
|
||||
android:layout_marginTop="@dimen/margin_base"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Login with OSM website"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body2.Light" />
|
||||
android:id="@+id/login_website"
|
||||
style="@style/MwmWidget.Button.Accent"
|
||||
android:layout_marginTop="@dimen/margin_base"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Login with OSM website"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body2.Light" />
|
||||
<Button
|
||||
android:id="@+id/login_username"
|
||||
style="@style/MwmWidget.Button.Accent"
|
||||
|
|
|
@ -22,35 +22,35 @@
|
|||
android:padding="@dimen/margin_base"
|
||||
tools:ignore="ScrollViewSize">
|
||||
<LinearLayout
|
||||
android:id="@+id/login_bottom_sheet"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
android:id="@+id/login_bottom_sheet"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
style="@style/MwmWidget.Editor.CustomTextInput"
|
||||
android:layout_marginTop="@dimen/margin_half"
|
||||
android:textColorHint="?android:textColorSecondary"
|
||||
app:endIconMode="custom">
|
||||
style="@style/MwmWidget.Editor.CustomTextInput"
|
||||
android:layout_marginTop="@dimen/margin_half"
|
||||
android:textColorHint="?android:textColorSecondary"
|
||||
app:endIconMode="custom">
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/osm_username"
|
||||
style="@style/MwmWidget.Editor.FieldLayout.EditText"
|
||||
android:padding="@dimen/margin_half_double_plus"
|
||||
android:autofillHints="emailAddress"
|
||||
android:hint="@string/email_or_username" />
|
||||
android:id="@+id/osm_username"
|
||||
style="@style/MwmWidget.Editor.FieldLayout.EditText"
|
||||
android:padding="@dimen/margin_half_double_plus"
|
||||
android:autofillHints="emailAddress"
|
||||
android:hint="@string/email_or_username" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
style="@style/MwmWidget.Editor.CustomTextInput"
|
||||
android:textColorHint="?android:textColorSecondary"
|
||||
app:endIconMode="password_toggle"
|
||||
app:endIconTint="?android:textColorSecondary">
|
||||
style="@style/MwmWidget.Editor.CustomTextInput"
|
||||
android:textColorHint="?android:textColorSecondary"
|
||||
app:endIconMode="password_toggle"
|
||||
app:endIconTint="?android:textColorSecondary">
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/osm_password"
|
||||
style="@style/MwmWidget.Editor.FieldLayout.EditText"
|
||||
android:padding="@dimen/margin_half_double_plus"
|
||||
android:autofillHints="password"
|
||||
android:hint="@string/password"
|
||||
android:inputType="textPassword" />
|
||||
android:id="@+id/osm_password"
|
||||
style="@style/MwmWidget.Editor.FieldLayout.EditText"
|
||||
android:padding="@dimen/margin_half_double_plus"
|
||||
android:autofillHints="password"
|
||||
android:hint="@string/password"
|
||||
android:inputType="textPassword" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
</LinearLayout>
|
||||
|
||||
|
@ -64,7 +64,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Login with username"
|
||||
android:layout_marginTop="@dimen/margin_half"
|
||||
android:layout_marginTop="@dimen/margin_half"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body2.Light" />
|
||||
<ProgressBar
|
||||
android:id="@+id/osm_login_progress"
|
||||
|
@ -76,32 +76,32 @@
|
|||
</FrameLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginTop="@dimen/margin_base">
|
||||
<Button
|
||||
android:id="@+id/lost_password"
|
||||
style="@style/MwmWidget.Button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginTop="@dimen/margin_base">
|
||||
android:layout_gravity="start"
|
||||
android:layout_weight="1"
|
||||
android:background="?clickableBackground"
|
||||
android:padding="@dimen/margin_quarter"
|
||||
android:text="@string/forgot_password"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body3" />
|
||||
<Button
|
||||
android:id="@+id/lost_password"
|
||||
style="@style/MwmWidget.Button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="start"
|
||||
android:layout_weight="1"
|
||||
android:background="?clickableBackground"
|
||||
android:padding="@dimen/margin_quarter"
|
||||
android:text="@string/forgot_password"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body3" />
|
||||
<Button
|
||||
android:id="@+id/register"
|
||||
style="@style/MwmWidget.Button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_gravity="end"
|
||||
android:background="?clickableBackground"
|
||||
android:padding="@dimen/margin_quarter"
|
||||
android:text="@string/register_at_openstreetmap"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body3" />
|
||||
android:id="@+id/register"
|
||||
style="@style/MwmWidget.Button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_gravity="end"
|
||||
android:background="?clickableBackground"
|
||||
android:padding="@dimen/margin_quarter"
|
||||
android:text="@string/register_at_openstreetmap"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body3" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
|
Loading…
Add table
Reference in a new issue