Skip to content

Commit

Permalink
Merge pull request #20 from Nbti/feat-naze
Browse files Browse the repository at this point in the history
[FEAT] 공유 및 완료하기 버튼 구현
  • Loading branch information
NaZe0320 authored Jun 10, 2023
2 parents dfc84ed + e03d5c7 commit d7f2710
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 4 deletions.
2 changes: 2 additions & 0 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 Down
18 changes: 16 additions & 2 deletions app/src/main/java/com/nbit/Idear/text/AiTextAdapter.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package com.nbit.Idear.text

import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.TextView
import androidx.constraintlayout.utils.widget.ImageFilterButton
import androidx.core.content.ContextCompat.startActivity
import androidx.recyclerview.widget.RecyclerView
import com.nbit.Idear.R

class AiTextAdapter: RecyclerView.Adapter<AiTextAdapter.ViewHolder>() {
class AiTextAdapter(private val buttonClickListener: (String, Int) -> Unit): RecyclerView.Adapter<AiTextAdapter.ViewHolder>() {

private val items: MutableList<AiTextResult> = mutableListOf()

Expand All @@ -25,7 +28,6 @@ class AiTextAdapter: RecyclerView.Adapter<AiTextAdapter.ViewHolder>() {
override fun onBindViewHolder(holder: AiTextAdapter.ViewHolder, position: Int) {
val item = items[position]
holder.bind(item)

}

override fun getItemCount(): Int {
Expand All @@ -35,10 +37,22 @@ class AiTextAdapter: RecyclerView.Adapter<AiTextAdapter.ViewHolder>() {
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
private val textView1: TextView = itemView.findViewById(R.id.tv_ai_text)
private val favBtn: ImageFilterButton = itemView.findViewById(R.id.btn_favorite)
private val shareBtn: ImageFilterButton = itemView.findViewById(R.id.btn_share)
private val completeBtn: Button = itemView.findViewById(R.id.btn_complete)

fun bind(item: AiTextResult) {
textView1.text = item.content
favBtn.isSelected = item.favorite

shareBtn.setOnClickListener {
buttonClickListener.invoke(textView1.text.toString(), 1)
}
favBtn.setOnClickListener {
buttonClickListener.invoke(item.content, 0)
}
completeBtn.setOnClickListener {
buttonClickListener.invoke(item.content, 2)
}
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion app/src/main/java/com/nbit/Idear/write/WriteActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,24 @@ package com.nbit.Idear.write

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.lifecycle.ViewModelProvider
import com.nbit.Idear.R
import com.nbit.Idear.databinding.ActivityWriteBinding

class WriteActivity : AppCompatActivity() {
private lateinit var binding: ActivityWriteBinding

//private lateinit var writeViewModel : WriteViewModel
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

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

val repository = WriteRepository()

val viewModelFactory = WriteFactory(repository,this@WriteActivity)
//writeViewModel = ViewModelProvider(this@WriteActivity, viewModelFactory)[WriteViewModel::class.java]

supportFragmentManager.beginTransaction()
.add(R.id.fl_write, WriteFirstFragment()) // fragment_container는 Fragment를 삽입할 레이아웃의 ID입니다.
.commit()
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/com/nbit/Idear/write/WriteFirstFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.fragment.app.activityViewModels
import com.google.android.flexbox.FlexDirection
import com.google.android.flexbox.FlexWrap
import com.google.android.flexbox.FlexboxLayoutManager
Expand All @@ -25,6 +26,8 @@ class WriteFirstFragment : Fragment() {
private var selectItem: String = ""
private var next: Int = 0

//private val viewModel: WriteViewModel by activityViewModels()

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
_binding = FragmentWriteFirstBinding.inflate(inflater, container, false)

Expand Down Expand Up @@ -78,6 +81,14 @@ class WriteFirstFragment : Fragment() {
.addToBackStack("Write")
.commit()
}

// viewModel.test()






return binding.root
}

Expand Down
19 changes: 18 additions & 1 deletion app/src/main/java/com/nbit/Idear/write/WriteFourthFragment.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.nbit.Idear.write

import android.R
import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
Expand All @@ -23,7 +24,23 @@ class WriteFourthFragment : Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
_binding = FragmentWriteFourthBinding.inflate(inflater, container, false)

var aiTextAdapter = AiTextAdapter()
var aiTextAdapter = AiTextAdapter() { aa, type ->
when (type) {
0 -> {

}
1 -> {
val intent= Intent(Intent.ACTION_SEND)
intent.type = "text/plain"
intent.putExtra(Intent.EXTRA_TEXT,aa.trim())
startActivity(Intent.createChooser(intent,"공유하기"))
}
2 -> {
activity?.finish()
}
}

}


val item1 = AiTextResult("1231123123",false)
Expand Down

0 comments on commit d7f2710

Please sign in to comment.