mirror of
https://github.com/gsantner/dandelion
synced 2024-12-22 19:08:03 +01:00
Made hashtags in textviews clickable. Hashtags open post editor with hashtag inserted. Also cleaned up text sharing in general
This commit is contained in:
parent
f26f1539ec
commit
240551f34c
7 changed files with 129 additions and 38 deletions
|
@ -12,6 +12,9 @@
|
|||
android:name="com.github.dfa.diaspora_android.App"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme" >
|
||||
<provider
|
||||
android:name="com.github.dfa.diaspora_android.data.HashtagProvider"
|
||||
android:authorities="com.github.dfa.diaspora_android.mainactivity" />
|
||||
<activity
|
||||
android:name="com.github.dfa.diaspora_android.activity.SplashActivity"
|
||||
android:launchMode="singleInstance"
|
||||
|
@ -60,6 +63,13 @@
|
|||
<data android:mimeType="text/plain" />
|
||||
</intent-filter>
|
||||
|
||||
<!-- Hashtag click intent from HtmlTextViews -->
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<data android:mimeType="vnd.android.cursor.item/vnd.cc.tag" />
|
||||
</intent-filter>
|
||||
|
||||
<!-- Intent from Web Browser / Mail / IM / Clickable Link -->
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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<Uri[]> 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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
|
||||
}
|
||||
}
|
|
@ -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" />
|
||||
</LinearLayout>
|
||||
</android.support.v4.widget.NestedScrollView>
|
||||
|
|
|
@ -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" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
|
@ -41,8 +40,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/fragment_license__3rd_party_libs_content"
|
||||
android:textAppearance="@android:style/TextAppearance.DeviceDefault.Small"
|
||||
android:linksClickable="true"
|
||||
android:autoLink="web"/>
|
||||
style="@android:style/TextAppearance.DeviceDefault.Small"
|
||||
android:linksClickable="true" />
|
||||
</LinearLayout>
|
||||
</android.support.v4.widget.NestedScrollView>
|
||||
|
|
Loading…
Reference in a new issue