diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 4dc906ff..5f869ef1 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -12,6 +12,9 @@
android:name="com.github.dfa.diaspora_android.App"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
+
+
+
+
+
+
+
+
diff --git a/app/src/main/java/com/github/dfa/diaspora_android/activity/AboutActivity.java b/app/src/main/java/com/github/dfa/diaspora_android/activity/AboutActivity.java
index 7ffe528d..e32cc66a 100644
--- a/app/src/main/java/com/github/dfa/diaspora_android/activity/AboutActivity.java
+++ b/app/src/main/java/com/github/dfa/diaspora_android/activity/AboutActivity.java
@@ -1,5 +1,9 @@
package com.github.dfa.diaspora_android.activity;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
@@ -29,6 +33,12 @@ public class AboutActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);
+ registerReceiver(new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ Log.d("INTREC", intent.toString());
+ }
+ }, new IntentFilter(Intent.ACTION_VIEW));
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
toolbar.setNavigationIcon(getResources().getDrawable(R.drawable.ic_arrow_back_white_24px));
diff --git a/app/src/main/java/com/github/dfa/diaspora_android/activity/MainActivity.java b/app/src/main/java/com/github/dfa/diaspora_android/activity/MainActivity.java
index 39e10d50..ffcf3464 100644
--- a/app/src/main/java/com/github/dfa/diaspora_android/activity/MainActivity.java
+++ b/app/src/main/java/com/github/dfa/diaspora_android/activity/MainActivity.java
@@ -114,6 +114,7 @@ public class MainActivity extends AppCompatActivity
public static final String ACTION_RELOAD_ACTIVITY = "com.github.dfa.diaspora_android.MainActivity.reload_activity";
public static final String URL_MESSAGE = "URL_MESSAGE";
public static final String EXTRA_URL = "com.github.dfa.diaspora_android.extra_url";
+ public static final String CONTENT_HASHTAG = "content://com.github.dfa.diaspora_android.mainactivity/";
private App app;
private ValueCallback mFilePathCallback;
@@ -457,11 +458,16 @@ public class MainActivity extends AppCompatActivity
String type = intent.getType();
String loadUrl = null;
-
if (ACTION_OPEN_URL.equals(action)) {
loadUrl = intent.getStringExtra(URL_MESSAGE);
} else if (Intent.ACTION_VIEW.equals(action) && intent.getDataString() != null) {
- loadUrl = intent.getDataString();
+ Uri data = intent.getData();
+ if(data != null && data.toString().startsWith(CONTENT_HASHTAG)) {
+ handleHashtag(intent);
+ return;
+ } else {
+ loadUrl = intent.getDataString();
+ }
} else if (ACTION_CHANGE_ACCOUNT.equals(action)) {
app.resetPodData(webView);
Helpers.animateToActivity(MainActivity.this, PodSelectionActivity.class, true);
@@ -858,18 +864,13 @@ public class MainActivity extends AppCompatActivity
app.getAvatarImageLoader().startImageDownload(navheaderImage, avatarUrl);
}
+ private void handleHashtag(Intent intent) {
+ setSharedTexts(null, intent.getData().toString().split("/")[3]);
+ webView.loadUrlNew(urls.getNewPostUrl());
+ }
+
private void handleSendText(Intent intent) {
- String content = WebHelper.replaceUrlWithMarkdown(intent.getStringExtra(Intent.EXTRA_TEXT));
- if (appSettings.isAppendSharedViaApp()) {
- //
= \n
- content = content + "\n\n" + getString(R.string.shared_by_diaspora_android);
- }
-
- final String sharedText = WebHelper.escapeHtmlText(content);
- if (sharedText != null) {
- textToBeShared = sharedText;
- }
-
+ setSharedTexts(null, intent.getStringExtra(Intent.EXTRA_TEXT));
webView.loadUrlNew(urls.getBlankUrl());
webView.loadUrlNew(urls.getNewPostUrl());
}
@@ -880,23 +881,35 @@ public class MainActivity extends AppCompatActivity
* @param intent intent
*/
private void handleSendSubject(Intent intent) {
- webView.loadUrlNew(urls.getNewPostUrl());
- String content = WebHelper.replaceUrlWithMarkdown(intent.getStringExtra(Intent.EXTRA_TEXT));
- String subject = WebHelper.replaceUrlWithMarkdown(intent.getStringExtra(Intent.EXTRA_SUBJECT));
-
- if (appSettings.isAppendSharedViaApp()) {
- //
= \n
- content = content + "\n\n" + getString(R.string.shared_by_diaspora_android);
- }
-
- final String sharedSubject = WebHelper.escapeHtmlText(subject);
- final String sharedContent = WebHelper.escapeHtmlText(content);
- textToBeShared = "**" + sharedSubject + "** " + sharedContent;
-
+ setSharedTexts(intent.getStringExtra(Intent.EXTRA_SUBJECT), intent.getStringExtra(Intent.EXTRA_TEXT));
webView.loadUrlNew(urls.getBlankUrl());
webView.loadUrlNew(urls.getNewPostUrl());
}
+ /**
+ * Set sharedText variable to escaped and formatted subject + body.
+ * If subject is null, only the body will be set. Else the subject will be set as header.
+ * Depending on whether the user has the setting isAppendSharedViaApp set, a reference to
+ * the app will be added at the bottom
+ * @param sharedSubject post subject or null
+ * @param sharedBody post text
+ */
+ private void setSharedTexts(String sharedSubject, String sharedBody) {
+ String body = WebHelper.replaceUrlWithMarkdown(sharedBody);
+ if (appSettings.isAppendSharedViaApp()) {
+ body = body + "\n\n" + getString(R.string.shared_by_diaspora_android);
+ }
+ final String escapedBody = WebHelper.escapeHtmlText(body);
+ if(sharedSubject != null) {
+ String escapedSubject = WebHelper.escapeHtmlText(WebHelper.replaceUrlWithMarkdown(sharedSubject));
+ textToBeShared = "**" + escapedSubject + "** " + escapedBody;
+ } else {
+ textToBeShared = escapedBody;
+ }
+
+
+ }
+
//TODO: Implement?
private void handleSendImage(Intent intent) {
final Uri imageUri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
diff --git a/app/src/main/java/com/github/dfa/diaspora_android/data/HashtagProvider.java b/app/src/main/java/com/github/dfa/diaspora_android/data/HashtagProvider.java
new file mode 100644
index 00000000..e31825ac
--- /dev/null
+++ b/app/src/main/java/com/github/dfa/diaspora_android/data/HashtagProvider.java
@@ -0,0 +1,46 @@
+package com.github.dfa.diaspora_android.data;
+
+import android.content.ContentProvider;
+import android.content.ContentValues;
+import android.database.Cursor;
+import android.net.Uri;
+
+public class HashtagProvider extends ContentProvider {
+
+ @Override
+ public int delete(Uri arg0, String arg1, String[] arg2) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public String getType(Uri arg0) {
+ return "vnd.android.cursor.item/vnd.cc.tag";
+ }
+
+ @Override
+ public Uri insert(Uri arg0, ContentValues arg1) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public boolean onCreate() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public Cursor query(Uri arg0, String[] arg1, String arg2, String[] arg3,
+ String arg4) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public int update(Uri arg0, ContentValues arg1, String arg2, String[] arg3) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/github/dfa/diaspora_android/ui/HtmlTextView.java b/app/src/main/java/com/github/dfa/diaspora_android/ui/HtmlTextView.java
index cb8b30ea..bb90c344 100644
--- a/app/src/main/java/com/github/dfa/diaspora_android/ui/HtmlTextView.java
+++ b/app/src/main/java/com/github/dfa/diaspora_android/ui/HtmlTextView.java
@@ -6,9 +6,13 @@ import android.text.Html;
import android.text.SpannableString;
import android.text.util.Linkify;
import android.util.AttributeSet;
+import android.util.Patterns;
import android.widget.TextView;
-import com.github.dfa.diaspora_android.R;
+import com.github.dfa.diaspora_android.activity.MainActivity;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
public class HtmlTextView extends TextView {
@@ -34,8 +38,19 @@ public class HtmlTextView extends TextView {
}
private void init(){
- final SpannableString content = new SpannableString(Html.fromHtml(getText().toString()));
- Linkify.addLinks(content, Linkify.WEB_URLS);
- setText(content);
+ setText(new SpannableString(Html.fromHtml(getText().toString())));
+ Linkify.TransformFilter filter = new Linkify.TransformFilter() {
+ public final String transformUrl(final Matcher match, String url) {
+ return match.group();
+ }
+ };
+
+ Pattern hashtagPattern = Pattern.compile("[#]+[A-Za-z0-9-_]+\\b");
+ String hashtagScheme = MainActivity.CONTENT_HASHTAG;
+ Linkify.addLinks(this, hashtagPattern, hashtagScheme, null, filter);
+
+ Pattern urlPattern = Patterns.WEB_URL;
+ Linkify.addLinks(this, urlPattern, null, null, filter);
+
}
}
\ No newline at end of file
diff --git a/app/src/main/res/layout/fragment_about.xml b/app/src/main/res/layout/fragment_about.xml
index 165398e1..579b1a2e 100644
--- a/app/src/main/res/layout/fragment_about.xml
+++ b/app/src/main/res/layout/fragment_about.xml
@@ -39,7 +39,6 @@
android:layout_height="wrap_content"
android:text="@string/fragment_about__about_content"
style="@android:style/TextAppearance.DeviceDefault.Small"
- android:linksClickable="true"
- android:autoLink="web"/>
+ android:linksClickable="true" />
diff --git a/app/src/main/res/layout/fragment_license.xml b/app/src/main/res/layout/fragment_license.xml
index 63859d21..ae3956a8 100644
--- a/app/src/main/res/layout/fragment_license.xml
+++ b/app/src/main/res/layout/fragment_license.xml
@@ -26,9 +26,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/fragment_license__license_content"
- android:textAppearance="@android:style/TextAppearance.DeviceDefault.Small"
- android:linksClickable="true"
- android:autoLink="web"/>
+ style="@android:style/TextAppearance.DeviceDefault.Small"
+ android:linksClickable="true" />
+ style="@android:style/TextAppearance.DeviceDefault.Small"
+ android:linksClickable="true" />