From ed9358a3cc230bb97d86456a1f1b8a5de8b71225 Mon Sep 17 00:00:00 2001 From: Oguz Kocer Date: Tue, 31 Oct 2023 19:31:35 -0400 Subject: [PATCH] Try wordpress-rs --- WordPress/build.gradle | 3 +++ .../android/ui/posts/PostListMainViewModel.kt | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/WordPress/build.gradle b/WordPress/build.gradle index 8e74183734e5..3e592d0db48b 100644 --- a/WordPress/build.gradle +++ b/WordPress/build.gradle @@ -36,6 +36,7 @@ repositories { includeGroup "org.wordpress.fluxc" includeGroup "org.wordpress.wellsql" includeGroup "org.wordpress.gutenberg-mobile" + includeGroup "rs.wordpress" includeGroupByRegex "org.wordpress.react-native-libraries.*" includeGroup "com.automattic" includeGroup "com.automattic.stories" @@ -342,6 +343,8 @@ kapt { } dependencies { + implementation 'rs.wordpress:wp_api:trunk-e0af8e4b7ad36852136b097ab28e6c2061f9f61f' + implementation 'androidx.webkit:webkit:1.10.0' implementation "androidx.navigation:navigation-compose:$androidxComposeNavigationVersion" compileOnly project(path: ':libs:annotations') diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostListMainViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostListMainViewModel.kt index e5a5caf976da..9cfe43a1ccb1 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostListMainViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostListMainViewModel.kt @@ -41,6 +41,7 @@ import org.wordpress.android.ui.posts.PostListType.TRASHED import org.wordpress.android.ui.prefs.AppPrefsWrapper import org.wordpress.android.ui.uploads.UploadActionUseCase import org.wordpress.android.ui.uploads.UploadStarter +import org.wordpress.android.ui.utils.UiString import org.wordpress.android.ui.utils.UiString.UiStringRes import org.wordpress.android.util.AppLog import org.wordpress.android.util.NetworkUtilsWrapper @@ -54,6 +55,8 @@ import org.wordpress.android.viewmodel.helpers.ToastMessageHolder import org.wordpress.android.viewmodel.posts.PostFetcher import org.wordpress.android.viewmodel.posts.PostListItemIdentifier.LocalPostId import org.wordpress.android.viewmodel.posts.PostListViewModelConnector +import rs.wordpress.wp_api.Library +import uniffi.wp_api.WpAuthentication import javax.inject.Inject import javax.inject.Named import kotlin.coroutines.CoroutineContext @@ -290,6 +293,21 @@ class PostListMainViewModel @Inject constructor( savePostToDbUseCase.savePostToDb(editPostRepository, site) }) } + + fetchPostListFromRust() + } + + private fun fetchPostListFromRust() { + // This is an empty test site that'll be destroyed in a few days. This authentication + // token is only temporarily shared to collaborate and will be discarded within a day. + val rustLibrary = Library("https://stupendous-poetry-koala.jurassic.ninja", WpAuthentication("ZGVtbzo2cjFTIHhySlogN2k0RSBXM0J0IEs1dUMgUGN5Yg==")) + launch { + val firstPostTitle = rustLibrary.makePostListRequest().postList!!.first().title!!.raw + withContext(mainDispatcher) { + _snackBarMessage.value = + SnackbarMessageHolder(message = UiString.UiStringText("Fetched first post title from Rust: $firstPostTitle")) + } + } } override fun onCleared() { @@ -382,6 +400,7 @@ class PostListMainViewModel @Inject constructor( ) } + fun showTargetPost(targetPostId: Int) { val postModel = postStore.getPostByLocalPostId(targetPostId) if (postModel == null) {