Compare commits
4 Commits
v171811305
...
v171811307
Author | SHA1 | Date | |
---|---|---|---|
fec6683701 | |||
1549edb647 | |||
3de48ba162 | |||
a2a3d6f1a7 |
@ -26,6 +26,7 @@ import android.widget.Toast
|
||||
import androidx.room.Room
|
||||
import androidx.room.RoomDatabase
|
||||
import androidx.work.Constraints
|
||||
import androidx.work.ExistingPeriodicWorkPolicy
|
||||
import androidx.work.OneTimeWorkRequestBuilder
|
||||
import androidx.work.PeriodicWorkRequestBuilder
|
||||
import androidx.work.WorkManager
|
||||
@ -1412,7 +1413,8 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
.build()
|
||||
|
||||
|
||||
WorkManager.getInstance().enqueue(backgroundWork)
|
||||
WorkManager.getInstance().enqueueUniquePeriodicWork("selfoss-loading", ExistingPeriodicWorkPolicy.REPLACE, backgroundWork)
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -15,10 +15,33 @@ import retrofit2.Call
|
||||
import retrofit2.Callback
|
||||
import retrofit2.Response
|
||||
import kotlin.concurrent.thread
|
||||
import android.app.NotificationManager
|
||||
import android.app.NotificationChannel
|
||||
import android.util.Log
|
||||
import androidx.core.app.NotificationCompat
|
||||
import apps.amine.bou.readerforselfoss.R
|
||||
|
||||
class LoadingWorker(val context: Context, params: WorkerParameters) : Worker(context, params) {
|
||||
|
||||
override fun doWork(): Result {
|
||||
val notificationManager =
|
||||
applicationContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
|
||||
//If on Oreo then notification required a notification channel.
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
||||
val channel =
|
||||
NotificationChannel("default", "Default", NotificationManager.IMPORTANCE_DEFAULT)
|
||||
notificationManager.createNotificationChannel(channel)
|
||||
}
|
||||
|
||||
val notification = NotificationCompat.Builder(applicationContext, "default")
|
||||
.setContentTitle("Loading")
|
||||
.setContentText("Loading new items")
|
||||
.setOngoing(true)
|
||||
.setSmallIcon(R.mipmap.ic_launcher)
|
||||
|
||||
notificationManager.notify(1, notification.build())
|
||||
|
||||
val settings = this.context.getSharedPreferences(Config.settingsName, Context.MODE_PRIVATE)
|
||||
val sharedPref = PreferenceManager.getDefaultSharedPreferences(this.context)
|
||||
val shouldLogEverything = sharedPref.getBoolean("should_log_everything", false)
|
||||
@ -36,6 +59,7 @@ class LoadingWorker(val context: Context, params: WorkerParameters) : Worker(con
|
||||
)
|
||||
api.allItems().enqueue(object : Callback<List<Item>> {
|
||||
override fun onFailure(call: Call<List<Item>>, t: Throwable) {
|
||||
notificationManager.cancel(1)
|
||||
}
|
||||
|
||||
override fun onResponse(
|
||||
@ -49,6 +73,7 @@ class LoadingWorker(val context: Context, params: WorkerParameters) : Worker(con
|
||||
db.itemsDao()
|
||||
.insertAllItems(*(apiItems.map { it.toEntity() }).toTypedArray())
|
||||
}
|
||||
notificationManager.cancel(1)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -152,5 +152,5 @@
|
||||
<string name="pref_switch_items_caching_off">Los artículos no se guardarán en la memoria del dispositivo y la aplicación no se podrá utilizar sin conexión.</string>
|
||||
<string name="pref_switch_items_caching_on">Los artículos se guardarán en la memoria del dispositivo y se utilizarán para el uso sin conexión.</string>
|
||||
<string name="pref_switch_items_caching">Guardar elementos para uso sin conexión</string>
|
||||
<string name="no_network_connectivity">Not connected !</string>
|
||||
<string name="no_network_connectivity">Sin conexión!</string>
|
||||
</resources>
|
||||
|
@ -152,5 +152,5 @@
|
||||
<string name="pref_switch_items_caching_off">Les articles ne seront pas enregistrés et l\'application ne sera pas utilisable hors ligne.</string>
|
||||
<string name="pref_switch_items_caching_on">Les articles seront enregistrés et l\'application sera utilisable hors ligne.</string>
|
||||
<string name="pref_switch_items_caching">Sauvegarder les articles pour une utilisation hors ligne</string>
|
||||
<string name="no_network_connectivity">Not connected !</string>
|
||||
<string name="no_network_connectivity">Hors connexion !</string>
|
||||
</resources>
|
||||
|
@ -152,5 +152,5 @@
|
||||
<string name="pref_switch_items_caching_off">Os artigos non se gardaran na memoria do dispositivo e non se poderá utilizar a aplicación sen conexión.</string>
|
||||
<string name="pref_switch_items_caching_on">Os artigos gardaranse na memoria do dispositivo e estarán dispoñibles sen conexión.</string>
|
||||
<string name="pref_switch_items_caching">Gardar elementos para uso sen conexión</string>
|
||||
<string name="no_network_connectivity">Not connected !</string>
|
||||
<string name="no_network_connectivity">Non conectado!</string>
|
||||
</resources>
|
||||
|
@ -1,14 +1 @@
|
||||
include ':app'
|
||||
|
||||
ext.isCiServer = !!System.getProperty("CI")
|
||||
|
||||
buildCache {
|
||||
local {
|
||||
enabled = !isCiServer
|
||||
}
|
||||
remote(HttpBuildCache) {
|
||||
// DO NOT COMMIT !!!!!
|
||||
url = 'http://amine-bou.fr:8885/cache/'
|
||||
push = isCiServer
|
||||
}
|
||||
}
|
||||
include ':app'
|
Reference in New Issue
Block a user