aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel.gultsch@rwth-aachen.de>2014-05-08 11:53:00 +0200
committerDaniel Gultsch <daniel.gultsch@rwth-aachen.de>2014-05-08 11:53:00 +0200
commitdc73a25ae4c0729052f858af830707411463e43f (patch)
tree527f26da9e9e328c5dadacfba2c2f207e9af07ee /src
parent0d8bf660db579c863459d2409175d9d9d8baacf0 (diff)
code cleanup
Diffstat (limited to '')
-rw-r--r--src/eu/siacs/conversations/entities/Conversation.java3
-rw-r--r--src/eu/siacs/conversations/entities/Message.java1
-rw-r--r--src/eu/siacs/conversations/services/XmppConnectionService.java11
-rw-r--r--src/eu/siacs/conversations/ui/ConversationActivity.java6
-rw-r--r--src/eu/siacs/conversations/ui/ConversationFragment.java313
5 files changed, 170 insertions, 164 deletions
diff --git a/src/eu/siacs/conversations/entities/Conversation.java b/src/eu/siacs/conversations/entities/Conversation.java
index d800cfd4..5674f84a 100644
--- a/src/eu/siacs/conversations/entities/Conversation.java
+++ b/src/eu/siacs/conversations/entities/Conversation.java
@@ -15,7 +15,6 @@ import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
-import android.util.Log;
public class Conversation extends AbstractEntity {
@@ -238,7 +237,6 @@ public class Conversation extends AbstractEntity {
}
return this.otrSession;
} catch (OtrException e) {
- Log.d("xmppServic", "couldnt start otr");
return null;
}
}
@@ -347,7 +345,6 @@ public class Conversation extends AbstractEntity {
}
public void setNextMessage(String message) {
- Log.d("xmppService","saving text: "+message);
this.nextMessage = message;
}
}
diff --git a/src/eu/siacs/conversations/entities/Message.java b/src/eu/siacs/conversations/entities/Message.java
index 49ae0265..a17d552f 100644
--- a/src/eu/siacs/conversations/entities/Message.java
+++ b/src/eu/siacs/conversations/entities/Message.java
@@ -17,7 +17,6 @@ public class Message extends AbstractEntity {
public static final int STATUS_SEND = 2;
public static final int STATUS_SEND_FAILED = 3;
public static final int STATUS_SEND_REJECTED = 4;
- public static final int STATUS_PREPARING = 5;
public static final int STATUS_OFFERED = 6;
public static final int ENCRYPTION_NONE = 0;
diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java
index 6b67c419..3581d189 100644
--- a/src/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/eu/siacs/conversations/services/XmppConnectionService.java
@@ -451,18 +451,14 @@ public class XmppConnectionService extends Service {
final Message message = new Message(conversation, "",Message.ENCRYPTION_NONE);
message.setPresence(presence);
message.setType(Message.TYPE_IMAGE);
- message.setStatus(Message.STATUS_PREPARING);
- conversation.getMessages().add(message);
- if (convChangedListener != null) {
- convChangedListener.onConversationListChanged();
- }
+ message.setStatus(Message.STATUS_OFFERED);
new Thread(new Runnable() {
@Override
public void run() {
getFileBackend().copyImageToPrivateStorage(message, uri);
- message.setStatus(Message.STATUS_OFFERED);
databaseBackend.createMessage(message);
+ conversation.getMessages().add(message);
if (convChangedListener != null) {
convChangedListener.onConversationListChanged();
}
@@ -477,14 +473,13 @@ public class XmppConnectionService extends Service {
final Message message = new Message(conversation, "",Message.ENCRYPTION_DECRYPTED);
message.setPresence(presence);
message.setType(Message.TYPE_IMAGE);
- message.setStatus(Message.STATUS_PREPARING);
+ message.setStatus(Message.STATUS_OFFERED);
new Thread(new Runnable() {
@Override
public void run() {
getFileBackend().copyImageToPrivateStorage(message, uri);
getPgpEngine().encrypt(message, callback);
- message.setStatus(Message.STATUS_OFFERED);
}
}).start();
return message;
diff --git a/src/eu/siacs/conversations/ui/ConversationActivity.java b/src/eu/siacs/conversations/ui/ConversationActivity.java
index fbe2752a..565d7ff4 100644
--- a/src/eu/siacs/conversations/ui/ConversationActivity.java
+++ b/src/eu/siacs/conversations/ui/ConversationActivity.java
@@ -178,16 +178,14 @@ public class ConversationActivity extends XmppActivity {
convLastMsg.setVisibility(View.VISIBLE);
imagePreview.setVisibility(View.GONE);
} else if (latestMessage.getType() == Message.TYPE_IMAGE) {
- if ((latestMessage.getStatus() >= Message.STATUS_RECIEVED)&&(latestMessage.getStatus() != Message.STATUS_PREPARING)) {
+ if (latestMessage.getStatus() >= Message.STATUS_RECIEVED) {
convLastMsg.setVisibility(View.GONE);
imagePreview.setVisibility(View.VISIBLE);
loadBitmap(latestMessage, imagePreview);
} else {
convLastMsg.setVisibility(View.VISIBLE);
imagePreview.setVisibility(View.GONE);
- if (latestMessage.getStatus() == Message.STATUS_PREPARING) {
- convLastMsg.setText(getText(R.string.preparing_image));
- } else if (latestMessage.getStatus() == Message.STATUS_RECEIVED_OFFER) {
+ if (latestMessage.getStatus() == Message.STATUS_RECEIVED_OFFER) {
convLastMsg.setText(getText(R.string.image_offered_for_download));
} else if (latestMessage.getStatus() == Message.STATUS_RECIEVING) {
convLastMsg.setText(getText(R.string.receiving_image));
diff --git a/src/eu/siacs/conversations/ui/ConversationFragment.java b/src/eu/siacs/conversations/ui/ConversationFragment.java
index 2a6cc886..33aa5b5c 100644
--- a/src/eu/siacs/conversations/ui/ConversationFragment.java
+++ b/src/eu/siacs/conversations/ui/ConversationFragment.java
@@ -192,6 +192,155 @@ public class ConversationFragment extends Fragment {
}
}
+ private void displayStatus(ViewHolder viewHolder, Message message) {
+ String filesize = null;
+ String info = null;
+ boolean error = false;
+ if (message.getType() == Message.TYPE_IMAGE) {
+ String[] fileParams = message.getBody().split(",");
+ long size = Long.parseLong(fileParams[0]);
+ filesize = size / 1024 + " KB";
+ }
+ switch (message.getStatus()) {
+ case Message.STATUS_UNSEND:
+ info = getString(R.string.sending);
+ break;
+ case Message.STATUS_OFFERED:
+ info = getString(R.string.offering);
+ break;
+ case Message.STATUS_SEND_FAILED:
+ info = getString(R.string.send_failed);
+ error = true;
+ break;
+ case Message.STATUS_SEND_REJECTED:
+ info = getString(R.string.send_rejected);
+ error = true;
+ break;
+ default:
+ if ((message.getConversation().getMode() == Conversation.MODE_MULTI)
+ && (message.getStatus() <= Message.STATUS_RECIEVED)) {
+ info = message.getCounterpart();
+ }
+ break;
+ }
+ if (error) {
+ viewHolder.time.setTextColor(0xFFe92727);
+ } else {
+ viewHolder.time.setTextColor(0xFF8e8e8e);
+ }
+ if (message.getEncryption() == Message.ENCRYPTION_NONE) {
+ viewHolder.indicator.setVisibility(View.GONE);
+ } else {
+ viewHolder.indicator.setVisibility(View.VISIBLE);
+ }
+
+ String formatedTime = UIHelper.readableTimeDifference(message
+ .getTimeSent());
+ if (message.getStatus() <= Message.STATUS_RECIEVED) {
+ if ((filesize != null) && (info != null)) {
+ viewHolder.time.setText(filesize + " \u00B7 " + info);
+ } else if ((filesize == null) && (info != null)) {
+ viewHolder.time.setText(formatedTime + " \u00B7 "
+ + info);
+ } else if ((filesize != null) && (info == null)) {
+ viewHolder.time.setText(formatedTime + " \u00B7 "
+ + filesize);
+ } else {
+ viewHolder.time.setText(formatedTime);
+ }
+ } else {
+ if ((filesize != null) && (info != null)) {
+ viewHolder.time.setText(filesize + " \u00B7 " + info);
+ } else if ((filesize == null) && (info != null)) {
+ viewHolder.time.setText(info + " \u00B7 "
+ + formatedTime);
+ } else if ((filesize != null) && (info == null)) {
+ viewHolder.time.setText(filesize + " \u00B7 "
+ + formatedTime);
+ } else {
+ viewHolder.time.setText(formatedTime);
+ }
+ }
+ }
+
+ private void displayInfoMessage(ViewHolder viewHolder, int r) {
+ viewHolder.download_button.setVisibility(View.GONE);
+ viewHolder.image.setVisibility(View.GONE);
+ viewHolder.messageBody.setVisibility(View.VISIBLE);
+ viewHolder.messageBody.setText(getString(r));
+ viewHolder.messageBody.setTextColor(0xff33B5E5);
+ viewHolder.messageBody.setTypeface(null, Typeface.ITALIC);
+ }
+
+ private void displayDecryptionFailed(ViewHolder viewHolder) {
+ viewHolder.download_button.setVisibility(View.GONE);
+ viewHolder.image.setVisibility(View.GONE);
+ viewHolder.messageBody.setVisibility(View.VISIBLE);
+ viewHolder.messageBody
+ .setText(getString(R.string.decryption_failed));
+ viewHolder.messageBody.setTextColor(0xFFe92727);
+ viewHolder.messageBody.setTypeface(null, Typeface.NORMAL);
+ }
+
+ private void displayTextMessage(ViewHolder viewHolder, String text) {
+ if (viewHolder.download_button != null) {
+ viewHolder.download_button.setVisibility(View.GONE);
+ }
+ viewHolder.image.setVisibility(View.GONE);
+ viewHolder.messageBody.setVisibility(View.VISIBLE);
+ if (text != null) {
+ viewHolder.messageBody.setText(text.trim());
+ } else {
+ viewHolder.messageBody.setText("");
+ }
+ viewHolder.messageBody.setTextColor(0xff333333);
+ viewHolder.messageBody.setTypeface(null, Typeface.NORMAL);
+ }
+
+ private void displayImageMessage(ViewHolder viewHolder,
+ final Message message) {
+ if (viewHolder.download_button != null) {
+ viewHolder.download_button.setVisibility(View.GONE);
+ }
+ viewHolder.messageBody.setVisibility(View.GONE);
+ viewHolder.image.setVisibility(View.VISIBLE);
+ String[] fileParams = message.getBody().split(",");
+ if (fileParams.length == 3) {
+ double target = metrics.density * 288;
+ int w = Integer.parseInt(fileParams[1]);
+ int h = Integer.parseInt(fileParams[2]);
+ int scalledW;
+ int scalledH;
+ if (w <= h) {
+ scalledW = (int) (w / ((double) h / target));
+ scalledH = (int) target;
+ } else {
+ scalledW = (int) target;
+ scalledH = (int) (h / ((double) w / target));
+ }
+ viewHolder.image
+ .setLayoutParams(new LinearLayout.LayoutParams(
+ scalledW, scalledH));
+ }
+ activity.loadBitmap(message, viewHolder.image);
+ viewHolder.image.setOnClickListener(new OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ Uri uri = Uri
+ .parse("content://eu.siacs.conversations.images/"
+ + message.getConversationUuid()
+ + "/"
+ + message.getUuid());
+ Log.d("xmppService",
+ "staring intent with uri:" + uri.toString());
+ Intent intent = new Intent(Intent.ACTION_VIEW);
+ intent.setDataAndType(uri, "image/*");
+ startActivity(intent);
+ }
+ });
+ }
+
@Override
public View getView(int position, View view, ViewGroup parent) {
final Message item = getItem(position);
@@ -265,36 +414,9 @@ public class ConversationFragment extends Fragment {
}
}
- if (item.getEncryption() == Message.ENCRYPTION_NONE) {
- viewHolder.indicator.setVisibility(View.GONE);
- } else {
- viewHolder.indicator.setVisibility(View.VISIBLE);
- }
-
- String filesize = "";
-
if (item.getType() == Message.TYPE_IMAGE) {
- String[] fileParams = item.getBody().split(",");
- if ((fileParams.length >= 1)
- && (item.getStatus() != Message.STATUS_PREPARING)) {
- long size = Long.parseLong(fileParams[0]);
- filesize = size / 1024 + " KB \u00B7 ";
- }
- if ((item.getStatus() == Message.STATUS_PREPARING)
- || (item.getStatus() == Message.STATUS_RECIEVING)) {
- viewHolder.image.setVisibility(View.GONE);
- viewHolder.messageBody.setVisibility(View.VISIBLE);
- if (item.getStatus() == Message.STATUS_PREPARING) {
- viewHolder.messageBody
- .setText(getString(R.string.preparing_image));
- } else if (item.getStatus() == Message.STATUS_RECIEVING) {
- viewHolder.download_button.setVisibility(View.GONE);
- viewHolder.messageBody
- .setText(getString(R.string.receiving_image));
- }
- viewHolder.messageBody.setTextColor(0xff33B5E5);
- viewHolder.messageBody.setTypeface(null,
- Typeface.ITALIC);
+ if (item.getStatus() == Message.STATUS_RECIEVING) {
+ displayInfoMessage(viewHolder, R.string.receiving_image);
} else if (item.getStatus() == Message.STATUS_RECEIVED_OFFER) {
viewHolder.image.setVisibility(View.GONE);
viewHolder.messageBody.setVisibility(View.GONE);
@@ -316,129 +438,26 @@ public class ConversationFragment extends Fragment {
});
} else if ((item.getEncryption() == Message.ENCRYPTION_DECRYPTED)
|| (item.getEncryption() == Message.ENCRYPTION_NONE)) {
- viewHolder.messageBody.setVisibility(View.GONE);
- viewHolder.image.setVisibility(View.VISIBLE);
- if (fileParams.length == 3) {
- double target = metrics.density * 288;
- int w = Integer.parseInt(fileParams[1]);
- int h = Integer.parseInt(fileParams[2]);
- int scalledW;
- int scalledH;
- if (w <= h) {
- scalledW = (int) (w / ((double) h / target));
- scalledH = (int) target;
- } else {
- scalledW = (int) target;
- scalledH = (int) (h / ((double) w / target));
- }
- viewHolder.image
- .setLayoutParams(new LinearLayout.LayoutParams(
- scalledW, scalledH));
- } else {
- Log.d("xmppService",
- "message body has less than 3 params");
- }
- activity.loadBitmap(item, viewHolder.image);
- viewHolder.image
- .setOnClickListener(new OnClickListener() {
-
- @Override
- public void onClick(View v) {
- Uri uri = Uri.parse("content://eu.siacs.conversations.images/"
- + item.getConversationUuid()
- + "/" + item.getUuid());
- Log.d("xmppService",
- "staring intent with uri:"
- + uri.toString());
- Intent intent = new Intent(
- Intent.ACTION_VIEW);
- intent.setDataAndType(uri, "image/*");
- startActivity(intent);
- }
- });
+ displayImageMessage(viewHolder, item);
} else if (item.getEncryption() == Message.ENCRYPTION_PGP) {
- viewHolder.image.setVisibility(View.GONE);
- viewHolder.messageBody.setVisibility(View.VISIBLE);
- viewHolder.messageBody
- .setText(getString(R.string.encrypted_message));
- viewHolder.messageBody.setTextColor(0xff33B5E5);
- viewHolder.messageBody.setTypeface(null,
- Typeface.ITALIC);
+ displayInfoMessage(viewHolder,
+ R.string.encrypted_message);
} else {
- viewHolder.image.setVisibility(View.GONE);
- viewHolder.messageBody.setVisibility(View.VISIBLE);
- viewHolder.messageBody
- .setText(getString(R.string.decryption_failed));
- viewHolder.messageBody.setTextColor(0xFFe92727);
- viewHolder.messageBody.setTypeface(null,
- Typeface.NORMAL);
+ displayDecryptionFailed(viewHolder);
}
} else {
- viewHolder.image.setVisibility(View.GONE);
- viewHolder.messageBody.setVisibility(View.VISIBLE);
- String body = item.getBody();
- if (body != null) {
- if (item.getEncryption() == Message.ENCRYPTION_PGP) {
- viewHolder.messageBody
- .setText(getString(R.string.encrypted_message));
- viewHolder.messageBody.setTextColor(0xff33B5E5);
- viewHolder.messageBody.setTypeface(null,
- Typeface.ITALIC);
- } else if (item.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) {
- viewHolder.messageBody
- .setText(getString(R.string.decryption_failed));
- viewHolder.messageBody.setTextColor(0xFFe92727);
- viewHolder.messageBody.setTypeface(null,
- Typeface.NORMAL);
- } else {
- viewHolder.messageBody.setText(body.trim());
- viewHolder.messageBody.setTextColor(0xff333333);
- viewHolder.messageBody.setTypeface(null,
- Typeface.NORMAL);
- }
- }
- }
- switch (item.getStatus()) {
- case Message.STATUS_UNSEND:
- viewHolder.time.setTypeface(null, Typeface.ITALIC);
- viewHolder.time.setTextColor(0xFF8e8e8e);
- viewHolder.time.setText(filesize + "sending\u2026");
- break;
- case Message.STATUS_OFFERED:
- viewHolder.time.setTypeface(null, Typeface.ITALIC);
- viewHolder.time.setTextColor(0xFF8e8e8e);
- viewHolder.time.setText(filesize + "offering\u2026");
- break;
- case Message.STATUS_SEND_FAILED:
- viewHolder.time.setText(filesize
- + getString(R.string.send_failed)
- + " \u00B7 "
- + UIHelper.readableTimeDifference(item
- .getTimeSent()));
- viewHolder.time.setTextColor(0xFFe92727);
- viewHolder.time.setTypeface(null, Typeface.NORMAL);
- break;
- case Message.STATUS_SEND_REJECTED:
- viewHolder.time.setText(filesize
- + getString(R.string.send_rejected));
- viewHolder.time.setTextColor(0xFFe92727);
- viewHolder.time.setTypeface(null, Typeface.NORMAL);
- break;
- default:
- viewHolder.time.setTypeface(null, Typeface.NORMAL);
- viewHolder.time.setTextColor(0xFF8e8e8e);
- if (item.getConversation().getMode() == Conversation.MODE_SINGLE) {
- viewHolder.time.setText(filesize
- + UIHelper.readableTimeDifference(item
- .getTimeSent()));
+ if (item.getEncryption() == Message.ENCRYPTION_PGP) {
+ displayInfoMessage(viewHolder,
+ R.string.encrypted_message);
+ } else if (item.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) {
+ displayDecryptionFailed(viewHolder);
} else {
- viewHolder.time.setText(item.getCounterpart()
- + " \u00B7 "
- + UIHelper.readableTimeDifference(item
- .getTimeSent()));
+ displayTextMessage(viewHolder, item.getBody());
}
- break;
}
+
+ displayStatus(viewHolder, item);
+
return view;
}
};
@@ -533,7 +552,6 @@ public class ConversationFragment extends Fragment {
}
private void decryptMessage(final Message message) {
- Log.d("xmppService", "called to decrypt");
PgpEngine engine = activity.xmppConnectionService.getPgpEngine();
if (engine != null) {
engine.decrypt(message, new OnPgpEngineResult() {
@@ -546,7 +564,6 @@ public class ConversationFragment extends Fragment {
@Override
public void success() {
- Log.d("xmppService", "successfully decrypted");
activity.xmppConnectionService.databaseBackend
.updateMessage(message);
updateMessages();
@@ -561,7 +578,7 @@ public class ConversationFragment extends Fragment {
}
});
} else {
- Log.d("xmppService", "engine was null");
+ pgpInfo.setVisibility(View.VISIBLE);
}
}