aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de
diff options
context:
space:
mode:
authorsteckbrief <steckbrief@chefmail.de>2015-11-03 21:33:14 +0100
committersteckbrief <steckbrief@chefmail.de>2015-11-03 21:33:14 +0100
commit0575767152abc391fd1d0241d9cbae154236df70 (patch)
treed4530ebbdb2de9ed0f0c41eb008a712edba6d7f6 /src/main/java/de
parent389e3d4f0f5116f5ea22cc7c5e8cec1e6c791e3a (diff)
parentb22d863c362bb6492240700c0f69f1a5d926f46b (diff)
Merge remote-tracking branch 'remotes/origin/trz/rename' into trz/rebase
Diffstat (limited to 'src/main/java/de')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ConversationsPlusPreferences.java14
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/enums/UserDecision.java10
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/dialogs/MessageDetailsDialog.java3
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/dialogs/UserDecisionDialog.java70
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/listeners/ResizePictureUserDecisionListener.java97
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/listeners/ShareWithResizePictureUserDecisionListener.java48
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/listeners/UserDecisionListener.java12
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/utils/FileHelper.java43
8 files changed, 296 insertions, 1 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/ConversationsPlusPreferences.java b/src/main/java/de/thedevstack/conversationsplus/ConversationsPlusPreferences.java
index b20cfb8f..b7b7fe47 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ConversationsPlusPreferences.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ConversationsPlusPreferences.java
@@ -4,6 +4,7 @@ import android.content.SharedPreferences;
import java.util.Set;
+import de.thedevstack.conversationsplus.enums.UserDecision;
import de.tzur.conversations.Settings;
/**
@@ -13,6 +14,14 @@ public class ConversationsPlusPreferences extends Settings {
private static ConversationsPlusPreferences instance;
private final SharedPreferences sharedPreferences;
+ public static UserDecision resizePicture() {
+ return getEnumFromStringPref("resize_picture", UserDecision.ASK);
+ }
+
+ public static void applyResizePicture(UserDecision decision) {
+ applyString("resize_picture", decision.name());
+ }
+
/**
* Whether automatic downloads should only be done when connected to Wifi or not.
* @return
@@ -243,6 +252,11 @@ public class ConversationsPlusPreferences extends Settings {
}
}
+ protected static <T extends Enum<T>> T getEnumFromStringPref(String key, T defaultValue) {
+ String enumValueAsString = getString(key, defaultValue.name());
+ return (T) Enum.valueOf(defaultValue.getClass(), enumValueAsString);
+ }
+
private static boolean getBoolean(String key, boolean defValue) {
return getSharedPreferences().getBoolean(key, defValue);
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/enums/UserDecision.java b/src/main/java/de/thedevstack/conversationsplus/enums/UserDecision.java
new file mode 100644
index 00000000..ccb658d5
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/enums/UserDecision.java
@@ -0,0 +1,10 @@
+package de.thedevstack.conversationsplus.enums;
+
+/**
+ * Created by tzur on 30.10.2015.
+ */
+public enum UserDecision {
+ ASK,
+ ALWAYS,
+ NEVER;
+}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/MessageDetailsDialog.java b/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/MessageDetailsDialog.java
index 75ba39c3..d7be3fe2 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/MessageDetailsDialog.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/MessageDetailsDialog.java
@@ -43,6 +43,8 @@ public class MessageDetailsDialog extends AbstractAlertDialog {
displayMessageTypeInfo(view, message);
displayMessageStatusInfo(view, message);
displayFileInfo(view, message);
+
+ this.setView(view);
}
/**
@@ -61,7 +63,6 @@ public class MessageDetailsDialog extends AbstractAlertDialog {
TextView mimetype = (TextView) view.findViewById(R.id.dlgMsgDetFileMimeType);
mimetype.setText(message.getMimeType());
}
- this.setView(view);
}
/**
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/UserDecisionDialog.java b/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/UserDecisionDialog.java
new file mode 100644
index 00000000..2d919528
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/UserDecisionDialog.java
@@ -0,0 +1,70 @@
+package de.thedevstack.conversationsplus.ui.dialogs;
+
+import android.app.Activity;
+import android.content.DialogInterface;
+import android.view.View;
+import android.widget.CheckBox;
+import android.widget.TextView;
+
+import de.thedevstack.conversationsplus.enums.UserDecision;
+import de.thedevstack.conversationsplus.ui.listeners.UserDecisionListener;
+import eu.siacs.conversations.R;
+
+/**
+ * Created by tzur on 31.10.2015.
+ */
+public class UserDecisionDialog extends AbstractAlertDialog {
+ protected final UserDecisionListener listener;
+ protected final CheckBox rememberCheckBox;
+
+ public UserDecisionDialog(Activity context, int questionResourceId, UserDecisionListener userDecisionListener) {
+ super(context, "User Decision");
+ this.listener = userDecisionListener;
+
+ int viewId = R.layout.dialog_userdecision;
+ View view = context.getLayoutInflater().inflate(viewId, null);
+
+ ((TextView)view.findViewById(R.id.dlgUserDecQuestion)).setText(questionResourceId);
+ this.rememberCheckBox = (CheckBox) view.findViewById(R.id.dlgUserDecRemember);
+
+ this.setPositiveButton(R.string.cplus_yes, new PositiveOnClickListener());
+ this.setNegativeButton(R.string.cplus_no, new NegativeOnClickListener());
+ this.setView(view);
+ }
+
+ public void decide(UserDecision baseDecision) {
+ switch (baseDecision) {
+ case ALWAYS:
+ this.listener.onYes();
+ break;
+ case NEVER:
+ this.listener.onNo();
+ break;
+ case ASK:
+ this.show();
+ break;
+ }
+ }
+
+ class PositiveOnClickListener implements DialogInterface.OnClickListener {
+
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ listener.onYes();
+ if (rememberCheckBox.isChecked()) {
+ listener.onRemember(UserDecision.ALWAYS);
+ }
+ }
+ }
+
+ class NegativeOnClickListener implements DialogInterface.OnClickListener {
+
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ listener.onNo();
+ if (rememberCheckBox.isChecked()) {
+ listener.onRemember(UserDecision.NEVER);
+ }
+ }
+ }
+}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ResizePictureUserDecisionListener.java b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ResizePictureUserDecisionListener.java
new file mode 100644
index 00000000..135d6faa
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ResizePictureUserDecisionListener.java
@@ -0,0 +1,97 @@
+package de.thedevstack.conversationsplus.ui.listeners;
+
+import android.app.PendingIntent;
+import android.net.Uri;
+import android.widget.Toast;
+
+import de.thedevstack.conversationsplus.ConversationsPlusApplication;
+import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
+import de.thedevstack.conversationsplus.enums.UserDecision;
+import eu.siacs.conversations.R;
+import eu.siacs.conversations.entities.Conversation;
+import eu.siacs.conversations.entities.Message;
+import eu.siacs.conversations.services.XmppConnectionService;
+import eu.siacs.conversations.ui.UiCallback;
+import eu.siacs.conversations.ui.XmppActivity;
+
+/**
+ * Created by tzur on 31.10.2015.
+ */
+public class ResizePictureUserDecisionListener implements UserDecisionListener {
+ protected Uri uri;
+ protected final Conversation conversation;
+ protected final UiCallback<Message> callback;
+ protected final XmppConnectionService xmppConnectionService;
+ protected final Toast prepareFileToast;
+ protected final XmppActivity activity;
+
+ public ResizePictureUserDecisionListener(XmppActivity activity, Conversation conversation, XmppConnectionService xmppConnectionService) {
+ this.xmppConnectionService = xmppConnectionService;
+ this.conversation = conversation;
+ this.activity = activity;
+ this.prepareFileToast = Toast.makeText(ConversationsPlusApplication.getAppContext(), ConversationsPlusApplication.getInstance().getText(R.string.preparing_image), Toast.LENGTH_LONG);
+ this.callback = new UiCallback<Message>() {
+
+ @Override
+ public void userInputRequried(PendingIntent pi,
+ Message object) {
+ hidePrepareFileToast();
+ }
+
+ @Override
+ public void success(Message message) {
+ ResizePictureUserDecisionListener.this.xmppConnectionService.sendMessage(message);
+ }
+
+ @Override
+ public void error(int error, Message message) {
+ hidePrepareFileToast();
+ ResizePictureUserDecisionListener.this.activity.displayErrorDialog(error);
+ }
+
+ protected void hidePrepareFileToast() {
+ ResizePictureUserDecisionListener.this.activity.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ ResizePictureUserDecisionListener.this.prepareFileToast.cancel();
+ }
+ });
+ }
+ };
+ }
+
+ public ResizePictureUserDecisionListener(XmppActivity activity, Conversation conversation, Uri uri, XmppConnectionService xmppConnectionService) {
+ this(activity, conversation, xmppConnectionService);
+ this.uri = uri;
+ }
+
+ public void setUri(Uri uri) {
+ this.uri = uri;
+ }
+
+ protected void showPrepareFileToast() {
+ activity.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ prepareFileToast.show();
+ }
+ });
+ }
+
+ @Override
+ public void onYes() {
+ this.showPrepareFileToast();
+ xmppConnectionService.attachImageToConversation(this.conversation, this.uri, this.callback);
+ }
+
+ @Override
+ public void onNo() {
+ this.showPrepareFileToast();
+ xmppConnectionService.attachImageToConversationWithoutResizing(this.conversation, this.uri, this.callback);
+ }
+
+ @Override
+ public void onRemember(UserDecision decision) {
+ ConversationsPlusPreferences.applyResizePicture(decision);
+ }
+}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ShareWithResizePictureUserDecisionListener.java b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ShareWithResizePictureUserDecisionListener.java
new file mode 100644
index 00000000..7455cf97
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ShareWithResizePictureUserDecisionListener.java
@@ -0,0 +1,48 @@
+package de.thedevstack.conversationsplus.ui.listeners;
+
+import android.net.Uri;
+
+import java.util.List;
+
+import eu.siacs.conversations.entities.Conversation;
+import eu.siacs.conversations.services.XmppConnectionService;
+import eu.siacs.conversations.ui.XmppActivity;
+
+/**
+ * Created by tzur on 03.11.2015.
+ */
+public class ShareWithResizePictureUserDecisionListener extends ResizePictureUserDecisionListener {
+ protected final List<Uri> uris;
+
+ public ShareWithResizePictureUserDecisionListener(XmppActivity activity, Conversation conversation, XmppConnectionService xmppConnectionService, List<Uri> uris) {
+ super(activity, conversation, xmppConnectionService);
+ this.uris = uris;
+ }
+
+ @Override
+ public void onYes() {
+ if (null != this.uris && !this.uris.isEmpty()) {
+ for (Uri uri : this.uris) {
+ this.setUri(uri);
+ super.onYes();
+ }
+ }
+ this.finishSharing();
+ }
+
+ @Override
+ public void onNo() {
+ if (null != this.uris && !this.uris.isEmpty()) {
+ for (Uri uri : this.uris) {
+ this.setUri(uri);
+ super.onNo();
+ }
+ }
+ this.finishSharing();
+ }
+
+ protected void finishSharing() {
+ this.activity.switchToConversation(conversation, null, true);
+ this.activity.finish();
+ }
+}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/listeners/UserDecisionListener.java b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/UserDecisionListener.java
new file mode 100644
index 00000000..fbee6290
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/UserDecisionListener.java
@@ -0,0 +1,12 @@
+package de.thedevstack.conversationsplus.ui.listeners;
+
+import de.thedevstack.conversationsplus.enums.UserDecision;
+
+/**
+ * Created by tzur on 31.10.2015.
+ */
+public interface UserDecisionListener {
+ void onYes();
+ void onNo();
+ void onRemember(UserDecision decision);
+}
diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/FileHelper.java b/src/main/java/de/thedevstack/conversationsplus/utils/FileHelper.java
new file mode 100644
index 00000000..3384b54e
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/utils/FileHelper.java
@@ -0,0 +1,43 @@
+package de.thedevstack.conversationsplus.utils;
+
+import android.database.Cursor;
+import android.net.Uri;
+import android.provider.MediaStore;
+
+import de.thedevstack.conversationsplus.ConversationsPlusApplication;
+
+/**
+ * Created by tzur on 30.10.2015.
+ */
+public final class FileHelper {
+
+ /**
+ * Get the real path from an Uri.
+ * @param uri the uri to convert to the real path
+ * @return the real path or <code>null</code>
+ */
+ public static String getRealPathFromUri(Uri uri) {
+ String path = null;
+ if (uri.getScheme().equals("file")) {
+ return uri.getPath();
+ } else if (uri.toString().startsWith("content://media/")) {
+ String[] projection = {MediaStore.MediaColumns.DATA};
+ Cursor metaCursor = ConversationsPlusApplication.getInstance().getContentResolver().query(uri,
+ projection, null, null, null);
+ if (metaCursor != null) {
+ try {
+ if (metaCursor.moveToFirst()) {
+ path = metaCursor.getString(0);
+ }
+ } finally {
+ metaCursor.close();
+ }
+ }
+ }
+ return path;
+ }
+
+ private FileHelper() {
+ // Utility class - do not instantiate
+ }
+}