mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-26 08:37:29 +00:00
textutils cleanup
This commit is contained in:
parent
0c72e66768
commit
b3a0344d6d
@ -19,7 +19,6 @@ import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.activity.OnBackPressedCallback;
|
||||
@ -72,6 +71,7 @@ import awais.instagrabber.webservices.StoriesService;
|
||||
import awaisomereport.LogCollector;
|
||||
|
||||
import static androidx.core.content.PermissionChecker.checkSelfPermission;
|
||||
import static awais.instagrabber.fragments.HashTagFragment.ARG_HASHTAG;
|
||||
import static awais.instagrabber.utils.DownloadUtils.WRITE_PERMISSION;
|
||||
import static awais.instagrabber.utils.Utils.logCollector;
|
||||
import static awais.instagrabber.utils.Utils.settingsHelper;
|
||||
@ -414,15 +414,29 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
|
||||
|
||||
if (TextUtils.isEmpty(biography)) {
|
||||
locationDetailsBinding.locationBiography.setVisibility(View.GONE);
|
||||
} else if (TextUtils.hasMentions(biography)) {
|
||||
locationDetailsBinding.locationBiography.setVisibility(View.VISIBLE);
|
||||
biography = TextUtils.getMentionText(biography);
|
||||
locationDetailsBinding.locationBiography.setText(biography, TextView.BufferType.SPANNABLE);
|
||||
// binding.locationBiography.setMentionClickListener(mentionClickListener);
|
||||
} else {
|
||||
locationDetailsBinding.locationBiography.setVisibility(View.VISIBLE);
|
||||
locationDetailsBinding.locationBiography.setText(biography);
|
||||
locationDetailsBinding.locationBiography.setMentionClickListener(null);
|
||||
locationDetailsBinding.locationBiography.addOnHashtagListener(autoLinkItem -> {
|
||||
final NavController navController = NavHostFragment.findNavController(this);
|
||||
final Bundle bundle = new Bundle();
|
||||
final String originalText = autoLinkItem.getOriginalText().trim();
|
||||
bundle.putString(ARG_HASHTAG, originalText);
|
||||
navController.navigate(R.id.action_global_hashTagFragment, bundle);
|
||||
});
|
||||
locationDetailsBinding.locationBiography.addOnMentionClickListener(autoLinkItem -> {
|
||||
final String originalText = autoLinkItem.getOriginalText().trim();
|
||||
navigateToProfile(originalText);
|
||||
});
|
||||
locationDetailsBinding.locationBiography.addOnEmailClickListener(autoLinkItem -> Utils.openEmailAddress(getContext(),
|
||||
autoLinkItem.getOriginalText()
|
||||
.trim()));
|
||||
locationDetailsBinding.locationBiography
|
||||
.addOnURLClickListener(autoLinkItem -> Utils.openURL(getContext(), autoLinkItem.getOriginalText().trim()));
|
||||
locationDetailsBinding.locationBiography.setOnLongClickListener(v -> {
|
||||
Utils.copyText(context, biography);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
if (!locationModel.getGeo().startsWith("geo:0.0,0.0?z=17")) {
|
||||
|
@ -29,7 +29,7 @@ public final class NotificationModel {
|
||||
final String previewUrl,
|
||||
final NotificationType type) {
|
||||
this.id = id;
|
||||
this.text = TextUtils.hasMentions(text) ? TextUtils.getMentionText(text) : text;
|
||||
this.text = text;
|
||||
this.timestamp = timestamp;
|
||||
this.userId = userId;
|
||||
this.username = username;
|
||||
|
@ -24,56 +24,6 @@ import java.util.regex.Pattern;
|
||||
import awais.instagrabber.customviews.CommentMentionClickSpan;
|
||||
|
||||
public final class TextUtils {
|
||||
private static final Pattern URL_PATTERN = Pattern.compile(
|
||||
"(^|[\\s.:;?\\-\\]<\\(])((https?://|www\\.|pic\\.)[-\\w;/?:@&=+$\\|\\_.!~*\\|'()\\[\\]%#,☺]+[\\w/#](\\(\\))?)(?=$|[\\s',\\|\\(\\).:;?\\-\\[\\]>\\)])");
|
||||
|
||||
@NonNull
|
||||
public static CharSequence getMentionText(@NonNull final CharSequence text) {
|
||||
final int commentLength = text.length();
|
||||
final SpannableStringBuilder stringBuilder = new SpannableStringBuilder(text, 0, commentLength);
|
||||
|
||||
for (int i = 0; i < commentLength; ++i) {
|
||||
char currChar = text.charAt(i);
|
||||
|
||||
if (currChar == '@' || currChar == '#') {
|
||||
final int startLen = i;
|
||||
|
||||
do {
|
||||
if (++i == commentLength) break;
|
||||
currChar = text.charAt(i);
|
||||
|
||||
if (currChar == '.' && i + 1 < commentLength) {
|
||||
final char nextChar = text.charAt(i + 1);
|
||||
if (nextChar == '.' || nextChar == ' ' || nextChar == '#' || nextChar == '@' || nextChar == '/'
|
||||
|| nextChar == '\r' || nextChar == '\n') {
|
||||
break;
|
||||
}
|
||||
} else if (currChar == '.')
|
||||
break;
|
||||
|
||||
// for merged hashtags
|
||||
if (currChar == '#') {
|
||||
--i;
|
||||
break;
|
||||
}
|
||||
} while (currChar != ' ' && currChar != '\r' && currChar != '\n' && currChar != '>' && currChar != '<'
|
||||
&& currChar != ':' && currChar != ';' && currChar != '\'' && currChar != '"' && currChar != '['
|
||||
&& currChar != ']' && currChar != '\\' && currChar != '=' && currChar != '-' && currChar != '!'
|
||||
&& currChar != '$' && currChar != '%' && currChar != '^' && currChar != '&' && currChar != '*'
|
||||
&& currChar != '(' && currChar != ')' && currChar != '{' && currChar != '}' && currChar != '/'
|
||||
&& currChar != '|' && currChar != '?' && currChar != '`' && currChar != '~'
|
||||
);
|
||||
|
||||
final int endLen = currChar != '#' ? i : i + 1; // for merged hashtags
|
||||
stringBuilder.setSpan(new CommentMentionClickSpan(), startLen,
|
||||
Math.min(commentLength, endLen), // fixed - crash when end index is greater than comment length ( @kernoeb )
|
||||
Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
|
||||
}
|
||||
}
|
||||
|
||||
return stringBuilder;
|
||||
}
|
||||
|
||||
// extracted from String class
|
||||
public static int indexOfChar(@NonNull final CharSequence sequence, final int ch, final int startIndex) {
|
||||
final int max = sequence.length();
|
||||
@ -90,11 +40,6 @@ public final class TextUtils {
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static boolean hasMentions(final CharSequence text) {
|
||||
if (isEmpty(text)) return false;
|
||||
return indexOfChar(text, '@', 0) != -1 || indexOfChar(text, '#', 0) != -1;
|
||||
}
|
||||
|
||||
public static CharSequence getSpannableUrl(final String url) {
|
||||
if (isEmpty(url)) return url;
|
||||
final int httpIndex = url.indexOf("http:");
|
||||
|
@ -83,24 +83,18 @@
|
||||
app:layout_constraintTop_toBottomOf="@id/mainLocationImage"
|
||||
tools:text="OUR HOUSE" />
|
||||
|
||||
<awais.instagrabber.customviews.RamboTextView
|
||||
<awais.instagrabber.customviews.RamboTextViewV2
|
||||
android:id="@+id/locationBiography"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/locationFullName"
|
||||
android:padding="8dp"
|
||||
android:background="?android:selectableItemBackground"
|
||||
android:paddingStart="8dp"
|
||||
android:paddingLeft="8dp"
|
||||
android:paddingEnd="8dp"
|
||||
android:paddingRight="8dp"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintBottom_toTopOf="@id/locationUrl"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/locationFullName"
|
||||
tools:text="IN THE MIDDLE OF OUR STREET"
|
||||
tools:visibility="visible" />
|
||||
tools:text="IN THE MIDDLE OF OUR STREET" />
|
||||
|
||||
<awais.instagrabber.customviews.RamboTextView
|
||||
android:id="@+id/locationUrl"
|
||||
|
Loading…
Reference in New Issue
Block a user