diff --git a/twidere/src.unused/main/java/org/mariotaku/twidere/util/ChoreographerCompat.java b/twidere/src.unused/main/java/org/mariotaku/twidere/util/ChoreographerCompat.java deleted file mode 100644 index d9fecf530..000000000 --- a/twidere/src.unused/main/java/org/mariotaku/twidere/util/ChoreographerCompat.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2017 Mariotaku Lee - * - * 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. - * - * This program 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 this program. If not, see . - */ - -package org.mariotaku.twidere.util; - -import android.annotation.TargetApi; -import android.os.Build; -import android.os.Handler; -import android.os.Looper; -import android.view.Choreographer; - -import java.util.Map; -import java.util.WeakHashMap; - -/** - * Created by mariotaku on 2017/8/20. - */ - -public abstract class ChoreographerCompat { - - private ChoreographerCompat() { - - } - - public abstract void postFrameCallback(ChoreographerCompat.FrameCallback callback); - - public abstract void postFrameCallbackDelayed(ChoreographerCompat.FrameCallback callback, long delayMillis); - - public abstract void removeFrameCallback(ChoreographerCompat.FrameCallback callback); - - public static ChoreographerCompat getInstance() { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { - return ChoreographerCompatImpl.getCompatInstance(); - } - return ChoreographerNativeDelegate.getNativeInstance(); - } - - public interface FrameCallback { - void doFrame(long frameTimeNanos); - } - - private static class ChoreographerCompatImpl extends ChoreographerCompat { - - private static final Map sInstances = new WeakHashMap<>(); - - private final Handler handler; - - ChoreographerCompatImpl(Looper looper) { - handler = new Handler(looper); - } - - @Override - public void postFrameCallback(FrameCallback callback) { - handler.postDelayed(CompatFrameCallbackWrapper.wrap(callback), 0); - } - - @Override - public void postFrameCallbackDelayed(FrameCallback callback, long delayMillis) { - handler.postDelayed(CompatFrameCallbackWrapper.wrap(callback), delayMillis + 16); - } - - @Override - public void removeFrameCallback(FrameCallback callback) { - handler.removeCallbacks(CompatFrameCallbackWrapper.wrap(callback)); - } - - static ChoreographerCompat getCompatInstance() { - final Looper looper = Looper.myLooper(); - ChoreographerCompat instance = sInstances.get(looper); - if (instance != null) return instance; - instance = new ChoreographerCompatImpl(looper); - sInstances.put(looper, instance); - return instance; - } - - - private static class CompatFrameCallbackWrapper implements Runnable { - private static final Map sInstances = new WeakHashMap<>(); - private final FrameCallback callback; - - private CompatFrameCallbackWrapper(ChoreographerCompat.FrameCallback callback) { - this.callback = callback; - } - - @Override - public void run() { - callback.doFrame(System.nanoTime()); - } - - static Runnable wrap(FrameCallback callback) { - Runnable wrapper = sInstances.get(callback); - if (wrapper != null) return wrapper; - wrapper = new CompatFrameCallbackWrapper(callback); - sInstances.put(callback, wrapper); - return wrapper; - } - - } - } - - @TargetApi(Build.VERSION_CODES.JELLY_BEAN) - private static class ChoreographerNativeDelegate extends ChoreographerCompat { - - private static final Map sInstances = new WeakHashMap<>(); - - private final Choreographer implementation; - - ChoreographerNativeDelegate(Choreographer implementation) { - this.implementation = implementation; - } - - public void postFrameCallback(ChoreographerCompat.FrameCallback callback) { - implementation.postFrameCallback(NativeFrameCallbackWrapper.wrap(callback)); - } - - public void postFrameCallbackDelayed(ChoreographerCompat.FrameCallback callback, long delayMillis) { - implementation.postFrameCallbackDelayed(NativeFrameCallbackWrapper.wrap(callback), delayMillis); - } - - public void removeFrameCallback(ChoreographerCompat.FrameCallback callback) { - implementation.removeFrameCallback(NativeFrameCallbackWrapper.wrap(callback)); - } - - static ChoreographerCompat getNativeInstance() { - final Choreographer implementation = Choreographer.getInstance(); - ChoreographerCompat instance = sInstances.get(implementation); - if (instance != null) return instance; - instance = new ChoreographerNativeDelegate(implementation); - sInstances.put(implementation, instance); - return instance; - } - - private static class NativeFrameCallbackWrapper implements Choreographer.FrameCallback { - private static final Map sInstances = new WeakHashMap<>(); - private final FrameCallback callback; - - private NativeFrameCallbackWrapper(ChoreographerCompat.FrameCallback callback) { - this.callback = callback; - } - - @Override - public void doFrame(long frameTimeNanos) { - callback.doFrame(frameTimeNanos); - } - - static Choreographer.FrameCallback wrap(ChoreographerCompat.FrameCallback callback) { - Choreographer.FrameCallback wrapper = sInstances.get(callback); - if (wrapper != null) return wrapper; - wrapper = new NativeFrameCallbackWrapper(callback); - sInstances.put(callback, wrapper); - return wrapper; - } - - } - } -} diff --git a/twidere/src/androidTest/kotlin/org/mariotaku/twidere/activity/ComposeActivityTest.kt b/twidere/src/androidTest/kotlin/org/mariotaku/twidere/activity/ComposeActivityTest.kt index 8965337d6..1a59e9f03 100644 --- a/twidere/src/androidTest/kotlin/org/mariotaku/twidere/activity/ComposeActivityTest.kt +++ b/twidere/src/androidTest/kotlin/org/mariotaku/twidere/activity/ComposeActivityTest.kt @@ -47,8 +47,8 @@ class ComposeActivityTest { @Test fun testReply() { - val context = InstrumentationRegistry.getContext() - val targetContext = InstrumentationRegistry.getTargetContext() + val context = InstrumentationRegistry.getInstrumentation().context + val targetContext = InstrumentationRegistry.getInstrumentation().targetContext val status: ParcelableStatus = context.resources.getJsonResource(R.raw.parcelable_status_848051071444410368) val intent = Intent(INTENT_ACTION_REPLY) intent.setClass(targetContext, ComposeActivity::class.java) @@ -67,8 +67,8 @@ class ComposeActivityTest { @Test fun testReplyRemovedSomeMentions() { - val context = InstrumentationRegistry.getContext() - val targetContext = InstrumentationRegistry.getTargetContext() + val context = InstrumentationRegistry.getInstrumentation().context + val targetContext = InstrumentationRegistry.getInstrumentation().targetContext val status: ParcelableStatus = context.resources.getJsonResource(R.raw.parcelable_status_848051071444410368) val intent = Intent(INTENT_ACTION_REPLY) intent.setClass(targetContext, ComposeActivity::class.java) @@ -87,8 +87,8 @@ class ComposeActivityTest { @Test fun testReplyNoMentions() { - val context = InstrumentationRegistry.getContext() - val targetContext = InstrumentationRegistry.getTargetContext() + val context = InstrumentationRegistry.getInstrumentation().context + val targetContext = InstrumentationRegistry.getInstrumentation().targetContext val status: ParcelableStatus = context.resources.getJsonResource(R.raw.parcelable_status_848051071444410368) val intent = Intent(INTENT_ACTION_REPLY) intent.setClass(targetContext, ComposeActivity::class.java) @@ -109,8 +109,8 @@ class ComposeActivityTest { @Test fun testReplySelf() { - val context = InstrumentationRegistry.getContext() - val targetContext = InstrumentationRegistry.getTargetContext() + val context = InstrumentationRegistry.getInstrumentation().context + val targetContext = InstrumentationRegistry.getInstrumentation().targetContext val status: ParcelableStatus = context.resources.getJsonResource(R.raw.parcelable_status_852737226718838790) val intent = Intent(INTENT_ACTION_REPLY) intent.setClass(targetContext, ComposeActivity::class.java) @@ -129,8 +129,8 @@ class ComposeActivityTest { @Test fun testReplySelfRemovedSomeMentions() { - val context = InstrumentationRegistry.getContext() - val targetContext = InstrumentationRegistry.getTargetContext() + val context = InstrumentationRegistry.getInstrumentation().context + val targetContext = InstrumentationRegistry.getInstrumentation().targetContext val status: ParcelableStatus = context.resources.getJsonResource(R.raw.parcelable_status_852737226718838790) val intent = Intent(INTENT_ACTION_REPLY) intent.setClass(targetContext, ComposeActivity::class.java) @@ -149,8 +149,8 @@ class ComposeActivityTest { @Test fun testReplySelfNoMentions() { - val context = InstrumentationRegistry.getContext() - val targetContext = InstrumentationRegistry.getTargetContext() + val context = InstrumentationRegistry.getInstrumentation().context + val targetContext = InstrumentationRegistry.getInstrumentation().targetContext val status: ParcelableStatus = context.resources.getJsonResource(R.raw.parcelable_status_852737226718838790) val intent = Intent(INTENT_ACTION_REPLY) intent.setClass(targetContext, ComposeActivity::class.java) @@ -174,7 +174,7 @@ class ComposeActivityTest { private fun ComposeActivity.getStatusUpdateTest(checkLength: Boolean): ParcelableStatusUpdate { val getStatusUpdate = javaClass.getDeclaredMethod("getStatusUpdate", - kotlin.Boolean::class.java).apply { + Boolean::class.java).apply { isAccessible = true } return getStatusUpdate(this, checkLength) as ParcelableStatusUpdate diff --git a/twidere/src/androidTest/kotlin/org/mariotaku/twidere/extension/FileExtensionsTest.kt b/twidere/src/androidTest/kotlin/org/mariotaku/twidere/extension/FileExtensionsTest.kt index 5e8262fc4..69501e719 100644 --- a/twidere/src/androidTest/kotlin/org/mariotaku/twidere/extension/FileExtensionsTest.kt +++ b/twidere/src/androidTest/kotlin/org/mariotaku/twidere/extension/FileExtensionsTest.kt @@ -33,7 +33,7 @@ import java.util.* class FileExtensionsTest { @Test fun testTempFileInputStream() { - val context = InstrumentationRegistry.getTargetContext() + val context = InstrumentationRegistry.getInstrumentation().targetContext val random = Random() val testData = ByteArray(1024) random.nextBytes(testData) diff --git a/twidere/src/androidTest/kotlin/org/mariotaku/twidere/extension/model/DraftExtensionsTest.kt b/twidere/src/androidTest/kotlin/org/mariotaku/twidere/extension/model/DraftExtensionsTest.kt index 8ebeb86f8..ad6c172f6 100644 --- a/twidere/src/androidTest/kotlin/org/mariotaku/twidere/extension/model/DraftExtensionsTest.kt +++ b/twidere/src/androidTest/kotlin/org/mariotaku/twidere/extension/model/DraftExtensionsTest.kt @@ -1,8 +1,9 @@ package org.mariotaku.twidere.extension.model +import android.media.RingtoneManager import android.net.Uri -import androidx.test.platform.app.InstrumentationRegistry import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.platform.app.InstrumentationRegistry import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith @@ -19,7 +20,7 @@ import java.util.concurrent.TimeUnit class DraftExtensionsTest { @Test fun testMimeMessageProcessing() { - val context = InstrumentationRegistry.getTargetContext() + val context = InstrumentationRegistry.getInstrumentation().targetContext val draft = Draft() draft.action_type = Draft.Action.UPDATE_STATUS draft.timestamp = System.currentTimeMillis() @@ -27,12 +28,12 @@ class DraftExtensionsTest { draft.text = "Hello world 测试" draft.location = ParcelableLocation(-11.956, 99.625) // Randomly generated draft.media = arrayOf( - "file:///system/media/audio/ringtones/Atria.ogg", - "file:///system/media/audio/ringtones/Callisto.ogg", - "file:///system/media/audio/ringtones/Dione.ogg" + RingtoneManager.getActualDefaultRingtoneUri(context, RingtoneManager.TYPE_RINGTONE), + RingtoneManager.getActualDefaultRingtoneUri(context, RingtoneManager.TYPE_NOTIFICATION), + RingtoneManager.getActualDefaultRingtoneUri(context, RingtoneManager.TYPE_ALARM) ).map { uri -> ParcelableMediaUpdate().apply { - this.uri = uri + this.uri = uri.toString() this.type = ParcelableMedia.Type.VIDEO this.alt_text = String(CharArray(420).apply { fill('A') @@ -58,7 +59,7 @@ class DraftExtensionsTest { Assert.assertEquals(expected.type, actual.type) val stl = context.contentResolver.openInputStream(Uri.parse(expected.uri)) val str = context.contentResolver.openInputStream(Uri.parse(actual.uri)) - Assert.assertTrue(stl.contentEquals(str)) + Assert.assertTrue(stl!!.contentEquals(str!!)) stl.close() str.close() } diff --git a/twidere/src/androidTest/kotlin/org/mariotaku/twidere/extension/text/twitter/ExtractorExtensionsTest.kt b/twidere/src/androidTest/kotlin/org/mariotaku/twidere/extension/text/twitter/ExtractorExtensionsTest.kt index 8b9aae90a..0a6e75f7b 100644 --- a/twidere/src/androidTest/kotlin/org/mariotaku/twidere/extension/text/twitter/ExtractorExtensionsTest.kt +++ b/twidere/src/androidTest/kotlin/org/mariotaku/twidere/extension/text/twitter/ExtractorExtensionsTest.kt @@ -42,7 +42,7 @@ class ExtractorExtensionsTest { @Before fun setUp() { - val context = InstrumentationRegistry.getContext() + val context = InstrumentationRegistry.getInstrumentation().context // This is a tweet by @t_deyarmin, mentioning @nixcraft inReplyTo = context.resources.openRawResource(R.raw.parcelable_status_848051071444410368).use { diff --git a/twidere/src/androidTest/kotlin/org/mariotaku/twidere/model/util/ParcelableStatusUtilsTest.kt b/twidere/src/androidTest/kotlin/org/mariotaku/twidere/model/util/ParcelableStatusUtilsTest.kt index 016f161cc..77536988c 100644 --- a/twidere/src/androidTest/kotlin/org/mariotaku/twidere/model/util/ParcelableStatusUtilsTest.kt +++ b/twidere/src/androidTest/kotlin/org/mariotaku/twidere/model/util/ParcelableStatusUtilsTest.kt @@ -23,7 +23,7 @@ class ParcelableStatusUtilsTest { @Test fun testFromStatus() { - val context = InstrumentationRegistry.getContext() + val context = InstrumentationRegistry.getInstrumentation().context val status_8754050 = context.resources.openRawResource(R.raw.status_8754050).use { val status = JsonSerializer.parse(it, Status::class.java) return@use status.toParcelable(UserKey("1234567", "gnusocial.de"), AccountType.STATUSNET) diff --git a/twidere/src/androidTest/kotlin/org/mariotaku/twidere/provider/TwidereDataStoreTest.kt b/twidere/src/androidTest/kotlin/org/mariotaku/twidere/provider/TwidereDataStoreTest.kt index 3d0ec7001..f4b222bb8 100644 --- a/twidere/src/androidTest/kotlin/org/mariotaku/twidere/provider/TwidereDataStoreTest.kt +++ b/twidere/src/androidTest/kotlin/org/mariotaku/twidere/provider/TwidereDataStoreTest.kt @@ -15,7 +15,7 @@ import org.junit.runner.RunWith class TwidereDataStoreTest { @Test fun testBaseUris() { - val context = InstrumentationRegistry.getTargetContext() + val context = InstrumentationRegistry.getInstrumentation().targetContext val resolver = context.contentResolver Assert.assertEquals(TwidereDataStore.BASE_CONTENT_URI, Uri.parse("content://twidere")) Assert.assertNull(resolver.query(TwidereDataStore.CONTENT_URI_NULL, null, null, null, null)) diff --git a/twidere/src/androidTest/kotlin/org/mariotaku/twidere/task/SaveFileTaskTest.kt b/twidere/src/androidTest/kotlin/org/mariotaku/twidere/task/SaveFileTaskTest.kt index 3eb1425d6..c01a83ace 100644 --- a/twidere/src/androidTest/kotlin/org/mariotaku/twidere/task/SaveFileTaskTest.kt +++ b/twidere/src/androidTest/kotlin/org/mariotaku/twidere/task/SaveFileTaskTest.kt @@ -11,7 +11,7 @@ class SaveFileTaskTest { @Test @Throws(Exception::class) fun testGetFileNameWithExtension() { - assertEquals("pbs_twimg_com_media_abcdefghijklmn.jpg", + assertEquals("abcdefghijklmn.jpg", SaveFileTask.getFileNameWithExtension("pbs_twimg_com_media_abcdefghijklmn_jpg", "jpg", '_', null)) assertEquals("pbs_twimg_com_media_abcdefghijklmn_jpg", diff --git a/twidere/src/androidTest/kotlin/org/mariotaku/twidere/util/DataStoreUtilsTest.kt b/twidere/src/androidTest/kotlin/org/mariotaku/twidere/util/DataStoreUtilsTest.kt index 8d63bb52f..45715aa70 100644 --- a/twidere/src/androidTest/kotlin/org/mariotaku/twidere/util/DataStoreUtilsTest.kt +++ b/twidere/src/androidTest/kotlin/org/mariotaku/twidere/util/DataStoreUtilsTest.kt @@ -12,13 +12,13 @@ import org.junit.runner.RunWith class DataStoreUtilsTest { @Test fun testCleanDatabasesByItemLimit() { - val context = InstrumentationRegistry.getTargetContext() + val context = InstrumentationRegistry.getInstrumentation().targetContext DataStoreUtils.cleanDatabasesByItemLimit(context) } @Test fun testGetAccountKeys() { - val context = InstrumentationRegistry.getTargetContext() + val context = InstrumentationRegistry.getInstrumentation().targetContext DataStoreUtils.getAccountKeys(context) } } \ No newline at end of file diff --git a/twidere/src/androidTest/kotlin/org/mariotaku/twidere/util/MapFragmentFactoryTest.kt b/twidere/src/androidTest/kotlin/org/mariotaku/twidere/util/MapFragmentFactoryTest.kt index 51bab6bed..7b02f195a 100644 --- a/twidere/src/androidTest/kotlin/org/mariotaku/twidere/util/MapFragmentFactoryTest.kt +++ b/twidere/src/androidTest/kotlin/org/mariotaku/twidere/util/MapFragmentFactoryTest.kt @@ -12,7 +12,7 @@ import org.junit.runner.RunWith class MapFragmentFactoryTest { @Test fun testGetInstance() { - val context = InstrumentationRegistry.getTargetContext() + val context = InstrumentationRegistry.getInstrumentation().targetContext MapFragmentFactory.instance.createMapFragment(context = context) } } \ No newline at end of file diff --git a/twidere/src/androidTest/kotlin/org/mariotaku/twidere/util/StatusShortenerInterfaceTest.kt b/twidere/src/androidTest/kotlin/org/mariotaku/twidere/util/StatusShortenerInterfaceTest.kt index 7df597592..14d2c2ad1 100644 --- a/twidere/src/androidTest/kotlin/org/mariotaku/twidere/util/StatusShortenerInterfaceTest.kt +++ b/twidere/src/androidTest/kotlin/org/mariotaku/twidere/util/StatusShortenerInterfaceTest.kt @@ -24,7 +24,7 @@ class StatusShortenerInterfaceTest { @Test @FlakyTest fun testConnection() { - val context = InstrumentationRegistry.getTargetContext() + val context = InstrumentationRegistry.getInstrumentation().targetContext val application = context.applicationContext as Application val preferences = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE) val shortenerComponent = preferences.getString(TwidereConstants.KEY_STATUS_SHORTENER, null) ?: return diff --git a/twidere/src/androidTest/kotlin/org/mariotaku/twidere/util/TestAccountUtils.kt b/twidere/src/androidTest/kotlin/org/mariotaku/twidere/util/TestAccountUtils.kt index efff879c2..9c78bdad5 100644 --- a/twidere/src/androidTest/kotlin/org/mariotaku/twidere/util/TestAccountUtils.kt +++ b/twidere/src/androidTest/kotlin/org/mariotaku/twidere/util/TestAccountUtils.kt @@ -35,8 +35,8 @@ object TestAccountUtils { private val accountResources = intArrayOf(R.raw.account_4223092274_twitter_com) fun insertTestAccounts() { - val targetContext = InstrumentationRegistry.getTargetContext() - val context = InstrumentationRegistry.getContext() + val targetContext = InstrumentationRegistry.getInstrumentation().targetContext + val context = InstrumentationRegistry.getInstrumentation().context val am = AccountManager.get(targetContext) val existingAccounts = AccountUtils.getAllAccountDetails(am, false) accountResources.forEach { resId -> @@ -52,7 +52,7 @@ object TestAccountUtils { } fun removeTestAccounts() { - val targetContext = InstrumentationRegistry.getTargetContext() + val targetContext = InstrumentationRegistry.getInstrumentation().targetContext val am = AccountManager.get(targetContext) val existingAccounts = AccountUtils.getAllAccountDetails(am, false) existingAccounts.filter { it.test }.forEach { am.removeAccountSupport(it.account) } diff --git a/twidere/src/androidTest/kotlin/org/mariotaku/twidere/util/UtilsTest.kt b/twidere/src/androidTest/kotlin/org/mariotaku/twidere/util/UtilsTest.kt index 396e23460..7701fe469 100644 --- a/twidere/src/androidTest/kotlin/org/mariotaku/twidere/util/UtilsTest.kt +++ b/twidere/src/androidTest/kotlin/org/mariotaku/twidere/util/UtilsTest.kt @@ -1,6 +1,5 @@ package org.mariotaku.twidere.util -import androidx.test.platform.app.InstrumentationRegistry import androidx.test.ext.junit.runners.AndroidJUnit4 import org.junit.Test import org.junit.runner.RunWith diff --git a/twidere/src/androidTest/kotlin/org/mariotaku/twidere/util/filter/UrlFiltersSubscriptionProviderTest.kt b/twidere/src/androidTest/kotlin/org/mariotaku/twidere/util/filter/UrlFiltersSubscriptionProviderTest.kt index 5f187fd5e..a4907e08a 100644 --- a/twidere/src/androidTest/kotlin/org/mariotaku/twidere/util/filter/UrlFiltersSubscriptionProviderTest.kt +++ b/twidere/src/androidTest/kotlin/org/mariotaku/twidere/util/filter/UrlFiltersSubscriptionProviderTest.kt @@ -15,7 +15,7 @@ import org.mariotaku.twidere.model.filter.UrlFiltersSubscriptionProviderArgument class UrlFiltersSubscriptionProviderTest { @Test fun testFetchXml() { - val context = InstrumentationRegistry.getTargetContext() + val context = InstrumentationRegistry.getInstrumentation().targetContext val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager if (cm.activeNetworkInfo?.isConnected != true) return diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/task/SaveFileTask.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/task/SaveFileTask.kt index 6429245df..3a5c80b3a 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/task/SaveFileTask.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/task/SaveFileTask.kt @@ -148,6 +148,7 @@ abstract class SaveFileTask( sb.append(name .removeSuffix(extension) .removeSuffix(".") + .removeSuffix(specialCharacter.toString()) .takeLastWhile { it != specialCharacter }) } else { sb.append(name)