Skip to content

Commit

Permalink
로그인 유지 및 퀴즈 3분류
Browse files Browse the repository at this point in the history
  • Loading branch information
Chan3711 committed Jun 20, 2024
1 parent d213c93 commit ab9a74b
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 38 deletions.
6 changes: 5 additions & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@
android:exported="false" />
<activity
android:name=".QuizActivity"
android:exported="false" />
android:exported="true">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".CreateQuiz"
android:exported="false" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ class LoginActivity : AppCompatActivity() {
val password = findViewById<EditText>(R.id.passwordEditText).text.toString()
login(email, password)
}

if (SharedPreferencesUtil.isLoggedIn(this)) {
val intent = Intent(this@LoginActivity, MainActivity::class.java)
startActivity(intent)
finish()
}

}

// HTTP 통신을 통한 로그인 시도
Expand All @@ -79,6 +86,7 @@ class LoginActivity : AppCompatActivity() {
SharedPreferencesUtil.saveUserData(this@LoginActivity, name, id, email)
SharedPreferencesUtil.saveAccessToken(this@LoginActivity, accessToken)
SharedPreferencesUtil.saveRefreshToken(this@LoginActivity, refreshToken)
SharedPreferencesUtil.saveLoggedInStatus(this@LoginActivity, true)

// 로그인 성공 시 MainActivity로 이동
val intent = Intent(this@LoginActivity, MainActivity::class.java)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.os.Build
import android.util.Log
import androidx.core.app.NotificationCompat
import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage
Expand Down Expand Up @@ -36,8 +35,7 @@ class MyFirebaseMessagingService : FirebaseMessagingService() {
// 알림 클릭 시 실행할 액티비티 설정
val intent = Intent(this, QuizActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
val pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_MUTABLE)

val pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_UPDATE_CURRENT)

// 알림 생성
val notificationBuilder = NotificationCompat.Builder(this, "default")
Expand Down
14 changes: 13 additions & 1 deletion android/app/src/main/java/com/example/sharenote/QuizActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,30 @@ class QuizActivity : AppCompatActivity(), QuizAdapter.OnItemClickListener {
val btnSolved: TextView = findViewById(R.id.btnSolved)

btnAll.setOnClickListener {
btnAll.setBackgroundResource(R.drawable.rectangle_bright_blue)
btnUnsolved.setBackgroundResource(R.drawable.rectangle)
btnSolved.setBackgroundResource(R.drawable.rectangle)

supportFragmentManager.beginTransaction()
.replace(R.id.fragmentContainerView, AllQuizFragment())
.commit()
}

btnUnsolved.setOnClickListener {
btnAll.setBackgroundResource(R.drawable.rectangle)
btnUnsolved.setBackgroundResource(R.drawable.rectangle_bright_blue)
btnSolved.setBackgroundResource(R.drawable.rectangle)

supportFragmentManager.beginTransaction()
.replace(R.id.fragmentContainerView, UnsolvedQuizFragment())
.commit()
}

btnSolved.setOnClickListener {
btnAll.setBackgroundResource(R.drawable.rectangle)
btnUnsolved.setBackgroundResource(R.drawable.rectangle)
btnSolved.setBackgroundResource(R.drawable.rectangle_bright_blue)

supportFragmentManager.beginTransaction()
.replace(R.id.fragmentContainerView, SolvedQuizFragment())
.commit()
Expand Down Expand Up @@ -108,7 +120,7 @@ class QuizActivity : AppCompatActivity(), QuizAdapter.OnItemClickListener {
startActivity(intent)
}



private fun showNoteListDialog(editText: TextView) {
val dialogView = LayoutInflater.from(this).inflate(R.layout.quiz_note_list, null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ object SharedPreferencesUtil {

// 유저 정보 저장
private const val PREF_NAME_USER = "MyPrefs_user"
private const val KEY_LOGGED_IN = "loggedIn"
private const val KEY_USER_NAME = "user_name"
private const val KEY_USER_ID = "user_id"
private const val KEY_USER_EMAIL = "user_email"
Expand Down Expand Up @@ -127,6 +128,17 @@ object SharedPreferencesUtil {
}


fun saveLoggedInStatus(context: Context, loggedIn: Boolean) {
val sharedPreferences = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE)
sharedPreferences.edit().putBoolean(KEY_LOGGED_IN, loggedIn).apply()
}

fun isLoggedIn(context: Context): Boolean {
val sharedPreferences = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE)
return sharedPreferences.getBoolean(KEY_LOGGED_IN, false) // 기본값은 false
}


// 사용자 정보 저장
fun saveUserData(context: Context, name: String, userId: String, email: String) {
val sharedPrefs = context.getSharedPreferences(PREF_NAME_USER, Context.MODE_PRIVATE)
Expand Down
2 changes: 1 addition & 1 deletion android/app/src/main/res/layout/activity_quiz.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
android:layout_width="70dp"
android:layout_height="40dp"
android:gravity="center"
android:background="@drawable/rectangle"
android:background="@drawable/rectangle_bright_blue"
android:layout_toLeftOf="@+id/btnUnsolved"
android:layout_marginRight="30dp"
android:text="All"
Expand Down
69 changes: 38 additions & 31 deletions android/app/src/main/res/layout/activity_quiz_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
android:layout_height="wrap_content"
android:layout_below="@id/layout1"
android:padding="10dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp">

<FrameLayout
Expand All @@ -97,40 +98,46 @@
android:background="@drawable/rectangle_white"
android:layout_marginTop="2dp">



<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Q."
android:textColor="@color/blue"
android:textSize="18dp"
android:textStyle="bold"
android:padding="10dp" />

<TextView
android:id="@+id/titleEditText"
android:layout_width="320dp"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:hint=" 퀴즈 문제 내용"
android:textSize="18dp"
android:textColor="@color/black"
android:textStyle="bold"
android:padding="10dp" />

<LinearLayout
android:id="@+id/container"
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_marginBottom="25dp"
android:layout_below="@+id/titleEditText"
android:orientation="vertical">
</LinearLayout>
android:layout_height="wrap_content">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Q."
android:textColor="@color/blue"
android:textSize="18dp"
android:textStyle="bold"
android:padding="10dp" />

<TextView
android:id="@+id/titleEditText"
android:layout_width="320dp"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:text="퀴즈 문제 내용"
android:textSize="18dp"
android:textColor="@color/black"
android:textStyle="bold"
android:padding="10dp" />

<LinearLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/titleEditText"
android:layout_marginBottom="5dp"
android:orientation="vertical">
</LinearLayout>

</RelativeLayout>

</FrameLayout>

</RelativeLayout>


<RelativeLayout
android:id="@+id/layout3"
android:layout_width="match_parent"
Expand All @@ -145,7 +152,7 @@
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_marginTop="5dp"
android:layout_below="@id/layout3"
android:padding="1dp"
android:layout_marginLeft="10dp"
Expand Down
2 changes: 1 addition & 1 deletion android/app/src/main/res/layout/add_choice_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_marginBottom="25dp"
android:padding="1dp">

<FrameLayout
Expand Down

0 comments on commit ab9a74b

Please sign in to comment.