diff --git a/app/src/main/java/com/hapramp/ui/activity/CreateArticleActivity.java b/app/src/main/java/com/hapramp/ui/activity/CreateArticleActivity.java index 2d1ec6ad..21dc9b31 100644 --- a/app/src/main/java/com/hapramp/ui/activity/CreateArticleActivity.java +++ b/app/src/main/java/com/hapramp/ui/activity/CreateArticleActivity.java @@ -33,6 +33,7 @@ import com.hapramp.utils.ConnectionUtils; import com.hapramp.utils.Constants; import com.hapramp.utils.GoogleImageFilePathReader; +import com.hapramp.utils.ImageRotationHandler; import com.hapramp.utils.MomentsUtils; import com.hapramp.utils.PostHashTagPreprocessor; import com.hapramp.views.editor.LinkInsertDialog; @@ -51,7 +52,7 @@ import static xute.markdeditor.Styles.TextComponentStyle.NORMAL; -public class CreateArticleActivity extends AppCompatActivity implements SteemPostCreator.SteemPostCreatorCallback, EditorControlBar.EditorControlListener, DraftsHelper.DraftsHelperCallback { +public class CreateArticleActivity extends AppCompatActivity implements SteemPostCreator.SteemPostCreatorCallback, EditorControlBar.EditorControlListener, DraftsHelper.DraftsHelperCallback, ImageRotationHandler.ImageRotationOperationListner { public static final String EXTRA_KEY_DRAFT_ID = "draftId"; public static final String EXTRA_KEY_DRAFT_JSON = "draftJson"; private static final int REQUEST_IMAGE_SELECTOR = 119; @@ -100,6 +101,8 @@ public class CreateArticleActivity extends AppCompatActivity implements SteemPos private boolean leftActivityWithPurpose = false; private boolean shouldSaveOrUpdateDraft = true; + private ImageRotationHandler imageRotationHandler; + private Handler handler; @Override protected void onCreate(Bundle savedInstanceState) { @@ -112,7 +115,10 @@ protected void onCreate(Bundle savedInstanceState) { } private void init() { + handler = new Handler(); draftsHelper = new DraftsHelper(); + imageRotationHandler = new ImageRotationHandler(this); + imageRotationHandler.setImageRotationOperationListner(this); draftsHelper.setDraftsHelperCallback(this); progressDialog = new ProgressDialog(this); articleCategoryView.initCategory(); @@ -332,14 +338,6 @@ private boolean checkValidSaveOption(DraftModel draftModel) { return false; } - private void updateDraft() { - DraftModel draftModel = markDEditor.getDraft(); - String draftTitle = articleTitleEt.getText().toString(); - draftModel.setDraftTitle(draftTitle); - draftModel.setDraftId(mDraftId); - draftsHelper.updateBlogDraft(draftModel); - } - private void closeEditor() { showProgressDialog(false, ""); AnalyticsUtil.logEvent(AnalyticsParams.EVENT_CREATE_ARTICLE); @@ -351,6 +349,14 @@ public void run() { }, 1000); } + private void updateDraft() { + DraftModel draftModel = markDEditor.getDraft(); + String draftTitle = articleTitleEt.getText().toString(); + draftModel.setDraftTitle(draftTitle); + draftModel.setDraftId(mDraftId); + draftsHelper.updateBlogDraft(draftModel); + } + private void toast(String s) { Toast.makeText(this, s, Toast.LENGTH_LONG).show(); } @@ -390,25 +396,11 @@ private void handleImageResult(final Intent intent) { @Override public void run() { final String filePath = GoogleImageFilePathReader.getImageFilePath(CreateArticleActivity.this, intent); - handler.post(new Runnable() { - @Override - public void run() { - addImage(filePath); - } - }); + imageRotationHandler.checkOrientationAndFixImage(filePath, 0); } }.start(); } - public void addImage(String filePath) { - try { - markDEditor.insertImage(filePath); - } - catch (Exception e) { - e.printStackTrace(); - } - } - @Override public void onBackPressed() { showExistAlert(); @@ -527,4 +519,23 @@ public void onDraftUpdated(boolean success) { public void onDraftDeleted(boolean success) { } + + @Override + public void onImageRotationFixed(final String filePath, boolean fileShouldBeDeleted, long uid) { + handler.post(new Runnable() { + @Override + public void run() { + addImage(filePath); + } + }); + } + + public void addImage(String filePath) { + try { + markDEditor.insertImage(filePath); + } + catch (Exception e) { + e.printStackTrace(); + } + } } diff --git a/app/src/main/java/com/hapramp/ui/activity/ParticipateEditorActivity.java b/app/src/main/java/com/hapramp/ui/activity/ParticipateEditorActivity.java index 569aa62d..49afc97e 100644 --- a/app/src/main/java/com/hapramp/ui/activity/ParticipateEditorActivity.java +++ b/app/src/main/java/com/hapramp/ui/activity/ParticipateEditorActivity.java @@ -35,13 +35,13 @@ import com.hapramp.api.URLS; import com.hapramp.models.CompetitionEntryConfirmationBody; import com.hapramp.models.CompetitionEntryResponse; -import com.hapramp.notification.NotificationSubscriber; import com.hapramp.preferences.HaprampPreferenceManager; import com.hapramp.steem.PermlinkGenerator; import com.hapramp.steem.SteemPostCreator; import com.hapramp.utils.ConnectionUtils; import com.hapramp.utils.Constants; import com.hapramp.utils.GoogleImageFilePathReader; +import com.hapramp.utils.ImageRotationHandler; import com.hapramp.utils.MomentsUtils; import com.hapramp.utils.PostHashTagPreprocessor; import com.hapramp.views.editor.LinkInsertDialog; @@ -61,7 +61,7 @@ import static xute.markdeditor.Styles.TextComponentStyle.NORMAL; -public class ParticipateEditorActivity extends AppCompatActivity implements EditorControlBar.EditorControlListener, SteemPostCreator.SteemPostCreatorCallback { +public class ParticipateEditorActivity extends AppCompatActivity implements EditorControlBar.EditorControlListener, SteemPostCreator.SteemPostCreatorCallback, ImageRotationHandler.ImageRotationOperationListner { public static final String EXTRA_COMPETITION_ID = "competition_id"; public static final String EXTRA_COMPETITION_TITLE = "competition_title"; @@ -112,6 +112,8 @@ public class ParticipateEditorActivity extends AppCompatActivity implements Edit private String mCompetitionHashtag; private String mCompetitionId; private String mCompetitionTitle; + private ImageRotationHandler imageRotationHandler; + private Handler handler; @Override protected void onCreate(Bundle savedInstanceState) { @@ -134,7 +136,10 @@ private void collectCompetitionExtras() { } private void init() { + handler = new Handler(); progressDialog = new ProgressDialog(this); + imageRotationHandler = new ImageRotationHandler(this); + imageRotationHandler.setImageRotationOperationListner(this); articleCategoryView.initCategory(); setContestInfo(); editorControlBar.setEditorControlListener(this); @@ -429,25 +434,15 @@ private void openGallery() { } private void handleImageResult(final Intent intent) { - final Handler handler = new Handler(); new Thread() { @Override public void run() { final String filePath = GoogleImageFilePathReader.getImageFilePath(ParticipateEditorActivity.this, intent); - handler.post(new Runnable() { - @Override - public void run() { - addImage(filePath); - } - }); + imageRotationHandler.checkOrientationAndFixImage(filePath, 0); } }.start(); } - public void addImage(String filePath) { - markDEditor.insertImage(filePath); - } - @Override public void onInsertImageClicked() { openGallery(); @@ -473,4 +468,18 @@ public void onLinkAdded(String text, String link) { public void onPointerCaptureChanged(boolean hasCapture) { } + + @Override + public void onImageRotationFixed(final String filePath, boolean fileShouldBeDeleted, long uid) { + handler.post(new Runnable() { + @Override + public void run() { + addImage(filePath); + } + }); + } + + public void addImage(String filePath) { + markDEditor.insertImage(filePath); + } } diff --git a/app/src/main/java/com/hapramp/utils/FilePathUtils.java b/app/src/main/java/com/hapramp/utils/FilePathUtils.java index b75a2d8c..1f075dff 100644 --- a/app/src/main/java/com/hapramp/utils/FilePathUtils.java +++ b/app/src/main/java/com/hapramp/utils/FilePathUtils.java @@ -4,6 +4,7 @@ import android.annotation.TargetApi; import android.content.ContentUris; import android.content.Context; +import android.database.Cursor; import android.net.Uri; import android.os.Build; import android.os.Environment; @@ -126,11 +127,25 @@ public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) { + Cursor cursor = null; + final String column = "_data"; + final String[] projection = {column}; try { - returnPathAferSavingFile(context, uri); + cursor = context.getContentResolver().query(uri, projection, + selection, selectionArgs, null); + if (cursor != null && cursor.moveToFirst()) { + final int index = cursor.getColumnIndexOrThrow(column); + String col = cursor.getString(index); + if (col != null) { + return col; + } else { + returnPathAferSavingFile(context, uri); + } + } } catch (Exception e) { e.printStackTrace(); + returnPathAferSavingFile(context, uri); } return nopath; } diff --git a/app/src/main/java/com/hapramp/utils/ImageRotationHandler.java b/app/src/main/java/com/hapramp/utils/ImageRotationHandler.java index 4e2a06d0..975cca91 100644 --- a/app/src/main/java/com/hapramp/utils/ImageRotationHandler.java +++ b/app/src/main/java/com/hapramp/utils/ImageRotationHandler.java @@ -5,8 +5,6 @@ import android.graphics.BitmapFactory; import android.graphics.Matrix; import android.media.ExifInterface; -import android.util.Log; - import java.io.File; import java.io.FileOutputStream; import java.io.IOException;