mirror of
https://github.com/Matte23/circolapp.git
synced 2025-12-05 23:19:10 +00:00
Highlight unread circulars on Android
This commit is contained in:
@@ -30,6 +30,7 @@ import android.view.MenuItem
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.appcompat.widget.SearchView
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.navigation.findNavController
|
||||
import androidx.navigation.ui.AppBarConfiguration
|
||||
import androidx.navigation.ui.setupActionBarWithNavController
|
||||
@@ -38,7 +39,9 @@ import androidx.preference.PreferenceManager
|
||||
import com.google.android.material.bottomnavigation.BottomNavigationView
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import com.mikepenz.aboutlibraries.LibsBuilder
|
||||
import kotlinx.coroutines.launch
|
||||
import net.underdesk.circolapp.adapters.CircularLetterAdapter
|
||||
import net.underdesk.circolapp.data.AndroidDatabase
|
||||
import net.underdesk.circolapp.databinding.ActivityMainBinding
|
||||
import net.underdesk.circolapp.utils.DownloadableFile
|
||||
import net.underdesk.circolapp.works.PollWork
|
||||
@@ -113,6 +116,12 @@ class MainActivity : AppCompatActivity(), CircularLetterAdapter.AdapterCallback
|
||||
refreshCallback?.refresh()
|
||||
true
|
||||
}
|
||||
R.id.menu_main_mark_all_read -> {
|
||||
lifecycleScope.launch {
|
||||
AndroidDatabase.getDaoInstance(this@MainActivity).markAllRead(true)
|
||||
}
|
||||
true
|
||||
}
|
||||
R.id.menu_main_settings -> {
|
||||
startActivity(Intent(this, SettingsActivity::class.java))
|
||||
true
|
||||
|
||||
@@ -21,6 +21,7 @@ package net.underdesk.circolapp.adapters
|
||||
import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.graphics.Typeface
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
@@ -85,6 +86,14 @@ class CircularLetterAdapter(
|
||||
holder.title.text = circulars[position].name
|
||||
holder.date.text = circulars[position].date
|
||||
|
||||
if (circulars[position].read) {
|
||||
holder.number.typeface = Typeface.DEFAULT
|
||||
holder.date.typeface = Typeface.DEFAULT
|
||||
} else {
|
||||
holder.number.typeface = Typeface.defaultFromStyle(Typeface.BOLD)
|
||||
holder.date.typeface = Typeface.defaultFromStyle(Typeface.BOLD)
|
||||
}
|
||||
|
||||
holder.favouriteButton.setImageResource(
|
||||
if (circulars[position].favourite) {
|
||||
holder.favouriteButton.contentDescription =
|
||||
@@ -154,6 +163,14 @@ class CircularLetterAdapter(
|
||||
}
|
||||
|
||||
holder.viewButton.setOnClickListener {
|
||||
adapterScope.launch {
|
||||
AndroidDatabase.getDaoInstance(context).markRead(
|
||||
circulars[position].id,
|
||||
circulars[position].school,
|
||||
true
|
||||
)
|
||||
}
|
||||
|
||||
FileUtils.viewFile(circulars[position].url, context)
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,10 @@
|
||||
android:id="@+id/menu_main_refresh"
|
||||
android:title="@string/menu_refresh"
|
||||
app:showAsAction="never" />
|
||||
<item
|
||||
android:id="@+id/menu_main_mark_all_read"
|
||||
android:title="@string/menu_mark_all_read"
|
||||
app:showAsAction="never" />
|
||||
<item
|
||||
android:id="@+id/menu_main_settings"
|
||||
android:title="@string/title_settings" />
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
<string name="menu_about">Informazioni</string>
|
||||
<string name="menu_search">Cerca</string>
|
||||
<string name="menu_refresh">Aggiorna</string>
|
||||
<string name="menu_mark_all_read">Segna tutte le circolari come lette</string>
|
||||
|
||||
<string name="preferences_general_header">Generale</string>
|
||||
<string name="preference_notifications_header">Notifiche</string>
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
<string name="menu_about">About</string>
|
||||
<string name="menu_search">Search</string>
|
||||
<string name="menu_refresh">Refresh</string>
|
||||
<string name="menu_mark_all_read">Mark all circulars as read</string>
|
||||
|
||||
<string name="preferences_general_header">General</string>
|
||||
<string name="preference_notifications_header">Notifications</string>
|
||||
|
||||
@@ -26,6 +26,7 @@ data class Circular(
|
||||
val date: String,
|
||||
var favourite: Boolean = false,
|
||||
var reminder: Boolean = false,
|
||||
var read: Boolean = false,
|
||||
val attachmentsNames: MutableList<String> = mutableListOf(),
|
||||
val attachmentsUrls: MutableList<String> = mutableListOf()
|
||||
)
|
||||
|
||||
@@ -16,7 +16,7 @@ class CircularDao(
|
||||
private val appDatabaseQueries = database.appDatabaseQueries
|
||||
|
||||
private val circularMapper =
|
||||
{ id: Long, school: Long, name: String, url: String, date: String, favourite: Long, reminder: Long, attachmentsNames: String, attachmentsUrls: String ->
|
||||
{ id: Long, school: Long, name: String, url: String, date: String, favourite: Long, reminder: Long, read: Long, attachmentsNames: String, attachmentsUrls: String ->
|
||||
Circular(
|
||||
id,
|
||||
school.toInt(),
|
||||
@@ -25,6 +25,7 @@ class CircularDao(
|
||||
date,
|
||||
favourite.toBoolean(),
|
||||
reminder.toBoolean(),
|
||||
read.toBoolean(),
|
||||
attachmentsNames.toList(),
|
||||
attachmentsUrls.toList()
|
||||
)
|
||||
@@ -40,6 +41,7 @@ class CircularDao(
|
||||
it.date,
|
||||
it.favourite.toLong(),
|
||||
it.reminder.toLong(),
|
||||
it.read.toLong(),
|
||||
it.attachmentsNames.joinToString(),
|
||||
it.attachmentsUrls.joinToString()
|
||||
)
|
||||
@@ -56,11 +58,28 @@ class CircularDao(
|
||||
)
|
||||
}
|
||||
|
||||
suspend fun markRead(id: Long, school: Int, read: Boolean) =
|
||||
withContext(PlatformDispatcher.IO) {
|
||||
appDatabaseQueries.markCircularRead(
|
||||
read.toLong(),
|
||||
id,
|
||||
school.toLong()
|
||||
)
|
||||
}
|
||||
|
||||
suspend fun markAllRead(read: Boolean) =
|
||||
withContext(PlatformDispatcher.IO) {
|
||||
appDatabaseQueries.markAllRead(
|
||||
read.toLong()
|
||||
)
|
||||
}
|
||||
|
||||
suspend fun deleteAll() = withContext(PlatformDispatcher.IO) {
|
||||
appDatabaseQueries.deleteAllCirculars()
|
||||
}
|
||||
|
||||
fun getCircular(id: Long, school: Int) = appDatabaseQueries.getCircular(id, school.toLong(), circularMapper).executeAsOne()
|
||||
fun getCircular(id: Long, school: Int) =
|
||||
appDatabaseQueries.getCircular(id, school.toLong(), circularMapper).executeAsOne()
|
||||
|
||||
fun getCirculars(school: Int) =
|
||||
appDatabaseQueries.getCirculars(school.toLong(), circularMapper).executeAsList()
|
||||
|
||||
@@ -6,20 +6,30 @@ CREATE TABLE Circulars (
|
||||
date TEXT NOT NULL,
|
||||
favourite INTEGER NOT NULL DEFAULT 0,
|
||||
reminder INTEGER NOT NULL DEFAULT 0,
|
||||
read INTEGER NOT NULL DEFAULT 0,
|
||||
attachmentsNames TEXT NOT NULL,
|
||||
attachmentsUrls TEXT NOT NULL,
|
||||
PRIMARY KEY (id, school)
|
||||
);
|
||||
|
||||
insertCircular:
|
||||
INSERT OR IGNORE INTO Circulars(id, school, name, url, date, favourite, reminder, attachmentsNames, attachmentsUrls)
|
||||
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?);
|
||||
INSERT OR IGNORE INTO Circulars(id, school, name, url, date, favourite, reminder, read, attachmentsNames, attachmentsUrls)
|
||||
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?);
|
||||
|
||||
updateCircular:
|
||||
UPDATE Circulars
|
||||
SET favourite = ?, reminder = ?
|
||||
WHERE id = ? AND school = ?;
|
||||
|
||||
markCircularRead:
|
||||
UPDATE Circulars
|
||||
SET read = ?
|
||||
WHERE id = ? AND school = ?;
|
||||
|
||||
markAllRead:
|
||||
UPDATE Circulars
|
||||
SET read = ?;
|
||||
|
||||
deleteAllCirculars:
|
||||
DELETE FROM Circulars;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user