Skip to content

Commit

Permalink
fix: attempt at fixing CSV exports crashing app
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBjare committed Jan 5, 2024
1 parent a082295 commit 9169e3a
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class WebUIFragment : Fragment() {

myWebView.settings.javaScriptEnabled = true
myWebView.settings.domStorageEnabled = true
myWebView.addJavascriptInterface(WebAppInterface(context), "Android")

Check failure on line 100 in mobile/src/main/java/net/activitywatch/android/fragments/WebUIFragment.kt

View workflow job for this annotation

GitHub Actions / Test

Type mismatch: inferred type is Context? but Context was expected

Check failure on line 100 in mobile/src/main/java/net/activitywatch/android/fragments/WebUIFragment.kt

View workflow job for this annotation

GitHub Actions / Test

Type mismatch: inferred type is Context? but Context was expected

Check failure on line 100 in mobile/src/main/java/net/activitywatch/android/fragments/WebUIFragment.kt

View workflow job for this annotation

GitHub Actions / Build aab

Type mismatch: inferred type is Context? but Context was expected
arguments?.let {
it.getString(ARG_URL)?.let { it1 -> myWebView.loadUrl(it1) }
}
Expand Down Expand Up @@ -145,3 +146,24 @@ class WebUIFragment : Fragment() {
}
}
}

class WebAppInterface(private val mContext: Context) {
@JavascriptInterface

Check failure on line 151 in mobile/src/main/java/net/activitywatch/android/fragments/WebUIFragment.kt

View workflow job for this annotation

GitHub Actions / Test

Unresolved reference: JavascriptInterface

Check failure on line 151 in mobile/src/main/java/net/activitywatch/android/fragments/WebUIFragment.kt

View workflow job for this annotation

GitHub Actions / Test

Unresolved reference: JavascriptInterface

Check failure on line 151 in mobile/src/main/java/net/activitywatch/android/fragments/WebUIFragment.kt

View workflow job for this annotation

GitHub Actions / Build aab

Unresolved reference: JavascriptInterface
fun downloadCSV(csv: String, filename: String) {
downloadFile(csv, filename, "text/csv")
}

@JavascriptInterface

Check failure on line 156 in mobile/src/main/java/net/activitywatch/android/fragments/WebUIFragment.kt

View workflow job for this annotation

GitHub Actions / Test

Unresolved reference: JavascriptInterface

Check failure on line 156 in mobile/src/main/java/net/activitywatch/android/fragments/WebUIFragment.kt

View workflow job for this annotation

GitHub Actions / Test

Unresolved reference: JavascriptInterface

Check failure on line 156 in mobile/src/main/java/net/activitywatch/android/fragments/WebUIFragment.kt

View workflow job for this annotation

GitHub Actions / Build aab

Unresolved reference: JavascriptInterface
fun downloadJSON(csv: String, filename: String) {
downloadFile(csv, filename, "application/json")
}

fun downloadFile(csv: String, filename: String, mimetype: String) {
val file = File(mContext.getExternalFilesDir(null), filename)

Check failure on line 162 in mobile/src/main/java/net/activitywatch/android/fragments/WebUIFragment.kt

View workflow job for this annotation

GitHub Actions / Test

Unresolved reference: File

Check failure on line 162 in mobile/src/main/java/net/activitywatch/android/fragments/WebUIFragment.kt

View workflow job for this annotation

GitHub Actions / Test

Unresolved reference: File

Check failure on line 162 in mobile/src/main/java/net/activitywatch/android/fragments/WebUIFragment.kt

View workflow job for this annotation

GitHub Actions / Build aab

Unresolved reference: File
file.writeText(csv)
val intent = Intent(Intent.ACTION_VIEW)
intent.setDataAndType(Uri.fromFile(file), mimetype)
intent.flags = Intent.FLAG_ACTIVITY_NO_HISTORY
mContext.startActivity(intent)
}
}

0 comments on commit 9169e3a

Please sign in to comment.