Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions .idea/deploymentTargetSelector.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ configurations.all {
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
id("com.google.gms.google-services")
id("com.google.gms.google-services") version "4.4.2" apply false
}

android {
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
>

<activity
android:name=".MainActivity"
android:name=".LoginActivity"
android:exported="true"
android:label="@string/app_name">
<intent-filter>
Expand All @@ -33,6 +33,11 @@
</intent-filter>
</activity>



<activity
android:name=".MainActivity"
android:exported="false" />
<service
android:name=".MyFirebaseMessagingService"
android:exported="false">
Expand Down
17 changes: 17 additions & 0 deletions app/src/main/java/com/example/iamhere/LoginActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.example.iamhere

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.example.iamhere.ui.login.LoginFragment

class LoginActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_login) // 로그인 레이아웃 연결

// 처음 실행 시 LoginFragment 띄우기
supportFragmentManager.beginTransaction()
.replace(R.id.fragment_container, LoginFragment())
.commit()
}
}
3 changes: 3 additions & 0 deletions app/src/main/java/com/example/iamhere/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class MainActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)



Log.d("MainActivity", "MainActivity 실행됨")
val navView = findViewById<BottomNavigationView>(R.id.nav_view)
val navHostFragment = supportFragmentManager
.findFragmentById(R.id.nav_host_fragment_activity_main) as NavHostFragment
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/com/example/iamhere/model/LoginRequest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.iamhere.model

data class LoginRequest(
val login_id: String,
val password: String,
val userType: String
)
20 changes: 20 additions & 0 deletions app/src/main/java/com/example/iamhere/model/LoginResponse.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.example.iamhere.model

import com.google.gson.annotations.SerializedName

data class LoginResponse(
@SerializedName("access_token")
val accessToken: String,

@SerializedName("token_type")
val tokenType: String,

@SerializedName("user_name")
val userName: String,

@SerializedName("user_id") //not login_id!
val userId: String,

@SerializedName("today_attendance")
val today_attendance: TodayLecture? // Optional 처리
)
14 changes: 14 additions & 0 deletions app/src/main/java/com/example/iamhere/network/LoginApi.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.example.iamhere.network

import com.example.iamhere.model.LoginRequest
import com.example.iamhere.model.LoginResponse
import retrofit2.Call

import retrofit2.http.Body
import retrofit2.http.POST

interface LoginApi {
@POST("login") // 실제 서버 주소 경로에 맞게 수정
suspend fun login(@Body request: LoginRequest): LoginResponse //suspend로 비동기 처리

}
12 changes: 12 additions & 0 deletions app/src/main/java/com/example/iamhere/network/RetrofitClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,25 @@ import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

object RetrofitClient {

private const val BASE_URL = "http://34.64.121.178:8000/" // ← 예시 GCP IP

//private const val BASE_URL = "http://10.0.2.2:8000/" //실제 디바이스의 경우 네트워크의 로컬 ip가필요
//private const val BASE_URL = "http://192.168.219.109:8000/"

val attendanceApi: AttendanceApi by lazy {
Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build()
.create(AttendanceApi::class.java)
}
// loginApi 초기화
val loginApi: LoginApi by lazy {
Retrofit.Builder() // Retrofit 객체 다시 생성
.baseUrl(BASE_URL) // 기본 URL 설정
.addConverterFactory(GsonConverterFactory.create()) // GsonConverterFactory 추가
.build()
.create(LoginApi::class.java) // LoginApi 인터페이스 구현
}
}
96 changes: 96 additions & 0 deletions app/src/main/java/com/example/iamhere/ui/login/LoginFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package com.example.iamhere.ui.login

import android.annotation.SuppressLint
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.EditText
import android.widget.Toast
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import com.example.iamhere.R
import android.content.Intent
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope

import com.example.iamhere.MainActivity
import com.example.iamhere.model.LoginRequest
import com.example.iamhere.model.LoginResponse
import com.example.iamhere.network.RetrofitClient
import kotlinx.coroutines.launch
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response

class LoginFragment : Fragment() {

private val viewModel: LoginViewModel by viewModels()

@SuppressLint("MissingInflatedId")
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
val view = inflater.inflate(R.layout.fragment_login, container, false)

val studentButton = view.findViewById<Button>(R.id.studentButton)
val professorButton = view.findViewById<Button>(R.id.professorButton)
val loginButton = view.findViewById<Button>(R.id.loginButton)

val idEditText = view.findViewById<EditText>(R.id.editTextId)
val pwEditText = view.findViewById<EditText>(R.id.editTextPassword)

studentButton.setOnClickListener {
viewModel.setUserType("학생")
Toast.makeText(context, "학생 로그인 선택됨", Toast.LENGTH_SHORT).show()
}

professorButton.setOnClickListener {
viewModel.setUserType("교수")
Toast.makeText(context, "교수 로그인 선택됨", Toast.LENGTH_SHORT).show()
}

loginButton.setOnClickListener {
Log.d("LoginFragment", "로그인 버튼 눌림")
val id = idEditText.text.toString().trim()
val pw = pwEditText.text.toString().trim()
val userType = viewModel.userType.value ?: "학생"

val loginRequest = LoginRequest(id, pw,userType)

lifecycleScope.launch {
try {
val response = RetrofitClient.loginApi.login(loginRequest) // suspend 함수 호출
val token = response.accessToken
if (token != null) {
// 토큰 저장
val prefs = requireContext().getSharedPreferences(
"auth",
AppCompatActivity.MODE_PRIVATE
)
prefs.edit().putString("access_token", token).apply()

Toast.makeText(context, "$userType 로그인 성공", Toast.LENGTH_SHORT).show()

// MainActivity 등으로 이동
val intent = Intent(requireContext(), MainActivity::class.java)
startActivity(intent)
requireActivity().finish()
} else {
Toast.makeText(context, "토큰이 없습니다", Toast.LENGTH_SHORT).show()
}
} catch (e: Exception) {
Toast.makeText(context, "로그인 실패: ${e.message}", Toast.LENGTH_SHORT).show()
}
}
}

return view
}
}



14 changes: 14 additions & 0 deletions app/src/main/java/com/example/iamhere/ui/login/LoginViewModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.example.iamhere.ui.login

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel

class LoginViewModel : ViewModel() {
private val _userType = MutableLiveData("학생") // 기본값: 학생
val userType: LiveData<String> = _userType

fun setUserType(type: String) {
_userType.value = type
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.example.iamhere.ui.mypage;

import androidx.fragment.app.Fragment;

public class MypageFragment extends Fragment {
}
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class NotificationsFragment : Fragment() {
super.onViewCreated(view, savedInstanceState)

val retrofit = Retrofit.Builder()
.baseUrl("http://34.64.206.110:8000/") // ✅ 실제 서버 주소로 수정
.baseUrl("http://34.64.121.178:8000/") // ✅ 실제 서버 주소로 수정
.addConverterFactory(GsonConverterFactory.create())
.build()

Expand Down
18 changes: 18 additions & 0 deletions app/src/main/res/drawable/professor_button_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<!-- 전체 배경 (흰색 or 투명) -->
<item>
<shape android:shape="rectangle">
<solid android:color="#FFFFFF"/> <!-- 배경: 흰색 -->
</shape>
</item>

<!-- 아래 테두리 선 -->
<item android:bottom="0dp" android:top="56dp">
<shape android:shape="rectangle">
<solid android:color="@color/purple_200"/>
</shape>
</item>

</layer-list>
18 changes: 18 additions & 0 deletions app/src/main/res/drawable/student_button_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<!-- 전체 배경 (흰색 or 투명) -->
<item>
<shape android:shape="rectangle">
<solid android:color="#FFFFFF"/> <!-- 배경: 흰색 -->
</shape>
</item>

<!-- 아래 테두리 선 -->
<item android:bottom="0dp" android:top="56dp">
<shape android:shape="rectangle">
<solid android:color="#0D47A1"/>
</shape>
</item>

</layer-list>
16 changes: 16 additions & 0 deletions app/src/main/res/layout/activity_login.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">

<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>
Loading