Skip to content

Commit

Permalink
[Refactor/#9] ktlint 포맷 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
gaeun5744 committed Jun 26, 2023
1 parent a40d3ea commit 74f1d41
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 80 deletions.
17 changes: 4 additions & 13 deletions app/src/main/java/org/android/go/sopt/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.android.go.sopt

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import org.android.go.sopt.databinding.ActivityMainBinding
import org.android.go.sopt.present.menuFragment.GalleryFragment
Expand All @@ -15,7 +15,6 @@ class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)


binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)

Expand All @@ -24,12 +23,11 @@ class MainActivity : AppCompatActivity() {
supportFragmentManager.beginTransaction().add(R.id.fcv_main, HomeFragment()).commit()
}


binding.bnvMain.setOnItemSelectedListener { item ->
// 선택된 탭의 itemId와 현재 보여지고 있는 FragmentContainerView의 itemId가 같은 경우
// 즉 같은 탭을 다시 선택한 경우에 scrollTo 메소드를 호출
if (binding.bnvMain.selectedItemId == item.itemId){
binding.fcvMain.scrollTo(0,0)
if (binding.bnvMain.selectedItemId == item.itemId) {
binding.fcvMain.scrollTo(0, 0)
}

when (item.itemId) {
Expand All @@ -52,21 +50,14 @@ class MainActivity : AppCompatActivity() {
else -> {
false
}

}


}

}

private fun changeFragment(fragment: Fragment) {
supportFragmentManager
.beginTransaction()
.replace(R.id.fcv_main, fragment)
.commit()

}


}
}
24 changes: 2 additions & 22 deletions app/src/main/java/org/android/go/sopt/MultiViewAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,13 @@ import org.android.go.sopt.databinding.ItemTopBinding
import org.android.go.sopt.databinding.ItemUsersBinding
import org.android.go.sopt.remote.remoteData.model.ResponseListUsersDto



class MultiViewAdapter(context: Context) :
ListAdapter<ResponseListUsersDto.Data, ViewHolder>(diffUtil) {

init { // selectionTracker를 위한 설정
setHasStableIds(true)
}


private val inflater by lazy { LayoutInflater.from(context) }
private lateinit var selectionTracker: SelectionTracker<Long>

Expand All @@ -50,37 +47,29 @@ class MultiViewAdapter(context: Context) :
val binding: ItemUsersBinding = ItemUsersBinding.inflate(inflater, parent, false)
return UsersListViewHolder(binding)
}


}
}

override fun getItemId(position: Int): Long {
return position.toLong()
}


override fun getItemViewType(position: Int): Int {
return when (position) {
0 -> MULTI_TYPE1
currentList.size + 1 -> MULTI_TYPE3
else -> MULTI_TYPE2

}

}

override fun getItemCount(): Int {
return currentList.size + 2 // UserList + Top + Bottom 이므로 +2를 해준다
}


fun setSelectionTracker(selectionTracker: SelectionTracker<Long>) {

this.selectionTracker = selectionTracker
}


override fun onBindViewHolder(holder: ViewHolder, position: Int) {
when (getItemViewType(position)) {
MULTI_TYPE1 -> {
Expand All @@ -96,7 +85,6 @@ class MultiViewAdapter(context: Context) :
holder.setIsRecyclable(false)
}
}

}

class TopRvTitleViewHolder(private val binding: ItemTopBinding) : ViewHolder(binding.root) {
Expand All @@ -109,7 +97,6 @@ class MultiViewAdapter(context: Context) :
ViewHolder(binding.root) {

fun onBind(item: ResponseListUsersDto.Data) {

binding.tvUserName.text = item.first_name + item.last_name
binding.tvUserEmail.text = item.email
Glide.with(binding.root).load(item.avatar).into(binding.ivAvatar)
Expand All @@ -119,8 +106,6 @@ class MultiViewAdapter(context: Context) :
} else {
binding.ivSelect.setImageResource(R.drawable.ic_image)
}


}

fun getItemDetails(viewHolder: RecyclerView.ViewHolder?): ItemDetailsLookup.ItemDetails<Long> {
Expand Down Expand Up @@ -148,26 +133,23 @@ class MultiViewAdapter(context: Context) :
fun onBind() {
binding.tvMusicEnd.text = "후원사 SOPT"
}

}


companion object {
val diffUtil = object : DiffUtil.ItemCallback<ResponseListUsersDto.Data>() {
override fun areItemsTheSame(
oldItem: ResponseListUsersDto.Data,
newItem: ResponseListUsersDto.Data
newItem: ResponseListUsersDto.Data,
): Boolean {
return oldItem === newItem
}

override fun areContentsTheSame(
oldItem: ResponseListUsersDto.Data,
newItem: ResponseListUsersDto.Data
newItem: ResponseListUsersDto.Data,
): Boolean {
return oldItem == newItem
}

}
}

Expand All @@ -183,6 +165,4 @@ class MultiViewAdapter(context: Context) :
return null
}
}


}
2 changes: 1 addition & 1 deletion app/src/main/java/org/android/go/sopt/data/MultiMode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package org.android.go.sopt.data

const val MULTI_TYPE1 = 0
const val MULTI_TYPE2 = 1
const val MULTI_TYPE3 = 2
const val MULTI_TYPE3 = 2
10 changes: 5 additions & 5 deletions app/src/main/java/org/android/go/sopt/data/User.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import kotlinx.parcelize.Parcelize

@Parcelize
data class User(
val id : String,
val pw : String,
val name : String,
val feature : String
):Parcelable
val id: String,
val pw: String,
val name: String,
val feature: String,
) : Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -4,61 +4,69 @@ import android.content.Context
import android.content.SharedPreferences

object MySharedPreferences {
private val MY_ACCOUNT : String = "account"
private val MY_ACCOUNT: String = "account"

fun setUserId(context: Context, input: String) {
val prefs : SharedPreferences = context.getSharedPreferences(MY_ACCOUNT, Context.MODE_PRIVATE)
val editor : SharedPreferences.Editor = prefs.edit()
val prefs: SharedPreferences =
context.getSharedPreferences(MY_ACCOUNT, Context.MODE_PRIVATE)
val editor: SharedPreferences.Editor = prefs.edit()
editor.putString("MY_ID", input)
editor.commit()
}

fun getUserId(context: Context): String {
val prefs : SharedPreferences = context.getSharedPreferences(MY_ACCOUNT, Context.MODE_PRIVATE)
val prefs: SharedPreferences =
context.getSharedPreferences(MY_ACCOUNT, Context.MODE_PRIVATE)
return prefs.getString("MY_ID", "").toString()
}

fun setUserPass(context: Context, input: String) {
val prefs : SharedPreferences = context.getSharedPreferences(MY_ACCOUNT, Context.MODE_PRIVATE)
val editor : SharedPreferences.Editor = prefs.edit()
val prefs: SharedPreferences =
context.getSharedPreferences(MY_ACCOUNT, Context.MODE_PRIVATE)
val editor: SharedPreferences.Editor = prefs.edit()
editor.putString("MY_PASS", input)
editor.commit()
}

fun getUserPass(context: Context): String {
val prefs : SharedPreferences = context.getSharedPreferences(MY_ACCOUNT, Context.MODE_PRIVATE)
val prefs: SharedPreferences =
context.getSharedPreferences(MY_ACCOUNT, Context.MODE_PRIVATE)
return prefs.getString("MY_PASS", "").toString()
}

fun setUserName(context: Context, input: String) {
val prefs : SharedPreferences = context.getSharedPreferences(MY_ACCOUNT, Context.MODE_PRIVATE)
val editor : SharedPreferences.Editor = prefs.edit()
val prefs: SharedPreferences =
context.getSharedPreferences(MY_ACCOUNT, Context.MODE_PRIVATE)
val editor: SharedPreferences.Editor = prefs.edit()
editor.putString("MY_NAME", input)
editor.commit()
}

fun getUserName(context: Context): String {
val prefs : SharedPreferences = context.getSharedPreferences(MY_ACCOUNT, Context.MODE_PRIVATE)
val prefs: SharedPreferences =
context.getSharedPreferences(MY_ACCOUNT, Context.MODE_PRIVATE)
return prefs.getString("MY_NAME", "").toString()
}

fun setUserSpec(context: Context, input: String) {
val prefs : SharedPreferences = context.getSharedPreferences(MY_ACCOUNT, Context.MODE_PRIVATE)
val editor : SharedPreferences.Editor = prefs.edit()
val prefs: SharedPreferences =
context.getSharedPreferences(MY_ACCOUNT, Context.MODE_PRIVATE)
val editor: SharedPreferences.Editor = prefs.edit()
editor.putString("MY_SPEC", input)
editor.commit()
}

fun getUserSpec(context: Context): String {
val prefs : SharedPreferences = context.getSharedPreferences(MY_ACCOUNT, Context.MODE_PRIVATE)
val prefs: SharedPreferences =
context.getSharedPreferences(MY_ACCOUNT, Context.MODE_PRIVATE)
return prefs.getString("MY_SPEC", "").toString()
}

fun clearUser(context: Context) {
val prefs : SharedPreferences = context.getSharedPreferences(MY_ACCOUNT, Context.MODE_PRIVATE)
val editor : SharedPreferences.Editor = prefs.edit()
val prefs: SharedPreferences =
context.getSharedPreferences(MY_ACCOUNT, Context.MODE_PRIVATE)
val editor: SharedPreferences.Editor = prefs.edit()
editor.clear()
editor.commit()
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class GalleryFragment : Fragment() {
override fun onCreateView( // 뷰를 만든다 << 이때 초기화하면 좋음
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
savedInstanceState: Bundle?,
): View { // 이제 반환하는 View가 Null일 수 없기 때문에, ?를 지워주셔도 됩니다.
_binding = FragmentGalleryBinding.inflate(inflater, container, false)
return binding.root
Expand All @@ -33,12 +33,10 @@ class GalleryFragment : Fragment() {
TabLayoutMediator(binding.tabLayout, binding.pagerHome) { tab, position ->
tab.text = "Fragment ${position + 1}"
}.attach()


}

override fun onDestroyView() {
_binding = null
super.onDestroyView()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import android.view.ViewGroup
import androidx.fragment.app.Fragment
import org.android.go.sopt.databinding.FragmentSearchBinding

class SearchFragment: Fragment() {
class SearchFragment : Fragment() {
private var _binding: FragmentSearchBinding? = null
private val binding: FragmentSearchBinding
get() = requireNotNull(_binding) { "앗 ! _binding이 null이다 !" }

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
savedInstanceState: Bundle?,
): View { // 이제 반환하는 View가 Null일 수 없기 때문에, ?를 지워주셔도 됩니다.
_binding = FragmentSearchBinding.inflate(inflater, container, false)
return binding.root
Expand All @@ -30,4 +30,4 @@ class SearchFragment: Fragment() {
super.onDestroyView()
_binding = null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package org.android.go.sopt.remote.remoteData.model
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable


@Serializable
data class ResponseListUsersDto(
@SerialName("page")
Expand Down Expand Up @@ -40,4 +39,4 @@ data class ResponseListUsersDto(
@SerialName("text")
val text: String,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ data class RequestLogInDto(
@SerialName("id")
val id: String,
@SerialName("password")
val password: String
val password: String,
)

@Serializable
Expand All @@ -18,15 +18,15 @@ data class ResponseLogInDto(
@SerialName("message")
val message: String,
@SerialName("data")
val data: LogInData?
val data: LogInData?,
) {
@Serializable
data class LogInData(
@SerialName("id")
val id:String,
val id: String,
@SerialName("name")
val name: String,
@SerialName("skill")
val skill: String,
)
}
}
Loading

0 comments on commit 74f1d41

Please sign in to comment.