Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update minSdk to 24, cleanup code #4014

Merged
merged 10 commits into from
Sep 12, 2023
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ android {
defaultConfig {
applicationId APP_ID
namespace "com.keylesspalace.tusky"
minSdk 23
minSdk 24
targetSdk 33
versionCode 113
versionName "23.0"
Expand Down
72 changes: 47 additions & 25 deletions app/lint-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

<issue
id="InlinedApi"
message="Field requires API level 33 (current min is 23): `android.Manifest.permission#POST_NOTIFICATIONS`"
message="Field requires API level 33 (current min is 24): `android.Manifest.permission#POST_NOTIFICATIONS`"
errorLine1=" arrayOf(Manifest.permission.POST_NOTIFICATIONS),"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
Expand Down Expand Up @@ -73,17 +73,6 @@
file="$GRADLE_USER_HOME/caches/modules-2/files-2.1/org.pageseeder.diffx/pso-diffx/1.1.1/b655ebc87588a857a4f3d88cf98bcefa87a6105b/pso-diffx-1.1.1.jar"/>
</issue>

<issue
id="NewApi"
message="Call requires API level 24 (current min is 23): `java.lang.Iterable#forEach`"
errorLine1=" media.value.forEach { item ->"
errorLine2=" ~~~~~~~">
<location
file="src/main/java/com/keylesspalace/tusky/components/compose/ComposeViewModel.kt"
line="278"
column="21"/>
</issue>

<issue
id="UseAppTint"
message="Must use `app:tint` instead of `android:tint`"
Expand Down Expand Up @@ -471,13 +460,46 @@

<issue
id="ObsoleteSdkInt"
message="Unnecessary; SDK_INT is always >= 23"
errorLine1=" return PendingIntent.FLAG_UPDATE_CURRENT | (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? PendingIntent.FLAG_IMMUTABLE : 0);"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
message="Unnecessary; SDK_INT is always >= 24"
errorLine1=" if (Build.VERSION.SDK_INT > 23) {"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/com/keylesspalace/tusky/components/notifications/NotificationHelper.java"
line="862"
column="57"/>
file="src/main/java/com/keylesspalace/tusky/fragment/ViewVideoFragment.kt"
line="252"
column="13"/>
</issue>

<issue
id="ObsoleteSdkInt"
message="Unnecessary; SDK_INT is never &lt; 24"
errorLine1=" if (Build.VERSION.SDK_INT &lt;= 23 || player == null) {"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/com/keylesspalace/tusky/fragment/ViewVideoFragment.kt"
line="261"
column="13"/>
</issue>

<issue
id="ObsoleteSdkInt"
message="Unnecessary; SDK_INT is never &lt; 24"
errorLine1=" if (Build.VERSION.SDK_INT &lt;= 23) {"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/com/keylesspalace/tusky/fragment/ViewVideoFragment.kt"
line="284"
column="13"/>
</issue>

<issue
id="ObsoleteSdkInt"
message="Unnecessary; SDK_INT is always >= 24"
errorLine1=" if (Build.VERSION.SDK_INT > 23) {"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/com/keylesspalace/tusky/fragment/ViewVideoFragment.kt"
line="296"
column="13"/>
</issue>

<issue
Expand Down Expand Up @@ -1103,7 +1125,7 @@
errorLine2=" ~~~~~~~">
<location
file="src/main/java/com/keylesspalace/tusky/components/notifications/NotificationHelper.java"
line="274"
line="273"
column="51"/>
</issue>

Expand All @@ -1114,7 +1136,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/com/keylesspalace/tusky/components/notifications/NotificationHelper.java"
line="274"
line="273"
column="68"/>
</issue>

Expand All @@ -1125,7 +1147,7 @@
errorLine2=" ~~~~~~~~~~~~~">
<location
file="src/main/java/com/keylesspalace/tusky/components/notifications/NotificationHelper.java"
line="274"
line="273"
column="109"/>
</issue>

Expand All @@ -1136,7 +1158,7 @@
errorLine2=" ~~~~~~~">
<location
file="src/main/java/com/keylesspalace/tusky/components/notifications/NotificationHelper.java"
line="612"
line="611"
column="48"/>
</issue>

Expand All @@ -1147,7 +1169,7 @@
errorLine2=" ~~~~~~~">
<location
file="src/main/java/com/keylesspalace/tusky/components/notifications/NotificationHelper.java"
line="640"
line="639"
column="49"/>
</issue>

Expand All @@ -1158,7 +1180,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/com/keylesspalace/tusky/components/notifications/NotificationHelper.java"
line="656"
line="655"
column="46"/>
</issue>

Expand All @@ -1169,7 +1191,7 @@
errorLine2=" ~~~~~~~~~~~~~">
<location
file="src/main/java/com/keylesspalace/tusky/components/notifications/NotificationHelper.java"
line="656"
line="655"
column="87"/>
</issue>

Expand Down
3 changes: 1 addition & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,7 @@
android:icon="@drawable/ic_quicksettings"
android:label="@string/tusky_compose_post_quicksetting_label"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE"
android:exported="true"
tools:targetApi="24">
android:exported="true">
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE" />
</intent-filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -679,17 +679,12 @@ private void setupContentAndSpoiler(final LinkListener listener) {
);
LinkHelper.setClickableText(statusContent, emojifiedText, statusViewData.getActionable().getMentions(), statusViewData.getActionable().getTags(), listener);

CharSequence emojifiedContentWarning;
if (statusViewData.getSpoilerText() != null) {
emojifiedContentWarning = CustomEmojiHelper.emojify(
statusViewData.getSpoilerText(),
CharSequence emojifiedContentWarning = CustomEmojiHelper.emojify(
statusViewData.getStatus().getSpoilerText(),
statusViewData.getActionable().getEmojis(),
contentWarningDescriptionTextView,
statusDisplayOptions.animateEmojis()
);
} else {
emojifiedContentWarning = "";
}
contentWarningDescriptionTextView.setText(emojifiedContentWarning);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ protected void setSpoilerAndContent(@NonNull StatusViewData.Concrete status,
final StatusActionListener listener) {

Status actionable = status.getActionable();
String spoilerText = status.getSpoilerText();
String spoilerText = actionable.getSpoilerText();
List<Emoji> emojis = actionable.getEmojis();

boolean sensitive = !TextUtils.isEmpty(spoilerText);
Expand Down Expand Up @@ -764,7 +764,7 @@ public void setupWithStatus(@NonNull StatusViewData.Concrete status,
if (payloads == null) {
Status actionable = status.getActionable();
setDisplayName(actionable.getAccount().getName(), actionable.getAccount().getEmojis(), statusDisplayOptions);
setUsername(status.getUsername());
setUsername(actionable.getAccount().getUsername());
setMetaData(status, statusDisplayOptions, listener);
setIsReply(actionable.getInReplyToId() != null);
setReplyCount(actionable.getRepliesCount(), statusDisplayOptions.showStatsInline());
Expand Down Expand Up @@ -860,11 +860,11 @@ private void setDescriptionForStatus(@NonNull StatusViewData.Concrete status,
String description = context.getString(R.string.description_status,
actionable.getAccount().getDisplayName(),
getContentWarningDescription(context, status),
(TextUtils.isEmpty(status.getSpoilerText()) || !actionable.getSensitive() || status.isExpanded() ? status.getContent() : ""),
(TextUtils.isEmpty(actionable.getSpoilerText()) || !actionable.getSensitive() || status.isExpanded() ? status.getContent() : ""),
getCreatedAtDescription(actionable.getCreatedAt(), statusDisplayOptions),
actionable.getEditedAt() != null ? context.getString(R.string.description_post_edited) : "",
getReblogDescription(context, status),
status.getUsername(),
actionable.getAccount().getUsername(),
actionable.getReblogged() ? context.getString(R.string.description_post_reblogged) : "",
actionable.getFavourited() ? context.getString(R.string.description_post_favourited) : "",
actionable.getBookmarked() ? context.getString(R.string.description_post_bookmarked) : "",
Expand Down Expand Up @@ -911,8 +911,8 @@ private static CharSequence getMediaDescription(Context context,

private static CharSequence getContentWarningDescription(Context context,
@NonNull StatusViewData.Concrete status) {
if (!TextUtils.isEmpty(status.getSpoilerText())) {
return context.getString(R.string.description_post_cw, status.getSpoilerText());
if (!TextUtils.isEmpty(status.getActionable().getSpoilerText())) {
return context.getString(R.string.description_post_cw, status.getActionable().getSpoilerText());
} else {
return "";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void setupWithConversation(
if (payloads == null) {
TimelineAccount account = status.getAccount();

setupCollapsedState(statusViewData.isCollapsible(), statusViewData.isCollapsed(), statusViewData.isExpanded(), statusViewData.getSpoilerText(), listener);
setupCollapsedState(statusViewData.isCollapsible(), statusViewData.isCollapsed(), statusViewData.isExpanded(), status.getSpoilerText(), listener);

setDisplayName(account.getDisplayName(), account.getEmojis(), statusDisplayOptions);
setUsername(account.getUsername());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,7 @@ public static android.app.Notification make(final Context context, NotificationM
builder.setLargeIcon(accountAvatar);

// Reply to mention action; RemoteInput is available from KitKat Watch, but buttons are available from Nougat
if (body.getType() == Notification.Type.MENTION
&& android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
if (body.getType() == Notification.Type.MENTION) {
RemoteInput replyRemoteInput = new RemoteInput.Builder(KEY_REPLY)
.setLabel(context.getString(R.string.label_quick_reply))
.build();
Expand Down Expand Up @@ -859,7 +858,7 @@ public static int pendingIntentFlags(boolean mutable) {
if (mutable) {
return PendingIntent.FLAG_UPDATE_CURRENT | (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ? PendingIntent.FLAG_MUTABLE : 0);
} else {
return PendingIntent.FLAG_UPDATE_CURRENT | (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? PendingIntent.FLAG_IMMUTABLE : 0);
return PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ class StatusViewHolder(
shouldTrimStatus(viewdata.content),
viewState.isCollapsed(viewdata.id, true),
viewState.isContentShow(viewdata.id, viewdata.status.sensitive),
viewdata.spoilerText
viewdata.status.spoilerText
)

if (viewdata.spoilerText.isBlank()) {
if (viewdata.status.spoilerText.isBlank()) {
setTextVisible(true, viewdata.content, viewdata.status.mentions, viewdata.status.tags, viewdata.status.emojis, adapterHandler)
binding.statusContentWarningButton.hide()
binding.statusContentWarningDescription.hide()
} else {
val emojiSpoiler = viewdata.spoilerText.emojify(viewdata.status.emojis, binding.statusContentWarningDescription, statusDisplayOptions.animateEmojis)
val emojiSpoiler = viewdata.status.spoilerText.emojify(viewdata.status.emojis, binding.statusContentWarningDescription, statusDisplayOptions.animateEmojis)
binding.statusContentWarningDescription.text = emojiSpoiler
binding.statusContentWarningDescription.show()
binding.statusContentWarningButton.show()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

package com.keylesspalace.tusky.service

import android.annotation.TargetApi
import android.content.Intent
import android.service.quicksettings.TileService
import com.keylesspalace.tusky.MainActivity
Expand All @@ -25,8 +24,6 @@ import com.keylesspalace.tusky.components.compose.ComposeActivity
* Small Addition that adds in a QuickSettings tile
* opens the Compose activity or shows an account selector when multiple accounts are present
*/

@TargetApi(24)
class TuskyTileService : TileService() {

override fun onClick() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class ListStatusAccessibilityDelegate(
val pos = recyclerView.getChildAdapterPosition(host)
val status = statusProvider.getStatus(pos) ?: return
if (status is StatusViewData.Concrete) {
if (status.spoilerText.isNotEmpty()) {
if (status.status.spoilerText.isNotEmpty()) {
info.addAction(if (status.isExpanded) collapseCwAction else expandCwAction)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

package com.keylesspalace.tusky.util

import android.icu.text.BreakIterator
import android.text.InputFilter
import android.text.SpannableStringBuilder
import android.text.Spanned
Expand Down Expand Up @@ -72,20 +73,10 @@ object SmartLengthInputFilter : InputFilter {
if (source[keep].isLetterOrDigit()) {
var boundary: Int

// Android N+ offer a clone of the ICU APIs in Java for better internationalization and
// unicode support. Using the ICU version of BreakIterator grants better support for
// those without having to add the ICU4J library at a minimum Api trade-off.
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
val iterator = android.icu.text.BreakIterator.getWordInstance()
iterator.setText(source.toString())
boundary = iterator.following(keep)
if (keep - boundary > RUNWAY) boundary = iterator.preceding(keep)
} else {
val iterator = java.text.BreakIterator.getWordInstance()
iterator.setText(source.toString())
boundary = iterator.following(keep)
if (keep - boundary > RUNWAY) boundary = iterator.preceding(keep)
}
val iterator = BreakIterator.getWordInstance()
iterator.setText(source.toString())
boundary = iterator.following(keep)
if (keep - boundary > RUNWAY) boundary = iterator.preceding(keep)

keep = boundary
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package com.keylesspalace.tusky.util

import android.text.Html.TagHandler
import android.text.SpannableStringBuilder
import android.text.Spanned
import androidx.core.text.parseAsHtml

Expand All @@ -36,31 +35,3 @@ fun String.parseAsMastodonHtml(tagHandler: TagHandler? = null): Spanned {
* most status contents do, so it should be trimmed. */
.trimTrailingWhitespace()
}

fun replaceCrashingCharacters(content: Spanned): Spanned {
return replaceCrashingCharacters(content as CharSequence) as Spanned
}

fun replaceCrashingCharacters(content: CharSequence): CharSequence? {
var replacing = false
var builder: SpannableStringBuilder? = null
val length = content.length
for (index in 0 until length) {
val character = content[index]

// If there are more than one or two, switch to a map
if (character == SOFT_HYPHEN) {
if (!replacing) {
replacing = true
builder = SpannableStringBuilder(content, 0, index)
}
builder!!.append(ASCII_HYPHEN)
} else if (replacing) {
builder!!.append(character)
}
}
return if (replacing) builder else content
}

private const val SOFT_HYPHEN = '\u00ad'
private const val ASCII_HYPHEN = '-'
Loading