Compare commits
7 Commits
v171811305
...
v171811307
Author | SHA1 | Date | |
---|---|---|---|
00ef542e49 | |||
a78c6e6b33 | |||
363eaf9bf9 | |||
fec6683701 | |||
1549edb647 | |||
3de48ba162 | |||
a2a3d6f1a7 |
@ -1,5 +1,7 @@
|
||||
**1.7.x**
|
||||
|
||||
- Closes #33. Background sync with settings.
|
||||
|
||||
- Closing #1. Initial article caching.
|
||||
|
||||
- Closing #228 by removing the list action bar. Action buttons are exclusively on the card view from now on.
|
||||
|
@ -26,6 +26,8 @@ import android.widget.Toast
|
||||
import androidx.room.Room
|
||||
import androidx.room.RoomDatabase
|
||||
import androidx.work.Constraints
|
||||
import androidx.work.ExistingPeriodicWorkPolicy
|
||||
import androidx.work.NetworkType
|
||||
import androidx.work.OneTimeWorkRequestBuilder
|
||||
import androidx.work.PeriodicWorkRequestBuilder
|
||||
import androidx.work.WorkManager
|
||||
@ -117,6 +119,10 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
private var itemsCaching: Boolean = false
|
||||
private var hiddenTags: List<String> = emptyList()
|
||||
|
||||
private var periodicRefresh = false
|
||||
private var refreshMinutes: Long = 360L
|
||||
private var refreshWhenChargingOnly = false
|
||||
|
||||
private lateinit var tabNewBadge: TextBadgeItem
|
||||
private lateinit var tabArchiveBadge: TextBadgeItem
|
||||
private lateinit var tabStarredBadge: TextBadgeItem
|
||||
@ -186,8 +192,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
handleDrawer()
|
||||
|
||||
handleSwipeRefreshLayout()
|
||||
|
||||
handleRecurringTask()
|
||||
}
|
||||
|
||||
private fun handleSwipeRefreshLayout() {
|
||||
@ -343,6 +347,8 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
getElementsAccordingToTab()
|
||||
|
||||
handleGDPRDialog(sharedPref.getBoolean("GDPR_shown", false))
|
||||
|
||||
handleRecurringTask()
|
||||
}
|
||||
|
||||
private fun getAndStoreAllItems() {
|
||||
@ -392,6 +398,13 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
} else {
|
||||
emptyList()
|
||||
}
|
||||
periodicRefresh = sharedPref.getBoolean("periodic_refresh", false)
|
||||
refreshWhenChargingOnly = sharedPref.getBoolean("refresh_when_charging", false)
|
||||
refreshMinutes = sharedPref.getString("periodic_refresh_minutes", "360").toLong()
|
||||
|
||||
if (refreshMinutes <= 15) {
|
||||
refreshMinutes = 15
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleThemeBinding() {
|
||||
@ -1398,22 +1411,22 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
}
|
||||
|
||||
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")
|
||||
if (periodicRefresh) {
|
||||
val myConstraints = Constraints.Builder()
|
||||
.setRequiresBatteryNotLow(true)
|
||||
.setRequiresCharging(refreshWhenChargingOnly)
|
||||
.setRequiresStorageNotLow(true)
|
||||
.build()
|
||||
|
||||
val backgroundWork =
|
||||
PeriodicWorkRequestBuilder<LoadingWorker>(refreshMinutes, TimeUnit.MINUTES)
|
||||
.setConstraints(myConstraints)
|
||||
.addTag("selfoss-loading")
|
||||
.build()
|
||||
|
||||
WorkManager.getInstance().enqueue(backgroundWork)
|
||||
|
||||
WorkManager.getInstance().enqueueUniquePeriodicWork("selfoss-loading", ExistingPeriodicWorkPolicy.REPLACE, backgroundWork)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,11 @@
|
||||
package apps.amine.bou.readerforselfoss
|
||||
|
||||
import android.app.NotificationChannel
|
||||
import android.app.NotificationManager
|
||||
import android.content.Context
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.preference.PreferenceManager
|
||||
import androidx.multidex.MultiDexApplication
|
||||
import android.widget.ImageView
|
||||
@ -59,6 +62,18 @@ class MyApp : MultiDexApplication() {
|
||||
initTheme()
|
||||
|
||||
tryToHandleBug()
|
||||
|
||||
handleNotificationChannels()
|
||||
}
|
||||
|
||||
private fun handleNotificationChannels() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
val name = getString(R.string.notification_channel_sync)
|
||||
val importance = NotificationManager.IMPORTANCE_LOW
|
||||
val mChannel = NotificationChannel(Config.syncChannelId, name, importance)
|
||||
val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
|
||||
notificationManager.createNotificationChannel(mChannel)
|
||||
}
|
||||
}
|
||||
|
||||
override fun attachBaseContext(base: Context?) {
|
||||
|
@ -1,10 +1,15 @@
|
||||
package apps.amine.bou.readerforselfoss.background
|
||||
|
||||
import android.app.NotificationManager
|
||||
import android.content.Context
|
||||
import android.os.Handler
|
||||
import android.preference.PreferenceManager
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.app.NotificationCompat.PRIORITY_LOW
|
||||
import androidx.room.Room
|
||||
import androidx.work.Worker
|
||||
import androidx.work.WorkerParameters
|
||||
import apps.amine.bou.readerforselfoss.R
|
||||
import apps.amine.bou.readerforselfoss.api.selfoss.Item
|
||||
import apps.amine.bou.readerforselfoss.api.selfoss.SelfossApi
|
||||
import apps.amine.bou.readerforselfoss.persistence.database.AppDatabase
|
||||
@ -14,11 +19,26 @@ import apps.amine.bou.readerforselfoss.utils.persistence.toEntity
|
||||
import retrofit2.Call
|
||||
import retrofit2.Callback
|
||||
import retrofit2.Response
|
||||
import java.util.*
|
||||
import kotlin.concurrent.schedule
|
||||
import kotlin.concurrent.thread
|
||||
|
||||
class LoadingWorker(val context: Context, params: WorkerParameters) : Worker(context, params) {
|
||||
|
||||
override fun doWork(): Result {
|
||||
val notificationManager =
|
||||
applicationContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
|
||||
val notification = NotificationCompat.Builder(applicationContext, Config.syncChannelId)
|
||||
.setContentTitle(context.getString(R.string.loading_notification_title))
|
||||
.setContentText(context.getString(R.string.loading_notification_text))
|
||||
.setOngoing(true)
|
||||
.setPriority(PRIORITY_LOW)
|
||||
.setChannelId(Config.syncChannelId)
|
||||
.setSmallIcon(R.drawable.ic_cloud_download)
|
||||
|
||||
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 +56,9 @@ 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) {
|
||||
Timer("", false).schedule(4000) {
|
||||
notificationManager.cancel(1)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResponse(
|
||||
@ -49,6 +72,9 @@ class LoadingWorker(val context: Context, params: WorkerParameters) : Worker(con
|
||||
db.itemsDao()
|
||||
.insertAllItems(*(apiItems.map { it.toEntity() }).toTypedArray())
|
||||
}
|
||||
Timer("", false).schedule(4000) {
|
||||
notificationManager.cancel(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -36,6 +36,8 @@ class Config(c: Context) {
|
||||
|
||||
const val trackerUrl = "https://github.com/aminecmi/ReaderforSelfoss/issues"
|
||||
|
||||
const val syncChannelId = "sync-channel-id"
|
||||
|
||||
fun logoutAndRedirect(
|
||||
c: Context,
|
||||
callingActivity: Activity,
|
||||
|
BIN
app/src/main/res/drawable-hdpi/ic_cloud_download.png
Normal file
BIN
app/src/main/res/drawable-hdpi/ic_cloud_download.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 334 B |
BIN
app/src/main/res/drawable-mdpi/ic_cloud_download.png
Normal file
BIN
app/src/main/res/drawable-mdpi/ic_cloud_download.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 228 B |
BIN
app/src/main/res/drawable-xhdpi/ic_cloud_download.png
Normal file
BIN
app/src/main/res/drawable-xhdpi/ic_cloud_download.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 380 B |
BIN
app/src/main/res/drawable-xxhdpi/ic_cloud_download.png
Normal file
BIN
app/src/main/res/drawable-xxhdpi/ic_cloud_download.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 547 B |
BIN
app/src/main/res/drawable-xxxhdpi/ic_cloud_download.png
Normal file
BIN
app/src/main/res/drawable-xxxhdpi/ic_cloud_download.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 678 B |
@ -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>
|
||||
|
@ -153,4 +153,12 @@
|
||||
<string name="pref_switch_items_caching_on">Articles will be saved to the device memory and will be used for offline use.</string>
|
||||
<string name="pref_switch_items_caching">Save items for offline use</string>
|
||||
<string name="no_network_connectivity">Not connected !</string>
|
||||
<string name="pref_switch_periodic_refresh">Sync articles</string>
|
||||
<string name="pref_switch_periodic_refresh_off">Articles will not be synced in the background</string>
|
||||
<string name="pref_switch_periodic_refresh_on">Articles will periodically be synced</string>
|
||||
<string name="pref_periodic_refresh_minutes_title"><![CDATA[Sync interval ( >= 15 minutes)]]></string>
|
||||
<string name="pref_switch_refresh_when_charging">Only refresh when phone is charging</string>
|
||||
<string name="loading_notification_title">Loading ...</string>
|
||||
<string name="loading_notification_text">Selfoss is syncing your articles</string>
|
||||
<string name="notification_channel_sync">Sync notification</string>
|
||||
</resources>
|
||||
|
@ -5,4 +5,28 @@
|
||||
android:summaryOff="@string/pref_switch_items_caching_off"
|
||||
android:summaryOn="@string/pref_switch_items_caching_on"
|
||||
android:title="@string/pref_switch_items_caching" />
|
||||
|
||||
<SwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:key="periodic_refresh"
|
||||
android:dependency="items_caching"
|
||||
android:summaryOff="@string/pref_switch_periodic_refresh_off"
|
||||
android:summaryOn="@string/pref_switch_periodic_refresh_on"
|
||||
android:title="@string/pref_switch_periodic_refresh" />
|
||||
|
||||
<EditTextPreference
|
||||
android:dependency="periodic_refresh"
|
||||
android:defaultValue="360"
|
||||
android:inputType="number"
|
||||
android:key="periodic_refresh_minutes"
|
||||
android:selectAllOnFocus="true"
|
||||
android:singleLine="true"
|
||||
android:title="@string/pref_periodic_refresh_minutes_title" />
|
||||
|
||||
|
||||
<SwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:key="refresh_when_charging"
|
||||
android:dependency="items_caching"
|
||||
android:title="@string/pref_switch_refresh_when_charging" />
|
||||
</PreferenceScreen>
|
||||
|
@ -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