-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20301 from wordpress-mobile/issue/20189-post-sync…
…-before-editing [Offline Mode] Post sync before editing
- Loading branch information
Showing
14 changed files
with
285 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
WordPress/src/main/java/org/wordpress/android/modules/PostModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.wordpress.android.modules | ||
|
||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import org.wordpress.android.ui.posts.IPostFreshnessChecker | ||
import org.wordpress.android.ui.posts.PostFreshnessCheckerImpl | ||
import javax.inject.Singleton | ||
|
||
@InstallIn(SingletonComponent::class) | ||
@Module | ||
class PostModule { | ||
@Singleton | ||
@Provides | ||
fun providePostFreshnessChecker(): IPostFreshnessChecker = PostFreshnessCheckerImpl() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
WordPress/src/main/java/org/wordpress/android/ui/posts/IPostFreshnessChecker.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.wordpress.android.ui.posts | ||
|
||
import org.wordpress.android.fluxc.model.PostImmutableModel | ||
|
||
/** | ||
* This interface is implemented by a component that determines if a post | ||
* is "fresh" or we need to refetch it from the backend. | ||
*/ | ||
interface IPostFreshnessChecker { | ||
fun shouldRefreshPost(post: PostImmutableModel): Boolean | ||
} | ||
|
||
interface TimeProvider { | ||
fun currentTimeMillis(): Long | ||
} | ||
|
25 changes: 25 additions & 0 deletions
25
WordPress/src/main/java/org/wordpress/android/ui/posts/PostFreshnessCheckerImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.wordpress.android.ui.posts | ||
|
||
import org.wordpress.android.fluxc.model.PostImmutableModel | ||
|
||
class PostFreshnessCheckerImpl( | ||
private val timeProvider: TimeProvider = SystemTimeProvider() | ||
) : IPostFreshnessChecker { | ||
override fun shouldRefreshPost(post: PostImmutableModel): Boolean { | ||
return postNeedsRefresh(post) | ||
} | ||
|
||
private fun postNeedsRefresh(post: PostImmutableModel) : Boolean { | ||
return timeProvider.currentTimeMillis() - post.dbTimestamp > CACHE_VALIDITY_MILLIS | ||
} | ||
|
||
companion object { | ||
// Todo turn this into a remote config value | ||
const val CACHE_VALIDITY_MILLIS = 20000 | ||
} | ||
} | ||
|
||
class SystemTimeProvider : TimeProvider { | ||
override fun currentTimeMillis(): Long = System.currentTimeMillis() | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
WordPress/src/main/java/org/wordpress/android/util/config/SyncPublishingFeatureConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.wordpress.android.util.config | ||
|
||
import org.wordpress.android.BuildConfig | ||
import org.wordpress.android.annotation.Feature | ||
import javax.inject.Inject | ||
|
||
private const val SYNC_PUBLISHING_FEATURE_REMOTE_FIELD = "sync_publishing" | ||
|
||
@Feature(SYNC_PUBLISHING_FEATURE_REMOTE_FIELD, false) | ||
class SyncPublishingFeatureConfig @Inject constructor( | ||
appConfig: AppConfig | ||
) : FeatureConfig( | ||
appConfig, | ||
BuildConfig.SYNC_PUBLISHING, | ||
SYNC_PUBLISHING_FEATURE_REMOTE_FIELD | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.