Commit 5a4acebb authored by Grigory Fedorov's avatar Grigory Fedorov

ActionBarPainter used in AccountEditor and ChatEditor (preferences)

parent 30a3ab3a
...@@ -100,6 +100,6 @@ public class ContactAdd extends ManagedActivity implements ContactAddFragment.Li ...@@ -100,6 +100,6 @@ public class ContactAdd extends ManagedActivity implements ContactAddFragment.Li
@Override @Override
public void onAccountSelected(String account) { public void onAccountSelected(String account) {
actionBarPainter.update(account); actionBarPainter.updateWithAccountName(account);
} }
} }
...@@ -14,6 +14,7 @@ public class ActionBarPainter { ...@@ -14,6 +14,7 @@ public class ActionBarPainter {
private int[] accountActionBarColors; private int[] accountActionBarColors;
private int[] accountStatusBarColors; private int[] accountStatusBarColors;
private String[] accountColorNames;
private Window window; private Window window;
private int defaultStatusBarColor; private int defaultStatusBarColor;
...@@ -26,6 +27,7 @@ public class ActionBarPainter { ...@@ -26,6 +27,7 @@ public class ActionBarPainter {
accountActionBarColors = activity.getResources().getIntArray(R.array.account_action_bar); accountActionBarColors = activity.getResources().getIntArray(R.array.account_action_bar);
accountStatusBarColors = activity.getResources().getIntArray(R.array.account_status_bar); accountStatusBarColors = activity.getResources().getIntArray(R.array.account_status_bar);
accountColorNames = activity.getResources().getStringArray(R.array.account_color_names);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window = this.activity.getWindow(); window = this.activity.getWindow();
...@@ -39,8 +41,11 @@ public class ActionBarPainter { ...@@ -39,8 +41,11 @@ public class ActionBarPainter {
defaultActionBarBackground = new ColorDrawable(activity.getResources().getColor(attributeResourceId)); defaultActionBarBackground = new ColorDrawable(activity.getResources().getColor(attributeResourceId));
} }
public void update(String account) { public void updateWithAccountName(String account) {
int colorLevel = AccountManager.getInstance().getColorLevel(account); updateWithColorLevel(AccountManager.getInstance().getColorLevel(account));
}
public void updateWithColorLevel(int colorLevel) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.setStatusBarColor(accountStatusBarColors[colorLevel]); window.setStatusBarColor(accountStatusBarColors[colorLevel]);
} }
...@@ -54,4 +59,13 @@ public class ActionBarPainter { ...@@ -54,4 +59,13 @@ public class ActionBarPainter {
activity.getSupportActionBar().setBackgroundDrawable(defaultActionBarBackground); activity.getSupportActionBar().setBackgroundDrawable(defaultActionBarBackground);
} }
public void updateWithColorName(String targetColorName) {
for (int i = 0; i < accountColorNames.length; i++) {
String accountColorName = accountColorNames[i];
if (accountColorName.equals(targetColorName)) {
updateWithColorLevel(i);
}
}
}
} }
...@@ -39,7 +39,7 @@ public class ContactTitleActionBarInflater { ...@@ -39,7 +39,7 @@ public class ContactTitleActionBarInflater {
} }
public void update(AbstractContact abstractContact) { public void update(AbstractContact abstractContact) {
actionBarPainter.update(abstractContact.getAccount()); actionBarPainter.updateWithAccountName(abstractContact.getAccount());
activity.getSupportActionBar().setDisplayShowCustomEnabled(true); activity.getSupportActionBar().setDisplayShowCustomEnabled(true);
activity.getSupportActionBar().setDisplayShowTitleEnabled(false); activity.getSupportActionBar().setDisplayShowTitleEnabled(false);
......
...@@ -28,6 +28,7 @@ import com.xabber.android.data.account.AccountManager; ...@@ -28,6 +28,7 @@ import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.intent.AccountIntentBuilder; import com.xabber.android.data.intent.AccountIntentBuilder;
import com.xabber.android.ui.OAuthActivity; import com.xabber.android.ui.OAuthActivity;
import com.xabber.android.ui.dialog.OrbotInstallerDialogBuilder; import com.xabber.android.ui.dialog.OrbotInstallerDialogBuilder;
import com.xabber.android.ui.helper.ActionBarPainter;
import com.xabber.android.ui.helper.ManagedActivity; import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
...@@ -46,6 +47,7 @@ public class AccountEditor extends ManagedActivity implements ...@@ -46,6 +47,7 @@ public class AccountEditor extends ManagedActivity implements
private AccountItem accountItem; private AccountItem accountItem;
private String token; private String token;
private ActionBarPainter actionBarPainter;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
...@@ -76,6 +78,9 @@ public class AccountEditor extends ManagedActivity implements ...@@ -76,6 +78,9 @@ public class AccountEditor extends ManagedActivity implements
setSupportActionBar((Toolbar) findViewById(R.id.toolbar_default)); setSupportActionBar((Toolbar) findViewById(R.id.toolbar_default));
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setTitle(AccountManager.getInstance().getVerboseName(account)); setTitle(AccountManager.getInstance().getVerboseName(account));
actionBarPainter = new ActionBarPainter(this);
actionBarPainter.updateWithAccountName(account);
} }
@Override @Override
...@@ -158,4 +163,9 @@ public class AccountEditor extends ManagedActivity implements ...@@ -158,4 +163,9 @@ public class AccountEditor extends ManagedActivity implements
public void showOrbotDialog() { public void showOrbotDialog() {
showDialog(ORBOT_DIALOG_ID); showDialog(ORBOT_DIALOG_ID);
} }
@Override
public void onColorChange(String colorName) {
actionBarPainter.updateWithColorName(colorName);
}
} }
...@@ -92,6 +92,11 @@ public class AccountEditorFragment extends BaseSettingsFragment ...@@ -92,6 +92,11 @@ public class AccountEditorFragment extends BaseSettingsFragment
} }
} }
} }
if (getString(R.string.account_color_key).equals(key)) {
mListener.onColorChange((String)newValue);
}
return true; return true;
} }
...@@ -210,10 +215,11 @@ public class AccountEditorFragment extends BaseSettingsFragment ...@@ -210,10 +215,11 @@ public class AccountEditorFragment extends BaseSettingsFragment
} }
public interface AccountEditorFragmentInteractionListener { public interface AccountEditorFragmentInteractionListener {
public String getAccount(); String getAccount();
public AccountItem getAccountItem(); AccountItem getAccountItem();
public String getToken(); String getToken();
public void onOAuthClick(); void onOAuthClick();
public void showOrbotDialog(); void showOrbotDialog();
void onColorChange(String colorName);
} }
} }
...@@ -23,6 +23,7 @@ import com.xabber.android.data.Application; ...@@ -23,6 +23,7 @@ import com.xabber.android.data.Application;
import com.xabber.android.data.account.AccountItem; import com.xabber.android.data.account.AccountItem;
import com.xabber.android.data.account.AccountManager; import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.intent.EntityIntentBuilder; import com.xabber.android.data.intent.EntityIntentBuilder;
import com.xabber.android.ui.helper.ActionBarPainter;
import com.xabber.android.ui.helper.ManagedActivity; import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
...@@ -51,6 +52,9 @@ public class ChatEditor extends ManagedActivity ...@@ -51,6 +52,9 @@ public class ChatEditor extends ManagedActivity
setSupportActionBar((Toolbar) findViewById(R.id.toolbar_default)); setSupportActionBar((Toolbar) findViewById(R.id.toolbar_default));
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ActionBarPainter actionBarPainter = new ActionBarPainter(this);
actionBarPainter.updateWithAccountName(account);
if (savedInstanceState == null) { if (savedInstanceState == null) {
getFragmentManager().beginTransaction() getFragmentManager().beginTransaction()
.add(R.id.preferences_activity_container, new ChatEditorFragment()).commit(); .add(R.id.preferences_activity_container, new ChatEditorFragment()).commit();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment