From 0ef56fb86d437a16ea9ed85317b4f1dffd937c29 Mon Sep 17 00:00:00 2001 From: agrajaghh Date: Thu, 5 Nov 2015 17:47:29 +0100 Subject: [PATCH] add custom color to MessageDetailsActivity Fixes #3560 Closes #3580 // FREEBIE --- .../securesms/ConversationFragment.java | 17 +++++++ .../securesms/ConversationItem.java | 1 + .../securesms/MessageDetailsActivity.java | 47 +++++++++++++++---- 3 files changed, 57 insertions(+), 8 deletions(-) diff --git a/src/org/thoughtcrime/securesms/ConversationFragment.java b/src/org/thoughtcrime/securesms/ConversationFragment.java index d91bc4bf04..142aac2cea 100644 --- a/src/org/thoughtcrime/securesms/ConversationFragment.java +++ b/src/org/thoughtcrime/securesms/ConversationFragment.java @@ -1,3 +1,19 @@ +/** + * Copyright (C) 2015 Open Whisper Systems + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package org.thoughtcrime.securesms; import android.app.Activity; @@ -283,6 +299,7 @@ public class ConversationFragment extends Fragment intent.putExtra(MessageDetailsActivity.MASTER_SECRET_EXTRA, masterSecret); intent.putExtra(MessageDetailsActivity.MESSAGE_ID_EXTRA, message.getId()); intent.putExtra(MessageDetailsActivity.TYPE_EXTRA, message.isMms() ? MmsSmsDatabase.MMS_TRANSPORT : MmsSmsDatabase.SMS_TRANSPORT); + intent.putExtra(MessageDetailsActivity.RECIPIENTS_IDS_EXTRA, recipients.getIds()); startActivity(intent); } diff --git a/src/org/thoughtcrime/securesms/ConversationItem.java b/src/org/thoughtcrime/securesms/ConversationItem.java index eb7f32ef43..ccad1f3d70 100644 --- a/src/org/thoughtcrime/securesms/ConversationItem.java +++ b/src/org/thoughtcrime/securesms/ConversationItem.java @@ -543,6 +543,7 @@ public class ConversationItem extends LinearLayout intent.putExtra(MessageDetailsActivity.MESSAGE_ID_EXTRA, messageRecord.getId()); intent.putExtra(MessageDetailsActivity.TYPE_EXTRA, messageRecord.isMms() ? MmsSmsDatabase.MMS_TRANSPORT : MmsSmsDatabase.SMS_TRANSPORT); intent.putExtra(MessageDetailsActivity.IS_PUSH_GROUP_EXTRA, groupThread && messageRecord.isPush()); + intent.putExtra(MessageDetailsActivity.RECIPIENTS_IDS_EXTRA, conversationRecipients.getIds()); context.startActivity(intent); } else if (!messageRecord.isOutgoing() && messageRecord.isIdentityMismatchFailure()) { handleApproveIdentity(); diff --git a/src/org/thoughtcrime/securesms/MessageDetailsActivity.java b/src/org/thoughtcrime/securesms/MessageDetailsActivity.java index 45ffce71fd..9c483b31da 100644 --- a/src/org/thoughtcrime/securesms/MessageDetailsActivity.java +++ b/src/org/thoughtcrime/securesms/MessageDetailsActivity.java @@ -18,7 +18,9 @@ package org.thoughtcrime.securesms; import android.content.Context; import android.database.Cursor; +import android.graphics.drawable.ColorDrawable; import android.os.AsyncTask; +import android.os.Build; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.v4.app.LoaderManager.LoaderCallbacks; @@ -31,6 +33,7 @@ import android.view.ViewGroup; import android.widget.ListView; import android.widget.TextView; +import org.thoughtcrime.securesms.color.MaterialColor; import org.thoughtcrime.securesms.crypto.MasterSecret; import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.database.EncryptingSmsDatabase; @@ -46,6 +49,7 @@ import org.thoughtcrime.securesms.util.DateUtils; import org.thoughtcrime.securesms.util.DynamicLanguage; import org.thoughtcrime.securesms.util.DynamicTheme; import org.thoughtcrime.securesms.util.GroupUtil; +import org.thoughtcrime.securesms.util.Util; import java.io.IOException; import java.lang.ref.WeakReference; @@ -58,13 +62,14 @@ import java.util.Locale; /** * @author Jake McGinty */ -public class MessageDetailsActivity extends PassphraseRequiredActionBarActivity implements LoaderCallbacks { +public class MessageDetailsActivity extends PassphraseRequiredActionBarActivity implements LoaderCallbacks, Recipients.RecipientsModifiedListener { private final static String TAG = MessageDetailsActivity.class.getSimpleName(); - public final static String MASTER_SECRET_EXTRA = "master_secret"; - public final static String MESSAGE_ID_EXTRA = "message_id"; - public final static String IS_PUSH_GROUP_EXTRA = "is_push_group"; - public final static String TYPE_EXTRA = "type"; + public final static String MASTER_SECRET_EXTRA = "master_secret"; + public final static String MESSAGE_ID_EXTRA = "message_id"; + public final static String IS_PUSH_GROUP_EXTRA = "is_push_group"; + public final static String TYPE_EXTRA = "type"; + public final static String RECIPIENTS_IDS_EXTRA = "recipients_ids"; private MasterSecret masterSecret; private boolean isPushGroup; @@ -94,8 +99,7 @@ public class MessageDetailsActivity extends PassphraseRequiredActionBarActivity setContentView(R.layout.message_details_activity); initializeResources(); - - getSupportActionBar().setDisplayHomeAsUpEnabled(true); + initializeActionBar(); getSupportLoaderManager().initLoader(0, null, this); } @@ -107,6 +111,33 @@ public class MessageDetailsActivity extends PassphraseRequiredActionBarActivity getSupportActionBar().setTitle(R.string.AndroidManifest__message_details); } + private void initializeActionBar() { + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + + Recipients recipients = RecipientFactory.getRecipientsForIds(this, getIntent().getLongArrayExtra(RECIPIENTS_IDS_EXTRA), true); + recipients.addListener(this); + + setActionBarColor(recipients.getColor()); + } + + private void setActionBarColor(MaterialColor color) { + getSupportActionBar().setBackgroundDrawable(new ColorDrawable(color.toActionBarColor(this))); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + getWindow().setStatusBarColor(color.toStatusBarColor(this)); + } + } + + @Override + public void onModified(final Recipients recipients) { + Util.runOnMain(new Runnable() { + @Override + public void run() { + setActionBarColor(recipients.getColor()); + } + }); + } + private void initializeResources() { inflater = LayoutInflater.from(this); View header = inflater.inflate(R.layout.message_details_header, recipientsList, false); @@ -274,7 +305,7 @@ public class MessageDetailsActivity extends PassphraseRequiredActionBarActivity .getGroupMembers(GroupUtil.getDecodedId(groupId), false); } catch (IOException e) { Log.w(TAG, e); - recipients = RecipientFactory.getRecipientsFor(MessageDetailsActivity.this, new LinkedList(), false); + recipients = RecipientFactory.getRecipientsFor(MessageDetailsActivity.this, new LinkedList(), false); } }