Skip to content

Bottom sheet theming & Collabora #88

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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,113 @@
package com.nmc.android

import android.os.Looper
import androidx.activity.result.contract.ActivityResultContract
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.intent.rule.IntentsTestRule
import androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withText
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.gson.Gson
import com.nextcloud.client.device.DeviceInfo
import com.nextcloud.client.documentscan.AppScanOptionalFeature
import com.nextcloud.utils.EditorUtils
import com.owncloud.android.AbstractIT
import com.owncloud.android.datamodel.ArbitraryDataProvider
import com.owncloud.android.datamodel.ArbitraryDataProviderImpl
import com.owncloud.android.datamodel.OCFile
import com.owncloud.android.lib.common.Creator
import com.owncloud.android.lib.common.DirectEditing
import com.owncloud.android.lib.resources.status.CapabilityBooleanType
import com.owncloud.android.ui.activity.FileDisplayActivity
import com.owncloud.android.ui.fragment.OCFileListBottomSheetActions
import com.owncloud.android.ui.fragment.OCFileListBottomSheetDialog
import com.owncloud.android.utils.MimeTypeUtil
import com.owncloud.android.utils.theme.CapabilityUtils
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.mockito.Mock
import org.mockito.MockitoAnnotations

class OCFileListBottomSheetDialogIT : AbstractIT() {

@Mock
private lateinit var actions: OCFileListBottomSheetActions

@get:Rule
val activityRule = IntentsTestRule(FileDisplayActivity::class.java, true, true)

@Before
fun setUp() {
MockitoAnnotations.initMocks(this)
}

@Test
fun validateCreateTextDocumentMenuOption() {
if (Looper.myLooper() == null) {
Looper.prepare()
}

val info = DeviceInfo()
val ocFile = OCFile("/test.md")

// add direct editing info
val creatorMap = mutableMapOf<String, Creator>()
creatorMap["1"] = Creator(
"1",
"md",
"markdown file",
".md",
MimeTypeUtil.MIMETYPE_TEXT_MARKDOWN,
false
)

val directEditing = DirectEditing(
creators = creatorMap
)

val json = Gson().toJson(directEditing)
ArbitraryDataProviderImpl(targetContext).storeOrUpdateKeyValue(
user.accountName,
ArbitraryDataProvider.DIRECT_EDITING,
json
)

val capability = activityRule.activity.capabilities
capability.richDocuments = CapabilityBooleanType.TRUE
capability.richDocumentsDirectEditing = CapabilityBooleanType.TRUE
capability.richDocumentsTemplatesAvailable = CapabilityBooleanType.TRUE
capability.accountName = user.accountName
CapabilityUtils.updateCapability(capability)

val appScanOptionalFeature: AppScanOptionalFeature = object : AppScanOptionalFeature() {
override fun getScanContract(): ActivityResultContract<Unit, String?> {
throw UnsupportedOperationException("Document scan is not available")
}
}

val editorUtils = EditorUtils(ArbitraryDataProviderImpl(targetContext))
val sut = OCFileListBottomSheetDialog(
activityRule.activity,
actions,
info,
user,
ocFile,
activityRule.activity.themeUtils,
activityRule.activity.viewThemeUtils,
editorUtils,
appScanOptionalFeature
)

activityRule.activity.runOnUiThread { sut.show() }

waitForIdleSync()

sut.behavior.state = BottomSheetBehavior.STATE_EXPANDED

shortSleep()

onView(withText("Create text document")).check(matches(isCompletelyDisplayed()))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.annotation.IdRes
import androidx.appcompat.content.res.AppCompatResources
import androidx.core.os.bundleOf
import androidx.core.view.isEmpty
import androidx.core.content.res.ResourcesCompat
import androidx.core.view.isVisible
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.setFragmentResult
Expand Down Expand Up @@ -94,8 +94,6 @@ class FileActionsBottomSheet : BottomSheetDialogFragment(), Injectable {
bottomSheetDialog.behavior.state = BottomSheetBehavior.STATE_EXPANDED
bottomSheetDialog.behavior.skipCollapsed = true

viewThemeUtils.platform.colorViewBackground(binding.bottomSheet, ColorRole.SURFACE)

return binding.root
}

Expand Down Expand Up @@ -147,7 +145,11 @@ class FileActionsBottomSheet : BottomSheetDialogFragment(), Injectable {

private fun setMultipleFilesThumbnail() {
context?.let {
val drawable = viewThemeUtils.platform.tintDrawable(it, R.drawable.file_multiple, ColorRole.PRIMARY)
// NMC Customization
val drawable = viewThemeUtils.platform.colorDrawable(
ResourcesCompat.getDrawable(it.resources, R.drawable.file_multiple, null)!!,
it.resources.getColor(R.color.primary, null)
)
binding.thumbnailLayout.thumbnail.setImageDrawable(drawable)
}
}
Expand Down Expand Up @@ -278,12 +280,8 @@ class FileActionsBottomSheet : BottomSheetDialogFragment(), Injectable {
}
text.setText(action.title)
if (action.icon != null) {
val drawable =
viewThemeUtils.platform.tintDrawable(
requireContext(),
AppCompatResources.getDrawable(requireContext(), action.icon)!!
)
icon.setImageDrawable(drawable)
// NMC customization
icon.setImageResource(action.icon)
}
}
return itemBinding.root
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.annotation.IdRes
import androidx.appcompat.content.res.AppCompatResources
import androidx.core.content.res.ResourcesCompat
import androidx.core.os.bundleOf
import androidx.core.view.isEmpty
import androidx.core.view.isVisible
Expand Down Expand Up @@ -134,7 +134,11 @@ class TrashbinFileActionsBottomSheet : BottomSheetDialogFragment(), Injectable {

private fun setMultipleFilesThumbnail() {
context?.let {
val drawable = viewThemeUtils.platform.tintDrawable(it, R.drawable.file_multiple, ColorRole.PRIMARY)
// NMC Customization
val drawable = viewThemeUtils.platform.colorDrawable(
ResourcesCompat.getDrawable(it.resources, R.drawable.file_multiple, null)!!,
it.resources.getColor(R.color.primary, null)
)
binding.thumbnailLayout.thumbnail.setImageDrawable(drawable)
}
}
Expand Down Expand Up @@ -196,12 +200,8 @@ class TrashbinFileActionsBottomSheet : BottomSheetDialogFragment(), Injectable {
}
text.setText(action.title)
if (action.icon != null) {
val drawable =
viewThemeUtils.platform.tintDrawable(
requireContext(),
AppCompatResources.getDrawable(requireContext(), action.icon)!!
)
icon.setImageDrawable(drawable)
// NMC customization
icon.setImageResource(action.icon)
}
}
return itemBinding.root
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/java/com/nextcloud/utils/BuildHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
*/
package com.nextcloud.utils

import com.owncloud.android.BuildConfig

object BuildHelper {
const val GPLAY: String = "gplay"

fun isFlavourGPlay(): Boolean = GPLAY == BuildConfig.FLAVOR
// NMC Customization to have it false always
fun isFlavourGPlay(): Boolean = false
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import android.view.ViewGroup
import android.widget.Toast
import androidx.recyclerview.widget.GridLayoutManager
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.nextcloud.android.common.ui.theme.utils.ColorRole
import com.nextcloud.client.di.Injectable
import com.nextcloud.client.utils.IntentUtil.createSendIntent
import com.owncloud.android.R
Expand Down Expand Up @@ -56,7 +55,6 @@ class SendFilesDialog : BottomSheetDialogFragment(R.layout.send_files_fragment),
binding = SendFilesFragmentBinding.inflate(inflater, container, false)

setupSendButtonRecyclerView()
viewThemeUtils?.platform?.colorViewBackground(binding.bottomSheet, ColorRole.SURFACE)

return binding.root
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,6 @@ class GalleryFragmentBottomSheetDialog(
}

private fun setupLayout() {
viewThemeUtils.platform.colorViewBackground(binding.bottomSheet, ColorRole.SURFACE)

listOf(
binding.tickMarkShowImages,
binding.tickMarkShowVideos
).forEach {
viewThemeUtils.platform.colorImageView(it, ColorRole.PRIMARY)
}

listOf(
binding.btnSelectMediaFolder,
binding.btnHideVideos,
binding.btnHideImages
).forEach {
viewThemeUtils.material.colorMaterialButtonText(it)
}

when (currentMediaState) {
MediaState.MEDIA_STATE_PHOTOS_ONLY -> {
binding.tickMarkShowImages.visibility = View.VISIBLE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.google.gson.Gson;
import com.nextcloud.android.common.ui.theme.utils.ColorRole;
import com.nextcloud.client.account.User;
import com.nextcloud.client.device.DeviceInfo;
import com.nextcloud.client.di.Injectable;
Expand All @@ -31,6 +30,8 @@
import com.owncloud.android.utils.theme.ThemeUtils;
import com.owncloud.android.utils.theme.ViewThemeUtils;

import androidx.core.content.ContextCompat;

/**
* FAB menu {@link android.app.Dialog} styled as a bottom sheet for main actions.
*/
Expand Down Expand Up @@ -76,12 +77,8 @@ protected void onCreate(Bundle savedInstanceState) {
binding = FileListActionsBottomSheetFragmentBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());

viewThemeUtils.platform.colorImageView(binding.menuIconUploadFiles, ColorRole.PRIMARY);
viewThemeUtils.platform.colorImageView(binding.menuIconUploadFromApp, ColorRole.PRIMARY);
viewThemeUtils.platform.colorImageView(binding.menuIconDirectCameraUpload, ColorRole.PRIMARY);
viewThemeUtils.platform.colorImageView(binding.menuIconScanDocUpload, ColorRole.PRIMARY);
viewThemeUtils.platform.colorImageView(binding.menuIconMkdir, ColorRole.PRIMARY);
viewThemeUtils.platform.colorImageView(binding.menuIconAddFolderInfo, ColorRole.PRIMARY);
// NMC Customization
reorderUploadFromOtherAppsView();

binding.addToCloud.setText(getContext().getResources().getString(R.string.add_to_cloud,
themeUtils.getDefaultDisplayNameForRootFolder(getContext())));
Expand Down Expand Up @@ -111,16 +108,23 @@ protected void onCreate(Bundle savedInstanceState) {

View creatorView = creatorViewBinding.getRoot();

creatorViewBinding.creatorName.setText(
String.format(fileActivity.getString(R.string.editor_placeholder),
fileActivity.getString(R.string.create_new),
creator.getName()));

creatorViewBinding.creatorThumbnail.setImageDrawable(
MimeTypeUtil.getFileTypeIcon(creator.getMimetype(),
creator.getExtension(),
creatorViewBinding.creatorThumbnail.getContext(),
viewThemeUtils));
//for NMC we have different text and icon for Markdown(.md) menu
if (creator.getMimetype().equalsIgnoreCase(MimeTypeUtil.MIMETYPE_TEXT_MARKDOWN)) {
creatorViewBinding.creatorName.setText(fileActivity.getString(R.string.create_text_document));
creatorViewBinding.creatorThumbnail.setImageDrawable(ContextCompat.getDrawable(getContext(),
R.drawable.ic_new_txt_doc));
} else {
creatorViewBinding.creatorName.setText(
String.format(fileActivity.getString(R.string.editor_placeholder),
fileActivity.getString(R.string.create_new),
creator.getName()));

creatorViewBinding.creatorThumbnail.setImageDrawable(
MimeTypeUtil.getFileTypeIcon(creator.getMimetype(),
creator.getExtension(),
creatorViewBinding.creatorThumbnail.getContext(),
viewThemeUtils));
}

creatorView.setOnClickListener(v -> {
actions.showTemplate(creator, creatorViewBinding.creatorName.getText().toString());
Expand All @@ -136,8 +140,9 @@ protected void onCreate(Bundle savedInstanceState) {
binding.menuDirectCameraUpload.setVisibility(View.GONE);
}

// not required for NMC
// create rich workspace
if (editorUtils.isEditorAvailable(user,
/* if (editorUtils.isEditorAvailable(user,
MimeTypeUtil.MIMETYPE_TEXT_MARKDOWN) &&
file != null && !file.isEncrypted()) {
// richWorkspace
Expand All @@ -154,12 +159,20 @@ protected void onCreate(Bundle savedInstanceState) {
} else {
binding.menuCreateRichWorkspace.setVisibility(View.GONE);
binding.menuCreateRichWorkspaceDivider.setVisibility(View.GONE);
}
} */

setupClickListener();
filterActionsForOfflineOperations();
}

private void reorderUploadFromOtherAppsView() {
// move the upload from other app option
// below Create new folder or Create new e2ee folder
// NMC-3095 requirement
binding.actionLinear.removeView(binding.menuUploadFromApp);
binding.actionLinear.addView(binding.menuUploadFromApp, binding.actionLinear.indexOfChild(binding.menuEncryptedMkdir) + 1);
}

private void setupClickListener() {
binding.menuCreateRichWorkspace.setOnClickListener(v -> {
actions.createRichWorkspace();
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/drawable/ic_encrypted_folder.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M4,21.75a3,3 0,0 1,-3 -3L1,2.25L7.5,2.25a3.65,3.65 0,0 1,2.7 1.2l0.45,0.45a1.43,1.43 0,0 0,0.85 0.35L23,4.25v14.5a3,3 0,0 1,-3 3ZM2.5,18.75a1.46,1.46 0,0 0,1.43 1.5L20,20.25a1.47,1.47 0,0 0,1.5 -1.44L21.5,5.75h-10A2.57,2.57 0,0 1,9.6 4.9l-0.45,-0.45a2.38,2.38 0,0 0,-1.65 -0.7h-5Z"
android:fillColor="#262626"/>
<path
android:pathData="M14.14,16.56L9.86,16.56a1.07,1.07 0,0 1,-1.07 -1.08L8.79,12.09h0.89v-0.71a2.32,2.32 0,0 1,4.64 0v0.71h0.89v3.39A1.07,1.07 0,0 1,14.14 16.56ZM12,13.56a0.54,0.54 0,0 0,-0.54 0.53,0.55 0.55,0 0,0 0.18,0.4v0.68h0.72v-0.68a0.53,0.53 0,0 0,0 -0.75A0.52,0.52 0,0 0,12 13.52ZM12,9.63a1.79,1.79 0,0 0,-1.79 1.79v0.71h3.58v-0.71A1.79,1.79 0,0 0,12 9.59Z"
android:fillColor="#262626"/>
</vector>
12 changes: 12 additions & 0 deletions app/src/main/res/drawable/ic_file_collection.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M17.75,0.5L8,0.5L8,3.5L5,3.5L5,6.5L2,6.5L2,21.25C2,22.4925 3.0075,23.5 4.25,23.5L13.25,23.5C14.4925,23.5 15.5,22.4925 15.5,21.25L15.5,20.5L16.25,20.5C17.4925,20.5 18.5,19.4925 18.5,18.25L18.5,17.5L19.25,17.5C20.4925,17.5 21.5,16.4925 21.5,15.25L21.5,4.3635L17.75,0.5ZM14,21.25C14,21.6635 13.6635,22 13.25,22L4.25,22C3.8365,22 3.5,21.6635 3.5,21.25L3.5,8L5,8L5,18.25C5,19.4925 6.0075,20.5 7.25,20.5L14,20.5L14,21.25ZM17,18.25C17,18.6635 16.6635,19 16.25,19L7.25,19C6.8365,19 6.5,18.6635 6.5,18.25L6.5,5L8,5L8,15.25C8,16.4925 9.0075,17.5 10.25,17.5L17,17.5L17,18.25ZM19.25,16L10.25,16C9.8365,16 9.5,15.6635 9.5,15.25L9.5,2L16,2L16,4.1705C16,4.9045 16.595,5.5 17.3295,5.5L20,5.5L20,15.25C20,15.6635 19.6635,16 19.25,16Z"
android:strokeWidth="1"
android:fillColor="#262626"
android:fillType="nonZero"
android:strokeColor="#00000000"/>
</vector>
Loading