Skip to content

Commit

Permalink
Customized theming related changes for grid and list views.
Browse files Browse the repository at this point in the history
NMC-2121: Theming applied to passcode.
NMC-2374: Image edit functionality customized.
  • Loading branch information
surinder-tsys committed Sep 13, 2024
1 parent 2f4dcbd commit c9bb244
Show file tree
Hide file tree
Showing 33 changed files with 479 additions and 249 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package com.nextcloud.client.editimage

import android.graphics.Bitmap
import android.graphics.drawable.ColorDrawable
import android.net.Uri
import android.os.Build
import android.os.Bundle
Expand All @@ -16,9 +17,6 @@ import android.view.MenuItem
import android.view.View
import androidx.appcompat.content.res.AppCompatResources
import androidx.core.content.ContextCompat
import androidx.core.graphics.drawable.DrawableCompat
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat
import com.canhub.cropper.CropImageView
import com.nextcloud.client.di.Injectable
import com.nextcloud.client.jobs.upload.FileUploadHelper
Expand Down Expand Up @@ -73,21 +71,25 @@ class EditImageActivity :
file = intent.extras?.getParcelableArgument(EXTRA_FILE, OCFile::class.java)
?: throw IllegalArgumentException("Missing file argument")

setSupportActionBar(binding.toolbar)
supportActionBar?.apply {
title = file.fileName
setDisplayHomeAsUpEnabled(true)
}

val windowInsetsController = WindowCompat.getInsetsController(window, window.decorView)
windowInsetsController.hide(WindowInsetsCompat.Type.statusBars())

window.statusBarColor = ContextCompat.getColor(this, R.color.black)
window.navigationBarColor = getColor(R.color.black)
//NMC Customization
setupToolbar()
setupActionBar()

setupCropper()
}

//NMC Customization
private fun setupActionBar() {
supportActionBar?.let {
viewThemeUtils.platform.themeStatusBar(this)
it.setDisplayHomeAsUpEnabled(true)
it.setDisplayShowTitleEnabled(true)
//custom color for back arrow for NMC
viewThemeUtils.files.themeActionBar(this, it, file.fileName)
it.setBackgroundDrawable(ColorDrawable(resources.getColor(R.color.bg_default, null)))
}
}

override fun onCropImageComplete(view: CropImageView, result: CropImageView.CropResult) {
if (!result.isSuccessful) {
DisplayUtils.showSnackMessage(this, getString(R.string.image_editor_unable_to_edit_image))
Expand Down Expand Up @@ -124,14 +126,20 @@ class EditImageActivity :
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
// add save button to action bar
menuInflater.inflate(R.menu.custom_menu_placeholder, menu)
val saveIcon = AppCompatResources.getDrawable(this, R.drawable.ic_check)?.also {
DrawableCompat.setTint(it, resources.getColor(R.color.white, theme))
}
// NMC: No need to apply NC tint here as we will be doing it later in code
val saveIcon = AppCompatResources.getDrawable(this, R.drawable.ic_tick)
menu?.findItem(R.id.custom_menu_placeholder_item)?.apply {
icon = saveIcon
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
contentDescription = getString(R.string.common_save)
}
// NMC customization
icon = icon?.let {
viewThemeUtils.platform.colorDrawable(
it,
ContextCompat.getColor(this@EditImageActivity, R.color.fontAppbar)
)
}
}
return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ class FileActionsBottomSheet : BottomSheetDialogFragment(), Injectable {
binding.thumbnailLayout.thumbnailShimmer,
syncedFolderProvider.preferences,
viewThemeUtils,
syncedFolderProvider
syncedFolderProvider,
false
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,6 @@ private static String getWebLoginUserAgent() {
@SuppressFBWarnings("ANDROID_WEB_VIEW_JAVASCRIPT")
@SuppressLint("SetJavaScriptEnabled")
private void initWebViewLogin(String baseURL, boolean useGenericUserAgent) {
viewThemeUtils.platform.colorCircularProgressBar(accountSetupWebviewBinding.loginWebviewProgressBar, ColorRole.ON_PRIMARY_CONTAINER);
accountSetupWebviewBinding.loginWebview.setVisibility(View.GONE);
new WebViewUtil(this).setProxyKKPlus(accountSetupWebviewBinding.loginWebview);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import androidx.annotation.VisibleForTesting
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
import com.google.android.material.snackbar.Snackbar
import com.nextcloud.android.common.ui.theme.utils.ColorRole
import com.nextcloud.client.di.Injectable
import com.nextcloud.client.preferences.AppPreferences
import com.owncloud.android.R
Expand Down Expand Up @@ -80,30 +79,18 @@ class PassCodeActivity : AppCompatActivity(), Injectable {
setContentView(binding.root)

PassCodeManager.setSecureFlag(this, true)
applyTint()
setupPasscodeEditTexts()
setSoftInputMode()
setupUI(savedInstanceState)
setTextListeners()
}

private fun applyTint() {
viewThemeUtils.platform.colorViewBackground(binding.cardViewContent, ColorRole.SURFACE_VARIANT)
viewThemeUtils.material.colorMaterialButtonPrimaryBorderless(binding.cancel)
}

private fun setupPasscodeEditTexts() {
passCodeEditTexts[0] = binding.txt0
passCodeEditTexts[1] = binding.txt1
passCodeEditTexts[2] = binding.txt2
passCodeEditTexts[3] = binding.txt3

passCodeEditTexts.forEach {
it?.let { editText ->
viewThemeUtils.platform.colorEditText(editText)
}
}

passCodeEditTexts[0]?.requestFocus()

binding.cardViewContent.setOnClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ class GalleryAdapter(
transferServiceGetter,
showMetadata = false,
showShareAvatar = false,
viewThemeUtils
viewThemeUtils,
true
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int positi
if (isCheckedFile(file)) {
gridViewHolder.itemLayout.setBackgroundColor(ContextCompat.getColor(mContext, R.color.selected_item_background));

gridViewHolder.checkbox.setImageDrawable(
viewThemeUtils.platform.tintDrawable(mContext, R.drawable.ic_checkbox_marked, ColorRole.PRIMARY));
gridViewHolder.checkbox.setImageResource(R.drawable.ic_checkbox_marked);
} else {
gridViewHolder.itemLayout.setBackgroundColor(mContext.getResources().getColor(R.color.bg_default));
gridViewHolder.checkbox.setImageResource(R.drawable.ic_checkbox_blank_outline);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ public OCFileListAdapter(
.getVersion()
.isShareesOnDavSupported(),
viewThemeUtils,
false,
syncedFolderProvider);

setHasStableIds(true);
Expand Down Expand Up @@ -370,6 +371,8 @@ public boolean isEmpty() {
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
switch (viewType) {
// change required for NMC
// default case will be used for VIEW_TYPE_IMAGE & VIEWTYPE_ITEM also
default -> {
if (gridView) {
return new OCFileListGridItemViewHolder(
Expand All @@ -381,17 +384,6 @@ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int
);
}
}
case VIEW_TYPE_IMAGE -> {
if (gridView) {
return new OCFileListViewHolder(
GridImageBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)
);
} else {
return new OCFileListItemViewHolder(
ListItemBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)
);
}
}
case VIEW_TYPE_FOOTER -> {
return new OCFileListFooterViewHolder(
ListFooterBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)
Expand All @@ -415,7 +407,6 @@ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
if (holder instanceof OCFileListFooterViewHolder footerViewHolder) {
footerViewHolder.getFooterText().setText(getFooterText());
viewThemeUtils.platform.colorCircularProgressBar(footerViewHolder.getLoadingProgressBar(), ColorRole.ON_SURFACE_VARIANT);
footerViewHolder.getLoadingProgressBar().setVisibility(
ocFileListFragmentInterface.isLoading() ? View.VISIBLE : View.GONE);
} else if (holder instanceof OCFileListHeaderViewHolder headerViewHolder) {
Expand Down Expand Up @@ -509,15 +500,10 @@ private void updateLivePhotoIndicators(ListViewHolder holder, OCFile file) {
private void bindListGridItemViewHolder(ListGridItemViewHolder holder, OCFile file) {
holder.getFileName().setText(file.getDecryptedFileName());

boolean gridImage = MimeTypeUtil.isImage(file) || MimeTypeUtil.isVideo(file);
if (gridView && gridImage) {
if (gridView && ocFileListFragmentInterface.getColumnsCount() > showFilenameColumnThreshold) {
holder.getFileName().setVisibility(View.GONE);
} else {
if (gridView && ocFileListFragmentInterface.getColumnsCount() > showFilenameColumnThreshold) {
holder.getFileName().setVisibility(View.GONE);
} else {
holder.getFileName().setVisibility(View.VISIBLE);
}
holder.getFileName().setVisibility(View.VISIBLE);
}

ViewExtensionsKt.setVisibleIf(holder.getShared(), !file.isOfflineOperation());
Expand Down Expand Up @@ -722,7 +708,7 @@ public boolean shouldShowHeader() {
return false;
}

if (MainApp.isOnlyOnDevice()) {
if (MainApp.isOnlyOnDevice() || ocFileListFragmentInterface.isSearchFragment()) {
return false;
}

Expand Down Expand Up @@ -1121,6 +1107,7 @@ public void cancelAllPendingTasks() {

public void setGridView(boolean bool) {
gridView = bool;
ocFileListDelegate.setGridView(bool);
}

public void setShowMetadata(boolean bool) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ class OCFileListDelegate(
private val storageManager: FileDataStorageManager,
private val hideItemOptions: Boolean,
private val preferences: AppPreferences,
private val gridView: Boolean,
private var gridView: Boolean,
private val transferServiceGetter: ComponentsGetter,
private val showMetadata: Boolean,
private var showShareAvatar: Boolean,
private var viewThemeUtils: ViewThemeUtils,
private val isMediaGallery: Boolean,
private val syncFolderProvider: SyncedFolderProvider? = null
) {
private val checkedFiles: MutableSet<OCFile> = HashSet()
Expand Down Expand Up @@ -214,7 +215,8 @@ class OCFileListDelegate(
gridViewHolder.shimmerThumbnail,
preferences,
viewThemeUtils,
syncFolderProvider
syncFolderProvider,
isMediaGallery
)

// item layout + click listeners
Expand All @@ -238,7 +240,8 @@ class OCFileListDelegate(

// shares
val shouldHideShare = (
hideItemOptions ||
gridView || // NMC: don't show share icon in grid mode
hideItemOptions ||
!file.isFolder &&
file.isEncrypted ||
file.isEncrypted &&
Expand Down Expand Up @@ -315,9 +318,8 @@ class OCFileListDelegate(

private fun setCheckBoxImage(file: OCFile, gridViewHolder: ListViewHolder) {
if (isCheckedFile(file)) {
gridViewHolder.checkbox.setImageDrawable(
viewThemeUtils.platform.tintDrawable(context, R.drawable.ic_checkbox_marked, ColorRole.PRIMARY)
)
// NMC Customization
gridViewHolder.checkbox.setImageResource(R.drawable.ic_checkbox_marked)
} else {
gridViewHolder.checkbox.setImageResource(R.drawable.ic_checkbox_blank_outline)
}
Expand Down Expand Up @@ -405,6 +407,10 @@ class OCFileListDelegate(
showShareAvatar = bool
}

fun setGridView(bool: Boolean){
gridView = bool
}

companion object {
private val TAG = OCFileListDelegate::class.java.simpleName
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ internal class OCFileListGridItemViewHolder(var binding: GridItemBinding) :
get() = null
override val livePhotoIndicatorSeparator: TextView?
get() = null
override val fileFeaturesLayout: LinearLayout
get() = binding.fileFeaturesLayout
override val fileFeaturesLayout: LinearLayout?
get() = null
override val more: ImageButton
get() = binding.more

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ public void onBindHeaderViewHolder(SectionedViewHolder holder, int section, bool
headerViewHolder.binding.uploadListTitle.setText(
String.format(parentActivity.getString(R.string.uploads_view_group_header),
group.getGroupName(), group.getGroupItemCount()));
viewThemeUtils.platform.colorPrimaryTextViewElement(headerViewHolder.binding.uploadListTitle);
//NMC Customization
headerViewHolder.binding.uploadListTitle.setTextColor(parentActivity.getResources().getColor(R.color.primary, null));

headerViewHolder.binding.uploadListTitle.setOnClickListener(v -> {
toggleSectionExpanded(section);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ class ConflictsResolveDialog : DialogFragment(), Injectable {
null,
syncedFolderProvider.preferences,
viewThemeUtils,
syncedFolderProvider
syncedFolderProvider,
false
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ public interface OCFileListFragmentInterface {
boolean isLoading();

void onHeaderClicked();

boolean isSearchFragment();
}
Loading

0 comments on commit c9bb244

Please sign in to comment.