Skip to content

Commit

Permalink
Merge pull request #8 from GO-SOPT-ANDROID/feature/week4
Browse files Browse the repository at this point in the history
Feature/week4
  • Loading branch information
gaeun5744 authored May 23, 2023
2 parents ceb0023 + 2d82f3c commit 6d1c44c
Show file tree
Hide file tree
Showing 33 changed files with 1,089 additions and 127 deletions.
25 changes: 25 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'org.jetbrains.kotlin.plugin.serialization' version '1.8.0'
}

Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())

android {
namespace 'org.android.go.sopt'
compileSdk 33
Expand All @@ -15,6 +19,9 @@ android {
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
buildConfigField "String", "AUTH_BASE_URL", properties["auth.base.url"]
buildConfigField "String", "REQRES_BASE_URL", properties["reqres.base.url"]
buildConfigField "String","USERS_LIST_BASE_URL", properties["user.list.base.url"]
}

buildTypes {
Expand Down Expand Up @@ -42,11 +49,29 @@ dependencies {
implementation 'com.google.android.material:material:1.8.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.recyclerview:recyclerview-selection:1.1.0'
implementation 'androidx.navigation:navigation-fragment-ktx:2.4.1'
implementation 'androidx.navigation:navigation-ui-ktx:2.4.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
implementation "androidx.recyclerview:recyclerview:1.2.0-rc01"
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-parcelize'
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1'
implementation 'com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:0.8.0'
// define a BOM and its version
implementation(platform("com.squareup.okhttp3:okhttp-bom:4.10.0"))

// define any required OkHttp artifacts without version (BOM을 위에 명시했으니, 밑의 버전들은 BOM에 맞게 적용됩니다.)
implementation("com.squareup.okhttp3:okhttp")
implementation("com.squareup.okhttp3:logging-interceptor")

implementation 'androidx.viewpager2:viewpager2:1.0.0'
// glide
implementation 'com.github.bumptech.glide:glide:4.13.2'



}
16 changes: 14 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

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

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
Expand All @@ -10,17 +12,27 @@
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.GOSOPTAndroid"
android:usesCleartextTraffic="true"
tools:targetApi="31">

<activity
android:name=".MainActivity"
android:windowSoftInputMode="adjustPan"
android:exported="true"
android:windowSoftInputMode="adjustPan"></activity>
<activity
android:name=".myPage.IntroduceActivity"
android:exported="false" />
<activity
android:name=".myPage.LoginActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".myPage.SignUpActivity"
android:exported="false" />
</application>

</manifest>
76 changes: 42 additions & 34 deletions app/src/main/java/org/android/go/sopt/MultiViewAdapter.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.android.go.sopt

import android.R
import android.content.Context
import android.view.LayoutInflater
import android.view.MotionEvent
Expand All @@ -13,22 +12,26 @@ import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.bumptech.glide.Glide
import org.android.go.sopt.data.*
import org.android.go.sopt.databinding.ItemBottomBinding
import org.android.go.sopt.databinding.ItemMusicBinding
import org.android.go.sopt.databinding.ItemTopBinding
import org.android.go.sopt.databinding.ItemUsersBinding
import org.android.go.sopt.remote.model.ResponseListUsersDto



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

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


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


override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
Expand All @@ -38,16 +41,16 @@ class MultiViewAdapter(context: Context) :
return TopRvTitleViewHolder(binding)
}
MULTI_TYPE2 -> {
val binding: ItemMusicBinding = ItemMusicBinding.inflate(inflater, parent, false)
return MusicListViewHolder(binding)
val binding: ItemUsersBinding = ItemUsersBinding.inflate(inflater, parent, false)
return UsersListViewHolder(binding)
}
MULTI_TYPE3 -> {
val binding: ItemBottomBinding = ItemBottomBinding.inflate(inflater, parent, false)
return BottomSponsorViewHolder(binding)
}
else -> {
val binding: ItemMusicBinding = ItemMusicBinding.inflate(inflater, parent, false)
return MusicListViewHolder(binding)
val binding: ItemUsersBinding = ItemUsersBinding.inflate(inflater, parent, false)
return UsersListViewHolder(binding)
}


Expand All @@ -60,15 +63,17 @@ class MultiViewAdapter(context: Context) :


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

}

}

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


Expand All @@ -81,42 +86,40 @@ class MultiViewAdapter(context: Context) :
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
when (getItemViewType(position)) {
MULTI_TYPE1 -> {
(holder as TopRvTitleViewHolder).onBind(currentList[position])
(holder as TopRvTitleViewHolder).onBind()
holder.setIsRecyclable(false)
}
MULTI_TYPE2 -> {
(holder as MusicListViewHolder).onBind(currentList[position], position)
(holder as UsersListViewHolder).onBind(currentList[position - 1])
holder.setIsRecyclable(false)
}
MULTI_TYPE3 -> {
(holder as BottomSponsorViewHolder).onBind(currentList[position])
(holder as BottomSponsorViewHolder).onBind()
holder.setIsRecyclable(false)
}
}

}

class TopRvTitleViewHolder(private val binding: ItemTopBinding) :
ViewHolder(binding.root) {
fun onBind(item: MultiData) {
val dataObject = item.dataObject as DataObject.TopRvTitle
binding.tvTitle.text = dataObject.title
class TopRvTitleViewHolder(private val binding: ItemTopBinding) : ViewHolder(binding.root) {
fun onBind() {
binding.tvTitle.text = "USER LIST"
}
}

inner class MusicListViewHolder(private val binding: ItemMusicBinding) :
inner class UsersListViewHolder(private val binding: ItemUsersBinding) :
ViewHolder(binding.root) {

fun onBind(item: MultiData, itemPosition: Int) {
fun onBind(item: ResponseListUsersDto.Data) {

val dataObject = item.dataObject as DataObject.Music
binding.tvMusicTitle.text = dataObject.music
binding.tvMusicSinger.text = dataObject.singer
binding.tvUserName.text = item.first_name + item.last_name
binding.tvUserEmail.text = item.email
Glide.with(context).load(item.avatar).into(binding.ivAvatar)

if (selectionTracker != null && selectionTracker.isSelected(absoluteAdapterPosition.toLong())) {
binding.chkSelect.setImageResource(R.drawable.ic_media_play)
binding.ivSelect.setImageResource(R.drawable.ic_home)
} else {
binding.chkSelect.setImageResource(R.drawable.ic_menu_delete)
binding.ivSelect.setImageResource(R.drawable.ic_image)
}


Expand Down Expand Up @@ -144,21 +147,26 @@ class MultiViewAdapter(context: Context) :

class BottomSponsorViewHolder(private val binding: ItemBottomBinding) :
ViewHolder(binding.root) {
fun onBind(item: MultiData) {
val dataObject = item.dataObject as DataObject.BottomSponsor
binding.tvMusicEnd.text = dataObject.sponsor
fun onBind() {
binding.tvMusicEnd.text = "후원사 SOPT"
}

}


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

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

Expand All @@ -169,9 +177,9 @@ class MultiViewAdapter(context: Context) :
@Nullable
override fun getItemDetails(@NonNull motionEvent: MotionEvent): ItemDetails<Long>? {
val view = recyclerView.findChildViewUnder(motionEvent.x, motionEvent.y)
if (view != null && recyclerView.getChildViewHolder(view) is MultiViewAdapter.MusicListViewHolder) {
if (view != null && recyclerView.getChildViewHolder(view) is MultiViewAdapter.UsersListViewHolder) {
val viewHolder =
recyclerView.getChildViewHolder(view) as MultiViewAdapter.MusicListViewHolder
recyclerView.getChildViewHolder(view) as MultiViewAdapter.UsersListViewHolder
return viewHolder.getItemDetails(viewHolder)
}
return null
Expand Down
36 changes: 36 additions & 0 deletions app/src/main/java/org/android/go/sopt/ViewPagerAdapter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.android.go.sopt

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import org.android.go.sopt.databinding.ItemPagerBinding

class ViewPagerAdapter(
_itemList: List<Int> = listOf(),
) : RecyclerView.Adapter<ViewPagerAdapter.PagerViewHolder>() {
private var itemList: List<Int> = _itemList

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PagerViewHolder {
val binding = ItemPagerBinding.inflate(LayoutInflater.from(parent.context), parent, false)
return PagerViewHolder(binding)
}

class PagerViewHolder(
private val binding: ItemPagerBinding,
) : RecyclerView.ViewHolder(binding.root) {
fun bind(src: Int) {
binding.ivPager.setImageResource(src)
}
}

override fun onBindViewHolder(holder: PagerViewHolder, position: Int) {
holder.bind(itemList[position])
}

override fun getItemCount() = itemList.size

fun setItemList(itemList: List<Int>) {
this.itemList = itemList
notifyDataSetChanged()
}
}
18 changes: 0 additions & 18 deletions app/src/main/java/org/android/go/sopt/data/DataObject.kt

This file was deleted.

6 changes: 0 additions & 6 deletions app/src/main/java/org/android/go/sopt/data/MultiData.kt

This file was deleted.

11 changes: 11 additions & 0 deletions app/src/main/java/org/android/go/sopt/myPage/ContextUtil.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.android.go.sopt.myPage

import android.app.Activity
import android.content.Context
import android.view.View
import android.view.inputmethod.InputMethodManager

fun Context.hideKeyboard(view: View) {
val inputMethodManager = getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
inputMethodManager.hideSoftInputFromWindow(view.windowToken, 0)
}
Loading

0 comments on commit 6d1c44c

Please sign in to comment.