Skip to content

Commit

Permalink
add pref if download image when unsupported
Browse files Browse the repository at this point in the history
Signed-off-by: parneet-guraya <[email protected]>
  • Loading branch information
parneet-guraya authored and alperozturk96 committed Sep 11, 2024
1 parent a2eba07 commit a7b6d0d
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -391,4 +391,6 @@ default void onDarkThemeModeChanged(DarkMode mode) {

@NonNull
String getLastSelectedMediaFolder();

boolean getShouldDownloadUnsupportedImage();
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ public final class AppPreferencesImpl implements AppPreferences {
private static final String PREF__STORAGE_PERMISSION_REQUESTED = "storage_permission_requested";
private static final String PREF__IN_APP_REVIEW_DATA = "in_app_review_data";

private static final String PREF__ALWAYS_DOWNLOAD_UNSUPPORTED_IMAGES = "always_download_unsupported_images";

private static final String LOG_ENTRY = "log_entry";

private final Context context;
Expand Down Expand Up @@ -505,9 +507,12 @@ public void saveLogEntry(List<LogEntry> logEntryList) {
@Override
public List<LogEntry> readLogEntry() {
String json = preferences.getString(LOG_ENTRY, null);
if (json == null) return emptyList();
if (json == null) {
return emptyList();
}
Gson gson = new Gson();
Type listType = new TypeToken<List<LogEntry>>() {}.getType();
Type listType = new TypeToken<List<LogEntry>>() {
}.getType();
return gson.fromJson(json, listType);
}

Expand Down Expand Up @@ -732,7 +737,7 @@ public void setCalendarLastBackup(long timestamp) {

@Override
public boolean isGlobalUploadPaused() {
return preferences.getBoolean(PREF__GLOBAL_PAUSE_STATE,false);
return preferences.getBoolean(PREF__GLOBAL_PAUSE_STATE, false);
}

@Override
Expand Down Expand Up @@ -764,6 +769,7 @@ public void setStoragePermissionRequested(boolean value) {
public int computeBruteForceDelay(int count) {
return (int) Math.min(count / 3d, 10);
}

@Override
public void setInAppReviewData(@NonNull AppReviewShownModel appReviewShownModel) {
Gson gson = new Gson();
Expand All @@ -789,4 +795,10 @@ public void setLastSelectedMediaFolder(@NonNull String path) {
public String getLastSelectedMediaFolder() {
return preferences.getString(PREF__MEDIA_FOLDER_LAST_PATH, OCFile.ROOT_PATH);
}

@Override
public boolean getShouldDownloadUnsupportedImage() {
return preferences.getBoolean(PREF__ALWAYS_DOWNLOAD_UNSUPPORTED_IMAGES, false);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -723,26 +723,30 @@ class PreviewImageFragment : FileFragment(), Injectable {

fun setErrorPreviewMessage() {
try {
if (activity != null) {
Snackbar.make(
binding.emptyListView,
R.string.resized_image_not_possible_download,
Snackbar.LENGTH_INDEFINITE
)
.setAction(
R.string.common_yes
) { v: View? ->
val activity = activity as PreviewImageActivity?
if (activity != null) {
activity.requestForDownload(file)
} else if (context != null) {
Snackbar.make(
binding.emptyListView,
resources.getString(R.string.could_not_download_image),
Snackbar.LENGTH_INDEFINITE
).show()
}
}.show()
(requireActivity() as PreviewImageActivity).let { parentImageActivity ->
if (parentImageActivity.preferences.shouldDownloadUnsupportedImage) {
parentImageActivity.requestForDownload(file)
} else {
Snackbar.make(
binding.emptyListView,
R.string.resized_image_not_possible_download,
Snackbar.LENGTH_INDEFINITE
)
.setAction(
R.string.common_yes
) { v: View? ->
val activity = activity as PreviewImageActivity?
if (activity != null) {
activity.requestForDownload(file)
} else if (context != null) {
Snackbar.make(
binding.emptyListView,
resources.getString(R.string.could_not_download_image),
Snackbar.LENGTH_INDEFINITE
).show()
}
}.show()
}
}
} catch (e: IllegalArgumentException) {
Log_OC.d(TAG, e.message)
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1244,4 +1244,6 @@
<string name="file_name_validator_error_forbidden_file_extensions">.%s is a forbidden file extension</string>
<string name="file_name_validator_error_ends_with_space_period">Name ends with a space or a period</string>
<string name="sync">Sync</string>
<string name="download_unsupported_image">Download Unsupported Image</string>
<string name="always_download_unsupported_image">Always download unsupported image</string>
</resources>
6 changes: 6 additions & 0 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
android:title="@string/prefs_theme_title"
android:key="darkMode"
android:summary="%s" />

<com.owncloud.android.ui.ThemeableSwitchPreference
android:title="@string/download_unsupported_image"
android:summary="@string/always_download_unsupported_image"
android:key="always_download_unsupported_images"/>

</PreferenceCategory>
<PreferenceCategory
android:title="@string/drawer_synced_folders"
Expand Down

0 comments on commit a7b6d0d

Please sign in to comment.