From 9a8dfaa744ee0344a75aa2cfa381fa4c2c503206 Mon Sep 17 00:00:00 2001 From: Guntbert Reiter Date: Fri, 29 Apr 2022 18:35:25 +0200 Subject: [PATCH] Remove code to check the server version (#2469) solves #2439 --- .../components/compose/ComposeActivity.kt | 1 - .../components/instanceinfo/InstanceInfo.kt | 3 +- .../instanceinfo/InstanceInfoRepository.kt | 4 +- .../tusky/util/VersionUtils.java | 44 ------------------- .../tusky/util/VersionUtilsTest.kt | 35 --------------- 5 files changed, 2 insertions(+), 85 deletions(-) delete mode 100644 app/src/main/java/com/keylesspalace/tusky/util/VersionUtils.java delete mode 100644 app/src/test/java/com/keylesspalace/tusky/util/VersionUtilsTest.kt diff --git a/app/src/main/java/com/keylesspalace/tusky/components/compose/ComposeActivity.kt b/app/src/main/java/com/keylesspalace/tusky/components/compose/ComposeActivity.kt index b7a65a7f4..48e14def5 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/compose/ComposeActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/compose/ComposeActivity.kt @@ -335,7 +335,6 @@ class ComposeActivity : maximumTootCharacters = instanceData.maxChars charactersReservedPerUrl = instanceData.charactersReservedPerUrl updateVisibleCharactersLeft() - binding.composeScheduleButton.visible(instanceData.supportsScheduled) } viewModel.emoji.observe { emoji -> setEmojiList(emoji) } combineLiveData(viewModel.markMediaAsSensitive, viewModel.showContentWarning) { markSensitive, showContentWarning -> diff --git a/app/src/main/java/com/keylesspalace/tusky/components/instanceinfo/InstanceInfo.kt b/app/src/main/java/com/keylesspalace/tusky/components/instanceinfo/InstanceInfo.kt index db6ec0e1f..05e10b6bc 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/instanceinfo/InstanceInfo.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/instanceinfo/InstanceInfo.kt @@ -21,6 +21,5 @@ data class InstanceInfo( val pollMaxLength: Int, val pollMinDuration: Int, val pollMaxDuration: Int, - val charactersReservedPerUrl: Int, - val supportsScheduled: Boolean + val charactersReservedPerUrl: Int ) diff --git a/app/src/main/java/com/keylesspalace/tusky/components/instanceinfo/InstanceInfoRepository.kt b/app/src/main/java/com/keylesspalace/tusky/components/instanceinfo/InstanceInfoRepository.kt index 287d54995..8ed26d7b1 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/instanceinfo/InstanceInfoRepository.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/instanceinfo/InstanceInfoRepository.kt @@ -22,7 +22,6 @@ import com.keylesspalace.tusky.db.EmojisEntity import com.keylesspalace.tusky.db.InstanceInfoEntity import com.keylesspalace.tusky.entity.Emoji import com.keylesspalace.tusky.network.MastodonApi -import com.keylesspalace.tusky.util.VersionUtils import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import javax.inject.Inject @@ -83,8 +82,7 @@ class InstanceInfoRepository @Inject constructor( pollMaxLength = instanceInfo?.maxPollOptionLength ?: DEFAULT_MAX_OPTION_LENGTH, pollMinDuration = instanceInfo?.minPollDuration ?: DEFAULT_MIN_POLL_DURATION, pollMaxDuration = instanceInfo?.maxPollDuration ?: DEFAULT_MAX_POLL_DURATION, - charactersReservedPerUrl = instanceInfo?.charactersReservedPerUrl ?: DEFAULT_CHARACTERS_RESERVED_PER_URL, - supportsScheduled = instanceInfo?.version?.let { VersionUtils(it).supportsScheduledToots() } ?: false + charactersReservedPerUrl = instanceInfo?.charactersReservedPerUrl ?: DEFAULT_CHARACTERS_RESERVED_PER_URL ) } } diff --git a/app/src/main/java/com/keylesspalace/tusky/util/VersionUtils.java b/app/src/main/java/com/keylesspalace/tusky/util/VersionUtils.java deleted file mode 100644 index dceef0f30..000000000 --- a/app/src/main/java/com/keylesspalace/tusky/util/VersionUtils.java +++ /dev/null @@ -1,44 +0,0 @@ -/* Copyright 2019 kyori19 - * - * This file is a part of Tusky. - * - * This program is free software; you can redistribute it and/or modify it under the terms of the - * GNU General Public License as published by the Free Software Foundation; either version 3 of the - * License, or (at your option) any later version. - * - * Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even - * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. - * - * You should have received a copy of the GNU General Public License along with Tusky; if not, - * see . */ - -package com.keylesspalace.tusky.util; - -import androidx.annotation.NonNull; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class VersionUtils { - - private int major; - private int minor; - private int patch; - - public VersionUtils(@NonNull String versionString) { - String regex = "([0-9]+)\\.([0-9]+)\\.([0-9]+).*"; - Pattern pattern = Pattern.compile(regex); - Matcher matcher = pattern.matcher(versionString); - if (matcher.find()) { - major = Integer.parseInt(matcher.group(1)); - minor = Integer.parseInt(matcher.group(2)); - patch = Integer.parseInt(matcher.group(3)); - } - } - - public boolean supportsScheduledToots() { - return (major == 2) ? ( (minor == 7) ? (patch >= 0) : (minor > 7) ) : (major > 2); - } - -} diff --git a/app/src/test/java/com/keylesspalace/tusky/util/VersionUtilsTest.kt b/app/src/test/java/com/keylesspalace/tusky/util/VersionUtilsTest.kt deleted file mode 100644 index 2731228a0..000000000 --- a/app/src/test/java/com/keylesspalace/tusky/util/VersionUtilsTest.kt +++ /dev/null @@ -1,35 +0,0 @@ -package com.keylesspalace.tusky.util - -import org.junit.Assert.assertEquals -import org.junit.Test -import org.junit.runner.RunWith -import org.junit.runners.Parameterized - -@RunWith(Parameterized::class) -class VersionUtilsTest( - private val versionString: String, - private val supportsScheduledToots: Boolean -) { - - companion object { - @JvmStatic - @Parameterized.Parameters - fun data() = listOf( - arrayOf("2.0.0", false), - arrayOf("2a9a0", false), - arrayOf("1.0", false), - arrayOf("error", false), - arrayOf("", false), - arrayOf("2.6.9", false), - arrayOf("2.7.0", true), - arrayOf("2.00008.0", true), - arrayOf("2.7.2 (compatible; Pleroma 1.0.0-1168-ge18c7866-pleroma-dot-site)", true), - arrayOf("3.0.1", true) - ) - } - - @Test - fun testVersionUtils() { - assertEquals(VersionUtils(versionString).supportsScheduledToots(), supportsScheduledToots) - } -}