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

Feat1/week3 #7

Open
wants to merge 20 commits into
base: develop
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
8 changes: 7 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,16 @@ android {
kotlinOptions {
jvmTarget = '11'
}
buildFeatures {
viewBinding true
}
}

dependencies {

implementation 'com.github.bumptech.glide:glide:4.12.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2"
implementation "androidx.fragment:fragment-ktx:1.6.1"
implementation 'androidx.core:core-ktx:1.8.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.5.0'
Expand Down
18 changes: 16 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Comment on lines +5 to +6

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

κΆŒν•œ ν—ˆκ°€κΉŒμ§€,,! λ©‹μžˆλ‹€

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

λ©‹μžˆλ‹€... 0-0


<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
Expand All @@ -14,13 +17,24 @@
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
android:exported="false">
</activity>
<activity android:name=".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=".SignUpActivity"
android:exported="false">
</activity>

<activity
android:name=".HomeActivity"
android:exported="true">
</activity>

</application>

</manifest>
35 changes: 35 additions & 0 deletions app/src/main/java/org/sopt/dosopttemplate/DoAndroidFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.sopt.dosopttemplate

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import org.sopt.dosopttemplate.databinding.FragmentDoAndroidBinding


class DoAndroidFragment : Fragment() {
private var _binding : FragmentDoAndroidBinding ? = null
private val binding: FragmentDoAndroidBinding
get() = requireNotNull(_binding){"바인딩 μ—λŸ¬"}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μš”κΈ°λŠ” string으둜 λΊ΄μ£Όμ‹œλ©΄ 쒋을 것 κ°™μ•„μš”~ getString(R.string.xxx)으둜 μ‚¬μš©ν•˜μ‹€ 수 μžˆμŠ΅λ‹ˆλ‹€!


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

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

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


19 changes: 19 additions & 0 deletions app/src/main/java/org/sopt/dosopttemplate/FriendViewHolder.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.sopt.dosopttemplate

import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import org.sopt.dosopttemplate.databinding.ItemFriendBinding

class FriendViewHolder(private val binding: ItemFriendBinding) :
RecyclerView.ViewHolder(binding.root) {

fun onBind(userUserProfileData: UserProfile.User) {
with(binding) {
Glide.with(ivProfile)
.load(userUserProfileData.profileImage)
.into(ivProfile)
Comment on lines +12 to +14
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

였 coilμ΄λž€ μ΄λ―Έμ§€λ‘œλ”λ„ 곡뢀해보면 쒋을덧! μ†νŠΈ κΏ€νŒμ— κΈ€μžˆμŒ!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Glideκ°€ 무슨 κΈ°λŠ₯을 ν•˜λŠ” 클래슀 μΈκ°€μš”??

tvName.text = userUserProfileData.name
tvSelfMessage.text = userUserProfileData.message
}
}
}
174 changes: 174 additions & 0 deletions app/src/main/java/org/sopt/dosopttemplate/HomeActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
package org.sopt.dosopttemplate

import android.animation.ObjectAnimator
import android.content.pm.PackageManager
import android.graphics.Bitmap
import android.graphics.Canvas
import android.os.Bundle
import android.os.Environment
import android.provider.MediaStore
import android.util.Log
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import org.sopt.dosopttemplate.databinding.ActivityHomeBinding
import java.io.File
import java.io.FileOutputStream
import java.io.IOException
import android.Manifest


class HomeActivity : AppCompatActivity() {
private lateinit var binding: ActivityHomeBinding
private var openFAB = false
private val WRITE_EXTERNAL_STORAGE_REQUEST_CODE = 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이것도 companion object에 λ„£μœΌλ©΄ 더 쒋을 것 κ°™μŠ΅λ‹ˆλ‹€!

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityHomeBinding.inflate(layoutInflater)
setContentView(binding.root)

val currentFragment = supportFragmentManager.findFragmentById(R.id.fcv_home)
if (currentFragment == null) {
supportFragmentManager.beginTransaction()
.add(R.id.fcv_home, HomeFragment())
.commit()
}
clickBottomNavigation()
setCLICKFAB()
checkManageExternalStoragePermission()
}

companion object {
fun createMyPageFragment(user_id: String?, user_major: String?): MyPageFragment {
return if (user_id != null && user_major != null) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isUserExist μš”λŸ°μ‹μœΌλ‘œ λ”°λ‘œ μ‘°κ±΄λ³€μˆ˜λ₯Ό λΉΌλ³΄λŠ” 건 μ–΄λ–€κ°€μš”?

MyPageFragment.newInstance(user_id, user_major)
} else {
throw IllegalArgumentException("데이터가 μ—†μ–΄μš”!")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

λ§ˆμ°¬κ°€μ§€μž…λ‹ˆλ‹€!

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

였.. μ—λŸ¬λ₯Ό λ˜μ§€κ΅°μš”

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error handlingκΉŒμ§€ μΆ”κ°€ν•œ κ±° μ’‹λ„€μš”!! λ°°μ›Œκ°‘λ‹ˆλ‹€...끙차끙차

}
}
}

private fun clickBottomNavigation() {
binding.bnvHome.setOnItemSelectedListener {
when (it.itemId) {
R.id.menu_home -> {
replaceFragment(HomeFragment())
true
}

R.id.menu_do_android -> {
replaceFragment(DoAndroidFragment())
true
}

R.id.menu_mypage -> {
try {
val user_id = intent?.getStringExtra("user_id")
val user_major = intent?.getStringExtra("user_major")
val myPageFragment = createMyPageFragment(user_id, user_major)
replaceFragment(myPageFragment)
} catch (e: IllegalArgumentException) {
Toast.makeText(this, e.message, Toast.LENGTH_SHORT).show()
}
true
}

else -> false
Comment on lines +56 to +79

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sealed class κ³΅λΆ€ν•΄λ³΄μ‹œλŠ” κ±Έ μΆ”μ²œλ“œλ¦½λ‹ˆλ‹€! elseκ°€ 없어도 λœλ‹€λŠ” 점,,γ…Žγ…Ž

}
}
}

private fun replaceFragment(fragment: Fragment) {
supportFragmentManager.beginTransaction()
.replace(R.id.fcv_home, fragment)
.commit()

}

private fun setCLICKFAB() {
binding.fabMain.setOnClickListener {
eventFAB()
}
binding.fabCapture.setOnClickListener {
takeScreenshot()
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ν•¨μˆ˜ μͺΌκ°  κ±° 보기 νŽΈν•˜κ³  μ’‹λ„€μš”!


binding.fabShare.setOnClickListener {
Toast.makeText(this, "κ³΅μœ ν•˜λŠ” 쀑", Toast.LENGTH_SHORT).show()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

string,,κ·€μ‹ ,,λ“±μž₯

}
}

private fun eventFAB() {
if (openFAB) {
ObjectAnimator.ofFloat(binding.fabShare, "translationY", 0f).apply { start() }
ObjectAnimator.ofFloat(binding.fabCapture, "translationY", 0f).apply { start() }
} else {
ObjectAnimator.ofFloat(binding.fabShare, "translationY", -400f).apply { start() }
ObjectAnimator.ofFloat(binding.fabCapture, "translationY", -200f).apply { start() }
}
openFAB = !openFAB
}

private fun checkManageExternalStoragePermission() {
val managePermission = ContextCompat.checkSelfPermission(
this,
Manifest.permission.WRITE_EXTERNAL_STORAGE
)

if (managePermission != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(
this,
arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE),
WRITE_EXTERNAL_STORAGE_REQUEST_CODE
)
}
}
override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<out String>,
grantResults: IntArray
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)

if (requestCode == WRITE_EXTERNAL_STORAGE_REQUEST_CODE) {
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Toast.makeText(this, "κΆŒν•œμ΄ ν—ˆμš©λ˜μ—ˆμŠ΅λ‹ˆλ‹€.", Toast.LENGTH_SHORT).show()
} else {
Toast.makeText(this, "κΆŒν•œμ΄ κ±°λΆ€λ˜μ—ˆμŠ΅λ‹ˆλ‹€.", Toast.LENGTH_SHORT).show()
}
}
}

private fun takeScreenshot() {
val rootView = window.decorView.rootView
val screenShot: File? = captureScreen(rootView)
}
private fun captureScreen(view: View): File? {
val screenBitmap = Bitmap.createBitmap(view.width, view.height, Bitmap.Config.ARGB_8888)
val canvas = Canvas(screenBitmap)
view.draw(canvas)

if (screenBitmap.byteCount == 0) {
return null
}

val filename = "Profilescreenshot.png"
val file = File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), filename)

try {
val output = FileOutputStream(file)
screenBitmap.compress(Bitmap.CompressFormat.PNG, 100, output)
output.close()

} catch (e: IOException) {
e.printStackTrace()
return null
}

return file
}
}

41 changes: 41 additions & 0 deletions app/src/main/java/org/sopt/dosopttemplate/HomeFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.sopt.dosopttemplate

import MainAdapter
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.viewModels
import org.sopt.dosopttemplate.databinding.FragmentHomeBinding

class HomeFragment : Fragment() {
private var _binding: FragmentHomeBinding? = null
private val binding: FragmentHomeBinding
get() = requireNotNull(_binding) { "바인딩 μ—λŸ¬" }

private val viewModel by viewModels<HomeViewModel>()

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

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val MainAdapter = MainAdapter(requireContext())
binding.rvFriends.adapter = MainAdapter
MainAdapter.profileList = viewModel.mockUserProfileLists
Comment on lines +30 to +32

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ν•¨μˆ˜λ‘œ λ”°λ‘œ 빼주셔도 쒋을 λ“― ν•©λ‹ˆλ‹€!

}

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


68 changes: 68 additions & 0 deletions app/src/main/java/org/sopt/dosopttemplate/HomeViewModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package org.sopt.dosopttemplate

import androidx.lifecycle.ViewModel

class HomeViewModel : ViewModel() {
val mockUserProfileLists = mutableListOf<UserProfile>(
UserProfile.My (
profileImage = R.drawable.boong1,
name = "μ‘°μ„Έμ—°",
message = "λΆ•μ–΄μ˜ κ³„μ ˆν‹°λΉ„",
),
UserProfile.User(
profileImage = R.drawable.myimage,
name = "κ²½μ§€ν˜„",
message = "λΉ„ν‹°λΉ„νƒ€μ˜€λ°±"
),
UserProfile.User(
profileImage = R.drawable.myimage,
name = "박강희",
message = "였늘 생일티비!"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고맙티비!

),
UserProfile.User(
profileImage = R.drawable.myimage,
name = "이삭",
message = "μ•ˆλ“œμ§±ν‹°λΉ„"
),
UserProfile.User(
profileImage = R.drawable.myimage,
name = "박동민",
message = "일본티비"
),
UserProfile.User(
profileImage = R.drawable.myimage,
name = "λΆ•μ–΄λΉ΅",
message = "슈크림근본"
),
UserProfile.User(
profileImage = R.drawable.myimage,
name = "λΆ•μ–΄",
message = "예?"
),
UserProfile.User(
profileImage = R.drawable.myimage,
name = "λΆ•",
message = "λΆ•λΆ•μ•„"
),
UserProfile.User(
profileImage = R.drawable.myimage,
name = "μ‹œν—˜",
message = "λ©ˆμΆ°ν‹°λΉ„"
),
UserProfile.User(
profileImage = R.drawable.myimage,
name = "μˆ™λŒ€",
message = "λˆˆμ†‘ν‹°λΉ„"
),
UserProfile.User(
profileImage = R.drawable.myimage,
name = "μƒˆλ²½",
message = "λ°°κ³ ν””ν‹°λΉ„"
),
UserProfile.User(
profileImage = R.drawable.myimage,
name = "μ†νŠΈ",
message = "μ•ˆλ“œν‹°λΉ„"
)
)
}
Loading