Skip to content
Draft
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright (C) 2014-2023 Arpit Khurana <arpitkh96@gmail.com>, Vishal Nehra <vishalmeham2@gmail.com>,
* Emmanuel Messulam<emmanuelbendavid@gmail.com>, Raymond Lai <airwave209gt at gmail.com> and Contributors.
*
* This file is part of Amaze File Manager.
*
* Amaze File Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.amaze.filemanager.adapters.data

import androidx.test.ext.junit.runners.AndroidJUnit4
import com.amaze.filemanager.adapters.data.IconDataParcelable.IMAGE_FROMCLOUD
import com.amaze.filemanager.adapters.data.IconDataParcelable.IMAGE_RES
import com.amaze.filemanager.application.AppConfig
import com.amaze.filemanager.fileoperations.filesystem.OpenMode
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class LayoutElementParcelableEspressoTest {
/**
* Test constructor of [LayoutElementParcelable] with a big remote file (size > 10 MB)
* and verify that the icon type is set to [IMAGE_RES].
*/
@Test
fun testConstructorWithBigRemoteFile() {
val a =
LayoutElementParcelable(
AppConfig.getInstance(),
false,
"test-verify.jpg",
"ssh://127.0.0.1:22222/home/user/test-verify.jpg",
"777",
"",
"17.89 MB",
17889945,
false,
System.currentTimeMillis().toString(),
false,
true,
OpenMode.SFTP,
)
a.iconData.run {
assertEquals(IMAGE_RES, type)
}
}

/**
* Test constructor of [LayoutElementParcelable] with a small remote file (size <= 10 MB)
* and verify that the icon type is set to [IMAGE_FROMCLOUD].
*/
@Test
fun testConstructorWithSmallRemoteFile() {
val b =
LayoutElementParcelable(
AppConfig.getInstance(),
false,
"test-verify.jpg",
"ssh://127.0.0.1:22222/home/user/test-verify.jpg",
"777",
"",
"100 KB",
102400,
false,
System.currentTimeMillis().toString(),
false,
true,
OpenMode.SFTP,
)
b.iconData.run {
assertEquals(IMAGE_FROMCLOUD, type)
Comment on lines +23 to +84
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This instrumentation test asserts that a large remote file defaults to IMAGE_RES, but the new preference default is index 0 ("No limit"), which should yield IMAGE_FROMCLOUD for remote images/APKs/videos. The test should explicitly set PREFERENCE_SHOW_REMOTE_THUMB_MAX_SIZE to a capped value before constructing the element (and ideally reset it afterward) to avoid a failing/flaky test that depends on persisted device prefs.

Suggested change
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.amaze.filemanager.adapters.data.IconDataParcelable.IMAGE_FROMCLOUD
import com.amaze.filemanager.adapters.data.IconDataParcelable.IMAGE_RES
import com.amaze.filemanager.application.AppConfig
import com.amaze.filemanager.fileoperations.filesystem.OpenMode
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class LayoutElementParcelableEspressoTest {
@Test
fun testConstructorWithBigRemoteFile() {
val a =
LayoutElementParcelable(
AppConfig.getInstance(),
false,
"test-verify.jpg",
"ssh://127.0.0.1:22222/home/user/test-verify.jpg",
"777",
"",
"17.89 MB",
17889945,
false,
System.currentTimeMillis().toString(),
false,
true,
OpenMode.SFTP,
)
a.iconData.run {
assertEquals(IMAGE_RES, type)
}
}
@Test
fun testConstructorWithSmallRemoteFile() {
val b =
LayoutElementParcelable(
AppConfig.getInstance(),
false,
"test-verify.jpg",
"ssh://127.0.0.1:22222/home/user/test-verify.jpg",
"777",
"",
"100 KB",
102400,
false,
System.currentTimeMillis().toString(),
false,
true,
OpenMode.SFTP,
)
b.iconData.run {
assertEquals(IMAGE_FROMCLOUD, type)
import android.content.SharedPreferences
import androidx.preference.PreferenceManager
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.amaze.filemanager.adapters.data.IconDataParcelable.IMAGE_FROMCLOUD
import com.amaze.filemanager.adapters.data.IconDataParcelable.IMAGE_RES
import com.amaze.filemanager.application.AppConfig
import com.amaze.filemanager.fileoperations.filesystem.OpenMode
import com.amaze.filemanager.utils.PreferenceConstants.PREFERENCE_SHOW_REMOTE_THUMB_MAX_SIZE
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class LayoutElementParcelableEspressoTest {
private companion object {
private const val CAPPED_REMOTE_THUMB_MAX_SIZE = "1"
}
private fun withRemoteThumbMaxSizePreference(value: String, block: () -> Unit) {
val preferences = PreferenceManager.getDefaultSharedPreferences(AppConfig.getInstance())
val originalValue = preferences.all[PREFERENCE_SHOW_REMOTE_THUMB_MAX_SIZE]
preferences.edit().putString(PREFERENCE_SHOW_REMOTE_THUMB_MAX_SIZE, value).commit()
try {
block()
} finally {
restorePreferenceValue(
preferences,
PREFERENCE_SHOW_REMOTE_THUMB_MAX_SIZE,
originalValue,
)
}
}
private fun restorePreferenceValue(
preferences: SharedPreferences,
key: String,
value: Any?,
) {
val editor = preferences.edit()
when (value) {
null -> editor.remove(key)
is String -> editor.putString(key, value)
is Int -> editor.putInt(key, value)
is Long -> editor.putLong(key, value)
is Float -> editor.putFloat(key, value)
is Boolean -> editor.putBoolean(key, value)
is Set<*> -> {
@Suppress("UNCHECKED_CAST")
editor.putStringSet(key, value as Set<String>)
}
}
editor.commit()
}
@Test
fun testConstructorWithBigRemoteFile() {
withRemoteThumbMaxSizePreference(CAPPED_REMOTE_THUMB_MAX_SIZE) {
val a =
LayoutElementParcelable(
AppConfig.getInstance(),
false,
"test-verify.jpg",
"ssh://127.0.0.1:22222/home/user/test-verify.jpg",
"777",
"",
"17.89 MB",
17889945,
false,
System.currentTimeMillis().toString(),
false,
true,
OpenMode.SFTP,
)
a.iconData.run {
assertEquals(IMAGE_RES, type)
}
}
}
@Test
fun testConstructorWithSmallRemoteFile() {
withRemoteThumbMaxSizePreference(CAPPED_REMOTE_THUMB_MAX_SIZE) {
val b =
LayoutElementParcelable(
AppConfig.getInstance(),
false,
"test-verify.jpg",
"ssh://127.0.0.1:22222/home/user/test-verify.jpg",
"777",
"",
"100 KB",
102400,
false,
System.currentTimeMillis().toString(),
false,
true,
OpenMode.SFTP,
)
b.iconData.run {
assertEquals(IMAGE_FROMCLOUD, type)
}

Copilot uses AI. Check for mistakes.
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,30 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.amaze.filemanager;
package com.amaze.filemanager

import com.amaze.filemanager.adapters.glide.apkimage.ApkImageModelLoaderFactory;
import com.amaze.filemanager.adapters.glide.cloudicon.CloudIconModelFactory;
import com.bumptech.glide.Glide;
import com.bumptech.glide.Registry;
import com.bumptech.glide.annotation.GlideModule;
import com.bumptech.glide.module.AppGlideModule;
import android.content.Context
import android.graphics.Bitmap
import android.graphics.drawable.Drawable
import com.amaze.filemanager.adapters.glide.apkimage.ApkImageModelLoaderFactory
import com.amaze.filemanager.adapters.glide.cloudicon.CloudIconModelFactory
import com.bumptech.glide.Glide
import com.bumptech.glide.Registry
import com.bumptech.glide.annotation.GlideModule
import com.bumptech.glide.module.AppGlideModule

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;

/** Ensures that Glide's generated API is created for the Gallery sample. */
@GlideModule
public class AmazeFileManagerModule extends AppGlideModule {
@Override
public void registerComponents(Context context, Glide glide, Registry registry) {
registry.prepend(String.class, Drawable.class, new ApkImageModelLoaderFactory(context));
registry.prepend(String.class, Bitmap.class, new CloudIconModelFactory(context));
}
class AmazeFileManagerModule : AppGlideModule() {
override fun registerComponents(
context: Context,
glide: Glide,
registry: Registry,
) {
registry.prepend(
String::class.java,
Drawable::class.java,
ApkImageModelLoaderFactory(context),
)
registry.prepend(String::class.java, Bitmap::class.java, CloudIconModelFactory(context))
}
}
Loading
Loading