Skip to content

Commit ff50f52

Browse files
committed
improve android database setup
1 parent 1103f7a commit ff50f52

12 files changed

Lines changed: 171 additions & 184 deletions

File tree

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ jobs:
163163
- name: Copy package files
164164
run: |
165165
mkdir -p termux-packages/packages/
166-
cp -r ./scripts/termux/packages/* termux-packages/packages/
166+
cp -r ./termux/packages/* termux-packages/packages/
167167
168168
- name: Build wikilite package
169169
run: |
@@ -199,7 +199,7 @@ jobs:
199199
- name: Copy package files
200200
run: |
201201
mkdir -p termux-packages/packages/
202-
cp -r ./scripts/termux/packages/* termux-packages/packages/
202+
cp -r ./termux/packages/* termux-packages/packages/
203203
204204
- name: Build wikilite package
205205
run: |

android/app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
package="it.eja.wikilite">
55

66
<uses-permission android:name="android.permission.INTERNET" />
7-
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
8-
android:maxSdkVersion="28" />
9-
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
10-
android:maxSdkVersion="28" />
7+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
8+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
119
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
1210
tools:ignore="ScopedStorage" />
1311

@@ -19,9 +17,7 @@
1917
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
2018
android:usesCleartextTraffic="true"
2119
android:requestLegacyExternalStorage="true"
22-
android:enableOnBackInvokedCallback="true"
23-
tools:targetApi="28">
24-
20+
android:enableOnBackInvokedCallback="true">
2521
<activity
2622
android:name=".MainActivity"
2723
android:exported="true">

android/app/src/main/java/it/eja/wikilite/DatabaseDownloadActivity.kt

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class DatabaseDownloadActivity : AppCompatActivity() {
2323
private val databaseFiles = mutableListOf<String>()
2424
private lateinit var preferences: SharedPreferences
2525
private var progressDialog: ProgressDialog? = null
26+
private val DB_FILENAME = "wikilite.db"
2627

2728
override fun onCreate(savedInstanceState: Bundle?) {
2829
super.onCreate(savedInstanceState)
@@ -34,12 +35,17 @@ class DatabaseDownloadActivity : AppCompatActivity() {
3435
loadDatabaseFiles()
3536
}
3637

38+
private fun goToMainActivity() {
39+
startActivity(Intent(this, MainActivity::class.java))
40+
finish()
41+
}
42+
3743
private fun setupUI() {
3844
recyclerView = findViewById(R.id.recyclerView)
3945
recyclerView.layoutManager = LinearLayoutManager(this)
4046

4147
adapter = DatabaseFileAdapter(databaseFiles) { filePath ->
42-
showDownloadOptions(filePath)
48+
startDownload(filePath, filesDir.absolutePath)
4349
}
4450
recyclerView.adapter = adapter
4551
}
@@ -93,35 +99,6 @@ class DatabaseDownloadActivity : AppCompatActivity() {
9399
return files
94100
}
95101

96-
private fun getAppStorageLocations(): List<String> {
97-
val locationPaths = mutableListOf<String>()
98-
val storageDirs = applicationContext.getExternalFilesDirs(null).filterNotNull()
99-
100-
if (storageDirs.isNotEmpty()) {
101-
locationPaths.addAll(storageDirs.map { it.absolutePath })
102-
}
103-
104-
if (locationPaths.isEmpty()) {
105-
locationPaths.add(applicationContext.filesDir.absolutePath)
106-
}
107-
return locationPaths
108-
}
109-
110-
private fun showDownloadOptions(filePath: String) {
111-
val storageLocations = getAppStorageLocations()
112-
113-
if (storageLocations.size <= 1) {
114-
val downloadPath = storageLocations.first()
115-
Toast.makeText(this, "Downloading to app storage...", Toast.LENGTH_SHORT).show()
116-
startDownload(filePath, downloadPath)
117-
} else {
118-
val dialog = DownloadDialog(filePath) { selectedFilePath, downloadPath ->
119-
startDownload(selectedFilePath, downloadPath)
120-
}
121-
dialog.show(supportFragmentManager, "download_dialog")
122-
}
123-
}
124-
125102
private fun startDownload(filePath: String, downloadPath: String) {
126103
DownloadAndExtractTask().execute(filePath to downloadPath)
127104
}
@@ -155,8 +132,7 @@ class DatabaseDownloadActivity : AppCompatActivity() {
155132

156133
val fileLength = connection.contentLength.toLong()
157134

158-
val finalFileName = currentFilePath.substringAfterLast("/").replace(".gz", "")
159-
val outputFile = File(downloadPath, finalFileName)
135+
val outputFile = File(downloadPath, DB_FILENAME)
160136
finalDbPath = outputFile.absolutePath
161137

162138
val inputStream = connection.getInputStream()
@@ -187,7 +163,6 @@ class DatabaseDownloadActivity : AppCompatActivity() {
187163
true
188164

189165
} catch (e: Exception) {
190-
println("Download/Extraction error: ${e.message}")
191166
e.printStackTrace()
192167
false
193168
}
@@ -216,8 +191,7 @@ class DatabaseDownloadActivity : AppCompatActivity() {
216191
if (success) {
217192
preferences.edit().putString("db_path", finalDbPath).apply()
218193
Toast.makeText(this@DatabaseDownloadActivity, "Download successful!", Toast.LENGTH_SHORT).show()
219-
startActivity(Intent(this@DatabaseDownloadActivity, MainActivity::class.java))
220-
finish()
194+
goToMainActivity()
221195
} else {
222196
Toast.makeText(this@DatabaseDownloadActivity, "Download failed!", Toast.LENGTH_LONG).show()
223197
}

android/app/src/main/java/it/eja/wikilite/DatabaseFileAdapter.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ class DatabaseFileAdapter(
2323

2424
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
2525
val filePath = files[position]
26-
val fileName = filePath.substringAfterLast("/")
27-
holder.tvFileName.text = fileName
26+
holder.tvFileName.text = filePath
2827

2928
holder.itemView.setOnClickListener {
3029
onItemClick(filePath)

android/app/src/main/java/it/eja/wikilite/DownloadDialog.kt

Lines changed: 0 additions & 88 deletions
This file was deleted.

0 commit comments

Comments
 (0)