Tangyuan/app/build.gradle.kts
grtsinry43 46588259dd
feat: Implement user profile screen and enhance authentication
This commit introduces a dedicated user profile screen (`UserScreen`) and significantly enhances the authentication system by adding registration, auto-login, and robust form validation.

**Key Changes:**

*   **feat(UserScreen):**
    *   Added a new `UserScreen` to display the logged-in user's profile.
    *   Displays user details including avatar, nickname, ID, bio, location, and email in a styled card.
    *   Includes a menu section for actions like "Post Management," "Settings," and "About."
    *   Shows a "not logged in" state to prompt users to log in.

*   **feat(Auth):**
    *   **Registration:** Implemented a registration flow alongside the login flow on the `LoginScreen`. Users can now switch between Login and Register modes.
    *   **Auto-Login:** The app now automatically logs in the user on startup if a valid token or saved credentials exist, improving user experience.
    *   **Token Management:** Enhanced `TokenManager` to handle JWT parsing to extract `userId`, check token validity (expiration), and securely store credentials. Added `java-jwt` dependency for this.
    *   **Logout:** Improved the logout function to clear all stored tokens and user credentials from `SharedPreferences`.

*   **feat(Validation):**
    *   Introduced `ValidationUtils` to provide real-time validation for phone number, password, and nickname fields on the `LoginScreen`.
    *   Input fields now display specific error messages to guide the user (e.g., "Password must contain a letter," "Invalid phone number format").

*   **refactor(LoginScreen):**
    *   Redesigned the `LoginScreen` to support both login and registration (`AuthMode`) with animated transitions between modes and form fields.
    *   Form submission buttons are dynamically enabled based on validation results.
    *   After successful registration, the user is now automatically logged in.

*   **refactor(UserViewModel):**
    *   Integrated auto-login logic (`checkAutoLogin`) that runs on initialization.
    *   Refactored `login` and `register` flows to handle token storage and fetch user profile data immediately after authentication.
    *   Added `isLoggedIn()` to provide a reliable check of the current authentication state.

*   **refactor(TopBar):**
    *   The top bar avatar now correctly reflects the user's login state. It displays the user's avatar when logged in and a generic app icon when logged out.
    *   Clicking the avatar/icon now navigates to the `UserScreen` if logged in, or the `LoginScreen` if not.
2025-10-07 00:06:37 +08:00

96 lines
2.9 KiB
Plaintext

plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlin.compose)
alias(libs.plugins.hilt.android)
alias(libs.plugins.kotlin.kapt)
}
android {
namespace = "com.qingshuige.tangyuan"
compileSdk = 36
defaultConfig {
applicationId = "com.qingshuige.tangyuan"
minSdk = 24
targetSdk = 36
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
debug {
isMinifyEnabled = false
isDebuggable = true
}
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = "11"
}
buildFeatures {
compose = true
buildConfig = true
}
}
dependencies {
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.activity.compose)
implementation(platform(libs.androidx.compose.bom))
implementation(libs.androidx.ui)
implementation(libs.androidx.ui.graphics)
implementation(libs.androidx.ui.tooling.preview)
implementation(libs.androidx.material3)
implementation(libs.androidx.material.icons.core)
implementation(libs.androidx.material.icons.extended)
implementation(libs.coil.compose)
implementation(libs.androidx.navigation.compose)
// Network dependencies
implementation(libs.retrofit)
implementation(libs.retrofit.converter.gson)
implementation(libs.okhttp)
implementation(libs.okhttp.logging.interceptor)
implementation(libs.gson)
implementation(libs.androidx.security.crypto)
implementation(libs.androidx.datastore.preferences)
// JWT library
implementation(libs.java.jwt)
// Hilt dependencies
implementation(libs.hilt.android)
implementation(libs.ui.graphics)
implementation(libs.androidx.animation.core)
kapt(libs.hilt.compiler)
implementation(libs.androidx.hilt.navigation.compose)
// ViewModel and Lifecycle
implementation(libs.androidx.lifecycle.viewmodel.compose)
implementation(libs.androidx.lifecycle.viewmodel.ktx)
implementation(libs.pangu.jvm)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
androidTestImplementation(platform(libs.androidx.compose.bom))
androidTestImplementation(libs.androidx.ui.test.junit4)
debugImplementation(libs.androidx.ui.tooling)
debugImplementation(libs.androidx.ui.test.manifest)
}