Skip to content

Commit 16aa821

Browse files
authored
Port download library and remove F-Droid incompatible libs. (#76)
* Port download library to fetch. * Remove sentry and rating library which are not compatible with F-Droid. * Remove leading and trailing punctuations from words for better UX during selection. * Update idea files.
1 parent 2f96495 commit 16aa821

File tree

16 files changed

+175
-337
lines changed

16 files changed

+175
-337
lines changed

.idea/compiler.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 0 additions & 208 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations.xml

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PrivacyPolicy.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ Information Collection and Use
1010

1111
The app does use third-party services that may collect information used to identify you.
1212

13-
Link to the privacy policy of third-party service providers used by the app
14-
15-
Sentry
16-
1713
Log Data
1814

1915
I want to inform you that whenever you use my Service, in a case of an error in the app I collect data and information (through third-party products) on your phone called Log Data. This Log Data may include information such as your device Internet Protocol (IP) address, device name, operating system version, the configuration of the app when utilizing my Service, the time and date of your use of the Service, and other statistics. This is used only for developmental purposes and for debugging crashes.

app/build.gradle

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ android {
2929
applicationId "com.xtreak.notificationdictionary"
3030
minSdk 24
3131
targetSdk 34
32-
versionCode 23
33-
versionName "0.0.23"
32+
versionCode 24
33+
versionName "0.0.24"
3434

3535
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
3636
}
@@ -40,6 +40,7 @@ android {
4040
minifyEnabled true
4141
shrinkResources true
4242
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
43+
signingConfig signingConfigs.release
4344
}
4445
}
4546
compileOptions {
@@ -62,12 +63,10 @@ dependencies {
6263
implementation 'com.google.android.material:material:1.4.0'
6364
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
6465
implementation 'io.github.medyo:android-about-page:2.0.0'
65-
implementation 'com.suddenh4x.ratingdialog:awesome-app-rating:2.4.0'
66-
implementation 'com.huxq17.pump:download:1.3.10'
6766
implementation 'com.squareup.okhttp3:okhttp:4.9.1'
6867
implementation 'de.cketti.library.changelog:ckchangelog:1.2.2'
69-
implementation 'io.sentry:sentry-android:4.3.0'
7068
implementation 'com.mikepenz:aboutlibraries:8.9.2'
69+
implementation "com.github.tonyofrancis.Fetch:fetch2:3.3.0"
7170

7271
testImplementation 'junit:junit:4.+'
7372
androidTestImplementation 'androidx.test.ext:junit:1.1.3'

app/src/main/AndroidManifest.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111
android:supportsRtl="true"
1212
android:theme="@style/Theme.NotificationDictionary">
1313

14-
<meta-data
15-
android:name="io.sentry.dsn"
16-
android:value="https://c2152c70152f4dbab75dd18714a65699@o996828.ingest.sentry.io/5955342" />
17-
1814
<activity
1915
android:name=".AboutActivity"
2016
android:exported="true"

app/src/main/java/com/xtreak/notificationdictionary/MainActivity.kt

Lines changed: 83 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,22 @@ import android.content.Context
1818
import android.content.DialogInterface
1919
import android.content.Intent
2020
import android.content.res.Configuration
21-
import android.os.*
21+
import android.os.Build
22+
import android.os.Bundle
23+
import android.os.Environment
24+
import android.os.Handler
25+
import android.os.Looper
2226
import android.util.Log
2327
import android.view.Menu
2428
import android.view.MenuItem
2529
import android.view.View
2630
import android.view.inputmethod.EditorInfo
27-
import android.widget.*
31+
import android.widget.AdapterView
32+
import android.widget.ArrayAdapter
33+
import android.widget.EditText
34+
import android.widget.Spinner
35+
import android.widget.Switch
36+
import android.widget.TextView
2837
import android.widget.TextView.OnEditorActionListener
2938
import androidx.appcompat.app.AlertDialog
3039
import androidx.appcompat.app.AppCompatActivity
@@ -33,17 +42,19 @@ import androidx.core.view.MenuItemCompat
3342
import androidx.recyclerview.widget.LinearLayoutManager
3443
import androidx.recyclerview.widget.RecyclerView
3544
import com.google.android.material.snackbar.Snackbar
36-
import com.huxq17.download.Pump
37-
import com.huxq17.download.config.DownloadConfig
38-
import com.huxq17.download.core.DownloadListener
3945
import com.mikepenz.aboutlibraries.LibsBuilder
40-
import com.suddenh4x.ratingdialog.AppRating
41-
import com.suddenh4x.ratingdialog.preferences.RatingThreshold
46+
import com.tonyodev.fetch2.AbstractFetchListener
47+
import com.tonyodev.fetch2.Download
48+
import com.tonyodev.fetch2.Error
49+
import com.tonyodev.fetch2.Fetch.Impl.getInstance
50+
import com.tonyodev.fetch2.FetchConfiguration
51+
import com.tonyodev.fetch2.NetworkType
52+
import com.tonyodev.fetch2.Priority
53+
import com.tonyodev.fetch2.Request
4254
import de.cketti.library.changelog.ChangeLog
43-
import io.sentry.Sentry
4455
import java.io.File
4556
import java.io.FileOutputStream
46-
import java.util.*
57+
import java.util.Locale
4758
import java.util.concurrent.Executors
4859
import java.util.zip.ZipFile
4960

@@ -188,7 +199,6 @@ class MainActivity : AppCompatActivity() {
188199

189200
initialize_spinner(database_name)
190201
// show_changelog()
191-
show_rating()
192202
onNewIntent(intent)
193203

194204
// Request notification permission in Android 33+
@@ -351,16 +361,6 @@ class MainActivity : AppCompatActivity() {
351361
}
352362
}
353363

354-
fun show_rating() {
355-
AppRating.Builder(this)
356-
.setMinimumLaunchTimes(10)
357-
.setMinimumDays(2)
358-
.setMinimumLaunchTimesToShowAgain(15)
359-
.setMinimumDaysToShowAgain(10)
360-
.setRatingThreshold(RatingThreshold.FIVE)
361-
.showIfMeetsConditions()
362-
}
363-
364364
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
365365
val inflater = menuInflater
366366
inflater.inflate(R.menu.menu, menu)
@@ -404,16 +404,19 @@ class MainActivity : AppCompatActivity() {
404404
val about_activity = Intent(applicationContext, AboutActivity::class.java)
405405
startActivityForResult(about_activity, 0)
406406
}
407+
407408
R.id.license -> {
408409
LibsBuilder()
409410
.withActivityTitle("Open Source Licenses")
410411
.withLicenseShown(true)
411412
.start(this)
412413
}
414+
413415
R.id.history -> {
414416
val history_activity = Intent(applicationContext, HistoryActivity::class.java)
415417
startActivityForResult(history_activity, 0)
416418
}
419+
417420
R.id.favourite -> {
418421
val favourite_activity = Intent(applicationContext, FavouriteActivity::class.java)
419422
startActivityForResult(favourite_activity, 0)
@@ -438,7 +441,8 @@ class MainActivity : AppCompatActivity() {
438441
// But we don't want the user to cancel this. It's one time and takes a couple of seconds
439442

440443
// TODO: Make this configurable based on environment?
441-
val url = "https://xtreak.sfo3.cdn.digitaloceanspaces.com/dictionaries/v2/$database_name.zip"
444+
val url =
445+
"https://xtreak.sfo3.cdn.digitaloceanspaces.com/dictionaries/v2/$database_name.zip"
442446
// val url = "http://192.168.0.105:8000/$database_name.zip" // for local mobile testing
443447
// val url = "http://10.0.2.2:8000/$database_name.zip" // for local emulator testing
444448

@@ -447,65 +451,69 @@ class MainActivity : AppCompatActivity() {
447451
Environment.getDataDirectory().absolutePath + "/data/" + packageName
448452
val zip_path = File("$package_data_directory/$database_name.zip").absolutePath
449453

450-
// https://github.com/huxq17/Pump/blob/master/kotlin_app/src/main/java/com/huxq17/download/demo/MainActivity.kt
451-
DownloadConfig.newBuilder()
452-
.setMaxRunningTaskNum(1)
453-
.setMinUsableStorageSpace(140 * 1024L * 1024) // 140MB as per database size
454+
val fetchConfiguration: FetchConfiguration = FetchConfiguration.Builder(this)
455+
.setDownloadConcurrentLimit(3)
454456
.build()
457+
458+
val fetch = getInstance(fetchConfiguration)
459+
val request: Request = Request(url, zip_path)
460+
request.priority = Priority.HIGH
461+
request.networkType = NetworkType.ALL
455462
progressDialog.progress = 0
456463
progressDialog.show()
457-
Pump.newRequest(url, zip_path)
458-
.listener(object : DownloadListener() {
464+
fetch.addListener(object : AbstractFetchListener() {
465+
466+
fun copy_and_unzip(source: String, destination: String) {
467+
val zipfile = ZipFile(source)
468+
val entry = zipfile.entries().toList().first()
469+
470+
// The zip file only has one entry which is the database. So use it as an
471+
// input stream and copy the unzipped file to output stream. Delete the source
472+
// zip file to save space.
473+
val input_stream = zipfile.getInputStream(entry)
474+
val output_stream = FileOutputStream(destination)
475+
input_stream.copyTo(output_stream, 1024 * 1024 * 2)
476+
File(zip_path).delete()
477+
}
459478

460-
override fun onProgress(progress: Int) {
461-
progressDialog.progress = progress
462-
}
479+
override fun onCompleted(download: Download) {
480+
val destination_folder = File("$package_data_directory/databases")
481+
val destination_path =
482+
File("$package_data_directory/databases/$database_name").absolutePath
483+
val source_path = download.file
463484

464-
fun copy_and_unzip(source: String, destination: String) {
465-
val zipfile = ZipFile(source)
466-
val entry = zipfile.entries().toList().first()
467-
468-
// The zip file only has one entry which is the database. So use it as an
469-
// input stream and copy the unzipped file to output stream. Delete the source
470-
// zip file to save space.
471-
val input_stream = zipfile.getInputStream(entry)
472-
val output_stream = FileOutputStream(destination)
473-
input_stream.copyTo(output_stream, 1024 * 1024 * 2)
474-
File(zip_path).delete()
485+
if (!destination_folder.exists()) {
486+
destination_folder.mkdirs()
475487
}
476488

477-
override fun onSuccess() {
478-
val destination_folder = File("$package_data_directory/databases")
479-
val destination_path =
480-
File("$package_data_directory/databases/$database_name").absolutePath
481-
val source_path = downloadInfo.filePath
482-
483-
if (!destination_folder.exists()) {
484-
destination_folder.mkdirs()
485-
}
486-
487-
copy_and_unzip(source_path, destination_path)
488-
progressDialog.dismiss()
489-
Snackbar.make(
490-
findViewById(R.id.mainLayout),
491-
"Download finished",
492-
Snackbar.LENGTH_SHORT
493-
).show()
494-
}
489+
copy_and_unzip(source_path, destination_path)
490+
progressDialog.dismiss()
491+
Snackbar.make(
492+
findViewById(R.id.mainLayout),
493+
"Download finished",
494+
Snackbar.LENGTH_SHORT
495+
).show()
496+
}
495497

496-
override fun onFailed() {
497-
progressDialog.dismiss()
498-
Snackbar.make(
499-
findViewById(R.id.mainLayout),
500-
"Download failed. Please check your internet connection and relaunch the app.",
501-
Snackbar.LENGTH_INDEFINITE
502-
).show()
503-
}
504-
})
505-
.forceReDownload(false)
506-
.threadNum(3)
507-
.setRetry(3, 200)
508-
.submit()
498+
override fun onError(download: Download, error: Error, throwable: Throwable?) {
499+
progressDialog.dismiss()
500+
Snackbar.make(
501+
findViewById(R.id.mainLayout),
502+
"Download failed. Please check your internet connection and relaunch the app.",
503+
Snackbar.LENGTH_INDEFINITE
504+
).show()
505+
}
506+
507+
override fun onProgress(
508+
download: Download,
509+
etaInMilliseconds: Long,
510+
downloadedBytesPerSecond: Long
511+
) {
512+
progressDialog.progress = download.progress
513+
}
514+
})
515+
516+
fetch.enqueue(request)
509517
}
510518

511519
override fun onDestroy() {
@@ -571,7 +579,8 @@ class MainActivity : AppCompatActivity() {
571579
// https://stackoverflow.com/questions/18414804/android-edittext-remove-focus-after-clicking-a-button
572580
wordEdit.clearFocus()
573581

574-
val word = wordEdit.text.toString().trim().lowercase()
582+
var word = wordEdit.text.toString().trim().lowercase()
583+
word = removePunctuation(word).toString()
575584

576585
val executor = Executors.newSingleThreadExecutor()
577586
val handler = Handler(Looper.getMainLooper())
@@ -588,7 +597,6 @@ class MainActivity : AppCompatActivity() {
588597
addHistoryEntry(historyDao, word)
589598
}
590599
} catch (e: Exception) {
591-
Sentry.captureException(e)
592600
Log.d("ndict:", e.toString())
593601
meanings = listOf(
594602
Word(
@@ -603,7 +611,7 @@ class MainActivity : AppCompatActivity() {
603611
try {
604612
resolveRedirectMeaning(meanings, dao)
605613
} catch (e: Exception) {
606-
Sentry.captureException(e)
614+
Log.d("ndict", e.toString())
607615
}
608616

609617
handler.post {

0 commit comments

Comments
 (0)