Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 118 additions & 0 deletions app/schemas/com.phpbg.easysync.db.AppDatabase/2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
{
"formatVersion": 1,
"database": {
"version": 2,
"identityHash": "555c0e853832f7aa52c9b3bf77b55a87",
"entities": [
{
"tableName": "File",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`pathname` TEXT NOT NULL, `local_pathname` TEXT NOT NULL, `id` INTEGER NOT NULL, `remote_date_changed` INTEGER, `local_date_changed` INTEGER, `etag` TEXT, `is_collection` INTEGER NOT NULL, PRIMARY KEY(`pathname`))",
"fields": [
{
"fieldPath": "pathname",
"columnName": "pathname",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "localPathname",
"columnName": "local_pathname",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "remoteDateChanged",
"columnName": "remote_date_changed",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "localDateChanged",
"columnName": "local_date_changed",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "etag",
"columnName": "etag",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "isCollection",
"columnName": "is_collection",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"pathname"
]
},
"indices": [
{
"name": "index_File_id",
"unique": true,
"columnNames": [
"id"
],
"orders": [],
"createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_File_id` ON `${TABLE_NAME}` (`id`)"
}
],
"foreignKeys": []
},
{
"tableName": "Error",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `created_date` INTEGER, `path` TEXT NOT NULL, `message` TEXT NOT NULL)",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "createdDate",
"columnName": "created_date",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "path",
"columnName": "path",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "message",
"columnName": "message",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
]
},
"indices": [],
"foreignKeys": []
}
],
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '555c0e853832f7aa52c9b3bf77b55a87')"
]
}
}
9 changes: 7 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@
android:label="@string/flavored_app_name"
android:localeConfig="@xml/locales_config"
android:networkSecurityConfig="@xml/network_security_config"
android:requestLegacyExternalStorage="true"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:requestLegacyExternalStorage="true"
android:theme="@style/Theme.MyApplication"
tools:targetApi="31">
<activity
android:name=".ui.SyncErrorsActivity"
android:exported="false"
android:label="@string/sync_errors_activity_title"
android:launchMode="singleTop" />
<activity
android:name=".ui.PermissionsActivity"
android:exported="false"
Expand All @@ -46,7 +51,7 @@
<activity
android:name=".ui.MainActivity"
android:exported="true"
android:launchMode="singleTop" >
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
35 changes: 33 additions & 2 deletions app/src/main/java/com/phpbg/easysync/Notifications.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,38 @@

package com.phpbg.easysync

import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import com.phpbg.easysync.ui.MainActivity

enum class Notifications(val id: Int) {
MISSING_PERMISSIONS(1),
TRIAL_EXPIRED(2)
MISSING_PERMISSIONS(1), TRIAL_EXPIRED(2)
}

fun showNotification(
context: Context, title: String, text: String, notificationId: Notifications
) {
val notificationManager =
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager

val intent = Intent(context, MainActivity::class.java).apply {
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
}
val pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE)

val id = context.getString(R.string.notification_channel_id)
val channel = NotificationChannel(
id, "Synchronization status", NotificationManager.IMPORTANCE_LOW
)
notificationManager.createNotificationChannel(channel)

val notification = Notification.Builder(context, id).setContentTitle(title).setContentText(text)
.setTicker(title).setSmallIcon(R.drawable.ic_launcher_background).setOnlyAlertOnce(true)
.setAutoCancel(true).setContentIntent(pendingIntent).build()

notificationManager.notify(notificationId.id, notification)
}
8 changes: 6 additions & 2 deletions app/src/main/java/com/phpbg/easysync/db/AppDatabase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,19 @@

package com.phpbg.easysync.db

import androidx.room.AutoMigration
import androidx.room.Database
import androidx.room.RoomDatabase
import androidx.room.TypeConverters

@Database(
entities = [File::class], version = 1, autoMigrations = [
]
entities = [File::class, Error::class],
version = 2,
autoMigrations = [AutoMigration(from = 1, to = 2)],
)
@TypeConverters(Converters::class)
abstract class AppDatabase : RoomDatabase() {
abstract fun fileDao(): FileDao

abstract fun errorDao(): ErrorDao
}
10 changes: 0 additions & 10 deletions app/src/main/java/com/phpbg/easysync/db/AppDatabaseFactory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,13 @@ package com.phpbg.easysync.db

import android.content.Context
import androidx.room.Room
import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase

val MIGRATION_1_2 = object : Migration(1, 2) {
override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL("ALTER TABLE File ADD COLUMN is_collection INTEGER NOT NULL DEFAULT(0)")
}
}


object AppDatabaseFactory {
fun create(context: Context): AppDatabase {
return Room.databaseBuilder(
context,
AppDatabase::class.java, "appdatabase"
)
.addMigrations(MIGRATION_1_2)
.enableMultiInstanceInvalidation()
.build()
}
Expand Down
41 changes: 41 additions & 0 deletions app/src/main/java/com/phpbg/easysync/db/Error.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* MIT License
*
* Copyright (c) 2024 Samuel CHEMLA
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package com.phpbg.easysync.db

import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import java.time.Instant

@Entity
data class Error(
@PrimaryKey(autoGenerate = true) val id: Long = 0,

@ColumnInfo(name = "created_date") val createdDate: Instant?,

val path: String,

val message: String,
)
45 changes: 45 additions & 0 deletions app/src/main/java/com/phpbg/easysync/db/ErrorDao.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* MIT License
*
* Copyright (c) 2024 Samuel CHEMLA
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package com.phpbg.easysync.db

import androidx.lifecycle.LiveData
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.Query

@Dao
interface ErrorDao {
@Query("SELECT * FROM error")
fun getAll(): LiveData<List<Error>>

@Query("SELECT COUNT(id) FROM error")
fun count(): LiveData<Int>

@Query("DELETE FROM error")
suspend fun deleteAll(): Int

@Insert
suspend fun insertAll(vararg errors: Error)
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ import androidx.compose.ui.unit.dp
import com.phpbg.easysync.R
import com.phpbg.easysync.settings.Settings
import com.phpbg.easysync.ui.components.Title
import com.phpbg.easysync.ui.theme.MyApplicationTheme
import com.phpbg.easysync.ui.theme.EasySyncTheme

class DavSettingsActivity : ComponentActivity() {

Expand All @@ -78,7 +78,7 @@ class DavSettingsActivity : ComponentActivity() {
viewModel.load()

setContent {
MyApplicationTheme {
EasySyncTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background
Expand Down Expand Up @@ -203,15 +203,15 @@ private fun Preferences(
@Preview(name = "FR", showBackground = true, locale = "fr")
@Composable
private fun PreferencesPreview() {
MyApplicationTheme {
EasySyncTheme {
Preferences(uiState = DavSettingsUiState(), stateChangeHandler = { }, saveHandler = { })
}
}

@Preview(name = "Light Mode", showBackground = true)
@Composable
private fun PreferencesPreviewWithCircularIndicator() {
MyApplicationTheme {
EasySyncTheme {
Preferences(uiState = DavSettingsUiState(ongoingIO = true), stateChangeHandler = { }, saveHandler = { })
}
}
Loading