diff options
19 files changed, 90 insertions, 109 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/DeckApplication.java b/app/src/main/java/it/niedermann/nextcloud/deck/DeckApplication.java index 85d3d0f1c..0b26e97f5 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/DeckApplication.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/DeckApplication.java @@ -1,8 +1,10 @@ package it.niedermann.nextcloud.deck; +import static androidx.appcompat.app.AppCompatDelegate.setDefaultNightMode; +import static androidx.lifecycle.Transformations.distinctUntilChanged; + import android.app.Application; import android.content.Context; -import android.content.SharedPreferences; import android.content.res.Configuration; import androidx.annotation.ColorInt; @@ -14,9 +16,6 @@ import androidx.preference.PreferenceManager; import it.niedermann.android.sharedpreferences.SharedPreferenceIntLiveData; import it.niedermann.nextcloud.deck.model.Account; -import static androidx.appcompat.app.AppCompatDelegate.setDefaultNightMode; -import static androidx.lifecycle.Transformations.distinctUntilChanged; - public class DeckApplication extends Application { public static final long NO_ACCOUNT_ID = -1L; @@ -35,7 +34,7 @@ public class DeckApplication extends Application { PREF_KEY_DEBUGGING = getString(R.string.pref_key_debugging); setAppTheme(getAppTheme(this)); DeckLog.enablePersistentLogs(isPersistentLoggingEnabled(this)); - final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); + final var sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); currentAccountColor$ = distinctUntilChanged(new SharedPreferenceIntLiveData(sharedPreferences, getString(R.string.shared_preference_last_account_color), ContextCompat.getColor(this, R.color.defaultBrand))); @@ -57,7 +56,7 @@ public class DeckApplication extends Application { // --------- public static boolean isPersistentLoggingEnabled(@NonNull Context context) { - final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); + final var sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); final boolean enabled = sharedPreferences.getBoolean(PREF_KEY_DEBUGGING, false); DeckLog.log("--- Read:", PREF_KEY_DEBUGGING, "→", enabled); return enabled; @@ -72,7 +71,7 @@ public class DeckApplication extends Application { } public static int getAppTheme(@NonNull Context context) { - final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + final var prefs = PreferenceManager.getDefaultSharedPreferences(context); String mode; try { mode = prefs.getString(PREF_KEY_THEME, context.getString(R.string.pref_value_theme_system_default)); @@ -101,7 +100,7 @@ public class DeckApplication extends Application { // -------------------------------------- public static void saveCurrentAccount(@NonNull Context context, @NonNull Account account) { - final SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit(); + final var editor = PreferenceManager.getDefaultSharedPreferences(context).edit(); DeckLog.log("--- Write:", context.getString(R.string.shared_preference_last_account), "→", account.getId()); editor.putLong(context.getString(R.string.shared_preference_last_account), account.getId()); DeckLog.log("--- Write:", context.getString(R.string.shared_preference_last_account_color), "→", account.getColor()); @@ -119,42 +118,42 @@ public class DeckApplication extends Application { @ColorInt public static int readCurrentAccountColor(@NonNull Context context) { - final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext()); + final var sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext()); @ColorInt final int accountColor = sharedPreferences.getInt(context.getString(R.string.shared_preference_last_account_color), context.getApplicationContext().getResources().getColor(R.color.defaultBrand)); DeckLog.log("--- Read:", context.getString(R.string.shared_preference_last_account_color), "→", accountColor); return accountColor; } public static long readCurrentAccountId(@NonNull Context context) { - final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); + final var sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); final long accountId = sharedPreferences.getLong(context.getString(R.string.shared_preference_last_account), NO_ACCOUNT_ID); DeckLog.log("--- Read:", context.getString(R.string.shared_preference_last_account), "→", accountId); return accountId; } public static void saveCurrentBoardId(@NonNull Context context, long accountId, long boardId) { - final SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit(); + final var editor = PreferenceManager.getDefaultSharedPreferences(context).edit(); DeckLog.log("--- Write:", context.getString(R.string.shared_preference_last_board_for_account_) + accountId, "→", boardId); editor.putLong(context.getString(R.string.shared_preference_last_board_for_account_) + accountId, boardId); editor.apply(); } public static long readCurrentBoardId(@NonNull Context context, long accountId) { - final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); + final var sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); final long boardId = sharedPreferences.getLong(context.getString(R.string.shared_preference_last_board_for_account_) + accountId, NO_BOARD_ID); DeckLog.log("--- Read:", context.getString(R.string.shared_preference_last_board_for_account_) + accountId, "→", boardId); return boardId; } public static void saveCurrentStackId(@NonNull Context context, long accountId, long boardId, long stackId) { - final SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit(); + final var editor = PreferenceManager.getDefaultSharedPreferences(context).edit(); DeckLog.log("--- Write:", context.getString(R.string.shared_preference_last_stack_for_account_and_board_) + accountId + "_" + boardId, "→", stackId); editor.putLong(context.getString(R.string.shared_preference_last_stack_for_account_and_board_) + accountId + "_" + boardId, stackId); editor.apply(); } public static long readCurrentStackId(@NonNull Context context, long accountId, long boardId) { - final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); + final var sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); final long savedStackId = sharedPreferences.getLong(context.getString(R.string.shared_preference_last_stack_for_account_and_board_) + accountId + "_" + boardId, NO_STACK_ID); DeckLog.log("--- Read:", context.getString(R.string.shared_preference_last_stack_for_account_and_board_) + accountId + "_" + boardId, "→", savedStackId); return savedStackId; diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/tiles/EditCardTileService.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/tiles/EditCardTileService.java index 09abbfa7a..ad691c943 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/tiles/EditCardTileService.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/tiles/EditCardTileService.java @@ -13,14 +13,14 @@ public class EditCardTileService extends TileService { @Override public void onStartListening() { - Tile tile = getQsTile(); + final var tile = getQsTile(); tile.setState(Tile.STATE_ACTIVE); tile.updateTile(); } @Override public void onClick() { - Intent intent = new Intent(getApplicationContext(), PrepareCreateActivity.class); + final var intent = new Intent(getApplicationContext(), PrepareCreateActivity.class); // ensure it won't open twice if already running intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); // ask to unlock the screen if locked, then start new note intent diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/view/ColorChooser.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/view/ColorChooser.java index 0dd431ff9..8345e63b9 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/view/ColorChooser.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/view/ColorChooser.java @@ -1,7 +1,6 @@ package it.niedermann.nextcloud.deck.ui.view; import android.content.Context; -import android.content.res.TypedArray; import android.graphics.Color; import android.util.AttributeSet; import android.view.LayoutInflater; @@ -42,22 +41,22 @@ public class ColorChooser extends LinearLayout { super(context, attrs); this.context = context; - final FlexboxLayout.LayoutParams params = new FlexboxLayout.LayoutParams( + final var params = new FlexboxLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT ); params.setMargins(0, DimensionUtil.INSTANCE.dpToPx(context, R.dimen.spacer_1x), 0, 0); params.setFlexBasisPercent(.15f); - final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ColorChooser, 0, 0); - colors = Arrays.stream(getResources().getStringArray(a.getResourceId(R.styleable.ColorChooser_colors, 0))) + final var styles = context.obtainStyledAttributes(attrs, R.styleable.ColorChooser, 0, 0); + colors = Arrays.stream(getResources().getStringArray(styles.getResourceId(R.styleable.ColorChooser_colors, 0))) .mapToInt(Color::parseColor) .toArray(); - a.recycle(); + styles.recycle(); binding = WidgetColorChooserBinding.inflate(LayoutInflater.from(context), this, true); for (final int color : colors) { - final ImageView image = new ImageView(getContext()); + final var image = new ImageView(getContext()); image.setLayoutParams(params); image.setOnClickListener((imageView) -> { if (previouslySelectedImageView != null) { // null when first selection diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/view/EmptyContentView.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/view/EmptyContentView.java index 3564662ce..b103e528a 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/view/EmptyContentView.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/view/EmptyContentView.java @@ -1,7 +1,6 @@ package it.niedermann.nextcloud.deck.ui.view; import android.content.Context; -import android.content.res.TypedArray; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; @@ -24,19 +23,19 @@ public class EmptyContentView extends RelativeLayout { binding = WidgetEmptyContentViewBinding.inflate(LayoutInflater.from(context), this, true); - TypedArray a = context.obtainStyledAttributes(attrs, + final var styles = context.obtainStyledAttributes(attrs, R.styleable.EmptyContentView, 0, 0); - @StringRes int descriptionRes = a.getResourceId(R.styleable.EmptyContentView_description, NO_DESCRIPTION); + @StringRes int descriptionRes = styles.getResourceId(R.styleable.EmptyContentView_description, NO_DESCRIPTION); - binding.title.setText(getResources().getString(a.getResourceId(R.styleable.EmptyContentView_title, R.string.no_content))); + binding.title.setText(getResources().getString(styles.getResourceId(R.styleable.EmptyContentView_title, R.string.no_content))); if (descriptionRes == NO_DESCRIPTION) { binding.description.setVisibility(View.GONE); } else { binding.description.setText(getResources().getString(descriptionRes)); } - binding.image.setImageResource(a.getResourceId(R.styleable.EmptyContentView_image, R.drawable.ic_app_logo)); - a.recycle(); + binding.image.setImageResource(styles.getResourceId(R.styleable.EmptyContentView_image, R.drawable.ic_app_logo)); + styles.recycle(); } public void hideDescription() { diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/view/OverlappingAvatars.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/view/OverlappingAvatars.java index 0facc385c..9d15df896 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/view/OverlappingAvatars.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/view/OverlappingAvatars.java @@ -4,7 +4,6 @@ import android.content.Context; import android.graphics.drawable.Drawable; import android.net.Uri; import android.util.AttributeSet; -import android.view.ViewGroup; import android.widget.ImageView; import android.widget.RelativeLayout; @@ -53,7 +52,7 @@ public class OverlappingAvatars extends RelativeLayout { } public void setAvatars(@NonNull Account account, @NonNull List<User> assignedUsers) { - @NonNull Context context = getContext(); + @NonNull final var context = getContext(); removeAllViews(); RelativeLayout.LayoutParams avatarLayoutParams; int avatarCount; @@ -62,7 +61,7 @@ public class OverlappingAvatars extends RelativeLayout { avatarLayoutParams.setMargins(0, 0, avatarCount * overlapPx, 0); avatarLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); - final ImageView avatar = new ImageView(context); + final var avatar = new ImageView(context); avatar.setLayoutParams(avatarLayoutParams); avatar.setPadding(avatarBorderSize, avatarBorderSize, avatarBorderSize, avatarBorderSize); @@ -79,7 +78,7 @@ public class OverlappingAvatars extends RelativeLayout { // Recalculate container size based on avatar count int size = overlapPx * (avatarCount - 1) + avatarSize; - ViewGroup.LayoutParams rememberParam = getLayoutParams(); + final var rememberParam = getLayoutParams(); rememberParam.width = size; setLayoutParams(rememberParam); } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/view/SquareRelativeLayout.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/view/SquareRelativeLayout.java index cdce90251..6937a370d 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/view/SquareRelativeLayout.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/view/SquareRelativeLayout.java @@ -25,6 +25,7 @@ public class SquareRelativeLayout extends RelativeLayout { @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { // Set a square layout. + //noinspection SuspiciousNameCombination super.onMeasure(widthMeasureSpec, widthMeasureSpec); } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/view/labelchip/LabelChip.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/view/labelchip/LabelChip.java index 83853f0b2..d69ff2898 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/view/labelchip/LabelChip.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/view/labelchip/LabelChip.java @@ -43,8 +43,8 @@ public class LabelChip extends Chip { try { int labelColor = label.getColor(); - ColorStateList c = ColorStateList.valueOf(labelColor); - setChipBackgroundColor(c); + final var colorStateList = ColorStateList.valueOf(labelColor); + setChipBackgroundColor(colorStateList); setTextColor(ColorUtil.INSTANCE.getForegroundColorForBackgroundColor(labelColor)); } catch (IllegalArgumentException e) { DeckLog.logError(e); diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/view/labellayout/LabelLayout.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/view/labellayout/LabelLayout.java index 3db539e53..526bdbaef 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/view/labellayout/LabelLayout.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/view/labellayout/LabelLayout.java @@ -56,9 +56,9 @@ public abstract class LabelLayout extends FlexboxLayout { private void removeObsoleteLabels(List<Label> labels) { chipList: for (int i = 0; i < chipList.size(); i++) { - LabelChip currentChip = chipList.get(i); - final Label existingLabel = currentChip.getLabel(); - for (Label label : labels) { + final var currentChip = chipList.get(i); + final var existingLabel = currentChip.getLabel(); + for (final var label : labels) { if (existingLabel.equals(label)) { continue chipList; } @@ -75,15 +75,15 @@ public abstract class LabelLayout extends FlexboxLayout { private void addNewLabels(List<Label> labels) { int oldLabelSize = chipList.size(); labelList: - for (Label label : labels) { + for (final var label : labels) { for (int i = 0; i < oldLabelSize; i++) { - final LabelChip currentChip = chipList.get(i); - final Label existingLabel = currentChip.getLabel(); + final var currentChip = chipList.get(i); + final var existingLabel = currentChip.getLabel(); if (existingLabel.equals(label)) { continue labelList; } } - final LabelChip chip = createLabelChip(label); + final var chip = createLabelChip(label); addView(chip); chipList.add(chip); } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/util/AttachmentUtil.java b/app/src/main/java/it/niedermann/nextcloud/deck/util/AttachmentUtil.java index fa514952c..aba73a11e 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/util/AttachmentUtil.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/util/AttachmentUtil.java @@ -4,7 +4,6 @@ import android.content.Context; import android.content.Intent; import android.net.Uri; import android.text.TextUtils; -import android.webkit.MimeTypeMap; import android.widget.Toast; import androidx.annotation.DrawableRes; @@ -110,13 +109,4 @@ public class AttachmentUtil { } } - public static String getMimeType(@Nullable String url) { - String type = null; - String extension = MimeTypeMap.getFileExtensionFromUrl(url); - if (extension != null) { - type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); - } - return type; - } - } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/util/CardUtil.java b/app/src/main/java/it/niedermann/nextcloud/deck/util/CardUtil.java index f8a1a9b1a..a0e3bdd69 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/util/CardUtil.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/util/CardUtil.java @@ -13,7 +13,6 @@ import java.util.stream.Collectors; import it.niedermann.android.markdown.MarkdownUtil; import it.niedermann.nextcloud.deck.R; -import it.niedermann.nextcloud.deck.model.Card; import it.niedermann.nextcloud.deck.model.Label; import it.niedermann.nextcloud.deck.model.full.FullCard; @@ -28,21 +27,21 @@ public class CardUtil { */ @NonNull public static String getCardContentAsString(@NonNull Context context, @NonNull FullCard fullCard) { - final Card card = fullCard.getCard(); - String text = card.getDescription(); + final var card = fullCard.getCard(); + final var text = new StringBuilder(card.getDescription()); if(card.getDueDate() != null) { if(!TextUtils.isEmpty(text)) { - text += "\n"; + text.append("\n"); } - text += context.getString(R.string.share_content_duedate, card.getDueDate().atZone(ZoneId.systemDefault()).format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM))); + text.append(context.getString(R.string.share_content_duedate, card.getDueDate().atZone(ZoneId.systemDefault()).format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM)))); } if(fullCard.getLabels() != null && !fullCard.getLabels().isEmpty()) { if(!TextUtils.isEmpty(text)) { - text += "\n"; + text.append("\n"); } - text += context.getString(R.string.share_content_labels, fullCard.getLabels().stream().map(Label::getTitle).collect(Collectors.joining(", "))); + text.append(context.getString(R.string.share_content_labels, fullCard.getLabels().stream().map(Label::getTitle).collect(Collectors.joining(", ")))); } - return text; + return text.toString(); } public static boolean cardHasCommentsOrAttachments(@NonNull FullCard fullCard) { @@ -65,7 +64,7 @@ public class CardUtil { @NonNull private static String getLineWithoutMarkDown(@NonNull String content, @SuppressWarnings("SameParameterValue") int lineNumber) { if (content.contains("\n")) { - final String[] lines = content.split("\n"); + final var lines = content.split("\n"); int currentLine = lineNumber; while (currentLine < lines.length && isEmptyLine(lines[currentLine])) { currentLine++; diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/util/CustomAppGlideModule.java b/app/src/main/java/it/niedermann/nextcloud/deck/util/CustomAppGlideModule.java index 3e7b2d44b..6b17d7881 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/util/CustomAppGlideModule.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/util/CustomAppGlideModule.java @@ -2,7 +2,6 @@ package it.niedermann.nextcloud.deck.util; import android.content.Context; import android.net.ConnectivityManager; -import android.net.NetworkInfo; import androidx.annotation.NonNull; import androidx.annotation.UiThread; @@ -29,9 +28,9 @@ public class CustomAppGlideModule extends AppGlideModule { @UiThread public static void clearCache(@NonNull Context context) { - final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + final var cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); if (cm != null) { - final NetworkInfo activeNetworkInfo = cm.getActiveNetworkInfo(); + final var activeNetworkInfo = cm.getActiveNetworkInfo(); if (activeNetworkInfo != null && activeNetworkInfo.isConnected()) { DeckLog.info("Clearing Glide memory cache"); Glide.get(context).clearMemory(); diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/util/DeckColorUtil.java b/app/src/main/java/it/niedermann/nextcloud/deck/util/DeckColorUtil.java index f69b59757..82a3efd1f 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/util/DeckColorUtil.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/util/DeckColorUtil.java @@ -18,8 +18,8 @@ public final class DeckColorUtil { private static final Map<ColorPair, Boolean> CONTRAST_RATIO_SUFFICIENT_CACHE = new HashMap<>(); public static boolean contrastRatioIsSufficient(@ColorInt int colorOne, @ColorInt int colorTwo) { - ColorPair key = new ColorPair(colorOne, colorTwo); - Boolean ret = CONTRAST_RATIO_SUFFICIENT_CACHE.get(key); + final var key = new ColorPair(colorOne, colorTwo); + var ret = CONTRAST_RATIO_SUFFICIENT_CACHE.get(key); if (ret == null) { ret = ColorUtil.INSTANCE.getContrastRatio(colorOne, colorTwo) > 3d; CONTRAST_RATIO_SUFFICIENT_CACHE.put(key, ret); @@ -29,8 +29,8 @@ public final class DeckColorUtil { } public static boolean contrastRatioIsSufficientBigAreas(@ColorInt int colorOne, @ColorInt int colorTwo) { - ColorPair key = new ColorPair(colorOne, colorTwo); - Boolean ret = CONTRAST_RATIO_SUFFICIENT_CACHE.get(key); + final var key = new ColorPair(colorOne, colorTwo); + var ret = CONTRAST_RATIO_SUFFICIENT_CACHE.get(key); if (ret == null) { ret = ColorUtil.INSTANCE.getContrastRatio(colorOne, colorTwo) > 1.47d; CONTRAST_RATIO_SUFFICIENT_CACHE.put(key, ret); @@ -48,7 +48,7 @@ public final class DeckColorUtil { @SuppressWarnings({"EqualsWhichDoesntCheckParameterClass", "NumberEquality"}) @Override public boolean equals(Object o) { - final ColorPair colorPair = (ColorPair) o; + final var colorPair = (ColorPair) o; if (first != colorPair.first) return false; return second == colorPair.second; } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/util/DrawerMenuUtil.java b/app/src/main/java/it/niedermann/nextcloud/deck/util/DrawerMenuUtil.java index d315c1867..1683a8ef4 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/util/DrawerMenuUtil.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/util/DrawerMenuUtil.java @@ -38,17 +38,17 @@ public class DrawerMenuUtil { boolean currentServerVersionIsSupported) { menu.add(Menu.NONE, MENU_ID_UPCOMING_CARDS, Menu.NONE, R.string.widget_upcoming_title).setIcon(R.drawable.calendar_blank_grey600_24dp); int index = 0; - for (Board board : boards) { - final MenuItem m = menu + for (final var board : boards) { + final var menuItem = menu .add(Menu.NONE, index++, Menu.NONE, board.getTitle()).setIcon(ViewUtil.getTintedImageView(context, R.drawable.circle_grey600_36dp, board.getColor())) .setCheckable(true); if (currentServerVersionIsSupported) { if (board.isPermissionManage()) { - final AppCompatImageButton contextMenu = new AppCompatImageButton(context); + final var contextMenu = new AppCompatImageButton(context); contextMenu.setBackgroundDrawable(null); contextMenu.setImageDrawable(ViewUtil.getTintedImageView(context, R.drawable.ic_menu, ContextCompat.getColor(context, R.color.grey600))); contextMenu.setOnClickListener((v) -> { - PopupMenu popup = new PopupMenu(context, contextMenu); + final var popup = new PopupMenu(context, contextMenu); popup.getMenuInflater().inflate(R.menu.navigation_context_menu, popup.getMenu()); final int SHARE_BOARD_ID = -1; if (board.isPermissionShare()) { @@ -80,13 +80,13 @@ public class DrawerMenuUtil { }); popup.show(); }); - m.setActionView(contextMenu); + menuItem.setActionView(contextMenu); } else if (board.isPermissionShare()) { - final AppCompatImageButton contextMenu = new AppCompatImageButton(context); + final var contextMenu = new AppCompatImageButton(context); contextMenu.setBackgroundDrawable(null); contextMenu.setImageDrawable(ViewUtil.getTintedImageView(context, R.drawable.ic_share_grey600_18dp, ContextCompat.getColor(context, R.color.grey600))); contextMenu.setOnClickListener((v) -> AccessControlDialogFragment.newInstance(board.getLocalId()).show(context.getSupportFragmentManager(), AccessControlDialogFragment.class.getSimpleName())); - m.setActionView(contextMenu); + menuItem.setActionView(contextMenu); } } } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/util/FilesUtil.java b/app/src/main/java/it/niedermann/nextcloud/deck/util/FilesUtil.java index 3e4a5842f..01ea4e004 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/util/FilesUtil.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/util/FilesUtil.java @@ -10,7 +10,6 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; -import java.io.InputStream; import it.niedermann.nextcloud.deck.DeckLog; @@ -30,12 +29,12 @@ public class FilesUtil { */ @WorkerThread public static File copyContentUriToTempFile(@NonNull Context context, @NonNull Uri currentUri, long accountId, Long localCardId) throws IOException, IllegalArgumentException { - final InputStream inputStream = context.getContentResolver().openInputStream(currentUri); + final var inputStream = context.getContentResolver().openInputStream(currentUri); if (inputStream == null) { throw new IOException("Could not open input stream for " + currentUri.getPath()); } - final File cacheFile = getTempCacheFile(context, "attachments/account-" + accountId + "/card-" + (localCardId == null ? "pending-creation" : localCardId) + '/' + UriUtils.getDisplayNameForUri(currentUri, context)); - final FileOutputStream outputStream = new FileOutputStream(cacheFile); + final var cacheFile = getTempCacheFile(context, "attachments/account-" + accountId + "/card-" + (localCardId == null ? "pending-creation" : localCardId) + '/' + UriUtils.getDisplayNameForUri(currentUri, context)); + final var outputStream = new FileOutputStream(cacheFile); byte[] buffer = new byte[4096]; int count; @@ -50,11 +49,11 @@ public class FilesUtil { * Creates a new {@link File} */ public static File getTempCacheFile(@NonNull Context context, String fileName) throws IOException { - File cacheFile = new File(context.getApplicationContext().getFilesDir().getAbsolutePath() + "/" + fileName); + final var cacheFile = new File(context.getApplicationContext().getFilesDir().getAbsolutePath() + "/" + fileName); DeckLog.verbose("- Full path for new cache file:", cacheFile.getAbsolutePath()); - final File tempDir = cacheFile.getParentFile(); + final var tempDir = cacheFile.getParentFile(); if (tempDir == null) { throw new FileNotFoundException("could not cacheFile.getParentFile()"); } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/util/ProjectUtil.java b/app/src/main/java/it/niedermann/nextcloud/deck/util/ProjectUtil.java index 781b5dabf..51d6c83c5 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/util/ProjectUtil.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/util/ProjectUtil.java @@ -19,13 +19,13 @@ public class ProjectUtil { public static Uri getResourceUri(@NonNull Account account, @NonNull String link) throws IllegalArgumentException { try { // Assume link contains a fully qualified Uri including host - final URL u = new URL(link); - return Uri.parse(u.toString()); + final var url = new URL(link); + return Uri.parse(url.toString()); } catch (Throwable linkIsNotQualified) { try { // Assume link is a absolute path that needs to be concatenated with account url for a complete Uri - final URL u = new URL(account.getUrl() + link); - return Uri.parse(u.toString()); + final var url = new URL(account.getUrl() + link); + return Uri.parse(url.toString()); } catch (Throwable throwable) { throw new IllegalArgumentException("Could not parse " + Uri.class.getSimpleName() + ": " + link, throwable); } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/util/SpannableUtil.java b/app/src/main/java/it/niedermann/nextcloud/deck/util/SpannableUtil.java index f8be0e90d..664407d72 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/util/SpannableUtil.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/util/SpannableUtil.java @@ -25,30 +25,30 @@ public class SpannableUtil { } public static SpannableString strong(@NonNull CharSequence text) { - final SpannableString span = new SpannableString(text); - span.setSpan(new StyleSpan(Typeface.BOLD), 0, span.length(), 0); - return span; + final var spannable = new SpannableString(text); + spannable.setSpan(new StyleSpan(Typeface.BOLD), 0, spannable.length(), 0); + return spannable; } public static SpannableString disabled(@NonNull CharSequence text, @NonNull Context context) { - final SpannableString span = new SpannableString(text); - span.setSpan(new StyleSpan(Typeface.ITALIC), 0, span.length(), 0); - span.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, R.color.fg_secondary)), 0, span.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - return span; + final var spannable = new SpannableString(text); + spannable.setSpan(new StyleSpan(Typeface.ITALIC), 0, spannable.length(), 0); + spannable.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, R.color.fg_secondary)), 0, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + return spannable; } public static SpannableString url(@NonNull CharSequence text, @NonNull String target) { - final SpannableString span = new SpannableString(text); - span.setSpan(new URLSpan(target), 0, span.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - return span; + final var spannable = new SpannableString(text); + spannable.setSpan(new URLSpan(target), 0, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + return spannable; } public static void setTextWithURL(@NonNull TextView textView, @NonNull Resources resources, @StringRes int containerTextId, @StringRes int linkLabelId, @StringRes int urlId) { final String linkLabel = resources.getString(linkLabelId); final String finalText = resources.getString(containerTextId, linkLabel); - final SpannableString finalSpannable = new SpannableString(finalText); - finalSpannable.setSpan(new URLSpan(resources.getString(urlId)), finalText.indexOf(linkLabel), finalText.indexOf(linkLabel) + linkLabel.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); - textView.setText(finalSpannable); + final var spannable = new SpannableString(finalText); + spannable.setSpan(new URLSpan(resources.getString(urlId)), finalText.indexOf(linkLabel), finalText.indexOf(linkLabel) + linkLabel.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + textView.setText(spannable); textView.setMovementMethod(new LinkMovementMethod()); } } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/util/UriUtils.java b/app/src/main/java/it/niedermann/nextcloud/deck/util/UriUtils.java index c317359cc..44031b70e 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/util/UriUtils.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/util/UriUtils.java @@ -2,7 +2,6 @@ package it.niedermann.nextcloud.deck.util; import android.content.ContentResolver; import android.content.Context; -import android.database.Cursor; import android.net.Uri; import android.provider.MediaStore; import android.webkit.MimeTypeMap; @@ -77,7 +76,7 @@ public final class UriUtils { displayNameColumn = MediaStore.Files.FileColumns.DISPLAY_NAME; } - try (Cursor cursor = context.getContentResolver().query( + try (final var cursor = context.getContentResolver().query( uri, new String[]{displayNameColumn}, null, null, null )) { diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/util/VCardUtil.java b/app/src/main/java/it/niedermann/nextcloud/deck/util/VCardUtil.java index a3e4f6d31..6c4b091fc 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/util/VCardUtil.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/util/VCardUtil.java @@ -1,8 +1,6 @@ package it.niedermann.nextcloud.deck.util; -import android.content.ContentResolver; import android.content.Context; -import android.database.Cursor; import android.graphics.Color; import android.net.Uri; import android.provider.ContactsContract; @@ -22,8 +20,8 @@ public class VCardUtil { } public static Uri getVCardContentUri(@NonNull Context context, @NonNull Uri contactUri) throws NoSuchElementException { - final ContentResolver cr = context.getContentResolver(); - try (final Cursor cursor = cr.query(contactUri, null, null, null, null)) { + final var cr = context.getContentResolver(); + try (final var cursor = cr.query(contactUri, null, null, null, null)) { if (cursor != null && cursor.moveToFirst()) { final String lookupKey = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY)); return Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_VCARD_URI, lookupKey); diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/util/ViewUtil.java b/app/src/main/java/it/niedermann/nextcloud/deck/util/ViewUtil.java index ba1b3e785..12f3418c3 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/util/ViewUtil.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/util/ViewUtil.java @@ -1,5 +1,8 @@ package it.niedermann.nextcloud.deck.util; +import static java.time.temporal.ChronoUnit.DAYS; +import static it.niedermann.nextcloud.deck.DeckApplication.isDarkTheme; + import android.content.Context; import android.content.res.ColorStateList; import android.graphics.drawable.Drawable; @@ -24,9 +27,6 @@ import java.time.LocalDate; import it.niedermann.android.util.DimensionUtil; import it.niedermann.nextcloud.deck.R; -import static it.niedermann.nextcloud.deck.DeckApplication.isDarkTheme; -import static java.time.temporal.ChronoUnit.DAYS; - public final class ViewUtil { private ViewUtil() { @@ -71,9 +71,9 @@ public final class ViewUtil { } public static Drawable getTintedImageView(@NonNull Context context, @DrawableRes int imageId, @ColorInt int color) { - final Drawable drawable = ContextCompat.getDrawable(context, imageId); + final var drawable = ContextCompat.getDrawable(context, imageId); assert drawable != null; - final Drawable wrapped = DrawableCompat.wrap(drawable).mutate(); + final var wrapped = DrawableCompat.wrap(drawable).mutate(); DrawableCompat.setTint(wrapped, color); return drawable; } |