Skip to content

Commit f72543f

Browse files
committed
fixups for android
1 parent f043c79 commit f72543f

File tree

6 files changed

+157
-97
lines changed

6 files changed

+157
-97
lines changed

android/PDFConverter/app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ android {
3434

3535
buildFeatures {
3636
viewBinding true
37+
buildConfig true
3738
}
3839
namespace 'com.profullstack.pdfconverter'
3940
}

android/PDFConverter/app/src/main/AndroidManifest.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
android:allowBackup="true"
1010
android:icon="@mipmap/ic_launcher"
1111
android:label="@string/app_name"
12-
android:roundIcon="@mipmap/ic_launcher_round"
1312
android:supportsRtl="true"
1413
android:theme="@style/Theme.PDFConverter"
1514
android:usesCleartextTraffic="true">
Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,15 @@
11
package com.profullstack.pdfconverter
22

33
import android.content.Context
4-
import java.io.File
5-
import java.io.FileInputStream
6-
import java.util.Properties
4+
import android.util.Log
75

86
object Config {
9-
// Default fallback URL
10-
private const val DEFAULT_API_BASE_URL = "https://profullstack.com/pdf"
7+
// Hardcoded production URL
8+
private const val DEFAULT_API_BASE_URL = "https://convert2doc.com"
119

12-
// Get API base URL from .env file
10+
// Get API base URL - hardcoded for simplicity
1311
fun getApiBaseUrl(context: Context): String {
14-
try {
15-
// Try to find the .env file in the project root
16-
// First, try to find it relative to the app's files directory
17-
val appDir = context.filesDir.parentFile?.parentFile?.parentFile?.parentFile?.parentFile
18-
val envFile = File(appDir, ".env")
19-
20-
if (envFile.exists()) {
21-
return parseEnvFile(envFile)
22-
}
23-
24-
// If not found, try to find it in external storage (for development)
25-
val externalDir = context.getExternalFilesDir(null)?.parentFile?.parentFile?.parentFile?.parentFile
26-
val externalEnvFile = File(externalDir, ".env")
27-
28-
if (externalEnvFile.exists()) {
29-
return parseEnvFile(externalEnvFile)
30-
}
31-
} catch (e: Exception) {
32-
e.printStackTrace()
33-
}
34-
35-
// Return default URL if .env file not found or error occurs
12+
Log.d("PDFConverter", "Using hardcoded URL: $DEFAULT_API_BASE_URL")
3613
return DEFAULT_API_BASE_URL
3714
}
38-
39-
private fun parseEnvFile(envFile: File): String {
40-
val properties = Properties()
41-
FileInputStream(envFile).use { input ->
42-
properties.load(input)
43-
}
44-
45-
// Get API_BASE_URL from properties
46-
val apiBaseUrl = properties.getProperty("API_BASE_URL")
47-
48-
// Return the URL if found, otherwise return default
49-
return apiBaseUrl ?: DEFAULT_API_BASE_URL
50-
}
5115
}
Lines changed: 83 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,44 @@
11
package com.profullstack.pdfconverter
22

33
import android.annotation.SuppressLint
4+
import android.os.Build
45
import android.os.Bundle
6+
import android.util.Log
57
import android.webkit.WebResourceError
68
import android.webkit.WebResourceRequest
79
import android.webkit.WebView
810
import android.webkit.WebViewClient
911
import android.widget.Toast
12+
import androidx.annotation.RequiresApi
1013
import androidx.appcompat.app.AppCompatActivity
11-
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
1214

1315
class MainActivity : AppCompatActivity() {
1416
private lateinit var webView: WebView
15-
private lateinit var swipeRefreshLayout: SwipeRefreshLayout
16-
// URL of the PWA - will be loaded from .env file
17+
// URL of the PWA - hardcoded for simplicity
1718
private lateinit var pwaUrl: String
1819

19-
2020
@SuppressLint("SetJavaScriptEnabled")
2121
override fun onCreate(savedInstanceState: Bundle?) {
2222
super.onCreate(savedInstanceState)
2323
setContentView(R.layout.activity_main)
2424

25-
// Get API base URL from .env file
25+
// Get API base URL from Config
2626
pwaUrl = Config.getApiBaseUrl(this)
27+
Log.d("PDFConverter", "Loading URL: $pwaUrl")
28+
29+
// Verify URL is valid
30+
try {
31+
val url = java.net.URL(pwaUrl)
32+
Log.d("PDFConverter", "URL is valid: $pwaUrl (protocol: ${url.protocol}, host: ${url.host}, path: ${url.path})")
33+
} catch (e: Exception) {
34+
Log.e("PDFConverter", "URL is invalid: $pwaUrl", e)
35+
// Fall back to hardcoded URL if the one from Config is invalid
36+
pwaUrl = "https://convert2doc.com"
37+
Log.d("PDFConverter", "Falling back to hardcoded URL: $pwaUrl")
38+
}
2739

2840
// Initialize WebView
2941
webView = findViewById(R.id.webView)
30-
swipeRefreshLayout = findViewById(R.id.swipeRefreshLayout)
3142

3243
// Configure WebView settings
3344
webView.settings.apply {
@@ -43,36 +54,63 @@ class MainActivity : AppCompatActivity() {
4354
setGeolocationEnabled(true)
4455
allowFileAccess = true
4556
allowContentAccess = true
46-
// Enable caching
47-
setAppCacheEnabled(true)
57+
// Modern caching is handled by the browser automatically
58+
cacheMode = android.webkit.WebSettings.LOAD_DEFAULT
4859
}
4960

5061
// Set WebViewClient to handle page navigation
5162
webView.webViewClient = object : WebViewClient() {
63+
override fun onPageStarted(view: WebView?, url: String?, favicon: android.graphics.Bitmap?) {
64+
super.onPageStarted(view, url, favicon)
65+
Log.d("PDFConverter", "Page loading started: $url")
66+
}
67+
5268
override fun onPageFinished(view: WebView?, url: String?) {
5369
super.onPageFinished(view, url)
54-
// Hide refresh indicator when page is loaded
55-
swipeRefreshLayout.isRefreshing = false
70+
Log.d("PDFConverter", "Page loading finished: $url")
5671
}
5772

73+
@RequiresApi(Build.VERSION_CODES.M)
5874
override fun onReceivedError(view: WebView?, request: WebResourceRequest?, error: WebResourceError?) {
5975
super.onReceivedError(view, request, error)
60-
Toast.makeText(this@MainActivity, "Error loading page", Toast.LENGTH_SHORT).show()
61-
swipeRefreshLayout.isRefreshing = false
76+
77+
val errorMessage = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
78+
"Error: ${error?.errorCode} - ${error?.description}"
79+
} else {
80+
"Error loading page"
81+
}
82+
83+
Log.e("PDFConverter", "WebView error: $errorMessage for URL: ${request?.url}")
84+
85+
// Check if this is a 404 error
86+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && error?.errorCode == -2) {
87+
Log.e("PDFConverter", "404 Not Found error detected")
88+
89+
// Try to load the fallback URL
90+
val fallbackUrl = "https://convert2doc.com"
91+
if (request?.url.toString() != fallbackUrl) {
92+
Log.d("PDFConverter", "Trying fallback URL: $fallbackUrl")
93+
view?.loadUrl(fallbackUrl)
94+
Toast.makeText(this@MainActivity, "Page not found, trying fallback URL", Toast.LENGTH_LONG).show()
95+
return
96+
}
97+
}
98+
99+
Toast.makeText(this@MainActivity, errorMessage, Toast.LENGTH_LONG).show()
62100
}
63101

64102
// Keep navigation within the WebView
65103
override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean {
104+
Log.d("PDFConverter", "Navigation to: ${request?.url}")
66105
return false
67106
}
68107
}
69108

70-
// Set up swipe to refresh
71-
swipeRefreshLayout.setOnRefreshListener {
72-
webView.reload()
73-
}
109+
// Check if URL is accessible
110+
checkUrlAccessibility(pwaUrl)
74111

75112
// Load the PWA
113+
Log.d("PDFConverter", "Loading PWA URL: $pwaUrl")
76114
webView.loadUrl(pwaUrl)
77115
}
78116

@@ -84,4 +122,33 @@ class MainActivity : AppCompatActivity() {
84122
super.onBackPressed()
85123
}
86124
}
125+
126+
// Check if URL is accessible
127+
private fun checkUrlAccessibility(url: String) {
128+
Thread {
129+
try {
130+
Log.d("PDFConverter", "Checking URL accessibility: $url")
131+
val connection = java.net.URL(url).openConnection() as java.net.HttpURLConnection
132+
connection.connectTimeout = 5000
133+
connection.readTimeout = 5000
134+
connection.requestMethod = "HEAD"
135+
val responseCode = connection.responseCode
136+
Log.d("PDFConverter", "URL accessibility check result: $url - Response code: $responseCode")
137+
138+
if (responseCode == 200) {
139+
Log.d("PDFConverter", "URL is accessible: $url")
140+
} else {
141+
Log.e("PDFConverter", "URL is not accessible: $url - Response code: $responseCode")
142+
runOnUiThread {
143+
Toast.makeText(this@MainActivity, "Warning: URL may not be accessible (HTTP $responseCode)", Toast.LENGTH_LONG).show()
144+
}
145+
}
146+
} catch (e: Exception) {
147+
Log.e("PDFConverter", "Error checking URL accessibility: $url", e)
148+
runOnUiThread {
149+
Toast.makeText(this@MainActivity, "Warning: Could not check URL accessibility", Toast.LENGTH_LONG).show()
150+
}
151+
}
152+
}.start()
153+
}
87154
}
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
2+
<FrameLayout
33
xmlns:android="http://schemas.android.com/apk/res/android"
44
xmlns:app="http://schemas.android.com/apk/res-auto"
55
xmlns:tools="http://schemas.android.com/tools"
6-
android:id="@+id/swipeRefreshLayout"
76
android:layout_width="match_parent"
87
android:layout_height="match_parent"
98
tools:context=".MainActivity">
@@ -13,4 +12,4 @@
1312
android:layout_width="match_parent"
1413
android:layout_height="match_parent" />
1514

16-
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
15+
</FrameLayout>

public/js/components/document-history.js

Lines changed: 66 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,54 @@ export class DocumentHistory extends BaseComponent {
3939
margin-bottom: 20px;
4040
}
4141
42-
.history-table {
42+
.history-list {
4343
width: 100%;
44-
border-collapse: collapse;
44+
list-style-position: inside;
45+
padding: 0;
4546
margin-bottom: 20px;
4647
}
4748
48-
.history-table th,
49-
.history-table td {
50-
padding: 10px;
51-
text-align: left;
52-
border-bottom: 1px solid #ddd;
49+
.history-item {
50+
padding: 15px;
51+
margin-bottom: 10px;
52+
border: 1px solid #ddd;
53+
border-radius: 4px;
54+
background-color: var(--background-color);
5355
}
5456
55-
.history-table th {
56-
background-color: var(--background-color-alt);
57+
.history-item:hover {
58+
background-color: var(--hover-color, rgba(0, 0, 0, 0.05));
59+
}
60+
61+
.history-item-header {
62+
display: flex;
63+
justify-content: space-between;
64+
align-items: center;
65+
margin-bottom: 10px;
66+
}
67+
68+
.history-item-type {
5769
font-weight: bold;
70+
font-size: 16px;
5871
}
5972
60-
.history-table tr:hover {
61-
background-color: var(--hover-color, rgba(0, 0, 0, 0.05));
73+
.history-item-date {
74+
color: #666;
75+
font-size: 14px;
76+
}
77+
78+
.history-item-details {
79+
margin-bottom: 10px;
80+
}
81+
82+
.history-item-detail {
83+
margin-bottom: 5px;
84+
}
85+
86+
.history-item-label {
87+
font-weight: bold;
88+
display: inline-block;
89+
margin-right: 5px;
6290
}
6391
6492
.download-link {
@@ -222,31 +250,33 @@ export class DocumentHistory extends BaseComponent {
222250
}
223251

224252
return `
225-
<table class="history-table">
226-
<thead>
227-
<tr>
228-
<th>Type</th>
229-
<th>Generated At</th>
230-
<th>Storage Path</th>
231-
<th>Metadata</th>
232-
<th>Actions</th>
233-
</tr>
234-
</thead>
235-
<tbody>
236-
${this._history.map(item => `
237-
<tr>
238-
<td>${this._formatDocumentType(item.document_type)}</td>
239-
<td>${this._formatDate(item.generated_at)}</td>
240-
<td>${item.storage_path}</td>
241-
<td>${this._formatMetadata(item.metadata)}</td>
242-
<td class="action-buttons">
243-
<button class="download-link" data-path="${item.storage_path}">Download</button>
244-
${item.source_doc ? `<button class="edit-link" data-source="${encodeURIComponent(item.source_doc)}" data-type="${item.document_type}">Edit</button>` : ''}
245-
</td>
246-
</tr>
247-
`).join('')}
248-
</tbody>
249-
</table>
253+
<ol class="history-list">
254+
${this._history.map(item => `
255+
<li class="history-item">
256+
<div class="history-item-header">
257+
<div class="history-item-type">${this._formatDocumentType(item.document_type)}</div>
258+
<div class="history-item-date">${this._formatDate(item.generated_at)}</div>
259+
</div>
260+
261+
<div class="history-item-details">
262+
<div class="history-item-detail">
263+
<span class="history-item-label">Storage Path:</span>
264+
<span>${item.storage_path}</span>
265+
</div>
266+
267+
<div class="history-item-detail">
268+
<span class="history-item-label">Metadata:</span>
269+
<div>${this._formatMetadata(item.metadata)}</div>
270+
</div>
271+
</div>
272+
273+
<div class="action-buttons">
274+
<button class="download-link" data-path="${item.storage_path}">Download</button>
275+
${item.source_doc ? `<button class="edit-link" data-source="${encodeURIComponent(item.source_doc)}" data-type="${item.document_type}">Edit</button>` : ''}
276+
</div>
277+
</li>
278+
`).join('')}
279+
</ol>
250280
`;
251281
}
252282

0 commit comments

Comments
 (0)