Move feedback trigger and making link clickable to UiUtils

parent 920a1d04
......@@ -2,26 +2,24 @@ package org.briarproject.briar.android.keyagreement;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.SpannableStringBuilder;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import org.acra.ACRA;
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
import org.briarproject.bramble.api.system.AndroidExecutor;
import org.briarproject.briar.R;
import org.briarproject.briar.android.activity.ActivityComponent;
import org.briarproject.briar.android.fragment.BaseFragment;
import org.briarproject.briar.android.util.UserFeedback;
import org.briarproject.briar.android.util.UiUtils;
import javax.inject.Inject;
import static org.briarproject.briar.android.util.UiUtils.onSingleLinkClick;
@MethodsNotNullByDefault
@ParametersNotNullByDefault
public class ContactExchangeErrorFragment extends BaseFragment {
......@@ -70,24 +68,7 @@ public class ContactExchangeErrorFragment extends BaseFragment {
// make feedback link clickable
TextView explanation = v.findViewById(R.id.errorMessage);
SpannableStringBuilder ssb =
new SpannableStringBuilder(explanation.getText());
ClickableSpan[] spans =
ssb.getSpans(0, ssb.length(), ClickableSpan.class);
if (spans.length != 1) throw new AssertionError();
ClickableSpan span = spans[0];
int start = ssb.getSpanStart(span);
int end = ssb.getSpanEnd(span);
ssb.removeSpan(span);
ClickableSpan cSpan = new ClickableSpan() {
@Override
public void onClick(View v) {
triggerFeedback();
}
};
ssb.setSpan(cSpan, start + 1, end, 0);
explanation.setText(ssb);
explanation.setMovementMethod(new LinkMovementMethod());
onSingleLinkClick(explanation, this::triggerFeedback);
// technical error message
TextView msg = v.findViewById(R.id.errorMessageTech);
......@@ -110,9 +91,7 @@ public class ContactExchangeErrorFragment extends BaseFragment {
private void triggerFeedback() {
finish();
androidExecutor.runOnBackgroundThread(
() -> ACRA.getErrorReporter()
.handleException(new UserFeedback(), false));
UiUtils.triggerFeedback(androidExecutor);
}
}
......@@ -22,7 +22,6 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import org.acra.ACRA;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.event.Event;
import org.briarproject.bramble.api.event.EventBus;
......@@ -40,7 +39,6 @@ import org.briarproject.briar.R;
import org.briarproject.briar.android.Localizer;
import org.briarproject.briar.android.navdrawer.NavDrawerActivity;
import org.briarproject.briar.android.util.UiUtils;
import org.briarproject.briar.android.util.UserFeedback;
import java.util.ArrayList;
import java.util.Collections;
......@@ -88,6 +86,7 @@ import static org.briarproject.briar.android.TestingConstants.IS_DEBUG_BUILD;
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_RINGTONE;
import static org.briarproject.briar.android.navdrawer.NavDrawerActivity.INTENT_SIGN_OUT;
import static org.briarproject.briar.android.util.UiUtils.hasScreenLock;
import static org.briarproject.briar.android.util.UiUtils.triggerFeedback;
import static org.briarproject.briar.api.android.AndroidNotificationManager.BLOG_CHANNEL_ID;
import static org.briarproject.briar.api.android.AndroidNotificationManager.CONTACT_CHANNEL_ID;
import static org.briarproject.briar.api.android.AndroidNotificationManager.FORUM_CHANNEL_ID;
......@@ -210,7 +209,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
findPreference("pref_key_send_feedback").setOnPreferenceClickListener(
preference -> {
triggerFeedback();
triggerFeedback(androidExecutor);
return true;
});
......@@ -484,11 +483,6 @@ public class SettingsFragment extends PreferenceFragmentCompat
return true;
}
private void triggerFeedback() {
androidExecutor.runOnBackgroundThread(() -> ACRA.getErrorReporter()
.handleException(new UserFeedback(), false));
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (preference == language) {
......
......@@ -21,6 +21,7 @@ import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.format.DateUtils;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.text.style.ForegroundColorSpan;
import android.text.style.URLSpan;
......@@ -28,9 +29,11 @@ import android.util.TypedValue;
import android.view.View;
import android.widget.TextView;
import org.acra.ACRA;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
import org.briarproject.bramble.api.system.AndroidExecutor;
import org.briarproject.briar.R;
import org.briarproject.briar.android.view.ArticleMovementMethod;
import org.briarproject.briar.android.widget.LinkDialogFragment;
......@@ -147,6 +150,32 @@ public class UiUtils {
v.setMovementMethod(ArticleMovementMethod.getInstance());
}
/**
* Executes the runnable when clicking the link in the textView's text.
*
* Attention: This assumes that there's only <b>one</b> link in the text.
*/
public static void onSingleLinkClick(TextView textView, Runnable runnable) {
SpannableStringBuilder ssb =
new SpannableStringBuilder(textView.getText());
ClickableSpan[] spans =
ssb.getSpans(0, ssb.length(), ClickableSpan.class);
if (spans.length != 1) throw new AssertionError();
ClickableSpan span = spans[0];
int start = ssb.getSpanStart(span);
int end = ssb.getSpanEnd(span);
ssb.removeSpan(span);
ClickableSpan cSpan = new ClickableSpan() {
@Override
public void onClick(View v) {
runnable.run();
}
};
ssb.setSpan(cSpan, start + 1, end, 0);
textView.setText(ssb);
textView.setMovementMethod(new LinkMovementMethod());
}
public static String getAvatarTransitionName(ContactId c) {
return "avatar" + c.getInt();
}
......@@ -242,4 +271,10 @@ public class UiUtils {
(SDK_INT >= 23 && keyguardManager.isDeviceSecure());
}
public static void triggerFeedback(AndroidExecutor androidExecutor) {
androidExecutor.runOnBackgroundThread(
() -> ACRA.getErrorReporter()
.handleException(new UserFeedback(), false));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment