aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/services
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/eu/siacs/conversations/services')
-rw-r--r--src/main/java/eu/siacs/conversations/services/AvatarService.java12
-rw-r--r--src/main/java/eu/siacs/conversations/services/CheckAppVersionService.java43
-rw-r--r--src/main/java/eu/siacs/conversations/services/NotificationService.java36
-rw-r--r--src/main/java/eu/siacs/conversations/services/UpdaterWebService.java91
4 files changed, 158 insertions, 24 deletions
diff --git a/src/main/java/eu/siacs/conversations/services/AvatarService.java b/src/main/java/eu/siacs/conversations/services/AvatarService.java
index 7412eb933..e88047f67 100644
--- a/src/main/java/eu/siacs/conversations/services/AvatarService.java
+++ b/src/main/java/eu/siacs/conversations/services/AvatarService.java
@@ -44,12 +44,12 @@ public class AvatarService {
if (avatar != null || cachedOnly) {
return avatar;
}
- if (contact.getProfilePhoto() != null) {
- avatar = mXmppConnectionService.getFileBackend().cropCenterSquare(Uri.parse(contact.getProfilePhoto()), size);
- }
if (avatar == null && contact.getAvatar() != null) {
avatar = mXmppConnectionService.getFileBackend().getAvatar(contact.getAvatar(), size);
}
+ if (avatar == null && contact.getProfilePhoto() != null) {
+ avatar = mXmppConnectionService.getFileBackend().cropCenterSquare(Uri.parse(contact.getProfilePhoto()), size);
+ }
if (avatar == null) {
avatar = get(contact.getDisplayName(), size, cachedOnly);
}
@@ -265,11 +265,11 @@ public class AvatarService {
Contact contact = user.getContact();
if (contact != null) {
Uri uri = null;
- if (contact.getProfilePhoto() != null) {
- uri = Uri.parse(contact.getProfilePhoto());
- } else if (contact.getAvatar() != null) {
+ if (contact.getAvatar() != null) {
uri = mXmppConnectionService.getFileBackend().getAvatarUri(
contact.getAvatar());
+ } else if (contact.getProfilePhoto() != null) {
+ uri = Uri.parse(contact.getProfilePhoto());
}
if (uri != null) {
Bitmap bitmap = mXmppConnectionService.getFileBackend()
diff --git a/src/main/java/eu/siacs/conversations/services/CheckAppVersionService.java b/src/main/java/eu/siacs/conversations/services/CheckAppVersionService.java
new file mode 100644
index 000000000..33faeaeca
--- /dev/null
+++ b/src/main/java/eu/siacs/conversations/services/CheckAppVersionService.java
@@ -0,0 +1,43 @@
+package eu.siacs.conversations.services;
+
+import com.google.gson.JsonObject;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+public class CheckAppVersionService extends HttpServlet {
+ private static final long serialVersionUID = 1L;
+
+ public CheckAppVersionService() {
+ super();
+ }
+
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+ doPost(request,response);
+ }
+
+ protected void doPost(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+
+ PrintWriter out = response.getWriter();
+ response.setContentType("text/html");
+
+ //send a JSON response with the app Version and file URI
+ JsonObject myObj = new JsonObject();
+ myObj.addProperty("success", false);
+ myObj.addProperty("latestVersionCode", 2);
+ myObj.addProperty("latestVersion", "1.0.0");
+ myObj.addProperty("changelog", "");
+ myObj.addProperty("appURI", "");
+ out.println(myObj.toString());
+ out.close();
+
+ }
+
+}
diff --git a/src/main/java/eu/siacs/conversations/services/NotificationService.java b/src/main/java/eu/siacs/conversations/services/NotificationService.java
index e9095020d..515e57c85 100644
--- a/src/main/java/eu/siacs/conversations/services/NotificationService.java
+++ b/src/main/java/eu/siacs/conversations/services/NotificationService.java
@@ -60,12 +60,12 @@ public class NotificationService {
public boolean notify(final Message message) {
return (message.getStatus() == Message.STATUS_RECEIVED)
- && notificationsEnabled()
- && !message.getConversation().isMuted()
- && (message.getConversation().isPnNA()
- || conferenceNotificationsEnabled()
- || wasHighlightedOrPrivate(message)
- );
+ && notificationsEnabled()
+ && !message.getConversation().isMuted()
+ && (message.getConversation().isPnNA()
+ || conferenceNotificationsEnabled()
+ || wasHighlightedOrPrivate(message)
+ );
}
public void notifyPebble(final Message message) {
@@ -179,7 +179,7 @@ public class NotificationService {
private void updateNotification(final boolean notify) {
final NotificationManager notificationManager = (NotificationManager) mXmppConnectionService
- .getSystemService(Context.NOTIFICATION_SERVICE);
+ .getSystemService(Context.NOTIFICATION_SERVICE);
final SharedPreferences preferences = mXmppConnectionService.getPreferences();
final String ringtone = preferences.getString("notification_ringtone", null);
@@ -235,7 +235,7 @@ public class NotificationService {
conversation = messages.get(0).getConversation();
final String name = conversation.getName();
style.addLine(Html.fromHtml("<b>" + name + "</b> "
- + UIHelper.getMessagePreview(mXmppConnectionService,messages.get(0)).first));
+ + UIHelper.getMessagePreview(mXmppConnectionService,messages.get(0)).first));
names.append(name);
names.append(", ");
}
@@ -275,9 +275,9 @@ public class NotificationService {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ?
R.drawable.ic_file_download_white_24dp : R.drawable.ic_action_download,
mXmppConnectionService.getResources().getString(R.string.download_x_file,
- UIHelper.getFileDescriptionString(mXmppConnectionService, message)),
+ UIHelper.getFileDescriptionString(mXmppConnectionService, message)),
createDownloadIntent(message)
- );
+ );
}
if ((message = getFirstLocationMessage(messages)) != null) {
mBuilder.addAction(R.drawable.ic_room_white_24dp,
@@ -290,16 +290,16 @@ public class NotificationService {
}
private void modifyForImage(final Builder builder, final Message message,
- final ArrayList<Message> messages, final boolean notify) {
+ final ArrayList<Message> messages, final boolean notify) {
try {
final Bitmap bitmap = mXmppConnectionService.getFileBackend()
- .getThumbnail(message, getPixel(288), false);
+ .getThumbnail(message, getPixel(200), false);
final ArrayList<Message> tmp = new ArrayList<>();
for (final Message msg : messages) {
if (msg.getType() == Message.TYPE_TEXT
&& msg.getTransferable() == null) {
tmp.add(msg);
- }
+ }
}
final BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle();
bigPictureStyle.bigPicture(bitmap);
@@ -318,7 +318,7 @@ public class NotificationService {
}
private void modifyForTextOnly(final Builder builder,
- final ArrayList<Message> messages, final boolean notify) {
+ final ArrayList<Message> messages, final boolean notify) {
builder.setStyle(new NotificationCompat.BigTextStyle().bigText(getMergedBodies(messages)));
builder.setContentText(UIHelper.getMessagePreview(mXmppConnectionService,messages.get(0)).first);
if (notify) {
@@ -333,7 +333,7 @@ public class NotificationService {
&& message.getEncryption() != Message.ENCRYPTION_PGP
&& message.getFileParams().height > 0) {
return message;
- }
+ }
}
return null;
}
@@ -380,7 +380,7 @@ public class NotificationService {
private PendingIntent createContentIntent(final String conversationUuid, final String downloadMessageUuid) {
final TaskStackBuilder stackBuilder = TaskStackBuilder
- .create(mXmppConnectionService);
+ .create(mXmppConnectionService);
stackBuilder.addParentStack(ConversationActivity.class);
final Intent viewConversationIntent = new Intent(mXmppConnectionService,
@@ -468,7 +468,7 @@ public class NotificationService {
private int getPixel(final int dp) {
final DisplayMetrics metrics = mXmppConnectionService.getResources()
- .getDisplayMetrics();
+ .getDisplayMetrics();
return ((int) (dp * metrics.density));
}
@@ -478,7 +478,7 @@ public class NotificationService {
private boolean inMiniGracePeriod(final Account account) {
final int miniGrace = account.getStatus() == Account.State.ONLINE ? Config.MINI_GRACE_PERIOD
- : Config.MINI_GRACE_PERIOD * 2;
+ : Config.MINI_GRACE_PERIOD * 2;
return SystemClock.elapsedRealtime() < (this.mLastNotification + miniGrace);
}
diff --git a/src/main/java/eu/siacs/conversations/services/UpdaterWebService.java b/src/main/java/eu/siacs/conversations/services/UpdaterWebService.java
new file mode 100644
index 000000000..0b220f2bc
--- /dev/null
+++ b/src/main/java/eu/siacs/conversations/services/UpdaterWebService.java
@@ -0,0 +1,91 @@
+package eu.siacs.conversations.services;
+
+import android.app.IntentService;
+import android.content.Intent;
+import android.util.Log;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpStatus;
+import org.apache.http.StatusLine;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.conn.params.ConnManagerParams;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.params.HttpConnectionParams;
+import org.apache.http.params.HttpParams;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import eu.siacs.conversations.Config;
+import eu.siacs.conversations.ui.UpdaterActivity.UpdateReceiver;
+
+public class UpdaterWebService extends IntentService{
+ public static final String REQUEST_STRING = "";
+ public static final String RESPONSE_MESSAGE = "";
+
+ private String URL = null;
+ public static final int REGISTRATION_TIMEOUT = 3 * 1000;
+ public static final int WAIT_TIMEOUT = 30 * 1000;
+
+ public UpdaterWebService() {
+ super("UpdaterWebService");
+ }
+
+ @Override
+ protected void onHandleIntent(Intent intent) {
+
+ String requestString = intent.getStringExtra(REQUEST_STRING);
+ Log.d(Config.LOGTAG, "AppUpdater: " + requestString);
+ String responseMessage = "";
+
+ try {
+
+ URL = requestString;
+ HttpClient httpclient = new DefaultHttpClient();
+ HttpParams params = httpclient.getParams();
+
+ HttpConnectionParams.setConnectionTimeout(params, REGISTRATION_TIMEOUT);
+ HttpConnectionParams.setSoTimeout(params, WAIT_TIMEOUT);
+ ConnManagerParams.setTimeout(params, WAIT_TIMEOUT);
+
+ HttpGet httpGet = new HttpGet(URL);
+ HttpResponse response = httpclient.execute(httpGet);
+
+ StatusLine statusLine = response.getStatusLine();
+ Log.d(Config.LOGTAG, "AppUpdater: HTTP Status Code: " + statusLine.getStatusCode());
+ if(statusLine.getStatusCode() == HttpStatus.SC_OK){
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ response.getEntity().writeTo(out);
+ out.close();
+ responseMessage = out.toString();
+ }
+
+ else{
+ Log.d(Config.LOGTAG, "AppUpdater: HTTP1:" + statusLine.getReasonPhrase());
+ response.getEntity().getContent().close();
+ throw new IOException(statusLine.getReasonPhrase());
+ }
+
+ } catch (ClientProtocolException e) {
+ Log.d(Config.LOGTAG, "AppUpdater: HTTP2:" + e);
+ responseMessage = e.getMessage();
+ } catch (IOException e) {
+ Log.d(Config.LOGTAG, "AppUpdater: HTTP3:" + e);
+ responseMessage = e.getMessage();
+ }catch (Exception e) {
+ Log.d(Config.LOGTAG, "AppUpdater: HTTP4:" + e);
+ responseMessage = e.getMessage();
+ }
+
+
+ Intent broadcastIntent = new Intent();
+ broadcastIntent.setAction(UpdateReceiver.PROCESS_RESPONSE);
+ broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT);
+ broadcastIntent.putExtra(RESPONSE_MESSAGE, responseMessage);
+ sendBroadcast(broadcastIntent);
+
+ }
+
+} \ No newline at end of file