Skip to content

Commit d169a47

Browse files
committed
Merge branch 'develop'
2 parents b4773df + cf5e8c3 commit d169a47

File tree

10 files changed

+124
-48
lines changed

10 files changed

+124
-48
lines changed

.idea/misc.xml

Lines changed: 19 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ dependencies {
109109
implementation 'com.squareup.okhttp3:logging-interceptor:4.9.0'
110110

111111
// espresso
112+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
112113
androidTestImplementation 'androidx.test:runner:1.4.0'
113114
androidTestImplementation 'androidx.test:rules:1.4.0'
114115

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package org.inu.events
2+
3+
import android.view.View
4+
import android.view.ViewGroup
5+
import androidx.test.espresso.Espresso
6+
import androidx.test.espresso.Espresso.onView
7+
import androidx.test.espresso.action.ViewActions
8+
import androidx.test.espresso.action.ViewActions.click
9+
import androidx.test.espresso.action.ViewActions.typeText
10+
import androidx.test.espresso.matcher.ViewMatchers
11+
import androidx.test.espresso.matcher.ViewMatchers.withId
12+
import androidx.test.ext.junit.runners.AndroidJUnit4
13+
import androidx.test.filters.LargeTest
14+
import androidx.test.rule.ActivityTestRule
15+
import org.junit.Rule
16+
import org.junit.Test
17+
import org.junit.runner.RunWith
18+
19+
/**
20+
* 에뮬레이터 언어 설정 한국어로 설정해 주세요!
21+
*/
22+
23+
@RunWith(AndroidJUnit4::class)
24+
@LargeTest
25+
class PostEventTest {
26+
@get:Rule
27+
val activityRule = ActivityTestRule(MainActivity::class.java)
28+
29+
@Test
30+
fun test() {
31+
// login()
32+
onView(withId(R.id.floating_action_button)).perform(click())
33+
onView(withId(R.id.checkBox_image)).perform(click())
34+
onView(withId(R.id.button_complete)).perform(click())
35+
onView(withId(R.id.editText_title)).perform(typeText("wpahrdldi~~~!!"))
36+
onView(withId(R.id.editText_host)).perform(typeText("doqtpsxj"))
37+
onView(withId(R.id.editText_target)).perform(typeText("sjaksdhaus eho!!"))
38+
onView(withId(R.id.checkBox)).perform(click())
39+
onView(withId(R.id.checkBox_location)).perform(click())
40+
onView(withId(R.id.spinner_classification)).perform(click())
41+
// onView(ViewMatchers.withSpinnerText("동아리/소모임")).perform(click())
42+
}
43+
44+
fun login() {
45+
onView(withId(R.id.imageView)).perform(click())
46+
47+
}
48+
}

app/src/main/AndroidManifest.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
77
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
88
<uses-permission android:name="android.permission.WAKE_LOCK" />
9-
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
109

1110
<application
1211
android:name=".MyApplication"
@@ -91,7 +90,6 @@
9190
<action android:name="com.google.firebase.MESSAGING_EVENT" />
9291
</intent-filter>
9392
</service>
94-
<service android:name=".service.AlarmService" />
9593
</application>
9694

9795
</manifest>

app/src/main/java/org/inu/events/UpdateProfileActivity.kt

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@ import androidx.activity.viewModels
66
import com.bumptech.glide.Glide
77
import okhttp3.MediaType.Companion.toMediaType
88
import okhttp3.MultipartBody
9-
import okhttp3.RequestBody.Companion.asRequestBody
109
import org.inu.events.base.BaseActivity
11-
import org.inu.events.common.util.URIPathHelper
10+
import org.inu.events.common.extension.asRequestBody
11+
import org.inu.events.common.extension.toast
1212
import org.inu.events.databinding.ActivityUpdateProfileBinding
1313
import org.inu.events.lib.actionsheet.UniActionSheet
1414
import org.inu.events.viewmodel.UpdateProfileViewModel
15-
import java.io.File
1615

1716

1817
class UpdateProfileActivity : BaseActivity<ActivityUpdateProfileBinding>() {
@@ -24,13 +23,21 @@ class UpdateProfileActivity : BaseActivity<ActivityUpdateProfileBinding>() {
2423
if (result.resultCode == RESULT_OK) {
2524
try {
2625
val uri = result.data?.data
26+
if (uri == null) {
27+
toast("이미지를 가져오지 못 하였습니다 ㅠㅡㅠ")
28+
return@registerForActivityResult
29+
}
30+
2731
Glide.with(this).load(uri).into(binding.photoUpdate)
2832

29-
val filePath = URIPathHelper().getPath(this, uri!!)
30-
val file = File(filePath!!)
33+
val stream = contentResolver.openInputStream(uri)
34+
if (stream == null) {
35+
toast("입력 스트림을 열지 못 하였습니다 ㅠㅡㅠ")
36+
return@registerForActivityResult
37+
}
3138

32-
val requestFile = file.asRequestBody("multipart/form-data".toMediaType())
33-
val image = MultipartBody.Part.createFormData("file", file.name, requestFile)
39+
val requestFile = stream.asRequestBody("multipart/form-data".toMediaType())
40+
val image = MultipartBody.Part.createFormData("file", "file", requestFile)
3441
viewModel.uploadImage(image)
3542
} catch (e: Exception) {
3643
e.printStackTrace()
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package org.inu.events.common.extension
2+
3+
import okhttp3.MediaType
4+
import okhttp3.RequestBody
5+
import okio.BufferedSink
6+
import java.io.InputStream
7+
8+
fun InputStream.asRequestBody(contentType: MediaType? = null): RequestBody {
9+
val byteArray = this.readBytes()
10+
11+
return object : RequestBody() {
12+
override fun contentType() = contentType
13+
14+
override fun contentLength() = byteArray.size.toLong()
15+
16+
override fun writeTo(sink: BufferedSink) {
17+
sink.write(byteArray)
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)