Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/FOR-GRAD/For-Grad-android i…
Browse files Browse the repository at this point in the history
…nto 21-졸업-요건-ui
  • Loading branch information
dkyuuum committed Feb 19, 2024
2 parents 0677c83 + 5bde4d3 commit e0aca97
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 10 deletions.
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />
<!--갤러리 오픈 권한-->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
android:allowBackup="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ class CareerEditActivityFragment : Fragment() {
if (isDeleted) {
//삭제 작업이 완료되면 목록 업데이트
navigate(R.id.action_fragment_edit_activity_to_fragment_career_activity)
Toast.makeText(mContext, "삭제되었습니다.", Toast.LENGTH_SHORT).show()
}
})
}
Expand All @@ -85,7 +84,6 @@ class CareerEditActivityFragment : Fragment() {
if (isUpdated) {
//수정 작업이 완료되면 목록 업데이트
navigate(R.id.action_fragment_edit_activity_to_fragment_career_activity)
Toast.makeText(mContext, "수정되었습니다.", Toast.LENGTH_SHORT).show()
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ class CareerEditCertificateFragment : Fragment() {
if (isDeleted) {
//삭제 작업이 완료되면 목록 업데이트
navigate(R.id.action_fragment_edit_certificate_to_fragment_career_certificate)
Toast.makeText(mContext, "삭제되었습니다.", Toast.LENGTH_SHORT).show()
}
})
}
Expand All @@ -76,7 +75,6 @@ class CareerEditCertificateFragment : Fragment() {
if (isUpdated) {
//수정 작업이 완료되면 목록 업데이트
navigate(R.id.action_fragment_edit_certificate_to_fragment_career_certificate)
Toast.makeText(mContext, "수정되었습니다.", Toast.LENGTH_SHORT).show()
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ class CareerEditContestFragment : Fragment() {
if (isDeleted) {
//삭제 작업이 완료되면 목록 업데이트
navigate(R.id.action_fragment_edit_contest_to_fragment_career_contest)
Toast.makeText(mContext, "삭제되었습니다.", Toast.LENGTH_SHORT).show()
}
})
}
Expand All @@ -83,7 +82,6 @@ class CareerEditContestFragment : Fragment() {
if (isUpdated) {
//수정 작업이 완료되면 목록 업데이트
navigate(R.id.action_fragment_edit_contest_to_fragment_career_contest)
Toast.makeText(mContext, "수정되었습니다.", Toast.LENGTH_SHORT).show()
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ class CareerEditVolunteerFragment : Fragment() {
if (isDeleted) {
//삭제 작업이 완료되면 목록 업데이트
navigate(R.id.action_fragment_edit_volunteer_to_fragment_career_volunteer)
Toast.makeText(mContext, "삭제되었습니다.", Toast.LENGTH_SHORT).show()
}
})
}
Expand All @@ -74,7 +73,6 @@ class CareerEditVolunteerFragment : Fragment() {
if (isUpdated) {
//수정 작업이 완료되면 목록 업데이트
navigate(R.id.action_fragment_edit_volunteer_to_fragment_career_volunteer)
Toast.makeText(mContext, "수정되었습니다.", Toast.LENGTH_SHORT).show()
}
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package umc.com.mobile.project.ui.career

import android.Manifest
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.net.Uri
import android.os.Bundle
import android.provider.OpenableColumns
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.core.content.ContextCompat
import androidx.fragment.app.activityViewModels
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import umc.com.mobile.project.databinding.FragmentUploadBottomBinding
Expand All @@ -26,6 +32,9 @@ class UploadBottomFragment(context: Context, private val viewModelType: Int) :
private val editViewModel: CareerEditActivityViewModel by activityViewModels()
private val binding get() = _binding!!

private val REQUEST_CODE_PERMISSIONS = 10
private val REQUIRED_PERMISSIONS = arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE)

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
Expand All @@ -44,9 +53,28 @@ class UploadBottomFragment(context: Context, private val viewModelType: Int) :
_binding!!.ivUploadBottomClose.setOnClickListener {
dialog!!.dismiss()
}

if (!allPermissionsGranted()) {
requestPermissions(REQUIRED_PERMISSIONS, REQUEST_CODE_PERMISSIONS)
}
return binding.root
}

private fun allPermissionsGranted() = REQUIRED_PERMISSIONS.all {
ContextCompat.checkSelfPermission(requireContext(), it) == PackageManager.PERMISSION_GRANTED
}

override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) {
if (requestCode == REQUEST_CODE_PERMISSIONS) {
if (allPermissionsGranted()) {
// 권한이 모두 부여되었을 때 실행할 코드를 여기에 작성합니다.
} else {
Toast.makeText(requireContext(), "Permissions not granted by the user.", Toast.LENGTH_SHORT).show()
activity?.finish()
}
}
}

private val PICK_IMAGE_MULTIPLE = 2

private fun openGallery() {
Expand All @@ -68,13 +96,20 @@ class UploadBottomFragment(context: Context, private val viewModelType: Int) :
}

private fun createImageFile(uri: Uri): File {
val fileName = "img_" + System.currentTimeMillis() + ".jpg"
val fileName = getFileName(uri)
val directory = requireContext().getExternalFilesDir(null)
val file = File(directory, fileName)

val inputStream = requireContext().contentResolver.openInputStream(uri)
val originalBitmap = BitmapFactory.decodeStream(inputStream)

// 이미지 리사이징
val newWidth = originalBitmap.width / 2
val newHeight = originalBitmap.height / 2
val resizedBitmap = Bitmap.createScaledBitmap(originalBitmap, newWidth, newHeight, true)

val outputStream: OutputStream = FileOutputStream(file)
inputStream?.copyTo(outputStream)
resizedBitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream)

inputStream?.close()
outputStream.close()
Expand Down

0 comments on commit e0aca97

Please sign in to comment.