Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

. #14

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

. #14

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
8 changes: 8 additions & 0 deletions .idea/modules.xml

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

6 changes: 6 additions & 0 deletions .idea/vcs.xml

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

3 changes: 3 additions & 0 deletions summer_coding_android/.idea/.gitignore

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

19 changes: 19 additions & 0 deletions summer_coding_android/.idea/modules/summer_coding_android.iml

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

6 changes: 4 additions & 2 deletions summer_coding_android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,19 @@ android {
kotlinOptions {
jvmTarget = '1.8'
}
viewBinding {
enabled = true
buildFeatures{
viewBinding = true
}
}

dependencies {

implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package kr.co.landvibe.summer_coding_android

/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import androidx.fragment.app.Fragment
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty

/**
* A lazy property that gets cleaned up when the fragment's view is destroyed.
*
* Accessing this variable while the fragment's view is destroyed will throw NPE.
*/
class AutoClearedValue<T : Any>(val fragment: Fragment) : ReadWriteProperty<Fragment, T> {
private var _value: T? = null

init {
fragment.lifecycle.addObserver(object: DefaultLifecycleObserver {
override fun onCreate(owner: LifecycleOwner) {
fragment.viewLifecycleOwnerLiveData.observe(fragment) { viewLifecycleOwner ->
viewLifecycleOwner?.lifecycle?.addObserver(object: DefaultLifecycleObserver {
override fun onDestroy(owner: LifecycleOwner) {
_value = null
}
})
}
}
})
}

override fun getValue(thisRef: Fragment, property: KProperty<*>): T {
return _value ?: throw IllegalStateException(
"should never call auto-cleared-value get when it might not be available"
)
}

override fun setValue(thisRef: Fragment, property: KProperty<*>, value: T) {
_value = value
}
}

/**
* Creates an [AutoClearedValue] associated with this fragment.
*/
fun <T : Any> Fragment.autoCleared() = AutoClearedValue<T>(this)
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package kr.co.landvibe.summer_coding_android.ckgod
import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import kr.co.landvibe.summer_coding_android.R
import kr.co.landvibe.summer_coding_android.ckgod.adapters.ItemListAdapter
import kr.co.landvibe.summer_coding_android.ckgod.data.Item
import kr.co.landvibe.summer_coding_android.databinding.ActivityCkgod2Binding
Expand All @@ -11,11 +12,11 @@ class Ckgod2Activity : AppCompatActivity() {
private lateinit var binding: ActivityCkgod2Binding

val data: List<Item> = listOf(
Item("1", "고창국"),
Item("1", "고창국"),
Item("1", "고창국1"),
Item("1", "고창국1"),
Item("1", "고창2국"),
Item(R.drawable.profile_common, "고창국"),
Item(R.drawable.profile_common, "고창국"),
Item(R.drawable.profile_common, "고창국1"),
Item(R.drawable.profile_common, "고창국1"),
Item(R.drawable.profile_common, "고창2국"),
)

override fun onCreate(savedInstanceState: Bundle?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package kr.co.landvibe.summer_coding_android.ckgod.data

// class와 data class의 차이 알아보기!
data class Item(
val image: String,
val image: Int,
val name: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,39 @@ package kr.co.landvibe.summer_coding_android.d11210920

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.google.android.material.bottomnavigation.BottomNavigationView
import kr.co.landvibe.summer_coding_android.R
import kr.co.landvibe.summer_coding_android.d11210920.friendsFragment
import kr.co.landvibe.summer_coding_android.databinding.ActivityD11210920Binding

class D11210920Activity : AppCompatActivity() {

private val binding by lazy{ActivityD11210920Binding.inflate(layoutInflater)}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_d11210920)
setContentView(binding.root)

val bnvmain = binding.bottomNavigationView

supportFragmentManager.beginTransaction().add(binding.linearLayout.id,friendsFragment()).commit()

bnvmain.setOnItemSelectedListener { item ->
when(item.itemId){
R.id.page_friendlist ->{
supportFragmentManager.beginTransaction().replace(R.id.linearLayout,friendsFragment()).commitAllowingStateLoss()
return@setOnItemSelectedListener true
}
R.id.page_chatlist ->{
supportFragmentManager.beginTransaction().replace(R.id.linearLayout,chatFragment()).commitAllowingStateLoss()
return@setOnItemSelectedListener true
}
else -> {return@setOnItemSelectedListener false}
}
}

}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package kr.co.landvibe.summer_coding_android.d11210920

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.RecyclerView
import kr.co.landvibe.summer_coding_android.AutoClearedValue
import kr.co.landvibe.summer_coding_android.R
import kr.co.landvibe.summer_coding_android.databinding.*

class chatFragment : Fragment() {
private var binding by AutoClearedValue<FragmentChatBinding>(this)

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = FragmentChatBinding.inflate(inflater, container, false)
return binding.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {


var chatdata : MutableList<chatItem> = mutableListOf()

for(i in 1..101){
val chatdata_ : chatItem = chatItem(R.drawable.profile,"단체채팅방${i}","안녕하세요")
chatdata.add(chatdata_)
}


var recyclerViewAdapter = CustomAdapter(chatdata)

binding.dhChatRv.adapter = recyclerViewAdapter

}

class CustomAdapter(private val item_List: List<chatItem>) : RecyclerView.Adapter<CustomAdapter.Holder>(){

class Holder(val binding: DhChatlistItemBinding) : RecyclerView.ViewHolder(binding.root){
fun setData(item: chatItem){
binding.dhChatName.text = item.name
binding.dhChatprofile.setImageDrawable(itemView.context.getDrawable(item.image))
binding.dhChatContent.text = item.content
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder {
val binding = DhChatlistItemBinding.inflate(LayoutInflater.from(parent.context),parent,false)
return Holder(binding)
}

override fun onBindViewHolder(holder: Holder, position: Int) {
holder.setData(item_List[position])
}

override fun getItemCount(): Int {
return item_List.size
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package kr.co.landvibe.summer_coding_android.d11210920

data class chatItem(
val image: Int,
val name: String,
val content: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package kr.co.landvibe.summer_coding_android.d11210920

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.RecyclerView
import kr.co.landvibe.summer_coding_android.AutoClearedValue
import kr.co.landvibe.summer_coding_android.R
import kr.co.landvibe.summer_coding_android.ckgod.data.Item
import kr.co.landvibe.summer_coding_android.databinding.DhFriendslistItemBinding
import kr.co.landvibe.summer_coding_android.databinding.FragmentFriendsBinding

class friendsFragment : Fragment() {
private var binding by AutoClearedValue<FragmentFriendsBinding>(this)

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = FragmentFriendsBinding.inflate(inflater, container, false)
return binding.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {

val data_ : Item = Item(R.drawable.profile,"김동하")

var data : MutableList<Item> = mutableListOf()

for(i in 0..100){
data.add(data_)
}


var recyclerViewAdapter = CustomAdapter(data)

binding.dhRv.adapter = recyclerViewAdapter

}

class CustomAdapter(private val item_List: List<Item>) : RecyclerView.Adapter<CustomAdapter.Holder>(){

class Holder(val binding: DhFriendslistItemBinding) : RecyclerView.ViewHolder(binding.root){
fun setData(item: Item){
binding.dhName.text = item.name
binding.dhProfile.setImageDrawable(itemView.context.getDrawable(item.image))
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder {
val binding = DhFriendslistItemBinding.inflate(LayoutInflater.from(parent.context),parent,false)
return Holder(binding)
}

override fun onBindViewHolder(holder: Holder, position: Int) {
holder.setData(item_List[position])
}

override fun getItemCount(): Int {
return item_List.size
}

}
}
10 changes: 10 additions & 0 deletions summer_coding_android/app/src/main/res/drawable/dh_chatlist.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M20,2L4,2c-1.1,0 -1.99,0.9 -1.99,2L2,22l4,-4h14c1.1,0 2,-0.9 2,-2L22,4c0,-1.1 -0.9,-2 -2,-2zM6,9h12v2L6,11L6,9zM14,14L6,14v-2h8v2zM18,8L6,8L6,6h12v2z"/>
</vector>
10 changes: 10 additions & 0 deletions summer_coding_android/app/src/main/res/drawable/dh_friendslist.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M19,3h-4.18C14.4,1.84 13.3,1 12,1c-1.3,0 -2.4,0.84 -2.82,2L5,3c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2L21,5c0,-1.1 -0.9,-2 -2,-2zM12,3c0.55,0 1,0.45 1,1s-0.45,1 -1,1 -1,-0.45 -1,-1 0.45,-1 1,-1zM12,7c1.66,0 3,1.34 3,3s-1.34,3 -3,3 -3,-1.34 -3,-3 1.34,-3 3,-3zM18,19L6,19v-1.4c0,-2 4,-3.1 6,-3.1s6,1.1 6,3.1L18,19z"/>
</vector>
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,25 @@
android:layout_height="match_parent"
tools:context=".d11210920.D11210920Activity">

<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@+id/bottomNavigationView"/>

<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottomNavigationView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:labelVisibilityMode="labeled"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:menu="@menu/bottom_navigation_menu"
app:itemBackground="@android:color/white"/>

</androidx.constraintlayout.widget.ConstraintLayout>
Loading