Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature - Offline File Creation #13501

Merged
merged 51 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
2548480
Add file creation operation
alperozturk96 Sep 2, 2024
b0e7a2e
Add type adapter to get sealed class variables
alperozturk96 Sep 2, 2024
86bc1d9
Add mime type for create file
alperozturk96 Sep 2, 2024
0a09e55
Enable upload files when device dont have internet
alperozturk96 Sep 2, 2024
7086859
Add offline file entity creation
alperozturk96 Sep 2, 2024
ca56dca
Filter menu action for file
alperozturk96 Sep 2, 2024
091a015
setParentPath only for already created folder
alperozturk96 Sep 2, 2024
16809a6
Fix type conversions
alperozturk96 Sep 2, 2024
929b674
Fix duplication
alperozturk96 Sep 2, 2024
764b20e
wont user let open the file when device is offline
alperozturk96 Sep 2, 2024
66cef34
Fix rename for uploading files
alperozturk96 Sep 2, 2024
844aff3
Add rename support for file itself
alperozturk96 Sep 2, 2024
9ab36dd
Add rename support for file itself
alperozturk96 Sep 2, 2024
8605bac
Fix code analytics
alperozturk96 Sep 3, 2024
b282912
Add callback for isNetworkAndServerAvailable, remove repeated thread …
alperozturk96 Sep 3, 2024
e1def9b
use refreshCurrentDirectory for create folder
alperozturk96 Sep 3, 2024
f137436
Fix kotlin spotless check
alperozturk96 Sep 3, 2024
21333d1
Add offlineOperations to the adapter
alperozturk96 Sep 3, 2024
7e03584
Fix paths
alperozturk96 Sep 3, 2024
da2e083
Fix concurrent modification
alperozturk96 Sep 3, 2024
b928464
add todo
alperozturk96 Sep 3, 2024
5138046
Remove parent path, no need to check
alperozturk96 Sep 3, 2024
a8551fa
optimization for addOfflineOperations
alperozturk96 Sep 4, 2024
086378f
remove unused variable
alperozturk96 Sep 4, 2024
40b5821
Add SearchType.OFFLINE_MODE
alperozturk96 Sep 6, 2024
fd01a10
Check e2e setup only via internet
alperozturk96 Sep 6, 2024
8e89a46
better worker impl
alperozturk96 Sep 6, 2024
1e61fde
fix kotlin spotless check
alperozturk96 Sep 6, 2024
4c65078
Fix delete function for file
alperozturk96 Sep 6, 2024
be56a27
Fix license for new icon
alperozturk96 Sep 6, 2024
55a48c1
Fix license header
alperozturk96 Sep 6, 2024
9a32ddb
Add doc for addOfflineOperations
alperozturk96 Sep 10, 2024
60aa0a0
Add doc for buildOCFilesFromShares
alperozturk96 Sep 10, 2024
c4f9579
Rebase master
alperozturk96 Sep 11, 2024
72f86fc
fix codacy
alperozturk96 Sep 11, 2024
4b5a901
Rename .java to .kt
alperozturk96 Sep 11, 2024
1c41a1f
fix ss test -- require activity crash
alperozturk96 Sep 11, 2024
9984571
Rebase, Add Migration84to85
alperozturk96 Sep 23, 2024
6d06f9e
Better translations
alperozturk96 Sep 23, 2024
0a25085
Fix testConfirmationDialogWithThreeActionRTL ss-test
alperozturk96 Sep 25, 2024
5265782
Fix creation and modification date
alperozturk96 Sep 26, 2024
b5c935c
Add thumbnail for offline operation
alperozturk96 Sep 26, 2024
be309d5
Refresh list if internet connection is back
alperozturk96 Sep 26, 2024
775b1f6
Fixes
alperozturk96 Sep 26, 2024
f00a896
renaming handler variable
alperozturk96 Sep 26, 2024
70b689a
fix code analytics
alperozturk96 Sep 30, 2024
3f8644e
Add Migration 85 to 86
alperozturk96 Oct 1, 2024
be14914
remove unnecessary migration
alperozturk96 Oct 7, 2024
0f9b27e
remove unnecessary 86 db version
alperozturk96 Oct 7, 2024
3463124
revert 84 changes
alperozturk96 Oct 7, 2024
c5c7e9f
no need migration, just drop not used column
alperozturk96 Oct 7, 2024
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
1,301 changes: 1,301 additions & 0 deletions app/schemas/com.nextcloud.client.database.NextcloudDatabase/85.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions app/src/androidTest/java/com/owncloud/android/AbstractIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,8 @@ public void uploadFile(File file, String remotePath) {
public void uploadOCUpload(OCUpload ocUpload) {
ConnectivityService connectivityServiceMock = new ConnectivityService() {
@Override
public boolean isNetworkAndServerAvailable() throws NetworkOnMainThreadException {
return false;
public void isNetworkAndServerAvailable(@NonNull GenericCallback<Boolean> callback) {

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ public void uploadOCUpload(OCUpload ocUpload) {
public void uploadOCUpload(OCUpload ocUpload, int localBehaviour) {
ConnectivityService connectivityServiceMock = new ConnectivityService() {
@Override
public boolean isNetworkAndServerAvailable() throws NetworkOnMainThreadException {
return false;
public void isNetworkAndServerAvailable(@NonNull GenericCallback<Boolean> callback) {

}

@Override
Expand Down
12 changes: 6 additions & 6 deletions app/src/androidTest/java/com/owncloud/android/UploadIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public class UploadIT extends AbstractOnServerIT {

private ConnectivityService connectivityServiceMock = new ConnectivityService() {
@Override
public boolean isNetworkAndServerAvailable() throws NetworkOnMainThreadException {
return false;
public void isNetworkAndServerAvailable(@NonNull GenericCallback<Boolean> callback) {

}

@Override
Expand Down Expand Up @@ -282,8 +282,8 @@ public BatteryStatus getBattery() {
public void testUploadOnWifiOnlyButNoWifi() {
ConnectivityService connectivityServiceMock = new ConnectivityService() {
@Override
public boolean isNetworkAndServerAvailable() throws NetworkOnMainThreadException {
return false;
public void isNetworkAndServerAvailable(@NonNull GenericCallback<Boolean> callback) {

}

@Override
Expand Down Expand Up @@ -371,8 +371,8 @@ public void testUploadOnWifiOnlyAndWifi() {
public void testUploadOnWifiOnlyButMeteredWifi() {
ConnectivityService connectivityServiceMock = new ConnectivityService() {
@Override
public boolean isNetworkAndServerAvailable() throws NetworkOnMainThreadException {
return false;
public void isNetworkAndServerAvailable(@NonNull GenericCallback<Boolean> callback) {

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ abstract class FileUploaderIT : AbstractOnServerIT() {
private var uploadsStorageManager: UploadsStorageManager? = null

private val connectivityServiceMock: ConnectivityService = object : ConnectivityService {
override fun isNetworkAndServerAvailable(): Boolean {
return false
}
override fun isNetworkAndServerAvailable(callback: ConnectivityService.GenericCallback<Boolean>) = Unit

override fun isConnected(): Boolean {
return false
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Nextcloud - Android Client
*
* SPDX-FileCopyrightText: 2024 Alper Ozturk <alper.ozturk@nextcloud.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
package com.owncloud.android.ui.dialog

import androidx.annotation.UiThread
import androidx.test.core.app.launchActivity
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.IdlingRegistry
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.isRoot
import com.owncloud.android.AbstractIT
import com.owncloud.android.datamodel.OCFile
import com.owncloud.android.ui.activity.FileDisplayActivity
import com.owncloud.android.ui.dialog.SyncFileNotEnoughSpaceDialogFragment.Companion.newInstance
import com.owncloud.android.utils.EspressoIdlingResource
import com.owncloud.android.utils.ScreenshotTest
import org.junit.After
import org.junit.Before
import org.junit.Test

class SyncFileNotEnoughSpaceDialogFragmentTest : AbstractIT() {
private val testClassName = "com.owncloud.android.ui.dialog.SyncFileNotEnoughSpaceDialogFragmentTest"

@Before
fun registerIdlingResource() {
IdlingRegistry.getInstance().register(EspressoIdlingResource.countingIdlingResource)
}

@After
fun unregisterIdlingResource() {
IdlingRegistry.getInstance().unregister(EspressoIdlingResource.countingIdlingResource)
}

@Test
@ScreenshotTest
@UiThread
fun showNotEnoughSpaceDialogForFolder() {
launchActivity<FileDisplayActivity>().use { scenario ->
scenario.onActivity { sut ->
val ocFile = OCFile("/Document/").apply {
fileLength = 5000000
setFolder()
}

onIdleSync {
EspressoIdlingResource.increment()
newInstance(ocFile, 1000).apply {
show(sut.supportFragmentManager, "1")
}
EspressoIdlingResource.decrement()

val screenShotName = createName(testClassName + "_" + "showNotEnoughSpaceDialogForFolder", "")
onView(isRoot()).check(matches(isDisplayed()))
screenshotViaName(sut, screenShotName)
}
}
}
}

@Test
@ScreenshotTest
@UiThread
fun showNotEnoughSpaceDialogForFile() {
launchActivity<FileDisplayActivity>().use { scenario ->
scenario.onActivity { sut ->
val ocFile = OCFile("/Video.mp4").apply {
fileLength = 1000000
}

onIdleSync {
EspressoIdlingResource.increment()
newInstance(ocFile, 2000).apply {
show(sut.supportFragmentManager, "2")
}
EspressoIdlingResource.decrement()

val screenShotName = createName(testClassName + "_" + "showNotEnoughSpaceDialogForFile", "")
onView(isRoot()).check(matches(isDisplayed()))
screenshotViaName(sut, screenShotName)
}
}
}
}
}
6 changes: 2 additions & 4 deletions app/src/debug/java/com/nextcloud/test/TestActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class TestActivity :
private lateinit var binding: TestLayoutBinding

val connectivityServiceMock: ConnectivityService = object : ConnectivityService {
override fun isNetworkAndServerAvailable(callback: ConnectivityService.GenericCallback<Boolean>) = Unit

override fun isConnected(): Boolean {
return false
}
Expand All @@ -53,10 +55,6 @@ class TestActivity :
override fun getConnectivity(): Connectivity {
return Connectivity.CONNECTED_WIFI
}

override fun isNetworkAndServerAvailable(): Boolean {
return false
}
}

override fun onCreate(savedInstanceState: Bundle?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.room.AutoMigration
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import com.nextcloud.client.core.Clock
import com.nextcloud.client.core.ClockImpl
import com.nextcloud.client.database.dao.ArbitraryDataDao
Expand All @@ -31,6 +32,7 @@ import com.nextcloud.client.database.migrations.DatabaseMigrationUtil
import com.nextcloud.client.database.migrations.Migration67to68
import com.nextcloud.client.database.migrations.RoomMigration
import com.nextcloud.client.database.migrations.addLegacyMigrations
import com.nextcloud.client.database.typeConverter.OfflineOperationTypeConverter
import com.owncloud.android.db.ProviderMeta

@Database(
Expand Down Expand Up @@ -65,11 +67,13 @@ import com.owncloud.android.db.ProviderMeta
AutoMigration(from = 80, to = 81),
AutoMigration(from = 81, to = 82),
AutoMigration(from = 82, to = 83),
AutoMigration(from = 83, to = 84)
AutoMigration(from = 83, to = 84),
AutoMigration(from = 84, to = 85, spec = DatabaseMigrationUtil.DeleteColumnSpec::class)
],
exportSchema = true
)
@Suppress("Detekt.UnnecessaryAbstractClass") // needed by Room
@TypeConverters(OfflineOperationTypeConverter::class)
abstract class NextcloudDatabase : RoomDatabase() {

abstract fun arbitraryDataDao(): ArbitraryDataDao
Expand All @@ -93,6 +97,7 @@ abstract class NextcloudDatabase : RoomDatabase() {
instance = Room
.databaseBuilder(context, NextcloudDatabase::class.java, ProviderMeta.DB_NAME)
.allowMainThreadQueries()
.addTypeConverter(OfflineOperationTypeConverter())
.addLegacyMigrations(clock, context)
.addMigrations(RoomMigration())
.addMigrations(Migration67to68())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package com.nextcloud.client.database.dao
import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update
import com.nextcloud.client.database.entity.OfflineOperationEntity
Expand All @@ -19,7 +20,7 @@ interface OfflineOperationDao {
@Query("SELECT * FROM offline_operations")
fun getAll(): List<OfflineOperationEntity>

@Insert
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(vararg entity: OfflineOperationEntity)

@Update
Expand All @@ -35,5 +36,8 @@ interface OfflineOperationDao {
fun getByPath(path: String): OfflineOperationEntity?

@Query("SELECT * FROM offline_operations WHERE offline_operations_parent_oc_file_id = :parentOCFileId")
fun getSubDirectoriesByParentOCFileId(parentOCFileId: Long): List<OfflineOperationEntity>
fun getSubEntitiesByParentOCFileId(parentOCFileId: Long): List<OfflineOperationEntity>

@Query("DELETE FROM offline_operations")
fun clearTable()
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ data class OfflineOperationEntity(
@ColumnInfo(name = ProviderTableMeta.OFFLINE_OPERATION_PARENT_OC_FILE_ID)
var parentOCFileId: Long? = null,

@ColumnInfo(name = ProviderTableMeta.OFFLINE_OPERATION_PARENT_PATH)
var parentPath: String? = null,
@ColumnInfo(name = ProviderTableMeta.OFFLINE_OPERATION_PATH)
var path: String? = null,

@ColumnInfo(name = ProviderTableMeta.OFFLINE_OPERATION_TYPE)
var type: OfflineOperationType? = null,

@ColumnInfo(name = ProviderTableMeta.OFFLINE_OPERATION_PATH)
var path: String? = null,

@ColumnInfo(name = ProviderTableMeta.OFFLINE_OPERATION_FILE_NAME)
var filename: String? = null,

@ColumnInfo(name = ProviderTableMeta.OFFLINE_OPERATION_CREATED_AT)
var createdAt: Long? = null
var createdAt: Long? = null,

@ColumnInfo(name = ProviderTableMeta.OFFLINE_OPERATION_MODIFIED_AT)
var modifiedAt: Long? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
package com.nextcloud.client.database.migrations

import androidx.room.DeleteColumn
import androidx.room.migration.AutoMigrationSpec
import androidx.sqlite.db.SupportSQLiteDatabase

Expand Down Expand Up @@ -90,4 +91,12 @@ object DatabaseMigrationUtil {
super.onPostMigrate(db)
}
}

@DeleteColumn.Entries(
DeleteColumn(
tableName = "offline_operations",
columnName = "offline_operations_parent_path"
)
)
class DeleteColumnSpec : AutoMigrationSpec
}
Loading
Loading