diff --git a/.circleci/.firebase.secrets.json.enc b/.circleci/.firebase.secrets.json.enc index 84e8c322ed..63f49ac7c9 100644 Binary files a/.circleci/.firebase.secrets.json.enc and b/.circleci/.firebase.secrets.json.enc differ diff --git a/.circleci/gradle.properties.enc b/.circleci/gradle.properties.enc index 1c350e1c76..565c18aee9 100644 Binary files a/.circleci/gradle.properties.enc and b/.circleci/gradle.properties.enc differ diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000000..40146908b4 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,258 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/build.gradle b/build.gradle index 27e23cca9e..dc86b86b90 100644 --- a/build.gradle +++ b/build.gradle @@ -69,9 +69,11 @@ subprojects { } ext { - daggerVersion = '2.11' + daggerVersion = '2.22.1' wellSqlVersion = '1.4.0' supportLibraryVersion = '27.1.1' arch_paging_version = '1.0.1' arch_lifecycle_version = '1.1.1' + arch_core_version = '2.0.1' + appcompat_version = '1.0.2' } diff --git a/config/checkstyle.xml b/config/checkstyle.xml index 721b0aa929..340f075a2d 100644 --- a/config/checkstyle.xml +++ b/config/checkstyle.xml @@ -160,7 +160,7 @@ - + diff --git a/example/build.gradle b/example/build.gradle index efe92af59f..c430e7b899 100644 --- a/example/build.gradle +++ b/example/build.gradle @@ -13,7 +13,7 @@ apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-kapt' android { - compileSdkVersion 27 + compileSdkVersion 28 buildToolsVersion '28.0.3' defaultConfig { @@ -26,7 +26,7 @@ android { versionCode 1 versionName "1.0" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { @@ -87,10 +87,13 @@ dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion" - implementation "com.android.support:appcompat-v7:$supportLibraryVersion" - implementation "com.android.support:support-v4:$supportLibraryVersion" - implementation "com.android.support:recyclerview-v7:$supportLibraryVersion" - implementation 'com.android.support.constraint:constraint-layout:1.1.3' + implementation "androidx.appcompat:appcompat:$appcompat_version" + implementation "androidx.legacy:legacy-support-v4:1.0.0" + implementation "androidx.recyclerview:recyclerview:1.0.0" + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + implementation 'androidx.annotation:annotation:1.0.2' + implementation "androidx.arch.core:core-common:$arch_core_version" + implementation "androidx.arch.core:core-runtime:$arch_core_version" // WordPress libs implementation ('org.wordpress:utils:1.20.0') { @@ -114,16 +117,16 @@ dependencies { testImplementation 'org.mockito:mockito-core:2.23.0' testImplementation 'com.nhaarman.mockitokotlin2:mockito-kotlin:2.1.0' testImplementation 'org.assertj:assertj-core:3.11.1' - testImplementation "android.arch.core:core-testing:$arch_lifecycle_version" + testImplementation "androidx.arch.core:core-testing:$arch_core_version" androidTestImplementation 'org.mockito:mockito-android:2.6.3' androidTestImplementation 'org.apache.commons:commons-lang3:3.5' - androidTestImplementation "android.arch.core:core-testing:1.1.1" + androidTestImplementation "androidx.arch.core:core-testing:$arch_core_version" kaptAndroidTest "com.google.dagger:dagger-compiler:$daggerVersion" androidTestCompileOnly 'org.glassfish:javax.annotation:10.0-b28' // Test orchestrator - androidTestImplementation 'com.android.support.test:runner:1.0.2' - androidTestUtil 'com.android.support.test:orchestrator:1.0.2' + androidTestImplementation 'androidx.test:runner:1.2.0' + androidTestUtil 'androidx.test:orchestrator:1.2.0' // Debug dependencies debugImplementation 'com.facebook.stetho:stetho:1.5.0' diff --git a/example/gradle.properties-example b/example/gradle.properties-example index 3becc9875d..8e0f0567d0 100644 --- a/example/gradle.properties-example +++ b/example/gradle.properties-example @@ -1,3 +1,5 @@ # OAuth credentials for example app wp.OAUTH.APP.ID = wp wp.OAUTH.APP.SECRET = wp +android.useAndroidX=true +android.enableJetifier=true diff --git a/example/src/androidTest/java/org/wordpress/android/fluxc/TestUtils.java b/example/src/androidTest/java/org/wordpress/android/fluxc/TestUtils.java index 3fa7e2d749..4834231021 100644 --- a/example/src/androidTest/java/org/wordpress/android/fluxc/TestUtils.java +++ b/example/src/androidTest/java/org/wordpress/android/fluxc/TestUtils.java @@ -2,9 +2,10 @@ import android.content.Context; import android.content.res.Configuration; -import android.support.annotation.NonNull; import android.text.TextUtils; +import androidx.annotation.NonNull; + import org.wordpress.android.fluxc.example.test.BuildConfig; import org.wordpress.android.util.AppLog; import org.wordpress.android.util.AppLog.T; diff --git a/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_AccountTest.java b/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_AccountTest.java index 15b345d3ee..f29b70b94b 100644 --- a/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_AccountTest.java +++ b/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_AccountTest.java @@ -1,6 +1,6 @@ package org.wordpress.android.fluxc.mocked; -import android.support.test.runner.AndroidJUnit4; +import androidx.test.runner.AndroidJUnit4; import org.greenrobot.eventbus.Subscribe; import org.junit.After; diff --git a/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_Base.java b/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_Base.java index f87397258b..6d69a8b0a0 100644 --- a/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_Base.java +++ b/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_Base.java @@ -13,7 +13,7 @@ import javax.inject.Inject; -import static android.support.test.InstrumentationRegistry.getInstrumentation; +import static androidx.test.InstrumentationRegistry.getInstrumentation; public class MockedStack_Base { Context mAppContext; diff --git a/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_NotificationTest.kt b/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_NotificationTest.kt index 76acbc2e80..bf336229aa 100644 --- a/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_NotificationTest.kt +++ b/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_NotificationTest.kt @@ -5,6 +5,7 @@ import org.greenrobot.eventbus.Subscribe import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse import org.junit.Assert.assertNotNull +import org.junit.Assert.assertNull import org.junit.Assert.assertTrue import org.junit.Test import org.wordpress.android.fluxc.Dispatcher @@ -16,11 +17,12 @@ import org.wordpress.android.fluxc.model.notification.NoteIdSet import org.wordpress.android.fluxc.model.notification.NotificationModel import org.wordpress.android.fluxc.module.ResponseMockingInterceptor import org.wordpress.android.fluxc.network.rest.wpcom.notifications.NotificationRestClient +import org.wordpress.android.fluxc.store.NotificationStore.DeviceRegistrationErrorType import org.wordpress.android.fluxc.store.NotificationStore.FetchNotificationHashesResponsePayload import org.wordpress.android.fluxc.store.NotificationStore.FetchNotificationResponsePayload import org.wordpress.android.fluxc.store.NotificationStore.FetchNotificationsResponsePayload -import org.wordpress.android.fluxc.store.NotificationStore.MarkNotificationsReadResponsePayload import org.wordpress.android.fluxc.store.NotificationStore.MarkNotificationSeenResponsePayload +import org.wordpress.android.fluxc.store.NotificationStore.MarkNotificationsReadResponsePayload import org.wordpress.android.fluxc.store.NotificationStore.NotificationAppKey import org.wordpress.android.fluxc.store.NotificationStore.RegisterDeviceResponsePayload import org.wordpress.android.fluxc.store.SiteStore @@ -105,6 +107,31 @@ class MockedStack_NotificationTest : MockedStack_Base() { assertEquals(responseJson.get("ID").asString, payload.deviceId) } + @Test + fun testRegistrationResponseNull() { + val errorJson = JsonObject().apply { + addProperty("error", DeviceRegistrationErrorType.INVALID_RESPONSE.name) + addProperty("message", "Response object is null") + } + + interceptor.respondWithError(errorJson) + + val gcmToken = "sample-token" + val uuid = "sample-uuid" + val site = SiteModel().apply { siteId = 123456 } + notificationRestClient.registerDeviceForPushNotifications(gcmToken, NotificationAppKey.WOOCOMMERCE, uuid, site) + + countDownLatch = CountDownLatch(1) + assertTrue(countDownLatch.await(TestUtils.DEFAULT_TIMEOUT_MS.toLong(), TimeUnit.MILLISECONDS)) + + assertEquals(NotificationAction.REGISTERED_DEVICE, lastAction!!.type) + + val payload = lastAction!!.payload as RegisterDeviceResponsePayload + assertNotNull(payload.error) + assertNull(payload.deviceId) + assertEquals(DeviceRegistrationErrorType.INVALID_RESPONSE, payload.error.type) + } + @Test fun testUnregistration() { val responseJson = JsonObject().apply { addProperty("success", "true") } diff --git a/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_WCStatsTest.kt b/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_WCStatsTest.kt index c77e3ea723..c734f3a988 100644 --- a/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_WCStatsTest.kt +++ b/example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_WCStatsTest.kt @@ -21,6 +21,7 @@ import org.wordpress.android.fluxc.store.WCStatsStore.FetchOrderStatsResponsePay import org.wordpress.android.fluxc.store.WCStatsStore.FetchTopEarnersStatsResponsePayload import org.wordpress.android.fluxc.store.WCStatsStore.FetchVisitorStatsResponsePayload import org.wordpress.android.fluxc.store.WCStatsStore.OrderStatsErrorType +import org.wordpress.android.fluxc.store.WCStatsStore.OrderStatsErrorType.RESPONSE_NULL import java.util.concurrent.CountDownLatch import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit.MILLISECONDS @@ -171,6 +172,28 @@ class MockedStack_WCStatsTest : MockedStack_Base() { assertEquals(OrderStatsErrorType.INVALID_PARAM, payload.error.type) } + @Test + fun testStatsFetchResponseNullError() { + val errorJson = JsonObject().apply { + addProperty("error", OrderStatsErrorType.RESPONSE_NULL.name) + addProperty("message", "Response object is null") + } + + interceptor.respondWithError(errorJson) + orderStatsRestClient.fetchStats(siteModel, OrderStatsApiUnit.DAY, "2019-02-01", 7) + + countDownLatch = CountDownLatch(1) + assertTrue(countDownLatch.await(TestUtils.DEFAULT_TIMEOUT_MS.toLong(), TimeUnit.MILLISECONDS)) + + assertEquals(WCStatsAction.FETCHED_ORDER_STATS, lastAction!!.type) + val payload = lastAction!!.payload as FetchOrderStatsResponsePayload + assertNotNull(payload.error) + assertEquals(siteModel, payload.site) + assertEquals(OrderStatsApiUnit.DAY, payload.apiUnit) + assertNull(payload.stats) + assertEquals(OrderStatsErrorType.RESPONSE_NULL, payload.error.type) + } + @Test fun testFetchTopEarnersStatsSuccess() { interceptor.respondWith("wc-top-earners-response-success.json") diff --git a/example/src/androidTest/java/org/wordpress/android/fluxc/module/MockedToolsModule.java b/example/src/androidTest/java/org/wordpress/android/fluxc/module/MockedToolsModule.java index a80e8efa7e..0e78f49fac 100644 --- a/example/src/androidTest/java/org/wordpress/android/fluxc/module/MockedToolsModule.java +++ b/example/src/androidTest/java/org/wordpress/android/fluxc/module/MockedToolsModule.java @@ -1,7 +1,8 @@ package org.wordpress.android.fluxc.module; import android.graphics.Bitmap; -import android.support.v4.util.LruCache; + +import androidx.collection.LruCache; import com.android.volley.toolbox.ImageLoader.ImageCache; diff --git a/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_Base.java b/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_Base.java index a4fd4a45a3..373be50222 100644 --- a/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_Base.java +++ b/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_Base.java @@ -17,7 +17,7 @@ import javax.inject.Inject; import javax.inject.Named; -import static android.support.test.InstrumentationRegistry.getInstrumentation; +import static androidx.test.InstrumentationRegistry.getInstrumentation; /** * NOTE: diff --git a/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_FluxCImageLoaderTest.java b/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_FluxCImageLoaderTest.java index a28049a81c..3b22620dd6 100644 --- a/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_FluxCImageLoaderTest.java +++ b/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_FluxCImageLoaderTest.java @@ -26,7 +26,7 @@ import javax.inject.Inject; -import static android.support.test.InstrumentationRegistry.getInstrumentation; +import static androidx.test.InstrumentationRegistry.getInstrumentation; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; diff --git a/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_MediaTestWPCom.java b/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_MediaTestWPCom.java index 14fd8cdf71..6a5027f760 100644 --- a/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_MediaTestWPCom.java +++ b/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_MediaTestWPCom.java @@ -1,8 +1,9 @@ package org.wordpress.android.fluxc.release; import android.annotation.SuppressLint; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.RandomStringUtils; diff --git a/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_PluginTestJetpack.java b/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_PluginTestJetpack.java index 8d874744b0..71f0ba5bfc 100644 --- a/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_PluginTestJetpack.java +++ b/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_PluginTestJetpack.java @@ -1,8 +1,9 @@ package org.wordpress.android.fluxc.release; -import android.support.annotation.NonNull; import android.text.TextUtils; +import androidx.annotation.NonNull; + import junit.framework.Assert; import org.greenrobot.eventbus.Subscribe; diff --git a/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_PostListTestWpCom.kt b/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_PostListTestWpCom.kt index 9c4193b903..2542742e64 100644 --- a/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_PostListTestWpCom.kt +++ b/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_PostListTestWpCom.kt @@ -1,6 +1,6 @@ package org.wordpress.android.fluxc.release -import android.arch.core.executor.testing.InstantTaskExecutorRule +import androidx.arch.core.executor.testing.InstantTaskExecutorRule import org.junit.Ignore import org.junit.Rule import org.junit.Test diff --git a/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_PostListTestXMLRPC.kt b/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_PostListTestXMLRPC.kt index cd2cef3cfb..ac3c82c3ce 100644 --- a/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_PostListTestXMLRPC.kt +++ b/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_PostListTestXMLRPC.kt @@ -1,6 +1,6 @@ package org.wordpress.android.fluxc.release -import android.arch.core.executor.testing.InstantTaskExecutorRule +import androidx.arch.core.executor.testing.InstantTaskExecutorRule import org.junit.Ignore import org.junit.Rule import org.junit.Test diff --git a/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_PostTestWPCom.java b/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_PostTestWPCom.java index e1e3c93177..ba00640eb8 100644 --- a/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_PostTestWPCom.java +++ b/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_PostTestWPCom.java @@ -43,6 +43,7 @@ public class ReleaseStack_PostTestWPCom extends ReleaseStack_WPComBase { @Inject PostStore mPostStore; + @Inject PostSqlUtils mPostSqlUtils; private static final String POST_DEFAULT_TITLE = "PostTestWPCom base post"; private static final String POST_DEFAULT_DESCRIPTION = "Hi there, I'm a post from FluxC!"; @@ -93,7 +94,7 @@ public void testRemoveLocalDraft() throws InterruptedException { mDispatcher.dispatch(PostActionBuilder.newRemovePostAction(post)); assertTrue(mCountDownLatch.await(TestUtils.DEFAULT_TIMEOUT_MS, TimeUnit.MILLISECONDS)); - assertEquals(0, PostSqlUtils.getPostsForSite(sSite, false).size()); + assertEquals(0, mPostSqlUtils.getPostsForSite(sSite, false).size()); } @Test diff --git a/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_ReaderTest.java b/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_ReaderTest.java index a5d759a744..e5ee72b3e8 100644 --- a/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_ReaderTest.java +++ b/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_ReaderTest.java @@ -1,6 +1,6 @@ package org.wordpress.android.fluxc.release; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import org.greenrobot.eventbus.Subscribe; import org.junit.Test; diff --git a/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_StockMediaTest.java b/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_StockMediaTest.java index 1fe1f16515..a283004e07 100644 --- a/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_StockMediaTest.java +++ b/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_StockMediaTest.java @@ -1,6 +1,6 @@ package org.wordpress.android.fluxc.release; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import org.greenrobot.eventbus.Subscribe; import org.junit.Test; @@ -21,8 +21,7 @@ import static junit.framework.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static org.wordpress.android.fluxc.network.rest.wpcom.stockmedia.StockMediaRestClient - .DEFAULT_NUM_STOCK_MEDIA_PER_FETCH; +import static org.wordpress.android.fluxc.network.rest.wpcom.stockmedia.StockMediaRestClient.DEFAULT_NUM_STOCK_MEDIA_PER_FETCH; public class ReleaseStack_StockMediaTest extends ReleaseStack_WPComBase { @Inject StockMediaStore mStockMediaStore; diff --git a/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_ThemeTestJetpack.java b/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_ThemeTestJetpack.java index 6a247d3df2..6e0a2dcf64 100644 --- a/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_ThemeTestJetpack.java +++ b/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_ThemeTestJetpack.java @@ -1,6 +1,6 @@ package org.wordpress.android.fluxc.release; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; diff --git a/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_WPComBase.java b/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_WPComBase.java index 50040aee36..e89193846c 100644 --- a/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_WPComBase.java +++ b/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_WPComBase.java @@ -25,7 +25,7 @@ import javax.inject.Inject; -import static android.support.test.InstrumentationRegistry.getInstrumentation; +import static androidx.test.InstrumentationRegistry.getInstrumentation; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; diff --git a/example/src/androidTest/java/org/wordpress/android/fluxc/release/utils/ListStoreConnectedTestHelper.kt b/example/src/androidTest/java/org/wordpress/android/fluxc/release/utils/ListStoreConnectedTestHelper.kt index cc4e130596..cd415dc5e6 100644 --- a/example/src/androidTest/java/org/wordpress/android/fluxc/release/utils/ListStoreConnectedTestHelper.kt +++ b/example/src/androidTest/java/org/wordpress/android/fluxc/release/utils/ListStoreConnectedTestHelper.kt @@ -1,6 +1,6 @@ package org.wordpress.android.fluxc.release.utils -import android.arch.lifecycle.Lifecycle +import androidx.lifecycle.Lifecycle import org.wordpress.android.fluxc.model.list.ListDescriptor import org.wordpress.android.fluxc.model.list.PagedListWrapper import org.wordpress.android.fluxc.model.list.datasource.ListItemDataSourceInterface diff --git a/example/src/androidTest/java/org/wordpress/android/fluxc/release/utils/LiveDataTextExtensions.kt b/example/src/androidTest/java/org/wordpress/android/fluxc/release/utils/LiveDataTextExtensions.kt index 665300510f..4ee4890aa9 100644 --- a/example/src/androidTest/java/org/wordpress/android/fluxc/release/utils/LiveDataTextExtensions.kt +++ b/example/src/androidTest/java/org/wordpress/android/fluxc/release/utils/LiveDataTextExtensions.kt @@ -1,8 +1,8 @@ package org.wordpress.android.fluxc.release.utils -import android.arch.lifecycle.LiveData -import android.arch.lifecycle.MediatorLiveData -import android.arch.lifecycle.Observer +import androidx.lifecycle.LiveData +import androidx.lifecycle.MediatorLiveData +import androidx.lifecycle.Observer import org.junit.Assert.assertEquals /** diff --git a/example/src/androidTest/java/org/wordpress/android/fluxc/release/utils/PagedListWrapperTestExtensions.kt b/example/src/androidTest/java/org/wordpress/android/fluxc/release/utils/PagedListWrapperTestExtensions.kt index dc499dd496..3dfca762b0 100644 --- a/example/src/androidTest/java/org/wordpress/android/fluxc/release/utils/PagedListWrapperTestExtensions.kt +++ b/example/src/androidTest/java/org/wordpress/android/fluxc/release/utils/PagedListWrapperTestExtensions.kt @@ -1,6 +1,6 @@ package org.wordpress.android.fluxc.release.utils -import android.arch.lifecycle.Observer +import androidx.lifecycle.Observer import org.junit.Assert.assertTrue import org.wordpress.android.fluxc.TestUtils import org.wordpress.android.fluxc.model.list.PagedListWrapper diff --git a/example/src/androidTest/java/org/wordpress/android/fluxc/release/utils/SimpleTestLifecycle.kt b/example/src/androidTest/java/org/wordpress/android/fluxc/release/utils/SimpleTestLifecycle.kt index e47efd56de..bc76b5dd1c 100644 --- a/example/src/androidTest/java/org/wordpress/android/fluxc/release/utils/SimpleTestLifecycle.kt +++ b/example/src/androidTest/java/org/wordpress/android/fluxc/release/utils/SimpleTestLifecycle.kt @@ -1,8 +1,8 @@ package org.wordpress.android.fluxc.release.utils -import android.arch.lifecycle.Lifecycle -import android.arch.lifecycle.LifecycleOwner -import android.arch.lifecycle.LifecycleRegistry +import androidx.lifecycle.Lifecycle +import androidx.lifecycle.LifecycleOwner +import androidx.lifecycle.LifecycleRegistry /** * A simple helper [LifecycleOwner] implementation to be used in tests. diff --git a/example/src/main/java/org/wordpress/android/fluxc/example/AccountFragment.kt b/example/src/main/java/org/wordpress/android/fluxc/example/AccountFragment.kt index 70d197c82e..333957fc0c 100644 --- a/example/src/main/java/org/wordpress/android/fluxc/example/AccountFragment.kt +++ b/example/src/main/java/org/wordpress/android/fluxc/example/AccountFragment.kt @@ -3,11 +3,11 @@ package org.wordpress.android.fluxc.example import android.app.AlertDialog import android.content.Context import android.os.Bundle -import android.support.v4.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.EditText +import androidx.fragment.app.Fragment import dagger.android.support.AndroidSupportInjection import kotlinx.android.synthetic.main.fragment_account.* import org.greenrobot.eventbus.Subscribe diff --git a/example/src/main/java/org/wordpress/android/fluxc/example/CommentsFragment.java b/example/src/main/java/org/wordpress/android/fluxc/example/CommentsFragment.java index 2e16abcf46..2acc2ee1c8 100644 --- a/example/src/main/java/org/wordpress/android/fluxc/example/CommentsFragment.java +++ b/example/src/main/java/org/wordpress/android/fluxc/example/CommentsFragment.java @@ -2,13 +2,14 @@ import android.content.Context; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; +import androidx.annotation.NonNull; +import androidx.fragment.app.Fragment; + import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; import org.wordpress.android.fluxc.Dispatcher; diff --git a/example/src/main/java/org/wordpress/android/fluxc/example/CustomStatsDialog.kt b/example/src/main/java/org/wordpress/android/fluxc/example/CustomStatsDialog.kt index a2ae0c61f2..50c0c1eb0c 100644 --- a/example/src/main/java/org/wordpress/android/fluxc/example/CustomStatsDialog.kt +++ b/example/src/main/java/org/wordpress/android/fluxc/example/CustomStatsDialog.kt @@ -3,14 +3,14 @@ package org.wordpress.android.fluxc.example import android.R.layout import android.app.DatePickerDialog import android.os.Bundle -import android.support.v4.app.DialogFragment -import android.support.v4.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.view.WindowManager import android.widget.ArrayAdapter import android.widget.Button +import androidx.fragment.app.DialogFragment +import androidx.fragment.app.Fragment import kotlinx.android.synthetic.main.dialog_custom_stats.* import org.wordpress.android.fluxc.store.WCStatsStore.StatsGranularity import org.wordpress.android.fluxc.utils.DateUtils diff --git a/example/src/main/java/org/wordpress/android/fluxc/example/FragmentExt.kt b/example/src/main/java/org/wordpress/android/fluxc/example/FragmentExt.kt index 99058900a3..099ca65710 100644 --- a/example/src/main/java/org/wordpress/android/fluxc/example/FragmentExt.kt +++ b/example/src/main/java/org/wordpress/android/fluxc/example/FragmentExt.kt @@ -1,7 +1,7 @@ @file:JvmName("FragmentExtensions") package org.wordpress.android.fluxc.example -import android.support.v4.app.Fragment +import androidx.fragment.app.Fragment /** * Shortcut for appending messages to the log in MainActivity diff --git a/example/src/main/java/org/wordpress/android/fluxc/example/MainExampleActivity.kt b/example/src/main/java/org/wordpress/android/fluxc/example/MainExampleActivity.kt index ae5e24817d..0b3530a95b 100644 --- a/example/src/main/java/org/wordpress/android/fluxc/example/MainExampleActivity.kt +++ b/example/src/main/java/org/wordpress/android/fluxc/example/MainExampleActivity.kt @@ -1,9 +1,9 @@ package org.wordpress.android.fluxc.example import android.os.Bundle -import android.support.v4.app.Fragment -import android.support.v4.app.FragmentActivity import android.text.method.ScrollingMovementMethod +import androidx.fragment.app.Fragment +import androidx.fragment.app.FragmentActivity import dagger.android.AndroidInjection import dagger.android.AndroidInjector import dagger.android.DispatchingAndroidInjector diff --git a/example/src/main/java/org/wordpress/android/fluxc/example/MainFragment.kt b/example/src/main/java/org/wordpress/android/fluxc/example/MainFragment.kt index b629297c33..77918d8154 100644 --- a/example/src/main/java/org/wordpress/android/fluxc/example/MainFragment.kt +++ b/example/src/main/java/org/wordpress/android/fluxc/example/MainFragment.kt @@ -2,12 +2,12 @@ package org.wordpress.android.fluxc.example import android.content.Context import android.os.Bundle -import android.support.v4.app.Fragment import android.text.TextUtils import android.view.LayoutInflater import android.view.View import android.view.View.OnClickListener import android.view.ViewGroup +import androidx.fragment.app.Fragment import dagger.android.support.AndroidSupportInjection import kotlinx.android.synthetic.main.fragment_main.* import org.greenrobot.eventbus.Subscribe diff --git a/example/src/main/java/org/wordpress/android/fluxc/example/MediaFragment.java b/example/src/main/java/org/wordpress/android/fluxc/example/MediaFragment.java index 995dee8405..0333276e57 100644 --- a/example/src/main/java/org/wordpress/android/fluxc/example/MediaFragment.java +++ b/example/src/main/java/org/wordpress/android/fluxc/example/MediaFragment.java @@ -5,8 +5,6 @@ import android.database.Cursor; import android.net.Uri; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.v4.app.Fragment; import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; @@ -15,6 +13,9 @@ import android.widget.Spinner; import android.widget.TextView; +import androidx.annotation.NonNull; +import androidx.fragment.app.Fragment; + import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; import org.wordpress.android.fluxc.Dispatcher; diff --git a/example/src/main/java/org/wordpress/android/fluxc/example/NotificationTypeSubtypeDialog.kt b/example/src/main/java/org/wordpress/android/fluxc/example/NotificationTypeSubtypeDialog.kt index 03291dafe7..962159231f 100644 --- a/example/src/main/java/org/wordpress/android/fluxc/example/NotificationTypeSubtypeDialog.kt +++ b/example/src/main/java/org/wordpress/android/fluxc/example/NotificationTypeSubtypeDialog.kt @@ -1,12 +1,12 @@ package org.wordpress.android.fluxc.example import android.os.Bundle -import android.support.v4.app.DialogFragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.view.WindowManager import android.widget.ArrayAdapter +import androidx.fragment.app.DialogFragment import kotlinx.android.synthetic.main.dialog_notification_type_subtype.* import org.wordpress.android.fluxc.model.notification.NotificationModel.Kind import org.wordpress.android.fluxc.model.notification.NotificationModel.Subkind diff --git a/example/src/main/java/org/wordpress/android/fluxc/example/NotificationsFragment.kt b/example/src/main/java/org/wordpress/android/fluxc/example/NotificationsFragment.kt index fcf55e4e57..21d71f1d47 100644 --- a/example/src/main/java/org/wordpress/android/fluxc/example/NotificationsFragment.kt +++ b/example/src/main/java/org/wordpress/android/fluxc/example/NotificationsFragment.kt @@ -2,10 +2,10 @@ package org.wordpress.android.fluxc.example import android.content.Context import android.os.Bundle -import android.support.v4.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.fragment.app.Fragment import dagger.android.support.AndroidSupportInjection import kotlinx.android.synthetic.main.fragment_notifications.* import org.greenrobot.eventbus.Subscribe @@ -13,8 +13,8 @@ import org.greenrobot.eventbus.ThreadMode.MAIN import org.wordpress.android.fluxc.Dispatcher import org.wordpress.android.fluxc.action.NotificationAction.FETCH_NOTIFICATION import org.wordpress.android.fluxc.action.NotificationAction.FETCH_NOTIFICATIONS -import org.wordpress.android.fluxc.action.NotificationAction.MARK_NOTIFICATIONS_SEEN import org.wordpress.android.fluxc.action.NotificationAction.MARK_NOTIFICATIONS_READ +import org.wordpress.android.fluxc.action.NotificationAction.MARK_NOTIFICATIONS_SEEN import org.wordpress.android.fluxc.action.NotificationAction.UPDATE_NOTIFICATION import org.wordpress.android.fluxc.example.NotificationTypeSubtypeDialog.Listener import org.wordpress.android.fluxc.generated.NotificationActionBuilder diff --git a/example/src/main/java/org/wordpress/android/fluxc/example/PostsFragment.kt b/example/src/main/java/org/wordpress/android/fluxc/example/PostsFragment.kt index 66e64b2758..4d874ce129 100644 --- a/example/src/main/java/org/wordpress/android/fluxc/example/PostsFragment.kt +++ b/example/src/main/java/org/wordpress/android/fluxc/example/PostsFragment.kt @@ -2,10 +2,10 @@ package org.wordpress.android.fluxc.example import android.content.Context import android.os.Bundle -import android.support.v4.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.fragment.app.Fragment import dagger.android.support.AndroidSupportInjection import kotlinx.android.synthetic.main.fragment_posts.* import org.greenrobot.eventbus.Subscribe diff --git a/example/src/main/java/org/wordpress/android/fluxc/example/SSLWarningDialog.java b/example/src/main/java/org/wordpress/android/fluxc/example/SSLWarningDialog.java index 5e14370843..af3714b6fe 100644 --- a/example/src/main/java/org/wordpress/android/fluxc/example/SSLWarningDialog.java +++ b/example/src/main/java/org/wordpress/android/fluxc/example/SSLWarningDialog.java @@ -4,13 +4,14 @@ import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.v4.app.DialogFragment; -import android.support.v7.app.AlertDialog; import android.view.LayoutInflater; import android.view.View; import android.widget.TextView; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AlertDialog; +import androidx.fragment.app.DialogFragment; + public class SSLWarningDialog extends DialogFragment { public interface Listener { void onClick(String username, String password, String url); diff --git a/example/src/main/java/org/wordpress/android/fluxc/example/SignedOutActionsFragment.java b/example/src/main/java/org/wordpress/android/fluxc/example/SignedOutActionsFragment.java index b535f27978..f6630b0bd1 100644 --- a/example/src/main/java/org/wordpress/android/fluxc/example/SignedOutActionsFragment.java +++ b/example/src/main/java/org/wordpress/android/fluxc/example/SignedOutActionsFragment.java @@ -4,16 +4,17 @@ import android.content.Context; import android.content.DialogInterface; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.v4.app.DialogFragment; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentTransaction; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.EditText; +import androidx.annotation.NonNull; +import androidx.fragment.app.DialogFragment; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentTransaction; + import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; import org.wordpress.android.fluxc.Dispatcher; diff --git a/example/src/main/java/org/wordpress/android/fluxc/example/SiteSelectorDialog.kt b/example/src/main/java/org/wordpress/android/fluxc/example/SiteSelectorDialog.kt index 70d5158493..9fdc9e6007 100644 --- a/example/src/main/java/org/wordpress/android/fluxc/example/SiteSelectorDialog.kt +++ b/example/src/main/java/org/wordpress/android/fluxc/example/SiteSelectorDialog.kt @@ -4,12 +4,12 @@ import android.app.AlertDialog import android.app.Dialog import android.content.Context import android.os.Bundle -import android.support.v4.app.DialogFragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.ArrayAdapter import android.widget.TextView +import androidx.fragment.app.DialogFragment import dagger.android.support.AndroidSupportInjection import org.greenrobot.eventbus.Subscribe import org.greenrobot.eventbus.ThreadMode diff --git a/example/src/main/java/org/wordpress/android/fluxc/example/SitesFragment.java b/example/src/main/java/org/wordpress/android/fluxc/example/SitesFragment.java index 132687a001..8cf190e37a 100644 --- a/example/src/main/java/org/wordpress/android/fluxc/example/SitesFragment.java +++ b/example/src/main/java/org/wordpress/android/fluxc/example/SitesFragment.java @@ -2,14 +2,15 @@ import android.content.Context; import android.os.Bundle; -import android.support.v4.app.DialogFragment; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentTransaction; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; +import androidx.fragment.app.DialogFragment; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentTransaction; + import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; import org.wordpress.android.fluxc.Dispatcher; diff --git a/example/src/main/java/org/wordpress/android/fluxc/example/TaxonomiesFragment.java b/example/src/main/java/org/wordpress/android/fluxc/example/TaxonomiesFragment.java index 681d7bdb4b..b26ac7ecf1 100644 --- a/example/src/main/java/org/wordpress/android/fluxc/example/TaxonomiesFragment.java +++ b/example/src/main/java/org/wordpress/android/fluxc/example/TaxonomiesFragment.java @@ -2,12 +2,13 @@ import android.content.Context; import android.os.Bundle; -import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; +import androidx.fragment.app.Fragment; + import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; import org.wordpress.android.fluxc.Dispatcher; diff --git a/example/src/main/java/org/wordpress/android/fluxc/example/ThemeFragment.kt b/example/src/main/java/org/wordpress/android/fluxc/example/ThemeFragment.kt index 457ae4eccd..ae34b3419b 100644 --- a/example/src/main/java/org/wordpress/android/fluxc/example/ThemeFragment.kt +++ b/example/src/main/java/org/wordpress/android/fluxc/example/ThemeFragment.kt @@ -2,12 +2,12 @@ package org.wordpress.android.fluxc.example import android.content.Context import android.os.Bundle -import android.support.v4.app.Fragment import android.text.TextUtils import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.TextView +import androidx.fragment.app.Fragment import dagger.android.support.AndroidSupportInjection import kotlinx.android.synthetic.main.fragment_themes.* import org.greenrobot.eventbus.Subscribe diff --git a/example/src/main/java/org/wordpress/android/fluxc/example/ThreeEditTextDialog.kt b/example/src/main/java/org/wordpress/android/fluxc/example/ThreeEditTextDialog.kt index 2eab7d22ce..804a24d1ad 100644 --- a/example/src/main/java/org/wordpress/android/fluxc/example/ThreeEditTextDialog.kt +++ b/example/src/main/java/org/wordpress/android/fluxc/example/ThreeEditTextDialog.kt @@ -2,11 +2,11 @@ package org.wordpress.android.fluxc.example import android.app.Dialog import android.os.Bundle -import android.support.v4.app.DialogFragment -import android.support.v7.app.AlertDialog import android.text.TextUtils import android.view.View import android.widget.EditText +import androidx.appcompat.app.AlertDialog +import androidx.fragment.app.DialogFragment class ThreeEditTextDialog : DialogFragment() { private lateinit var editText1: EditText diff --git a/example/src/main/java/org/wordpress/android/fluxc/example/UploadsFragment.java b/example/src/main/java/org/wordpress/android/fluxc/example/UploadsFragment.java index a85e5c1d0e..e4cf6b99a8 100644 --- a/example/src/main/java/org/wordpress/android/fluxc/example/UploadsFragment.java +++ b/example/src/main/java/org/wordpress/android/fluxc/example/UploadsFragment.java @@ -5,13 +5,14 @@ import android.database.Cursor; import android.net.Uri; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.v4.app.Fragment; import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import androidx.annotation.NonNull; +import androidx.fragment.app.Fragment; + import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; import org.wordpress.android.fluxc.Dispatcher; diff --git a/example/src/main/java/org/wordpress/android/fluxc/example/WCAddOrderShipmentTrackingDialog.kt b/example/src/main/java/org/wordpress/android/fluxc/example/WCAddOrderShipmentTrackingDialog.kt index 5581fc6a34..30fe112efa 100644 --- a/example/src/main/java/org/wordpress/android/fluxc/example/WCAddOrderShipmentTrackingDialog.kt +++ b/example/src/main/java/org/wordpress/android/fluxc/example/WCAddOrderShipmentTrackingDialog.kt @@ -3,8 +3,6 @@ package org.wordpress.android.fluxc.example import android.R.layout import android.app.DatePickerDialog import android.os.Bundle -import android.support.v4.app.DialogFragment -import android.support.v4.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -12,6 +10,8 @@ import android.view.WindowManager import android.widget.AdapterView import android.widget.ArrayAdapter import android.widget.Button +import androidx.fragment.app.DialogFragment +import androidx.fragment.app.Fragment import kotlinx.android.synthetic.main.dialog_wc_add_order_shipment_tracking.* import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.WCOrderModel diff --git a/example/src/main/java/org/wordpress/android/fluxc/example/di/AppComponent.kt b/example/src/main/java/org/wordpress/android/fluxc/example/di/AppComponent.kt index 45ad1784b9..e0ad17b328 100644 --- a/example/src/main/java/org/wordpress/android/fluxc/example/di/AppComponent.kt +++ b/example/src/main/java/org/wordpress/android/fluxc/example/di/AppComponent.kt @@ -4,7 +4,7 @@ import android.app.Application import dagger.BindsInstance import dagger.Component import dagger.android.AndroidInjector -import dagger.android.support.AndroidSupportInjectionModule +import dagger.android.AndroidInjectionModule import org.wordpress.android.fluxc.example.ExampleApp import org.wordpress.android.fluxc.module.ReleaseBaseModule import org.wordpress.android.fluxc.module.ReleaseNetworkModule @@ -14,7 +14,7 @@ import javax.inject.Singleton @Singleton @Component(modules = arrayOf( - AndroidSupportInjectionModule::class, + AndroidInjectionModule::class, ApplicationModule::class, AppConfigModule::class, ReleaseOkHttpClientModule::class, diff --git a/example/src/main/java/org/wordpress/android/fluxc/example/ui/WooCommerceFragment.kt b/example/src/main/java/org/wordpress/android/fluxc/example/ui/WooCommerceFragment.kt index d2f542f44d..aa3b6d107f 100644 --- a/example/src/main/java/org/wordpress/android/fluxc/example/ui/WooCommerceFragment.kt +++ b/example/src/main/java/org/wordpress/android/fluxc/example/ui/WooCommerceFragment.kt @@ -2,10 +2,10 @@ package org.wordpress.android.fluxc.example.ui import android.content.Context import android.os.Bundle -import android.support.v4.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.fragment.app.Fragment import dagger.android.support.AndroidSupportInjection import kotlinx.android.synthetic.main.fragment_woocommerce.* import org.greenrobot.eventbus.Subscribe diff --git a/example/src/main/java/org/wordpress/android/fluxc/example/ui/orders/WooOrdersFragment.kt b/example/src/main/java/org/wordpress/android/fluxc/example/ui/orders/WooOrdersFragment.kt index ed5407c915..c8fb504273 100644 --- a/example/src/main/java/org/wordpress/android/fluxc/example/ui/orders/WooOrdersFragment.kt +++ b/example/src/main/java/org/wordpress/android/fluxc/example/ui/orders/WooOrdersFragment.kt @@ -2,10 +2,10 @@ package org.wordpress.android.fluxc.example.ui.orders import android.content.Context import android.os.Bundle -import android.support.v4.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.fragment.app.Fragment import dagger.android.support.AndroidSupportInjection import kotlinx.android.synthetic.main.fragment_woo_orders.* import org.greenrobot.eventbus.Subscribe diff --git a/example/src/main/java/org/wordpress/android/fluxc/example/ui/products/WooProductsFragment.kt b/example/src/main/java/org/wordpress/android/fluxc/example/ui/products/WooProductsFragment.kt index 481532d2d5..08851d02a9 100644 --- a/example/src/main/java/org/wordpress/android/fluxc/example/ui/products/WooProductsFragment.kt +++ b/example/src/main/java/org/wordpress/android/fluxc/example/ui/products/WooProductsFragment.kt @@ -2,10 +2,10 @@ package org.wordpress.android.fluxc.example.ui.products import android.content.Context import android.os.Bundle -import android.support.v4.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.fragment.app.Fragment import dagger.android.support.AndroidSupportInjection import kotlinx.android.synthetic.main.fragment_woo_products.* import org.greenrobot.eventbus.Subscribe diff --git a/example/src/main/java/org/wordpress/android/fluxc/example/ui/stats/WooStatsFragment.kt b/example/src/main/java/org/wordpress/android/fluxc/example/ui/stats/WooStatsFragment.kt index 69d7ee6bae..ac08639dd4 100644 --- a/example/src/main/java/org/wordpress/android/fluxc/example/ui/stats/WooStatsFragment.kt +++ b/example/src/main/java/org/wordpress/android/fluxc/example/ui/stats/WooStatsFragment.kt @@ -2,10 +2,10 @@ package org.wordpress.android.fluxc.example.ui.stats import android.content.Context import android.os.Bundle -import android.support.v4.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.fragment.app.Fragment import dagger.android.support.AndroidSupportInjection import kotlinx.android.synthetic.main.fragment_woo_stats.* import org.greenrobot.eventbus.Subscribe diff --git a/example/src/main/java/org/wordpress/android/fluxc/example/utils/AlertDialogUtils.kt b/example/src/main/java/org/wordpress/android/fluxc/example/utils/AlertDialogUtils.kt index ec1e39a9f0..3b20cb1348 100644 --- a/example/src/main/java/org/wordpress/android/fluxc/example/utils/AlertDialogUtils.kt +++ b/example/src/main/java/org/wordpress/android/fluxc/example/utils/AlertDialogUtils.kt @@ -1,8 +1,8 @@ package org.wordpress.android.fluxc.example.utils -import android.support.v4.app.FragmentActivity -import android.support.v7.app.AlertDialog import android.widget.EditText +import androidx.appcompat.app.AlertDialog +import androidx.fragment.app.FragmentActivity typealias AlertTextListener = (EditText) -> Unit diff --git a/example/src/main/res/layout/dialog_custom_stats.xml b/example/src/main/res/layout/dialog_custom_stats.xml index 7160737a8a..2101ae7173 100644 --- a/example/src/main/res/layout/dialog_custom_stats.xml +++ b/example/src/main/res/layout/dialog_custom_stats.xml @@ -7,7 +7,7 @@ android:layout_height="match_parent" tools:context="org.wordpress.android.fluxc.example.CustomStatsDialog"> - - + diff --git a/example/src/main/res/layout/dialog_notification_type_subtype.xml b/example/src/main/res/layout/dialog_notification_type_subtype.xml index ba8ddfcd27..82d447256b 100644 --- a/example/src/main/res/layout/dialog_notification_type_subtype.xml +++ b/example/src/main/res/layout/dialog_notification_type_subtype.xml @@ -1,5 +1,5 @@ - - + diff --git a/example/src/main/res/layout/dialog_wc_add_order_shipment_tracking.xml b/example/src/main/res/layout/dialog_wc_add_order_shipment_tracking.xml index 552bea8983..835be6c996 100644 --- a/example/src/main/res/layout/dialog_wc_add_order_shipment_tracking.xml +++ b/example/src/main/res/layout/dialog_wc_add_order_shipment_tracking.xml @@ -6,7 +6,7 @@ android:layout_height="match_parent" tools:context="org.wordpress.android.fluxc.example.WCAddOrderShipmentTrackingDialog"> - @@ -177,5 +177,5 @@ android:text="CANCEL" app:layout_constraintEnd_toStartOf="@+id/tracking_ok" app:layout_constraintTop_toBottomOf="@+id/tracking_dateShipped"/> - + diff --git a/example/src/test/java/org/wordpress/android/fluxc/list/PagedListFactoryTest.kt b/example/src/test/java/org/wordpress/android/fluxc/list/PagedListFactoryTest.kt index 887d16a33c..ecff9b2dc0 100644 --- a/example/src/test/java/org/wordpress/android/fluxc/list/PagedListFactoryTest.kt +++ b/example/src/test/java/org/wordpress/android/fluxc/list/PagedListFactoryTest.kt @@ -1,6 +1,6 @@ package org.wordpress.android.fluxc.list -import android.arch.paging.DataSource.InvalidatedCallback +import androidx.paging.DataSource.InvalidatedCallback import com.nhaarman.mockitokotlin2.mock import com.nhaarman.mockitokotlin2.times import com.nhaarman.mockitokotlin2.verify diff --git a/example/src/test/java/org/wordpress/android/fluxc/list/PagedListWrapperTest.kt b/example/src/test/java/org/wordpress/android/fluxc/list/PagedListWrapperTest.kt index 7e8d3e8d13..d7c5f176b5 100644 --- a/example/src/test/java/org/wordpress/android/fluxc/list/PagedListWrapperTest.kt +++ b/example/src/test/java/org/wordpress/android/fluxc/list/PagedListWrapperTest.kt @@ -1,11 +1,11 @@ package org.wordpress.android.fluxc.list -import android.arch.core.executor.testing.InstantTaskExecutorRule -import android.arch.lifecycle.Lifecycle -import android.arch.lifecycle.LifecycleRegistry -import android.arch.lifecycle.MutableLiveData -import android.arch.lifecycle.Observer -import android.arch.paging.PagedList +import androidx.arch.core.executor.testing.InstantTaskExecutorRule +import androidx.lifecycle.Lifecycle +import androidx.lifecycle.LifecycleRegistry +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.Observer +import androidx.paging.PagedList import com.nhaarman.mockitokotlin2.firstValue import com.nhaarman.mockitokotlin2.mock import com.nhaarman.mockitokotlin2.verify diff --git a/example/src/test/java/org/wordpress/android/fluxc/page/PageStoreLocalDraftTest.kt b/example/src/test/java/org/wordpress/android/fluxc/page/PageStoreLocalDraftTest.kt index 9eec26f83f..45a94c49da 100644 --- a/example/src/test/java/org/wordpress/android/fluxc/page/PageStoreLocalDraftTest.kt +++ b/example/src/test/java/org/wordpress/android/fluxc/page/PageStoreLocalDraftTest.kt @@ -21,7 +21,13 @@ import java.util.UUID @RunWith(RobolectricTestRunner::class) class PageStoreLocalDraftTest { - private val pageStore = PageStore(postStore = mock(), dispatcher = mock(), coroutineContext = Dispatchers.Default) + private val postSqlUtils = PostSqlUtils() + private val pageStore = PageStore( + postStore = mock(), + dispatcher = mock(), + coroutineContext = Dispatchers.Default, + postSqlUtils = postSqlUtils + ) @Before fun setUp() { @@ -62,7 +68,7 @@ class PageStoreLocalDraftTest { } ) - expectedPages.plus(unexpectedPosts).forEach { PostSqlUtils.insertPostForResult(it) } + expectedPages.plus(unexpectedPosts).forEach { postSqlUtils.insertPostForResult(it) } // Act val localDraftPages = pageStore.getLocalDraftPages(site) @@ -70,7 +76,7 @@ class PageStoreLocalDraftTest { // Assert assertThat(localDraftPages).hasSize(3) assertThat(localDraftPages).allMatch { it.title.startsWith(baseTitle) } - assertThat(localDraftPages.map { it.pageId }).isEqualTo(expectedPages.map { it.id }) + assertThat(localDraftPages.map { it.id }).isEqualTo(expectedPages.map { it.id }) } private fun createLocalDraft(localSiteId: Int, baseTitle: String = "Title") = PostModel().apply { diff --git a/example/src/test/java/org/wordpress/android/fluxc/page/PageStoreTest.kt b/example/src/test/java/org/wordpress/android/fluxc/page/PageStoreTest.kt index d4f80f83ab..8551b6eac9 100644 --- a/example/src/test/java/org/wordpress/android/fluxc/page/PageStoreTest.kt +++ b/example/src/test/java/org/wordpress/android/fluxc/page/PageStoreTest.kt @@ -31,6 +31,7 @@ import org.wordpress.android.fluxc.model.page.PageStatus.PUBLISHED import org.wordpress.android.fluxc.model.page.PageStatus.SCHEDULED import org.wordpress.android.fluxc.model.page.PageStatus.TRASHED import org.wordpress.android.fluxc.model.post.PostStatus +import org.wordpress.android.fluxc.persistence.PostSqlUtils import org.wordpress.android.fluxc.store.PageStore import org.wordpress.android.fluxc.store.PostStore import org.wordpress.android.fluxc.store.PostStore.FetchPostsPayload @@ -81,7 +82,7 @@ class PageStoreTest { actionCaptor = argumentCaptor() val pages = listOf(pageWithoutQuery, pageWithQuery, pageWithoutTitle) whenever(postStore.getPagesForSite(site)).thenReturn(pages) - store = PageStore(postStore, dispatcher, Dispatchers.Unconfined) + store = PageStore(postStore, PostSqlUtils(), dispatcher, Dispatchers.Unconfined) } @Test diff --git a/example/src/test/java/org/wordpress/android/fluxc/persistence/PostSqlUtilsTest.kt b/example/src/test/java/org/wordpress/android/fluxc/persistence/PostSqlUtilsTest.kt index 86013ea727..0358a7c4fc 100644 --- a/example/src/test/java/org/wordpress/android/fluxc/persistence/PostSqlUtilsTest.kt +++ b/example/src/test/java/org/wordpress/android/fluxc/persistence/PostSqlUtilsTest.kt @@ -16,6 +16,8 @@ import kotlin.test.assertNull @Config(manifest = Config.NONE) @RunWith(RobolectricTestRunner::class) class PostSqlUtilsTest { + private val postSqlUtils = PostSqlUtils() + @Before fun setUp() { val appContext = RuntimeEnvironment.application.applicationContext @@ -39,18 +41,18 @@ class PostSqlUtilsTest { post.localSiteId = site.id post.remotePostId = remotePostId - post = PostSqlUtils.insertPostForResult(post) + post = postSqlUtils.insertPostForResult(post) assertNull(post.autoSaveModified) assertNull(post.autoSavePreviewUrl) assertEquals(0, post.autoSaveRevisionId) - PostSqlUtils.updatePostsAutoSave( + postSqlUtils.updatePostsAutoSave( site, PostRemoteAutoSaveModel(revisionId, remotePostId, modifiedDate, previewUrl) ) - val postsForSite = PostSqlUtils.getPostsForSite(site, false) + val postsForSite = postSqlUtils.getPostsForSite(site, false) assertEquals(1, postsForSite.size) assertEquals(revisionId, postsForSite.first().autoSaveRevisionId) diff --git a/example/src/test/java/org/wordpress/android/fluxc/post/PostStoreUnitTest.java b/example/src/test/java/org/wordpress/android/fluxc/post/PostStoreDbIntegrationTest.java similarity index 84% rename from example/src/test/java/org/wordpress/android/fluxc/post/PostStoreUnitTest.java rename to example/src/test/java/org/wordpress/android/fluxc/post/PostStoreDbIntegrationTest.java index 60dd7cc41f..b1cccac32c 100644 --- a/example/src/test/java/org/wordpress/android/fluxc/post/PostStoreUnitTest.java +++ b/example/src/test/java/org/wordpress/android/fluxc/post/PostStoreDbIntegrationTest.java @@ -43,9 +43,10 @@ import static org.junit.Assert.assertNotEquals; @RunWith(RobolectricTestRunner.class) -public class PostStoreUnitTest { +public class PostStoreDbIntegrationTest { + private PostSqlUtils mPostSqlUtils = new PostSqlUtils(); private PostStore mPostStore = new PostStore(new Dispatcher(), Mockito.mock(PostRestClient.class), - Mockito.mock(PostXMLRPCClient.class)); + Mockito.mock(PostXMLRPCClient.class), mPostSqlUtils); @Before public void setUp() { @@ -63,7 +64,7 @@ public void setUp() { @Test public void testInsertNullPost() { - assertEquals(0, PostSqlUtils.insertOrUpdatePostOverwritingLocalChanges(null)); + assertEquals(0, mPostSqlUtils.insertOrUpdatePostOverwritingLocalChanges(null)); assertEquals(0, PostTestUtils.getPostsCount()); } @@ -72,7 +73,7 @@ public void testInsertNullPost() { public void testSimpleInsertionAndRetrieval() { PostModel postModel = new PostModel(); postModel.setRemotePostId(42); - PostModel result = PostSqlUtils.insertPostForResult(postModel); + PostModel result = mPostSqlUtils.insertPostForResult(postModel); assertEquals(1, PostTestUtils.getPostsCount()); assertEquals(42, PostTestUtils.getPosts().get(0).getRemotePostId()); @@ -83,15 +84,15 @@ public void testSimpleInsertionAndRetrieval() { public void testInsertWithLocalChanges() { PostModel postModel = PostTestUtils.generateSampleUploadedPost(); postModel.setIsLocallyChanged(true); - PostSqlUtils.insertPostForResult(postModel); + mPostSqlUtils.insertPostForResult(postModel); String newTitle = "A different title"; postModel.setTitle(newTitle); - assertEquals(0, PostSqlUtils.insertOrUpdatePostKeepingLocalChanges(postModel)); + assertEquals(0, mPostSqlUtils.insertOrUpdatePostKeepingLocalChanges(postModel)); assertEquals("A test post", PostTestUtils.getPosts().get(0).getTitle()); - assertEquals(1, PostSqlUtils.insertOrUpdatePostOverwritingLocalChanges(postModel)); + assertEquals(1, mPostSqlUtils.insertOrUpdatePostOverwritingLocalChanges(postModel)); assertEquals(newTitle, PostTestUtils.getPosts().get(0).getTitle()); } @@ -100,7 +101,7 @@ public void testPushAndFetchCollision() throws InterruptedException { // Test uploading a post, fetching remote posts and updating the db from the fetch first PostModel postModel = PostTestUtils.generateSampleLocalDraftPost(); - PostSqlUtils.insertPostForResult(postModel); + mPostSqlUtils.insertPostForResult(postModel); // The post after uploading, updated with the remote post ID, about to be saved locally PostModel postFromUploadResponse = PostTestUtils.getPosts().get(0); @@ -111,8 +112,8 @@ public void testPushAndFetchCollision() throws InterruptedException { final PostModel postFromPostListFetch = postFromUploadResponse.clone(); postFromPostListFetch.setId(0); - PostSqlUtils.insertOrUpdatePostOverwritingLocalChanges(postFromPostListFetch); - PostSqlUtils.insertOrUpdatePostOverwritingLocalChanges(postFromUploadResponse); + mPostSqlUtils.insertOrUpdatePostOverwritingLocalChanges(postFromPostListFetch); + mPostSqlUtils.insertOrUpdatePostOverwritingLocalChanges(postFromUploadResponse); assertEquals(1, PostTestUtils.getPosts().size()); @@ -124,29 +125,29 @@ public void testPushAndFetchCollision() throws InterruptedException { @Test public void testInsertWithoutLocalChanges() { PostModel postModel = PostTestUtils.generateSampleUploadedPost(); - PostSqlUtils.insertPostForResult(postModel); + mPostSqlUtils.insertPostForResult(postModel); String newTitle = "A different title"; postModel.setTitle(newTitle); - assertEquals(1, PostSqlUtils.insertOrUpdatePostKeepingLocalChanges(postModel)); + assertEquals(1, mPostSqlUtils.insertOrUpdatePostKeepingLocalChanges(postModel)); assertEquals(newTitle, PostTestUtils.getPosts().get(0).getTitle()); newTitle = "Another different title"; postModel.setTitle(newTitle); - assertEquals(1, PostSqlUtils.insertOrUpdatePostOverwritingLocalChanges(postModel)); + assertEquals(1, mPostSqlUtils.insertOrUpdatePostOverwritingLocalChanges(postModel)); assertEquals(newTitle, PostTestUtils.getPosts().get(0).getTitle()); } @Test public void testGetPostsForSite() { PostModel uploadedPost1 = PostTestUtils.generateSampleUploadedPost(); - PostSqlUtils.insertPostForResult(uploadedPost1); + mPostSqlUtils.insertPostForResult(uploadedPost1); PostModel uploadedPost2 = PostTestUtils.generateSampleUploadedPost(); uploadedPost2.setLocalSiteId(8); - PostSqlUtils.insertPostForResult(uploadedPost2); + mPostSqlUtils.insertPostForResult(uploadedPost2); SiteModel site1 = new SiteModel(); site1.setId(uploadedPost1.getLocalSiteId()); @@ -165,9 +166,9 @@ public void testGetPostsWithFormatForSite() { PostModel textPost = PostTestUtils.generateSampleUploadedPost(); PostModel imagePost = PostTestUtils.generateSampleUploadedPost("image"); PostModel videoPost = PostTestUtils.generateSampleUploadedPost("video"); - PostSqlUtils.insertPostForResult(textPost); - PostSqlUtils.insertPostForResult(imagePost); - PostSqlUtils.insertPostForResult(videoPost); + mPostSqlUtils.insertPostForResult(textPost); + mPostSqlUtils.insertPostForResult(imagePost); + mPostSqlUtils.insertPostForResult(videoPost); SiteModel site = new SiteModel(); site.setId(textPost.getLocalSiteId()); @@ -189,10 +190,10 @@ public void testGetPublishedPosts() { site.setId(6); PostModel uploadedPost = PostTestUtils.generateSampleUploadedPost(); - PostSqlUtils.insertPostForResult(uploadedPost); + mPostSqlUtils.insertPostForResult(uploadedPost); PostModel localDraft = PostTestUtils.generateSampleLocalDraftPost(); - PostSqlUtils.insertPostForResult(localDraft); + mPostSqlUtils.insertPostForResult(localDraft); assertEquals(2, PostTestUtils.getPostsCount()); assertEquals(2, mPostStore.getPostsCountForSite(site)); @@ -203,7 +204,7 @@ public void testGetPublishedPosts() { @Test public void testGetPostByLocalId() { PostModel post = PostTestUtils.generateSampleLocalDraftPost(); - PostSqlUtils.insertPostForResult(post); + mPostSqlUtils.insertPostForResult(post); assertEquals(post, mPostStore.getPostByLocalPostId(post.getId())); } @@ -211,7 +212,7 @@ public void testGetPostByLocalId() { @Test public void testGetPostByRemoteId() { PostModel post = PostTestUtils.generateSampleUploadedPost(); - PostSqlUtils.insertPostForResult(post); + mPostSqlUtils.insertPostForResult(post); SiteModel site = new SiteModel(); site.setId(6); @@ -225,21 +226,21 @@ public void testDeleteUploadedPosts() { site.setId(6); PostModel uploadedPost1 = PostTestUtils.generateSampleUploadedPost(); - PostSqlUtils.insertPostForResult(uploadedPost1); + mPostSqlUtils.insertPostForResult(uploadedPost1); PostModel uploadedPost2 = PostTestUtils.generateSampleUploadedPost(); uploadedPost2.setRemotePostId(9); - PostSqlUtils.insertPostForResult(uploadedPost2); + mPostSqlUtils.insertPostForResult(uploadedPost2); PostModel localDraft = PostTestUtils.generateSampleLocalDraftPost(); - PostSqlUtils.insertPostForResult(localDraft); + mPostSqlUtils.insertPostForResult(localDraft); PostModel locallyChangedPost = PostTestUtils.generateSampleLocallyChangedPost(); - PostSqlUtils.insertPostForResult(locallyChangedPost); + mPostSqlUtils.insertPostForResult(locallyChangedPost); assertEquals(4, mPostStore.getPostsCountForSite(site)); - PostSqlUtils.deleteUploadedPostsForSite(site, false); + mPostSqlUtils.deleteUploadedPostsForSite(site, false); assertEquals(2, mPostStore.getPostsCountForSite(site)); } @@ -250,32 +251,32 @@ public void testDeletePost() { site.setId(6); PostModel uploadedPost1 = PostTestUtils.generateSampleUploadedPost(); - PostSqlUtils.insertPostForResult(uploadedPost1); + mPostSqlUtils.insertPostForResult(uploadedPost1); PostModel uploadedPost2 = PostTestUtils.generateSampleUploadedPost(); uploadedPost2.setRemotePostId(9); - PostSqlUtils.insertPostForResult(uploadedPost2); + mPostSqlUtils.insertPostForResult(uploadedPost2); PostModel localDraft = PostTestUtils.generateSampleLocalDraftPost(); - PostSqlUtils.insertPostForResult(localDraft); + mPostSqlUtils.insertPostForResult(localDraft); PostModel locallyChangedPost = PostTestUtils.generateSampleLocallyChangedPost(); - PostSqlUtils.insertPostForResult(locallyChangedPost); + mPostSqlUtils.insertPostForResult(locallyChangedPost); assertEquals(4, mPostStore.getPostsCountForSite(site)); - PostSqlUtils.deletePost(uploadedPost1); + mPostSqlUtils.deletePost(uploadedPost1); assertEquals(null, mPostStore.getPostByLocalPostId(uploadedPost1.getId())); assertEquals(3, mPostStore.getPostsCountForSite(site)); - PostSqlUtils.deletePost(uploadedPost2); - PostSqlUtils.deletePost(localDraft); + mPostSqlUtils.deletePost(uploadedPost2); + mPostSqlUtils.deletePost(localDraft); assertNotEquals(null, mPostStore.getPostByLocalPostId(locallyChangedPost.getId())); assertEquals(1, mPostStore.getPostsCountForSite(site)); - PostSqlUtils.deletePost(locallyChangedPost); + mPostSqlUtils.deletePost(locallyChangedPost); assertEquals(null, mPostStore.getPostByLocalPostId(locallyChangedPost.getId())); assertEquals(0, mPostStore.getPostsCountForSite(site)); @@ -290,13 +291,13 @@ public void testPostAndPageSeparation() { PostModel post = new PostModel(); post.setLocalSiteId(6); post.setRemotePostId(42); - PostSqlUtils.insertPostForResult(post); + mPostSqlUtils.insertPostForResult(post); PostModel page = new PostModel(); page.setIsPage(true); page.setLocalSiteId(6); page.setRemotePostId(43); - PostSqlUtils.insertPostForResult(page); + mPostSqlUtils.insertPostForResult(page); assertEquals(2, PostTestUtils.getPostsCount()); @@ -319,21 +320,21 @@ public void testPostOrder() { post.setLocalSiteId(6); post.setRemotePostId(42); post.setDateCreated(DateTimeUtils.iso8601UTCFromDate(new Date())); - PostSqlUtils.insertPostForResult(post); + mPostSqlUtils.insertPostForResult(post); PostModel localDraft = new PostModel(); localDraft.setLocalSiteId(6); localDraft.setIsLocalDraft(true); localDraft.setDateCreated("2016-01-01T07:00:00+00:00"); - PostSqlUtils.insertPostForResult(localDraft); + mPostSqlUtils.insertPostForResult(localDraft); PostModel scheduledPost = new PostModel(); scheduledPost.setLocalSiteId(6); scheduledPost.setRemotePostId(23); scheduledPost.setDateCreated("2056-01-01T07:00:00+00:00"); - PostSqlUtils.insertPostForResult(scheduledPost); + mPostSqlUtils.insertPostForResult(scheduledPost); - List posts = PostSqlUtils.getPostsForSite(site, false); + List posts = mPostSqlUtils.getPostsForSite(site, false); // Expect order draft > scheduled > published assertTrue(posts.get(0).isLocalDraft()); @@ -344,15 +345,15 @@ public void testPostOrder() { @Test public void testRemoveAllPosts() { PostModel uploadedPost1 = PostTestUtils.generateSampleUploadedPost(); - PostSqlUtils.insertPostForResult(uploadedPost1); + mPostSqlUtils.insertPostForResult(uploadedPost1); PostModel uploadedPost2 = PostTestUtils.generateSampleUploadedPost(); uploadedPost2.setLocalSiteId(8); - PostSqlUtils.insertPostForResult(uploadedPost2); + mPostSqlUtils.insertPostForResult(uploadedPost2); assertEquals(2, PostTestUtils.getPostsCount()); - PostSqlUtils.deleteAllPosts(); + mPostSqlUtils.deleteAllPosts(); assertEquals(0, PostTestUtils.getPostsCount()); } @@ -360,17 +361,17 @@ public void testRemoveAllPosts() { @Test public void testNumLocalChanges() { // first make sure there aren't any local changes - assertEquals(PostStore.getNumLocalChanges(), 0); + assertEquals(mPostStore.getNumLocalChanges(), 0); // then add a post with local changes and ensure we get the correct count PostModel testPost = PostTestUtils.generateSampleLocalDraftPost(); testPost.setIsLocallyChanged(true); - PostSqlUtils.insertOrUpdatePost(testPost, true); - assertEquals(PostStore.getNumLocalChanges(), 1); + mPostSqlUtils.insertOrUpdatePost(testPost, true); + assertEquals(mPostStore.getNumLocalChanges(), 1); // delete the post and again check the count - PostSqlUtils.deletePost(testPost); - assertEquals(PostStore.getNumLocalChanges(), 0); + mPostSqlUtils.deletePost(testPost); + assertEquals(mPostStore.getNumLocalChanges(), 0); } @Test @@ -443,15 +444,15 @@ public void testGetLocalDraftPostsMethodOnlyReturnsLocalDrafts() { for (int i = 0; i < 3; i++) { final String compoundTitle = baseTitle.concat(":").concat(UUID.randomUUID().toString()); final PostModel post = PostTestUtils.generateSampleLocalDraftPost(compoundTitle); - PostSqlUtils.insertPostForResult(post); + mPostSqlUtils.insertPostForResult(post); } final PostModel localDraftPage = PostTestUtils.generateSampleLocalDraftPost(); localDraftPage.setIsPage(true); - PostSqlUtils.insertPostForResult(localDraftPage); + mPostSqlUtils.insertPostForResult(localDraftPage); final PostModel uploadedPost = PostTestUtils.generateSampleUploadedPost(); - PostSqlUtils.insertPostForResult(uploadedPost); + mPostSqlUtils.insertPostForResult(uploadedPost); final SiteModel site = new SiteModel(); site.setId(PostTestUtils.DEFAULT_LOCAL_SITE_ID); @@ -524,14 +525,14 @@ private void generateAndInsertPosts(int localSiteId, List localIds, Lis for (int i = 1; i <= localIds.size(); i++) { PostModel post = PostTestUtils.generateSampleLocalDraftPost(); post.setLocalSiteId(localSiteId); - PostSqlUtils.insertOrUpdatePost(post, false); + mPostSqlUtils.insertOrUpdatePost(post, false); } for (RemoteId remoteId : remoteIds) { PostModel post = PostTestUtils.generateSampleUploadedPost(); post.setLocalSiteId(localSiteId); post.setRemotePostId(remoteId.getValue()); - PostSqlUtils.insertOrUpdatePost(post, false); + mPostSqlUtils.insertOrUpdatePost(post, false); } } } diff --git a/example/src/test/java/org/wordpress/android/fluxc/post/PostStoreTest.kt b/example/src/test/java/org/wordpress/android/fluxc/post/PostStoreTest.kt new file mode 100644 index 0000000000..e610c09dfb --- /dev/null +++ b/example/src/test/java/org/wordpress/android/fluxc/post/PostStoreTest.kt @@ -0,0 +1,246 @@ +package org.wordpress.android.fluxc.post + +import com.nhaarman.mockitokotlin2.any +import com.nhaarman.mockitokotlin2.argThat +import com.nhaarman.mockitokotlin2.mock +import com.nhaarman.mockitokotlin2.verify +import com.nhaarman.mockitokotlin2.verifyNoMoreInteractions +import com.nhaarman.mockitokotlin2.whenever +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.Mock +import org.mockito.junit.MockitoJUnitRunner +import org.wordpress.android.fluxc.Dispatcher +import org.wordpress.android.fluxc.action.ListAction +import org.wordpress.android.fluxc.action.PostAction +import org.wordpress.android.fluxc.generated.PostActionBuilder +import org.wordpress.android.fluxc.model.PostModel +import org.wordpress.android.fluxc.model.SiteModel +import org.wordpress.android.fluxc.model.list.PostListDescriptor +import org.wordpress.android.fluxc.model.post.PostStatus +import org.wordpress.android.fluxc.model.post.PostStatus.PUBLISHED +import org.wordpress.android.fluxc.persistence.PostSqlUtils +import org.wordpress.android.fluxc.store.ListStore.FetchedListItemsPayload +import org.wordpress.android.fluxc.store.PostStore +import org.wordpress.android.fluxc.store.PostStore.FetchPostListResponsePayload +import org.wordpress.android.fluxc.store.PostStore.PostError +import org.wordpress.android.fluxc.store.PostStore.PostErrorType.GENERIC_ERROR +import org.wordpress.android.fluxc.store.PostStore.PostListItem + +@RunWith(MockitoJUnitRunner::class) +class PostStoreTest { + @Mock lateinit var site: SiteModel + @Mock lateinit var postSqlUtils: PostSqlUtils + @Mock lateinit var dispatcher: Dispatcher + private lateinit var store: PostStore + @Mock lateinit var mockedListDescriptor: PostListDescriptor + + @Before + fun setUp() { + store = PostStore(dispatcher, mock(), mock(), postSqlUtils) + whenever(mockedListDescriptor.site).thenReturn(mock()) + // verify "register" so we can use verifyNoMoreInteractions in all the test methods + verify(dispatcher).register(any()) + } + + @Test + fun `handleFetchedPostList emits FetchedListItemsAction on success`() { + // Arrange + val action = createFetchedPostListAction() + + // Act + store.onAction(action) + + // Assert + verify(dispatcher).dispatch(argThat { + (this.type == ListAction.FETCHED_LIST_ITEMS) + }) + verifyNoMoreInteractions(dispatcher) + } + + @Test + fun `handleFetchedPostList emits FetchedListItemsAction on error`() { + // Arrange + val action = createFetchedPostListAction(postError = PostError(GENERIC_ERROR)) + + // Act + store.onAction(action) + + // Assert + verify(dispatcher).dispatch(argThat { + (this.type == ListAction.FETCHED_LIST_ITEMS) + }) + verifyNoMoreInteractions(dispatcher) + } + + @Test + fun `handleFetchedPostList emits FetchedListItemsAction with an error field set on error`() { + // Arrange + val action = createFetchedPostListAction(postError = PostError(GENERIC_ERROR)) + + // Act + store.onAction(action) + + // Assert + verify(dispatcher).dispatch(argThat { + (this.payload as FetchedListItemsPayload).isError + }) + verifyNoMoreInteractions(dispatcher) + } + + @Test + fun `handleFetchedPostList emits just FetchedListItemsAction when post not changed`() { + // Arrange + val postInLocalDb = createPostModel() + whenever(postSqlUtils.getPostsByRemoteIds(any(), any())).thenReturn(listOf(postInLocalDb)) + + val remotePostListItem = createRemotePostListItem(postInLocalDb) + val action = createFetchedPostListAction(postListItems = listOf(remotePostListItem)) + + // Act + store.onAction(action) + + // Assert + verify(dispatcher).dispatch(argThat { + (this.type == ListAction.FETCHED_LIST_ITEMS) + }) + verifyNoMoreInteractions(dispatcher) + } + + @Test + fun `handleFetchedPostList emits FetchPostAction when post changed in remote`() { + // Arrange + val postInLocalDb = createPostModel() + whenever(postSqlUtils.getPostsByRemoteIds(any(), any())).thenReturn(listOf(postInLocalDb)) + + val remotePostListItem = createRemotePostListItem(postInLocalDb, lastModified = "modified in remote") + val action = createFetchedPostListAction(postListItems = listOf(remotePostListItem)) + + // Act + store.onAction(action) + + // Assert + verify(dispatcher).dispatch(argThat { + (this.type == PostAction.FETCH_POST) + }) + verify(dispatcher).dispatch(argThat { + (this.type == ListAction.FETCHED_LIST_ITEMS) + }) + verifyNoMoreInteractions(dispatcher) + } + + @Test + fun `handleFetchedPostList emits UpdatePostAction when post changed in both remote and local`() { + // Arrange + val postInLocalDb = createPostModel(isLocallyChanged = true) + whenever(postSqlUtils.getPostsByRemoteIds(any(), any())).thenReturn(listOf(postInLocalDb)) + + val remotePostListItem = createRemotePostListItem(postInLocalDb, lastModified = "modified in remote") + val action = createFetchedPostListAction(postListItems = listOf(remotePostListItem)) + + // Act + store.onAction(action) + + // Assert + verify(dispatcher).dispatch(argThat { + (this.type == PostAction.UPDATE_POST) + }) + verify(dispatcher).dispatch(argThat { + (this.type == ListAction.FETCHED_LIST_ITEMS) + }) + verifyNoMoreInteractions(dispatcher) + } + + @Test + fun `handleFetchedPostList emits UpdatePostAction when post changed locally and post status changed in remote`() { + // Arrange + val postInLocalDb = createPostModel(isLocallyChanged = true) + whenever(postSqlUtils.getPostsByRemoteIds(any(), any())).thenReturn(listOf(postInLocalDb)) + + val remotePostListItem = createRemotePostListItem(postInLocalDb, status = PostStatus.TRASHED.toString()) + val action = createFetchedPostListAction(postListItems = listOf(remotePostListItem)) + + // Act + store.onAction(action) + + // Assert + verify(dispatcher).dispatch(argThat { + (this.type == PostAction.UPDATE_POST) + }) + verify(dispatcher).dispatch(argThat { + (this.type == ListAction.FETCHED_LIST_ITEMS) + }) + verifyNoMoreInteractions(dispatcher) + } + + @Test + fun `handleFetchedPostList sets remoteLastModified field when post changed in both remote and local`() { + // Arrange + val postInLocalDb = createPostModel(isLocallyChanged = true) + whenever(postSqlUtils.getPostsByRemoteIds(any(), any())).thenReturn(listOf(postInLocalDb)) + + val remotePostListItem = createRemotePostListItem(postInLocalDb, lastModified = "modified in remote") + val action = createFetchedPostListAction(postListItems = listOf(remotePostListItem)) + + // Act + store.onAction(action) + + // Assert + verify(dispatcher).dispatch(argThat { + ((this.payload as? PostModel)?.remoteLastModified == remotePostListItem.lastModified) + }) + } + + @Test + fun `handleFetchedPostList emits FetchPostAction when post status changed in remote`() { + // Arrange + val postInLocalDb = createPostModel() + whenever(postSqlUtils.getPostsByRemoteIds(any(), any())).thenReturn(listOf(postInLocalDb)) + + val remotePostListItem = createRemotePostListItem(postInLocalDb, status = PostStatus.TRASHED.toString()) + val action = createFetchedPostListAction(postListItems = listOf(remotePostListItem)) + + // Act + store.onAction(action) + + // Assert + verify(dispatcher).dispatch(argThat { + (this.type == PostAction.FETCH_POST) + }) + verify(dispatcher).dispatch(argThat { + (this.type == ListAction.FETCHED_LIST_ITEMS) + }) + verifyNoMoreInteractions(dispatcher) + } + + private fun createFetchedPostListAction( + postListItems: List = listOf(), + listDescriptor: PostListDescriptor = mockedListDescriptor, + postError: PostError? = null + ) = PostActionBuilder.newFetchedPostListAction( + FetchPostListResponsePayload( + listDescriptor, + postListItems, + false, + false, + postError + ) + ) + + private fun createPostModel(isLocallyChanged: Boolean = false, postStatus: PostStatus = PUBLISHED): PostModel { + val post = PostModel() + post.remotePostId = 1 + post.status = postStatus.toString() + post.setIsLocallyChanged(isLocallyChanged) + post.autoSaveModified = "1955-11-05T14:15:00Z" + return post + } + + private fun createRemotePostListItem( + post: PostModel, + status: String = post.status, + lastModified: String = post.lastModified, + autoSaveModified: String = post.autoSaveModified + ) = PostListItem(post.remotePostId, lastModified, status, autoSaveModified) +} diff --git a/example/src/test/java/org/wordpress/android/fluxc/post/PostTestUtils.java b/example/src/test/java/org/wordpress/android/fluxc/post/PostTestUtils.java index b246fad476..c0ccb162c6 100644 --- a/example/src/test/java/org/wordpress/android/fluxc/post/PostTestUtils.java +++ b/example/src/test/java/org/wordpress/android/fluxc/post/PostTestUtils.java @@ -1,6 +1,6 @@ package org.wordpress.android.fluxc.post; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import com.yarolegovich.wellsql.WellSql; diff --git a/example/src/test/java/org/wordpress/android/fluxc/site/SiteStoreUnitTest.java b/example/src/test/java/org/wordpress/android/fluxc/site/SiteStoreUnitTest.java index ba5967b960..54fed66be6 100644 --- a/example/src/test/java/org/wordpress/android/fluxc/site/SiteStoreUnitTest.java +++ b/example/src/test/java/org/wordpress/android/fluxc/site/SiteStoreUnitTest.java @@ -18,6 +18,7 @@ import org.wordpress.android.fluxc.model.SitesModel; import org.wordpress.android.fluxc.network.rest.wpcom.site.SiteRestClient; import org.wordpress.android.fluxc.network.xmlrpc.site.SiteXMLRPCClient; +import org.wordpress.android.fluxc.persistence.PostSqlUtils; import org.wordpress.android.fluxc.persistence.SiteSqlUtils; import org.wordpress.android.fluxc.persistence.SiteSqlUtils.DuplicateSiteException; import org.wordpress.android.fluxc.persistence.WellSqlConfig; @@ -45,7 +46,8 @@ @RunWith(RobolectricTestRunner.class) public class SiteStoreUnitTest { - private SiteStore mSiteStore = new SiteStore(new Dispatcher(), Mockito.mock(SiteRestClient.class), + private PostSqlUtils mPostSqlUtils = new PostSqlUtils(); + private SiteStore mSiteStore = new SiteStore(new Dispatcher(), mPostSqlUtils, Mockito.mock(SiteRestClient.class), Mockito.mock(SiteXMLRPCClient.class)); @Before @@ -811,7 +813,7 @@ public void testRemoveWPComRestSitesAbsentFromList() sitesToKeep.addAll(allSites.subList(0, 6)); // remove six sites (2/3 * (15 - 6)) - SiteSqlUtils.removeWPComRestSitesAbsentFromList(sitesToKeep); + SiteSqlUtils.removeWPComRestSitesAbsentFromList(mPostSqlUtils, sitesToKeep); assertTrue(mSiteStore.getSitesCount() == 9); diff --git a/example/src/test/java/org/wordpress/android/fluxc/store/StatsStoreTest.kt b/example/src/test/java/org/wordpress/android/fluxc/store/StatsStoreTest.kt index 9b6f58c10d..3ae81e4d9f 100644 --- a/example/src/test/java/org/wordpress/android/fluxc/store/StatsStoreTest.kt +++ b/example/src/test/java/org/wordpress/android/fluxc/store/StatsStoreTest.kt @@ -1,5 +1,6 @@ package org.wordpress.android.fluxc.store +import android.content.SharedPreferences import com.nhaarman.mockitokotlin2.any import com.nhaarman.mockitokotlin2.eq import com.nhaarman.mockitokotlin2.never @@ -12,6 +13,7 @@ import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.mockito.Mock +import org.mockito.Mockito import org.mockito.junit.MockitoJUnitRunner import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.persistence.InsightTypeSqlUtils @@ -19,12 +21,17 @@ import org.wordpress.android.fluxc.store.StatsStore.InsightType.COMMENTS import org.wordpress.android.fluxc.store.StatsStore.InsightType.FOLLOWERS import org.wordpress.android.fluxc.store.StatsStore.InsightType.LATEST_POST_SUMMARY import org.wordpress.android.fluxc.store.StatsStore.InsightType.POSTING_ACTIVITY +import org.wordpress.android.fluxc.store.StatsStore.ManagementType import org.wordpress.android.fluxc.test +import org.wordpress.android.fluxc.utils.PreferenceUtils.PreferenceUtilsWrapper @RunWith(MockitoJUnitRunner::class) class StatsStoreTest { @Mock lateinit var site: SiteModel @Mock lateinit var insightTypesSqlUtils: InsightTypeSqlUtils + @Mock lateinit var preferenceUtilsWrapper: PreferenceUtilsWrapper + @Mock lateinit var sharedPreferences: SharedPreferences + @Mock lateinit var sharedPreferencesEditor: SharedPreferences.Editor private lateinit var store: StatsStore @ExperimentalCoroutinesApi @@ -32,8 +39,11 @@ class StatsStoreTest { fun setUp() { store = StatsStore( Unconfined, - insightTypesSqlUtils + insightTypesSqlUtils, + preferenceUtilsWrapper ) + whenever(preferenceUtilsWrapper.getFluxCPreferences()).thenReturn(sharedPreferences) + whenever(sharedPreferences.edit()).thenReturn(sharedPreferencesEditor) } @Test @@ -150,4 +160,52 @@ class StatsStoreTest { store.getRemovedInsights(addedTypes - POSTING_ACTIVITY) ) } + + @Test + fun `insight types starts with news type and ends with control type when news card was not shown`() = test { + whenever(insightTypesSqlUtils.selectAddedItemsOrderedByStatus(site)).thenReturn(listOf(COMMENTS)) + whenever(sharedPreferences.getBoolean(INSIGHTS_MANAGEMENT_NEWS_CARD_SHOWN, false)).thenReturn(false) + + val insightTypes = store.getInsightTypes(site) + + assertThat(insightTypes).hasSize(3) + assertThat(insightTypes[0]).isEqualTo(ManagementType.NEWS_CARD) + assertThat(insightTypes[1]).isEqualTo(COMMENTS) + assertThat(insightTypes[2]).isEqualTo(ManagementType.CONTROL) + } + + @Test + fun `insight types does not start with news type when news card was shown`() = test { + whenever(insightTypesSqlUtils.selectAddedItemsOrderedByStatus(site)).thenReturn(listOf(COMMENTS)) + whenever(sharedPreferences.getBoolean(INSIGHTS_MANAGEMENT_NEWS_CARD_SHOWN, false)).thenReturn(true) + + val insightTypes = store.getInsightTypes(site) + + assertThat(insightTypes).hasSize(2) + assertThat(insightTypes[0]).isEqualTo(COMMENTS) + assertThat(insightTypes[1]).isEqualTo(ManagementType.CONTROL) + } + + @Test + fun `hide news card sets shared prefs`() { + whenever(sharedPreferencesEditor.putBoolean(any(), any())).thenReturn(sharedPreferencesEditor) + + store.hideInsightsManagementNewsCard() + + verify(sharedPreferences).edit() + Mockito.inOrder(sharedPreferencesEditor).apply { + this.verify(sharedPreferencesEditor).putBoolean(INSIGHTS_MANAGEMENT_NEWS_CARD_SHOWN, true) + this.verify(sharedPreferencesEditor).apply() + } + } + + @Test + fun `is news card showing returns from shared prefs`() { + val prefsValue = true + whenever(sharedPreferences.getBoolean(INSIGHTS_MANAGEMENT_NEWS_CARD_SHOWN, true)).thenReturn(prefsValue) + + val insightsManagementNewsCardShowing = store.isInsightsManagementNewsCardShowing() + + assertThat(insightsManagementNewsCardShowing).isEqualTo(prefsValue) + } } diff --git a/example/src/test/java/org/wordpress/android/fluxc/upload/UploadSqlUtilsTest.java b/example/src/test/java/org/wordpress/android/fluxc/upload/UploadSqlUtilsTest.java index 3ef0d848dd..e4b751e1da 100644 --- a/example/src/test/java/org/wordpress/android/fluxc/upload/UploadSqlUtilsTest.java +++ b/example/src/test/java/org/wordpress/android/fluxc/upload/UploadSqlUtilsTest.java @@ -33,6 +33,7 @@ @RunWith(RobolectricTestRunner.class) public class UploadSqlUtilsTest { private Random mRandom = new Random(System.currentTimeMillis()); + private PostSqlUtils mPostSqlUtils = new PostSqlUtils(); @Before public void setUp() { @@ -173,7 +174,7 @@ public void testInsertNullPost() { @Test public void testInsertPost() { PostModel testPost = UploadTestUtils.getTestPost(); - assertEquals(1, PostSqlUtils.insertOrUpdatePostOverwritingLocalChanges(testPost)); + assertEquals(1, mPostSqlUtils.insertOrUpdatePostOverwritingLocalChanges(testPost)); List postList = PostTestUtils.getPosts(); assertEquals(1, postList.size()); assertNotNull(postList.get(0)); @@ -189,7 +190,7 @@ public void testInsertPost() { assertEquals(PostUploadModel.PENDING, postUploadModel.getUploadState()); // Deleting the PostModel should cause the corresponding PostUploadModel to be deleted also - PostSqlUtils.deletePost(testPost); + mPostSqlUtils.deletePost(testPost); postList = PostTestUtils.getPosts(); assertTrue(postList.isEmpty()); @@ -202,10 +203,10 @@ public void testInsertPost() { public void testGetPostModelsByState() { PostModel testPost1 = UploadTestUtils.getTestPost(); testPost1.setIsLocalDraft(true); - assertEquals(1, PostSqlUtils.insertOrUpdatePostOverwritingLocalChanges(testPost1)); + assertEquals(1, mPostSqlUtils.insertOrUpdatePostOverwritingLocalChanges(testPost1)); PostModel testPost2 = UploadTestUtils.getTestPost(); testPost2.setIsLocalDraft(true); - assertEquals(1, PostSqlUtils.insertOrUpdatePostOverwritingLocalChanges(testPost2)); + assertEquals(1, mPostSqlUtils.insertOrUpdatePostOverwritingLocalChanges(testPost2)); List postList = PostTestUtils.getPosts(); assertEquals(2, postList.size()); @@ -255,8 +256,8 @@ public void testDeletePostUploadModel() { testPost1.setIsLocalDraft(true); PostModel testPost2 = UploadTestUtils.getTestPost(); testPost2.setIsLocalDraft(true); - assertEquals(1, PostSqlUtils.insertOrUpdatePostOverwritingLocalChanges(testPost1)); - assertEquals(1, PostSqlUtils.insertOrUpdatePostOverwritingLocalChanges(testPost2)); + assertEquals(1, mPostSqlUtils.insertOrUpdatePostOverwritingLocalChanges(testPost1)); + assertEquals(1, mPostSqlUtils.insertOrUpdatePostOverwritingLocalChanges(testPost2)); List postModels = PostTestUtils.getPosts(); assertEquals(2, postModels.size()); diff --git a/example/src/test/java/org/wordpress/android/fluxc/upload/UploadStoreUnitTest.java b/example/src/test/java/org/wordpress/android/fluxc/upload/UploadStoreUnitTest.java index 4a1bfe55ed..5048ae744d 100644 --- a/example/src/test/java/org/wordpress/android/fluxc/upload/UploadStoreUnitTest.java +++ b/example/src/test/java/org/wordpress/android/fluxc/upload/UploadStoreUnitTest.java @@ -41,8 +41,9 @@ public class UploadStoreUnitTest { private Dispatcher mDispatcher = new Dispatcher(); private UploadStore mUploadStore = new UploadStore(mDispatcher); + private PostSqlUtils mPostSqlUtils = new PostSqlUtils(); private PostStore mPostStore = new PostStore(mDispatcher, Mockito.mock(PostRestClient.class), - Mockito.mock(PostXMLRPCClient.class)); + Mockito.mock(PostXMLRPCClient.class), mPostSqlUtils); @Before public void setUp() { @@ -78,7 +79,7 @@ public void testPostModelRegistration() { // Create a PostModel and add it to the PostStore PostModel postModel = UploadTestUtils.getTestPost(); postModel.setId(55); - PostSqlUtils.insertOrUpdatePostOverwritingLocalChanges(postModel); + mPostSqlUtils.insertOrUpdatePostOverwritingLocalChanges(postModel); postModel = mPostStore.getPostByLocalPostId(postModel.getId()); assertNotNull(postModel); @@ -126,7 +127,7 @@ public void testGetUploadErrorForPost() { // Create a PostModel and add it to the PostStore PostModel postModel = UploadTestUtils.getTestPost(); postModel.setId(55); - PostSqlUtils.insertOrUpdatePostOverwritingLocalChanges(postModel); + mPostSqlUtils.insertOrUpdatePostOverwritingLocalChanges(postModel); postModel = mPostStore.getPostByLocalPostId(postModel.getId()); assertNotNull(postModel); @@ -187,7 +188,7 @@ public void testGetUploadErrorForPost() { // Create another PostModel and add it to the PostStore - this time, without registering it with the UploadStore PostModel unregisteredPostModel = UploadTestUtils.getTestPost(); unregisteredPostModel.setId(55); - PostSqlUtils.insertOrUpdatePostOverwritingLocalChanges(unregisteredPostModel); + mPostSqlUtils.insertOrUpdatePostOverwritingLocalChanges(unregisteredPostModel); // Create a MediaModel attached to the above post MediaModel mediaLinkedToPost = UploadTestUtils.getLocalTestMedia(); diff --git a/fluxc/build.gradle b/fluxc/build.gradle index d67985244b..447fc256f4 100644 --- a/fluxc/build.gradle +++ b/fluxc/build.gradle @@ -21,7 +21,7 @@ repositories { android { useLibrary 'org.apache.http.legacy' - compileSdkVersion 27 + compileSdkVersion 28 buildToolsVersion '28.0.3' defaultConfig { @@ -66,10 +66,10 @@ android.buildTypes.all { buildType -> dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion" - implementation "com.android.support:appcompat-v7:$supportLibraryVersion" - implementation "com.android.support:recyclerview-v7:$supportLibraryVersion" + implementation "androidx.appcompat:appcompat:$appcompat_version" + implementation "androidx.recyclerview:recyclerview:1.0.0" - implementation "com.android.support:exifinterface:$supportLibraryVersion" + implementation "androidx.exifinterface:exifinterface:1.0.0" // WordPress libs implementation ('org.wordpress:utils:1.20.0') { @@ -87,13 +87,13 @@ dependencies { kapt project(':fluxc-processor') // External libs - api 'org.greenrobot:eventbus:3.0.0' + api 'org.greenrobot:eventbus:3.1.1' api 'com.squareup.okhttp3:okhttp:3.9.0' implementation 'com.squareup.okhttp3:okhttp-urlconnection:3.9.0' api 'com.android.volley:volley:1.1.1' implementation 'com.google.code.gson:gson:2.8.5' implementation 'org.apache.commons:commons-text:1.1' - api "android.arch.paging:runtime:$arch_paging_version" + api "androidx.paging:paging-runtime:2.1.0" // Dagger implementation "com.google.dagger:dagger:$daggerVersion" diff --git a/fluxc/gradle.properties-example b/fluxc/gradle.properties-example index 96f330dc0c..720168df99 100644 --- a/fluxc/gradle.properties-example +++ b/fluxc/gradle.properties-example @@ -1 +1,3 @@ -fluxc.ENABLE_WPAPI = false \ No newline at end of file +fluxc.ENABLE_WPAPI = false +android.useAndroidX=true +android.enableJetifier=true \ No newline at end of file diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/model/MediaUploadModel.java b/fluxc/src/main/java/org/wordpress/android/fluxc/model/MediaUploadModel.java index 26d8fa852d..a4b6ef9363 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/model/MediaUploadModel.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/model/MediaUploadModel.java @@ -1,9 +1,10 @@ package org.wordpress.android.fluxc.model; -import android.support.annotation.IntDef; -import android.support.annotation.Nullable; import android.text.TextUtils; +import androidx.annotation.IntDef; +import androidx.annotation.Nullable; + import com.yarolegovich.wellsql.core.Identifiable; import com.yarolegovich.wellsql.core.annotation.Column; import com.yarolegovich.wellsql.core.annotation.PrimaryKey; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/model/PostModel.java b/fluxc/src/main/java/org/wordpress/android/fluxc/model/PostModel.java index f461e016b0..f51f95f0a3 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/model/PostModel.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/model/PostModel.java @@ -1,9 +1,10 @@ package org.wordpress.android.fluxc.model; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; import android.text.TextUtils; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + import com.yarolegovich.wellsql.core.Identifiable; import com.yarolegovich.wellsql.core.annotation.Column; import com.yarolegovich.wellsql.core.annotation.PrimaryKey; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/model/PostUploadModel.java b/fluxc/src/main/java/org/wordpress/android/fluxc/model/PostUploadModel.java index 3e21d2fd8c..7538a9d463 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/model/PostUploadModel.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/model/PostUploadModel.java @@ -1,10 +1,11 @@ package org.wordpress.android.fluxc.model; -import android.support.annotation.IntDef; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; import android.text.TextUtils; +import androidx.annotation.IntDef; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + import com.yarolegovich.wellsql.core.Identifiable; import com.yarolegovich.wellsql.core.annotation.Column; import com.yarolegovich.wellsql.core.annotation.PrimaryKey; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/model/PostsModel.java b/fluxc/src/main/java/org/wordpress/android/fluxc/model/PostsModel.java index 05f42c4b5a..27a05abd73 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/model/PostsModel.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/model/PostsModel.java @@ -1,6 +1,6 @@ package org.wordpress.android.fluxc.model; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import org.wordpress.android.fluxc.Payload; import org.wordpress.android.fluxc.network.BaseRequest.BaseNetworkError; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/model/SiteModel.java b/fluxc/src/main/java/org/wordpress/android/fluxc/model/SiteModel.java index c80366502a..881e621c99 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/model/SiteModel.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/model/SiteModel.java @@ -1,7 +1,7 @@ package org.wordpress.android.fluxc.model; -import android.support.annotation.IntDef; -import android.support.annotation.NonNull; +import androidx.annotation.IntDef; +import androidx.annotation.NonNull; import com.yarolegovich.wellsql.core.Identifiable; import com.yarolegovich.wellsql.core.annotation.Column; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/model/SitesModel.java b/fluxc/src/main/java/org/wordpress/android/fluxc/model/SitesModel.java index f097b86c1b..0c7a5afb31 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/model/SitesModel.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/model/SitesModel.java @@ -1,6 +1,6 @@ package org.wordpress.android.fluxc.model; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import org.wordpress.android.fluxc.Payload; import org.wordpress.android.fluxc.network.BaseRequest.BaseNetworkError; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/model/SubscriptionModel.java b/fluxc/src/main/java/org/wordpress/android/fluxc/model/SubscriptionModel.java index 124908e86d..61b086719b 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/model/SubscriptionModel.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/model/SubscriptionModel.java @@ -1,6 +1,6 @@ package org.wordpress.android.fluxc.model; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import com.yarolegovich.wellsql.core.Identifiable; import com.yarolegovich.wellsql.core.annotation.Column; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/model/SubscriptionsModel.java b/fluxc/src/main/java/org/wordpress/android/fluxc/model/SubscriptionsModel.java index dae4fbae7b..be012b1dd0 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/model/SubscriptionsModel.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/model/SubscriptionsModel.java @@ -1,6 +1,6 @@ package org.wordpress.android.fluxc.model; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import org.wordpress.android.fluxc.Payload; import org.wordpress.android.fluxc.network.BaseRequest.BaseNetworkError; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/model/TermsModel.java b/fluxc/src/main/java/org/wordpress/android/fluxc/model/TermsModel.java index aef6b469b1..88fdeec939 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/model/TermsModel.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/model/TermsModel.java @@ -1,6 +1,6 @@ package org.wordpress.android.fluxc.model; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import org.wordpress.android.fluxc.Payload; import org.wordpress.android.fluxc.network.BaseRequest.BaseNetworkError; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/model/list/PagedListFactory.kt b/fluxc/src/main/java/org/wordpress/android/fluxc/model/list/PagedListFactory.kt index d341a4485c..cc4062de80 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/model/list/PagedListFactory.kt +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/model/list/PagedListFactory.kt @@ -1,7 +1,7 @@ package org.wordpress.android.fluxc.model.list -import android.arch.paging.DataSource -import android.arch.paging.PositionalDataSource +import androidx.paging.DataSource +import androidx.paging.PositionalDataSource import org.wordpress.android.fluxc.model.list.datasource.InternalPagedListDataSource /** diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/model/list/PagedListWrapper.kt b/fluxc/src/main/java/org/wordpress/android/fluxc/model/list/PagedListWrapper.kt index ac4586ef89..85743eb72e 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/model/list/PagedListWrapper.kt +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/model/list/PagedListWrapper.kt @@ -1,12 +1,12 @@ package org.wordpress.android.fluxc.model.list -import android.arch.lifecycle.Lifecycle -import android.arch.lifecycle.LifecycleObserver -import android.arch.lifecycle.LiveData -import android.arch.lifecycle.MediatorLiveData -import android.arch.lifecycle.MutableLiveData -import android.arch.lifecycle.OnLifecycleEvent -import android.arch.paging.PagedList +import androidx.lifecycle.Lifecycle +import androidx.lifecycle.LifecycleObserver +import androidx.lifecycle.LiveData +import androidx.lifecycle.MediatorLiveData +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.OnLifecycleEvent +import androidx.paging.PagedList import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Job import kotlinx.coroutines.launch diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/model/plugin/ImmutablePluginModel.java b/fluxc/src/main/java/org/wordpress/android/fluxc/model/plugin/ImmutablePluginModel.java index f9ab19a6c3..78493b49c5 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/model/plugin/ImmutablePluginModel.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/model/plugin/ImmutablePluginModel.java @@ -1,6 +1,6 @@ package org.wordpress.android.fluxc.model.plugin; -import android.support.annotation.Nullable; +import androidx.annotation.Nullable; import org.wordpress.android.util.StringUtils; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/BaseRequest.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/BaseRequest.java index 09d881b8e9..3ad656bd3f 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/BaseRequest.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/BaseRequest.java @@ -2,9 +2,10 @@ import android.net.Uri; import android.net.Uri.Builder; -import android.support.annotation.NonNull; import android.util.Base64; +import androidx.annotation.NonNull; + import com.android.volley.AuthFailureError; import com.android.volley.Cache; import com.android.volley.DefaultRetryPolicy; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/BaseRequestFuture.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/BaseRequestFuture.java index 6ec9e24fe7..2102c0f4d0 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/BaseRequestFuture.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/BaseRequestFuture.java @@ -18,7 +18,7 @@ package org.wordpress.android.fluxc.network; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import com.android.volley.Request; import com.android.volley.Response.Listener; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/BaseUploadRequestBody.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/BaseUploadRequestBody.java index 97d14e1bf6..7d70d18965 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/BaseUploadRequestBody.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/BaseUploadRequestBody.java @@ -1,8 +1,9 @@ package org.wordpress.android.fluxc.network; -import android.support.annotation.NonNull; import android.text.TextUtils; +import androidx.annotation.NonNull; + import org.wordpress.android.fluxc.model.MediaModel; import org.wordpress.android.fluxc.utils.MediaUtils; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/HTTPAuthManager.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/HTTPAuthManager.java index 205a856b6a..7e512ba884 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/HTTPAuthManager.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/HTTPAuthManager.java @@ -1,7 +1,7 @@ package org.wordpress.android.fluxc.network; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import com.yarolegovich.wellsql.WellSql; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/MemorizingTrustManager.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/MemorizingTrustManager.java index 3be297a8e0..b4de95534f 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/MemorizingTrustManager.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/MemorizingTrustManager.java @@ -1,8 +1,9 @@ package org.wordpress.android.fluxc.network; import android.content.Context; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import org.wordpress.android.util.AppLog; import org.wordpress.android.util.AppLog.T; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/discovery/DiscoveryRequest.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/discovery/DiscoveryRequest.java index 3ae0afd030..e9c717598a 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/discovery/DiscoveryRequest.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/discovery/DiscoveryRequest.java @@ -1,6 +1,6 @@ package org.wordpress.android.fluxc.network.discovery; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import com.android.volley.NetworkResponse; import com.android.volley.Response; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/discovery/DiscoveryXMLRPCRequest.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/discovery/DiscoveryXMLRPCRequest.java index 24eb2e90be..4546c397b0 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/discovery/DiscoveryXMLRPCRequest.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/discovery/DiscoveryXMLRPCRequest.java @@ -1,6 +1,6 @@ package org.wordpress.android.fluxc.network.discovery; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import com.android.volley.Response.Listener; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/discovery/SelfHostedEndpointFinder.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/discovery/SelfHostedEndpointFinder.java index 4eb8f9bff0..71515f532a 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/discovery/SelfHostedEndpointFinder.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/discovery/SelfHostedEndpointFinder.java @@ -1,9 +1,10 @@ package org.wordpress.android.fluxc.network.discovery; -import android.support.annotation.NonNull; import android.text.TextUtils; import android.webkit.URLUtil; +import androidx.annotation.NonNull; + import org.wordpress.android.fluxc.BuildConfig; import org.wordpress.android.fluxc.Dispatcher; import org.wordpress.android.fluxc.Payload; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/discovery/WPAPIHeadRequest.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/discovery/WPAPIHeadRequest.java index 7e2c5ae239..d09abd5798 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/discovery/WPAPIHeadRequest.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/discovery/WPAPIHeadRequest.java @@ -1,6 +1,6 @@ package org.wordpress.android.fluxc.network.discovery; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import com.android.volley.NetworkResponse; import com.android.volley.Response; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpapi/WPAPIGsonRequest.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpapi/WPAPIGsonRequest.java index fa9485aade..bbbd7e6bde 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpapi/WPAPIGsonRequest.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpapi/WPAPIGsonRequest.java @@ -1,6 +1,6 @@ package org.wordpress.android.fluxc.network.rest.wpapi; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import com.android.volley.Response.Listener; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/WPComGsonRequest.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/WPComGsonRequest.java index 7e37c5e2eb..ba116a30b6 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/WPComGsonRequest.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/WPComGsonRequest.java @@ -1,8 +1,9 @@ package org.wordpress.android.fluxc.network.rest.wpcom; -import android.support.annotation.NonNull; import android.text.TextUtils; +import androidx.annotation.NonNull; + import com.android.volley.Response.Listener; import com.android.volley.toolbox.HttpHeaderParser; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/account/AccountRestClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/account/AccountRestClient.java index 24bbc66256..a3907173ac 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/account/AccountRestClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/account/AccountRestClient.java @@ -1,10 +1,11 @@ package org.wordpress.android.fluxc.network.rest.wpcom.account; import android.content.Context; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; import android.text.TextUtils; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + import com.android.volley.RequestQueue; import com.android.volley.Response.Listener; import com.android.volley.VolleyError; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/account/AccountSocialRequest.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/account/AccountSocialRequest.java index abf06066f6..e268fa2683 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/account/AccountSocialRequest.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/account/AccountSocialRequest.java @@ -1,6 +1,6 @@ package org.wordpress.android.fluxc.network.rest.wpcom.account; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import com.android.volley.AuthFailureError; import com.android.volley.NetworkResponse; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/auth/Authenticator.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/auth/Authenticator.java index 69058151f0..0ab09d3356 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/auth/Authenticator.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/auth/Authenticator.java @@ -1,9 +1,10 @@ package org.wordpress.android.fluxc.network.rest.wpcom.auth; import android.content.Context; -import android.support.annotation.NonNull; import android.text.TextUtils; +import androidx.annotation.NonNull; + import com.android.volley.NetworkResponse; import com.android.volley.ParseError; import com.android.volley.Request; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/comment/CommentRestClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/comment/CommentRestClient.java index b1e672384d..ade16f03ad 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/comment/CommentRestClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/comment/CommentRestClient.java @@ -1,8 +1,9 @@ package org.wordpress.android.fluxc.network.rest.wpcom.comment; import android.content.Context; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import com.android.volley.RequestQueue; import com.android.volley.Response.Listener; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java index 6a3c717283..0f33369671 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRestClient.java @@ -1,9 +1,10 @@ package org.wordpress.android.fluxc.network.rest.wpcom.media; import android.content.Context; -import android.support.annotation.NonNull; import android.text.TextUtils; +import androidx.annotation.NonNull; + import com.android.volley.RequestQueue; import com.android.volley.Response.Listener; import com.google.gson.Gson; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/RestUploadRequestBody.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/RestUploadRequestBody.java index e456318f28..4e09f0a3ca 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/RestUploadRequestBody.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/RestUploadRequestBody.java @@ -1,6 +1,6 @@ package org.wordpress.android.fluxc.network.rest.wpcom.media; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import org.wordpress.android.fluxc.model.MediaModel; import org.wordpress.android.fluxc.network.BaseUploadRequestBody; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/notifications/NotificationRestClient.kt b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/notifications/NotificationRestClient.kt index 229ad67167..4db934dab0 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/notifications/NotificationRestClient.kt +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/notifications/NotificationRestClient.kt @@ -28,6 +28,8 @@ import org.wordpress.android.fluxc.store.NotificationStore.NotificationErrorType import org.wordpress.android.fluxc.store.NotificationStore.RegisterDeviceResponsePayload import org.wordpress.android.fluxc.store.NotificationStore.UnregisterDeviceResponsePayload import org.wordpress.android.fluxc.store.SiteStore +import org.wordpress.android.util.AppLog +import org.wordpress.android.util.AppLog.T import org.wordpress.android.util.DeviceUtils import org.wordpress.android.util.PackageUtils import java.util.Date @@ -72,12 +74,20 @@ class NotificationRestClient constructor( val url = WPCOMREST.devices.new_.urlV1 val request = WPComGsonRequest.buildPostRequest( url, params, RegisterDeviceRestResponse::class.java, - { response -> - response.id?.takeIf { it.isNotEmpty() }?.let { - val payload = RegisterDeviceResponsePayload(it) - dispatcher.dispatch(NotificationActionBuilder.newRegisteredDeviceAction(payload)) + { response: RegisterDeviceRestResponse? -> + response?.let { + if (!it.id.isNullOrEmpty()) { + val payload = RegisterDeviceResponsePayload(it.id) + dispatcher.dispatch(NotificationActionBuilder.newRegisteredDeviceAction(payload)) + } else { + val registrationError = + DeviceRegistrationError(DeviceRegistrationErrorType.MISSING_DEVICE_ID) + val payload = RegisterDeviceResponsePayload(registrationError) + dispatcher.dispatch(NotificationActionBuilder.newRegisteredDeviceAction(payload)) + } } ?: run { - val registrationError = DeviceRegistrationError(DeviceRegistrationErrorType.MISSING_DEVICE_ID) + AppLog.e(T.API, "Response for url $url with param $params is null: $response") + val registrationError = DeviceRegistrationError(DeviceRegistrationErrorType.INVALID_RESPONSE) val payload = RegisterDeviceResponsePayload(registrationError) dispatcher.dispatch(NotificationActionBuilder.newRegisteredDeviceAction(payload)) } diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/plugin/PluginRestClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/plugin/PluginRestClient.java index 281ed1b5de..6b3d2ba186 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/plugin/PluginRestClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/plugin/PluginRestClient.java @@ -1,7 +1,8 @@ package org.wordpress.android.fluxc.network.rest.wpcom.plugin; import android.content.Context; -import android.support.annotation.NonNull; + +import androidx.annotation.NonNull; import com.android.volley.RequestQueue; import com.android.volley.Response.Listener; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/post/PostRestClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/post/PostRestClient.java index c1bb61dda9..d02bed6cee 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/post/PostRestClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/post/PostRestClient.java @@ -1,10 +1,11 @@ package org.wordpress.android.fluxc.network.rest.wpcom.post; import android.content.Context; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; import android.text.TextUtils; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + import com.android.volley.RequestQueue; import com.android.volley.Response.Listener; import com.google.gson.JsonArray; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/reader/ReaderRestClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/reader/ReaderRestClient.java index 0fa3281e2a..ec4909b610 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/reader/ReaderRestClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/reader/ReaderRestClient.java @@ -1,7 +1,8 @@ package org.wordpress.android.fluxc.network.rest.wpcom.reader; import android.content.Context; -import android.support.annotation.NonNull; + +import androidx.annotation.NonNull; import com.android.volley.RequestQueue; import com.android.volley.Response; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/site/SiteRestClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/site/SiteRestClient.java index 43fe1631d2..2f834e75f8 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/site/SiteRestClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/site/SiteRestClient.java @@ -1,8 +1,9 @@ package org.wordpress.android.fluxc.network.rest.wpcom.site; import android.content.Context; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import com.android.volley.DefaultRetryPolicy; import com.android.volley.RequestQueue; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/stockmedia/StockMediaRestClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/stockmedia/StockMediaRestClient.java index e99493020b..793f770feb 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/stockmedia/StockMediaRestClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/stockmedia/StockMediaRestClient.java @@ -1,7 +1,8 @@ package org.wordpress.android.fluxc.network.rest.wpcom.stockmedia; import android.content.Context; -import android.support.annotation.NonNull; + +import androidx.annotation.NonNull; import com.android.volley.RequestQueue; import com.android.volley.Response; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/taxonomy/TaxonomyRestClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/taxonomy/TaxonomyRestClient.java index 5b22afbfc7..5680906249 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/taxonomy/TaxonomyRestClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/taxonomy/TaxonomyRestClient.java @@ -1,7 +1,8 @@ package org.wordpress.android.fluxc.network.rest.wpcom.taxonomy; import android.content.Context; -import android.support.annotation.NonNull; + +import androidx.annotation.NonNull; import com.android.volley.RequestQueue; import com.android.volley.Response.Listener; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/theme/ThemeRestClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/theme/ThemeRestClient.java index 05def24a89..3d7d09a762 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/theme/ThemeRestClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/theme/ThemeRestClient.java @@ -1,9 +1,10 @@ package org.wordpress.android.fluxc.network.rest.wpcom.theme; import android.content.Context; -import android.support.annotation.NonNull; import android.text.TextUtils; +import androidx.annotation.NonNull; + import com.android.volley.RequestQueue; import com.android.volley.Response; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/wporg/WPOrgAPIGsonRequest.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/wporg/WPOrgAPIGsonRequest.java index f2927388b2..0404ba0643 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/wporg/WPOrgAPIGsonRequest.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/wporg/WPOrgAPIGsonRequest.java @@ -1,6 +1,6 @@ package org.wordpress.android.fluxc.network.wporg; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import com.android.volley.Response.Listener; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/wporg/plugin/PluginWPOrgClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/wporg/plugin/PluginWPOrgClient.java index 65a8350038..a279412ec6 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/wporg/plugin/PluginWPOrgClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/wporg/plugin/PluginWPOrgClient.java @@ -1,9 +1,10 @@ package org.wordpress.android.fluxc.network.wporg.plugin; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; import android.text.TextUtils; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + import com.android.volley.Request.Method; import com.android.volley.RequestQueue; import com.android.volley.Response.Listener; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/XMLRPCRequest.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/XMLRPCRequest.java index 31019225d1..de3ca005ef 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/XMLRPCRequest.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/XMLRPCRequest.java @@ -1,8 +1,9 @@ package org.wordpress.android.fluxc.network.xmlrpc; -import android.support.annotation.NonNull; import android.util.Xml; +import androidx.annotation.NonNull; + import com.android.volley.AuthFailureError; import com.android.volley.NetworkResponse; import com.android.volley.ParseError; @@ -29,6 +30,7 @@ import java.nio.charset.Charset; import java.util.List; + // TODO: Would be great to use generics / return POJO or model direclty (see GSON code?) public class XMLRPCRequest extends BaseRequest { private static final String PROTOCOL_CHARSET = "utf-8"; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/XMLRPCUtils.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/XMLRPCUtils.java index 02f8bea85b..f7daa89880 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/XMLRPCUtils.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/XMLRPCUtils.java @@ -1,6 +1,6 @@ package org.wordpress.android.fluxc.network.xmlrpc; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import org.wordpress.android.util.MapUtils; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/comment/CommentXMLRPCClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/comment/CommentXMLRPCClient.java index 396284e8b9..16f1e9f9dc 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/comment/CommentXMLRPCClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/comment/CommentXMLRPCClient.java @@ -1,7 +1,7 @@ package org.wordpress.android.fluxc.network.xmlrpc.comment; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import com.android.volley.RequestQueue; import com.android.volley.Response.Listener; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java index 039d53b68d..5e356d7bb7 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/MediaXMLRPCClient.java @@ -1,9 +1,10 @@ package org.wordpress.android.fluxc.network.xmlrpc.media; -import android.support.annotation.NonNull; import android.text.TextUtils; import android.util.Base64; +import androidx.annotation.NonNull; + import com.android.volley.RequestQueue; import com.android.volley.Response.Listener; import com.android.volley.VolleyError; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/XmlrpcUploadRequestBody.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/XmlrpcUploadRequestBody.java index 670a1c9a1d..d1ebb57a47 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/XmlrpcUploadRequestBody.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/media/XmlrpcUploadRequestBody.java @@ -1,8 +1,9 @@ package org.wordpress.android.fluxc.network.xmlrpc.media; -import android.support.annotation.NonNull; import android.util.Base64; +import androidx.annotation.NonNull; + import org.apache.commons.lang3.StringEscapeUtils; import org.wordpress.android.fluxc.model.MediaModel; import org.wordpress.android.fluxc.model.SiteModel; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/post/PostXMLRPCClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/post/PostXMLRPCClient.java index 339f5ad7b6..f21309ae1e 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/post/PostXMLRPCClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/post/PostXMLRPCClient.java @@ -1,9 +1,10 @@ package org.wordpress.android.fluxc.network.xmlrpc.post; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; import android.text.TextUtils; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + import com.android.volley.RequestQueue; import com.android.volley.Response.Listener; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/site/SiteXMLRPCClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/site/SiteXMLRPCClient.java index 11ad47e0a0..626be24aad 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/site/SiteXMLRPCClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/site/SiteXMLRPCClient.java @@ -1,6 +1,6 @@ package org.wordpress.android.fluxc.network.xmlrpc.site; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import com.android.volley.RequestQueue; import com.android.volley.Response.Listener; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/taxonomy/TaxonomyXMLRPCClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/taxonomy/TaxonomyXMLRPCClient.java index bec1753da1..13f85685c0 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/taxonomy/TaxonomyXMLRPCClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/xmlrpc/taxonomy/TaxonomyXMLRPCClient.java @@ -1,8 +1,9 @@ package org.wordpress.android.fluxc.network.xmlrpc.taxonomy; -import android.support.annotation.NonNull; import android.text.TextUtils; +import androidx.annotation.NonNull; + import com.android.volley.RequestQueue; import com.android.volley.Response.Listener; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/AccountSqlUtils.java b/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/AccountSqlUtils.java index 1a4fce8b28..495578f6c9 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/AccountSqlUtils.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/AccountSqlUtils.java @@ -1,7 +1,9 @@ package org.wordpress.android.fluxc.persistence; import android.content.ContentValues; -import android.support.annotation.NonNull; +import android.database.sqlite.SQLiteDatabase; + +import androidx.annotation.NonNull; import com.wellsql.generated.AccountModelTable; import com.wellsql.generated.SubscriptionModelTable; @@ -24,18 +26,29 @@ public static int insertOrUpdateDefaultAccount(AccountModel account) { } public static int insertOrUpdateAccount(AccountModel account, int localId) { - if (account == null) return 0; - account.setId(localId); - List accountResults = WellSql.select(AccountModel.class) - .where() - .equals(AccountModelTable.ID, localId) - .endWhere().getAsModel(); - if (accountResults.isEmpty()) { - WellSql.insert(account).execute(); + if (account == null) { return 0; - } else { - ContentValues cv = new UpdateAllExceptId<>(AccountModel.class).toCv(account); - return updateAccount(accountResults.get(0).getId(), cv); + } + account.setId(localId); + SQLiteDatabase db = WellSql.giveMeWritableDb(); + db.beginTransaction(); + try { + List accountResults = WellSql.select(AccountModel.class) + .where() + .equals(AccountModelTable.ID, localId) + .endWhere().getAsModel(); + if (accountResults.isEmpty()) { + WellSql.insert(account).execute(); + db.setTransactionSuccessful(); + return 0; + } else { + ContentValues cv = new UpdateAllExceptId<>(AccountModel.class).toCv(account); + int result = updateAccount(accountResults.get(0).getId(), cv); + db.setTransactionSuccessful(); + return result; + } + } finally { + db.endTransaction(); } } diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/PluginSqlUtils.java b/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/PluginSqlUtils.java index f53a029ee2..3cd705b6ee 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/PluginSqlUtils.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/PluginSqlUtils.java @@ -1,9 +1,10 @@ package org.wordpress.android.fluxc.persistence; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; import android.text.TextUtils; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + import com.wellsql.generated.PluginDirectoryModelTable; import com.wellsql.generated.SitePluginModelTable; import com.wellsql.generated.WPOrgPluginModelTable; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/PostSqlUtils.java b/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/PostSqlUtils.java index 59077b88aa..992d13b54c 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/PostSqlUtils.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/PostSqlUtils.java @@ -1,10 +1,11 @@ package org.wordpress.android.fluxc.persistence; import android.content.ContentValues; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; import android.text.TextUtils; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + import com.wellsql.generated.LocalDiffModelTable; import com.wellsql.generated.LocalRevisionModelTable; import com.wellsql.generated.PostModelTable; @@ -27,8 +28,17 @@ import java.util.Collections; import java.util.List; +import javax.inject.Inject; + +import dagger.Reusable; + +@Reusable public class PostSqlUtils { - public static int insertOrUpdatePost(PostModel post, boolean overwriteLocalChanges) { + @Inject + public PostSqlUtils() { + } + + public int insertOrUpdatePost(PostModel post, boolean overwriteLocalChanges) { if (post == null) { return 0; } @@ -73,15 +83,15 @@ public static int insertOrUpdatePost(PostModel post, boolean overwriteLocalChang return 0; } - public static int insertOrUpdatePostKeepingLocalChanges(PostModel post) { + public int insertOrUpdatePostKeepingLocalChanges(PostModel post) { return insertOrUpdatePost(post, false); } - public static int insertOrUpdatePostOverwritingLocalChanges(PostModel post) { + public int insertOrUpdatePostOverwritingLocalChanges(PostModel post) { return insertOrUpdatePost(post, true); } - public static List getPostsForSite(SiteModel site, boolean getPages) { + public List getPostsForSite(SiteModel site, boolean getPages) { if (site == null) { return Collections.emptyList(); } @@ -96,7 +106,7 @@ public static List getPostsForSite(SiteModel site, boolean getPages) .getAsModel(); } - public static List getPostsForSiteWithFormat(SiteModel site, List postFormat, boolean getPages) { + public List getPostsForSiteWithFormat(SiteModel site, List postFormat, boolean getPages) { if (site == null) { return Collections.emptyList(); } @@ -112,7 +122,7 @@ public static List getPostsForSiteWithFormat(SiteModel site, List getUploadedPostsForSite(SiteModel site, boolean getPages) { + public List getUploadedPostsForSite(SiteModel site, boolean getPages) { if (site == null) { return Collections.emptyList(); } @@ -128,7 +138,7 @@ public static List getUploadedPostsForSite(SiteModel site, boolean ge .getAsModel(); } - public static List getLocalDrafts(@NonNull Integer localSiteId, boolean isPage) { + public List getLocalDrafts(@NonNull Integer localSiteId, boolean isPage) { return WellSql.select(PostModel.class) .where() .beginGroup() @@ -140,7 +150,7 @@ public static List getLocalDrafts(@NonNull Integer localSiteId, boole .getAsModel(); } - public static List getPostsByRemoteIds(@Nullable List remoteIds, int localSiteId) { + public List getPostsByRemoteIds(@Nullable List remoteIds, int localSiteId) { if (remoteIds != null && remoteIds.size() > 0) { return WellSql.select(PostModel.class) .where().isIn(PostModelTable.REMOTE_POST_ID, remoteIds) @@ -150,7 +160,7 @@ public static List getPostsByRemoteIds(@Nullable List remoteIds return Collections.emptyList(); } - public static List getPostsByLocalOrRemotePostIds( + public List getPostsByLocalOrRemotePostIds( @NonNull List localOrRemoteIds, int localSiteId) { if (localOrRemoteIds.isEmpty()) { return Collections.emptyList(); @@ -180,13 +190,13 @@ public static List getPostsByLocalOrRemotePostIds( return whereQuery.endGroup().endWhere().getAsModel(); } - public static PostModel insertPostForResult(PostModel post) { + public PostModel insertPostForResult(PostModel post) { WellSql.insert(post).asSingleTransaction(true).execute(); return post; } - public static int deletePost(PostModel post) { + public int deletePost(PostModel post) { if (post == null) { return 0; } @@ -200,7 +210,7 @@ public static int deletePost(PostModel post) { .execute(); } - public static int deleteUploadedPostsForSite(SiteModel site, boolean pages) { + public int deleteUploadedPostsForSite(SiteModel site, boolean pages) { if (site == null) { return 0; } @@ -216,11 +226,11 @@ public static int deleteUploadedPostsForSite(SiteModel site, boolean pages) { .execute(); } - public static int deleteAllPosts() { + public int deleteAllPosts() { return WellSql.delete(PostModel.class).execute(); } - public static boolean getSiteHasLocalChanges(SiteModel site) { + public boolean getSiteHasLocalChanges(SiteModel site) { return site != null && WellSql.select(PostModel.class) .where().beginGroup() .equals(PostModelTable.LOCAL_SITE_ID, site.getId()) @@ -231,7 +241,7 @@ public static boolean getSiteHasLocalChanges(SiteModel site) { .endGroup().endGroup().endWhere().getAsCursor().getCount() > 0; } - public static int getNumLocalChanges() { + public int getNumLocalChanges() { return WellSql.select(PostModel.class) .where().beginGroup() .equals(PostModelTable.IS_LOCAL_DRAFT, true) @@ -241,8 +251,7 @@ public static int getNumLocalChanges() { .getAsCursor().getCount(); } - - public static int updatePostsAutoSave(SiteModel site, final PostRemoteAutoSaveModel autoSaveModel) { + public int updatePostsAutoSave(SiteModel site, final PostRemoteAutoSaveModel autoSaveModel) { return WellSql.update(PostModel.class) .where().beginGroup() .equals(PostModelTable.LOCAL_SITE_ID, site.getId()) @@ -261,7 +270,7 @@ public ContentValues toCv(PostRemoteAutoSaveModel item) { }).execute(); } - public static void insertOrUpdateLocalRevision(LocalRevisionModel revision, List diffs) { + public void insertOrUpdateLocalRevision(LocalRevisionModel revision, List diffs) { int localRevisionModels = WellSql.select(LocalRevisionModel.class) .where().beginGroup() @@ -294,7 +303,7 @@ public static void insertOrUpdateLocalRevision(LocalRevisionModel revision, List } } - public static List getLocalRevisions(SiteModel site, PostModel post) { + public List getLocalRevisions(SiteModel site, PostModel post) { return WellSql.select(LocalRevisionModel.class) .where().beginGroup() .equals(LocalRevisionModelTable.POST_ID, post.getRemotePostId()) @@ -302,7 +311,7 @@ public static List getLocalRevisions(SiteModel site, PostMod .endGroup().endWhere().getAsModel(); } - public static List getLocalRevisionDiffs(LocalRevisionModel revision) { + public List getLocalRevisionDiffs(LocalRevisionModel revision) { return WellSql.select(LocalDiffModel.class) .where().beginGroup() .equals(LocalDiffModelTable.POST_ID, revision.getPostId()) @@ -311,7 +320,7 @@ public static List getLocalRevisionDiffs(LocalRevisionModel revi .endGroup().endWhere().getAsModel(); } - public static void deleteLocalRevisionAndDiffs(LocalRevisionModel revision) { + public void deleteLocalRevisionAndDiffs(LocalRevisionModel revision) { WellSql.delete(LocalRevisionModel.class) .where().beginGroup() .equals(LocalRevisionModelTable.REVISION_ID, revision.getRevisionId()) @@ -327,7 +336,7 @@ public static void deleteLocalRevisionAndDiffs(LocalRevisionModel revision) { .endGroup().endWhere().execute(); } - public static void deleteLocalRevisionAndDiffsOfAPostOrPage(PostModel post) { + public void deleteLocalRevisionAndDiffsOfAPostOrPage(PostModel post) { WellSql.delete(LocalRevisionModel.class) .where().beginGroup() .equals(LocalRevisionModelTable.POST_ID, post.getRemotePostId()) @@ -341,7 +350,7 @@ public static void deleteLocalRevisionAndDiffsOfAPostOrPage(PostModel post) { .endGroup().endWhere().execute(); } - public static List getLocalPostIdsForFilter(SiteModel site, boolean isPage, String searchQuery, + public List getLocalPostIdsForFilter(SiteModel site, boolean isPage, String searchQuery, String orderBy, @Order int order) { ConditionClauseBuilder> clauseBuilder = WellSql.select(PostModel.class) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/SiteSqlUtils.java b/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/SiteSqlUtils.java index f15e8f3c76..bedce41c7c 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/SiteSqlUtils.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/SiteSqlUtils.java @@ -2,7 +2,8 @@ import android.content.ContentValues; import android.database.sqlite.SQLiteConstraintException; -import android.support.annotation.NonNull; + +import androidx.annotation.NonNull; import com.wellsql.generated.AccountModelTable; import com.wellsql.generated.PostFormatModelTable; @@ -285,7 +286,7 @@ public static void insertOrReplaceUserRoles(@NonNull SiteModel site, @NonNull Li * @param sites * list of sites to keep in local database */ - public static int removeWPComRestSitesAbsentFromList(@NonNull List sites) { + public static int removeWPComRestSitesAbsentFromList(PostSqlUtils postSqlUtils, @NonNull List sites) { // get all local WP.com+Jetpack sites List localSites = WellSql.select(SiteModel.class) .where() @@ -299,7 +300,7 @@ public static int removeWPComRestSitesAbsentFromList(@NonNull List si SiteModel localSite = localIterator.next(); // don't remove sites with local changes - if (PostSqlUtils.getSiteHasLocalChanges(localSite)) { + if (postSqlUtils.getSiteHasLocalChanges(localSite)) { localIterator.remove(); } else { // don't remove local site if the remote ID matches a given site's ID diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/ThemeSqlUtils.java b/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/ThemeSqlUtils.java index aee34ff7eb..c36aa5164d 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/ThemeSqlUtils.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/ThemeSqlUtils.java @@ -1,8 +1,9 @@ package org.wordpress.android.fluxc.persistence; -import android.support.annotation.NonNull; import android.text.TextUtils; +import androidx.annotation.NonNull; + import com.wellsql.generated.ThemeModelTable; import com.yarolegovich.wellsql.WellSql; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/UploadSqlUtils.java b/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/UploadSqlUtils.java index 279d0160fb..da74a56575 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/UploadSqlUtils.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/UploadSqlUtils.java @@ -1,8 +1,9 @@ package org.wordpress.android.fluxc.persistence; import android.content.ContentValues; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import com.wellsql.generated.MediaModelTable; import com.wellsql.generated.MediaUploadModelTable; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/WellSqlConfig.java b/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/WellSqlConfig.java index a034e5b690..74f00469de 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/WellSqlConfig.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/WellSqlConfig.java @@ -5,7 +5,8 @@ import android.database.sqlite.SQLiteDatabase; import android.os.Build; import android.preference.PreferenceManager; -import android.support.annotation.StringDef; + +import androidx.annotation.StringDef; import com.yarolegovich.wellsql.DefaultWellConfig; import com.yarolegovich.wellsql.WellSql; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/store/AccountStore.java b/fluxc/src/main/java/org/wordpress/android/fluxc/store/AccountStore.java index 2504d25bf8..217e49ef0f 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/store/AccountStore.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/store/AccountStore.java @@ -1,9 +1,10 @@ package org.wordpress.android.fluxc.store; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; import android.text.TextUtils; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + import com.android.volley.VolleyError; import com.yarolegovich.wellsql.WellSql; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/store/CommentStore.java b/fluxc/src/main/java/org/wordpress/android/fluxc/store/CommentStore.java index f0b8daa0ad..4b84faa1b8 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/store/CommentStore.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/store/CommentStore.java @@ -1,8 +1,9 @@ package org.wordpress.android.fluxc.store; import android.annotation.SuppressLint; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import com.yarolegovich.wellsql.SelectQuery; import com.yarolegovich.wellsql.SelectQuery.Order; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/store/ListStore.kt b/fluxc/src/main/java/org/wordpress/android/fluxc/store/ListStore.kt index 6a21c72704..7379c62e47 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/store/ListStore.kt +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/store/ListStore.kt @@ -1,10 +1,10 @@ package org.wordpress.android.fluxc.store -import android.arch.lifecycle.Lifecycle -import android.arch.lifecycle.LiveData -import android.arch.paging.LivePagedListBuilder -import android.arch.paging.PagedList -import android.arch.paging.PagedList.BoundaryCallback +import androidx.lifecycle.Lifecycle +import androidx.lifecycle.LiveData +import androidx.paging.LivePagedListBuilder +import androidx.paging.PagedList +import androidx.paging.PagedList.BoundaryCallback import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch import org.greenrobot.eventbus.Subscribe diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java b/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java index 1a0df8f882..5c33da8457 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/store/MediaStore.java @@ -1,9 +1,10 @@ package org.wordpress.android.fluxc.store; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; import android.text.TextUtils; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + import com.wellsql.generated.MediaModelTable; import com.yarolegovich.wellsql.WellCursor; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/store/NotificationStore.kt b/fluxc/src/main/java/org/wordpress/android/fluxc/store/NotificationStore.kt index 7d31b703bf..93ac4ea4ef 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/store/NotificationStore.kt +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/store/NotificationStore.kt @@ -72,6 +72,7 @@ constructor( ) : OnChangedError enum class DeviceRegistrationErrorType { + INVALID_RESPONSE, MISSING_DEVICE_ID, GENERIC_ERROR; @@ -290,6 +291,8 @@ constructor( AppLog.e(T.NOTIFS, "Server response missing device_id - registration skipped!") DeviceRegistrationErrorType.GENERIC_ERROR -> AppLog.e(T.NOTIFS, "Error trying to register device: ${error.type} - ${error.message}") + DeviceRegistrationErrorType.INVALID_RESPONSE -> + AppLog.e(T.NOTIFS, "Server response missing response object: ${error.type} - ${error.message}") } onDeviceRegistered.error = payload.error } else { diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/store/PageStore.kt b/fluxc/src/main/java/org/wordpress/android/fluxc/store/PageStore.kt index 9a48f49f96..6716072b6c 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/store/PageStore.kt +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/store/PageStore.kt @@ -31,6 +31,7 @@ import kotlin.coroutines.suspendCoroutine @Singleton class PageStore @Inject constructor( private val postStore: PostStore, + private val postSqlUtils: PostSqlUtils, private val dispatcher: Dispatcher, private val coroutineContext: CoroutineContext ) { @@ -170,7 +171,7 @@ class PageStore @Inject constructor( suspend fun deletePageFromDb(page: PageModel): Boolean = withContext(coroutineContext) { val post = postStore.getPostByLocalPostId(page.pageId) return@withContext if (post != null) { - PostSqlUtils.deletePost(post) > 0 + postSqlUtils.deletePost(post) > 0 } else { false } @@ -182,10 +183,14 @@ class PageStore @Inject constructor( fetchPages(site, false) } - suspend fun getLocalDraftPages(site: SiteModel): List = withContext(coroutineContext) { - return@withContext PostSqlUtils.getLocalDrafts(site.id, true).map { - PageModel(post = it, site = site) - } + /** + * Get pages that have not been uploaded to the server yet. + * + * This returns [PostModel] instead of [PageModel] to accommodate the `UploadService` in WPAndroid which relies + * heavily on [PostModel]. When `UploadService` gets refactored, we should change this back to using [PageModel]. + */ + suspend fun getLocalDraftPages(site: SiteModel): List = withContext(coroutineContext) { + return@withContext postSqlUtils.getLocalDrafts(site.id, true) } private fun fetchPages(site: SiteModel, loadMore: Boolean) { diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/store/PluginStore.java b/fluxc/src/main/java/org/wordpress/android/fluxc/store/PluginStore.java index 21a41d5261..20bb4548a0 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/store/PluginStore.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/store/PluginStore.java @@ -1,7 +1,7 @@ package org.wordpress.android.fluxc.store; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/store/PostStore.java b/fluxc/src/main/java/org/wordpress/android/fluxc/store/PostStore.java index d672aa14db..2d1bf70959 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/store/PostStore.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/store/PostStore.java @@ -1,9 +1,10 @@ package org.wordpress.android.fluxc.store; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; import android.text.TextUtils; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + import com.wellsql.generated.PostModelTable; import com.yarolegovich.wellsql.SelectQuery; import com.yarolegovich.wellsql.WellSql; @@ -341,16 +342,19 @@ public enum RevisionsErrorType { private final PostRestClient mPostRestClient; private final PostXMLRPCClient mPostXMLRPCClient; + private final PostSqlUtils mPostSqlUtils; // Ensures that the UploadStore is initialized whenever the PostStore is, // to ensure actions are shadowed and repeated by the UploadStore @SuppressWarnings("unused") @Inject UploadStore mUploadStore; @Inject - public PostStore(Dispatcher dispatcher, PostRestClient postRestClient, PostXMLRPCClient postXMLRPCClient) { + public PostStore(Dispatcher dispatcher, PostRestClient postRestClient, PostXMLRPCClient postXMLRPCClient, + PostSqlUtils postSqlUtils) { super(dispatcher); mPostRestClient = postRestClient; mPostXMLRPCClient = postXMLRPCClient; + mPostSqlUtils = postSqlUtils; } @Override @@ -374,7 +378,7 @@ public PostModel instantiatePostModel(SiteModel site, boolean isPage, List post.setPostFormat(postFormat); // Insert the post into the db, updating the object to include the local ID - post = PostSqlUtils.insertPostForResult(post); + post = mPostSqlUtils.insertPostForResult(post); // id is set to -1 if insertion fails if (post.getId() == -1) { @@ -387,21 +391,21 @@ public PostModel instantiatePostModel(SiteModel site, boolean isPage, List * Returns all posts in the store for the given site as a {@link PostModel} list. */ public List getPostsForSite(SiteModel site) { - return PostSqlUtils.getPostsForSite(site, false); + return mPostSqlUtils.getPostsForSite(site, false); } /** * Returns posts with given format in the store for the given site as a {@link PostModel} list. */ public List getPostsForSiteWithFormat(SiteModel site, List postFormat) { - return PostSqlUtils.getPostsForSiteWithFormat(site, postFormat, false); + return mPostSqlUtils.getPostsForSiteWithFormat(site, postFormat, false); } /** * Returns all pages in the store for the given site as a {@link PostModel} list. */ public List getPagesForSite(SiteModel site) { - return PostSqlUtils.getPostsForSite(site, true); + return mPostSqlUtils.getPostsForSite(site, true); } /** @@ -422,14 +426,14 @@ public int getPagesCountForSite(SiteModel site) { * Returns all uploaded posts in the store for the given site. */ public List getUploadedPostsForSite(SiteModel site) { - return PostSqlUtils.getUploadedPostsForSite(site, false); + return mPostSqlUtils.getUploadedPostsForSite(site, false); } /** * Returns all uploaded pages in the store for the given site. */ public List getUploadedPagesForSite(SiteModel site) { - return PostSqlUtils.getUploadedPostsForSite(site, true); + return mPostSqlUtils.getUploadedPostsForSite(site, true); } /** @@ -450,7 +454,7 @@ public int getUploadedPagesCountForSite(SiteModel site) { * Returns all posts and pages that are local drafts for the given site. */ public List getLocalDraftPosts(@NonNull SiteModel site) { - return PostSqlUtils.getLocalDrafts(site.getId(), false); + return mPostSqlUtils.getLocalDrafts(site.getId(), false); } /** @@ -473,7 +477,7 @@ public List getPostsByLocalOrRemotePostIds(List getPostsByRemotePostIds(List remoteIds, SiteM if (site == null) { return Collections.emptyMap(); } - List postList = PostSqlUtils.getPostsByRemoteIds(remoteIds, site.getId()); + List postList = mPostSqlUtils.getPostsByRemoteIds(remoteIds, site.getId()); Map postMap = new HashMap<>(postList.size()); for (PostModel post : postList) { postMap.put(post.getRemotePostId(), post); @@ -546,14 +550,14 @@ public PostModel getPostByRemotePostId(long remoteId, SiteModel site) { } else { order = SelectQuery.ORDER_DESCENDING; } - return PostSqlUtils.getLocalPostIdsForFilter(postListDescriptor.getSite(), false, searchQuery, orderBy, order); + return mPostSqlUtils.getLocalPostIdsForFilter(postListDescriptor.getSite(), false, searchQuery, orderBy, order); } /** * returns the total number of posts with local changes across all sites */ - public static int getNumLocalChanges() { - return PostSqlUtils.getNumLocalChanges(); + public int getNumLocalChanges() { + return mPostSqlUtils.getNumLocalChanges(); } @Subscribe(threadMode = ThreadMode.ASYNC) @@ -726,7 +730,7 @@ private void handleFetchedPostList(FetchPostListResponsePayload payload) { private void fetchPosts(FetchPostsPayload payload, boolean pages) { int offset = 0; if (payload.loadMore) { - offset = PostSqlUtils.getUploadedPostsForSite(payload.site, pages).size(); + offset = mPostSqlUtils.getUploadedPostsForSite(payload.site, pages).size(); } if (payload.site.isUsingWpComRestApi()) { @@ -791,7 +795,7 @@ private void handlePostSuccessfullyTrashed(DeletedPostPayload payload) { mDispatcher.dispatch( PostActionBuilder.newFetchPostAction(new RemotePostPayload(postToSave, payload.site))); } - PostSqlUtils.insertOrUpdatePostOverwritingLocalChanges(postToSave); + mPostSqlUtils.insertOrUpdatePostOverwritingLocalChanges(postToSave); } private void handleFetchPostsCompleted(FetchPostsResponsePayload payload) { @@ -812,12 +816,12 @@ private void handleFetchPostsCompleted(FetchPostsResponsePayload payload) { // This is the simplest way of keeping our local posts in sync with remote posts (in case of deletions, // or if the user manual changed some post IDs) if (!payload.loadedMore) { - PostSqlUtils.deleteUploadedPostsForSite(payload.site, payload.isPages); + mPostSqlUtils.deleteUploadedPostsForSite(payload.site, payload.isPages); } int rowsAffected = 0; for (PostModel post : payload.posts.getPosts()) { - rowsAffected += PostSqlUtils.insertOrUpdatePostKeepingLocalChanges(post); + rowsAffected += mPostSqlUtils.insertOrUpdatePostKeepingLocalChanges(post); } onPostChanged = new OnPostChanged(causeOfChange, rowsAffected, payload.canLoadMore); @@ -866,7 +870,7 @@ private void handlePushPostCompleted(RemotePostPayload payload) { // XML-RPC does not respond to new/edit post calls with the modified post // Update the post locally to reflect its uploaded status, but also request a fresh copy // from the server to ensure local copy matches server - PostSqlUtils.insertOrUpdatePostOverwritingLocalChanges(payload.post); + mPostSqlUtils.insertOrUpdatePostOverwritingLocalChanges(payload.post); mPostXMLRPCClient.fetchPost(payload.post, payload.site, PostAction.PUSH_POST); } } @@ -885,7 +889,7 @@ private void handleRestorePostCompleted(RemotePostPayload payload, boolean synci // XML-RPC responds to post restore request with status boolean // Update the post locally to reflect its published state, and request a fresh copy // from the server to ensure local copy matches server - PostSqlUtils.insertOrUpdatePostOverwritingLocalChanges(payload.post); + mPostSqlUtils.insertOrUpdatePostOverwritingLocalChanges(payload.post); mPostXMLRPCClient.fetchPost(payload.post, payload.site, PostAction.RESTORE_POST); } } @@ -909,7 +913,7 @@ private void updatePost(PostModel post, boolean changeLocalDate) { if (changeLocalDate) { post.setDateLocallyChanged((DateTimeUtils.iso8601UTCFromDate(DateTimeUtils.nowUTC()))); } - int rowsAffected = PostSqlUtils.insertOrUpdatePostOverwritingLocalChanges(post); + int rowsAffected = mPostSqlUtils.insertOrUpdatePostOverwritingLocalChanges(post); CauseOfOnPostChanged causeOfChange = new CauseOfOnPostChanged.UpdatePost(post.getId(), post.getRemotePostId()); OnPostChanged onPostChanged = new OnPostChanged(causeOfChange, rowsAffected); emitChange(onPostChanged); @@ -925,7 +929,7 @@ private void removePost(PostModel post) { mDispatcher.dispatch(ListActionBuilder.newListItemsRemovedAction( new ListItemsRemovedPayload(PostListDescriptor.calculateTypeIdentifier(post.getLocalSiteId()), Collections.singletonList(post.getRemotePostId())))); - int rowsAffected = PostSqlUtils.deletePost(post); + int rowsAffected = mPostSqlUtils.deletePost(post); CauseOfOnPostChanged causeOfChange = new CauseOfOnPostChanged.RemovePost(post.getId(), post.getRemotePostId()); OnPostChanged onPostChanged = new OnPostChanged(causeOfChange, rowsAffected); @@ -933,13 +937,13 @@ private void removePost(PostModel post) { } private void removeAllPosts() { - int rowsAffected = PostSqlUtils.deleteAllPosts(); + int rowsAffected = mPostSqlUtils.deleteAllPosts(); OnPostChanged event = new OnPostChanged(RemoveAllPosts.INSTANCE, rowsAffected); emitChange(event); } private void restorePost(PostModel postModel) { - int rowsAffected = PostSqlUtils.insertOrUpdatePostOverwritingLocalChanges(postModel); + int rowsAffected = mPostSqlUtils.insertOrUpdatePostOverwritingLocalChanges(postModel); CauseOfOnPostChanged causeOfChange = new CauseOfOnPostChanged.RestorePost(postModel.getId(), postModel.getRemotePostId()); OnPostChanged onPostChanged = new OnPostChanged(causeOfChange, rowsAffected); @@ -965,7 +969,7 @@ private void handleRemoteAutoSavedPost(RemoteAutoSavePostPayload payload) { onPostChanged = new OnPostChanged(causeOfChange, 0); onPostChanged.error = payload.error; } else { - int rowsAffected = PostSqlUtils.updatePostsAutoSave(payload.site, payload.autoSaveModel); + int rowsAffected = mPostSqlUtils.updatePostsAutoSave(payload.site, payload.autoSaveModel); if (rowsAffected != 1) { String errorMsg = "Updating fields of a single post affected: " + rowsAffected + " rows"; AppLog.e(AppLog.T.API, errorMsg); @@ -993,12 +997,12 @@ public void setLocalRevision(RevisionModel model, SiteModel site, PostModel post contentDiff, LocalDiffType.CONTENT, localRevision)); } - PostSqlUtils.insertOrUpdateLocalRevision(localRevision, localDiffs); + mPostSqlUtils.insertOrUpdateLocalRevision(localRevision, localDiffs); } public RevisionModel getLocalRevision(SiteModel site, PostModel post) { - List localRevisions = PostSqlUtils.getLocalRevisions(site, post); + List localRevisions = mPostSqlUtils.getLocalRevisions(site, post); if (localRevisions.isEmpty()) { return null; @@ -1007,17 +1011,17 @@ public RevisionModel getLocalRevision(SiteModel site, PostModel post) { // we currently only support one local revision per post or page LocalRevisionModel localRevision = localRevisions.get(0); List localDiffs = - PostSqlUtils.getLocalRevisionDiffs(localRevision); + mPostSqlUtils.getLocalRevisionDiffs(localRevision); return RevisionModel.fromLocalRevisionAndDiffs(localRevision, localDiffs); } public void deleteLocalRevision(RevisionModel revisionModel, SiteModel site, PostModel post) { - PostSqlUtils.deleteLocalRevisionAndDiffs( + mPostSqlUtils.deleteLocalRevisionAndDiffs( LocalRevisionModel.fromRevisionModel(revisionModel, site, post)); } public void deleteLocalRevisionOfAPostOrPage(PostModel post) { - PostSqlUtils.deleteLocalRevisionAndDiffsOfAPostOrPage(post); + mPostSqlUtils.deleteLocalRevisionAndDiffsOfAPostOrPage(post); } } diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/store/ReaderStore.java b/fluxc/src/main/java/org/wordpress/android/fluxc/store/ReaderStore.java index 5dd4272491..a9ac9b860c 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/store/ReaderStore.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/store/ReaderStore.java @@ -1,6 +1,6 @@ package org.wordpress.android.fluxc.store; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/store/SiteStore.java b/fluxc/src/main/java/org/wordpress/android/fluxc/store/SiteStore.java index 2001ca75a2..45b8aac2b4 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/store/SiteStore.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/store/SiteStore.java @@ -1,10 +1,11 @@ package org.wordpress.android.fluxc.store; import android.database.Cursor; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; import android.text.TextUtils; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + import com.wellsql.generated.SiteModelTable; import com.yarolegovich.wellsql.WellSql; import com.yarolegovich.wellsql.mapper.SelectMapper; @@ -32,6 +33,7 @@ import org.wordpress.android.fluxc.network.rest.wpcom.site.SupportedCountryResponse; import org.wordpress.android.fluxc.network.rest.wpcom.site.SupportedStateResponse; import org.wordpress.android.fluxc.network.xmlrpc.site.SiteXMLRPCClient; +import org.wordpress.android.fluxc.persistence.PostSqlUtils; import org.wordpress.android.fluxc.persistence.SiteSqlUtils; import org.wordpress.android.fluxc.persistence.SiteSqlUtils.DuplicateSiteException; import org.wordpress.android.fluxc.utils.SiteErrorUtils; @@ -896,12 +898,15 @@ public String toString() { private SiteRestClient mSiteRestClient; private SiteXMLRPCClient mSiteXMLRPCClient; + private PostSqlUtils mPostSqlUtils; @Inject - public SiteStore(Dispatcher dispatcher, SiteRestClient siteRestClient, SiteXMLRPCClient siteXMLRPCClient) { + public SiteStore(Dispatcher dispatcher, PostSqlUtils postSqlUtils, SiteRestClient siteRestClient, + SiteXMLRPCClient siteXMLRPCClient) { super(dispatcher); mSiteRestClient = siteRestClient; mSiteXMLRPCClient = siteXMLRPCClient; + mPostSqlUtils = postSqlUtils; } @Override @@ -1412,7 +1417,7 @@ private void handleFetchedSitesWPComRest(SitesModel fetchedSites) { if (res.duplicateSiteFound) { event.error = new SiteError(SiteErrorType.DUPLICATE_SITE); } - SiteSqlUtils.removeWPComRestSitesAbsentFromList(fetchedSites.getSites()); + SiteSqlUtils.removeWPComRestSitesAbsentFromList(mPostSqlUtils, fetchedSites.getSites()); } emitChange(event); } diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/store/StatsStore.kt b/fluxc/src/main/java/org/wordpress/android/fluxc/store/StatsStore.kt index 9499631852..f95cef3a61 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/store/StatsStore.kt +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/store/StatsStore.kt @@ -40,18 +40,39 @@ import org.wordpress.android.fluxc.store.StatsStore.TimeStatsType.REFERRERS import org.wordpress.android.fluxc.store.StatsStore.TimeStatsType.SEARCH_TERMS import org.wordpress.android.fluxc.store.StatsStore.TimeStatsType.VIDEOS import org.wordpress.android.fluxc.store.Store.OnChangedError +import org.wordpress.android.fluxc.utils.PreferenceUtils.PreferenceUtilsWrapper import java.util.Collections import javax.inject.Inject import javax.inject.Singleton import kotlin.coroutines.CoroutineContext val DEFAULT_INSIGHTS = listOf(POSTING_ACTIVITY, TODAY_STATS, ALL_TIME_STATS, MOST_POPULAR_DAY_AND_HOUR, COMMENTS) +const val INSIGHTS_MANAGEMENT_NEWS_CARD_SHOWN = "INSIGHTS_MANAGEMENT_NEWS_CARD_SHOWN" @Singleton class StatsStore @Inject constructor( private val coroutineContext: CoroutineContext, - private val insightTypeSqlUtils: InsightTypeSqlUtils + private val insightTypeSqlUtils: InsightTypeSqlUtils, + private val preferenceUtils: PreferenceUtilsWrapper ) { + suspend fun getInsightTypes(site: SiteModel): List = withContext(coroutineContext) { + val types = mutableListOf() + if (!preferenceUtils.getFluxCPreferences().getBoolean(INSIGHTS_MANAGEMENT_NEWS_CARD_SHOWN, false)) { + types.add(ManagementType.NEWS_CARD) + } + types.addAll(getAddedInsights(site)) + types.add(ManagementType.CONTROL) + return@withContext types + } + + fun hideInsightsManagementNewsCard() { + preferenceUtils.getFluxCPreferences().edit().putBoolean(INSIGHTS_MANAGEMENT_NEWS_CARD_SHOWN, true).apply() + } + + fun isInsightsManagementNewsCardShowing(): Boolean { + return preferenceUtils.getFluxCPreferences().getBoolean(INSIGHTS_MANAGEMENT_NEWS_CARD_SHOWN, true) + } + suspend fun getAddedInsights(site: SiteModel) = withContext(coroutineContext) { val addedInsights = insightTypeSqlUtils.selectAddedItemsOrderedByStatus(site) val removedInsights = insightTypeSqlUtils.selectRemovedItemsOrderedByStatus(site) @@ -149,6 +170,11 @@ class StatsStore PUBLICIZE } + enum class ManagementType : StatsType { + NEWS_CARD, + CONTROL + } + enum class TimeStatsType : StatsType { OVERVIEW, POSTS_AND_PAGES, diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/store/StockMediaStore.java b/fluxc/src/main/java/org/wordpress/android/fluxc/store/StockMediaStore.java index c9e22fc546..7d1e53e18e 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/store/StockMediaStore.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/store/StockMediaStore.java @@ -1,6 +1,6 @@ package org.wordpress.android.fluxc.store; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/store/TaxonomyStore.java b/fluxc/src/main/java/org/wordpress/android/fluxc/store/TaxonomyStore.java index dda07000dd..a9cf4482f4 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/store/TaxonomyStore.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/store/TaxonomyStore.java @@ -1,6 +1,6 @@ package org.wordpress.android.fluxc.store; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/store/ThemeStore.java b/fluxc/src/main/java/org/wordpress/android/fluxc/store/ThemeStore.java index 15aca74f3f..41ce37ef34 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/store/ThemeStore.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/store/ThemeStore.java @@ -1,8 +1,9 @@ package org.wordpress.android.fluxc.store; -import android.support.annotation.NonNull; import android.text.TextUtils; +import androidx.annotation.NonNull; + import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; import org.wordpress.android.fluxc.Dispatcher; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/store/UploadStore.java b/fluxc/src/main/java/org/wordpress/android/fluxc/store/UploadStore.java index 1667a23cec..76451de1b7 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/store/UploadStore.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/store/UploadStore.java @@ -1,7 +1,7 @@ package org.wordpress.android.fluxc.store; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/utils/CommentErrorUtils.java b/fluxc/src/main/java/org/wordpress/android/fluxc/utils/CommentErrorUtils.java index 5304338be3..ef09a1961e 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/utils/CommentErrorUtils.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/utils/CommentErrorUtils.java @@ -1,6 +1,6 @@ package org.wordpress.android.fluxc.utils; -import android.support.annotation.Nullable; +import androidx.annotation.Nullable; import org.wordpress.android.fluxc.model.CommentModel; import org.wordpress.android.fluxc.model.SiteModel; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/utils/MediaUtils.java b/fluxc/src/main/java/org/wordpress/android/fluxc/utils/MediaUtils.java index 3ec7c82d6d..6a040d8991 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/utils/MediaUtils.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/utils/MediaUtils.java @@ -1,9 +1,10 @@ package org.wordpress.android.fluxc.utils; -import android.support.annotation.NonNull; -import android.support.media.ExifInterface; import android.text.TextUtils; +import androidx.annotation.NonNull; +import androidx.exifinterface.media.ExifInterface; + import org.wordpress.android.fluxc.model.MediaModel; import org.wordpress.android.fluxc.network.BaseUploadRequestBody; import org.wordpress.android.util.AppLog; diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/utils/PreferenceUtils.kt b/fluxc/src/main/java/org/wordpress/android/fluxc/utils/PreferenceUtils.kt index 424b8ca389..4fb924c289 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/utils/PreferenceUtils.kt +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/utils/PreferenceUtils.kt @@ -2,10 +2,18 @@ package org.wordpress.android.fluxc.utils import android.content.Context import android.content.SharedPreferences +import javax.inject.Inject object PreferenceUtils { @JvmStatic fun getFluxCPreferences(context: Context): SharedPreferences { return context.getSharedPreferences("${context.packageName}_fluxc-preferences", Context.MODE_PRIVATE) } + + class PreferenceUtilsWrapper + @Inject constructor(private val context: Context) { + fun getFluxCPreferences(): SharedPreferences { + return PreferenceUtils.getFluxCPreferences(context) + } + } } diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/utils/SiteUtils.java b/fluxc/src/main/java/org/wordpress/android/fluxc/utils/SiteUtils.java index 931b0e5918..f551165cd5 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/utils/SiteUtils.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/utils/SiteUtils.java @@ -1,6 +1,6 @@ package org.wordpress.android.fluxc.utils; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import org.wordpress.android.fluxc.model.SiteModel; diff --git a/instaflux/build.gradle b/instaflux/build.gradle index ba8a462d09..6b1bc2adcb 100644 --- a/instaflux/build.gradle +++ b/instaflux/build.gradle @@ -16,7 +16,7 @@ apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' android { - compileSdkVersion 27 + compileSdkVersion 28 buildToolsVersion '28.0.3' defaultConfig { @@ -59,9 +59,9 @@ dependencies { exclude group: "com.android.support" } - implementation "com.android.support:appcompat-v7:$supportLibraryVersion" - implementation "com.android.support:support-v4:$supportLibraryVersion" - implementation "com.android.support:recyclerview-v7:$supportLibraryVersion" + implementation "androidx.appcompat:appcompat:1.0.2" + implementation "androidx.legacy:legacy-support-v4:1.0.0" + implementation "androidx.recyclerview:recyclerview:1.0.0" implementation 'com.squareup.picasso:picasso:2.5.2' diff --git a/instaflux/src/main/java/org/wordpress/android/fluxc/instaflux/MainInstafluxActivity.java b/instaflux/src/main/java/org/wordpress/android/fluxc/instaflux/MainInstafluxActivity.java index 529d8b8299..fb7b34f93d 100644 --- a/instaflux/src/main/java/org/wordpress/android/fluxc/instaflux/MainInstafluxActivity.java +++ b/instaflux/src/main/java/org/wordpress/android/fluxc/instaflux/MainInstafluxActivity.java @@ -3,14 +3,15 @@ import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; -import android.support.v4.app.DialogFragment; -import android.support.v4.app.FragmentTransaction; -import android.support.v7.app.AppCompatActivity; import android.text.TextUtils; import android.view.View; import android.widget.Button; import android.widget.TextView; +import androidx.appcompat.app.AppCompatActivity; +import androidx.fragment.app.DialogFragment; +import androidx.fragment.app.FragmentTransaction; + import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; import org.wordpress.android.fluxc.Dispatcher; diff --git a/instaflux/src/main/java/org/wordpress/android/fluxc/instaflux/PostActivity.java b/instaflux/src/main/java/org/wordpress/android/fluxc/instaflux/PostActivity.java index c905ac8c03..4d5936ec03 100644 --- a/instaflux/src/main/java/org/wordpress/android/fluxc/instaflux/PostActivity.java +++ b/instaflux/src/main/java/org/wordpress/android/fluxc/instaflux/PostActivity.java @@ -7,19 +7,20 @@ import android.database.Cursor; import android.net.Uri; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.v4.app.ActivityCompat; -import android.support.v4.content.ContextCompat; -import android.support.v7.app.AlertDialog; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.DividerItemDecoration; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.ProgressBar; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AlertDialog; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.app.ActivityCompat; +import androidx.core.content.ContextCompat; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; import org.wordpress.android.fluxc.Dispatcher; diff --git a/instaflux/src/main/java/org/wordpress/android/fluxc/instaflux/PostAdapter.java b/instaflux/src/main/java/org/wordpress/android/fluxc/instaflux/PostAdapter.java index 35f64deb75..ad3351bfab 100644 --- a/instaflux/src/main/java/org/wordpress/android/fluxc/instaflux/PostAdapter.java +++ b/instaflux/src/main/java/org/wordpress/android/fluxc/instaflux/PostAdapter.java @@ -1,7 +1,6 @@ package org.wordpress.android.fluxc.instaflux; import android.content.Context; -import android.support.v7.widget.RecyclerView; import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; @@ -9,6 +8,8 @@ import android.widget.ImageView; import android.widget.TextView; +import androidx.recyclerview.widget.RecyclerView; + import com.squareup.picasso.Picasso; import org.wordpress.android.fluxc.model.PostModel; diff --git a/instaflux/src/main/java/org/wordpress/android/fluxc/instaflux/SSLWarningDialog.java b/instaflux/src/main/java/org/wordpress/android/fluxc/instaflux/SSLWarningDialog.java index 77737e0316..a800b273a5 100644 --- a/instaflux/src/main/java/org/wordpress/android/fluxc/instaflux/SSLWarningDialog.java +++ b/instaflux/src/main/java/org/wordpress/android/fluxc/instaflux/SSLWarningDialog.java @@ -4,13 +4,14 @@ import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.v4.app.DialogFragment; -import android.support.v7.app.AlertDialog; import android.view.LayoutInflater; import android.view.View; import android.widget.TextView; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AlertDialog; +import androidx.fragment.app.DialogFragment; + public class SSLWarningDialog extends DialogFragment { public interface Listener { void onClick(String username, String password, String url); diff --git a/instaflux/src/main/java/org/wordpress/android/fluxc/instaflux/ThreeEditTextDialog.java b/instaflux/src/main/java/org/wordpress/android/fluxc/instaflux/ThreeEditTextDialog.java index 525ecaa91f..c81f61be59 100644 --- a/instaflux/src/main/java/org/wordpress/android/fluxc/instaflux/ThreeEditTextDialog.java +++ b/instaflux/src/main/java/org/wordpress/android/fluxc/instaflux/ThreeEditTextDialog.java @@ -4,13 +4,14 @@ import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.v4.app.DialogFragment; -import android.support.v7.app.AlertDialog; import android.view.LayoutInflater; import android.view.View; import android.widget.EditText; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AlertDialog; +import androidx.fragment.app.DialogFragment; + public class ThreeEditTextDialog extends DialogFragment { public interface Listener { void onClick(String text1, String text2, String text3); diff --git a/instaflux/src/main/res/layout/activity_post.xml b/instaflux/src/main/res/layout/activity_post.xml index 7d459d38fc..4e7f1670dc 100644 --- a/instaflux/src/main/res/layout/activity_post.xml +++ b/instaflux/src/main/res/layout/activity_post.xml @@ -7,7 +7,7 @@ android:layout_height="match_parent" tools:context="org.wordpress.android.fluxc.instaflux.PostActivity"> - diff --git a/plugins/woocommerce/build.gradle b/plugins/woocommerce/build.gradle index 87b2ae346e..ea6588842c 100644 --- a/plugins/woocommerce/build.gradle +++ b/plugins/woocommerce/build.gradle @@ -18,7 +18,7 @@ repositories { } android { - compileSdkVersion 27 + compileSdkVersion 28 buildToolsVersion '28.0.3' defaultConfig { diff --git a/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/network/rest/wpcom/wc/orderstats/OrderStatsRestClient.kt b/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/network/rest/wpcom/wc/orderstats/OrderStatsRestClient.kt index 0f593e7730..6a360eb7ef 100644 --- a/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/network/rest/wpcom/wc/orderstats/OrderStatsRestClient.kt +++ b/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/network/rest/wpcom/wc/orderstats/OrderStatsRestClient.kt @@ -83,21 +83,28 @@ class OrderStatsRestClient( val request = WPComGsonRequest.buildGetRequest(url, params, OrderStatsApiResponse::class.java, { apiResponse -> - val model = WCOrderStatsModel().apply { - this.localSiteId = site.id - this.unit = unit.toString() - this.fields = apiResponse.fields.toString() - this.data = apiResponse.data.toString() - this.quantity = quantity.toString() - this.date = date - endDate?.let { this.endDate = it } - startDate?.let { - this.startDate = startDate - this.isCustomField = true + apiResponse?.let { + val model = WCOrderStatsModel().apply { + this.localSiteId = site.id + this.unit = unit.toString() + this.fields = apiResponse.fields.toString() + this.data = apiResponse.data.toString() + this.quantity = quantity.toString() + this.date = date + endDate?.let { this.endDate = it } + startDate?.let { + this.startDate = startDate + this.isCustomField = true + } } + val payload = FetchOrderStatsResponsePayload(site, unit, model) + mDispatcher.dispatch(WCStatsActionBuilder.newFetchedOrderStatsAction(payload)) + } ?: run { + AppLog.e(T.API, "Response for url $url with param $params is null: $apiResponse") + val orderError = OrderStatsError(OrderStatsErrorType.RESPONSE_NULL, "Response object is null") + val payload = FetchOrderStatsResponsePayload(orderError, site, unit) + mDispatcher.dispatch(WCStatsActionBuilder.newFetchedOrderStatsAction(payload)) } - val payload = FetchOrderStatsResponsePayload(site, unit, model) - mDispatcher.dispatch(WCStatsActionBuilder.newFetchedOrderStatsAction(payload)) }, { networkError -> val orderError = networkErrorToOrderError(networkError) diff --git a/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/store/WCStatsStore.kt b/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/store/WCStatsStore.kt index 16da560f32..086044e43d 100644 --- a/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/store/WCStatsStore.kt +++ b/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/store/WCStatsStore.kt @@ -135,6 +135,7 @@ class WCStatsStore @Inject constructor( class OrderStatsError(val type: OrderStatsErrorType = GENERIC_ERROR, val message: String = "") : OnChangedError enum class OrderStatsErrorType { + RESPONSE_NULL, INVALID_PARAM, GENERIC_ERROR;