diff options
Diffstat (limited to 'app/src/main/java/app/fedilab/android/ui/drawer/NotificationAdapter.java')
-rw-r--r-- | app/src/main/java/app/fedilab/android/ui/drawer/NotificationAdapter.java | 86 |
1 files changed, 84 insertions, 2 deletions
diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/NotificationAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/NotificationAdapter.java index 78ed4255c..12911d4f1 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/NotificationAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/NotificationAdapter.java @@ -21,6 +21,7 @@ import android.app.Activity; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.content.res.Configuration; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -71,6 +72,7 @@ public class NotificationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH private final int TYPE_ADMIN_REPORT = 12; public FetchMoreCallBack fetchMoreCallBack; private Context context; + private RecyclerView mRecyclerView; public NotificationAdapter(List<Notification> notificationList) { this.notificationList = notificationList; @@ -120,6 +122,13 @@ public class NotificationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH return super.getItemViewType(position); } + @Override + public void onAttachedToRecyclerView(RecyclerView recyclerView) { + super.onAttachedToRecyclerView(recyclerView); + + mRecyclerView = recyclerView; + } + @NonNull @Override public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { @@ -136,11 +145,60 @@ public class NotificationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH } } + public static void applyColorAccount(Context context, ViewHolderFollow holder) { + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); + int currentNightMode = context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; + boolean customLight = sharedpreferences.getBoolean(context.getString(R.string.SET_CUSTOMIZE_LIGHT_COLORS), false); + boolean customDark = sharedpreferences.getBoolean(context.getString(R.string.SET_CUSTOMIZE_DARK_COLORS), false); + int theme_icons_color = -1; + int theme_statuses_color = -1; + int theme_text_color = -1; + int theme_text_header_1_line = -1; + int theme_text_header_2_line = -1; + if (currentNightMode == Configuration.UI_MODE_NIGHT_NO) { //LIGHT THEME + if (customLight) { + theme_icons_color = sharedpreferences.getInt(context.getString(R.string.SET_LIGHT_ICON), -1); + theme_statuses_color = sharedpreferences.getInt(context.getString(R.string.SET_LIGHT_BACKGROUND), -1); + theme_text_color = sharedpreferences.getInt(context.getString(R.string.SET_LIGHT_TEXT), -1); + theme_text_header_1_line = sharedpreferences.getInt(context.getString(R.string.SET_LIGHT_DISPLAY_NAME), -1); + theme_text_header_2_line = sharedpreferences.getInt(context.getString(R.string.SET_LIGHT_USERNAME), -1); + } + } else { + if (customDark) { + theme_icons_color = sharedpreferences.getInt(context.getString(R.string.SET_DARK_ICON), -1); + theme_statuses_color = sharedpreferences.getInt(context.getString(R.string.SET_DARK_BACKGROUND), -1); + theme_text_color = sharedpreferences.getInt(context.getString(R.string.SET_DARK_TEXT), -1); + theme_text_header_1_line = sharedpreferences.getInt(context.getString(R.string.SET_DARK_DISPLAY_NAME), -1); + theme_text_header_2_line = sharedpreferences.getInt(context.getString(R.string.SET_DARK_USERNAME), -1); + } + } + if (theme_text_color != -1) { + holder.binding.title.setTextColor(theme_text_color); + } + if (theme_icons_color != -1) { + Helper.changeDrawableColor(context, holder.binding.icon, theme_icons_color); + } + if (theme_statuses_color != -1) { + holder.binding.cardviewContainer.setBackgroundColor(theme_statuses_color); + } + if (theme_text_header_1_line != -1) { + holder.binding.displayName.setTextColor(theme_text_header_1_line); + } + if (theme_text_header_2_line != -1) { + holder.binding.username.setTextColor(theme_text_header_2_line); + } + } + @Override public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) { Notification notification = notificationList.get(position); if (getItemViewType(position) == TYPE_FOLLOW || getItemViewType(position) == TYPE_FOLLOW_REQUEST || getItemViewType(position) == TYPE_ADMIN_REPORT || getItemViewType(position) == TYPE_ADMIN_SIGNUP) { ViewHolderFollow holderFollow = (ViewHolderFollow) viewHolder; + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); + if (sharedpreferences.getBoolean(context.getString(R.string.SET_CARDVIEW), false)) { + holderFollow.binding.cardviewContainer.setCardElevation(Helper.convertDpToPixel(5, context)); + holderFollow.binding.dividerCard.setVisibility(View.GONE); + } MastodonHelper.loadPPMastodon(holderFollow.binding.avatar, notification.account); holderFollow.binding.displayName.setText( notification.account.getSpanDisplayName(context, @@ -217,8 +275,10 @@ public class NotificationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH } else { holderFollow.binding.layoutFetchMore.fetchMoreContainer.setVisibility(View.GONE); } + applyColorAccount(context, holderFollow); } else if (getItemViewType(position) == TYPE_FILERED) { StatusAdapter.StatusViewHolder holder = (StatusAdapter.StatusViewHolder) viewHolder; + holder.bindingFiltered.filteredText.setText(context.getString(R.string.filtered_by, notification.filteredByApp.title)); holder.bindingFiltered.displayButton.setOnClickListener(v -> { notification.filteredByApp = null; @@ -226,6 +286,11 @@ public class NotificationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH }); } else { StatusAdapter.StatusViewHolder holderStatus = (StatusAdapter.StatusViewHolder) viewHolder; + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); + if (sharedpreferences.getBoolean(context.getString(R.string.SET_CARDVIEW), false)) { + holderStatus.binding.cardviewContainer.setCardElevation(Helper.convertDpToPixel(5, context)); + holderStatus.binding.dividerCard.setVisibility(View.GONE); + } holderStatus.bindingNotification.status.typeOfNotification.setVisibility(View.VISIBLE); if (getItemViewType(position) == TYPE_MENTION) { @@ -243,13 +308,30 @@ public class NotificationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH } else if (getItemViewType(position) == TYPE_POLL) { holderStatus.bindingNotification.status.typeOfNotification.setImageResource(R.drawable.ic_baseline_poll_24); } + int theme_icons_color = -1; + int currentNightMode = context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; + boolean customLight = sharedpreferences.getBoolean(context.getString(R.string.SET_CUSTOMIZE_LIGHT_COLORS), false); + boolean customDark = sharedpreferences.getBoolean(context.getString(R.string.SET_CUSTOMIZE_DARK_COLORS), false); + if (currentNightMode == Configuration.UI_MODE_NIGHT_NO) { //LIGHT THEME + if (customLight) { + theme_icons_color = sharedpreferences.getInt(context.getString(R.string.SET_LIGHT_ICON), -1); + } + } else { + if (customDark) { + theme_icons_color = sharedpreferences.getInt(context.getString(R.string.SET_DARK_ICON), -1); + } + } + if (theme_icons_color != -1) { + Helper.changeDrawableColor(context, holderStatus.bindingNotification.status.typeOfNotification, theme_icons_color); + } + holderStatus.bindingNotification.status.mainContainer.setAlpha(1.0f); StatusesVM statusesVM = new ViewModelProvider((ViewModelStoreOwner) context).get(StatusesVM.class); SearchVM searchVM = new ViewModelProvider((ViewModelStoreOwner) context).get(SearchVM.class); if (notification.status != null) { notification.status.cached = notification.cached; } - statusManagement(context, statusesVM, searchVM, holderStatus, this, null, notification.status, Timeline.TimeLineEnum.NOTIFICATION, false, true, false, null); + statusManagement(context, statusesVM, searchVM, holderStatus, mRecyclerView, this, null, notification.status, Timeline.TimeLineEnum.NOTIFICATION, false, true, false, null); holderStatus.bindingNotification.status.dateShort.setText(Helper.dateDiff(context, notification.created_at)); if (getItemViewType(position) == TYPE_MENTION || getItemViewType(position) == TYPE_STATUS || getItemViewType(position) == TYPE_REACTION) { @@ -286,7 +368,6 @@ public class NotificationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH } else { holderStatus.bindingNotification.status.mainContainer.setAlpha(.7f); holderStatus.bindingNotification.status.mainContainer.setVisibility(View.VISIBLE); - SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); boolean displayMedia = sharedpreferences.getBoolean(context.getString(R.string.SET_DISPLAY_MEDIA_NOTIFICATION), true); if (displayMedia && notification.status != null && notification.status.media_attachments != null && notification.status.media_attachments.size() > 0) { holderStatus.bindingNotification.status.mediaContainer.setVisibility(View.VISIBLE); @@ -362,6 +443,7 @@ public class NotificationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH holderStatus.bindingNotification.status.username.setText(String.format("@%s", notification.account.acct)); holderStatus.bindingNotification.status.actionButtons.setVisibility(View.GONE); } + StatusAdapter.applyColor(context, holderStatus); } } |