bug fix, version upgrade

This commit is contained in:
nuclearfog 2022-01-28 18:15:01 +01:00
parent 8d0971b284
commit 2ef2f8acec
No known key found for this signature in database
GPG Key ID: AA0271FBE406DB98
10 changed files with 42 additions and 34 deletions

View File

@ -12,8 +12,8 @@ android {
applicationId 'org.nuclearfog.twidda' applicationId 'org.nuclearfog.twidda'
minSdkVersion 16 minSdkVersion 16
targetSdkVersion 31 targetSdkVersion 31
versionCode 54 versionCode 55
versionName '2.0.1' versionName '2.0.2'
// limiting language support for smaller APK size // limiting language support for smaller APK size
resConfigs 'en', 'de-rDE', 'zh-rCN' resConfigs 'en', 'de-rDE', 'zh-rCN'
vectorDrawables.useSupportLibrary true vectorDrawables.useSupportLibrary true

View File

@ -208,7 +208,7 @@ public class UserlistEditor extends AppCompatActivity implements OnClickListener
mHolder = new UserlistUpdate(titleStr, descrStr, isPublic, userList.getId()); mHolder = new UserlistUpdate(titleStr, descrStr, isPublic, userList.getId());
} else { } else {
// create new one // create new one
mHolder = new UserlistUpdate(titleStr, descrStr, isPublic); mHolder = new UserlistUpdate(titleStr, descrStr, isPublic, UserlistUpdate.NEW_LIST);
} }
updaterAsync = new ListUpdater(this, mHolder); updaterAsync = new ListUpdater(this, mHolder);
updaterAsync.execute(); updaterAsync.execute();

View File

@ -43,7 +43,7 @@ public class MessageUpdater extends AsyncTask<Void, Void, Boolean> {
protected Boolean doInBackground(Void[] v) { protected Boolean doInBackground(Void[] v) {
try { try {
// first check if user exists // first check if user exists
long id = twitter.showUser(message.getReceiver()).getId(); long id = twitter.showUser(message.getName()).getId();
// upload media if any // upload media if any
long mediaId = -1; long mediaId = -1;
if (message.getMediaStream() != null) { if (message.getMediaStream() != null) {

View File

@ -80,6 +80,7 @@ class TweetV1 implements Tweet {
coordinates = getLocation(json); coordinates = getLocation(json);
mediaLinks = addMedia(json); mediaLinks = addMedia(json);
text = createText(json); text = createText(json);
userMentions = StringTools.getUserMentions(text, author.getScreenname());
String replyName = json.optString("in_reply_to_screen_name"); String replyName = json.optString("in_reply_to_screen_name");
JSONObject locationJson = json.optJSONObject("place"); JSONObject locationJson = json.optJSONObject("place");
@ -92,11 +93,6 @@ class TweetV1 implements Tweet {
if (!replyName.equals("null")) { if (!replyName.equals("null")) {
this.replyName = '@' + replyName; this.replyName = '@' + replyName;
} }
if (author.isCurrentUser()) {
this.userMentions = StringTools.getUserMentions(text);
} else {
this.userMentions = author.getScreenname() + ' ' + StringTools.getUserMentions(text);
}
if (user_retweet != null) if (user_retweet != null)
retweetId = user_retweet.optLong("id"); retweetId = user_retweet.optLong("id");
if (quoted_tweet != null) { if (quoted_tweet != null) {

View File

@ -63,6 +63,7 @@ public class Twitter implements GlobalSettings.SettingsListener {
private static final String OAUTH = "1.0"; private static final String OAUTH = "1.0";
private static final String API = "https://api.twitter.com/"; private static final String API = "https://api.twitter.com/";
private static final String UPLOAD = "https://upload.twitter.com/"; private static final String UPLOAD = "https://upload.twitter.com/";
private static final String DOWNLOAD = "https://ton.twitter.com/";
private static final String AUTHENTICATE = API + "oauth/authenticate"; private static final String AUTHENTICATE = API + "oauth/authenticate";
public static final String REQUEST_URL = AUTHENTICATE + "?oauth_token="; public static final String REQUEST_URL = AUTHENTICATE + "?oauth_token=";
private static final String REQUEST_TOKEN = API + "oauth/request_token"; private static final String REQUEST_TOKEN = API + "oauth/request_token";
@ -1187,7 +1188,7 @@ public class Twitter implements GlobalSettings.SettingsListener {
public MediaStream downloadImage(String link) throws TwitterException { public MediaStream downloadImage(String link) throws TwitterException {
try { try {
// this type of link requires authentication // this type of link requires authentication
if (link.startsWith("https://ton.twitter.com/")) { if (link.startsWith(DOWNLOAD)) {
Response response = get(link, new ArrayList<>(0)); Response response = get(link, new ArrayList<>(0));
if (response.code() == 200 && response.body() != null) { if (response.code() == 200 && response.body() != null) {
MediaType type = response.body().contentType(); MediaType type = response.body().contentType();

View File

@ -43,7 +43,7 @@ public class DirectmessageUpdate {
* *
* @return screen name * @return screen name
*/ */
public String getReceiver() { public String getName() {
return name; return name;
} }
@ -79,15 +79,19 @@ public class DirectmessageUpdate {
* *
* @param context context used to create inputstream and mime type * @param context context used to create inputstream and mime type
* @param uri uri of a local media file * @param uri uri of a local media file
* @return true if file is valid
*/ */
public boolean addMedia(Context context, @NonNull Uri uri) { public boolean addMedia(Context context, @NonNull Uri uri) {
// check if file is valid
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
DocumentFile file = DocumentFile.fromSingleUri(context, uri); DocumentFile file = DocumentFile.fromSingleUri(context, uri);
if (file != null && file.exists() && file.canRead() && file.length() > 0) { if (file != null && file.exists() && file.canRead() && file.length() > 0) {
this.uri = uri; this.uri = uri;
return true; return true;
} }
} else { }
// skip validation for old android versions
else {
this.uri = uri; this.uri = uri;
return true; return true;
} }

View File

@ -47,6 +47,7 @@ public class ProfileUpdate {
* *
* @param context context used to resolve Uri * @param context context used to resolve Uri
* @param imageUrl Uri of the local image file * @param imageUrl Uri of the local image file
* @return true if file is valid, false otherwise
*/ */
public boolean setImage(Context context, @NonNull Uri imageUrl) { public boolean setImage(Context context, @NonNull Uri imageUrl) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
@ -67,6 +68,7 @@ public class ProfileUpdate {
* *
* @param context context used to resolve Uri * @param context context used to resolve Uri
* @param bannerUrl Uri of the local image file * @param bannerUrl Uri of the local image file
* @return true if file is valid, false otherwise
*/ */
public boolean setBanner(Context context, @NonNull Uri bannerUrl) { public boolean setBanner(Context context, @NonNull Uri bannerUrl) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {

View File

@ -7,12 +7,15 @@ package org.nuclearfog.twidda.backend.api.holder;
*/ */
public class UserlistUpdate { public class UserlistUpdate {
/**
* this ID indicates that the list isn't created yet
*/
public static final long NEW_LIST = -1; public static final long NEW_LIST = -1;
private long listId; private long listId;
private final String title; private String title;
private final String description; private String description;
private final boolean isPublic; private boolean isPublic;
/** /**
@ -22,20 +25,10 @@ public class UserlistUpdate {
* @param listId ID of the list to update or {@link UserlistUpdate#NEW_LIST} to create a new list * @param listId ID of the list to update or {@link UserlistUpdate#NEW_LIST} to create a new list
*/ */
public UserlistUpdate(String title, String description, boolean isPublic, long listId) { public UserlistUpdate(String title, String description, boolean isPublic, long listId) {
this(title, description, isPublic);
this.listId = listId;
}
/**
* @param title Title of the list
* @param description short description of the list
* @param isPublic true if list should be public
*/
public UserlistUpdate(String title, String description, boolean isPublic) {
this.title = title; this.title = title;
this.description = description; this.description = description;
this.isPublic = isPublic; this.isPublic = isPublic;
this.listId = NEW_LIST; this.listId = listId;
} }
/** /**

View File

@ -14,6 +14,8 @@ import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.Locale; import java.util.Locale;
import java.util.Random; import java.util.Random;
import java.util.Set;
import java.util.TreeSet;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -138,16 +140,26 @@ public final class StringTools {
/** /**
* append user mentions in a text to a string * append user mentions in a text to a string
* *
* @param text text with user mentions (e.g. tweet) * @param text text with user mentions (e.g. tweet)
* @param author additional text author name
* @return mentioned usernames in one string * @return mentioned usernames in one string
*/ */
public static String getUserMentions(String text) { public static String getUserMentions(String text, String author) {
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
Matcher m = MENTION.matcher(text); Set<String> sorted = new TreeSet<>(String::compareToIgnoreCase);
while (m.find()) { Matcher matcher = MENTION.matcher(text);
int start = m.start();
int end = m.end(); while (matcher.find()) {
buf.append(text.substring(start, end)).append(' '); int start = matcher.start();
int end = matcher.end();
sorted.add(text.substring(start, end));
}
if (!author.isEmpty()) {
buf.append(author).append(' ');
sorted.remove(author);
}
for (String item : sorted) {
buf.append(item).append(' ');
} }
return buf.toString(); return buf.toString();
} }

View File

@ -75,7 +75,7 @@ class TweetImpl implements Tweet {
retweeted = (tweetRegister & RTW_MASK) != 0; retweeted = (tweetRegister & RTW_MASK) != 0;
sensitive = (tweetRegister & MEDIA_SENS_MASK) != 0; sensitive = (tweetRegister & MEDIA_SENS_MASK) != 0;
mediaLinks = SEPARATOR.split(linkStr); mediaLinks = SEPARATOR.split(linkStr);
String userMentions = StringTools.getUserMentions(text); String userMentions = StringTools.getUserMentions(text, "");
// get media type // get media type
if ((tweetRegister & MEDIA_ANGIF_MASK) == MEDIA_ANGIF_MASK) { if ((tweetRegister & MEDIA_ANGIF_MASK) == MEDIA_ANGIF_MASK) {
mediaType = MEDIA_GIF; mediaType = MEDIA_GIF;