Skip to content

Commit

Permalink
Merge branch 'feature/169_github_implement' into develop
Browse files Browse the repository at this point in the history
# Conflicts:
#	app/src/main/java/com/xquare/xquare_android/XquareApplication.kt
#	app/src/main/java/com/xquare/xquare_android/feature/profile/ProfileScreen.kt
#	app/src/main/java/com/xquare/xquare_android/feature/profile/ProfileViewModel.kt
#	data/src/main/java/com/xquare/data/remote/datasource/attachment/AttachmentRemoteDataSourceImpl.kt
#	data/src/main/java/com/xquare/data/repository/attachment/AttachmentRepositoryImpl.kt
#	di/src/main/java/com/xquare/di/NetworkModule.kt
  • Loading branch information
JunJaBoy committed Sep 23, 2023
2 parents 24f9d43 + 368b067 commit b33664b
Show file tree
Hide file tree
Showing 67 changed files with 1,020 additions and 302 deletions.
30 changes: 18 additions & 12 deletions .idea/deploymentTargetDropDown.xml

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

15 changes: 15 additions & 0 deletions .idea/git_toolbox_prj.xml

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

34 changes: 23 additions & 11 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xquare.xquare_android">
package="com.xquare.xquare_android">

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.INTERNET" />

<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

Expand All @@ -17,24 +17,36 @@
android:supportsRtl="true"
android:hardwareAccelerated="true">

<service android:name=".feature.alarm.MyFirebaseMessagingService"
android:exported="false">
<service
android:name=".feature.alarm.MyFirebaseMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>

<activity
android:name="com.xquare.xquare_android.MainActivity"
android:exported="true"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/Theme.XquareAndroid">
android:name="com.xquare.xquare_android.MainActivity"
android:exported="true"
android:label="@string/app_name"
android:launchMode="standard"
android:screenOrientation="portrait"
android:theme="@style/Theme.XquareAndroid">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data
android:host="callback"
android:scheme="xquare" />
</intent-filter>
</activity>
</application>

Expand Down
74 changes: 64 additions & 10 deletions app/src/main/java/com/xquare/xquare_android/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@ package com.xquare.xquare_android

import android.content.Context
import android.content.ContextWrapper
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.util.Log
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.annotation.RequiresApi
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Scaffold
import androidx.compose.material.rememberScaffoldState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
Expand All @@ -26,12 +28,14 @@ import com.google.firebase.FirebaseApp
import com.google.firebase.messaging.FirebaseMessaging
import com.google.gson.Gson
import com.semicolon.design.color.primary.white.white
import com.xquare.domain.entity.github.GithubOAuthEntity
import com.xquare.domain.entity.schedules.SchedulesEntity
import com.xquare.xquare_android.component.BottomNavigation
import com.xquare.xquare_android.feature.alarm.AlarmScreen
import com.xquare.xquare_android.feature.all.AllScreen
import com.xquare.xquare_android.feature.allmeal.AllMealScreen
import com.xquare.xquare_android.feature.bug.BugReportScreen
import com.xquare.xquare_android.feature.github.GithubScreen
import com.xquare.xquare_android.feature.home.HomeScreen
import com.xquare.xquare_android.feature.imagedetail.ImageDetailScreen
import com.xquare.xquare_android.feature.onboard.OnboardScreen
Expand All @@ -49,7 +53,11 @@ import com.xquare.xquare_android.feature.today_teacher.TodayTeacherScreen
import com.xquare.xquare_android.feature.webview.CommonWebViewScreen
import com.xquare.xquare_android.navigation.AppNavigationItem
import com.xquare.xquare_android.navigation.BottomNavigationItem
import com.xquare.xquare_android.util.*
import com.xquare.xquare_android.util.DevicePaddings
import com.xquare.xquare_android.util.XquareExceptionHandler
import com.xquare.xquare_android.util.getNavigationBarHeightDp
import com.xquare.xquare_android.util.getStatusBarHeightDp
import com.xquare.xquare_android.util.setStatusBarTransparent
import dagger.hilt.android.AndroidEntryPoint
import java.io.File
import java.net.URLDecoder
Expand All @@ -58,15 +66,49 @@ import java.nio.charset.StandardCharsets

@AndroidEntryPoint
class MainActivity : ComponentActivity() {

private val mainActivityViewModel: MainActivityViewModel by viewModels()


private fun uploadGithubOauthCodeIfExists(intent: Intent) {
val action: String? = intent.action.also { println("ACTACT $it") }

if (action == Intent.ACTION_VIEW) {
val data: Uri? = intent.data
val code = data!!.getQueryParameter("code")
Log.d("TAG", "getCode: ${data.getQueryParameter("code")}")
mainActivityViewModel.registerGithubUser(
GithubOAuthEntity(code = code!!)
)
}
}


@RequiresApi(Build.VERSION_CODES.O)
override fun onCreate(savedInstanceState: Bundle?) {
setStatusBarTransparent()
DevicePaddings.statusBarHeightDp = getStatusBarHeightDp()
DevicePaddings.navigationBarHeightDp = getNavigationBarHeightDp()
super.onCreate(savedInstanceState)
saveDeviceToken(this)

setContent {
LaunchedEffect(Unit) {
mainActivityViewModel.eventFlow.collect { event ->
when (event) {
MainActivityViewModel.Event.OAuthFailure -> Toast.makeText(
this@MainActivity,
"깃허브 연동에 실패하였습니다.",
Toast.LENGTH_SHORT
).show()

MainActivityViewModel.Event.OAuthSuccess ->Toast.makeText(
this@MainActivity,
"깃허브 연동에 성공하였습니다.",
Toast.LENGTH_SHORT
).show()
}
}
}
Thread.setDefaultUncaughtExceptionHandler(
XquareExceptionHandler(
context = this,
Expand All @@ -75,6 +117,11 @@ class MainActivity : ComponentActivity() {
BaseApp()
}
}

override fun onResume() {
super.onResume()
uploadGithubOauthCodeIfExists(intent)
}
}

@RequiresApi(Build.VERSION_CODES.O)
Expand Down Expand Up @@ -131,15 +178,18 @@ fun BaseApp() {
composable(AppNavigationItem.Pass.route) {
PassScreen(navController)
}
composable(AppNavigationItem.TodayTeacher.route){
composable(AppNavigationItem.TodayTeacher.route) {
TodayTeacherScreen(navController)
}
composable(AppNavigationItem.Setting.route) {
SettingScreen(navController)
}
composable(AppNavigationItem.ReleaseNote.route){
composable(AppNavigationItem.ReleaseNote.route) {
ReleaseScreen(navController)


}
composable(AppNavigationItem.Github.route) {
GithubScreen(navController)
}
composable(AppNavigationItem.WriteSchedule.route) {
val schedulesData = it.arguments?.get("schedulesData").toString()
Expand Down Expand Up @@ -255,7 +305,7 @@ fun saveDeviceToken(context: Context) {
Log.d("TAG", "saveDeviceToken: $token")
val pref = context.getSharedPreferences("token", Context.MODE_PRIVATE)
val editor = pref.edit()
editor.putString("token",token).apply()
editor.putString("token", token).apply()
editor.commit()

Log.d("TAG", "Save Token Successfully")
Expand All @@ -277,4 +327,8 @@ fun Context.getActivity(): ComponentActivity? = when (this) {
is ComponentActivity -> this
is ContextWrapper -> baseContext.getActivity()
else -> null
}
}




Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.xquare.xquare_android

import com.xquare.domain.entity.github.GithubOAuthEntity
import com.xquare.domain.usecase.github.FetchGithubOAuthCheckUseCase
import com.xquare.domain.usecase.github.FetchGithubOAuthUseCase
import com.xquare.xquare_android.base.BaseViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import javax.inject.Inject

@HiltViewModel
class MainActivityViewModel @Inject constructor(
private val fetchGithubOAuthUseCase: FetchGithubOAuthUseCase,
private val fetchGithubOAuthCheckUseCase: FetchGithubOAuthCheckUseCase
) : BaseViewModel<MainActivityViewModel.Event>() {

fun registerGithubUser(githubOAuthEntity: GithubOAuthEntity) {
execute(
job = {
val connected = fetchGithubOAuthCheckUseCase.execute(Unit).is_connected

if (!connected) {
fetchGithubOAuthUseCase.execute(githubOAuthEntity)
}
},
onSuccess = { emitEvent(Event.OAuthSuccess) },
onFailure = { emitEvent(Event.OAuthFailure) }
)
}

sealed class Event {
object OAuthSuccess : Event()
object OAuthFailure : Event()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.xquare.xquare_android

import android.app.Application
import android.content.Context
import android.content.Intent
import android.util.Log
import com.google.firebase.FirebaseApp
import com.google.firebase.messaging.FirebaseMessaging
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.xquare.xquare_android.base
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.xquare.domain.exception.NeedLoginException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

abstract class BaseViewModel<T> : ViewModel() {
Expand All @@ -18,7 +19,7 @@ abstract class BaseViewModel<T> : ViewModel() {
job: suspend () -> V,
onSuccess: suspend (value: V) -> Unit,
onFailure: suspend (t: Throwable) -> Unit
) = viewModelScope.launch {
) = viewModelScope.launch(Dispatchers.IO) {
kotlin.runCatching { job() }
.onSuccess { onSuccess(it) }
.onFailure {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import com.xquare.xquare_android.util.DevicePaddings

@Composable
fun AllScreen(navController: NavController) {
val schoolMenuList = listOf("오늘의 자습감독 선생님")//"동아리 지원하기", "오늘의 자습감독 선생님", "랭킹")
val schoolMenuList = listOf("오늘의 자습감독 선생님", "랭킹")//"동아리 지원하기", "오늘의 자습감독 선생님", "랭킹")
val dormitoryMenuList = listOf("봉사 지원하기", "청소판 확인하기")
val userMenuList = listOf("업데이트 사항")

Expand Down Expand Up @@ -92,6 +92,7 @@ fun AllScreen(navController: NavController) {
ColumnMenuItem(title) {
when(index) {
0 -> navController.navigate(AppNavigationItem.TodayTeacher.route)
1 -> navController.navigate(AppNavigationItem.Github.route)
}
}
}
Expand Down
Loading

0 comments on commit b33664b

Please sign in to comment.