apps-android-wikipedia icon indicating copy to clipboard operation
apps-android-wikipedia copied to clipboard

Export reading list into a csv file

Open sharvaniharan opened this issue 3 years ago • 2 comments

Phab: https://phabricator.wikimedia.org/T316839

sharvaniharan avatar Sep 02 '22 17:09 sharvaniharan

A couple of (unsolicited) notes and hints:

  • Requesting permissions is only necessary for API <29. For API 29+, scoped storage will work automatically.
  • Opening a file in the Downloads directory automatically can be done with getExternalStoragePublicDirectory(...) for <29, and for 29+ using contentResolver.insert(...).
  • When showing a notification after the file is written, the intent of the notification can go directly to the Downloads directory: intent = Intent(DownloadManager.ACTION_VIEW_DOWNLOADS)

dbrant avatar Sep 09 '22 19:09 dbrant

@sharvaniharan Here's some rough code for creating a file in the Downloads folder using scoped storage (for API 29+):

val fileName = "foo.csv"

val contentResolver = context.contentResolver
val contentValues = ContentValues()
contentValues.put(MediaStore.MediaColumns.DISPLAY_NAME, fileName) // The file name is just the name, not the full path!
contentValues.put(MediaStore.MediaColumns.MIME_TYPE, "text/csv")
val uri = contentResolver.insert(MediaStore.Downloads.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY), contentValues)

val outputStream = contentResolver.openOutputStream(uri!!)!!

dbrant avatar Sep 15 '22 17:09 dbrant

@sharvaniharan One of the requirements in the phab task is to export multiple lists, which means implementing "multi-select" logic in the reading lists screen. Will that be part of this PR, or a follow-on PR?

dbrant avatar Sep 30 '22 18:09 dbrant

@dbrant will be doing that in a separate PR.

sharvaniharan avatar Oct 04 '22 20:10 sharvaniharan