This commit is contained in:
nuclearfog 2021-01-16 20:07:53 +01:00
parent 13b4e51830
commit 4bca316f47
No known key found for this signature in database
GPG Key ID: D5490E4A81F97B14
13 changed files with 101 additions and 26 deletions

View File

@ -94,7 +94,7 @@ public class TweetActivity extends AppCompatActivity implements OnClickListener,
*/
public static final Pattern LINK_PATTERN = Pattern.compile("https://twitter.com/\\w+/status/\\d+");
private TextView tweet_api, tweetDate, tweetText, scrName, usrName, tweetLocName, sensitive_media;
private TextView tweet_api, tweetDate, tweetText, scrName, usrName, tweetLocName, retweeter, sensitive_media;
private Button rtwButton, favButton, replyName, tweetLocGPS;
private ImageView profile_img, mediaButton;
private View header, footer;
@ -130,6 +130,7 @@ public class TweetActivity extends AppCompatActivity implements OnClickListener,
tweetLocGPS = findViewById(R.id.tweet_location_coordinate);
mediaButton = findViewById(R.id.tweet_media_attach);
sensitive_media = findViewById(R.id.tweet_sensitive);
retweeter = findViewById(R.id.tweet_retweeter);
Object data = getIntent().getSerializableExtra(KEY_TWEET_DATA);
long tweetId;
@ -159,6 +160,7 @@ public class TweetActivity extends AppCompatActivity implements OnClickListener,
favButton.setCompoundDrawablesWithIntrinsicBounds(R.drawable.favorite, 0, 0, 0);
tweetLocGPS.setCompoundDrawablesWithIntrinsicBounds(R.drawable.userlocation, 0, 0, 0);
sensitive_media.setCompoundDrawablesWithIntrinsicBounds(R.drawable.sensitive, 0, 0, 0);
retweeter.setCompoundDrawablesWithIntrinsicBounds(R.drawable.retweet, 0, 0, 0);
tweetText.setMovementMethod(LinkAndScrollMovement.getInstance());
tweetText.setLinkTextColor(settings.getHighlightColor());
deleteDialog = DialogBuilder.create(this, DELETE_TWEET, this);
@ -433,9 +435,11 @@ public class TweetActivity extends AppCompatActivity implements OnClickListener,
*/
public void setTweet(Tweet tweetUpdate) {
tweet = tweetUpdate;
// todo add information about the user who retweet this tweet
if (tweetUpdate.getEmbeddedTweet() != null)
if (tweetUpdate.getEmbeddedTweet() != null) {
tweetUpdate = tweetUpdate.getEmbeddedTweet();
retweeter.setText(tweet.getUser().getScreenname());
retweeter.setVisibility(VISIBLE);
}
User author = tweetUpdate.getUser();
invalidateOptionsMenu();

View File

@ -32,6 +32,7 @@ import org.nuclearfog.twidda.backend.utils.AppStyles;
import org.nuclearfog.twidda.backend.utils.DialogBuilder;
import org.nuclearfog.twidda.backend.utils.DialogBuilder.OnDialogClick;
import org.nuclearfog.twidda.backend.utils.ErrorHandler;
import org.nuclearfog.twidda.backend.utils.StringTools;
import org.nuclearfog.twidda.database.GlobalSettings;
import java.util.LinkedList;
@ -119,6 +120,11 @@ public class TweetPopup extends AppCompatActivity implements OnClickListener, Lo
*/
private static final int MAX_IMAGES = 4;
/**
* max amount of mentions in a tweet
*/
private static final int MAX_MENTIONS = 8;
@Nullable
private LocationManager mLocation;
private TweetUpdater uploaderAsync;
@ -293,6 +299,10 @@ public class TweetPopup extends AppCompatActivity implements OnClickListener, Lo
if (tweetStr.trim().isEmpty() && mediaPath.isEmpty()) {
Toast.makeText(this, R.string.error_empty_tweet, LENGTH_SHORT).show();
}
// check if mentions exceed the limit
else if (!settings.isCustomApiSet() && StringTools.countMentions(tweetStr) >= MAX_MENTIONS) {
Toast.makeText(this, R.string.error_mention_exceed, LENGTH_SHORT).show();
}
// check if gps locating is not pending
else if (locationProg.getVisibility() == INVISIBLE) {
tweet = new TweetHolder(tweetStr, inReplyId);

View File

@ -171,6 +171,7 @@ public class UserProfile extends AppCompatActivity implements OnClickListener, O
txtCreated.setCompoundDrawablesWithIntrinsicBounds(R.drawable.calendar, 0, 0, 0);
txtLocation.setCompoundDrawablesWithIntrinsicBounds(R.drawable.userlocation, 0, 0, 0);
lnkTxt.setCompoundDrawablesWithIntrinsicBounds(R.drawable.link, 0, 0, 0);
follow_back.setCompoundDrawablesWithIntrinsicBounds(R.drawable.followback, 0, 0, 0);
txtUser.setBackgroundColor(settings.getBackgroundColor() & TRANSPARENCY);
txtScrName.setBackgroundColor(settings.getBackgroundColor() & TRANSPARENCY);
follow_back.setBackgroundColor(settings.getBackgroundColor() & TRANSPARENCY);

View File

@ -35,7 +35,7 @@ import static android.view.View.GONE;
import static android.view.View.INVISIBLE;
import static android.view.View.VISIBLE;
import static androidx.recyclerview.widget.RecyclerView.NO_POSITION;
import static org.nuclearfog.twidda.backend.utils.TimeString.getTimeString;
import static org.nuclearfog.twidda.backend.utils.StringTools.getTimeString;
/**
* Adapter class for user lists

View File

@ -33,7 +33,7 @@ import java.util.List;
import static android.graphics.PorterDuff.Mode.SRC_ATOP;
import static androidx.recyclerview.widget.RecyclerView.NO_POSITION;
import static org.nuclearfog.twidda.backend.utils.TimeString.getTimeString;
import static org.nuclearfog.twidda.backend.utils.StringTools.getTimeString;
/**
* Adapter class for direct messages list

View File

@ -38,7 +38,7 @@ import static android.view.View.INVISIBLE;
import static android.view.View.VISIBLE;
import static androidx.recyclerview.widget.RecyclerView.NO_ID;
import static androidx.recyclerview.widget.RecyclerView.NO_POSITION;
import static org.nuclearfog.twidda.backend.utils.TimeString.getTimeString;
import static org.nuclearfog.twidda.backend.utils.StringTools.getTimeString;
/**
* Adapter class for tweet list

View File

@ -790,7 +790,11 @@ public class TwitterEngine {
List<DirectMessage> dmList = twitter.getDirectMessages(load);
List<Message> result = new LinkedList<>();
for (DirectMessage dm : dmList) {
result.add(getMessage(dm));
try {
result.add(getMessage(dm));
} catch (EngineException err) {
// ignore messages from suspended/deleted users
}
}
return result;
} catch (Exception err) {

View File

@ -6,9 +6,9 @@ import java.util.Date;
/**
* this class creates time strings
*/
public final class TimeString {
public final class StringTools {
private TimeString() {
private StringTools() {
}
/**
@ -45,4 +45,23 @@ public final class TimeString {
}
return "0 s";
}
/**
* count @usernames in a string
*
* @param text text
* @return username count
*/
public static int countMentions(String text) {
int result = 0;
for (int i = 0; i < text.length() - 1; i++) {
if (text.charAt(i) == '@') {
char next = text.charAt(i + 1);
if ((next >= 'a' && next <= 'z') || (next >= 'A' && next <= 'Z') || (next >= '0' && next <= '9')) {
result++;
}
}
}
return result;
}
}

View File

@ -101,7 +101,6 @@ public class GlobalSettings {
private static final int DEFAULT_ICON_COLOR = Color.WHITE;
private static final int DEFAULT_LOCATION_WOEID = 1;
private static final String DEFAULT_LOCATION_NAME = "Worldwide";
private static final boolean DEFAULT_DATA_USAGE = true;
private static final GlobalSettings ourInstance = new GlobalSettings();
@ -724,9 +723,9 @@ public class GlobalSettings {
icon_color = settings.getInt(ICON_COLOR, DEFAULT_ICON_COLOR);
indexFont = settings.getInt(INDEX_FONT, DEFAULT_FONT_INDEX);
listSize = settings.getInt(LIST_SIZE, DEFAULT_LIST_SIZE);
loadImage = settings.getBoolean(IMAGE_LOAD, DEFAULT_DATA_USAGE);
loadAnswer = settings.getBoolean(ANSWER_LOAD, DEFAULT_DATA_USAGE);
hqImages = settings.getBoolean(IMAGE_QUALITY, DEFAULT_DATA_USAGE);
loadImage = settings.getBoolean(IMAGE_LOAD, true);
loadAnswer = settings.getBoolean(ANSWER_LOAD, false);
hqImages = settings.getBoolean(IMAGE_QUALITY, false);
loggedIn = settings.getBoolean(LOGGED_IN, false);
isCustomAPIkeySet = settings.getBoolean(CUSTOM_CONSUMER_KEY_SET, false);
api_key1 = settings.getString(CUSTOM_CONSUMER_KEY_1, "");

View File

@ -35,4 +35,22 @@
android:padding="@dimen/infopopup_text_padding"
android:text="@string/settings_info_link" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/infopopup_text_padding"
android:text="@string/app_info_twitter_rules" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/infopopup_text_padding"
android:text="@string/app_info_twitter_link_1" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/infopopup_text_padding"
android:text="@string/app_info_twitter_link_2" />
</LinearLayout>

View File

@ -120,17 +120,32 @@
android:visibility="gone"
style="@style/RoundButton" />
<TextView
android:id="@+id/tweet_sensitive"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawablePadding="@dimen/tweet_padding_drawable"
android:paddingLeft="@dimen/tweet_button_padding"
android:paddingRight="@dimen/tweet_button_padding"
android:singleLine="true"
android:text="@string/tweet_sensitive_media"
android:textSize="@dimen/tweet_textsize_api"
android:visibility="gone" />
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/tweet_retweeter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawablePadding="@dimen/tweet_padding_drawable"
android:visibility="gone" />
<TextView
android:id="@+id/tweet_sensitive"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawablePadding="@dimen/tweet_padding_drawable"
android:paddingLeft="@dimen/tweet_button_padding"
android:paddingRight="@dimen/tweet_button_padding"
android:singleLine="true"
android:text="@string/tweet_sensitive_media"
android:textSize="@dimen/tweet_textsize_api"
android:visibility="gone" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"

View File

@ -190,4 +190,5 @@
<string name="settings_setup_custom_keys">Eigene API Schlüssel verwenden</string>
<string name="error_api_access_denied">Fehler, API Zugang wurde abgelehnt!</string>
<string name="confirm_back">Zurück</string>
<string name="error_mention_exceed">Zu viele Nutzer Erwähnungen!</string>
</resources>

View File

@ -12,6 +12,8 @@
<string name="settings_background">Background</string>
<string name="settings_font">Font</string>
<string name="settings_button_popup">Popup</string>
<string name="settings_color_card">Card color</string>
<string name="settings_icon_color">Icon color</string>
<string name="highlight">Highlight</string>
<string name="settings_list_size">List size</string>
<string name="confirm_retry_button">retry</string>
@ -99,6 +101,9 @@
<string name="info_list_followed">Userlist followed</string>
<string name="info_list_unfollowed">Userlist unfollowed</string>
<string name="descr_add_profile_image">change profile image</string>
<string name="app_info_twitter_link_1" translatable="false">https://support.twitter.com/articles/18311-the-twitter-rules</string>
<string name="app_info_twitter_link_2" translatable="false">https://help.twitter.com/rules-and-policies/twitter-api</string>
<string name="app_info_twitter_rules" translatable="false">The Twitter rules:</string>
<!-- toast messages to inform user -->
<string name="info_user_removed">User removed from list</string>
@ -171,6 +176,8 @@
<string name="error_cant_reply_to_tweet">You can\'t reply to this Tweet!</string>
<string name="error_corrupt_api_key">Error, corrupt API key!</string>
<string name="error_acc_update">Account update failed! Please check your input!</string>
<string name="error_api_access_denied">Error, API access denied!</string>
<string name="error_mention_exceed">Too much mentions!</string>
<string name="error_not_defined">Not defined Error!</string>
<!-- menu icon strings -->
@ -203,7 +210,4 @@
<string name="dialog_button_no">No</string>
<string name="dialog_button_cancel">Cancel</string>
<string name="dialog_button_ok">OK</string>
<string name="settings_color_card">Card color</string>
<string name="settings_icon_color">Icon color</string>
<string name="error_api_access_denied">Error, API access denied!</string>
</resources>