|
|
@@ -16,6 +16,7 @@ import android.support.annotation.NonNull;
|
|
|
import android.support.annotation.Nullable;
|
|
|
import android.support.v4.app.ActivityCompat;
|
|
|
import android.support.v4.content.ContextCompat;
|
|
|
+import android.util.Log;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
|
@@ -53,7 +54,6 @@ import kr.co.zumo.app.lifeplus.view.screen.FragmentBase;
|
|
|
public class EventQuestionFragment extends FragmentBase<EventQuestionPresenter> implements IEventQuestionView {
|
|
|
|
|
|
private static final int GET_ALBUM_PHOTO = 1;
|
|
|
- private Bitmap uploadImage;
|
|
|
private LinearLayout layoutContainer;
|
|
|
private LayoutInflater inflater;
|
|
|
private View layoutSubmit;
|
|
|
@@ -98,25 +98,33 @@ public class EventQuestionFragment extends FragmentBase<EventQuestionPresenter>
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
- public void getAlbumImage() {
|
|
|
- Intent intent = new Intent();
|
|
|
- intent.setType("image/*");
|
|
|
- intent.setAction(Intent.ACTION_GET_CONTENT);
|
|
|
- startActivityForResult(intent, GET_ALBUM_PHOTO);
|
|
|
+ public boolean hasStoragePermission() {
|
|
|
+ //갤러리 사용권한 체크
|
|
|
+ return ContextCompat.checkSelfPermission(getContext(), Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void checkPermission() {
|
|
|
- //갤러리 사용권한 체크
|
|
|
- if (ContextCompat.checkSelfPermission(getContext(), Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
|
|
- //권한 없음
|
|
|
- requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE,
|
|
|
- Manifest.permission.READ_EXTERNAL_STORAGE},
|
|
|
- PERMISSION_CHECK);
|
|
|
- }
|
|
|
- else {
|
|
|
- getAlbumImage();
|
|
|
+ public void requestStoragePermission() {
|
|
|
+ requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, PERMISSION_CHECK);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
|
|
+ switch (requestCode) {
|
|
|
+ case PERMISSION_CHECK:
|
|
|
+ if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
|
|
+ presenter.onEvent(new Event.Builder(Event.PERMISSION_GRANTED).build());
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ if (false == ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), Manifest.permission.READ_EXTERNAL_STORAGE)) {
|
|
|
+ presenter.onEvent(new Event.Builder(Event.DIALOG).build());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -181,8 +189,19 @@ public class EventQuestionFragment extends FragmentBase<EventQuestionPresenter>
|
|
|
eventQuestionViewHolder.draw(i, event -> presenter.onEvent(event), eventQuestionBean);
|
|
|
}
|
|
|
|
|
|
- if (null != questionItemView && null != eventQuestionViewHolder) {
|
|
|
- eventQuestionViewHolders.add(eventQuestionViewHolder);
|
|
|
+ if (null == eventQuestionViewHolder) {
|
|
|
+ // dummy : model 과 index 를 맞추기 위해서
|
|
|
+ eventQuestionViewHolder = new EventQuestionViewHolder(null) {
|
|
|
+ @Override
|
|
|
+ public void validate(boolean isValidate) {
|
|
|
+
|
|
|
+ }
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ eventQuestionViewHolders.add(eventQuestionViewHolder);
|
|
|
+
|
|
|
+ if (null != questionItemView) {
|
|
|
layoutContainer.addView(questionItemView);
|
|
|
}
|
|
|
}
|
|
|
@@ -211,30 +230,22 @@ public class EventQuestionFragment extends FragmentBase<EventQuestionPresenter>
|
|
|
|
|
|
}
|
|
|
|
|
|
-
|
|
|
@Override
|
|
|
- public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
|
|
- switch (requestCode) {
|
|
|
- case PERMISSION_CHECK:
|
|
|
- if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
|
|
- getAlbumImage();
|
|
|
- }
|
|
|
- else {
|
|
|
- if (false == ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), Manifest.permission.READ_EXTERNAL_STORAGE)) {
|
|
|
- presenter.onEvent(new Event.Builder(Event.DIALOG).build());
|
|
|
- }
|
|
|
- }
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
+ public void putAlbumImage(int index, Bitmap image) {
|
|
|
+ EventQuestionViewHolder eventQuestionViewHolder = eventQuestionViewHolders.get(index);
|
|
|
+ Log.d("APP# EventQuestionFragment | putAlbumImage", "|" + "hoolder -> " + eventQuestionViewHolder);
|
|
|
+ if (null != eventQuestionViewHolder) {
|
|
|
+ Log.d("APP# EventQuestionFragment | putAlbumImage", "| " + eventQuestionViewHolder.getClass().getSimpleName());
|
|
|
+ eventQuestionViewHolder.setUploadImage(image);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void uploadAlbumImage() {
|
|
|
- if (null != uploadImage) {
|
|
|
-// eventQuestionImageView.setUploadImage(uploadImage);
|
|
|
- }
|
|
|
+ public void requestAlbumImage() {
|
|
|
+ Intent intent = new Intent();
|
|
|
+ intent.setType("image/*");
|
|
|
+ intent.setAction(Intent.ACTION_GET_CONTENT);
|
|
|
+ startActivityForResult(intent, GET_ALBUM_PHOTO);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -243,16 +254,18 @@ public class EventQuestionFragment extends FragmentBase<EventQuestionPresenter>
|
|
|
try {
|
|
|
Uri uri = data.getData();
|
|
|
String urlString = data.getData().getPath();
|
|
|
- // Log.e("APP# EventQuestionFragment | onActivityResult", "| urlString" + urlString); // /external/images/media/196
|
|
|
- //Log.e("APP# EventQuestionFragment | onActivityResult", "| uri" + uri); // content://media/external/images/media/196
|
|
|
- //Log.e("APP# EventQuestionFragment | onActivityResult", "| 실제경로" + getPath(uri));// /storage/emulated/0/Pictures/Screenshots/Screenshot_2018-12-21-10-35-03.jpg
|
|
|
- presenter.onEvent(new Event.Builder(Event.URI).string(getPath(uri)).build());
|
|
|
+ Log.d("APP# EventQuestionFragment | onActivityResult", "| urlString" + urlString); // /external/images/media/196
|
|
|
+ Log.d("APP# EventQuestionFragment | onActivityResult", "| uri" + uri); // content://media/external/images/media/196
|
|
|
+ Log.d("APP# EventQuestionFragment | onActivityResult", "| 실제경로" + getPath(uri));// /storage/emulated/0/Pictures/Screenshots/Screenshot_2018-12-21-10-35-03.jpg
|
|
|
|
|
|
+ // fixme 파일 url 구하기
|
|
|
+
|
|
|
InputStream inputStream = getContext().getContentResolver().openInputStream(data.getData());
|
|
|
- uploadImage = BitmapFactory.decodeStream(inputStream);
|
|
|
+ Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
|
|
|
inputStream.close();
|
|
|
- presenter.onEvent(new Event.Builder(Event.IMAGE).build());
|
|
|
|
|
|
+ String path = getPath(uri);
|
|
|
+ presenter.onImageReceived(bitmap, path);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|