Remote RemoteModel.PictureHelper

pull/618/head
Alex Baker 7 years ago
parent accbeabe01
commit 84f71d0a8b

@ -85,42 +85,6 @@ abstract public class RemoteModel extends AbstractModel {
return NO_UUID.equals(uuid) || TextUtils.isEmpty(uuid); return NO_UUID.equals(uuid) || TextUtils.isEmpty(uuid);
} }
public static class PictureHelper {
public static JSONObject savePictureJson(final Uri uri) {
try {
JSONObject json = new JSONObject();
json.put("uri", uri.toString());
return json;
} catch (JSONException e) {
Timber.e(e, e.getMessage());
}
return null;
}
public static Uri getPictureUri(String value) {
try {
if (value == null) {
return null;
}
if (value.contains("uri") || value.contains("path")) {
JSONObject json = new JSONObject(value);
if (json.has("uri")) {
return Uri.parse(json.getString("uri"));
}
if (json.has("path")) {
String path = json.getString("path");
return Uri.fromFile(new File(path));
}
}
return null;
} catch (JSONException e) {
Timber.e(e, e.getMessage());
return null;
}
}
}
public String getUuidProperty() { public String getUuidProperty() {
return getValue(UUID_PROPERTY); return getValue(UUID_PROPERTY);
} }

@ -8,9 +8,15 @@ import android.net.Uri;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import org.json.JSONException;
import org.json.JSONObject;
import org.tasks.backup.XmlReader; import org.tasks.backup.XmlReader;
import org.tasks.backup.XmlWriter; import org.tasks.backup.XmlWriter;
import java.io.File;
import timber.log.Timber;
@Entity(tableName = "userActivity") @Entity(tableName = "userActivity")
public class UserActivity implements Parcelable { public class UserActivity implements Parcelable {
@ -142,7 +148,7 @@ public class UserActivity implements Parcelable {
} }
public Uri getPictureUri() { public Uri getPictureUri() {
return RemoteModel.PictureHelper.getPictureUri(picture); return getPictureUri(picture);
} }
public static final Creator<UserActivity> CREATOR = new Creator<UserActivity>() { public static final Creator<UserActivity> CREATOR = new Creator<UserActivity>() {
@ -173,4 +179,26 @@ public class UserActivity implements Parcelable {
dest.writeLong(created); dest.writeLong(created);
dest.writeLong(deleted); dest.writeLong(deleted);
} }
private static Uri getPictureUri(String value) {
try {
if (value == null) {
return null;
}
if (value.contains("uri") || value.contains("path")) {
JSONObject json = new JSONObject(value);
if (json.has("uri")) {
return Uri.parse(json.getString("uri"));
}
if (json.has("path")) {
String path = json.getString("path");
return Uri.fromFile(new File(path));
}
}
return null;
} catch (JSONException e) {
Timber.e(e, e.getMessage());
return null;
}
}
} }

@ -27,6 +27,7 @@ import com.todoroo.astrid.data.RemoteModel;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.UserActivity; import com.todoroo.astrid.data.UserActivity;
import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import org.tasks.R; import org.tasks.R;
import org.tasks.activities.CameraActivity; import org.tasks.activities.CameraActivity;
@ -46,6 +47,7 @@ import butterknife.ButterKnife;
import butterknife.OnClick; import butterknife.OnClick;
import butterknife.OnEditorAction; import butterknife.OnEditorAction;
import butterknife.OnTextChanged; import butterknife.OnTextChanged;
import timber.log.Timber;
import static org.tasks.files.FileHelper.getPathFromUri; import static org.tasks.files.FileHelper.getPathFromUri;
import static org.tasks.files.ImageHelper.sampleBitmap; import static org.tasks.files.ImageHelper.sampleBitmap;
@ -221,7 +223,7 @@ public class CommentBarFragment extends TaskEditControlFragment {
} }
String picture = null; String picture = null;
if (pendingCommentPicture != null) { if (pendingCommentPicture != null) {
JSONObject pictureJson = RemoteModel.PictureHelper.savePictureJson(pendingCommentPicture); JSONObject pictureJson = savePictureJson(pendingCommentPicture);
if (pictureJson != null) { if (pictureJson != null) {
picture = pictureJson.toString(); picture = pictureJson.toString();
} }
@ -236,6 +238,17 @@ public class CommentBarFragment extends TaskEditControlFragment {
callback.addComment(message, actionCode, picture); callback.addComment(message, actionCode, picture);
} }
private static JSONObject savePictureJson(final Uri uri) {
try {
JSONObject json = new JSONObject();
json.put("uri", uri.toString());
return json;
} catch (JSONException e) {
Timber.e(e, e.getMessage());
}
return null;
}
private void resetPictureButton() { private void resetPictureButton() {
TypedValue typedValue = new TypedValue(); TypedValue typedValue = new TypedValue();
getActivity().getTheme().resolveAttribute(R.attr.actionBarPrimaryText, typedValue, true); getActivity().getTheme().resolveAttribute(R.attr.actionBarPrimaryText, typedValue, true);

Loading…
Cancel
Save