Call Login API
This commit is contained in:
parent
46852a9b5a
commit
7aa30fd4d7
@ -6,6 +6,7 @@
|
||||
android:allowBackup="true"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
android:fullBackupContent="@xml/backup_rules"
|
||||
android:networkSecurityConfig="@xml/network_security_config"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
|
@ -11,7 +11,9 @@ import androidx.navigation.ui.NavigationUI;
|
||||
import androidx.drawerlayout.widget.DrawerLayout;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import com.stormtales.notevault.databinding.ActivityMainBinding;
|
||||
import com.stormtales.notevault.network.APICallback;
|
||||
import com.stormtales.notevault.network.auth.AuthService;
|
||||
import com.stormtales.notevault.ui.login.LoginDialog;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
@ -76,7 +78,27 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
public void showLoginDialog() {
|
||||
/*LoginFragment loginFragment = new LoginFragment();
|
||||
loginFragment.show(getSupportFragmentManager(), "login");*/
|
||||
LoginDialog loginDialog = LoginDialog.newInstance(new APICallback() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(String error) {
|
||||
|
||||
}
|
||||
}, new APICallback() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(String error) {
|
||||
|
||||
}
|
||||
});
|
||||
loginDialog.show(getSupportFragmentManager(), "login");
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
package com.stormtales.notevault.ui.login;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import com.stormtales.notevault.R;
|
||||
import com.stormtales.notevault.network.APICallback;
|
||||
import com.stormtales.notevault.network.auth.AuthService;
|
||||
|
||||
public class LoginDialog extends DialogFragment {
|
||||
|
||||
private APICallback loginCallback;
|
||||
private APICallback registerCallback;
|
||||
|
||||
private boolean isLoginMode = true;
|
||||
|
||||
private Dialog dialog;
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
if (loginCallback == null) {
|
||||
throw new IllegalStateException("LoginDialogFragment must be created using newInstance()");
|
||||
}
|
||||
}
|
||||
|
||||
public static LoginDialog newInstance(APICallback loginCallback, APICallback registerCallback) {
|
||||
LoginDialog fragment = new LoginDialog();
|
||||
fragment.loginCallback = loginCallback;
|
||||
fragment.registerCallback = registerCallback;
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(requireContext());
|
||||
LayoutInflater inflater = requireActivity().getLayoutInflater();
|
||||
View view = inflater.inflate(R.layout.fragment_login_dialog, null);
|
||||
|
||||
TextView textViewTitle = view.findViewById(R.id.textViewTitle);
|
||||
EditText editTextUsername = view.findViewById(R.id.editTextUsername);
|
||||
EditText editTextEmail = view.findViewById(R.id.editTextEmail);
|
||||
EditText editTextPassword = view.findViewById(R.id.editTextPassword);
|
||||
Button buttonAction = view.findViewById(R.id.buttonAction);
|
||||
TextView textViewSwitch = view.findViewById(R.id.textViewSwitch);
|
||||
|
||||
// Handle action button click
|
||||
buttonAction.setOnClickListener(v -> {
|
||||
if (isLoginMode) {
|
||||
// Handle login logic
|
||||
String email = editTextEmail.getText().toString();
|
||||
String password = editTextPassword.getText().toString();
|
||||
AuthService authRepository = new AuthService(this.getContext());
|
||||
authRepository.performLogin(email, password, loginCallback);
|
||||
} else {
|
||||
// Handle registration logic
|
||||
String email = editTextEmail.getText().toString();
|
||||
String password = editTextPassword.getText().toString();
|
||||
String username = editTextUsername.getText().toString();
|
||||
AuthService authRepository = new AuthService(this.getContext());
|
||||
authRepository.performRegistration(email, username, password, registerCallback);
|
||||
}
|
||||
});
|
||||
|
||||
// Toggle between Login and Registration
|
||||
textViewSwitch.setOnClickListener(v -> {
|
||||
isLoginMode = !isLoginMode;
|
||||
textViewTitle.setText(isLoginMode ? "Login" : "Register");
|
||||
editTextUsername.setVisibility(isLoginMode ? View.GONE : View.VISIBLE);
|
||||
buttonAction.setText(isLoginMode ? "Login" : "Register");
|
||||
textViewSwitch.setText(isLoginMode ? "Don't have an account? Register" : "Already have an account? Login");
|
||||
});
|
||||
|
||||
builder.setView(view);
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package com.stormtales.notevault.ui.login;
|
||||
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
public class LoginViewModel extends ViewModel {
|
||||
}
|
6
app/src/main/res/drawable/dialog_background.xml
Normal file
6
app/src/main/res/drawable/dialog_background.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<solid android:color="@android:color/white" />
|
||||
<corners android:radius="16dp" />
|
||||
<padding android:left="16dp" android:top="16dp" android:right="16dp" android:bottom="16dp" />
|
||||
<elevation android:height="4dp" />
|
||||
</shape>
|
68
app/src/main/res/layout/fragment_login_dialog.xml
Normal file
68
app/src/main/res/layout/fragment_login_dialog.xml
Normal file
@ -0,0 +1,68 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp"
|
||||
android:background="@drawable/dialog_background"
|
||||
android:layout_gravity="center_horizontal">
|
||||
|
||||
<!-- Title -->
|
||||
<TextView
|
||||
android:id="@+id/textViewTitle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Login"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold"
|
||||
android:gravity="center"
|
||||
android:paddingBottom="16dp" />
|
||||
|
||||
<!-- Username Field (Visible only in Registration mode) -->
|
||||
<EditText
|
||||
android:id="@+id/editTextUsername"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="Username"
|
||||
android:visibility="gone" />
|
||||
|
||||
<!-- Email Field -->
|
||||
<EditText
|
||||
android:id="@+id/editTextEmail"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="Email"
|
||||
android:inputType="textEmailAddress" />
|
||||
|
||||
<!-- Password Field -->
|
||||
<EditText
|
||||
android:id="@+id/editTextPassword"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="Password"
|
||||
android:inputType="textPassword" />
|
||||
|
||||
<!-- Action Button -->
|
||||
<Button
|
||||
android:id="@+id/buttonAction"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Login"
|
||||
android:backgroundTint="?attr/colorPrimary"
|
||||
android:textColor="@android:color/white"
|
||||
android:layout_marginTop="16dp" />
|
||||
|
||||
<!-- Toggle Login/Registration -->
|
||||
<TextView
|
||||
android:id="@+id/textViewSwitch"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Don't have an account? Register"
|
||||
android:gravity="center"
|
||||
android:textColor="?attr/colorPrimary"
|
||||
android:layout_marginTop="8dp"
|
||||
android:padding="8dp"
|
||||
android:clickable="true"
|
||||
android:focusable="true" />
|
||||
|
||||
</LinearLayout>
|
6
app/src/main/res/xml/network_security_config.xml
Normal file
6
app/src/main/res/xml/network_security_config.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<network-security-config>
|
||||
<domain-config cleartextTrafficPermitted="true">
|
||||
<domain includeSubdomains="true">192.168.178.30</domain>
|
||||
</domain-config>
|
||||
</network-security-config>
|
Loading…
Reference in New Issue
Block a user