Compare commits
5 Commits
v171811305
...
v171811307
Author | SHA1 | Date | |
---|---|---|---|
fec6683701 | |||
1549edb647 | |||
3de48ba162 | |||
a2a3d6f1a7 | |||
ccab2c7648 |
@ -160,6 +160,8 @@ dependencies {
|
|||||||
|
|
||||||
implementation "androidx.room:room-runtime:$room_version"
|
implementation "androidx.room:room-runtime:$room_version"
|
||||||
kapt "androidx.room:room-compiler:$room_version"
|
kapt "androidx.room:room-compiler:$room_version"
|
||||||
|
|
||||||
|
implementation "android.arch.work:work-runtime-ktx:$work_version"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,6 +25,11 @@ import android.view.View
|
|||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.room.Room
|
import androidx.room.Room
|
||||||
import androidx.room.RoomDatabase
|
import androidx.room.RoomDatabase
|
||||||
|
import androidx.work.Constraints
|
||||||
|
import androidx.work.ExistingPeriodicWorkPolicy
|
||||||
|
import androidx.work.OneTimeWorkRequestBuilder
|
||||||
|
import androidx.work.PeriodicWorkRequestBuilder
|
||||||
|
import androidx.work.WorkManager
|
||||||
import apps.amine.bou.readerforselfoss.adapters.ItemCardAdapter
|
import apps.amine.bou.readerforselfoss.adapters.ItemCardAdapter
|
||||||
import apps.amine.bou.readerforselfoss.adapters.ItemListAdapter
|
import apps.amine.bou.readerforselfoss.adapters.ItemListAdapter
|
||||||
import apps.amine.bou.readerforselfoss.adapters.ItemsAdapter
|
import apps.amine.bou.readerforselfoss.adapters.ItemsAdapter
|
||||||
@ -34,6 +39,7 @@ import apps.amine.bou.readerforselfoss.api.selfoss.Source
|
|||||||
import apps.amine.bou.readerforselfoss.api.selfoss.Stats
|
import apps.amine.bou.readerforselfoss.api.selfoss.Stats
|
||||||
import apps.amine.bou.readerforselfoss.api.selfoss.SuccessResponse
|
import apps.amine.bou.readerforselfoss.api.selfoss.SuccessResponse
|
||||||
import apps.amine.bou.readerforselfoss.api.selfoss.Tag
|
import apps.amine.bou.readerforselfoss.api.selfoss.Tag
|
||||||
|
import apps.amine.bou.readerforselfoss.background.LoadingWorker
|
||||||
import apps.amine.bou.readerforselfoss.persistence.database.AppDatabase
|
import apps.amine.bou.readerforselfoss.persistence.database.AppDatabase
|
||||||
import apps.amine.bou.readerforselfoss.persistence.migrations.MIGRATION_1_2
|
import apps.amine.bou.readerforselfoss.persistence.migrations.MIGRATION_1_2
|
||||||
import apps.amine.bou.readerforselfoss.settings.SettingsActivity
|
import apps.amine.bou.readerforselfoss.settings.SettingsActivity
|
||||||
@ -75,6 +81,7 @@ import org.acra.ACRA
|
|||||||
import retrofit2.Call
|
import retrofit2.Call
|
||||||
import retrofit2.Callback
|
import retrofit2.Callback
|
||||||
import retrofit2.Response
|
import retrofit2.Response
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
import kotlin.concurrent.thread
|
import kotlin.concurrent.thread
|
||||||
|
|
||||||
class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||||
@ -180,6 +187,8 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
|||||||
handleDrawer()
|
handleDrawer()
|
||||||
|
|
||||||
handleSwipeRefreshLayout()
|
handleSwipeRefreshLayout()
|
||||||
|
|
||||||
|
handleRecurringTask()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleSwipeRefreshLayout() {
|
private fun handleSwipeRefreshLayout() {
|
||||||
@ -1388,5 +1397,25 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
|||||||
alertDialog.show()
|
alertDialog.show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun handleRecurringTask() {
|
||||||
|
// TODO: add network type
|
||||||
|
val myConstraints = Constraints.Builder()
|
||||||
|
.setRequiresBatteryNotLow(true)
|
||||||
|
.setRequiresStorageNotLow(true)
|
||||||
|
.build()
|
||||||
|
|
||||||
|
// TODO: make the time variable from the settings.
|
||||||
|
val backgroundWork =
|
||||||
|
PeriodicWorkRequestBuilder<LoadingWorker>(4, TimeUnit.HOURS)
|
||||||
|
.setConstraints(myConstraints)
|
||||||
|
.addTag("selfoss-loading")
|
||||||
|
.build()
|
||||||
|
|
||||||
|
|
||||||
|
WorkManager.getInstance().enqueueUniquePeriodicWork("selfoss-loading", ExistingPeriodicWorkPolicy.REPLACE, backgroundWork)
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ import java.util.concurrent.ConcurrentHashMap
|
|||||||
|
|
||||||
class SelfossApi(
|
class SelfossApi(
|
||||||
c: Context,
|
c: Context,
|
||||||
callingActivity: Activity,
|
callingActivity: Activity?,
|
||||||
isWithSelfSignedCert: Boolean,
|
isWithSelfSignedCert: Boolean,
|
||||||
shouldLog: Boolean
|
shouldLog: Boolean
|
||||||
) {
|
) {
|
||||||
@ -91,9 +91,11 @@ class SelfossApi(
|
|||||||
.build()
|
.build()
|
||||||
service = retrofit.create(SelfossService::class.java)
|
service = retrofit.create(SelfossService::class.java)
|
||||||
} catch (e: IllegalArgumentException) {
|
} catch (e: IllegalArgumentException) {
|
||||||
|
if (callingActivity != null) {
|
||||||
Config.logoutAndRedirect(c, callingActivity, config.settings.edit(), baseUrlFail = true)
|
Config.logoutAndRedirect(c, callingActivity, config.settings.edit(), baseUrlFail = true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun login(): Call<SuccessResponse> =
|
fun login(): Call<SuccessResponse> =
|
||||||
service.loginToSelfoss(config.userLogin, config.userPassword)
|
service.loginToSelfoss(config.userLogin, config.userPassword)
|
||||||
|
@ -0,0 +1,82 @@
|
|||||||
|
package apps.amine.bou.readerforselfoss.background
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.preference.PreferenceManager
|
||||||
|
import androidx.room.Room
|
||||||
|
import androidx.work.Worker
|
||||||
|
import androidx.work.WorkerParameters
|
||||||
|
import apps.amine.bou.readerforselfoss.api.selfoss.Item
|
||||||
|
import apps.amine.bou.readerforselfoss.api.selfoss.SelfossApi
|
||||||
|
import apps.amine.bou.readerforselfoss.persistence.database.AppDatabase
|
||||||
|
import apps.amine.bou.readerforselfoss.persistence.migrations.MIGRATION_1_2
|
||||||
|
import apps.amine.bou.readerforselfoss.utils.Config
|
||||||
|
import apps.amine.bou.readerforselfoss.utils.persistence.toEntity
|
||||||
|
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)
|
||||||
|
|
||||||
|
val db = Room.databaseBuilder(
|
||||||
|
applicationContext,
|
||||||
|
AppDatabase::class.java, "selfoss-database"
|
||||||
|
).addMigrations(MIGRATION_1_2).build()
|
||||||
|
|
||||||
|
val api = SelfossApi(
|
||||||
|
this.context,
|
||||||
|
null,
|
||||||
|
settings.getBoolean("isSelfSignedCert", false),
|
||||||
|
shouldLogEverything
|
||||||
|
)
|
||||||
|
api.allItems().enqueue(object : Callback<List<Item>> {
|
||||||
|
override fun onFailure(call: Call<List<Item>>, t: Throwable) {
|
||||||
|
notificationManager.cancel(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onResponse(
|
||||||
|
call: Call<List<Item>>,
|
||||||
|
response: Response<List<Item>>
|
||||||
|
) {
|
||||||
|
thread {
|
||||||
|
if (response.body() != null) {
|
||||||
|
val apiItems = (response.body() as ArrayList<Item>)
|
||||||
|
db.itemsDao().deleteAllItems()
|
||||||
|
db.itemsDao()
|
||||||
|
.insertAllItems(*(apiItems.map { it.toEntity() }).toTypedArray())
|
||||||
|
}
|
||||||
|
notificationManager.cancel(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return Result.SUCCESS
|
||||||
|
}
|
||||||
|
}
|
@ -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_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_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="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>
|
</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_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_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="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>
|
</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_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_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="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>
|
</resources>
|
||||||
|
@ -6,6 +6,7 @@ buildscript {
|
|||||||
android_version = '1.0.0'
|
android_version = '1.0.0'
|
||||||
lifecycle_version = '2.0.0'
|
lifecycle_version = '2.0.0'
|
||||||
room_version = '2.1.0-alpha01'
|
room_version = '2.1.0-alpha01'
|
||||||
|
work_version = "1.0.0-alpha10"
|
||||||
}
|
}
|
||||||
repositories {
|
repositories {
|
||||||
google()
|
google()
|
||||||
|
@ -1,14 +1 @@
|
|||||||
include ':app'
|
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
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user