Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasKaminsky committed Dec 7, 2023
2 parents 33db1c0 + 2b166a8 commit 4ee92c6
Show file tree
Hide file tree
Showing 21 changed files with 375 additions and 310 deletions.
4 changes: 4 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ android {
}
}

buildFeatures {
buildConfig = true
}

productFlavors {
// used for f-droid
generic {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class StackRemoteViewsFactory(
val userAccountManager: UserAccountManager,
val clientFactory: ClientFactory,
val intent: Intent,
val widgetRepository: WidgetRepository
private val widgetRepository: WidgetRepository
) : RemoteViewsService.RemoteViewsFactory {

private lateinit var widgetConfiguration: WidgetConfiguration
Expand Down Expand Up @@ -163,58 +163,20 @@ class StackRemoteViewsFactory(

// we will switch soon to coil and then streamline all of this
// Kotlin cannot catch multiple exception types at same time
@Suppress("NestedBlockDepth", "TooGenericExceptionCaught")
@Suppress("NestedBlockDepth")
private fun createItemView(position: Int): RemoteViews {
return RemoteViews(context.packageName, R.layout.widget_item).apply {
if (widgetItems.isEmpty()) {
return@apply
}

val widgetItem = widgetItems[position]

// icon bitmap/svg
if (widgetItem.iconUrl.isNotEmpty()) {
val glide: FutureTarget<Bitmap>
if (Uri.parse(widgetItem.iconUrl).encodedPath!!.endsWith(".svg")) {
glide = Glide.with(context)
.using(
CustomGlideUriLoader(userAccountManager.user, clientFactory),
InputStream::class.java
)
.from(Uri::class.java)
.`as`(SVGorImage::class.java)
.transcode(SvgOrImageBitmapTranscoder(SVG_SIZE, SVG_SIZE), Bitmap::class.java)
.sourceEncoder(StreamEncoder())
.cacheDecoder(FileToStreamDecoder(SvgOrImageDecoder()))
.decoder(SvgOrImageDecoder())
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.load(Uri.parse(widgetItem.iconUrl))
.into(SVG_SIZE, SVG_SIZE)
} else {
glide = Glide.with(context)
.using(CustomGlideStreamLoader(widgetConfiguration.user.get(), clientFactory))
.load(widgetItem.iconUrl)
.asBitmap()
.into(SVG_SIZE, SVG_SIZE)
}

try {
if (widgetConfiguration.roundIcon) {
setImageViewBitmap(R.id.icon, BitmapUtils.roundBitmap(glide.get()))
} else {
setImageViewBitmap(R.id.icon, glide.get())
}
} catch (e: Exception) {
Log_OC.d(TAG, "Error setting icon", e)
setImageViewResource(R.id.icon, R.drawable.ic_dashboard)
}
loadIcon(widgetItem, this)
}

// text
setTextViewText(R.id.title, widgetItem.title)

if (widgetItem.subtitle.isNotEmpty()) {
setViewVisibility(R.id.subtitle, View.VISIBLE)
setTextViewText(R.id.subtitle, widgetItem.subtitle)
} else {
setViewVisibility(R.id.subtitle, View.GONE)
}
updateTexts(widgetItem, this)

if (widgetItem.link.isNotEmpty()) {
val clickIntent = Intent(Intent.ACTION_VIEW, Uri.parse(widgetItem.link))
Expand All @@ -223,6 +185,65 @@ class StackRemoteViewsFactory(
}
}

@Suppress("TooGenericExceptionCaught")
private fun loadIcon(widgetItem: DashboardWidgetItem, remoteViews: RemoteViews) {
val isIconSVG = Uri.parse(widgetItem.iconUrl).encodedPath!!.endsWith(".svg")
val source: FutureTarget<Bitmap> = if (isIconSVG) {
loadSVGIcon(widgetItem)
} else {
loadBitmapIcon(widgetItem)
}

try {
val bitmap: Bitmap = if (widgetConfiguration.roundIcon) {
BitmapUtils.roundBitmap(source.get())
} else {
source.get()
}

remoteViews.setImageViewBitmap(R.id.icon, bitmap)
} catch (e: Exception) {
Log_OC.d(TAG, "Error setting icon", e)
remoteViews.setImageViewResource(R.id.icon, R.drawable.ic_dashboard)
}
}

private fun loadSVGIcon(widgetItem: DashboardWidgetItem): FutureTarget<Bitmap> {
return Glide.with(context)
.using(
CustomGlideUriLoader(userAccountManager.user, clientFactory),
InputStream::class.java
)
.from(Uri::class.java)
.`as`(SVGorImage::class.java)
.transcode(SvgOrImageBitmapTranscoder(SVG_SIZE, SVG_SIZE), Bitmap::class.java)
.sourceEncoder(StreamEncoder())
.cacheDecoder(FileToStreamDecoder(SvgOrImageDecoder()))
.decoder(SvgOrImageDecoder())
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.load(Uri.parse(widgetItem.iconUrl))
.into(SVG_SIZE, SVG_SIZE)
}

private fun loadBitmapIcon(widgetItem: DashboardWidgetItem): FutureTarget<Bitmap> {
return Glide.with(context)
.using(CustomGlideStreamLoader(widgetConfiguration.user.get(), clientFactory))
.load(widgetItem.iconUrl)
.asBitmap()
.into(SVG_SIZE, SVG_SIZE)
}

private fun updateTexts(widgetItem: DashboardWidgetItem, remoteViews: RemoteViews) {
remoteViews.setTextViewText(R.id.title, widgetItem.title)

if (widgetItem.subtitle.isNotEmpty()) {
remoteViews.setViewVisibility(R.id.subtitle, View.VISIBLE)
remoteViews.setTextViewText(R.id.subtitle, widgetItem.subtitle)
} else {
remoteViews.setViewVisibility(R.id.subtitle, View.GONE)
}
}

override fun getLoadingView(): RemoteViews? {
return null
}
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/java/com/owncloud/android/db/UploadResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public enum UploadResult {
OLD_ANDROID_API(18),
SYNC_CONFLICT(19),
CANNOT_CREATE_FILE(20),
LOCAL_STORAGE_NOT_COPIED(21);
LOCAL_STORAGE_NOT_COPIED(21),
QUOTA_EXCEEDED(22);

private final int value;

Expand Down Expand Up @@ -104,6 +105,8 @@ public static UploadResult fromValue(int value) {
return CANNOT_CREATE_FILE;
case 21:
return LOCAL_STORAGE_NOT_COPIED;
case 22:
return QUOTA_EXCEEDED;
}
return UNKNOWN;
}
Expand Down Expand Up @@ -162,6 +165,8 @@ public static UploadResult fromOperationResult(RemoteOperationResult result) {
return VIRUS_DETECTED;
case CANNOT_CREATE_FILE:
return CANNOT_CREATE_FILE;
case QUOTA_EXCEEDED:
return QUOTA_EXCEEDED;
default:
return UNKNOWN;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
import javax.inject.Inject;

import androidx.core.app.NotificationCompat;
import androidx.core.app.ServiceCompat;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import dagger.android.AndroidInjection;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
Expand Down Expand Up @@ -203,7 +204,11 @@ public int onStartCommand(Intent intent, int flags, int startId) {
Log_OC.d(TAG, "Starting command with id " + startId);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
startForeground(FOREGROUND_SERVICE_ID, mNotification, ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC);
ServiceCompat.startForeground(
this,
FOREGROUND_SERVICE_ID,
mNotification,
ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC);
} else {
startForeground(FOREGROUND_SERVICE_ID, mNotification);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,14 +350,18 @@ private void checkStoragePath() {
public void onConfigurationChanged(@NonNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);

StoragePermissionDialogFragment fragment = (StoragePermissionDialogFragment) getSupportFragmentManager().findFragmentByTag(PERMISSION_CHOICE_DIALOG_TAG);
if (fragment != null) {
Dialog dialog = fragment.getDialog();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
StoragePermissionDialogFragment fragment =
(StoragePermissionDialogFragment) getSupportFragmentManager()
.findFragmentByTag(PERMISSION_CHOICE_DIALOG_TAG);
if (fragment != null) {
Dialog dialog = fragment.getDialog();

if (dialog != null && dialog.isShowing()) {
dialog.dismiss();
getSupportFragmentManager().beginTransaction().remove(fragment).commitNowAllowingStateLoss();
PermissionUtil.requestExternalStoragePermission(this, viewThemeUtils);
if (dialog != null && dialog.isShowing()) {
dialog.dismiss();
getSupportFragmentManager().beginTransaction().remove(fragment).commitNowAllowingStateLoss();
PermissionUtil.requestExternalStoragePermission(this, viewThemeUtils);
}
}
}
}
Expand Down
Loading

0 comments on commit 4ee92c6

Please sign in to comment.