Skip to content
Merged
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
10 changes: 9 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,15 @@ dependencies {
implementation ("com.squareup.retrofit2:converter-gson:2.9.0")
implementation ("com.squareup.okhttp3:okhttp:4.10.0")
implementation ("com.squareup.okhttp3:logging-interceptor:4.10.0")

//Data Store 라이브러리 추가
// Preferences DataStore (SharedPreferences like APIs)
implementation("androidx.datastore:datastore-preferences:1.0.0")
// optional - RxJava2 support
implementation("androidx.datastore:datastore-preferences-rxjava2:1.0.0")
// optional - RxJava3 support
implementation("androidx.datastore:datastore-preferences-rxjava3:1.0.0")
// Alternatively - use the following artifact without an Android dependency.
implementation("androidx.datastore:datastore-preferences-core:1.0.0")

testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
android:supportsRtl="true"
android:theme="@style/Theme.Maplemate"
tools:targetApi="31">
<activity
android:name=".UI.TestActivity"
android:exported="true" />
<activity
android:name=".MainActivity"
android:exported="true"
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/android/maplemate/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.android.maplemate

import android.content.Context
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.preferencesDataStore
import androidx.viewpager2.widget.ViewPager2
import com.android.maplemate.databinding.ActivityMainBinding
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator
import java.util.prefs.Preferences

class MainActivity : AppCompatActivity() {

Expand Down
184 changes: 145 additions & 39 deletions app/src/main/java/com/android/maplemate/UI/SecondFragment.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package com.android.maplemate.UI

import android.content.Context
import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.view.isVisible
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.preferencesDataStore
import androidx.lifecycle.lifecycleScope
import coil.load
import com.android.maplemate.BuildConfig
Expand All @@ -19,7 +23,7 @@ import retrofit2.Callback
import retrofit2.Response
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.Properties



class SecondFragment : Fragment() {
Expand All @@ -30,8 +34,7 @@ class SecondFragment : Fragment() {

private var _binding: FragmentSecondBinding? = null
private val binding get() = _binding!!

private lateinit var testApikey:String
private lateinit var testApikey: String


override fun onCreate(savedInstanceState: Bundle?) {
Expand Down Expand Up @@ -78,7 +81,7 @@ class SecondFragment : Fragment() {
blancRequest()
}
}
binding.ivBackButton.setOnClickListener{
binding.ivBackButton.setOnClickListener {
binding.apply {
boxResult.isVisible = false
boxSearch.isVisible = true
Expand Down Expand Up @@ -114,11 +117,17 @@ class SecondFragment : Fragment() {
mapleCall.enqueue(object : Callback<MapleData> {
override fun onResponse(call: Call<MapleData>, response: Response<MapleData>) {

val mapleinfo = response.body()
val mapleInfo = response.body()

if (mapleinfo != null) {
var getOcid = "${mapleinfo.ocid}"
Log.d("getocid", "${getOcid}")
//입력받은 캐릭터명은 식별자를 얻음과 동시에 저장하는(SharedPreferences)로직 추가.
//입력받은캐릭터명 = ocid(식별자) 형태로 저장,불러옴
//1.입력받은캐릭명(mapleNickName)이 Sharedprefereces에 존재하지않으면 ocid(식별자)를 조회하고 getocid(testApikey,mapleNickName) ->저장로직추가 > character(testApikey,mapleNickName,date)
//2.입력받은캐릭명(mapleNickName)이 Sharedprefereces에 존재(!=null)하면 캐릭명과 일치하는 ocid를 찾아 변수 srefgetocid 에 담고, character(testApikey,srefgetocid,date) 를받아 쿼리에 넣어 요청.

if (mapleInfo != null) {
var getOcid = "${mapleInfo.ocid}"
Log.d("getOcid", "${getOcid}")
//캐릭터 정보 조회 요청 로직을 characterCall에 담음
val characterCall = apiservicemaple.getCharacter(
testApikey,
"${getOcid}",
Expand All @@ -133,25 +142,27 @@ class SecondFragment : Fragment() {
response: Response<MapleData>
) {

val mapleinfo2 = response.body()
Log.d("mapleinfo2test", "mapleinfo2: ${mapleinfo2}")
val mapleInfo2 = response.body()
Log.d("mapleInfo2test", "mapleInfo2: ${mapleInfo2}")

if (mapleinfo2 != null) {
if (mapleInfo2 != null) {

Log.d("mapleinfo2success", "mapleinfo2: ${mapleinfo2}")
Log.d("mapleInfo2success", "mapleInfo2: ${mapleInfo2}")
binding.apply {
binding.ivCharacterImage.load(mapleinfo2.characterImage)
tvCharacterLevel.text = "성별: ${mapleinfo2.characterGender}"
tvWorldName.text = "서버: ${mapleinfo2.worldName}"
tvCharacterName.text = "닉네임: ${mapleinfo2.characterName}"
tvCharacterGuildName.text ="길드: ${mapleinfo2.characterGuildName}"
tvCharacterExpRate.text = "경험치: ${mapleinfo2.characterExpRate}%"
binding.ivCharacterImage.load(mapleInfo2.characterImage)
tvCharacterLevel.text = "Lv:${mapleInfo2.characterLevel}"
tvWorldName.text = "서버: ${mapleInfo2.worldName}"
tvCharacterName.text = "닉네임: ${mapleInfo2.characterName}"
tvCharacterGuildName.text =
"길드: ${mapleInfo2.characterGuildName}"
tvCharacterExpRate.text =
"경험치: ${mapleInfo2.characterExpRate}%"
}


} else {

Log.d("mapleinfo2", "mapleinfo2: ${mapleinfo2}")
Log.d("mapleInfo2", "mapleInfo2: ${mapleInfo2}")
}
}

Expand All @@ -167,7 +178,7 @@ class SecondFragment : Fragment() {

} else {

Log.e("Fuxxk", "mapleinfo: ${mapleinfo}")
Log.e("Fuxxk", "mapleInfo: ${mapleInfo}")
Log.d("Fuxxk", "response: ${response}")
}

Expand Down Expand Up @@ -204,17 +215,17 @@ class SecondFragment : Fragment() {
boxSearch.isVisible = true
}
binding.btnSearch.setOnClickListener {
mapleCall = apiservicemaple.getocid(testApikey,mapleNickName)
mapleCall = apiservicemaple.getocid(testApikey, mapleNickName)
}
}

mapleCall.enqueue(object : Callback<MapleData> {
override fun onResponse(call: Call<MapleData>, response: Response<MapleData>) {

val mapleinfo = response.body()
val mapleInfo = response.body()

if (mapleinfo != null) {
var getOcid = "${mapleinfo.ocid}"
if (mapleInfo != null) {
var getOcid = "${mapleInfo.ocid}"
Log.d("getocid", "${getOcid}")

val charaterCall = apiservicemaple.getCharacter(
Expand All @@ -231,29 +242,27 @@ class SecondFragment : Fragment() {
response: Response<MapleData>
) {

val mapleinfo2 = response.body()
Log.d("mapleinfo2test", "mapleinfo2: ${mapleinfo2}")
val mapleInfo2 = response.body()
Log.d("mapleInfo2test", "mapleInfo2: ${mapleInfo2}")

if (mapleinfo2 != null) {
if (mapleInfo2 != null) {

Log.d("mapleinfo2success", "mapleinfo2: ${mapleinfo2}")
Log.d("mapleInfo2success", "mapleInfo2: ${mapleInfo2}")
binding.apply {

ivCharacterImage.load(mapleinfo2.characterImage)
tvCharacterLevel.text = "Lv:${mapleinfo2.characterLevel}"
tvWorldName.text = "서버:${mapleinfo2.worldName}"
tvCharacterName.text = "닉네임:${mapleinfo2.characterName}"
tvCharacterGuildName.text ="길드:${mapleinfo2.characterGuildName}"
tvCharacterExpRate.text = "경험치:${mapleinfo2.characterExpRate}%"
ivCharacterImage.load(mapleInfo2.characterImage)
tvCharacterLevel.text = "Lv:${mapleInfo2.characterLevel}"
tvWorldName.text = "서버:${mapleInfo2.worldName}"
tvCharacterName.text = "닉네임:${mapleInfo2.characterName}"
tvCharacterGuildName.text = "길드:${mapleInfo2.characterGuildName}"
tvCharacterExpRate.text = "경험치:${mapleInfo2.characterExpRate}%"

}




} else {

Log.d("mapleinfo2", "mapleinfo2: ${mapleinfo2}")
Log.d("mapleInfo2", "mapleInfo2: ${mapleInfo2}")
}
}

Expand All @@ -269,7 +278,7 @@ class SecondFragment : Fragment() {

} else {

Log.e("Fuxxk", "mapleinfo: ${mapleinfo}")
Log.e("Fuxxk", "mapleInfo: ${mapleInfo}")
Log.d("Howtypelog", "etInputUserName: ${binding.searchView}")
Log.d("Fuxxk", "response: ${response}")
}
Expand All @@ -286,4 +295,101 @@ class SecondFragment : Fragment() {

}

}

private fun apiRequest2() {

//1.Retrofit 객체 초기화입
val retrofit: Retrofit = Retrofit.Builder()
.baseUrl("https://open.api.nexon.com")
.addConverterFactory(GsonConverterFactory.create())
.build()
//2. service 객체 생성
val apiservicemaple: ApiServiceMaple = retrofit.create(ApiServiceMaple::class.java)

//3. Call객체 생성
val mapleNickName = binding.searchView.text.toString()
Log.d("getNickName", "${mapleNickName}")
val mapleCall = apiservicemaple.getocid(
testApikey,
mapleNickName,
)

//4. 네트워크 통신
mapleCall.enqueue(object : Callback<MapleData> {
override fun onResponse(call: Call<MapleData>, response: Response<MapleData>) {

val mapleInfo = response.body()

//입력받은 캐릭터명은 식별자를 얻음과 동시에 저장하는(SharedPreferences)로직 추가.
//입력받은캐릭터명 = ocid(식별자) 형태로 저장,불러옴
//1.입력받은캐릭명(mapleNickName)이 Sharedprefereces에 존재하지않으면 ocid(식별자)를 조회하고 getocid(testApikey,mapleNickName) ->저장로직추가 > character(testApikey,mapleNickName,date)
//2.입력받은캐릭명(mapleNickName)이 Sharedprefereces에 존재(!=null)하면 캐릭명과 일치하는 ocid를 찾아 변수 srefgetocid 에 담고, character(testApikey,srefgetocid,date) 를받아 쿼리에 넣어 요청.

if (mapleInfo != null) {
var getOcid = "${mapleInfo.ocid}"
Log.d("getOcid", "${getOcid}")
//캐릭터 정보 조회 요청 로직을 characterCall에 담음
val characterCall = apiservicemaple.getCharacter(
testApikey,
"${getOcid}",
"2023-12-30"
)
if (getOcid != null) {
Log.d("characterCall 시작직전", "${getOcid}")

characterCall.enqueue(object : Callback<MapleData> {
override fun onResponse(
call: Call<MapleData>,
response: Response<MapleData>
) {

val mapleInfo2 = response.body()
Log.d("mapleInfo2test", "mapleInfo2: ${mapleInfo2}")

if (mapleInfo2 != null) {

Log.d("mapleInfo2success", "mapleInfo2: ${mapleInfo2}")
binding.apply {
binding.ivCharacterImage.load(mapleInfo2.characterImage)
tvCharacterLevel.text = "Lv:${mapleInfo2.characterLevel}"
tvWorldName.text = "서버: ${mapleInfo2.worldName}"
tvCharacterName.text = "닉네임: ${mapleInfo2.characterName}"
tvCharacterGuildName.text = "길드: ${mapleInfo2.characterGuildName}"
tvCharacterExpRate.text = "경험치: ${mapleInfo2.characterExpRate}%"
}


} else {

Log.d("mapleInfo2", "mapleInfo2: ${mapleInfo2}")
}
}

override fun onFailure(call: Call<MapleData>, t: Throwable) {

Log.e("Debug", "API Request Failed", t)
call.cancel()
}

})
}


} else {

Log.e("Fuxxk", "mapleInfo: ${mapleInfo}")
Log.d("Fuxxk", "response: ${response}")
}

}

override fun onFailure(call: Call<MapleData>, t: Throwable) {

Log.e("Debug", "API Request Failed", t)
call.cancel()
}

})

}
}
Loading