generated from NOW-SOPT-ANDROID/now-sopt-android-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[MERGE/#10] week4 xml 필수과제 구현
- Loading branch information
Showing
50 changed files
with
1,072 additions
and
306 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.sopt.now | ||
|
||
import android.util.Log | ||
import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory | ||
import com.sopt.now.presentation.auth.login.LoginActivity | ||
import com.sopt.now.data.remote.service.AuthService | ||
import com.sopt.now.data.remote.service.FollwerService | ||
import com.sopt.now.data.remote.service.UserService | ||
import kotlinx.serialization.json.Json | ||
import okhttp3.Interceptor | ||
import okhttp3.MediaType.Companion.toMediaType | ||
import okhttp3.OkHttpClient | ||
import okhttp3.Response | ||
import retrofit2.Retrofit | ||
import java.io.IOException | ||
|
||
object ApiFactory { | ||
private const val BASE_URL: String = BuildConfig.AUTH_BASE_URL | ||
const val USER_ID:String = "userId" | ||
|
||
val retrofit: Retrofit by lazy { | ||
Retrofit.Builder() | ||
.baseUrl(BASE_URL) | ||
.addConverterFactory(Json.asConverterFactory("application/json".toMediaType())) | ||
.build() | ||
} | ||
|
||
val userRetrofit: Retrofit by lazy { | ||
Retrofit.Builder() | ||
.baseUrl(BASE_URL) | ||
.client(provideOkHttpClient(HeaderInterceptor())) | ||
.addConverterFactory(Json.asConverterFactory("application/json".toMediaType())) | ||
.build() | ||
} | ||
private fun provideOkHttpClient(interceptor: HeaderInterceptor): OkHttpClient | ||
= OkHttpClient.Builder().run { | ||
addInterceptor(interceptor) | ||
build() | ||
} | ||
class HeaderInterceptor : Interceptor { | ||
@Throws(IOException::class) | ||
override fun intercept(chain: Interceptor.Chain): Response = with(chain) { | ||
val accessToken = LoginActivity.prefs.getString(USER_ID, "") | ||
val newRequest = request().newBuilder() | ||
.addHeader("memberId", accessToken) | ||
.build() | ||
proceed(newRequest) | ||
} | ||
} | ||
inline fun <reified T> create(): T = retrofit.create(T::class.java) | ||
inline fun <reified T> createUser(): T = userRetrofit.create(T::class.java) | ||
} | ||
|
||
object ServicePool { | ||
val authService = ApiFactory.create<AuthService>() | ||
val userService = ApiFactory.createUser<UserService>() | ||
val followerService = ApiFactory.create<FollwerService>() | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.sopt.now | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.Fragment | ||
import androidx.viewbinding.ViewBinding | ||
|
||
abstract class BindingFragment<T : ViewBinding> : Fragment() { | ||
private var _binding: T? = null | ||
val binding: T | ||
get() = requireNotNull(_binding) { "_binding이 null이 아닌 경우만 _binding 반환" } | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
_binding = fragmentBinding(inflater, container) | ||
return binding.root | ||
} | ||
|
||
abstract fun fragmentBinding(inflater: LayoutInflater, container: ViewGroup?): T | ||
|
||
override fun onDestroyView() { | ||
_binding = null | ||
super.onDestroyView() | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.sopt.now | ||
|
||
import android.content.Context | ||
import android.content.SharedPreferences | ||
|
||
class PreferenceUtil(context: Context) { | ||
private val prefs: SharedPreferences = | ||
context.getSharedPreferences(USER_ID, Context.MODE_PRIVATE) | ||
|
||
fun getString(key: String, defValue: String): String { | ||
return prefs.getString(key, defValue).toString() | ||
} | ||
|
||
fun setString(key: String, str: String) { | ||
prefs.edit().putString(key, str).apply() | ||
} | ||
|
||
companion object { | ||
const val USER_ID = "userId" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.