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 May 13, 2023
1 parent ceb6cd6 commit 0088480
Show file tree
Hide file tree
Showing 27 changed files with 140 additions and 145 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 @@ -29,14 +29,14 @@
import com.nextcloud.client.account.User;
import com.nextcloud.client.di.Injectable;
import com.nextcloud.client.jobs.BackgroundJobManager;
import com.nmc.android.utils.DialogThemeUtils;
import com.owncloud.android.R;
import com.owncloud.android.utils.theme.ViewThemeUtils;

import javax.inject.Inject;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment;

public class AccountRemovalConfirmationDialog extends DialogFragment implements Injectable {
Expand All @@ -62,16 +62,6 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
user = getArguments().getParcelable(KEY_USER);
}

@Override
public void onStart() {
super.onStart();

AlertDialog alertDialog = (AlertDialog) getDialog();

viewThemeUtils.platform.colorTextButtons(alertDialog.getButton(AlertDialog.BUTTON_POSITIVE),
alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL));
}

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Expand All @@ -84,7 +74,8 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
false))
.setNeutralButton(R.string.common_cancel, null);

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

return builder.create();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import com.nextcloud.client.account.User;
import com.nextcloud.client.di.Injectable;
import com.nextcloud.client.network.ClientFactory;
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 @@ -125,8 +126,6 @@ public void onStart() {
AlertDialog alertDialog = (AlertDialog) getDialog();

positiveButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
viewThemeUtils.platform.colorTextButtons(positiveButton,
alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL));
positiveButton.setOnClickListener(this);
positiveButton.setEnabled(false);

Expand Down Expand Up @@ -171,8 +170,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 @@ -210,7 +207,8 @@ public void afterTextChanged(Editable s) {
.setNeutralButton(R.string.common_cancel, null)
.setTitle(getTitle(type));

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 @@ -44,6 +44,7 @@ import com.nextcloud.client.account.User
import com.nextcloud.client.di.Injectable
import com.nextcloud.client.network.ClientFactory
import com.nextcloud.client.network.ClientFactory.CreationException
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 @@ -105,10 +106,6 @@ class ChooseTemplateDialogFragment : DialogFragment(), View.OnClickListener, Tem
val alertDialog = dialog as AlertDialog
val button = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE)

viewThemeUtils.platform.colorTextButtons(
button,
alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL)
)
button.setOnClickListener(this)
button.isEnabled = false
button.isClickable = false
Expand Down Expand Up @@ -141,10 +138,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 @@ -178,7 +171,8 @@ class ChooseTemplateDialogFragment : DialogFragment(), View.OnClickListener, Tem
.setNeutralButton(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 @@ -22,13 +22,13 @@

import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.nextcloud.client.di.Injectable;
import com.nmc.android.utils.DialogThemeUtils;
import com.owncloud.android.R;
import com.owncloud.android.utils.theme.ViewThemeUtils;

import javax.inject.Inject;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment;


Expand Down Expand Up @@ -78,19 +78,6 @@ public static ConfirmationDialogFragment newInstance(int messageResId, String[]
return frag;
}

@Override
public void onStart() {
super.onStart();

AlertDialog alertDialog = (AlertDialog) getDialog();

if(alertDialog != null) {
viewThemeUtils.platform.colorTextButtons(alertDialog.getButton(AlertDialog.BUTTON_POSITIVE),
alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE),
alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL));
}
}

public void setOnConfirmationListener(ConfirmationDialogFragmentListener listener) {
mListener = listener;
}
Expand Down Expand Up @@ -157,7 +144,8 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
});
}

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 @@ -34,6 +34,7 @@
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.common.collect.Sets;
import com.nextcloud.client.di.Injectable;
import com.nmc.android.utils.DialogThemeUtils;
import com.owncloud.android.R;
import com.owncloud.android.databinding.EditBoxDialogBinding;
import com.owncloud.android.datamodel.FileDataStorageManager;
Expand Down Expand Up @@ -100,9 +101,6 @@ public void onStart() {

if (alertDialog != null) {
positiveButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);

viewThemeUtils.platform.colorTextButtons(positiveButton,
alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL));
}
}

Expand All @@ -124,7 +122,6 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {

// Setup layout
binding.userInput.setText("");
viewThemeUtils.material.colorTextInputLayout(binding.userInputContainer);

OCFile parentFolder = requireArguments().getParcelable(ARG_PARENT_FOLDER);
List<OCFile> folderContent = fileDataStorageManager.getFolderContent(parentFolder, false);
Expand Down Expand Up @@ -182,7 +179,8 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
.setNeutralButton(R.string.common_cancel, this)
.setTitle(R.string.uploader_info_dirname);

viewThemeUtils.dialog.colorMaterialAlertDialogBackground(binding.userInputContainer.getContext(), builder);
//NMC customization
DialogThemeUtils.INSTANCE.colorMaterialAlertDialogBackground(binding.userInputContainer.getContext(), builder);

return builder.create();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package com.owncloud.android.ui.dialog;

import android.app.Dialog;
import android.graphics.PorterDuff;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
Expand Down Expand Up @@ -65,7 +66,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa

// set progress wheel color
ProgressBar progressBar = v.findViewById(R.id.loadingBar);
viewThemeUtils.platform.tintDrawable(requireContext(), progressBar.getIndeterminateDrawable());
//NMC Customisation
progressBar.getIndeterminateDrawable().setColorFilter(getResources().getColor(R.color.primary, null), PorterDuff.Mode.SRC_IN);

return v;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.nextcloud.client.di.Injectable;
import com.nmc.android.utils.DialogThemeUtils;
import com.owncloud.android.R;
import com.owncloud.android.databinding.StoragePathDialogBinding;
import com.owncloud.android.ui.adapter.StoragePathAdapter;
Expand Down Expand Up @@ -74,17 +75,6 @@ public static LocalStoragePathPickerDialogFragment newInstance() {
return new LocalStoragePathPickerDialogFragment();
}

@Override
public void onStart() {
super.onStart();

AlertDialog alertDialog = (AlertDialog) getDialog();

if (alertDialog != null) {
viewThemeUtils.platform.colorTextButtons(alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE));
}
}

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -111,10 +101,12 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
// Build the dialog
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(binding.getRoot().getContext());
builder.setView(view)
.setNegativeButton(R.string.common_cancel, this)
//NMC customisation to show primary color
.setPositiveButton(R.string.common_cancel, this)
.setTitle(R.string.storage_choose_location);

viewThemeUtils.dialog.colorMaterialAlertDialogBackground(binding.getRoot().getContext(), builder);
//NMC customization
DialogThemeUtils.INSTANCE.colorMaterialAlertDialogBackground(binding.getRoot().getContext(), builder);

return builder.create();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import java.util.Collection;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;

/**
* Dialog requiring confirmation before removing a collection of given OCFiles.
Expand Down Expand Up @@ -124,19 +123,6 @@ public static RemoveFilesDialogFragment newInstance(OCFile file) {
return newInstance(list);
}

@Override
public void onStart() {
super.onStart();

AlertDialog alertDialog = (AlertDialog) getDialog();

if (alertDialog != null) {
viewThemeUtils.platform.colorTextButtons(alertDialog.getButton(AlertDialog.BUTTON_POSITIVE),
alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE),
alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL));
}
}

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.common.collect.Sets;
import com.nextcloud.client.di.Injectable;
import com.nmc.android.utils.DialogThemeUtils;
import com.owncloud.android.R;
import com.owncloud.android.databinding.EditBoxDialogBinding;
import com.owncloud.android.datamodel.FileDataStorageManager;
Expand Down Expand Up @@ -102,8 +103,6 @@ public void onStart() {

if (alertDialog != null) {
positiveButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
viewThemeUtils.platform.colorTextButtons(positiveButton,
alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL));
}
}

Expand All @@ -126,7 +125,6 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
// Setup layout
String currentName = mTargetFile.getFileName();
binding.userInput.setText(currentName);
viewThemeUtils.material.colorTextInputLayout(binding.userInputContainer);
int extensionStart = mTargetFile.isFolder() ? -1 : currentName.lastIndexOf('.');
int selectionEnd = extensionStart >= 0 ? extensionStart : currentName.length();
binding.userInput.setSelection(0, selectionEnd);
Expand Down Expand Up @@ -184,7 +182,8 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
.setNeutralButton(R.string.common_cancel, this)
.setTitle(R.string.rename_dialog_title);

viewThemeUtils.dialog.colorMaterialAlertDialogBackground(binding.userInputContainer.getContext(), builder);
//NMC customization
DialogThemeUtils.INSTANCE.colorMaterialAlertDialogBackground(binding.userInputContainer.getContext(), builder);

return builder.create();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.nextcloud.client.di.Injectable;
import com.nmc.android.utils.DialogThemeUtils;
import com.owncloud.android.R;
import com.owncloud.android.databinding.EditBoxDialogBinding;
import com.owncloud.android.lib.resources.shares.OCShare;
Expand Down Expand Up @@ -68,18 +69,6 @@ public static RenamePublicShareDialogFragment newInstance(OCShare share) {
return frag;
}

@Override
public void onStart() {
super.onStart();

AlertDialog alertDialog = (AlertDialog) getDialog();

if (alertDialog != null) {
viewThemeUtils.platform.colorTextButtons(alertDialog.getButton(AlertDialog.BUTTON_POSITIVE),
alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL));
}
}

@Override
public void onResume() {
super.onResume();
Expand All @@ -97,7 +86,6 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
View view = binding.getRoot();

// Setup layout
viewThemeUtils.material.colorTextInputLayout(binding.userInputContainer);
binding.userInput.setText(publicShare.getLabel());

// Build the dialog
Expand All @@ -107,7 +95,8 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
.setNeutralButton(R.string.common_cancel, this)
.setTitle(R.string.public_share_name);

viewThemeUtils.dialog.colorMaterialAlertDialogBackground(binding.userInput.getContext(), builder);
//NMC customization
DialogThemeUtils.INSTANCE.colorMaterialAlertDialogBackground(binding.userInput.getContext(), builder);

return builder.create();
}
Expand Down
Loading

0 comments on commit 0088480

Please sign in to comment.