Skip to content

Commit

Permalink
Merge master
Browse files Browse the repository at this point in the history
Signed-off-by: alperozturk <[email protected]>
  • Loading branch information
alperozturk96 committed Nov 16, 2023
2 parents 8f83da0 + 574cfae commit 56a93e1
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 25 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
with:
swap-size-gb: 10
- name: Initialize CodeQL
uses: github/codeql-action/init@74483a38d39275f33fcff5f35b679b5ca4a26a99 # v2.22.5
uses: github/codeql-action/init@689fdc5193eeb735ecb2e52e819e3382876f93f4 # v2.22.6
with:
languages: ${{ matrix.language }}
- name: Set up JDK 17
Expand All @@ -46,4 +46,4 @@ jobs:
echo "org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError" > "$HOME/.gradle/gradle.properties"
./gradlew assembleDebug
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@74483a38d39275f33fcff5f35b679b5ca4a26a99 # v2.22.5
uses: github/codeql-action/analyze@689fdc5193eeb735ecb2e52e819e3382876f93f4 # v2.22.6
2 changes: 1 addition & 1 deletion .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ jobs:

# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@74483a38d39275f33fcff5f35b679b5ca4a26a99 # v2.22.5
uses: github/codeql-action/upload-sarif@689fdc5193eeb735ecb2e52e819e3382876f93f4 # v2.22.6
with:
sarif_file: results.sarif
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ abstract class NextcloudDatabase : RoomDatabase() {
INSTANCE = Room
.databaseBuilder(context, NextcloudDatabase::class.java, ProviderMeta.DB_NAME)
.allowMainThreadQueries()
.addLegacyMigrations(clock)
.addLegacyMigrations(clock, context)
.addMigrations(RoomMigration())
.addMigrations(Migration67to68())
.addMigrations(Migration70to71())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

package com.nextcloud.client.database.migrations

import android.content.Context
import androidx.room.RoomDatabase
import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase
Expand All @@ -36,12 +37,13 @@ private const val MIN_SUPPORTED_DB_VERSION = 24
class LegacyMigration(
private val from: Int,
private val to: Int,
private val clock: Clock
private val clock: Clock,
private val context: Context
) : Migration(from, to) {

override fun migrate(database: SupportSQLiteDatabase) {
LegacyMigrationHelper(clock)
.onUpgrade(database, from, to)
LegacyMigrationHelper(clock, context)
.tryUpgrade(database, from, to)
}
}

Expand All @@ -52,10 +54,11 @@ class LegacyMigration(
*/
@Suppress("ForEachOnRange")
fun RoomDatabase.Builder<NextcloudDatabase>.addLegacyMigrations(
clock: Clock
clock: Clock,
context: Context
): RoomDatabase.Builder<NextcloudDatabase> {
(MIN_SUPPORTED_DB_VERSION until NextcloudDatabase.FIRST_ROOM_DB_VERSION - 1)
.map { from -> LegacyMigration(from, from + 1, clock) }
.map { from -> LegacyMigration(from, from + 1, clock, context) }
.forEach { migration -> this.addMigrations(migration) }
return this
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

package com.nextcloud.client.database.migrations;

import android.app.ActivityManager;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteException;
Expand All @@ -31,11 +32,11 @@
import com.owncloud.android.db.ProviderMeta;
import com.owncloud.android.files.services.NameCollisionPolicy;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.providers.FileContentProvider;

import java.util.Locale;

import androidx.sqlite.db.SupportSQLiteDatabase;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

public class LegacyMigrationHelper {

Expand All @@ -52,12 +53,29 @@ public class LegacyMigrationHelper {
private static final String UPGRADE_VERSION_MSG = "OUT of the ADD in onUpgrade; oldVersion == %d, newVersion == %d";

private final Clock clock;
private final Context context;

public LegacyMigrationHelper(Clock clock) {
public LegacyMigrationHelper(Clock clock, Context context) {
this.clock = clock;
this.context = context;
}

public void onUpgrade(SupportSQLiteDatabase db, int oldVersion, int newVersion) {
public void tryUpgrade(SupportSQLiteDatabase db, int oldVersion, int newVersion) {
try {
upgrade(db, oldVersion, newVersion);
} catch (Throwable t) {
Log_OC.i(TAG, "Migration upgrade failed due to " + t);
clearStorage();
}
}

@SuppressFBWarnings("RV_RETURN_VALUE_IGNORED_BAD_PRACTICE")
private void clearStorage() {
context.getCacheDir().delete();
((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)).clearApplicationUserData();
}

private void upgrade(SupportSQLiteDatabase db, int oldVersion, int newVersion) {
Log_OC.i(TAG, "Entering in onUpgrade");
boolean upgraded = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2509,8 +2509,7 @@ private void openFile(User user, String fileId) {
setUser(user);

if (fileId == null) {
dismissLoadingDialog();
DisplayUtils.showSnackMessage(this, getString(R.string.error_retrieving_file));
onFileRequestError(null);
return;
}

Expand All @@ -2531,8 +2530,7 @@ private void openFileByPath(User user, String filepath) {
setUser(user);

if (filepath == null) {
dismissLoadingDialog();
DisplayUtils.showSnackMessage(this, getString(R.string.error_retrieving_file));
onFileRequestError(null);
return;
}

Expand All @@ -2546,8 +2544,7 @@ private void openFileByPath(User user, String filepath) {
try {
client = clientFactory.create(user);
} catch (ClientFactory.CreationException e) {
dismissLoadingDialog();
DisplayUtils.showSnackMessage(this, getString(R.string.error_retrieving_file));
onFileRequestError(null);
return;
}

Expand All @@ -2556,9 +2553,17 @@ private void openFileByPath(User user, String filepath) {
client,
storageManager,
user);
asyncRunner.postQuickTask(getRemoteFileTask, this::onFileRequestResult, null);
asyncRunner.postQuickTask(getRemoteFileTask, this::onFileRequestResult, this::onFileRequestError);
}

private Unit onFileRequestError(Throwable throwable) {
dismissLoadingDialog();
DisplayUtils.showSnackMessage(this, getString(R.string.error_retrieving_file));
Log_OC.e(TAG, "Requesting file from remote failed!", throwable);
return null;
}


private Unit onFileRequestResult(GetRemoteFileTask.Result result) {
dismissLoadingDialog();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
import com.owncloud.android.operations.RefreshFolderOperation;
import com.owncloud.android.ui.activity.ConflictsResolveActivity;
import com.owncloud.android.ui.activity.FileActivity;
import com.owncloud.android.ui.activity.FileDisplayActivity;
import com.owncloud.android.ui.preview.PreviewImageFragment;
import com.owncloud.android.utils.DisplayUtils;
import com.owncloud.android.utils.MimeTypeUtil;
import com.owncloud.android.utils.theme.ViewThemeUtils;
Expand Down Expand Up @@ -346,12 +348,15 @@ public void onBindViewHolder(SectionedViewHolder holder, int section, int relati
itemViewHolder.binding.uploadRightButton.setOnClickListener(v -> removeUpload(item));
}
itemViewHolder.binding.uploadRightButton.setVisibility(View.VISIBLE);
} else { // UploadStatus.UPLOAD_SUCCESS
} else { // UploadStatus.UPLOAD_SUCCEEDED
itemViewHolder.binding.uploadRightButton.setVisibility(View.INVISIBLE);
}

itemViewHolder.binding.uploadListItemLayout.setOnClickListener(null);

// Set icon or thumbnail
itemViewHolder.binding.thumbnail.setImageResource(R.drawable.file);

// click on item
if (item.getUploadStatus() == UploadStatus.UPLOAD_FAILED) {
final UploadResult uploadResult = item.getLastResult();
Expand Down Expand Up @@ -381,12 +386,15 @@ public void onBindViewHolder(SectionedViewHolder holder, int section, int relati
);
}
});
} else {
itemViewHolder.binding.uploadListItemLayout.setOnClickListener(v -> onUploadItemClick(item));
} else if (item.getUploadStatus() == UploadStatus.UPLOAD_SUCCEEDED){
itemViewHolder.binding.uploadListItemLayout.setOnClickListener(v -> onUploadedItemClick(item));
}

// Set icon or thumbnail
itemViewHolder.binding.thumbnail.setImageResource(R.drawable.file);

// click on thumbnail to open locally
if (item.getUploadStatus() != UploadStatus.UPLOAD_SUCCEEDED){
itemViewHolder.binding.thumbnail.setOnClickListener(v -> onUploadingItemClick(item));
}

/*
* Cancellation needs do be checked and done before changing the drawable in fileIcon, or
Expand Down Expand Up @@ -738,7 +746,10 @@ public final void loadUploadItemsFromDb() {
notifyDataSetChanged();
}

private void onUploadItemClick(OCUpload file) {
/**
* Open local file.
*/
private void onUploadingItemClick(OCUpload file) {
File f = new File(file.getLocalPath());
if (!f.exists()) {
DisplayUtils.showSnackMessage(parentActivity, R.string.local_file_not_found_message);
Expand All @@ -747,6 +758,30 @@ private void onUploadItemClick(OCUpload file) {
}
}

/**
* Open remote file.
*/
private void onUploadedItemClick(OCUpload upload) {
final OCFile file = parentActivity.getStorageManager().getFileByEncryptedRemotePath(upload.getRemotePath());
if (file == null){
DisplayUtils.showSnackMessage(parentActivity, R.string.error_retrieving_file);
Log_OC.i(TAG, "Could not find uploaded file on remote.");
return;
}

if (PreviewImageFragment.canBePreviewed(file)){
//show image preview and stay in uploads tab
Intent intent = FileDisplayActivity.openFileIntent(parentActivity, parentActivity.getUser().get(), file);
parentActivity.startActivity(intent);
}else{
Intent intent = new Intent(parentActivity, FileDisplayActivity.class);
intent.setAction(Intent.ACTION_VIEW);
intent.putExtra(FileDisplayActivity.KEY_FILE_PATH, upload.getRemotePath());
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
parentActivity.startActivity(intent);
}
}


/**
* Open file with app associates with its MIME type. If MIME type unknown, show list with all apps.
Expand Down

0 comments on commit 56a93e1

Please sign in to comment.