Skip to content

Commit

Permalink
Customized dialog theme.
Browse files Browse the repository at this point in the history
  • Loading branch information
surinder-tsys committed Jan 11, 2024
1 parent e625f45 commit 3cf9d90
Show file tree
Hide file tree
Showing 35 changed files with 342 additions and 333 deletions.
30 changes: 30 additions & 0 deletions app/src/main/java/com/nmc/android/utils/DialogThemeUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.nmc.android.utils

import android.content.Context
import android.content.res.ColorStateList
import android.os.Build
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.shape.MaterialShapeDrawable
import com.owncloud.android.R

object DialogThemeUtils {
fun colorMaterialAlertDialogBackground(context: Context, dialogBuilder: MaterialAlertDialogBuilder) {
val materialShapeDrawable = MaterialShapeDrawable(
context,
null,
R.attr.alertDialogStyle,
R.style.MaterialAlertDialog_MaterialComponents
)
materialShapeDrawable.initializeElevationOverlay(context)
materialShapeDrawable.fillColor =
ColorStateList.valueOf(context.resources.getColor(R.color.alert_bg_color, null))

// dialogCornerRadius first appeared in Android Pie
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
val radius: Float =
context.resources.getDimension(com.nextcloud.android.common.ui.R.dimen.dialogBorderRadius)
materialShapeDrawable.setCornerSize(radius)
}
dialogBuilder.background = materialShapeDrawable
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -827,11 +827,8 @@ class SyncedFoldersActivity :
.setNeutralButton(getString(R.string.battery_optimization_close)) { dialog, _ -> dialog.dismiss() }
.setIcon(R.drawable.ic_battery_alert)
if (lifecycle.currentState.isAtLeast(Lifecycle.State.RESUMED)) {
val alertDialog = alertDialogBuilder.show()
viewThemeUtils.platform.colorTextButtons(
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE),
alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL)
)
//NMC Customization
alertDialogBuilder.show()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class StoragePathAdapter(
val storagePathItem = pathList[position]
holder.binding.btnStoragePath.setIconResource(storagePathItem.icon)
holder.binding.btnStoragePath.text = storagePathItem.name
viewThemeUtils.material.colorMaterialButtonPrimaryBorderless(holder.binding.btnStoragePath)
}
}

Expand Down
141 changes: 16 additions & 125 deletions app/src/main/java/com/owncloud/android/ui/dialog/AccountRemovalDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,21 @@
package com.owncloud.android.ui.dialog

import android.app.Dialog
import android.graphics.drawable.Drawable
import android.content.DialogInterface
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.DialogFragment
import com.google.android.material.button.MaterialButton
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.nextcloud.client.account.User
import com.nextcloud.client.account.UserAccountManager
import com.nextcloud.client.di.Injectable
import com.nextcloud.client.jobs.BackgroundJobManager
import com.nextcloud.utils.extensions.getParcelableArgument
import com.nmc.android.utils.DialogThemeUtils
import com.owncloud.android.R
import com.owncloud.android.databinding.AccountRemovalDialogBinding
import com.owncloud.android.datamodel.FileDataStorageManager
import com.owncloud.android.utils.DisplayUtils
import com.owncloud.android.utils.DisplayUtils.AvatarGenerationListener
import com.owncloud.android.utils.theme.ViewThemeUtils
import javax.inject.Inject

class AccountRemovalDialog : DialogFragment(), AvatarGenerationListener, Injectable {
// NMC Customization: We don't need two option for logout. On logout directly logout the user locally from the app
class AccountRemovalDialog : DialogFragment(), Injectable {

@Inject
lateinit var backgroundJobManager: BackgroundJobManager
Expand All @@ -53,136 +47,33 @@ class AccountRemovalDialog : DialogFragment(), AvatarGenerationListener, Injecta
lateinit var viewThemeUtils: ViewThemeUtils

private var user: User? = null
private lateinit var alertDialog: AlertDialog
private var _binding: AccountRemovalDialogBinding? = null
private val binding get() = _binding!!

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
user = requireArguments().getParcelableArgument(KEY_USER, User::class.java)
}

override fun onStart() {
super.onStart()

// disable positive button and apply theming
alertDialog = dialog as AlertDialog
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).isEnabled = false

viewThemeUtils.platform.themeRadioButton(binding.radioLocalRemove)
viewThemeUtils.platform.themeRadioButton(binding.radioRequestDeletion)
viewThemeUtils.material.colorMaterialButtonPrimaryTonal(
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE) as MaterialButton
)
viewThemeUtils.material.colorMaterialButtonPrimaryBorderless(
alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE) as MaterialButton
)

binding.userName.text = UserAccountManager.getDisplayName(user)
binding.account.text = user?.let { DisplayUtils.convertIdn(it.accountName, false) }
}

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
_binding = AccountRemovalDialogBinding.inflate(layoutInflater)

// start avatar generation
setAvatar()

// hide second option when plug-in isn't installed
if (hasDropAccount()) {
binding.requestDeletion.visibility = View.VISIBLE
}

val builder =
MaterialAlertDialogBuilder(requireActivity())
.setTitle(R.string.delete_account)
.setView(binding.root)
.setNegativeButton(R.string.common_cancel) { _, _ -> }
.setPositiveButton(R.string.delete_account) { _, _ -> removeAccount() }

// allow selection by clicking on list element
binding.localRemove.setOnClickListener {
binding.radioLocalRemove.performClick()
}
binding.requestDeletion.setOnClickListener {
binding.radioRequestDeletion.performClick()
}

// set listeners for custom radio button list
binding.radioLocalRemove.setOnClickListener {
binding.radioRequestDeletion.isChecked = false
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).apply {
text = getText(R.string.delete_account)
isEnabled = true
}
}
binding.radioRequestDeletion.setOnClickListener {
binding.radioLocalRemove.isChecked = false
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).apply {
text = getString(R.string.request_account_deletion_button)
isEnabled = true
val builder = MaterialAlertDialogBuilder(requireActivity())
.setTitle(R.string.delete_account)
.setMessage(resources.getString(R.string.delete_account_warning, user!!.accountName))
.setIcon(R.drawable.ic_warning)
.setPositiveButton(R.string.common_ok) { _: DialogInterface?, _: Int ->
backgroundJobManager.startAccountRemovalJob(
user!!.accountName,
false
)
}
}
.setNegativeButton(R.string.common_cancel, null)

viewThemeUtils.dialog.colorMaterialAlertDialogBackground(requireActivity(), builder)
// NMC customization
DialogThemeUtils.colorMaterialAlertDialogBackground(requireActivity(), builder)

return builder.create()
}

/**
* Get value of `drop-account` capability.
*/
private fun hasDropAccount(): Boolean {
val capability = FileDataStorageManager(user, context?.contentResolver).getCapability(user)
return capability.dropAccount.isTrue
}

/**
* Start removal of account. Depending on which option is checked, either a browser will open to request deletion,
* or the local account will be removed immediately.
*/
private fun removeAccount() {
user?.let { user ->
if (binding.radioRequestDeletion.isChecked) {
DisplayUtils.startLinkIntent(activity, user.server.uri.toString() + DROP_ACCOUNT_URI)
} else {
backgroundJobManager.startAccountRemovalJob(user.accountName, false)
}
}
}

/**
* Start avatar generation.
*/
private fun setAvatar() {
try {
val imageView = binding.userIcon
imageView.tag = user!!.accountName
DisplayUtils.setAvatar(
user!!,
this,
resources.getDimension(R.dimen.list_item_avatar_icon_radius),
resources,
imageView,
context
)
} catch (_: Exception) {
}
}

override fun avatarGenerated(avatarDrawable: Drawable?, callContext: Any?) {
avatarDrawable?.let {
binding.userIcon.setImageDrawable(it)
}
}

override fun shouldCallGeneratedCallback(tag: String?, callContext: Any?): Boolean {
return binding.userIcon.tag == tag
}

companion object {
private const val KEY_USER = "USER"
private const val DROP_ACCOUNT_URI = "/settings/user/drop_account"

@JvmStatic
fun newInstance(user: User) = AccountRemovalDialog().apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import com.nextcloud.client.di.Injectable;
import com.nextcloud.client.network.ClientFactory;
import com.nextcloud.utils.extensions.BundleExtensionsKt;
import com.nmc.android.utils.DialogThemeUtils;
import com.owncloud.android.MainApp;
import com.owncloud.android.R;
import com.owncloud.android.databinding.ChooseTemplateBinding;
Expand Down Expand Up @@ -129,17 +130,9 @@ public void onStart() {

if (alertDialog != null) {
positiveButton = (MaterialButton) alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
viewThemeUtils.material.colorMaterialButtonPrimaryTonal(positiveButton);

MaterialButton negativeButton = (MaterialButton) alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE);
if (negativeButton != null) {
viewThemeUtils.material.colorMaterialButtonPrimaryBorderless(negativeButton);
}

positiveButton.setOnClickListener(this);
positiveButton.setEnabled(false);
}

checkEnablingCreateButton();
}

Expand Down Expand Up @@ -181,8 +174,6 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
binding = ChooseTemplateBinding.inflate(inflater, null, false);
View view = binding.getRoot();

viewThemeUtils.material.colorTextInputLayout(binding.filenameContainer);

Type type = Type.valueOf(arguments.getString(ARG_TYPE));
new FetchTemplateTask(this, client).execute(type);

Expand Down Expand Up @@ -222,7 +213,8 @@ public void afterTextChanged(Editable s) {
.setNegativeButton(R.string.common_cancel, null)
.setTitle(titleTextId);

viewThemeUtils.dialog.colorMaterialAlertDialogBackground(activity, builder);
//NMC customization
DialogThemeUtils.INSTANCE.colorMaterialAlertDialogBackground(activity, builder);

return builder.create();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import com.nextcloud.client.di.Injectable
import com.nextcloud.client.network.ClientFactory
import com.nextcloud.client.network.ClientFactory.CreationException
import com.nextcloud.utils.extensions.getParcelableArgument
import com.nmc.android.utils.DialogThemeUtils
import com.owncloud.android.MainApp
import com.owncloud.android.R
import com.owncloud.android.databinding.ChooseTemplateBinding
Expand Down Expand Up @@ -106,10 +107,6 @@ class ChooseTemplateDialogFragment : DialogFragment(), View.OnClickListener, Tem
val alertDialog = dialog as AlertDialog

val positiveButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE) as MaterialButton
viewThemeUtils.material.colorMaterialButtonPrimaryTonal(positiveButton)

val negativeButton = alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE) as MaterialButton
viewThemeUtils.material.colorMaterialButtonPrimaryBorderless(negativeButton)

positiveButton.setOnClickListener(this)
positiveButton.isEnabled = false
Expand Down Expand Up @@ -144,10 +141,6 @@ class ChooseTemplateDialogFragment : DialogFragment(), View.OnClickListener, Tem
_binding = ChooseTemplateBinding.inflate(inflater, null, false)
val view: View = binding.root

viewThemeUtils.material.colorTextInputLayout(
binding.filenameContainer
)

binding.filename.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) = Unit

Expand Down Expand Up @@ -181,7 +174,8 @@ class ChooseTemplateDialogFragment : DialogFragment(), View.OnClickListener, Tem
.setNegativeButton(R.string.common_cancel, null)
.setTitle(title)

viewThemeUtils.dialog.colorMaterialAlertDialogBackground(binding.list.context, builder)
//NMC customization
DialogThemeUtils.colorMaterialAlertDialogBackground(binding.list.context, builder)

return builder.create()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ import android.R
import android.app.Dialog
import android.content.DialogInterface
import android.os.Bundle
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.DialogFragment
import com.google.android.material.button.MaterialButton
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.nextcloud.client.di.Injectable
import com.nmc.android.utils.DialogThemeUtils
import com.owncloud.android.utils.theme.ViewThemeUtils
import javax.inject.Inject

Expand All @@ -36,29 +35,6 @@ open class ConfirmationDialogFragment : DialogFragment(), Injectable {

private var mListener: ConfirmationDialogFragmentListener? = null

override fun onStart() {
super.onStart()

val alertDialog = dialog as AlertDialog?

if (alertDialog != null) {
val positiveButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE) as MaterialButton?
if (positiveButton != null) {
viewThemeUtils?.material?.colorMaterialButtonPrimaryTonal(positiveButton)
}

val negativeButton = alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE) as MaterialButton?
if (negativeButton != null) {
viewThemeUtils?.material?.colorMaterialButtonPrimaryBorderless(negativeButton)
}

val neutralButton = alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL) as MaterialButton?
if (neutralButton != null) {
viewThemeUtils?.material?.colorMaterialButtonPrimaryBorderless(neutralButton)
}
}
}

fun setOnConfirmationListener(listener: ConfirmationDialogFragmentListener?) {
mListener = listener
}
Expand Down Expand Up @@ -104,7 +80,8 @@ open class ConfirmationDialogFragment : DialogFragment(), Injectable {
}
}

viewThemeUtils?.dialog?.colorMaterialAlertDialogBackground(requireActivity(), builder)
// NMC customization
DialogThemeUtils.colorMaterialAlertDialogBackground(requireActivity(), builder)

return builder.create()
}
Expand Down
Loading

0 comments on commit 3cf9d90

Please sign in to comment.