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

Week2 #2

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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

This file was deleted.

3 changes: 0 additions & 3 deletions AndroidAssignment/app/src/main/res/values/strings.xml

This file was deleted.

File renamed without changes.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.sopt.androidassignment

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import org.sopt.androidassignment.databinding.GitFollowerListBinding

class FollowerAdapter : RecyclerView.Adapter<FollowerAdapter.FollowerViewHolder>(){
val userList = mutableListOf<UserData>()

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

override fun onBindViewHolder(holder: FollowerAdapter.FollowerViewHolder, position: Int) {
holder.onBind(userList[position])
}

override fun getItemCount(): Int = userList.size

class FollowerViewHolder(private val binding : GitFollowerListBinding)
: RecyclerView.ViewHolder(binding.root){
fun onBind(data:UserData){
binding.tvFollowerName.text = data.name
binding.tvFollowerIntroduce.text = data.introduction
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.sopt.androidassignment

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.NonNull
import androidx.recyclerview.widget.GridLayoutManager
import org.sopt.androidassignment.databinding.FragmentFollowerListBinding

class FollowerList : Fragment() {
private var _binding:FragmentFollowerListBinding? = null
private val binding get() = _binding!!
private lateinit var followerAdapter: FollowerAdapter

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

override fun onDestroyView() {
super.onDestroyView()
_binding = null
}

private fun initAdapter(){
followerAdapter = FollowerAdapter()

binding.rvFollower.adapter=followerAdapter
followerAdapter.userList.addAll(
listOf(
UserData("권용민", "안드로이드 YB"),
UserData("김용민", "서버 YB"),
UserData("박용민", "IOS YB"),
UserData("최용민", "웹 YB"),
UserData("이용민", "기획 YB"),
UserData("나용민", "디자인 YB")
)
)
followerAdapter.notifyDataSetChanged()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package org.sopt.androidassignment

import android.content.ActivityNotFoundException
import android.content.Intent
import android.net.Uri
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Toast
import org.sopt.androidassignment.databinding.ActivityHomeBinding


class HomeActivity : AppCompatActivity() {
private var position = FIRST_FRAGMENT
private lateinit var binding : ActivityHomeBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

binding = ActivityHomeBinding.inflate(layoutInflater)
val address : Intent = Uri.parse("https://github.com/briandr97").let{webpage->Intent(Intent.ACTION_VIEW, webpage)}

//val webIntent = Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/briandr97"))


binding.btHomeGit.setOnClickListener{
//val intent = Intent(Intent.ACTION_SEND)
//val title = resources.getString(R.string.chooser_title)
//val chooser = createChooser(intent, title)
try{
startActivity(address)
}catch(e:ActivityNotFoundException){
Toast.makeText(this, "실행할 수 있는 앱이 없습니다.", Toast.LENGTH_SHORT).show()
}
}

initTransactionEvent()
setContentView(binding.root)
}

fun initTransactionEvent(){
val fragment1 = FollowerList()
val fragment2 = RepositoryListFragment()
supportFragmentManager.beginTransaction().add(R.id.container_fragment, fragment1).commit()

binding.btHomeFollower.setOnClickListener{
val transaction = supportFragmentManager.beginTransaction()

when(position){
FIRST_FRAGMENT->{
transaction.replace(R.id.container_fragment, fragment1)
position = FIRST_FRAGMENT
}
SECOND_FRAGMENT->{
transaction.replace(R.id.container_fragment, fragment1)
position= FIRST_FRAGMENT
}
}
transaction.commit()
}
binding.btHomeRepository.setOnClickListener{
val transaction = supportFragmentManager.beginTransaction()
when(position){
FIRST_FRAGMENT->{
transaction.replace(R.id.container_fragment, fragment2)
position= SECOND_FRAGMENT
}
SECOND_FRAGMENT->{
transaction.replace(R.id.container_fragment, fragment2)
position= SECOND_FRAGMENT
}
}

transaction.commit()
}
}

companion object{
const val FIRST_FRAGMENT = 1
const val SECOND_FRAGMENT = 2
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.sopt.androidassignment

import android.text.Layout
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import org.sopt.androidassignment.databinding.GitRepositoryListBinding

class RepositoryAdapter : RecyclerView.Adapter<RepositoryAdapter.RepositoryViewHolder>(){
val repoList = mutableListOf<RepositoryData>()

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

override fun onBindViewHolder(holder: RepositoryAdapter.RepositoryViewHolder, position: Int) {
holder.onBind(repoList[position])
}

override fun getItemCount(): Int = repoList.size

class RepositoryViewHolder(private val binding:GitRepositoryListBinding)
:RecyclerView.ViewHolder(binding.root){
fun onBind(data:RepositoryData){
binding.tvRepository.text = data.repo
binding.tvIntro.text = data.intro
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.sopt.androidassignment

data class RepositoryData(
val repo : String, val intro : String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.sopt.androidassignment

import android.annotation.SuppressLint
import android.graphics.drawable.ClipDrawable.VERTICAL
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import org.sopt.androidassignment.databinding.FragmentRepositoryListBinding

class RepositoryListFragment : Fragment() {
private var _binding : FragmentRepositoryListBinding? = null
private val binding get() = _binding!!
private lateinit var repositoryAdapter: RepositoryAdapter
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
_binding = FragmentRepositoryListBinding.inflate(layoutInflater, container, false)
initAdapter()
binding.rvRepository.adapter = repositoryAdapter
binding.rvRepository.layoutManager=GridLayoutManager(activity, 2)
return binding.root
}

override fun onDestroyView() {
super.onDestroyView()
_binding = null
}

private fun initAdapter(){
repositoryAdapter = RepositoryAdapter()

binding.rvRepository.adapter=repositoryAdapter
repositoryAdapter.repoList.addAll(
listOf(
RepositoryData("안드로이드 과제1\n레포지토리", "1주차 과제"),
RepositoryData("안드로이드 과제2\n레포지토리", "글자수 제한을 체크하겠습니다."),
RepositoryData("왕초보 스터디\n레포지토리", "제못제잘 과제"),
RepositoryData("코틀린 스터디\n레포지토리", "코틀린 가만안드.. 과제"),
RepositoryData("솝탁 스터디\n레포지토리", "알고리즘 과제"),
RepositoryData("풋살 스터디\n레포지토리", "개발스터디란 우리가 개발이라는"),

)
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.sopt.androidassignment

data class UserData(
val name : String,
val introduction : String)

Loading