aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/main/AndroidManifest.xml3
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ConversationsPlusApplication.java62
-rw-r--r--src/main/java/eu/siacs/conversations/generator/AbstractGenerator.java17
-rw-r--r--src/main/java/eu/siacs/conversations/generator/IqGenerator.java8
-rw-r--r--src/main/java/eu/siacs/conversations/services/NotificationService.java3
-rw-r--r--src/main/java/eu/siacs/conversations/ui/AboutPreference.java4
-rw-r--r--src/main/java/eu/siacs/conversations/utils/PhoneHelper.java15
7 files changed, 76 insertions, 36 deletions
diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml
index 9fe37017..9da8a4ea 100644
--- a/src/main/AndroidManifest.xml
+++ b/src/main/AndroidManifest.xml
@@ -20,7 +20,8 @@
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/ConversationsTheme"
- tools:replace="android:label" >
+ tools:replace="android:label"
+ android:name=".ConversationsPlusApplication">
<service android:name=".services.XmppConnectionService" />
<receiver android:name=".services.EventReceiver" >
diff --git a/src/main/java/de/thedevstack/conversationsplus/ConversationsPlusApplication.java b/src/main/java/de/thedevstack/conversationsplus/ConversationsPlusApplication.java
new file mode 100644
index 00000000..dfe67cb7
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/ConversationsPlusApplication.java
@@ -0,0 +1,62 @@
+package de.thedevstack.conversationsplus;
+
+import android.app.Application;
+import android.content.Context;
+import android.content.pm.PackageManager;
+
+import java.io.File;
+
+/**
+ * This class is used to provide static access to the applicationcontext.
+ */
+public class ConversationsPlusApplication extends Application {
+ /**
+ * Application instance for static access
+ */
+ private static ConversationsPlusApplication instance;
+
+ /**
+ * Initializes the application and saves its instance.
+ */
+ public void onCreate(){
+ super.onCreate();
+ ConversationsPlusApplication.instance = this;
+ }
+
+ /**
+ * Returns the application's context.
+ * @return Context the application's context
+ */
+ public static Context getAppContext() {
+ return ConversationsPlusApplication.instance.getApplicationContext();
+ }
+
+ /**
+ * Returns the application's private data directory.
+ * @return File the application's private data dir
+ */
+ public static File getPrivateFilesDir() {
+ return ConversationsPlusApplication.instance.getFilesDir();
+ }
+
+ public static String getVersion() {
+ final String packageName = ConversationsPlusApplication.getAppContext().getPackageName();
+ if (packageName != null) {
+ try {
+ return ConversationsPlusApplication.getAppContext().getPackageManager().getPackageInfo(packageName, 0).versionName;
+ } catch (final PackageManager.NameNotFoundException e) {
+ return "unknown";
+ }
+ } else {
+ return "unknown";
+ }
+ }
+
+ public static String getName() {
+ return ConversationsPlusApplication.getAppContext().getString(R.string.app_name);
+ }
+
+ public static String getNameAndVersion() {
+ return getName() + " " + getVersion();
+ }
+}
diff --git a/src/main/java/eu/siacs/conversations/generator/AbstractGenerator.java b/src/main/java/eu/siacs/conversations/generator/AbstractGenerator.java
index 3607b69a..190e42bc 100644
--- a/src/main/java/eu/siacs/conversations/generator/AbstractGenerator.java
+++ b/src/main/java/eu/siacs/conversations/generator/AbstractGenerator.java
@@ -12,9 +12,9 @@ import java.util.List;
import java.util.Locale;
import java.util.TimeZone;
+import de.thedevstack.conversationsplus.ConversationsPlusApplication;
import de.tzur.conversations.Settings;
import eu.siacs.conversations.services.XmppConnectionService;
-import eu.siacs.conversations.utils.PhoneHelper;
public abstract class AbstractGenerator {
private final String[] FEATURES = {
@@ -35,8 +35,6 @@ public abstract class AbstractGenerator {
"urn:xmpp:receipts"
};
private String mVersion = null;
- //FIXME use appname or similar!!!!!!!!!!!11elf
- public final String IDENTITY_NAME = "Conversations+";
public final String IDENTITY_TYPE = "phone";
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
@@ -47,20 +45,9 @@ public abstract class AbstractGenerator {
this.mXmppConnectionService = service;
}
- protected String getIdentityVersion() {
- if (mVersion == null) {
- this.mVersion = PhoneHelper.getVersionName(mXmppConnectionService);
- }
- return this.mVersion;
- }
-
- protected String getIdentityName() {
- return IDENTITY_NAME + " " + getIdentityVersion();
- }
-
public String getCapHash() {
StringBuilder s = new StringBuilder();
- s.append("client/" + IDENTITY_TYPE + "//" + getIdentityName() + "<");
+ s.append("client/" + IDENTITY_TYPE + "//" + ConversationsPlusApplication.getNameAndVersion() + "<");
MessageDigest md;
try {
md = MessageDigest.getInstance("SHA-1");
diff --git a/src/main/java/eu/siacs/conversations/generator/IqGenerator.java b/src/main/java/eu/siacs/conversations/generator/IqGenerator.java
index 47915e3f..98122446 100644
--- a/src/main/java/eu/siacs/conversations/generator/IqGenerator.java
+++ b/src/main/java/eu/siacs/conversations/generator/IqGenerator.java
@@ -4,12 +4,12 @@ package eu.siacs.conversations.generator;
import java.util.ArrayList;
import java.util.List;
+import de.thedevstack.conversationsplus.ConversationsPlusApplication;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.DownloadableFile;
import eu.siacs.conversations.services.MessageArchiveService;
import eu.siacs.conversations.services.XmppConnectionService;
-import eu.siacs.conversations.utils.PhoneHelper;
import eu.siacs.conversations.utils.Xmlns;
import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xmpp.forms.Data;
@@ -33,7 +33,7 @@ public class IqGenerator extends AbstractGenerator {
final Element identity = query.addChild("identity");
identity.setAttribute("category", "client");
identity.setAttribute("type", IDENTITY_TYPE);
- identity.setAttribute("name", getIdentityName());
+ identity.setAttribute("name", ConversationsPlusApplication.getNameAndVersion());
for (final String feature : getFeatures()) {
query.addChild("feature").setAttribute("var", feature);
}
@@ -43,8 +43,8 @@ public class IqGenerator extends AbstractGenerator {
public IqPacket versionResponse(final IqPacket request) {
final IqPacket packet = request.generateResponse(IqPacket.TYPE.RESULT);
Element query = packet.query("jabber:iq:version");
- query.addChild("name").setContent(IDENTITY_NAME);
- query.addChild("version").setContent(getIdentityVersion());
+ query.addChild("name").setContent(ConversationsPlusApplication.getName());
+ query.addChild("version").setContent(ConversationsPlusApplication.getVersion());
return packet;
}
diff --git a/src/main/java/eu/siacs/conversations/services/NotificationService.java b/src/main/java/eu/siacs/conversations/services/NotificationService.java
index 683fcb04..a6194d6e 100644
--- a/src/main/java/eu/siacs/conversations/services/NotificationService.java
+++ b/src/main/java/eu/siacs/conversations/services/NotificationService.java
@@ -31,6 +31,7 @@ import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import de.thedevstack.conversationsplus.ConversationsPlusApplication;
import de.tzur.conversations.Settings;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
@@ -82,7 +83,7 @@ public class NotificationService {
final String notificationData = new JSONArray().put(jsonData).toString();
i.putExtra("messageType", "PEBBLE_ALERT");
- i.putExtra("sender", "Conversations"); /* XXX: Shouldn't be hardcoded, e.g., AbstractGenerator.APP_NAME); */
+ i.putExtra("sender", ConversationsPlusApplication.getName());
i.putExtra("notificationData", notificationData);
// notify Pebble App
i.setPackage("com.getpebble.android");
diff --git a/src/main/java/eu/siacs/conversations/ui/AboutPreference.java b/src/main/java/eu/siacs/conversations/ui/AboutPreference.java
index a57e1b89..6ad34257 100644
--- a/src/main/java/eu/siacs/conversations/ui/AboutPreference.java
+++ b/src/main/java/eu/siacs/conversations/ui/AboutPreference.java
@@ -6,7 +6,7 @@ import android.content.pm.PackageManager;
import android.preference.Preference;
import android.util.AttributeSet;
-import eu.siacs.conversations.utils.PhoneHelper;
+import de.thedevstack.conversationsplus.ConversationsPlusApplication;
public class AboutPreference extends Preference {
public AboutPreference(final Context context, final AttributeSet attrs, final int defStyle) {
@@ -27,7 +27,7 @@ public class AboutPreference extends Preference {
}
private void setSummary() {
- setSummary("Conversations " + PhoneHelper.getVersionName(getContext()));
+ setSummary(ConversationsPlusApplication.getNameAndVersion());
}
}
diff --git a/src/main/java/eu/siacs/conversations/utils/PhoneHelper.java b/src/main/java/eu/siacs/conversations/utils/PhoneHelper.java
index 99e8ebb8..e0556af3 100644
--- a/src/main/java/eu/siacs/conversations/utils/PhoneHelper.java
+++ b/src/main/java/eu/siacs/conversations/utils/PhoneHelper.java
@@ -15,6 +15,8 @@ import android.os.Bundle;
import android.provider.ContactsContract;
import android.provider.ContactsContract.Profile;
+import de.thedevstack.conversationsplus.ConversationsPlusApplication;
+
public class PhoneHelper {
public static void loadPhoneContacts(Context context,final List<Bundle> phoneContacts, final OnPhoneContactsLoadedListener listener) {
@@ -92,17 +94,4 @@ public class PhoneHelper {
}
}
}
-
- public static String getVersionName(Context context) {
- final String packageName = context == null ? null : context.getPackageName();
- if (packageName != null) {
- try {
- return context.getPackageManager().getPackageInfo(packageName, 0).versionName;
- } catch (final PackageManager.NameNotFoundException e) {
- return "unknown";
- }
- } else {
- return "unknown";
- }
- }
}