diff --git a/app/src/main/java/ca/pkay/rcloneexplorer/Services/RcdService.java b/app/src/main/java/ca/pkay/rcloneexplorer/Services/RcdService.java index 5eb02ead..66e94c3d 100644 --- a/app/src/main/java/ca/pkay/rcloneexplorer/Services/RcdService.java +++ b/app/src/main/java/ca/pkay/rcloneexplorer/Services/RcdService.java @@ -25,6 +25,7 @@ import ca.pkay.rcloneexplorer.R; import ca.pkay.rcloneexplorer.RcloneRcd; import ca.pkay.rcloneexplorer.util.FLog; +import ca.pkay.rcloneexplorer.util.FlagsUtil; public class RcdService extends Service implements RcloneRcd.JobsUpdateHandler { @@ -176,7 +177,7 @@ public int onStartCommand(Intent intent, int flags, int startId) { private void showNotification() { Intent foregroundIntent = new Intent(this, RcdService.class); foregroundIntent.setAction(ACTION_START_FOREGROUND); - PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, foregroundIntent, 0); + PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, foregroundIntent, FlagsUtil.Companion.getFlagImmutable()); NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID) .setSmallIcon(R.drawable.ic_rclone_logo) diff --git a/app/src/main/java/ca/pkay/rcloneexplorer/VirtualContentProvider.java b/app/src/main/java/ca/pkay/rcloneexplorer/VirtualContentProvider.java index 55fde690..3d51ba54 100644 --- a/app/src/main/java/ca/pkay/rcloneexplorer/VirtualContentProvider.java +++ b/app/src/main/java/ca/pkay/rcloneexplorer/VirtualContentProvider.java @@ -1,5 +1,10 @@ package ca.pkay.rcloneexplorer; +import static android.provider.DocumentsContract.Document.COLUMN_DISPLAY_NAME; +import static android.provider.DocumentsContract.Document.COLUMN_LAST_MODIFIED; +import static android.provider.DocumentsContract.Document.COLUMN_SIZE; +import static android.provider.DocumentsContract.Document.MIME_TYPE_DIR; + import android.annotation.SuppressLint; import android.content.ComponentName; import android.content.ContentResolver; @@ -25,19 +30,13 @@ import android.system.ErrnoException; import android.system.OsConstants; import android.util.LruCache; + import androidx.annotation.IntDef; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; import androidx.annotation.VisibleForTesting; import androidx.preference.PreferenceManager; -import ca.pkay.rcloneexplorer.Items.FileItem; -import ca.pkay.rcloneexplorer.Items.RemoteItem; -import ca.pkay.rcloneexplorer.RcloneRcd.ListItem; -import ca.pkay.rcloneexplorer.Services.RcdService; -import ca.pkay.rcloneexplorer.util.FLog; -import io.github.x0b.safdav.provider.SingleRootProvider; -import java9.util.concurrent.CompletableFuture; import java.io.File; import java.io.FileNotFoundException; @@ -58,10 +57,13 @@ import java.util.concurrent.Executor; import java.util.concurrent.Executors; -import static android.provider.DocumentsContract.Document.COLUMN_DISPLAY_NAME; -import static android.provider.DocumentsContract.Document.COLUMN_LAST_MODIFIED; -import static android.provider.DocumentsContract.Document.COLUMN_SIZE; -import static android.provider.DocumentsContract.Document.MIME_TYPE_DIR; +import ca.pkay.rcloneexplorer.Items.FileItem; +import ca.pkay.rcloneexplorer.Items.RemoteItem; +import ca.pkay.rcloneexplorer.RcloneRcd.ListItem; +import ca.pkay.rcloneexplorer.Services.RcdService; +import ca.pkay.rcloneexplorer.util.FLog; +import io.github.x0b.safdav.provider.SingleRootProvider; +import java9.util.concurrent.CompletableFuture; // Beta quality notes // @@ -276,7 +278,7 @@ public Cursor queryRoots(@Nullable String[] projection) { FLog.v(TAG, "queryRoots: no remote data change"); } }, asyncExc); - String summary = context.getString(R.string.virtual_content_provider_summary, remotes.size()); + String summary = context.getResources().getQuantityString(R.plurals.virtual_content_provider_summary, remotes.size()); return buildRoot(R.mipmap.ic_launcher, R.string.app_name, summary, flags); } else { FLog.v(TAG, "queryRoots: VCP loading"); @@ -1234,9 +1236,6 @@ private Cursor getRemotesAsCursor(@NonNull String[] projection, @Nullable String } for (RemoteItem item : remotes.values()) { // Exclude from results - no need to loop back - if (RemoteItem.SAFW == item.getType()) { - continue; - } if (null != remoteName && remoteName.equals(item.getName())) { if (remoteName.equals(item.getName())) { cursor.addRow(getForProjection(item, projection)); @@ -1388,16 +1387,21 @@ synchronized void reloadRemotesIfRequired() { if (lastModified > configModifiedTimestamp) { configModifiedTimestamp = lastModified; FLog.d(TAG, "reloadRemotesIfRequired(): requesting new remote config data"); - Set oldRemotes = remotes.keySet(); + ArrayList newRemotes = new ArrayList(); for (RemoteItem remoteItem : rclone.getRemotes()) { + if (RemoteItem.SAFW == remoteItem.getType() || RemoteItem.LOCAL == remoteItem.getType()) { + continue; + } remotes.put(remoteItem.getName(), remoteItem); + newRemotes.add(remoteItem.getName()); } // Remove remotes that no longer exist. If instead // remotes.clear() were to be used, 'remotes' would need to be // locked for all access while it is being updated. - oldRemotes.removeAll(remotes.keySet()); - for (String oldRemote : oldRemotes) { - remotes.remove(oldRemote); + for (String remote : remotes.keySet()) { + if(!newRemotes.contains(remote)){ + remotes.remove(remote); + } } FLog.v(TAG, "reloadRemotesIfRequired(): remote config data updated"); } diff --git a/app/src/main/java/ca/pkay/rcloneexplorer/util/FlagsUtil.kt b/app/src/main/java/ca/pkay/rcloneexplorer/util/FlagsUtil.kt new file mode 100644 index 00000000..cb1e2e9a --- /dev/null +++ b/app/src/main/java/ca/pkay/rcloneexplorer/util/FlagsUtil.kt @@ -0,0 +1,27 @@ +package ca.pkay.rcloneexplorer.util + +import android.app.PendingIntent +import android.os.Build + +class FlagsUtil { + + companion object { + + fun getFlagImmutable() : Int { + return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + PendingIntent.FLAG_IMMUTABLE + } else { + 0 + } + } + + fun getFlagImmutable(flag: Int) : Int { + return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + PendingIntent.FLAG_IMMUTABLE and flag + } else { + flag + } + } + } + +} \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9c7db811..78ab6236 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -478,7 +478,10 @@ Invalid permission - can not access storage Storage or a subfolder is already added Third party not yet supported. Open an issue with the affected app name. - %1$d Remotes available + + One Remote available + %1$d Remotes available + Check your network connection Support info: \n%1$s Could not get remote or directory content. You may find more information in the log file.