Explorar el Código

[이벤트][Common] 참여하기 이미지 업로드후 실제 경로 프리젠터 전달

Hasemi hace 6 años
padre
commit
1636394934

+ 2 - 1
app/src/main/java/kr/co/zumo/app/lifeplus/view/Event.java

@@ -139,6 +139,7 @@ public class Event {
   public static final int ENTRY = 111;
   public static final int IMAGE = 112;
   public static final int DIALOG = 113;
+  public static final int URI = 114;
 
   @Retention(RetentionPolicy.SOURCE)
   @IntDef({
@@ -151,7 +152,7 @@ public class Event {
     SWITCH, BOOK_MARK_DEFAULT, BOOK_MARK_LIST, ADD, MY_COIN_MAIN, MY_PURCHASE_HISTORY, GUIDE, ADD_BUCKET, MY_MAIN_GUEST, COUPON_MALL, CATEGORY_CLICK,
     MY_FAQ, UPDATE, FILTER, CLOSE, HELP, CONTENTS, MORE, BANNER, RECOMMEND, KAKAO_TALK, FACE_BOOK, CODE_COPY, EVENT, TAG, BOOKMARK, ORDER, DEFAULT, COMPLETE_BUCKET,
     LIKE, FRAGMENT_STACK_EMPTY, OVER_VIEW, SHARE, CALL_INFO, LINK, HOME_PAGE, INSTAGRAM, ADDRESS, SCROLL, SORT, TUTORIAL, CLICK_HTML, LAST, PREV, NEXT, REFRESH, MY_EVENT,
-    ING_EVENT, WINNER_ANNOUNCEMENT, COUPON, TODAY, RECT, VOTE, MAIN, SEARCH, COIN, ENTRY, IMAGE, DIALOG
+    ING_EVENT, WINNER_ANNOUNCEMENT, COUPON, TODAY, RECT, VOTE, MAIN, SEARCH, COIN, ENTRY, IMAGE, DIALOG, URI,
 
   })
   public @interface ID {}

+ 18 - 3
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/event/EventQuestionFragment.java

@@ -2,12 +2,15 @@ package kr.co.zumo.app.lifeplus.view.screen.event;
 
 import android.Manifest;
 import android.content.Context;
+import android.content.CursorLoader;
 import android.content.Intent;
 import android.content.pm.PackageManager;
+import android.database.Cursor;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.net.Uri;
 import android.os.Bundle;
+import android.provider.MediaStore;
 import android.provider.Settings;
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
@@ -226,7 +229,6 @@ public class EventQuestionFragment extends FragmentBase<EventQuestionPresenter>
         }
         else {
           if (false == ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), Manifest.permission.READ_EXTERNAL_STORAGE)) {
-            // TODO: 추후 기획 반영 임시로 다시보지 않음 클릭 후 커스텀 알럿 띄움
             presenter.onEvent(new Event.Builder(Event.DIALOG).build());
           }
         }
@@ -248,8 +250,11 @@ public class EventQuestionFragment extends FragmentBase<EventQuestionPresenter>
     if (requestCode == GET_ALBUM_PHOTO) {
       try {
         Uri uri = data.getData();
-        //Uri 프리젠터로 보내기
-        //presenter.onEvent(new Event.Builder(Event.IMAGE ).string(uri.toString()).build());
+        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());
 
         InputStream inputStream = getContext().getContentResolver().openInputStream(data.getData());
         uploadImage = BitmapFactory.decodeStream(inputStream);
@@ -262,6 +267,16 @@ public class EventQuestionFragment extends FragmentBase<EventQuestionPresenter>
     }
   }
 
+  private String getPath(Uri uri) {
+    String[] projection = {MediaStore.Images.Media.DATA};
+    CursorLoader cursorLoader = new CursorLoader(getContext(), uri, projection, null, null, null);
+    Cursor cursor = cursorLoader.loadInBackground();
+    int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
+    cursor.moveToFirst();
+    return cursor.getString(columnIndex);
+  }
+
+
   private String getTimeString(String timeString) {
     return Formatter.format(timeString, EventBean.DATE_FORMAT, "yyyy.MM.dd");
   }

+ 5 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/event/EventQuestionPresenter.java

@@ -1,5 +1,7 @@
 package kr.co.zumo.app.lifeplus.view.screen.event;
 
+import android.util.Log;
+
 import kr.co.zumo.app.R;
 import kr.co.zumo.app.lifeplus.bean.api.EventDetailBean;
 import kr.co.zumo.app.lifeplus.helper.NavigationBar;
@@ -99,6 +101,9 @@ public class EventQuestionPresenter extends Presenter<EventQuestionModel, IEvent
       case Event.DIALOG: //권한 설정 완전 거부시 다이얼로그 임시
         showPermissionCheckDialog();
         break;
+      case Event.URI: //이미지 업로드시 경로
+        Log.w("APP# EventQuestionPresenter | onEventInternal", "| upload image path ===>" + event.getString());
+        break;
       default:
         break;
     }