Skip to content

Commit ebb6f32

Browse files
committed
added WebView download listener
1 parent 35820f8 commit ebb6f32

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

mobile/src/main/java/net/activitywatch/android/MainActivity.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,6 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
108108
R.id.nav_dashboard -> {
109109
fragmentClass = TestFragment::class.java
110110
}
111-
R.id.nav_buckets -> {
112-
fragmentClass = BucketListFragment::class.java
113-
}
114111
R.id.nav_webui -> {
115112
fragmentClass = WebUIFragment::class.java
116113
}

mobile/src/main/java/net/activitywatch/android/RustInterface.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class RustInterface constructor(context: Context? = null) {
9595

9696
fun getEventsJSON(bucket_id: String, limit: Int = 0): JSONArray {
9797
// TODO: Handle errors
98-
// TODO: Use limit
98+
// FIXME: Use limit (will have major performance benefits)
9999
val result = getEvents(bucket_id)
100100
return try {
101101
JSONArray(result)

mobile/src/main/java/net/activitywatch/android/fragments/WebUIFragment.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package net.activitywatch.android.fragments
22

33
import android.content.Context
4+
import android.content.Intent
45
import android.content.pm.ApplicationInfo
56
import android.net.Uri
67
import android.os.Bundle
@@ -18,7 +19,8 @@ import android.content.pm.ApplicationInfo.FLAG_DEBUGGABLE
1819
import android.os.Build
1920
import android.os.Build.VERSION_CODES.KITKAT
2021
import android.os.Build.VERSION.SDK_INT
21-
22+
import android.content.Intent.ACTION_VIEW
23+
import android.webkit.DownloadListener
2224

2325

2426
// TODO: Rename parameter arguments, choose names that match
@@ -64,6 +66,12 @@ class WebUIFragment : Fragment() {
6466

6567
val myWebView: WebView = view.findViewById(R.id.webview) as WebView
6668

69+
myWebView.setDownloadListener { url, _, _, _, _ ->
70+
val i = Intent(ACTION_VIEW)
71+
i.data = Uri.parse(url)
72+
startActivity(i)
73+
}
74+
6775
myWebView.settings.javaScriptEnabled = true
6876
myWebView.settings.domStorageEnabled = true
6977
myWebView.loadUrl("http://127.0.0.1:5600")

0 commit comments

Comments
 (0)