From a78c6e6b33acaabf589b33655b1f2d07c127a693 Mon Sep 17 00:00:00 2001 From: Amine Date: Sat, 3 Nov 2018 18:47:43 +0100 Subject: [PATCH] Sync with settings. --- .../bou/readerforselfoss/HomeActivity.kt | 6 +-- .../apps/amine/bou/readerforselfoss/MyApp.kt | 15 +++++++ .../readerforselfoss/background/background.kt | 37 +++++++++--------- .../bou/readerforselfoss/utils/Config.kt | 2 + .../res/drawable-hdpi/ic_cloud_download.png | Bin 0 -> 334 bytes .../res/drawable-mdpi/ic_cloud_download.png | Bin 0 -> 228 bytes .../res/drawable-xhdpi/ic_cloud_download.png | Bin 0 -> 380 bytes .../res/drawable-xxhdpi/ic_cloud_download.png | Bin 0 -> 547 bytes .../drawable-xxxhdpi/ic_cloud_download.png | Bin 0 -> 678 bytes app/src/main/res/values/strings.xml | 3 ++ 10 files changed, 42 insertions(+), 21 deletions(-) create mode 100644 app/src/main/res/drawable-hdpi/ic_cloud_download.png create mode 100644 app/src/main/res/drawable-mdpi/ic_cloud_download.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_cloud_download.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_cloud_download.png create mode 100644 app/src/main/res/drawable-xxxhdpi/ic_cloud_download.png diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt index c3fbb70..94ca30e 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt @@ -192,8 +192,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { handleDrawer() handleSwipeRefreshLayout() - - handleRecurringTask() } private fun handleSwipeRefreshLayout() { @@ -349,6 +347,8 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { getElementsAccordingToTab() handleGDPRDialog(sharedPref.getBoolean("GDPR_shown", false)) + + handleRecurringTask() } private fun getAndStoreAllItems() { @@ -1425,7 +1425,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { .build() - WorkManager.getInstance().enqueueUniquePeriodicWork("selfoss-loading", ExistingPeriodicWorkPolicy.KEEP, backgroundWork) + WorkManager.getInstance().enqueueUniquePeriodicWork("selfoss-loading", ExistingPeriodicWorkPolicy.REPLACE, backgroundWork) } } } diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/MyApp.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/MyApp.kt index c9aecc9..165c8de 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/MyApp.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/MyApp.kt @@ -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?) { diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/background/background.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/background/background.kt index 7366045..60453e3 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/background/background.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/background/background.kt @@ -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,12 +19,9 @@ 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 -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) { @@ -27,18 +29,13 @@ class LoadingWorker(val context: Context, params: WorkerParameters) : Worker(con 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") + 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) - .setSmallIcon(R.mipmap.ic_launcher) + .setPriority(PRIORITY_LOW) + .setChannelId(Config.syncChannelId) + .setSmallIcon(R.drawable.ic_cloud_download) notificationManager.notify(1, notification.build()) @@ -59,7 +56,9 @@ class LoadingWorker(val context: Context, params: WorkerParameters) : Worker(con ) api.allItems().enqueue(object : Callback> { override fun onFailure(call: Call>, t: Throwable) { - notificationManager.cancel(1) + Timer("", false).schedule(4000) { + notificationManager.cancel(1) + } } override fun onResponse( @@ -73,7 +72,9 @@ class LoadingWorker(val context: Context, params: WorkerParameters) : Worker(con db.itemsDao() .insertAllItems(*(apiItems.map { it.toEntity() }).toTypedArray()) } - notificationManager.cancel(1) + Timer("", false).schedule(4000) { + notificationManager.cancel(1) + } } } }) diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/utils/Config.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/utils/Config.kt index e5cb510..0956737 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/utils/Config.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/utils/Config.kt @@ -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, diff --git a/app/src/main/res/drawable-hdpi/ic_cloud_download.png b/app/src/main/res/drawable-hdpi/ic_cloud_download.png new file mode 100644 index 0000000000000000000000000000000000000000..9421b3c7de2a6e7b5145721331ac54b8e67ba024 GIT binary patch literal 334 zcmV-U0kQsxP)Y7Nvt1LQw0{29iVa!C}BE> z!H1I$|i6h~H7 z!octo&8!_DvrqsBPz*i#89rk;0#zfXrvE^zfL{EMM(^b literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-mdpi/ic_cloud_download.png b/app/src/main/res/drawable-mdpi/ic_cloud_download.png new file mode 100644 index 0000000000000000000000000000000000000000..f7881ba9466db30297a286bde09b222b35b882a4 GIT binary patch literal 228 zcmeAS@N?(olHy`uVBq!ia0vp^LLkh+0wn(&ce?|mR(rZQhE&{2PLMD-aAv~6f=Lgh z50@*<L}gExccu&u>+whN0`HY{RMc+D2Gr@Qf?`JB%Uj*Rd8 zSa^C*T*`$#Bv(!P&(rR>&$@9LPv}W~Hfaw96UMp!`IQYEx%ix? cTo7eo2$7jVmnkuVl6ksw5= z(rJ2T>YT2Q6`B9v^*Qx*)j4&#p{xI;Ar{!-l4ss%u+O4gIe=~R3(E`?!Ax-4 z0ZDz%cr0d$I}zi3&twc{m@5_I-C!^uw3UnT-jo47R9NRY3S;?@Dm6wexWHuG8d(Wp zrg;$FoK^VT}{_r-=QuHC>6T>7ly% ai~0l|L@dWSQIARh0000cbUpz+pSj_7f@kJ-(|LT{$bY<|by%-wQ85J3d-Z=)BhNZ|?(sNo$Y6p+LU zdi;mRaLx&4lQo=S)IVqtIa|h@IbP*M%%bc`iG0RPv(y#|GE&E8Gt`CzW#qalHN~%0 z7Sl1QLiO<$X9`(DL>|j1Q6f`xq#H40QB>H%dVXS<0`((-sxtDEN8Z%3=R_qjZpoy> z%!S;bHtZ9wINq=>?oc`5hV7BIhmM`{!5OfpmWcO)ju~0N8rrRGQEm|?@&+U31qpJO zsbGx1`xfivU3hCTCMIv%D33|Zk18gHK@;WKU%?noM0wG*q>89%gtZ1tGyNKMefsDa z0$x3?=+=g?3yoL0|I;@3&0{`r-W0x%!JrsN$2qK6-9AE#F<+uJGOL+hQ002ovPDHLkV1j_s^>qLM literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xxxhdpi/ic_cloud_download.png b/app/src/main/res/drawable-xxxhdpi/ic_cloud_download.png new file mode 100644 index 0000000000000000000000000000000000000000..e129a0815b3a20d22b0224e3ede152782961b901 GIT binary patch literal 678 zcmV;X0$KfuP)A{jRjPFGpq{ivRQ*9jS6~t**)e|Ee=|>_8nHG$3 zq-UvcCP;9k&r;wV!4EQ^O(e{L?vUX~XY@e^a0yva*#43N?cjtuO1H?G7o-?L&#B@J zqhJk2`Zo@#RAaS_si(%H#>3(q#hT)5^?(I^Xmbvhrx;Cl}0}30dX<)9Ij)q zQ5T?BZFGTrf5a8UYOgHb79i;_;_X#+r_e?q=^LW?3+TLdO`!tfxEn-z-T^=yxBbD# z4XQ3B5ErLBPnSCe=qvi<;0GN8#4#-gzX|;~({5#0=mt*o-P;N?U{-OYlW1^4r$J&$ z@zbh6sz^*R`l{M5Q$=FRvA;od&D;_a(}-LI?rSYjW(CIsx~N$*m<1e;?BaC=4UQ;g~AVY@Ptg6lY_v{n%3s zFAb4QaX3)*t_HSR3IRF3v M07*qoM6N<$f>yaaCIA2c literal 0 HcmV?d00001 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a935b3f..a053277 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -158,4 +158,7 @@ Articles will periodically be synced = 15 minutes)]]> Only refresh when phone is charging + Loading ... + Selfoss is syncing your articles + Sync notification