-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: develop
Are you sure you want to change the base?
Feat1/week3 #7
Changes from all commits
9b0de5c
64e8834
efe233b
de5b231
52e9613
b9a7226
1c8ae88
26dbe8a
6664c58
aa5d3c2
3689e84
4955493
a01b9d6
ddad73b
c51eaf1
95827d4
d6d65e1
373651c
2736fd1
f23443e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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){"λ°μΈλ© μλ¬"} | ||
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. μκΈ°λ 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() | ||
} | ||
} | ||
|
||
|
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
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. μ€ coilμ΄λ μ΄λ―Έμ§λ‘λλ 곡λΆν΄λ³΄λ©΄ μ’μλ§! μνΈ κΏνμ κΈμμ! 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. Glideκ° λ¬΄μ¨ κΈ°λ₯μ νλ ν΄λμ€ μΈκ°μ?? |
||
tvName.text = userUserProfileData.name | ||
tvSelfMessage.text = userUserProfileData.message | ||
} | ||
} | ||
} |
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 | ||
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. μ΄κ²λ 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) { | ||
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. isUserExist μλ°μμΌλ‘ λ°λ‘ 쑰건λ³μλ₯Ό 빼보λ 건 μ΄λ€κ°μ? |
||
MyPageFragment.newInstance(user_id, user_major) | ||
} else { | ||
throw IllegalArgumentException("λ°μ΄ν°κ° μμ΄μ!") | ||
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. λ§μ°¬κ°μ§μ λλ€! 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. μ€.. μλ¬λ₯Ό λμ§κ΅°μ 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. 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
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. 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() | ||
} | ||
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. ν¨μ μͺΌκ° κ±° 보기 νΈνκ³ μ’λ€μ! |
||
|
||
binding.fabShare.setOnClickListener { | ||
Toast.makeText(this, "곡μ νλ μ€", Toast.LENGTH_SHORT).show() | ||
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. 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 | ||
} | ||
} | ||
|
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
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. ν¨μλ‘ λ°λ‘ λΉΌμ£Όμ λ μ’μ λ― ν©λλ€! |
||
} | ||
|
||
override fun onDestroyView() { | ||
_binding = null | ||
super.onDestroyView() | ||
} | ||
} | ||
|
||
|
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 = "μ€λ μμΌν°λΉ!" | ||
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. κ³ λ§ν°λΉ! |
||
), | ||
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 = "μλν°λΉ" | ||
) | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
κΆν νκ°κΉμ§,,! λ©μλ€
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
λ©μλ€... 0-0