From 332d5e2b16a8fd9f5617892f95be63db243804ee Mon Sep 17 00:00:00 2001 From: nuclearfog Date: Mon, 5 Sep 2022 09:42:21 +0200 Subject: [PATCH] bug fix, code cleanup --- app/src/main/AndroidManifest.xml | 1 + app/src/main/assets/licenses.html | 1 - .../twidda/backend/api/Twitter.java | 6 ++-- .../impl/{MetricsImpl.java => MetricsV2.java} | 7 ++-- .../twidda/backend/utils/StringTools.java | 1 + .../twidda/ui/activities/MainActivity.java | 2 +- .../twidda/ui/activities/MetricsActivity.java | 2 +- app/src/main/res/drawable/quote.xml | 14 ++++---- app/src/main/res/drawable/views.xml | 14 ++++---- app/src/main/res/layout/page_metrics.xml | 33 +++++++++---------- .../res/mipmap-anydpi-v26/ic_launcher.xml | 4 +-- .../mipmap-anydpi-v26/ic_launcher_round.xml | 4 +-- .../res/values/ic_launcher_background.xml | 2 +- 13 files changed, 47 insertions(+), 44 deletions(-) rename app/src/main/java/org/nuclearfog/twidda/backend/api/impl/{MetricsImpl.java => MetricsV2.java} (92%) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0366307765..31d1b4c3d0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -38,6 +38,7 @@ + diff --git a/app/src/main/assets/licenses.html b/app/src/main/assets/licenses.html index 18c81543fe..6f67f2adc0 100644 --- a/app/src/main/assets/licenses.html +++ b/app/src/main/assets/licenses.html @@ -4,7 +4,6 @@ diff --git a/app/src/main/java/org/nuclearfog/twidda/backend/api/Twitter.java b/app/src/main/java/org/nuclearfog/twidda/backend/api/Twitter.java index b4af23d008..db0c0b5782 100644 --- a/app/src/main/java/org/nuclearfog/twidda/backend/api/Twitter.java +++ b/app/src/main/java/org/nuclearfog/twidda/backend/api/Twitter.java @@ -11,7 +11,7 @@ import org.json.JSONObject; import org.nuclearfog.twidda.backend.api.impl.DirectmessageV1; import org.nuclearfog.twidda.backend.api.impl.LocationV1; -import org.nuclearfog.twidda.backend.api.impl.MetricsImpl; +import org.nuclearfog.twidda.backend.api.impl.MetricsV2; import org.nuclearfog.twidda.backend.api.impl.RelationV1; import org.nuclearfog.twidda.backend.api.impl.TrendV1; import org.nuclearfog.twidda.backend.api.impl.TweetV1; @@ -1220,14 +1220,14 @@ public Directmessages getDirectmessages(String cursor) throws TwitterException { */ public Metrics getTweetMetrics(long tweetId) throws TwitterException { List params = new ArrayList<>(); - params.add(MetricsImpl.PARAMS); + params.add(MetricsV2.PARAMS); try { Response response = get(TWEET_UNI + tweetId, params); ResponseBody body = response.body(); if (body != null && response.code() == 200) { JSONObject json = new JSONObject(body.string()); if (json.opt("data") != null) { - return new MetricsImpl(json); + return new MetricsV2(json); } } throw new TwitterException(response); diff --git a/app/src/main/java/org/nuclearfog/twidda/backend/api/impl/MetricsImpl.java b/app/src/main/java/org/nuclearfog/twidda/backend/api/impl/MetricsV2.java similarity index 92% rename from app/src/main/java/org/nuclearfog/twidda/backend/api/impl/MetricsImpl.java rename to app/src/main/java/org/nuclearfog/twidda/backend/api/impl/MetricsV2.java index 462ce6b0f6..9deecad4e0 100644 --- a/app/src/main/java/org/nuclearfog/twidda/backend/api/impl/MetricsImpl.java +++ b/app/src/main/java/org/nuclearfog/twidda/backend/api/impl/MetricsV2.java @@ -9,8 +9,11 @@ * * @author nuclearfog */ -public class MetricsImpl implements Metrics { +public class MetricsV2 implements Metrics { + /** + * parameters to get extra information + */ public static final String PARAMS = "tweet.fields=organic_metrics%2Cpublic_metrics"; private int impressions; @@ -25,7 +28,7 @@ public class MetricsImpl implements Metrics { /** * @param json tweet json object containing metrics information */ - public MetricsImpl(JSONObject json) throws JSONException { + public MetricsV2(JSONObject json) throws JSONException { JSONObject metricsData = json.getJSONObject("data"); JSONObject metricsOrganic = metricsData.getJSONObject("organic_metrics"); JSONObject metricsPublic = metricsData.getJSONObject("public_metrics"); diff --git a/app/src/main/java/org/nuclearfog/twidda/backend/utils/StringTools.java b/app/src/main/java/org/nuclearfog/twidda/backend/utils/StringTools.java index 77c960a55b..98d004b3ec 100644 --- a/app/src/main/java/org/nuclearfog/twidda/backend/utils/StringTools.java +++ b/app/src/main/java/org/nuclearfog/twidda/backend/utils/StringTools.java @@ -240,6 +240,7 @@ public static int calculateIndexOffset(String text, int limit) { // determine if a pair of chars represent an emoji if (Character.isSurrogatePair(text.charAt(c), text.charAt(c + 1))) { offset++; + limit++; } } return offset; diff --git a/app/src/main/java/org/nuclearfog/twidda/ui/activities/MainActivity.java b/app/src/main/java/org/nuclearfog/twidda/ui/activities/MainActivity.java index 52c637a8fb..7db109b01f 100644 --- a/app/src/main/java/org/nuclearfog/twidda/ui/activities/MainActivity.java +++ b/app/src/main/java/org/nuclearfog/twidda/ui/activities/MainActivity.java @@ -149,7 +149,7 @@ else if (returnCode == LoginActivity.RETURN_LOGIN_SUCCESSFUL) { case REQUEST_ACCOUNT_CHANGE: // check if account or theme changed if (returnCode == AccountActivity.RETURN_ACCOUNT_CHANGED - || returnCode == AccountActivity.RETURN_SETTINGS_CHANGED) { + || returnCode == AccountActivity.RETURN_SETTINGS_CHANGED) { AppStyles.setTheme(root, settings.getBackgroundColor()); AppStyles.setTabIcons(tabLayout, settings, R.array.home_tab_icons); adapter.notifySettingsChanged(); diff --git a/app/src/main/java/org/nuclearfog/twidda/ui/activities/MetricsActivity.java b/app/src/main/java/org/nuclearfog/twidda/ui/activities/MetricsActivity.java index afd345bdb5..7599b31ba6 100644 --- a/app/src/main/java/org/nuclearfog/twidda/ui/activities/MetricsActivity.java +++ b/app/src/main/java/org/nuclearfog/twidda/ui/activities/MetricsActivity.java @@ -140,7 +140,7 @@ protected void onCreate(Bundle savedInst) { } username.setText(author.getUsername()); screenname.setText(author.getScreenname()); - tweetText.setText(Tagger.makeTextWithLinks(tweet.getText(),settings.getHighlightColor(), this)); + tweetText.setText(Tagger.makeTextWithLinks(tweet.getText(), settings.getHighlightColor(), this)); created.setText(StringTools.formatCreationTime(getResources(), tweet.getTimestamp())); } profile.setOnClickListener(this); diff --git a/app/src/main/res/drawable/quote.xml b/app/src/main/res/drawable/quote.xml index 15f19cbf44..94e62abb73 100644 --- a/app/src/main/res/drawable/quote.xml +++ b/app/src/main/res/drawable/quote.xml @@ -1,9 +1,9 @@ - + android:width="20dp" + android:height="20dp" + android:viewportWidth="20" + android:viewportHeight="20"> + diff --git a/app/src/main/res/drawable/views.xml b/app/src/main/res/drawable/views.xml index edc0873b18..76ecf4f774 100644 --- a/app/src/main/res/drawable/views.xml +++ b/app/src/main/res/drawable/views.xml @@ -1,9 +1,9 @@ - + android:width="20dp" + android:height="20dp" + android:viewportWidth="20" + android:viewportHeight="20"> + diff --git a/app/src/main/res/layout/page_metrics.xml b/app/src/main/res/layout/page_metrics.xml index 934317916f..124b28ae35 100644 --- a/app/src/main/res/layout/page_metrics.xml +++ b/app/src/main/res/layout/page_metrics.xml @@ -1,6 +1,5 @@ - + app:layout_constraintTop_toBottomOf="@id/metrics_toolbar" /> + app:layout_constraintEnd_toEndOf="parent" /> + app:layout_constraintEnd_toEndOf="parent" /> + app:layout_constraintEnd_toEndOf="parent" /> + app:constraint_referenced_ids="metrics_screenname,metrics_profile" /> + app:layout_constraintEnd_toEndOf="parent" /> + android:gravity="end" /> + android:gravity="end" /> + android:gravity="end" /> + android:gravity="end" /> + android:gravity="end" /> + android:gravity="end" /> + android:gravity="end" /> + android:gravity="end" /> @@ -185,6 +184,6 @@ app:layout_constraintStart_toStartOf="@id/metrics_scroll" app:layout_constraintTop_toTopOf="@id/metrics_scroll" app:layout_constraintBottom_toBottomOf="@id/metrics_scroll" - app:layout_constraintEnd_toEndOf="@id/metrics_scroll"/> + app:layout_constraintEnd_toEndOf="@id/metrics_scroll" /> \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml index bbd3e02123..65bd9d3e40 100644 --- a/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -1,5 +1,5 @@ - - + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml index bbd3e02123..65bd9d3e40 100644 --- a/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -1,5 +1,5 @@ - - + + \ No newline at end of file diff --git a/app/src/main/res/values/ic_launcher_background.xml b/app/src/main/res/values/ic_launcher_background.xml index 2aa65686ef..15290b9b6c 100644 --- a/app/src/main/res/values/ic_launcher_background.xml +++ b/app/src/main/res/values/ic_launcher_background.xml @@ -1,4 +1,4 @@ - #FFA500 + #FFA500 \ No newline at end of file