Skip to content

Convert ReaderPostPagerActivity to Kotlin #21822

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Apr 22, 2025
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
6d429ca
Make ReaderPostPagerActivity fullscreen
nbradbury Apr 18, 2025
bc635fb
Reverted custom theme
nbradbury Apr 18, 2025
7619d7d
Use EdgeToEdge.enable
nbradbury Apr 18, 2025
9c0c027
Converted pager activity to ConstraintLayout
nbradbury Apr 18, 2025
486b4f1
Don't overlay navigation bar
nbradbury Apr 18, 2025
8e89c95
Hide navigation bar
nbradbury Apr 18, 2025
d8164fd
Only enable fullscreen for Android 33+
nbradbury Apr 18, 2025
945e219
Use non-deprecated fullscreen
nbradbury Apr 19, 2025
b91225a
Rename .java to .kt
nbradbury Apr 19, 2025
702f0af
First pass at converting ReaderPostPagerActivity to Kotlin
nbradbury Apr 19, 2025
704dcb9
Second pass at converting ReaderPostPagerActivity to Kotlin
nbradbury Apr 19, 2025
7569197
Use lateinit var
nbradbury Apr 21, 2025
ff95fed
Fixed unnecessary nonnull assertions
nbradbury Apr 21, 2025
5ee2306
Suppress deprecation warnings
nbradbury Apr 21, 2025
d43abd9
First pass at renaming variables
nbradbury Apr 21, 2025
137373c
Second pass at renaming variables
nbradbury Apr 21, 2025
4e84109
Use BundleCompat for serializable extras
nbradbury Apr 21, 2025
ab9df83
Suppress unchecked cast
nbradbury Apr 21, 2025
57262de
Renamed adapter variables
nbradbury Apr 21, 2025
f0360f3
Moved adapter
nbradbury Apr 21, 2025
beb2287
Mark class deprecated
nbradbury Apr 21, 2025
78cbb9f
Merge branch 'trunk' of https://github.com/wordpress-mobile/WordPress…
nbradbury Apr 21, 2025
8e922b2
Removed Java activity
nbradbury Apr 21, 2025
2d42224
Fixed Detekt warnings
nbradbury Apr 21, 2025
06cb147
Merge branch 'trunk' into issue/CMM-288-kotlin-reader-post-pager-acti…
nbradbury Apr 22, 2025
dee7d20
Merge branch 'trunk' into issue/CMM-288-kotlin-reader-post-pager-acti…
nbradbury Apr 22, 2025
1f0f899
Use Kotlin isNullOrEmpty instead of TextUtils.isEmpty
nbradbury Apr 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Moved adapter
  • Loading branch information
nbradbury committed Apr 21, 2025
commit f0360f37f96ac6c9ebc0fee628c289e796cfaa96
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,84 @@ class ReaderPostPagerActivity : BaseAppCompatActivity() {
ActivityLauncher.loginWithoutMagicLink(this)
}

@Deprecated("Deprecated in Java")
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)

when (requestCode) {
RequestCodes.EDIT_POST -> {
if (resultCode != RESULT_OK || data == null || isFinishing) {
return
}
val localId = data.getIntExtra(EditPostActivityConstants.EXTRA_POST_LOCAL_ID, 0)
val site = data.extras?.let {
BundleCompat.getSerializable(
it,
WordPress.SITE,
SiteModel::class.java
)
}
val post = postStore.getPostByLocalPostId(localId)

if (checkToRestart(data)) {
ActivityLauncher.editPostOrPageForResult(
data,
this@ReaderPostPagerActivity, site,
data.getIntExtra(EditPostActivityConstants.EXTRA_POST_LOCAL_ID, 0)
)

// a restart will happen so, no need to continue here
return
}

val snackbarAttachView = findViewById<View>(R.id.coordinator)
if (site != null && post != null && snackbarAttachView != null) {
uploadUtilsWrapper.handleEditPostResultSnackbars(
this,
snackbarAttachView,
data,
post,
site,
uploadActionUseCase.getUploadAction(post),
{ _: View? ->
UploadUtils.publishPost(
this@ReaderPostPagerActivity,
post,
site,
dispatcher
)
})
}
}

RequestCodes.DO_LOGIN -> if (resultCode == RESULT_OK) {
backFromLogin = true
}

RequestCodes.NO_REBLOG_SITE -> if (resultCode == RESULT_OK) {
finish() // Finish activity to make My Site page visible
}
}
}

@Suppress("unused")
@Subscribe(threadMode = ThreadMode.MAIN)
fun onPostUploaded(event: OnPostUploaded) {
val site = siteStore.getSiteByLocalId(selectedSiteRepository.getSelectedSiteLocalId())
val snackbarAttachView = findViewById<View>(R.id.coordinator)
if (site != null && event.post != null && snackbarAttachView != null) {
uploadUtilsWrapper.onPostUploadedSnackbarHandler(
this,
snackbarAttachView,
event.isError,
event.isFirstTimePublish,
event.post,
null,
site
)
}
}

/**
* pager adapter containing post detail fragments
*/
Expand Down Expand Up @@ -1134,82 +1212,4 @@ class ReaderPostPagerActivity : BaseAppCompatActivity() {
}
}
}

@Deprecated("Deprecated in Java")
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)

when (requestCode) {
RequestCodes.EDIT_POST -> {
if (resultCode != RESULT_OK || data == null || isFinishing) {
return
}
val localId = data.getIntExtra(EditPostActivityConstants.EXTRA_POST_LOCAL_ID, 0)
val site = data.extras?.let {
BundleCompat.getSerializable(
it,
WordPress.SITE,
SiteModel::class.java
)
}
val post = postStore.getPostByLocalPostId(localId)

if (checkToRestart(data)) {
ActivityLauncher.editPostOrPageForResult(
data,
this@ReaderPostPagerActivity, site,
data.getIntExtra(EditPostActivityConstants.EXTRA_POST_LOCAL_ID, 0)
)

// a restart will happen so, no need to continue here
return
}

val snackbarAttachView = findViewById<View>(R.id.coordinator)
if (site != null && post != null && snackbarAttachView != null) {
uploadUtilsWrapper.handleEditPostResultSnackbars(
this,
snackbarAttachView,
data,
post,
site,
uploadActionUseCase.getUploadAction(post),
{ _: View? ->
UploadUtils.publishPost(
this@ReaderPostPagerActivity,
post,
site,
dispatcher
)
})
}
}

RequestCodes.DO_LOGIN -> if (resultCode == RESULT_OK) {
backFromLogin = true
}

RequestCodes.NO_REBLOG_SITE -> if (resultCode == RESULT_OK) {
finish() // Finish activity to make My Site page visible
}
}
}

@Suppress("unused")
@Subscribe(threadMode = ThreadMode.MAIN)
fun onPostUploaded(event: OnPostUploaded) {
val site = siteStore.getSiteByLocalId(selectedSiteRepository.getSelectedSiteLocalId())
val snackbarAttachView = findViewById<View>(R.id.coordinator)
if (site != null && event.post != null && snackbarAttachView != null) {
uploadUtilsWrapper.onPostUploadedSnackbarHandler(
this,
snackbarAttachView,
event.isError,
event.isFirstTimePublish,
event.post,
null,
site
)
}
}
}