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
@Override
public void onAccountSelected(String account) {
actionBarPainter.update(account);
actionBarPainter.updateWithAccountName(account);
}
}
......@@ -14,6 +14,7 @@ public class ActionBarPainter {
private int[] accountActionBarColors;
private int[] accountStatusBarColors;
private String[] accountColorNames;
private Window window;
private int defaultStatusBarColor;
......@@ -26,6 +27,7 @@ public class ActionBarPainter {
accountActionBarColors = activity.getResources().getIntArray(R.array.account_action_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) {
window = this.activity.getWindow();
......@@ -39,8 +41,11 @@ public class ActionBarPainter {
defaultActionBarBackground = new ColorDrawable(activity.getResources().getColor(attributeResourceId));
}
public void update(String account) {
int colorLevel = AccountManager.getInstance().getColorLevel(account);
public void updateWithAccountName(String account) {
updateWithColorLevel(AccountManager.getInstance().getColorLevel(account));
}
public void updateWithColorLevel(int colorLevel) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.setStatusBarColor(accountStatusBarColors[colorLevel]);
}
......@@ -54,4 +59,13 @@ public class ActionBarPainter {
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 {
}
public void update(AbstractContact abstractContact) {
actionBarPainter.update(abstractContact.getAccount());
actionBarPainter.updateWithAccountName(abstractContact.getAccount());
activity.getSupportActionBar().setDisplayShowCustomEnabled(true);
activity.getSupportActionBar().setDisplayShowTitleEnabled(false);
......
......@@ -28,6 +28,7 @@ import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.intent.AccountIntentBuilder;
import com.xabber.android.ui.OAuthActivity;
import com.xabber.android.ui.dialog.OrbotInstallerDialogBuilder;
import com.xabber.android.ui.helper.ActionBarPainter;
import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.androiddev.R;
......@@ -46,6 +47,7 @@ public class AccountEditor extends ManagedActivity implements
private AccountItem accountItem;
private String token;
private ActionBarPainter actionBarPainter;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -76,6 +78,9 @@ public class AccountEditor extends ManagedActivity implements
setSupportActionBar((Toolbar) findViewById(R.id.toolbar_default));
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setTitle(AccountManager.getInstance().getVerboseName(account));
actionBarPainter = new ActionBarPainter(this);
actionBarPainter.updateWithAccountName(account);
}
@Override
......@@ -158,4 +163,9 @@ public class AccountEditor extends ManagedActivity implements
public void showOrbotDialog() {
showDialog(ORBOT_DIALOG_ID);
}
@Override
public void onColorChange(String colorName) {
actionBarPainter.updateWithColorName(colorName);
}
}
......@@ -92,6 +92,11 @@ public class AccountEditorFragment extends BaseSettingsFragment
}
}
}
if (getString(R.string.account_color_key).equals(key)) {
mListener.onColorChange((String)newValue);
}
return true;
}
......@@ -210,10 +215,11 @@ public class AccountEditorFragment extends BaseSettingsFragment
}
public interface AccountEditorFragmentInteractionListener {
public String getAccount();
public AccountItem getAccountItem();
public String getToken();
public void onOAuthClick();
public void showOrbotDialog();
String getAccount();
AccountItem getAccountItem();
String getToken();
void onOAuthClick();
void showOrbotDialog();
void onColorChange(String colorName);
}
}
......@@ -23,6 +23,7 @@ import com.xabber.android.data.Application;
import com.xabber.android.data.account.AccountItem;
import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.intent.EntityIntentBuilder;
import com.xabber.android.ui.helper.ActionBarPainter;
import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.androiddev.R;
......@@ -51,6 +52,9 @@ public class ChatEditor extends ManagedActivity
setSupportActionBar((Toolbar) findViewById(R.id.toolbar_default));
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ActionBarPainter actionBarPainter = new ActionBarPainter(this);
actionBarPainter.updateWithAccountName(account);
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.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