code cleanup, added comments and tostring

This commit is contained in:
nuclearfog 2022-12-21 17:29:30 +01:00
parent 54d10eb768
commit 1274e4ea85
No known key found for this signature in database
GPG Key ID: 03488A185C476379
13 changed files with 81 additions and 18 deletions

View File

@ -29,7 +29,6 @@ public class MessageV1 implements Message {
/**
* @param json JSON object containing directmessage information
* @throws JSONException if some values are missing
*/
public MessageV1(JSONObject json) throws JSONException {
JSONObject message = json.getJSONObject("message_create");

View File

@ -24,7 +24,6 @@ public class RelationV1 implements Relation {
/**
* @param json JSON object containing relationship information
* @throws JSONException if values are missing
*/
public RelationV1(JSONObject json) throws JSONException {
JSONObject relationship = json.getJSONObject("relationship");

View File

@ -21,13 +21,14 @@ public class TrendV1 implements Trend {
/**
* @param json JSON object containing trend information
* @param index array index of this item
* @param locationId Id of the trend location
*/
public TrendV1(JSONObject json, int index, int locationId) {
name = json.optString("name", "");
popularity = json.optInt("tweet_volume", -1);
this.locationId = locationId;
rank = index + 1;
this.rank = index + 1;
}

View File

@ -1,5 +1,7 @@
package org.nuclearfog.twidda.backend.api.twitter.impl.v2;
import androidx.annotation.NonNull;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@ -96,4 +98,11 @@ public class LocationV2 implements Location {
public String getFullName() {
return fullName;
}
@NonNull
@Override
public String toString() {
return "id=\"" + id + " full_name=" + fullName + " country=\"" + country + "\"";
}
}

View File

@ -49,7 +49,6 @@ public class TweetV2 implements Status {
*/
public static final String FIELDS_TWEET_PRIVATE = FIELDS_TWEET + "%2Cnon_public_metrics";
private long id;
private long timestamp;
private long replyUserId;
@ -77,14 +76,20 @@ public class TweetV2 implements Status {
private Card[] cards = {};
/**
* @param json tweet json format
* @param userMap map containing user instances
*/
public TweetV2(JSONObject json, UserV2Map userMap) throws JSONException {
this(json, userMap, null, null, null, null);
}
/**
* @param json Tweet v2 json
* @param tweetCompat Tweet containing base informations
* @param json tweet json format
* @param userMap map containing user instances
* @param mediaMap map containing media instances
* @param pollMap map containing poll instances
* @param locationMap map containing location instances
* @param tweetCompat tweet v1.1 object
*/
public TweetV2(JSONObject json, @NonNull UserV2Map userMap, @Nullable MediaV2Map mediaMap, @Nullable PollV2Map pollMap, @Nullable LocationV2Map locationMap, @Nullable Status tweetCompat) throws JSONException {
JSONObject publicMetrics = json.getJSONObject("public_metrics");

View File

@ -2,6 +2,8 @@ package org.nuclearfog.twidda.backend.api.twitter.impl.v2;
import android.util.Patterns;
import androidx.annotation.NonNull;
import org.json.JSONArray;
import org.json.JSONObject;
import org.nuclearfog.twidda.model.Card;
@ -20,7 +22,9 @@ public class TwitterCard implements Card {
private String description;
private String imageUrl = "";
/**
* @param json twitter card json
*/
public TwitterCard(JSONObject json) {
JSONArray images = json.optJSONArray("images");
url = json.optString("expanded_url", "");
@ -61,4 +65,11 @@ public class TwitterCard implements Card {
public String getImageUrl() {
return imageUrl;
}
@NonNull
@Override
public String toString() {
return "url=\"" + url + "\" description=\"" + description + "\"";
}
}

View File

@ -1,5 +1,7 @@
package org.nuclearfog.twidda.backend.api.twitter.impl.v2.maps;
import androidx.annotation.NonNull;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@ -31,4 +33,11 @@ public class LocationV2Map extends TreeMap<Long, Location> {
}
}
}
@NonNull
@Override
public String toString() {
return "size=" + size();
}
}

View File

@ -1,5 +1,7 @@
package org.nuclearfog.twidda.backend.api.twitter.impl.v2.maps;
import androidx.annotation.NonNull;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@ -31,4 +33,11 @@ public class MediaV2Map extends TreeMap<String, Media> {
}
}
}
@NonNull
@Override
public String toString() {
return "size=" + size();
}
}

View File

@ -1,5 +1,7 @@
package org.nuclearfog.twidda.backend.api.twitter.impl.v2.maps;
import androidx.annotation.NonNull;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@ -31,4 +33,11 @@ public class PollV2Map extends TreeMap<Long, Poll> {
}
}
}
@NonNull
@Override
public String toString() {
return "size=" + size();
}
}

View File

@ -1,5 +1,7 @@
package org.nuclearfog.twidda.backend.api.twitter.impl.v2.maps;
import androidx.annotation.NonNull;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@ -18,16 +20,23 @@ public class UserV2Map extends TreeMap<Long, User> {
private static final long serialVersionUID = 3107064180725473583L;
/**
* @param json json object from a tweet
* @param twitterId current user's ID
* @param json json object from a tweet
* @param twitterId current user's ID
*/
public UserV2Map(JSONObject json, long twitterId) throws JSONException {
JSONObject includesJson = json.getJSONObject("includes");
JSONArray userArray = includesJson.getJSONArray("users");
for (int i = 0 ; i < userArray.length() ; i++) {
for (int i = 0; i < userArray.length(); i++) {
JSONObject item = userArray.getJSONObject(i);
User user = new UserV2(item, twitterId);
put(user.getId(), user);
}
}
@NonNull
@Override
public String toString() {
return "size=" + size();
}
}

View File

@ -30,7 +30,6 @@ public interface Media extends Serializable {
int GIF = 802;
/**
*
* @return media key
*/
String getKey();

View File

@ -10,13 +10,15 @@
android:id="@+id/item_preview_image"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:scaleType="centerCrop" />
android:scaleType="centerCrop"
android:contentDescription="@string/status_media_preview" />
<ImageView
android:id="@+id/item_preview_play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/play"
android:layout_gravity="center" />
android:layout_gravity="center"
android:contentDescription="@string/status_media_preview_button" />
</androidx.cardview.widget.CardView>

View File

@ -57,6 +57,11 @@
<string name="info_tweet_location_copied">Location coordinates copied</string>
<string name="info_tweet_medialink_copied">Media link copied</string>
<string name="info_account_selected">%1$s selected</string>
<string name="info_user_favorited">%1$s favorited your status</string>
<string name="info_user_follow">%1$s followed you</string>
<string name="info_user_follow_request">%1$s request to follow you</string>
<string name="info_user_mention">%1$s mentioned you</string>
<string name="info_user_repost">%1$s reposted your status</string>
<string name="info_error">Error</string>
<!-- toast messages for error information -->
@ -276,12 +281,9 @@
<string name="toolbar_tweet_liker">User liking this status</string>
<string name="time_now">now</string>
<string name="confirm_open_link">open in browser</string>
<string name="info_user_favorited">%1$s favorited your status</string>
<string name="info_user_follow">%1$s followed you</string>
<string name="info_user_follow_request">%1$s request to follow you</string>
<string name="info_user_mention">%1$s mentioned you</string>
<string name="info_user_repost">%1$s reposted your status</string>
<string name="status_replyname_empty">Reply</string>
<string name="status_metrics_title">Status metrics</string>
<string name="status_media_preview">Media preview</string>
<string name="status_media_preview_button">Video preview button</string>
</resources>