* This is not threadsafe.
*
* @param context {@link Context} to use for accessing {@link PackageManager}.
@@ -107,6 +107,7 @@ public class CustomTabsHelper {
/**
* Used to check whether there is a specialized handler for a given intent.
+ *
* @param intent The intent to check with.
* @return Whether there is a specialized handler for the given intent.
*/
@@ -127,7 +128,7 @@ public class CustomTabsHelper {
return true;
}
} catch (RuntimeException e) {
- AppLog.e(TAG, "Runtime exception while getting specialized handlers");
+ AppLog.e(TAG, "Runtime exception while getting specialized handlers");
}
return false;
}
diff --git a/app/src/main/java/com/github/dfa/diaspora_android/util/DiasporaUrlHelper.java b/app/src/main/java/com/github/dfa/diaspora_android/util/DiasporaUrlHelper.java
index b3c99805..e13eae48 100644
--- a/app/src/main/java/com/github/dfa/diaspora_android/util/DiasporaUrlHelper.java
+++ b/app/src/main/java/com/github/dfa/diaspora_android/util/DiasporaUrlHelper.java
@@ -21,6 +21,7 @@ package com.github.dfa.diaspora_android.util;
import com.github.dfa.diaspora_android.App;
import com.github.dfa.diaspora_android.R;
import com.github.dfa.diaspora_android.data.AppSettings;
+import com.github.dfa.diaspora_android.data.DiasporaPodList.DiasporaPod;
import com.github.dfa.diaspora_android.data.PodAspect;
/**
@@ -31,7 +32,6 @@ import com.github.dfa.diaspora_android.data.PodAspect;
public class DiasporaUrlHelper {
private final AppSettings settings;
- public static final String HTTPS = "https://";
public static final String SUBURL_NOTIFICATIONS = "/notifications";
public static final String SUBURL_POSTS = "/posts/";
public static final String SUBURL_STREAM = "/stream";
@@ -49,6 +49,10 @@ public class DiasporaUrlHelper {
public static final String SUBURL_FOLOWED_TAGS = "/followed_tags";
public static final String SUBURL_ASPECTS = "/aspects";
public static final String SUBURL_STATISTICS = "/statistics";
+ public static final String SUBURL_PERSONAL_SETTINGS = "/user/edit";
+ public static final String SUBURL_MANAGE_TAGS = "/tag_followings/manage";
+ public static final String SUBURL_SIGN_IN = "/users/sign_in";
+ public static final String SUBURL_MANAGE_CONTACTS = "/contacts";
public static final String URL_BLANK = "about:blank";
public DiasporaUrlHelper(AppSettings settings) {
@@ -56,17 +60,22 @@ public class DiasporaUrlHelper {
}
/**
- * Return a https url of the pod set in AppSettings.
+ * Return a url of the pod set in AppSettings.
* Eg. https://pod.geraspora.de
*
* @return https://(pod-domain.tld)
*/
public String getPodUrl() {
- return HTTPS + settings.getPodDomain();
+ DiasporaPod pod = settings.getPod();
+ if (pod != null) {
+ return pod.getPodUrl().getBaseUrl();
+ }
+ return "http://127.0.0.1";
+
}
/**
- * Return a https url that points to the stream of the configured diaspora account
+ * Return a url that points to the stream of the configured diaspora account
*
* @return https://(pod-domain.tld)/stream
*/
@@ -75,7 +84,7 @@ public class DiasporaUrlHelper {
}
/**
- * Return a https url that points to the notifications feed of the configured diaspora account
+ * Return a url that points to the notifications feed of the configured diaspora account
*
* @return https://(pod-domain.tld)/notifications
*/
@@ -84,7 +93,7 @@ public class DiasporaUrlHelper {
}
/**
- * Returns a https url that points to the post with the id postId
+ * Returns a url that points to the post with the id postId
*
* @return https://(pod-domain.tld)/posts/(postId)
*/
@@ -93,7 +102,7 @@ public class DiasporaUrlHelper {
}
/**
- * Return a https url that points to the conversations overview of the registered diaspora account
+ * Return a url that points to the conversations overview of the registered diaspora account
*
* @return https://(pod-domain.tld)/conversations
*/
@@ -102,7 +111,7 @@ public class DiasporaUrlHelper {
}
/**
- * Return a https url that points to the new-post form that lets the user create a new post
+ * Return a url that points to the new-post form that lets the user create a new post
*
* @return https://(pod-domain.tld)/status_messages/new
*/
@@ -111,7 +120,7 @@ public class DiasporaUrlHelper {
}
/**
- * Return a https url that shows the profile of the currently registered diaspora account
+ * Return a url that shows the profile of the currently registered diaspora account
*
* @return https://(pod-domain.tld)/people/(profileId)
*/
@@ -120,7 +129,7 @@ public class DiasporaUrlHelper {
}
/**
- * Return a https url that shows the profile of the user with user id profileId
+ * Return a url that shows the profile of the user with user id profileId
*
* @param profileId Id of the profile to be shown
* @return https://(pod-domain.tld)/people/(profileId)
@@ -130,7 +139,7 @@ public class DiasporaUrlHelper {
}
/**
- * Return a https url that points to the activities feed of the currently registered diaspora account
+ * Return a url that points to the activities feed of the currently registered diaspora account
*
* @return https://(pod-domain.tld)/activity
*/
@@ -139,7 +148,7 @@ public class DiasporaUrlHelper {
}
/**
- * Return a https url that points to the feed of posts that were liked by the currently registered diaspora account
+ * Return a url that points to the feed of posts that were liked by the currently registered diaspora account
*
* @return https://(pod-domain.tld)/liked
*/
@@ -148,7 +157,7 @@ public class DiasporaUrlHelper {
}
/**
- * Return a https url that points to the stream of posts that were commented by the currently registered diaspora account
+ * Return a url that points to the stream of posts that were commented by the currently registered diaspora account
*
* @return https://(pod-domain.tld)/commented
*/
@@ -157,7 +166,7 @@ public class DiasporaUrlHelper {
}
/**
- * Return a https url that points to the stream of posts in which the currently registered diaspora account has been mentioned in
+ * Return a url that points to the stream of posts in which the currently registered diaspora account has been mentioned in
*
* @return https://(pod-domain.tld)/mentions
*/
@@ -166,7 +175,7 @@ public class DiasporaUrlHelper {
}
/**
- * Return a https url that points to the stream of public posts
+ * Return a url that points to the stream of public posts
*
* @return https://(pod-domain.tld)/public
*/
@@ -175,7 +184,7 @@ public class DiasporaUrlHelper {
}
/**
- * Return a https url that toggles between mobile and desktop view when opened
+ * Return a url that toggles between mobile and desktop view when opened
*
* @return https://(pod-domain.tld)/mobile/toggle
*/
@@ -184,7 +193,7 @@ public class DiasporaUrlHelper {
}
/**
- * Return a https url that queries posts for the given hashtag query
+ * Return a url that queries posts for the given hashtag query
*
* @param query hashtag to be searched
* @return https://(pod-domain.tld)/tags/query
@@ -194,7 +203,7 @@ public class DiasporaUrlHelper {
}
/**
- * Return a https url that queries user accounts for query
+ * Return a url that queries user accounts for query
*
* @param query search term
* @return https://(pod-domain.tld)/people.mobile?q=(query)
@@ -204,13 +213,50 @@ public class DiasporaUrlHelper {
}
/**
- * Return a https url that points to the statistics page of the pod.
+ * Return a url that points to the statistics page of the pod.
+ *
* @return https://(pod-domain.tld)/statistics
*/
public String getStatisticsUrl() {
return getPodUrl() + SUBURL_STATISTICS;
}
+ /**
+ * Return a url that points to the sign in page of the pod.
+ *
+ * @return https://(pod-domain.tld)/users/sign_in
+ */
+ public String getSignInUrl() {
+ return getPodUrl() + SUBURL_SIGN_IN;
+ }
+
+ /**
+ * Return a url that points to the personal settings page of the pod.
+ *
+ * @return https://(pod-domain.tld)/user/edit
+ */
+ public String getPersonalSettingsUrl() {
+ return getPodUrl() + SUBURL_PERSONAL_SETTINGS;
+ }
+
+ /**
+ * Return a url that points to the manage tags page of the pod.
+ *
+ * @return https://(pod-domain.tld)/tag_followings/manage
+ */
+ public String getManageTagsUrl() {
+ return getPodUrl() + SUBURL_MANAGE_TAGS;
+ }
+
+ /**
+ * Return a url that points to the manage tags page of the pod.
+ *
+ * @return https://(pod-domain.tld)/contacts
+ */
+ public String getManageContactsUrl() {
+ return getPodUrl() + SUBURL_MANAGE_CONTACTS;
+ }
+
/**
* Returns the url of the blank WebView
*
diff --git a/app/src/main/java/com/github/dfa/diaspora_android/util/Helpers.java b/app/src/main/java/com/github/dfa/diaspora_android/util/Helpers.java
index 2c4ba62b..68b10dca 100644
--- a/app/src/main/java/com/github/dfa/diaspora_android/util/Helpers.java
+++ b/app/src/main/java/com/github/dfa/diaspora_android/util/Helpers.java
@@ -26,8 +26,9 @@ import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
+import android.support.design.widget.Snackbar;
+import android.view.View;
-import com.github.dfa.diaspora_android.App;
import com.github.dfa.diaspora_android.R;
import java.io.BufferedReader;
@@ -72,7 +73,7 @@ public class Helpers {
// Create an image file name
String timeStamp = new SimpleDateFormat("dd-MM-yy_HH-mm", Locale.getDefault()).format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
- AppLog.d(Helpers.class, Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath());
+ AppLog.d(Helpers.class, Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath());
File storageDir = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES);
return new File(
@@ -120,18 +121,32 @@ public class Helpers {
public static void printBundle(Bundle savedInstanceState, String k) {
if (savedInstanceState != null) {
for (String key : savedInstanceState.keySet()) {
- AppLog.d("SAVED", key + " is a key in the bundle " + k);
+ AppLog.d("SAVED", key + " is a key in the bundle " + k);
Object bun = savedInstanceState.get(key);
if (bun != null) {
if (bun instanceof Bundle) {
printBundle((Bundle) bun, k + "." + key);
} else if (bun instanceof byte[]) {
- AppLog.d("SAVED", "Key: " + k + "." + key + ": " + Arrays.toString((byte[]) bun));
+ AppLog.d("SAVED", "Key: " + k + "." + key + ": " + Arrays.toString((byte[]) bun));
} else {
- AppLog.d("SAVED", "Key: " + k + "." + key + ": " + bun.toString());
+ AppLog.d("SAVED", "Key: " + k + "." + key + ": " + bun.toString());
}
}
}
}
}
+
+ /**
+ * Show Information if user is offline, returns true if is not connected to internet
+ *
+ * @param context Context
+ * @param anchor A view anchor
+ */
+ public static boolean showInfoIfUserNotConnectedToInternet(Context context, View anchor) {
+ boolean isOnline = WebHelper.isOnline(context);
+ if (!isOnline) {
+ Snackbar.make(anchor, R.string.no_internet, Snackbar.LENGTH_LONG).show();
+ }
+ return !isOnline;
+ }
}
diff --git a/app/src/main/java/com/github/dfa/diaspora_android/util/Log.java b/app/src/main/java/com/github/dfa/diaspora_android/util/Log.java
index f8743b1d..2cca9acf 100644
--- a/app/src/main/java/com/github/dfa/diaspora_android/util/Log.java
+++ b/app/src/main/java/com/github/dfa/diaspora_android/util/Log.java
@@ -43,8 +43,9 @@ public class Log extends Observable {
private Log() {
this(null);
}
+
private Log(AppSettings appSettings) {
- if(appSettings != null) {
+ if (appSettings != null) {
//TODO: Store/Restore logBuffer between app starts
logBuffer = new ArrayList<>();
} else {
@@ -55,17 +56,17 @@ public class Log extends Observable {
}
public static Log getInstance() {
- if(instance == null) instance = new Log();
+ if (instance == null) instance = new Log();
return instance;
}
public static Log getInstance(AppSettings appSettings) {
- if(instance == null) instance = new Log(appSettings);
+ if (instance == null) instance = new Log(appSettings);
return instance;
}
private static String time() {
- return getInstance().dateFormat.format(new Date())+": ";
+ return getInstance().dateFormat.format(new Date()) + ": ";
}
public static void d(String tag, String msg) {
@@ -116,23 +117,23 @@ public class Log extends Observable {
public synchronized static String getLogBuffer() {
String out = "";
- for(String s : getInstance().logBuffer) {
+ for (String s : getInstance().logBuffer) {
out = out + s + "\n";
}
return out;
}
private void notifyLogBufferChanged() {
- if(observers == null) return;
- for(Observer o : observers) {
- if(o != null) {
+ if (observers == null) return;
+ for (Observer o : observers) {
+ if (o != null) {
o.update(this, null);
}
}
}
private synchronized void addLogEntry(String msg) {
- logBuffer.add(time()+msg);
+ logBuffer.add(time() + msg);
while (logBuffer.size() > MAX_BUFFER_SIZE) {
logBuffer.remove(0);
}
diff --git a/app/src/main/java/com/github/dfa/diaspora_android/util/ProxyHandler.java b/app/src/main/java/com/github/dfa/diaspora_android/util/ProxyHandler.java
index a2cbf924..d3ab9711 100644
--- a/app/src/main/java/com/github/dfa/diaspora_android/util/ProxyHandler.java
+++ b/app/src/main/java/com/github/dfa/diaspora_android/util/ProxyHandler.java
@@ -46,7 +46,7 @@ public class ProxyHandler {
}
public static ProxyHandler getInstance() {
- if(instance == null) {
+ if (instance == null) {
instance = new ProxyHandler();
}
return instance;
@@ -77,7 +77,7 @@ public class ProxyHandler {
public void addWebView(WebView wv) {
AppLog.d(this, "AddWebView");
- if(wv != null && !webViews.contains(wv)) {
+ if (wv != null && !webViews.contains(wv)) {
webViews.add(wv);
updateWebViewProxySettings(wv, wv.getContext());
}
@@ -89,7 +89,7 @@ public class ProxyHandler {
StrictMode.ThreadPolicy old = StrictMode.getThreadPolicy();
StrictMode.ThreadPolicy tmp = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(tmp);
- if(appSettings.isProxyEnabled()) {
+ if (appSettings.isProxyEnabled()) {
if (wv != null) {
try {
WebkitProxy.setProxy(MainActivity.class.getName(), context.getApplicationContext(), wv, appSettings.getProxyHost(), appSettings.getProxyPort());
diff --git a/app/src/main/java/com/github/dfa/diaspora_android/util/WebHelper.java b/app/src/main/java/com/github/dfa/diaspora_android/util/WebHelper.java
index ba760d7b..21861da6 100644
--- a/app/src/main/java/com/github/dfa/diaspora_android/util/WebHelper.java
+++ b/app/src/main/java/com/github/dfa/diaspora_android/util/WebHelper.java
@@ -16,7 +16,7 @@
If not, see