Skip to content
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

Refactor DocumentPropertiesAsyncTaskLoader to Kotlin #285

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion app/src/main/java/app/grapheneos/pdfviewer/PdfViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ private int getWebViewRelease() {
@NonNull
@Override
public Loader<List<CharSequence>> onCreateLoader(int id, Bundle args) {
return new DocumentPropertiesAsyncTaskLoader(this, args.getString(KEY_PROPERTIES), mNumPages, mUri);
return new DocumentPropertiesAsyncTaskLoader(this, args.getString(KEY_PROPERTIES), mNumPages, mUri).asLoader();
}

@Override
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package app.grapheneos.pdfviewer.loader

import android.content.Context
import android.net.Uri
import androidx.loader.content.AsyncTaskLoader
import androidx.loader.content.Loader

class DocumentPropertiesAsyncTaskLoader(context: Context, private val mProperties: String, private val mNumPages: Int, private val mUri: Uri):
AsyncTaskLoader<List<CharSequence>>(context) {

companion object {
const val TAG = "DocumentPropertiesLoader"
const val ID = 1
}

//Workaround till PdfViewer is migrated to Kotlin
fun asLoader() = this as Loader<List<CharSequence>>

override fun onStartLoading() {
super.onStartLoading()
forceLoad()
}

override fun loadInBackground(): List<CharSequence> {
val loader = DocumentPropertiesLoader(
context,
mProperties,
mNumPages,
mUri
)
return loader.loadAsList()
}
}