diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9abf83c..4915f2a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -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" diff --git a/app/src/main/java/com/stormtales/notevault/MainActivity.java b/app/src/main/java/com/stormtales/notevault/MainActivity.java index b240b79..e22efed 100644 --- a/app/src/main/java/com/stormtales/notevault/MainActivity.java +++ b/app/src/main/java/com/stormtales/notevault/MainActivity.java @@ -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"); } } \ No newline at end of file diff --git a/app/src/main/java/com/stormtales/notevault/ui/login/LoginDialog.java b/app/src/main/java/com/stormtales/notevault/ui/login/LoginDialog.java new file mode 100644 index 0000000..b9af4d7 --- /dev/null +++ b/app/src/main/java/com/stormtales/notevault/ui/login/LoginDialog.java @@ -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(); + } + +} diff --git a/app/src/main/java/com/stormtales/notevault/ui/login/LoginViewModel.java b/app/src/main/java/com/stormtales/notevault/ui/login/LoginViewModel.java new file mode 100644 index 0000000..8169df4 --- /dev/null +++ b/app/src/main/java/com/stormtales/notevault/ui/login/LoginViewModel.java @@ -0,0 +1,6 @@ +package com.stormtales.notevault.ui.login; + +import androidx.lifecycle.ViewModel; + +public class LoginViewModel extends ViewModel { +} diff --git a/app/src/main/res/drawable/dialog_background.xml b/app/src/main/res/drawable/dialog_background.xml new file mode 100644 index 0000000..5b12544 --- /dev/null +++ b/app/src/main/res/drawable/dialog_background.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_login_dialog.xml b/app/src/main/res/layout/fragment_login_dialog.xml new file mode 100644 index 0000000..da64177 --- /dev/null +++ b/app/src/main/res/layout/fragment_login_dialog.xml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + +