-
Notifications
You must be signed in to change notification settings - Fork 0
Gok5959 week3 #11
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
Open
gok5959
wants to merge
4
commits into
main
Choose a base branch
from
gok5959_week3
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Gok5959 week3 #11
Changes from 5 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
53 changes: 53 additions & 0 deletions
53
...ndroid/app/src/main/java/kr/co/landvibe/summer_coding_android/gok5959/Gok59592Activity.kt
This file contains hidden or 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,53 @@ | ||
| package kr.co.landvibe.summer_coding_android.gok5959 | ||
|
|
||
| import android.content.Intent | ||
| import androidx.appcompat.app.AppCompatActivity | ||
| import android.os.Bundle | ||
| import android.util.Log | ||
| import androidx.recyclerview.widget.ItemTouchHelper | ||
| import kr.co.landvibe.summer_coding_android.R | ||
| import kr.co.landvibe.summer_coding_android.databinding.ActivityGok59592Binding | ||
| import kr.co.landvibe.summer_coding_android.gok5959.adapters.LocationAdapter | ||
| import kr.co.landvibe.summer_coding_android.gok5959.data.Location | ||
| import kr.co.landvibe.summer_coding_android.gok5959.data.locationItem | ||
| import kr.co.landvibe.summer_coding_android.gok5959.itemTouch.ItemTouchHelperCallback | ||
|
|
||
| class Gok59592Activity : AppCompatActivity() { | ||
|
|
||
| private lateinit var text:String | ||
| private lateinit var binding:ActivityGok59592Binding | ||
|
|
||
| val location: MutableList<Location> = mutableListOf( | ||
| Location("인하대학교 후문", 1), | ||
| Location("캐리비안베이", 2), | ||
| Location("파라다이스 시티", 3), | ||
| Location("BBQ치킨 인하대후문점", 4), | ||
| Location("인천국제공항 제1여객터미널", 5), | ||
| Location("부평역", 6), | ||
| Location("성원상떼빌아파트", 7), | ||
| Location("광안대교", 8), | ||
| Location("김해국제공항", 9), | ||
| Location("CU 영주 적십자병원점", 10), | ||
| Location("미진프라자", 11), | ||
| Location("강남역 1번출구", 12) | ||
|
|
||
|
|
||
| ) | ||
| override fun onCreate(savedInstanceState: Bundle?) { | ||
| super.onCreate(savedInstanceState) | ||
| binding = ActivityGok59592Binding.inflate(layoutInflater) | ||
| setContentView(binding.root) | ||
|
|
||
| val adapter = LocationAdapter(location) | ||
| binding.locationRV.adapter = adapter | ||
|
|
||
| val itemTouchHelperCallback = ItemTouchHelperCallback(adapter) | ||
|
|
||
| val helper = ItemTouchHelper(itemTouchHelperCallback) | ||
| helper.attachToRecyclerView(binding.locationRV) | ||
| adapter.addFooterAndSubmitList(location) | ||
| } | ||
|
|
||
|
|
||
|
|
||
| } | ||
33 changes: 32 additions & 1 deletion
33
...android/app/src/main/java/kr/co/landvibe/summer_coding_android/gok5959/Gok5959Activity.kt
This file contains hidden or 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 |
|---|---|---|
| @@ -1,12 +1,43 @@ | ||
| package kr.co.landvibe.summer_coding_android.gok5959 | ||
|
|
||
| import android.content.ContentValues.TAG | ||
| import android.content.Intent | ||
| import androidx.appcompat.app.AppCompatActivity | ||
| import android.os.Bundle | ||
| import android.util.Log | ||
| import androidx.activity.result.ActivityResultLauncher | ||
| import androidx.activity.result.contract.ActivityResultContracts | ||
| import kr.co.landvibe.summer_coding_android.R | ||
| import kr.co.landvibe.summer_coding_android.databinding.ActivityGok5959Binding | ||
|
|
||
| class Gok5959Activity : AppCompatActivity() { | ||
| private lateinit var binding: ActivityGok5959Binding | ||
| private lateinit var activityResultLauncher: ActivityResultLauncher<Intent> | ||
| private val TAG:String = "MainActivity" | ||
| override fun onCreate(savedInstanceState: Bundle?) { | ||
| super.onCreate(savedInstanceState) | ||
| setContentView(R.layout.activity_gok5959) | ||
| binding = ActivityGok5959Binding.inflate(layoutInflater) | ||
| setContentView(binding.root) | ||
| Log.d(TAG, "init") | ||
| initView() | ||
| Log.d(TAG, "init2") | ||
gok5959 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| fun initView() { | ||
| binding.run { | ||
| activityResultLauncher = | ||
| registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> | ||
| when (result.resultCode) { | ||
| 1000 -> { | ||
gok5959 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| nameTV.text = result.data?.getStringExtra("inputText") | ||
gok5959 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| binding.nameBTN.setOnClickListener { | ||
| val intent = Intent(this@Gok5959Activity, Gok59592Activity::class.java) | ||
| activityResultLauncher.launch(intent) | ||
| } | ||
| } | ||
| } | ||
23 changes: 23 additions & 0 deletions
23
...n/java/kr/co/landvibe/summer_coding_android/gok5959/Gok5959LocationinformationActivity.kt
This file contains hidden or 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,23 @@ | ||
| package kr.co.landvibe.summer_coding_android.gok5959 | ||
|
|
||
| import androidx.appcompat.app.AppCompatActivity | ||
| import android.os.Bundle | ||
| import kr.co.landvibe.summer_coding_android.R | ||
| import kr.co.landvibe.summer_coding_android.databinding.ActivityGok5959LocationinformationBinding | ||
|
|
||
| class Gok5959LocationinformationActivity : AppCompatActivity() { | ||
| lateinit var binding:ActivityGok5959LocationinformationBinding | ||
| override fun onCreate(savedInstanceState: Bundle?) { | ||
| super.onCreate(savedInstanceState) | ||
| binding = ActivityGok5959LocationinformationBinding.inflate(layoutInflater) | ||
| init() | ||
| setContentView(binding.root) | ||
| } | ||
|
|
||
| fun init(){ | ||
| binding.locationTV.text = intent.getStringExtra("locationName") | ||
| binding.backBTN.setOnClickListener { | ||
| finish() | ||
| } | ||
| } | ||
| } |
121 changes: 121 additions & 0 deletions
121
...pp/src/main/java/kr/co/landvibe/summer_coding_android/gok5959/adapters/LocationAdapter.kt
This file contains hidden or 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,121 @@ | ||
| package kr.co.landvibe.summer_coding_android.gok5959.adapters | ||
|
|
||
| import android.content.Intent | ||
| import android.util.Log | ||
| import android.view.LayoutInflater | ||
| import android.view.ViewGroup | ||
| import android.widget.Toast | ||
| import androidx.core.content.ContextCompat | ||
| import androidx.recyclerview.widget.DiffUtil | ||
| import androidx.recyclerview.widget.ListAdapter | ||
| import androidx.recyclerview.widget.RecyclerView | ||
| import kr.co.landvibe.summer_coding_android.databinding.FooterGok5959Binding | ||
| import kr.co.landvibe.summer_coding_android.databinding.ItemViewGok5959Binding | ||
| import kr.co.landvibe.summer_coding_android.gok5959.Gok5959LocationinformationActivity | ||
| import kr.co.landvibe.summer_coding_android.gok5959.data.Location | ||
| import kr.co.landvibe.summer_coding_android.gok5959.data.locationItem | ||
| import kr.co.landvibe.summer_coding_android.gok5959.itemTouch.ItemTouchHelperListener | ||
| import kr.co.landvibe.summer_coding_android.gok5959.util.DiffUtilCallback | ||
|
|
||
| class LocationAdapter(private val locationList: MutableList<Location>) : | ||
| ListAdapter<locationItem, RecyclerView.ViewHolder>(DiffUtilCallback()), | ||
| ItemTouchHelperListener { | ||
| lateinit var LocationAdded: String | ||
| val HEADER = 0 | ||
| val ITEM = 1 | ||
| val FOOTER = 2 | ||
gok5959 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { | ||
|
|
||
| return when (viewType) { | ||
| ITEM -> LocationViewHolder(ItemViewGok5959Binding.inflate(LayoutInflater.from( | ||
| parent.context), | ||
| parent, | ||
| false)) | ||
| FOOTER -> FooterViewHolder(FooterGok5959Binding.inflate(LayoutInflater.from( | ||
| parent.context), | ||
| parent, | ||
| false)) | ||
| else -> { | ||
| throw ClassCastException("error") | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
| override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { | ||
| when (holder) { | ||
| is FooterViewHolder -> { | ||
| holder.binding.addBTN.setOnClickListener { | ||
| LocationAdded = holder.binding.addET.text.toString() | ||
| if (LocationAdded.equals("")) { | ||
| Toast.makeText(it.context, "입력하세요", Toast.LENGTH_SHORT).show() | ||
| } else { | ||
| addLocation() | ||
| } | ||
| } | ||
| } | ||
| is LocationViewHolder -> { | ||
| val item = getItem(position) as locationItem.Item | ||
| holder.bind(item) | ||
| holder.binding.locationCTRL.setOnClickListener { | ||
| val tmp : String = holder.binding.locationTV.text.toString() | ||
| val intent = Intent(holder.binding.locationCTRL?.context, | ||
| Gok5959LocationinformationActivity::class.java) | ||
| intent.putExtra("locationName", tmp) | ||
| ContextCompat.startActivity(holder.binding.locationCTRL.context, intent, null) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| override fun getItemViewType(position: Int): Int { | ||
| return when (getItem(position)) { | ||
| is locationItem.Footer -> FOOTER | ||
| is locationItem.Item -> ITEM | ||
| else -> 0 | ||
gok5959 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
|
|
||
| class FooterViewHolder(val binding: FooterGok5959Binding) : | ||
| RecyclerView.ViewHolder(binding.root) { | ||
|
|
||
| } | ||
|
|
||
| class LocationViewHolder(val binding: ItemViewGok5959Binding) : | ||
| RecyclerView.ViewHolder(binding.root) { | ||
|
|
||
| fun bind(item: locationItem.Item) { // | ||
gok5959 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| binding.locationTV.text = item.name | ||
| } | ||
| } | ||
|
|
||
| fun addLocation() { | ||
| val newLocation = Location(LocationAdded, locationList.size + 1.toLong()) | ||
| locationList.add(newLocation) | ||
| addFooterAndSubmitList(locationList) | ||
| } | ||
|
|
||
| override fun onItemMove(from_position: Int, to_position: Int): Boolean { | ||
| val item = locationList[from_position] | ||
|
|
||
| locationList.removeAt(from_position) | ||
| locationList.add(to_position, item) | ||
| addFooterAndSubmitList(locationList) | ||
| return true; | ||
| } | ||
|
|
||
| override fun onItemSwipe(position: Int) { | ||
| TODO("Not yet implemented") | ||
| } | ||
|
|
||
| fun addFooterAndSubmitList(list: MutableList<Location>?) { | ||
| val items = when (list.isNullOrEmpty()) { | ||
| true -> listOf(locationItem.Footer) | ||
| false -> list.map { locationItem.Item(it) } + listOf(locationItem.Footer) | ||
| } | ||
| submitList(items) | ||
| } | ||
| } | ||
|
|
||
6 changes: 6 additions & 0 deletions
6
...g_android/app/src/main/java/kr/co/landvibe/summer_coding_android/gok5959/data/Location.kt
This file contains hidden or 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,6 @@ | ||
| package kr.co.landvibe.summer_coding_android.gok5959.data | ||
|
|
||
| data class Location( | ||
| var name: String, | ||
| var id: Long | ||
| ) |
16 changes: 16 additions & 0 deletions
16
...droid/app/src/main/java/kr/co/landvibe/summer_coding_android/gok5959/data/locationItem.kt
This file contains hidden or 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,16 @@ | ||
| package kr.co.landvibe.summer_coding_android.gok5959.data | ||
|
|
||
| sealed class locationItem{ | ||
| abstract var id: Long | ||
| abstract var name: String | ||
| data class Item(val location: Location) : locationItem() { | ||
| override var id = location.id | ||
| override var name = location.name | ||
|
|
||
| } | ||
| object Footer : locationItem(){ | ||
| override var id = Long.MAX_VALUE | ||
| override var name = "" | ||
| } | ||
| } | ||
|
|
32 changes: 32 additions & 0 deletions
32
...in/java/kr/co/landvibe/summer_coding_android/gok5959/itemTouch/ItemTouchHelperCallback.kt
This file contains hidden or 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,32 @@ | ||
| package kr.co.landvibe.summer_coding_android.gok5959.itemTouch | ||
|
|
||
| import androidx.recyclerview.widget.ItemTouchHelper | ||
| import androidx.recyclerview.widget.RecyclerView | ||
|
|
||
| class ItemTouchHelperCallback(val listener: ItemTouchHelperListener) | ||
| : ItemTouchHelper.Callback() | ||
| { | ||
|
|
||
| override fun getMovementFlags( | ||
| recyclerView: RecyclerView, | ||
| viewHolder: RecyclerView.ViewHolder, | ||
| ): Int { | ||
| val dragFlags = ItemTouchHelper.UP or ItemTouchHelper.DOWN | ||
| val swipeFlags = ItemTouchHelper.LEFT or ItemTouchHelper.RIGHT | ||
| return makeMovementFlags(dragFlags, 0) | ||
| } | ||
|
|
||
| override fun onMove( | ||
| recyclerView: RecyclerView, | ||
| viewHolder: RecyclerView.ViewHolder, | ||
| target: RecyclerView.ViewHolder, | ||
| ): Boolean { | ||
| return listener.onItemMove(viewHolder.adapterPosition, target.adapterPosition) | ||
| } | ||
|
|
||
| override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) { | ||
| listener.onItemSwipe(viewHolder.adapterPosition) | ||
| } | ||
|
|
||
|
|
||
| } |
6 changes: 6 additions & 0 deletions
6
...in/java/kr/co/landvibe/summer_coding_android/gok5959/itemTouch/ItemTouchHelperListener.kt
This file contains hidden or 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,6 @@ | ||
| package kr.co.landvibe.summer_coding_android.gok5959.itemTouch | ||
|
|
||
| interface ItemTouchHelperListener { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| fun onItemMove(from_position : Int, to_position: Int): Boolean | ||
| fun onItemSwipe(position: Int) | ||
| } | ||
18 changes: 18 additions & 0 deletions
18
...d/app/src/main/java/kr/co/landvibe/summer_coding_android/gok5959/util/DiffUtilCallback.kt
This file contains hidden or 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,18 @@ | ||
| package kr.co.landvibe.summer_coding_android.gok5959.util | ||
|
|
||
| import androidx.recyclerview.widget.DiffUtil | ||
| import kr.co.landvibe.summer_coding_android.gok5959.data.Location | ||
| import kr.co.landvibe.summer_coding_android.gok5959.data.locationItem | ||
|
|
||
| class DiffUtilCallback : DiffUtil.ItemCallback<locationItem>(){ | ||
|
|
||
|
|
||
| override fun areItemsTheSame(oldItem: locationItem, newItem: locationItem): Boolean { | ||
| return oldItem.id == newItem.id | ||
| } | ||
|
|
||
| override fun areContentsTheSame(oldItem: locationItem, newItem: locationItem): Boolean { | ||
| return oldItem == newItem | ||
| } | ||
|
|
||
| } |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions
5
summer_coding_android/app/src/main/res/drawable/edge_gok5959.xml
This file contains hidden or 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,5 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <shape xmlns:android="http://schemas.android.com/apk/res/android"> | ||
| <solid android:color="@null"/> | ||
| <stroke android:width="1dp" android:color="#000000"/> | ||
| </shape> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.