Commit ebe6d61b authored by Daniel Wolf's avatar Daniel Wolf
Browse files

Added loading animation for the rule import

parent bdff21b3
......@@ -80,6 +80,8 @@ This work contains third-party content, namely:
- License: Font Awesome Pro License, held by Daniel Wolf
- [Weblate](https://weblate.org) for managing translations
- License: GPLv3
- [FABProgressCircle](https://github.com/JorgeCastilloPrz/FABProgressCircle) for showing a loading indicator around floating action buttons
- License: [Apache License Version 2.0](https://www.apache.org/licenses/LICENSE-2.0)
# Cloning
Feel free to clone this software. However, there are a few things to notice:
......
......@@ -110,6 +110,8 @@ dependencies {
implementation 'io.sentry:sentry-android:1.7.23'
implementation 'com.github.anrwatchdog:anrwatchdog:1.4.0'
implementation 'com.github.jorgecastilloprz:fabprogresscircle:1.01@aar'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
......
......@@ -119,8 +119,12 @@ fun Context.registerLocalReceiver(
return actualReceiver
}
fun Context.unregisterLocalReceiver(receiver: BroadcastReceiver) {
LocalBroadcastManager.getInstance(this).unregisterReceiver(receiver)
fun Context.sendLocalBroadcast(intent: Intent) {
LocalBroadcastManager.getInstance(this).sendBroadcast(intent)
}
fun Context.unregisterLocalReceiver(receiver: BroadcastReceiver?) {
if(receiver != null) LocalBroadcastManager.getInstance(this).unregisterReceiver(receiver)
}
fun Context.getPreferences(): AppSettingsSharedPreferences {
......
package com.frostnerd.smokescreen.activity
import android.content.BroadcastReceiver
import android.content.Intent
import android.content.IntentFilter
import android.os.Bundle
import android.view.Menu
import android.view.View
......@@ -9,15 +11,14 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.frostnerd.cacheadapter.ListDataSource
import com.frostnerd.cacheadapter.ModelAdapterBuilder
import com.frostnerd.general.service.isServiceRunning
import com.frostnerd.lifecyclemanagement.BaseActivity
import com.frostnerd.lifecyclemanagement.BaseViewHolder
import com.frostnerd.smokescreen.R
import com.frostnerd.smokescreen.*
import com.frostnerd.smokescreen.database.entities.HostSource
import com.frostnerd.smokescreen.database.getDatabase
import com.frostnerd.smokescreen.dialog.NewHostSourceDialog
import com.frostnerd.smokescreen.getPreferences
import com.frostnerd.smokescreen.service.RuleImportService
import com.frostnerd.smokescreen.showInfoTextDialog
import com.frostnerd.smokescreen.util.SpaceItemDecorator
import kotlinx.android.synthetic.main.activity_dns_rules.*
import kotlinx.android.synthetic.main.activity_dns_rules.toolBar
......@@ -45,6 +46,7 @@ class DnsRuleActivity : BaseActivity() {
private lateinit var sourceAdapter: RecyclerView.Adapter<*>
private lateinit var sourceAdapterList: MutableList<HostSource>
private lateinit var adapterDataSource: ListDataSource<HostSource>
private var importDoneReceiver:BroadcastReceiver? = null
private var cnt = 0
override fun onCreate(savedInstanceState: Bundle?) {
......@@ -71,6 +73,8 @@ class DnsRuleActivity : BaseActivity() {
}
refresh.setOnClickListener {
startService(Intent(this, RuleImportService::class.java))
it.isEnabled = false
refreshProgress.show()
}
sourceAdapterList = getDatabase().hostSourceDao().getAll().toMutableList()
adapterDataSource = ListDataSource(sourceAdapterList)
......@@ -144,6 +148,29 @@ class DnsRuleActivity : BaseActivity() {
list.recycledViewPool.setMaxRecycledViews(1, 1)
list.addItemDecoration(SpaceItemDecorator(this))
list.adapter = sourceAdapter
if(isServiceRunning(RuleImportService::class.java)) {
refresh.isEnabled = false
refreshProgress.addOnLayoutChangeListener { _, _, _, _, _, _, _, _, _ ->
refreshProgress.show()
}
}
}
override fun onResume() {
super.onResume()
importDoneReceiver = registerLocalReceiver(IntentFilter(RuleImportService.BROADCAST_IMPORT_DONE)) {
refresh.isEnabled = true
refreshProgress.hide()
}
if(!isServiceRunning(RuleImportService::class.java) && !refresh.isEnabled) {
refresh.isEnabled = true
refreshProgress.hide()
}
}
override fun onPause() {
super.onPause()
unregisterLocalReceiver(importDoneReceiver)
}
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
......
......@@ -37,6 +37,7 @@ class LicensesDialog(context: Context):BaseDialog(context, context.getPreference
val libraries = mutableMapOf<String, String>()
libraries["sentry-java (BSD 3-Clause revised)"] = context.getString(R.string.license_sentry)
libraries["Material Design Icons (Apache License Version 2.0)"] = context.getString(R.string.license_apache2)
libraries["FABProgressCircle (Apache License Version 2.0)"] = context.getString(R.string.license_apache2)
setTitle(R.string.dialog_about_licenses)
val view = layoutInflater.inflate(R.layout.dialog_licenses, null, false)
......
......@@ -12,6 +12,7 @@ import com.frostnerd.smokescreen.database.entities.DnsRule
import com.frostnerd.smokescreen.database.entities.HostSource
import com.frostnerd.smokescreen.database.getDatabase
import com.frostnerd.smokescreen.log
import com.frostnerd.smokescreen.sendLocalBroadcast
import com.frostnerd.smokescreen.util.Notifications
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.Job
......@@ -53,6 +54,10 @@ class RuleImportService : Service() {
private var notification: NotificationCompat.Builder? = null
private var ruleCount:Int = 0
companion object {
const val BROADCAST_IMPORT_DONE = "com.frostnerd.nebulo.RULE_IMPORT_DONE"
}
private val httpClient by lazy {
OkHttpClient()
}
......@@ -228,6 +233,7 @@ class RuleImportService : Service() {
override fun onDestroy() {
super.onDestroy()
abortImport()
sendLocalBroadcast(Intent(BROADCAST_IMPORT_DONE))
}
override fun onBind(intent: Intent?): IBinder? {
......
......@@ -43,13 +43,18 @@
android:elevation="0dp"
android:layout_height="wrap_content"/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
<com.github.jorgecastilloprz.FABProgressCircle
android:layout_width="wrap_content"
android:id="@+id/refresh"
android:src="@drawable/ic_refresh"
android:elevation="0dp"
android:id="@+id/refreshProgress"
android:layout_marginStart="8dp"
android:layout_height="wrap_content"/>
android:layout_height="wrap_content">
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:id="@+id/refresh"
android:src="@drawable/ic_refresh"
android:elevation="0dp"
android:layout_height="wrap_content"/>
</com.github.jorgecastilloprz.FABProgressCircle>
</LinearLayout>
</RelativeLayout>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment