Linkify URLs and Bitmessage addresses

This commit is contained in:
Christian Basler 2015-11-17 22:19:11 +01:00
parent 9040026965
commit 055bd39a42
7 changed files with 66 additions and 55 deletions

View File

@ -3,7 +3,7 @@ apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "ch.dissem.apps.abit"
@ -22,9 +22,9 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:support-v4:23.1.0'
compile 'com.android.support:design:23.1.0'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'ch.dissem.jabit:jabit-domain:0.2.1-SNAPSHOT'
compile 'ch.dissem.jabit:jabit-networking:0.2.1-SNAPSHOT'
@ -38,7 +38,7 @@ dependencies {
compile 'com.mikepenz:iconics:1.6.2@aar'
compile 'com.mikepenz:community-material-typeface:1.1.71@aar'
}
5
idea.module {
downloadJavadoc = true
downloadSources = true

View File

@ -3,21 +3,36 @@ package ch.dissem.apps.abit;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.*;
import android.text.util.Linkify;
import android.text.util.Linkify.TransformFilter;
import android.util.Patterns;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.mikepenz.google_material_typeface_library.GoogleMaterial;
import java.util.Iterator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import ch.dissem.apps.abit.service.Singleton;
import ch.dissem.apps.abit.util.Drawables;
import ch.dissem.bitmessage.BitmessageContext;
import ch.dissem.bitmessage.entity.BitmessageAddress;
import ch.dissem.bitmessage.entity.Plaintext;
import ch.dissem.bitmessage.entity.valueobject.Label;
import ch.dissem.bitmessage.ports.MessageRepository;
import com.mikepenz.google_material_typeface_library.GoogleMaterial;
import java.util.Iterator;
import static android.text.util.Linkify.ALL;
import static android.text.util.Linkify.EMAIL_ADDRESSES;
import static android.text.util.Linkify.WEB_URLS;
import static ch.dissem.apps.abit.util.Constants.BITMESSAGE_ADDRESS_PATTERN;
import static ch.dissem.apps.abit.util.Constants.BITMESSAGE_URL_SCHEMA;
/**
@ -75,7 +90,19 @@ public class MessageDetailFragment extends Fragment {
} else if (item.getType() == Plaintext.Type.BROADCAST) {
((TextView) rootView.findViewById(R.id.recipient)).setText(R.string.broadcast);
}
((TextView) rootView.findViewById(R.id.text)).setText(item.getText());
TextView messageBody = (TextView) rootView.findViewById(R.id.text);
messageBody.setText(item.getText());
Linkify.addLinks(messageBody, WEB_URLS);
Linkify.addLinks(messageBody, BITMESSAGE_ADDRESS_PATTERN, BITMESSAGE_URL_SCHEMA, null,
new TransformFilter() {
public final String transformUrl(final Matcher match, String url) {
return match.group();
}
});
messageBody.setLinksClickable(true);
messageBody.setTextIsSelectable(true);
}
boolean removed = false;

View File

@ -71,7 +71,6 @@ public class OpenBitmessageLinkActivity extends AppCompatActivity {
final TextView addressView = (TextView) findViewById(R.id.address);
final EditText label = (EditText) findViewById(R.id.label);
final Switch importContact = (Switch) findViewById(R.id.import_contact);
final Switch subscribe = (Switch) findViewById(R.id.subscribe);
Uri uri = getIntent().getData();
@ -83,7 +82,6 @@ public class OpenBitmessageLinkActivity extends AppCompatActivity {
label.setText(parameter.substring(parameter.indexOf('=') + 1).trim());
} else if (name.startsWith("action")) {
parameter = parameter.toLowerCase();
importContact.setChecked(parameter.contains("add"));
subscribe.setChecked(parameter.contains("subscribe"));
}
}
@ -107,26 +105,21 @@ public class OpenBitmessageLinkActivity extends AppCompatActivity {
bmAddress.setAlias(label.getText().toString());
final int what;
if (subscribe.isChecked() && importContact.isChecked())
if (subscribe.isChecked())
what = MSG_SUBSCRIBE_AND_ADD_CONTACT;
else if (subscribe.isChecked())
what = MSG_SUBSCRIBE;
else if (importContact.isChecked())
what = MSG_ADD_CONTACT;
else
what = 0;
what = MSG_ADD_CONTACT;
if (what != 0) {
try {
Message message = Message.obtain(null, what);
Bundle bundle = new Bundle();
bundle.putSerializable(DATA_FIELD_ADDRESS, bmAddress);
message.setData(bundle);
service.send(message);
} catch (RemoteException e) {
LOG.error(e.getMessage(), e);
}
try {
Message message = Message.obtain(null, what);
Bundle bundle = new Bundle();
bundle.putSerializable(DATA_FIELD_ADDRESS, bmAddress);
message.setData(bundle);
service.send(message);
} catch (RemoteException e) {
LOG.error(e.getMessage(), e);
}
setResult(Activity.RESULT_OK);
finish();
}

View File

@ -0,0 +1,11 @@
package ch.dissem.apps.abit.util;
import java.util.regex.Pattern;
/**
* Created by chrigu on 16.11.15.
*/
public class Constants {
public static final String BITMESSAGE_URL_SCHEMA = "bitmessage:";
public static final Pattern BITMESSAGE_ADDRESS_PATTERN = Pattern.compile("\\bBM-[a-zA-Z0-9]+\\b");
}

View File

@ -26,20 +26,11 @@
</android.support.design.widget.TextInputLayout>
<Switch
android:id="@+id/import_contact"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/label_wrapper"
android:layout_centerHorizontal="true"
android:layout_marginTop="8dp"
android:text="@string/import_contact" />
<Switch
android:id="@+id/subscribe"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/import_contact"
android:layout_below="@+id/label_wrapper"
android:layout_centerHorizontal="true"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
@ -57,25 +48,14 @@
android:layout_marginTop="12dp"
android:text="@string/do_import" />
<Button
android:id="@+id/compose_message"
style="?android:attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/do_import"
android:layout_below="@+id/subscribe"
android:layout_toLeftOf="@+id/do_import"
android:layout_toStartOf="@+id/do_import"
android:text="@string/write_message" />
<Button
android:id="@+id/cancel"
style="?android:attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/compose_message"
android:layout_toLeftOf="@+id/compose_message"
android:layout_toStartOf="@+id/compose_message"
android:layout_alignTop="@+id/do_import"
android:layout_toLeftOf="@+id/do_import"
android:layout_toStartOf="@+id/do_import"
android:text="@string/cancel" />
</RelativeLayout>

View File

@ -9,7 +9,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.4.+'
classpath 'com.android.tools.build:gradle:1.5.0-beta1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files

View File

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip