Compare commits
No commits in common. "014534981786ff9b7a162b57a28152d1ea16d5b9" and "0fa133d89e3c75c27cdefd3d7cf636e40b7eb5c0" have entirely different histories.
0145349817
...
0fa133d89e
@ -44,6 +44,7 @@ import bou.amine.apps.readerforselfossv2.android.utils.Config
|
|||||||
import bou.amine.apps.readerforselfossv2.android.utils.bottombar.maybeShow
|
import bou.amine.apps.readerforselfossv2.android.utils.bottombar.maybeShow
|
||||||
import bou.amine.apps.readerforselfossv2.android.utils.bottombar.removeBadge
|
import bou.amine.apps.readerforselfossv2.android.utils.bottombar.removeBadge
|
||||||
import bou.amine.apps.readerforselfossv2.android.utils.customtabs.CustomTabActivityHelper
|
import bou.amine.apps.readerforselfossv2.android.utils.customtabs.CustomTabActivityHelper
|
||||||
|
import bou.amine.apps.readerforselfossv2.android.utils.network.isNetworkAvailable
|
||||||
import bou.amine.apps.readerforselfossv2.android.utils.persistence.toEntity
|
import bou.amine.apps.readerforselfossv2.android.utils.persistence.toEntity
|
||||||
import bou.amine.apps.readerforselfossv2.android.utils.persistence.toView
|
import bou.amine.apps.readerforselfossv2.android.utils.persistence.toView
|
||||||
import bou.amine.apps.readerforselfossv2.repository.Repository
|
import bou.amine.apps.readerforselfossv2.repository.Repository
|
||||||
@ -125,6 +126,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
|||||||
private var recyclerAdapter: RecyclerView.Adapter<*>? = null
|
private var recyclerAdapter: RecyclerView.Adapter<*>? = null
|
||||||
|
|
||||||
private var fromTabShortcut: Boolean = false
|
private var fromTabShortcut: Boolean = false
|
||||||
|
private var offlineShortcut: Boolean = false
|
||||||
|
|
||||||
private lateinit var tagsBadge: Map<Long, Int>
|
private lateinit var tagsBadge: Map<Long, Int>
|
||||||
|
|
||||||
@ -707,26 +709,30 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
|||||||
var sources: List<SelfossModel.Source>?
|
var sources: List<SelfossModel.Source>?
|
||||||
|
|
||||||
fun sourcesApiCall() {
|
fun sourcesApiCall() {
|
||||||
CoroutineScope(Dispatchers.Main).launch {
|
if (this@HomeActivity.isNetworkAvailable(null, offlineShortcut) && updateSources) {
|
||||||
val response = repository.getSources()
|
CoroutineScope(Dispatchers.Main).launch {
|
||||||
if (response != null) {
|
val response = repository.getSources()
|
||||||
sources = response
|
if (response != null) {
|
||||||
val apiDrawerData = DrawerData(tags, sources)
|
sources = response
|
||||||
if ((maybeDrawerData != null && maybeDrawerData != apiDrawerData) || maybeDrawerData == null) {
|
val apiDrawerData = DrawerData(tags, sources)
|
||||||
handleDrawerData(apiDrawerData)
|
if ((maybeDrawerData != null && maybeDrawerData != apiDrawerData) || maybeDrawerData == null) {
|
||||||
}
|
handleDrawerData(apiDrawerData)
|
||||||
} else {
|
}
|
||||||
val apiDrawerData = DrawerData(tags, null)
|
} else {
|
||||||
if ((maybeDrawerData != null && maybeDrawerData != apiDrawerData) || maybeDrawerData == null) {
|
val apiDrawerData = DrawerData(tags, null)
|
||||||
handleDrawerData(apiDrawerData)
|
if ((maybeDrawerData != null && maybeDrawerData != apiDrawerData) || maybeDrawerData == null) {
|
||||||
|
handleDrawerData(apiDrawerData)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
if (this@HomeActivity.isNetworkAvailable(null, offlineShortcut) && updateSources) {
|
||||||
tags = repository.getTags()
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
sourcesApiCall()
|
tags = repository.getTags()
|
||||||
|
sourcesApiCall()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -958,8 +964,10 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
|||||||
private fun reloadBadges() {
|
private fun reloadBadges() {
|
||||||
if (displayUnreadCount || displayAllCount) {
|
if (displayUnreadCount || displayAllCount) {
|
||||||
CoroutineScope(Dispatchers.Main).launch {
|
CoroutineScope(Dispatchers.Main).launch {
|
||||||
repository.reloadBadges()
|
if (applicationContext.isNetworkAvailable()) {
|
||||||
reloadBadgeContent()
|
repository.reloadBadges()
|
||||||
|
reloadBadgeContent()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1033,56 +1041,61 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
|||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
when (item.itemId) {
|
when (item.itemId) {
|
||||||
R.id.refresh -> {
|
R.id.refresh -> {
|
||||||
needsConfirmation(R.string.menu_home_refresh, R.string.refresh_dialog_message) {
|
if (this@HomeActivity.isNetworkAvailable(null, offlineShortcut)) {
|
||||||
Toast.makeText(this, R.string.refresh_in_progress, Toast.LENGTH_SHORT).show()
|
needsConfirmation(R.string.menu_home_refresh, R.string.refresh_dialog_message) {
|
||||||
// TODO: Use Dispatchers.IO
|
Toast.makeText(this, R.string.refresh_in_progress, Toast.LENGTH_SHORT).show()
|
||||||
CoroutineScope(Dispatchers.Main).launch {
|
// TODO: Use Dispatchers.IO
|
||||||
val updatedRemote = repository.updateRemote()
|
CoroutineScope(Dispatchers.Main).launch {
|
||||||
if (updatedRemote) {
|
val updatedRemote = repository.updateRemote()
|
||||||
// TODO: Send toast messages from the repository
|
if (updatedRemote) {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
this@HomeActivity,
|
this@HomeActivity,
|
||||||
R.string.refresh_success_response, Toast.LENGTH_LONG
|
R.string.refresh_success_response, Toast.LENGTH_LONG
|
||||||
)
|
)
|
||||||
.show()
|
.show()
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
this@HomeActivity,
|
this@HomeActivity,
|
||||||
R.string.refresh_failer_message,
|
R.string.refresh_failer_message,
|
||||||
Toast.LENGTH_SHORT
|
Toast.LENGTH_SHORT
|
||||||
).show()
|
).show()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
R.id.readAll -> {
|
R.id.readAll -> {
|
||||||
if (elementsShown == ItemType.UNREAD) {
|
if (elementsShown == ItemType.UNREAD) {
|
||||||
needsConfirmation(R.string.readAll, R.string.markall_dialog_message) {
|
needsConfirmation(R.string.readAll, R.string.markall_dialog_message) {
|
||||||
binding.swipeRefreshLayout.isRefreshing = true
|
binding.swipeRefreshLayout.isRefreshing = true
|
||||||
|
|
||||||
CoroutineScope(Dispatchers.Main).launch {
|
if (this@HomeActivity.isNetworkAvailable(null, offlineShortcut)) {
|
||||||
val success = repository.markAllAsRead(items)
|
CoroutineScope(Dispatchers.Main).launch {
|
||||||
if (success) {
|
val success = repository.markAllAsRead(items)
|
||||||
Toast.makeText(
|
if (success) {
|
||||||
this@HomeActivity,
|
Toast.makeText(
|
||||||
R.string.all_posts_read,
|
this@HomeActivity,
|
||||||
Toast.LENGTH_SHORT
|
R.string.all_posts_read,
|
||||||
).show()
|
Toast.LENGTH_SHORT
|
||||||
tabNewBadge.removeBadge()
|
).show()
|
||||||
|
tabNewBadge.removeBadge()
|
||||||
|
|
||||||
handleDrawerItems()
|
handleDrawerItems()
|
||||||
|
|
||||||
getElementsAccordingToTab()
|
getElementsAccordingToTab()
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
this@HomeActivity,
|
this@HomeActivity,
|
||||||
R.string.all_posts_not_read,
|
R.string.all_posts_not_read,
|
||||||
Toast.LENGTH_SHORT
|
Toast.LENGTH_SHORT
|
||||||
).show()
|
).show()
|
||||||
|
}
|
||||||
|
handleListResult()
|
||||||
|
binding.swipeRefreshLayout.isRefreshing = false
|
||||||
}
|
}
|
||||||
handleListResult()
|
|
||||||
binding.swipeRefreshLayout.isRefreshing = false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1134,15 +1147,17 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CoroutineScope(Dispatchers.Main).launch {
|
if (this@HomeActivity.isNetworkAvailable(null, offlineShortcut)) {
|
||||||
val actions = db.actionsDao().actions()
|
CoroutineScope(Dispatchers.Main).launch {
|
||||||
|
val actions = db.actionsDao().actions()
|
||||||
|
|
||||||
actions.forEach { action ->
|
actions.forEach { action ->
|
||||||
when {
|
when {
|
||||||
action.read -> doAndReportOnFail(repository.markAsReadById(action.articleId.toInt()), action)
|
action.read -> doAndReportOnFail(repository.markAsReadById(action.articleId.toInt()), action)
|
||||||
action.unread -> doAndReportOnFail(repository.unmarkAsReadById(action.articleId.toInt()), action)
|
action.unread -> doAndReportOnFail(repository.unmarkAsReadById(action.articleId.toInt()), action)
|
||||||
action.starred -> doAndReportOnFail(repository.starrById(action.articleId.toInt()), action)
|
action.starred -> doAndReportOnFail(repository.starrById(action.articleId.toInt()), action)
|
||||||
action.unstarred -> doAndReportOnFail(repository.unstarrById(action.articleId.toInt()), action)
|
action.unstarred -> doAndReportOnFail(repository.unstarrById(action.articleId.toInt()), action)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ import androidx.appcompat.app.AppCompatActivity
|
|||||||
import bou.amine.apps.readerforselfossv2.android.databinding.ActivityLoginBinding
|
import bou.amine.apps.readerforselfossv2.android.databinding.ActivityLoginBinding
|
||||||
import bou.amine.apps.readerforselfossv2.android.themes.AppColors
|
import bou.amine.apps.readerforselfossv2.android.themes.AppColors
|
||||||
import bou.amine.apps.readerforselfossv2.android.utils.isBaseUrlValid
|
import bou.amine.apps.readerforselfossv2.android.utils.isBaseUrlValid
|
||||||
|
import bou.amine.apps.readerforselfossv2.android.utils.network.isNetworkAvailable
|
||||||
import bou.amine.apps.readerforselfossv2.repository.Repository
|
import bou.amine.apps.readerforselfossv2.repository.Repository
|
||||||
import com.mikepenz.aboutlibraries.LibsBuilder
|
import com.mikepenz.aboutlibraries.LibsBuilder
|
||||||
import com.russhwolf.settings.Settings
|
import com.russhwolf.settings.Settings
|
||||||
@ -201,13 +202,15 @@ class LoginActivity() : AppCompatActivity(), DIAware {
|
|||||||
|
|
||||||
repository.refreshLoginInformation(url, login, password, httpLogin, httpPassword, isWithSelfSignedCert)
|
repository.refreshLoginInformation(url, login, password, httpLogin, httpPassword, isWithSelfSignedCert)
|
||||||
|
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
if (this@LoginActivity.isNetworkAvailable(this@LoginActivity.findViewById(R.id.loginForm))) {
|
||||||
val result = repository.login()
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
if (result) {
|
val result = repository.login()
|
||||||
goToMain()
|
if (result) {
|
||||||
} else {
|
goToMain()
|
||||||
CoroutineScope(Dispatchers.Main).launch {
|
} else {
|
||||||
preferenceError(Exception("Not success"))
|
CoroutineScope(Dispatchers.Main).launch {
|
||||||
|
preferenceError(Exception("Not success"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import bou.amine.apps.readerforselfossv2.android.adapters.SourcesListAdapter
|
|||||||
import bou.amine.apps.readerforselfossv2.android.databinding.ActivitySourcesBinding
|
import bou.amine.apps.readerforselfossv2.android.databinding.ActivitySourcesBinding
|
||||||
import bou.amine.apps.readerforselfossv2.android.themes.AppColors
|
import bou.amine.apps.readerforselfossv2.android.themes.AppColors
|
||||||
import bou.amine.apps.readerforselfossv2.android.themes.Toppings
|
import bou.amine.apps.readerforselfossv2.android.themes.Toppings
|
||||||
|
import bou.amine.apps.readerforselfossv2.android.utils.network.isNetworkAvailable
|
||||||
import bou.amine.apps.readerforselfossv2.repository.Repository
|
import bou.amine.apps.readerforselfossv2.repository.Repository
|
||||||
import bou.amine.apps.readerforselfossv2.rest.SelfossModel
|
import bou.amine.apps.readerforselfossv2.rest.SelfossModel
|
||||||
import com.ftinc.scoop.Scoop
|
import com.ftinc.scoop.Scoop
|
||||||
@ -63,28 +64,30 @@ class SourcesActivity : AppCompatActivity(), DIAware {
|
|||||||
binding.recyclerView.setHasFixedSize(true)
|
binding.recyclerView.setHasFixedSize(true)
|
||||||
binding.recyclerView.layoutManager = mLayoutManager
|
binding.recyclerView.layoutManager = mLayoutManager
|
||||||
|
|
||||||
CoroutineScope(Dispatchers.Main).launch {
|
if (this@SourcesActivity.isNetworkAvailable(binding.recyclerView)) {
|
||||||
val response = repository.getSources()
|
CoroutineScope(Dispatchers.Main).launch {
|
||||||
if (response != null) {
|
val response = repository.getSources()
|
||||||
items = response
|
if (response != null) {
|
||||||
val mAdapter = SourcesListAdapter(
|
items = response
|
||||||
this@SourcesActivity, items
|
val mAdapter = SourcesListAdapter(
|
||||||
)
|
this@SourcesActivity, items
|
||||||
binding.recyclerView.adapter = mAdapter
|
)
|
||||||
mAdapter.notifyDataSetChanged()
|
binding.recyclerView.adapter = mAdapter
|
||||||
if (items.isEmpty()) {
|
mAdapter.notifyDataSetChanged()
|
||||||
|
if (items.isEmpty()) {
|
||||||
|
Toast.makeText(
|
||||||
|
this@SourcesActivity,
|
||||||
|
R.string.nothing_here,
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
).show()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
this@SourcesActivity,
|
this@SourcesActivity,
|
||||||
R.string.nothing_here,
|
R.string.cant_get_sources,
|
||||||
Toast.LENGTH_SHORT
|
Toast.LENGTH_SHORT
|
||||||
).show()
|
).show()
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
Toast.makeText(
|
|
||||||
this@SourcesActivity,
|
|
||||||
R.string.cant_get_sources,
|
|
||||||
Toast.LENGTH_SHORT
|
|
||||||
).show()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ import bou.amine.apps.readerforselfossv2.android.utils.*
|
|||||||
import bou.amine.apps.readerforselfossv2.android.utils.customtabs.CustomTabActivityHelper
|
import bou.amine.apps.readerforselfossv2.android.utils.customtabs.CustomTabActivityHelper
|
||||||
import bou.amine.apps.readerforselfossv2.android.utils.glide.bitmapCenterCrop
|
import bou.amine.apps.readerforselfossv2.android.utils.glide.bitmapCenterCrop
|
||||||
import bou.amine.apps.readerforselfossv2.android.utils.glide.circularBitmapDrawable
|
import bou.amine.apps.readerforselfossv2.android.utils.glide.circularBitmapDrawable
|
||||||
|
import bou.amine.apps.readerforselfossv2.android.utils.network.isNetworkAvailable
|
||||||
import bou.amine.apps.readerforselfossv2.repository.Repository
|
import bou.amine.apps.readerforselfossv2.repository.Repository
|
||||||
import bou.amine.apps.readerforselfossv2.rest.SelfossModel
|
import bou.amine.apps.readerforselfossv2.rest.SelfossModel
|
||||||
import com.amulyakhare.textdrawable.TextDrawable
|
import com.amulyakhare.textdrawable.TextDrawable
|
||||||
@ -109,20 +110,22 @@ class ItemCardAdapter(
|
|||||||
|
|
||||||
binding.favButton.setOnClickListener {
|
binding.favButton.setOnClickListener {
|
||||||
val item = items[bindingAdapterPosition]
|
val item = items[bindingAdapterPosition]
|
||||||
if (item.starred) {
|
if (c.isNetworkAvailable()) {
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
if (item.starred) {
|
||||||
repository.unstarr(item)
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
// TODO: Handle failure
|
repository.unstarr(item)
|
||||||
|
// TODO: Handle failure
|
||||||
|
}
|
||||||
|
item.starred = false
|
||||||
|
binding.favButton.isSelected = false
|
||||||
|
} else {
|
||||||
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
|
repository.starr(item)
|
||||||
|
// TODO: Handle failure
|
||||||
|
}
|
||||||
|
item.starred = true
|
||||||
|
binding.favButton.isSelected = true
|
||||||
}
|
}
|
||||||
item.starred = false
|
|
||||||
binding.favButton.isSelected = false
|
|
||||||
} else {
|
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
|
||||||
repository.starr(item)
|
|
||||||
// TODO: Handle failure
|
|
||||||
}
|
|
||||||
item.starred = true
|
|
||||||
binding.favButton.isSelected = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ import bou.amine.apps.readerforselfossv2.android.model.getIcon
|
|||||||
import bou.amine.apps.readerforselfossv2.android.model.getTitleDecoded
|
import bou.amine.apps.readerforselfossv2.android.model.getTitleDecoded
|
||||||
import bou.amine.apps.readerforselfossv2.android.utils.Config
|
import bou.amine.apps.readerforselfossv2.android.utils.Config
|
||||||
import bou.amine.apps.readerforselfossv2.android.utils.glide.circularBitmapDrawable
|
import bou.amine.apps.readerforselfossv2.android.utils.glide.circularBitmapDrawable
|
||||||
|
import bou.amine.apps.readerforselfossv2.android.utils.network.isNetworkAvailable
|
||||||
import bou.amine.apps.readerforselfossv2.android.utils.toTextDrawableString
|
import bou.amine.apps.readerforselfossv2.android.utils.toTextDrawableString
|
||||||
import bou.amine.apps.readerforselfossv2.repository.Repository
|
import bou.amine.apps.readerforselfossv2.repository.Repository
|
||||||
import bou.amine.apps.readerforselfossv2.rest.SelfossModel
|
import bou.amine.apps.readerforselfossv2.rest.SelfossModel
|
||||||
@ -77,19 +78,21 @@ class SourcesListAdapter(
|
|||||||
val deleteBtn: Button = mView.findViewById(R.id.deleteBtn)
|
val deleteBtn: Button = mView.findViewById(R.id.deleteBtn)
|
||||||
|
|
||||||
deleteBtn.setOnClickListener {
|
deleteBtn.setOnClickListener {
|
||||||
val (id) = items[adapterPosition]
|
if (c.isNetworkAvailable(null)) {
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
val (id) = items[adapterPosition]
|
||||||
val successfullyDeletedSource = repository.deleteSource(id)
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
if (successfullyDeletedSource) {
|
val successfullyDeletedSource = repository.deleteSource(id)
|
||||||
items.removeAt(adapterPosition)
|
if (successfullyDeletedSource) {
|
||||||
notifyItemRemoved(adapterPosition)
|
items.removeAt(adapterPosition)
|
||||||
notifyItemRangeChanged(adapterPosition, itemCount)
|
notifyItemRemoved(adapterPosition)
|
||||||
} else {
|
notifyItemRangeChanged(adapterPosition, itemCount)
|
||||||
Toast.makeText(
|
} else {
|
||||||
app,
|
Toast.makeText(
|
||||||
R.string.can_delete_source,
|
app,
|
||||||
Toast.LENGTH_SHORT
|
R.string.can_delete_source,
|
||||||
).show()
|
Toast.LENGTH_SHORT
|
||||||
|
).show()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ import bou.amine.apps.readerforselfossv2.android.persistence.migrations.MIGRATIO
|
|||||||
import bou.amine.apps.readerforselfossv2.android.persistence.migrations.MIGRATION_2_3
|
import bou.amine.apps.readerforselfossv2.android.persistence.migrations.MIGRATION_2_3
|
||||||
import bou.amine.apps.readerforselfossv2.android.persistence.migrations.MIGRATION_3_4
|
import bou.amine.apps.readerforselfossv2.android.persistence.migrations.MIGRATION_3_4
|
||||||
import bou.amine.apps.readerforselfossv2.android.utils.Config
|
import bou.amine.apps.readerforselfossv2.android.utils.Config
|
||||||
|
import bou.amine.apps.readerforselfossv2.android.utils.network.isNetworkAvailable
|
||||||
import bou.amine.apps.readerforselfossv2.repository.Repository
|
import bou.amine.apps.readerforselfossv2.repository.Repository
|
||||||
import bou.amine.apps.readerforselfossv2.rest.SelfossModel
|
import bou.amine.apps.readerforselfossv2.rest.SelfossModel
|
||||||
import bou.amine.apps.readerforselfossv2.utils.ItemType
|
import bou.amine.apps.readerforselfossv2.utils.ItemType
|
||||||
@ -45,60 +46,65 @@ override fun doWork(): Result {
|
|||||||
val periodicRefresh = settings.getBoolean("periodic_refresh", false)
|
val periodicRefresh = settings.getBoolean("periodic_refresh", false)
|
||||||
if (periodicRefresh) {
|
if (periodicRefresh) {
|
||||||
|
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
if (context.isNetworkAvailable()) {
|
||||||
val notificationManager =
|
|
||||||
applicationContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
|
||||||
|
|
||||||
val notification =
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
NotificationCompat.Builder(applicationContext, Config.syncChannelId)
|
val notificationManager =
|
||||||
.setContentTitle(context.getString(R.string.loading_notification_title))
|
applicationContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||||
.setContentText(context.getString(R.string.loading_notification_text))
|
|
||||||
.setOngoing(true)
|
|
||||||
.setPriority(PRIORITY_LOW)
|
|
||||||
.setChannelId(Config.syncChannelId)
|
|
||||||
.setSmallIcon(R.drawable.ic_stat_cloud_download_black_24dp)
|
|
||||||
|
|
||||||
notificationManager.notify(1, notification.build())
|
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_stat_cloud_download_black_24dp)
|
||||||
|
|
||||||
val notifyNewItems = settings.getBoolean("notify_new_items", false)
|
notificationManager.notify(1, notification.build())
|
||||||
|
|
||||||
db = Room.databaseBuilder(
|
val notifyNewItems = settings.getBoolean("notify_new_items", false)
|
||||||
applicationContext,
|
|
||||||
AppDatabase::class.java, "selfoss-database"
|
|
||||||
).addMigrations(MIGRATION_1_2).addMigrations(MIGRATION_2_3)
|
|
||||||
.addMigrations(MIGRATION_3_4).build()
|
|
||||||
|
|
||||||
val actions = db.actionsDao().actions()
|
db = Room.databaseBuilder(
|
||||||
|
applicationContext,
|
||||||
|
AppDatabase::class.java, "selfoss-database"
|
||||||
|
).addMigrations(MIGRATION_1_2).addMigrations(MIGRATION_2_3)
|
||||||
|
.addMigrations(MIGRATION_3_4).build()
|
||||||
|
|
||||||
actions.forEach { action ->
|
val actions = db.actionsDao().actions()
|
||||||
when {
|
|
||||||
action.read -> doAndReportOnFail(
|
actions.forEach { action ->
|
||||||
repository.markAsReadById(action.articleId.toInt()),
|
when {
|
||||||
action
|
action.read -> doAndReportOnFail(
|
||||||
)
|
repository.markAsReadById(action.articleId.toInt()),
|
||||||
action.unread -> doAndReportOnFail(
|
action
|
||||||
repository.unmarkAsReadById(action.articleId.toInt()),
|
)
|
||||||
action
|
action.unread -> doAndReportOnFail(
|
||||||
)
|
repository.unmarkAsReadById(action.articleId.toInt()),
|
||||||
action.starred -> doAndReportOnFail(
|
action
|
||||||
repository.starrById(action.articleId.toInt()),
|
)
|
||||||
action
|
action.starred -> doAndReportOnFail(
|
||||||
)
|
repository.starrById(action.articleId.toInt()),
|
||||||
action.unstarred -> doAndReportOnFail(
|
action
|
||||||
repository.unstarrById(action.articleId.toInt()),
|
)
|
||||||
action
|
action.unstarred -> doAndReportOnFail(
|
||||||
)
|
repository.unstarrById(action.articleId.toInt()),
|
||||||
|
action
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
launch {
|
if (context.isNetworkAvailable()) {
|
||||||
try {
|
launch {
|
||||||
val newItems = repository.allItems(ItemType.UNREAD)
|
try {
|
||||||
handleNewItemsNotification(newItems, notifyNewItems, notificationManager)
|
val newItems = repository.allItems(ItemType.UNREAD)
|
||||||
val readItems = repository.allItems(ItemType.ALL)
|
handleNewItemsNotification(newItems, notifyNewItems, notificationManager)
|
||||||
val starredItems = repository.allItems(ItemType.STARRED)
|
val readItems = repository.allItems(ItemType.ALL)
|
||||||
// TODO: save all to DB
|
val starredItems = repository.allItems(ItemType.STARRED)
|
||||||
} catch (e: Throwable) {}
|
// TODO: save all to DB
|
||||||
|
} catch (e: Throwable) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,7 @@ import bou.amine.apps.readerforselfossv2.android.utils.*
|
|||||||
import bou.amine.apps.readerforselfossv2.android.utils.customtabs.CustomTabActivityHelper
|
import bou.amine.apps.readerforselfossv2.android.utils.customtabs.CustomTabActivityHelper
|
||||||
import bou.amine.apps.readerforselfossv2.android.utils.glide.getBitmapInputStream
|
import bou.amine.apps.readerforselfossv2.android.utils.glide.getBitmapInputStream
|
||||||
import bou.amine.apps.readerforselfossv2.android.utils.glide.loadMaybeBasicAuth
|
import bou.amine.apps.readerforselfossv2.android.utils.glide.loadMaybeBasicAuth
|
||||||
|
import bou.amine.apps.readerforselfossv2.android.utils.network.isNetworkAvailable
|
||||||
import bou.amine.apps.readerforselfossv2.repository.Repository
|
import bou.amine.apps.readerforselfossv2.repository.Repository
|
||||||
import bou.amine.apps.readerforselfossv2.rest.SelfossModel
|
import bou.amine.apps.readerforselfossv2.rest.SelfossModel
|
||||||
import bou.amine.apps.readerforselfossv2.utils.isEmptyOrNullOrNullString
|
import bou.amine.apps.readerforselfossv2.utils.isEmptyOrNullOrNullString
|
||||||
@ -275,87 +276,89 @@ class ArticleFragment : Fragment(), DIAware {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getContentFromMercury(customTabsIntent: CustomTabsIntent) {
|
private fun getContentFromMercury(customTabsIntent: CustomTabsIntent) {
|
||||||
binding.progressBar.visibility = View.VISIBLE
|
if ((context != null && requireContext().isNetworkAvailable(null)) || context == null) {
|
||||||
val parser = MercuryApi()
|
binding.progressBar.visibility = View.VISIBLE
|
||||||
|
val parser = MercuryApi()
|
||||||
|
|
||||||
parser.parseUrl(url).enqueue(
|
parser.parseUrl(url).enqueue(
|
||||||
object : Callback<ParsedContent> {
|
object : Callback<ParsedContent> {
|
||||||
override fun onResponse(
|
override fun onResponse(
|
||||||
call: Call<ParsedContent>,
|
call: Call<ParsedContent>,
|
||||||
response: Response<ParsedContent>
|
response: Response<ParsedContent>
|
||||||
) {
|
) {
|
||||||
// TODO: clean all the following after finding the mercury content issue
|
// TODO: clean all the following after finding the mercury content issue
|
||||||
try {
|
try {
|
||||||
if (response.body() != null && response.body()!!.content != null && !response.body()!!.content.isNullOrEmpty()) {
|
if (response.body() != null && response.body()!!.content != null && !response.body()!!.content.isNullOrEmpty()) {
|
||||||
try {
|
|
||||||
binding.titleView.text = response.body()!!.title
|
|
||||||
if (typeface != null) {
|
|
||||||
binding.titleView.typeface = typeface
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
// Note: Mercury may return relative urls... If it does the url val will not be changed.
|
binding.titleView.text = response.body()!!.title
|
||||||
URL(response.body()!!.url)
|
if (typeface != null) {
|
||||||
url = response.body()!!.url
|
binding.titleView.typeface = typeface
|
||||||
} catch (e: MalformedURLException) {
|
|
||||||
// Mercury returned a relative url. We do nothing.
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
contentText = response.body()!!.content.orEmpty()
|
|
||||||
htmlToWebview()
|
|
||||||
} catch (e: Exception) {
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (response.body()!!.lead_image_url != null && !response.body()!!.lead_image_url.isNullOrEmpty() && context != null) {
|
|
||||||
binding.imageView.visibility = View.VISIBLE
|
|
||||||
try {
|
|
||||||
Glide
|
|
||||||
.with(requireContext())
|
|
||||||
.asBitmap()
|
|
||||||
.loadMaybeBasicAuth(config, response.body()!!.lead_image_url.orEmpty())
|
|
||||||
.apply(RequestOptions.fitCenterTransform())
|
|
||||||
.into(binding.imageView)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
}
|
}
|
||||||
} else {
|
try {
|
||||||
binding.imageView.visibility = View.GONE
|
// Note: Mercury may return relative urls... If it does the url val will not be changed.
|
||||||
|
URL(response.body()!!.url)
|
||||||
|
url = response.body()!!.url
|
||||||
|
} catch (e: MalformedURLException) {
|
||||||
|
// Mercury returned a relative url. We do nothing.
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
|
||||||
if (context != null) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
binding.nestedScrollView.scrollTo(0, 0)
|
contentText = response.body()!!.content.orEmpty()
|
||||||
|
htmlToWebview()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
}
|
||||||
|
|
||||||
binding.progressBar.visibility = View.GONE
|
try {
|
||||||
} catch (e: Exception) {
|
if (response.body()!!.lead_image_url != null && !response.body()!!.lead_image_url.isNullOrEmpty() && context != null) {
|
||||||
if (context != null) {
|
binding.imageView.visibility = View.VISIBLE
|
||||||
|
try {
|
||||||
|
Glide
|
||||||
|
.with(requireContext())
|
||||||
|
.asBitmap()
|
||||||
|
.loadMaybeBasicAuth(config, response.body()!!.lead_image_url.orEmpty())
|
||||||
|
.apply(RequestOptions.fitCenterTransform())
|
||||||
|
.into(binding.imageView)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
binding.imageView.visibility = View.GONE
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
if (context != null) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
binding.nestedScrollView.scrollTo(0, 0)
|
||||||
|
|
||||||
|
binding.progressBar.visibility = View.GONE
|
||||||
|
} catch (e: Exception) {
|
||||||
|
if (context != null) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
openInBrowserAfterFailing(customTabsIntent)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
if (context != null) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} catch (e: Exception) {
|
||||||
try {
|
if (context != null) {
|
||||||
openInBrowserAfterFailing(customTabsIntent)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
if (context != null) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
|
||||||
if (context != null) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
override fun onFailure(
|
override fun onFailure(
|
||||||
call: Call<ParsedContent>,
|
call: Call<ParsedContent>,
|
||||||
t: Throwable
|
t: Throwable
|
||||||
) = openInBrowserAfterFailing(customTabsIntent)
|
) = openInBrowserAfterFailing(customTabsIntent)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun htmlToWebview() {
|
private fun htmlToWebview() {
|
||||||
|
@ -322,8 +322,7 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
|
|||||||
|
|
||||||
suspend fun updateRemote(): Boolean {
|
suspend fun updateRemote(): Boolean {
|
||||||
var response = false
|
var response = false
|
||||||
offlineOverride = false
|
if (isConnectionAvailable.value && !offlineOverride) {
|
||||||
if (isConnectionAvailable.value) {
|
|
||||||
response = api.update()?.isSuccess == true
|
response = api.update()?.isSuccess == true
|
||||||
}
|
}
|
||||||
return response
|
return response
|
||||||
|
Loading…
Reference in New Issue
Block a user