Commit c02dd0ba authored by Grigory Fedorov's avatar Grigory Fedorov

Toolbar is painted in first account color by default.

ActionBarPainter renamed to BarPainter.
AppCompatActivity used instead of ActionBarActivity.
parent 2cf81885
...@@ -23,11 +23,20 @@ import android.view.MenuInflater; ...@@ -23,11 +23,20 @@ import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import com.xabber.android.data.intent.AccountIntentBuilder; import com.xabber.android.data.intent.AccountIntentBuilder;
import com.xabber.android.ui.helper.BarPainter;
import com.xabber.android.ui.helper.ManagedActivity; import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
public class AccountAdd extends ManagedActivity { public class AccountAdd extends ManagedActivity {
public static Intent createIntent(Context context) {
return new Intent(context, AccountAdd.class);
}
public static Intent createAuthenticatorResult(String account) {
return new AccountIntentBuilder(null, null).setAccount(account).build();
}
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
...@@ -40,10 +49,15 @@ public class AccountAdd extends ManagedActivity { ...@@ -40,10 +49,15 @@ public class AccountAdd extends ManagedActivity {
getSupportFragmentManager().beginTransaction().add(R.id.container, AccountAddFragment.newInstance()).commit(); getSupportFragmentManager().beginTransaction().add(R.id.container, AccountAddFragment.newInstance()).commit();
} }
setSupportActionBar((Toolbar) findViewById(R.id.toolbar_default)); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_default);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_clear_white_24dp); getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_clear_white_24dp);
getSupportActionBar().setTitle(null); getSupportActionBar().setTitle(null);
BarPainter barPainter = new BarPainter(this, toolbar);
barPainter.setDefaultColor();
} }
@Override @Override
...@@ -67,12 +81,4 @@ public class AccountAdd extends ManagedActivity { ...@@ -67,12 +81,4 @@ public class AccountAdd extends ManagedActivity {
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
} }
public static Intent createIntent(Context context) {
return new Intent(context, AccountAdd.class);
}
public static Intent createAuthenticatorResult(String account) {
return new AccountIntentBuilder(null, null).setAccount(account).build();
}
} }
...@@ -38,6 +38,7 @@ import com.xabber.android.data.notification.NotificationManager; ...@@ -38,6 +38,7 @@ import com.xabber.android.data.notification.NotificationManager;
import com.xabber.android.data.roster.OnContactChangedListener; import com.xabber.android.data.roster.OnContactChangedListener;
import com.xabber.android.ui.adapter.ChatScrollIndicatorAdapter; import com.xabber.android.ui.adapter.ChatScrollIndicatorAdapter;
import com.xabber.android.ui.adapter.ChatViewerAdapter; import com.xabber.android.ui.adapter.ChatViewerAdapter;
import com.xabber.android.ui.helper.BarPainter;
import com.xabber.android.ui.helper.ManagedActivity; import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.android.ui.helper.StatusBarPainter; import com.xabber.android.ui.helper.StatusBarPainter;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
...@@ -71,20 +72,13 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -71,20 +72,13 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
private static final String SAVED_SELECTED_USER = "com.xabber.android.ui.ChatViewer.SAVED_SELECTED_USER"; private static final String SAVED_SELECTED_USER = "com.xabber.android.ui.ChatViewer.SAVED_SELECTED_USER";
private static final String SAVED_EXIT_ON_SEND = "com.xabber.android.ui.ChatViewer.EXIT_ON_SEND"; private static final String SAVED_EXIT_ON_SEND = "com.xabber.android.ui.ChatViewer.EXIT_ON_SEND";
private boolean exitOnSend;
private String extraText = null;
ChatScrollIndicatorAdapter chatScrollIndicatorAdapter; ChatScrollIndicatorAdapter chatScrollIndicatorAdapter;
ChatViewerAdapter chatViewerAdapter; ChatViewerAdapter chatViewerAdapter;
ViewPager viewPager; ViewPager viewPager;
Collection<ChatViewerFragment> registeredChats = new HashSet<>(); Collection<ChatViewerFragment> registeredChats = new HashSet<>();
Collection<RecentChatFragment> recentChatFragments = new HashSet<>(); Collection<RecentChatFragment> recentChatFragments = new HashSet<>();
private boolean exitOnSend;
private String extraText = null;
private BaseEntity initialChat = null; private BaseEntity initialChat = null;
private BaseEntity selectedChat = null; private BaseEntity selectedChat = null;
...@@ -92,6 +86,78 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -92,6 +86,78 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
private boolean isRecentChatsSelected; private boolean isRecentChatsSelected;
public static void hideKeyboard(Activity activity) {
// Check if no view has focus:
View view = activity.getCurrentFocus();
if (view != null) {
InputMethodManager inputManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
}
private static String getAccount(Intent intent) {
String value = EntityIntentBuilder.getAccount(intent);
if (value != null)
return value;
// Backward compatibility.
return intent.getStringExtra("com.xabber.android.data.account");
}
private static String getUser(Intent intent) {
String value = EntityIntentBuilder.getUser(intent);
if (value != null)
return value;
// Backward compatibility.
return intent.getStringExtra("com.xabber.android.data.user");
}
private static boolean hasAttention(Intent intent) {
return ACTION_ATTENTION.equals(intent.getAction());
}
public static Intent createSpecificChatIntent(Context context, String account, String user) {
Intent intent = new EntityIntentBuilder(context, ChatViewer.class).setAccount(account).setUser(user).build();
intent.setAction(ACTION_SPECIFIC_CHAT);
return intent;
}
public static Intent createRecentChatsIntent(Context context) {
Intent intent = new EntityIntentBuilder(context, ChatViewer.class).build();
intent.setAction(ACTION_RECENT_CHATS);
return intent;
}
public static Intent createClearTopIntent(Context context, String account, String user) {
Intent intent = createSpecificChatIntent(context, account, user);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
return intent;
}
/**
* Create intent to send message.
* <p/>
* Contact list will not be shown on when chat will be closed.
*
* @param context
* @param account
* @param user
* @param text if <code>null</code> then user will be able to send a number
* of messages. Else only one message can be send.
* @return
*/
public static Intent createSendIntent(Context context, String account, String user, String text) {
Intent intent = ChatViewer.createSpecificChatIntent(context, account, user);
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, text);
return intent;
}
public static Intent createAttentionRequestIntent(Context context, String account, String user) {
Intent intent = ChatViewer.createClearTopIntent(context, account, user);
intent.setAction(ACTION_ATTENTION);
return intent;
}
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
...@@ -318,11 +384,13 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -318,11 +384,13 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
} }
private void updateStatusBar() { private void updateStatusBar() {
String account;
if (isRecentChatsSelected) { if (isRecentChatsSelected) {
statusBarPainter.restore(); account = BarPainter.getFirstAccount();
} else { } else {
statusBarPainter.updateWithAccountName(selectedChat.getAccount()); account = selectedChat.getAccount();
} }
statusBarPainter.updateWithAccountName(account);
} }
private void updateRegisteredChats() { private void updateRegisteredChats() {
...@@ -349,7 +417,6 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -349,7 +417,6 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
recentChatFragments.remove(recentChatFragment); recentChatFragments.remove(recentChatFragment);
} }
@Override @Override
public void onChatViewAdapterFinishUpdate() { public void onChatViewAdapterFinishUpdate() {
insertExtraText(); insertExtraText();
...@@ -380,19 +447,11 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -380,19 +447,11 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
public void onChatSelected(AbstractChat chat) { public void onChatSelected(AbstractChat chat) {
selectChatPage(chat, true); selectChatPage(chat, true);
} }
public ChatViewerAdapter getChatViewerAdapter() { public ChatViewerAdapter getChatViewerAdapter() {
return chatViewerAdapter; return chatViewerAdapter;
} }
public static void hideKeyboard(Activity activity) {
// Check if no view has focus:
View view = activity.getCurrentFocus();
if (view != null) {
InputMethodManager inputManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
}
@Override @Override
public void onCloseChat() { public void onCloseChat() {
close(); close();
...@@ -415,7 +474,6 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -415,7 +474,6 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
registeredChats.remove(chat); registeredChats.remove(chat);
} }
private void close() { private void close() {
finish(); finish();
if (!Intent.ACTION_SEND.equals(getIntent().getAction())) { if (!Intent.ACTION_SEND.equals(getIntent().getAction())) {
...@@ -425,68 +483,4 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -425,68 +483,4 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
} }
} }
} }
private static String getAccount(Intent intent) {
String value = EntityIntentBuilder.getAccount(intent);
if (value != null)
return value;
// Backward compatibility.
return intent.getStringExtra("com.xabber.android.data.account");
}
private static String getUser(Intent intent) {
String value = EntityIntentBuilder.getUser(intent);
if (value != null)
return value;
// Backward compatibility.
return intent.getStringExtra("com.xabber.android.data.user");
}
private static boolean hasAttention(Intent intent) {
return ACTION_ATTENTION.equals(intent.getAction());
}
public static Intent createSpecificChatIntent(Context context, String account, String user) {
Intent intent = new EntityIntentBuilder(context, ChatViewer.class).setAccount(account).setUser(user).build();
intent.setAction(ACTION_SPECIFIC_CHAT);
return intent;
}
public static Intent createRecentChatsIntent(Context context) {
Intent intent = new EntityIntentBuilder(context, ChatViewer.class).build();
intent.setAction(ACTION_RECENT_CHATS);
return intent;
}
public static Intent createClearTopIntent(Context context, String account, String user) {
Intent intent = createSpecificChatIntent(context, account, user);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
return intent;
}
/**
* Create intent to send message.
* <p/>
* Contact list will not be shown on when chat will be closed.
*
* @param context
* @param account
* @param user
* @param text if <code>null</code> then user will be able to send a number
* of messages. Else only one message can be send.
* @return
*/
public static Intent createSendIntent(Context context, String account, String user, String text) {
Intent intent = ChatViewer.createSpecificChatIntent(context, account, user);
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, text);
return intent;
}
public static Intent createAttentionRequestIntent(Context context, String account, String user) {
Intent intent = ChatViewer.createClearTopIntent(context, account, user);
intent.setAction(ACTION_ATTENTION);
return intent;
}
} }
...@@ -7,7 +7,7 @@ import android.content.ClipboardManager; ...@@ -7,7 +7,7 @@ import android.content.ClipboardManager;
import android.content.Context; import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.NavUtils; import android.support.v4.app.NavUtils;
import android.support.v7.app.ActionBarActivity; import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
...@@ -50,7 +50,7 @@ import com.xabber.android.data.roster.AbstractContact; ...@@ -50,7 +50,7 @@ import com.xabber.android.data.roster.AbstractContact;
import com.xabber.android.data.roster.RosterManager; import com.xabber.android.data.roster.RosterManager;
import com.xabber.android.ui.adapter.ChatMessageAdapter; import com.xabber.android.ui.adapter.ChatMessageAdapter;
import com.xabber.android.ui.dialog.ChatExportDialogFragment; import com.xabber.android.ui.dialog.ChatExportDialogFragment;
import com.xabber.android.ui.helper.ActionBarPainter; import com.xabber.android.ui.helper.BarPainter;
import com.xabber.android.ui.helper.ContactTitleInflater; import com.xabber.android.ui.helper.ContactTitleInflater;
import com.xabber.android.ui.preferences.ChatEditor; import com.xabber.android.ui.preferences.ChatEditor;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
...@@ -62,17 +62,12 @@ public class ChatViewerFragment extends Fragment implements PopupMenu.OnMenuItem ...@@ -62,17 +62,12 @@ public class ChatViewerFragment extends Fragment implements PopupMenu.OnMenuItem
public static final String ARGUMENT_USER = "ARGUMENT_USER"; public static final String ARGUMENT_USER = "ARGUMENT_USER";
private static final int MINIMUM_MESSAGES_TO_LOAD = 10; private static final int MINIMUM_MESSAGES_TO_LOAD = 10;
boolean isInputEmpty = true;
private EditText inputView; private EditText inputView;
private ChatMessageAdapter chatMessageAdapter; private ChatMessageAdapter chatMessageAdapter;
private boolean skipOnTextChanges; private boolean skipOnTextChanges;
private String account; private String account;
private String user; private String user;
boolean isInputEmpty = true;
private ImageButton sendButton; private ImageButton sendButton;
private ImageButton securityButton; private ImageButton securityButton;
private Toolbar toolbar; private Toolbar toolbar;
...@@ -127,10 +122,7 @@ public class ChatViewerFragment extends Fragment implements PopupMenu.OnMenuItem ...@@ -127,10 +122,7 @@ public class ChatViewerFragment extends Fragment implements PopupMenu.OnMenuItem
abstractContact = RosterManager.getInstance().getBestContact(account, user); abstractContact = RosterManager.getInstance().getBestContact(account, user);
contactTitleView.findViewById(R.id.avatar).setOnClickListener(this); contactTitleView.findViewById(R.id.avatar).setOnClickListener(this);
ActionBarPainter actionBarPainter = new ActionBarPainter((ActionBarActivity) getActivity());
toolbar = (Toolbar) view.findViewById(R.id.toolbar_default); toolbar = (Toolbar) view.findViewById(R.id.toolbar_default);
toolbar.setBackgroundColor(actionBarPainter.getAccountColor(account));
toolbar.inflateMenu(R.menu.chat); toolbar.inflateMenu(R.menu.chat);
toolbar.setOnMenuItemClickListener(this); toolbar.setOnMenuItemClickListener(this);
toolbar.setNavigationIcon(R.drawable.ic_arrow_left_white_24dp); toolbar.setNavigationIcon(R.drawable.ic_arrow_left_white_24dp);
...@@ -141,6 +133,9 @@ public class ChatViewerFragment extends Fragment implements PopupMenu.OnMenuItem ...@@ -141,6 +133,9 @@ public class ChatViewerFragment extends Fragment implements PopupMenu.OnMenuItem
} }
}); });
BarPainter barPainter = new BarPainter((AppCompatActivity) getActivity(), toolbar);
toolbar.setBackgroundColor(barPainter.getAccountColor(account));
sendButton = (ImageButton) view.findViewById(R.id.button_send_message); sendButton = (ImageButton) view.findViewById(R.id.button_send_message);
sendButton.setImageResource(R.drawable.ic_button_send_inactive_24dp); sendButton.setImageResource(R.drawable.ic_button_send_inactive_24dp);
...@@ -613,17 +608,20 @@ public class ChatViewerFragment extends Fragment implements PopupMenu.OnMenuItem ...@@ -613,17 +608,20 @@ public class ChatViewerFragment extends Fragment implements PopupMenu.OnMenuItem
unregisterForContextMenu(caller); unregisterForContextMenu(caller);
} }
public interface ChatViewerFragmentListener {
void onCloseChat();
void onMessageSent();
void registerChat(ChatViewerFragment chat);
void unregisterChat(ChatViewerFragment chat);
}
public void playIncomingAnimation() { public void playIncomingAnimation() {
if (shakeAnimation == null) { if (shakeAnimation == null) {
shakeAnimation = AnimationUtils.loadAnimation(getActivity(), R.anim.shake); shakeAnimation = AnimationUtils.loadAnimation(getActivity(), R.anim.shake);
} }
toolbar.findViewById(R.id.name_holder).startAnimation(shakeAnimation); toolbar.findViewById(R.id.name_holder).startAnimation(shakeAnimation);
} }
public interface ChatViewerFragmentListener {
void onCloseChat();
void onMessageSent();
void registerChat(ChatViewerFragment chat);
void unregisterChat(ChatViewerFragment chat);
}
} }
...@@ -23,25 +23,47 @@ import android.view.MenuInflater; ...@@ -23,25 +23,47 @@ import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
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.BarPainter;
import com.xabber.android.ui.helper.ManagedActivity; import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
public class ContactAdd extends ManagedActivity implements ContactAddFragment.Listener { public class ContactAdd extends ManagedActivity implements ContactAddFragment.Listener {
ActionBarPainter actionBarPainter; BarPainter barPainter;
public static Intent createIntent(Context context) {
return createIntent(context, null);
}
public static Intent createIntent(Context context, String account) {
return createIntent(context, account, null);
}
public static Intent createIntent(Context context, String account, String user) {
return new EntityIntentBuilder(context, ContactAdd.class).setAccount(account).setUser(user).build();
}
private static String getAccount(Intent intent) {
return EntityIntentBuilder.getAccount(intent);
}
private static String getUser(Intent intent) {
return EntityIntentBuilder.getUser(intent);
}
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.contact_add); setContentView(R.layout.contact_add);
setSupportActionBar((Toolbar) findViewById(R.id.toolbar_default)); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_default);
getSupportActionBar().setDisplayHomeAsUpEnabled(true); toolbar.setNavigationIcon(R.drawable.ic_clear_white_24dp);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_clear_white_24dp); setTitle(null);
getSupportActionBar().setTitle(null); barPainter = new BarPainter(this, toolbar);
barPainter.setDefaultColor();
setSupportActionBar(toolbar);
actionBarPainter = new ActionBarPainter(this);
Intent intent = getIntent(); Intent intent = getIntent();
...@@ -78,28 +100,8 @@ public class ContactAdd extends ManagedActivity implements ContactAddFragment.Li ...@@ -78,28 +100,8 @@ public class ContactAdd extends ManagedActivity implements ContactAddFragment.Li
} }
} }
public static Intent createIntent(Context context) {
return createIntent(context, null);
}
public static Intent createIntent(Context context, String account) {
return createIntent(context, account, null);
}
public static Intent createIntent(Context context, String account, String user) {
return new EntityIntentBuilder(context, ContactAdd.class).setAccount(account).setUser(user).build();
}
private static String getAccount(Intent intent) {
return EntityIntentBuilder.getAccount(intent);
}
private static String getUser(Intent intent) {
return EntityIntentBuilder.getUser(intent);
}
@Override @Override
public void onAccountSelected(String account) { public void onAccountSelected(String account) {
actionBarPainter.updateWithAccountName(account); barPainter.updateWithAccountName(account);
} }
} }
...@@ -58,6 +58,7 @@ import com.xabber.android.ui.dialog.AccountChooseDialogFragment; ...@@ -58,6 +58,7 @@ import com.xabber.android.ui.dialog.AccountChooseDialogFragment;
import com.xabber.android.ui.dialog.AccountChooseDialogFragment.OnChoosedListener; import com.xabber.android.ui.dialog.AccountChooseDialogFragment.OnChoosedListener;
import com.xabber.android.ui.dialog.ContactIntegrationDialogFragment; import com.xabber.android.ui.dialog.ContactIntegrationDialogFragment;
import com.xabber.android.ui.dialog.StartAtBootDialogFragment; import com.xabber.android.ui.dialog.StartAtBootDialogFragment;
import com.xabber.android.ui.helper.BarPainter;
import com.xabber.android.ui.helper.ManagedActivity; import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.android.ui.preferences.PreferenceEditor; import com.xabber.android.ui.preferences.PreferenceEditor;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
...@@ -100,6 +101,34 @@ public class ContactList extends ManagedActivity implements OnAccountChangedList ...@@ -100,6 +101,34 @@ public class ContactList extends ManagedActivity implements OnAccountChangedList
private String sendText; private String sendText;
private SearchView searchView; private SearchView searchView;
private BarPainter barPainter;
public static Intent createPersistentIntent(Context context) {
Intent intent = new Intent(context, ContactList.class);
intent.setAction("android.intent.action.MAIN");
intent.addCategory("android.intent.category.LAUNCHER");
intent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_NEW_TASK);
return intent;
}
public static Intent createIntent(Context context) {
return new Intent(context, ContactList.class);
}
public static Intent createRoomInviteIntent(Context context, String account, String room) {
Intent intent = new EntityIntentBuilder(context, ContactList.class)
.setAccount(account).setUser(room).build();
intent.setAction(ACTION_ROOM_INVITE);
return intent;
}
private static String getRoomInviteAccount(Intent intent) {
return EntityIntentBuilder.getAccount(intent);
}
private static String getRoomInviteUser(Intent intent) {
return EntityIntentBuilder.getUser(intent);
}
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
...@@ -117,10 +146,12 @@ public class ContactList extends ManagedActivity implements OnAccountChangedList ...@@ -117,10 +146,12 @@ public class ContactList extends ManagedActivity implements OnAccountChangedList
setContentView(R.layout.contact_list); setContentView(R.layout.contact_list);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_default); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_default);
toolbar.setLogo(R.drawable.ic_xabber_logo);
toolbar.setOnClickListener(this); toolbar.setOnClickListener(this);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
barPainter = new BarPainter(this, toolbar);
barPainter.setDefaultColor();
setTitle(getString(R.string.production_title)); setTitle(getString(R.string.production_title));
if (savedInstanceState != null) { if (savedInstanceState != null) {
...@@ -214,6 +245,7 @@ public class ContactList extends ManagedActivity implements OnAccountChangedList ...@@ -214,6 +245,7 @@ public class ContactList extends ManagedActivity implements OnAccountChangedList
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
barPainter.setDefaultColor();
rebuildAccountToggle(); rebuildAccountToggle();
Application.getInstance().addUIListener(OnAccountChangedListener.class, this); Application.getInstance().addUIListener(OnAccountChangedListener.class, this);
...@@ -500,6 +532,7 @@ public class ContactList extends ManagedActivity implements OnAccountChangedList ...@@ -500,6 +532,7 @@ public class ContactList extends ManagedActivity implements OnAccountChangedList
@Override @Override
public void onAccountsChanged(Collection<String> accounts) { public void onAccountsChanged(Collection<String> accounts) {
((ContactListFragment)getSupportFragmentManager().findFragmentById(R.id.container)).onAccountsChanged(); ((ContactListFragment)getSupportFragmentManager().findFragmentById(R.id.container)).onAccountsChanged();
barPainter.setDefaultColor();
} }
@Override @Override
...@@ -511,31 +544,4 @@ public class ContactList extends ManagedActivity implements OnAccountChangedList ...@@ -511,31 +544,4 @@ public class ContactList extends ManagedActivity implements OnAccountChangedList
((ContactListFragment)getSupportFragmentManager().findFragmentById(R.id.container)).rebuild(); ((ContactListFragment)getSupportFragmentManager().findFragmentById(R.id.container)).rebuild();
} }
public static Intent createPersistentIntent(Context context) {
Intent intent = new Intent(context, ContactList.class);
intent.setAction("android.intent.action.MAIN");
intent.addCategory("android.intent.category.LAUNCHER");
intent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_NEW_TASK);
return intent;
}
public static Intent createIntent(Context context) {
return new Intent(context, ContactList.class);
}
public static Intent createRoomInviteIntent(Context context, String account, String room) {
Intent intent = new EntityIntentBuilder(context, ContactList.class)
.setAccount(account).setUser(room).build();
intent.setAction(ACTION_ROOM_INVITE);
return intent;
}
private static String getRoomInviteAccount(Intent intent) {
return EntityIntentBuilder.getAccount(intent);
}
private static String getRoomInviteUser(Intent intent) {
return EntityIntentBuilder.getUser(intent);
}
} }
...@@ -30,18 +30,30 @@ import com.xabber.android.data.roster.AbstractContact; ...@@ -30,18 +30,30 @@ import com.xabber.android.data.roster.AbstractContact;
import com.xabber.android.data.roster.PresenceManager; import com.xabber.android.data.roster.PresenceManager;
import com.xabber.android.data.roster.RosterManager; import com.xabber.android.data.roster.RosterManager;
import com.xabber.android.data.roster.SubscriptionRequest; import com.xabber.android.data.roster.SubscriptionRequest;
import com.xabber.android.ui.helper.ActionBarPainter; import com.xabber.android.ui.helper.BarPainter;
import com.xabber.android.ui.helper.SingleActivity; import com.xabber.android.ui.helper.SingleActivity;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
import org.w3c.dom.Text;
public class ContactSubscription extends SingleActivity implements View.OnClickListener { public class ContactSubscription extends SingleActivity implements View.OnClickListener {
private String account; private String account;
private String user; private String user;
private SubscriptionRequest subscriptionRequest; private SubscriptionRequest subscriptionRequest;
public static Intent createIntent(Context context, String account,
String user) {
return new EntityIntentBuilder(context, ContactSubscription.class)
.setAccount(account).setUser(user).build();
}
private static String getAccount(Intent intent) {
return EntityIntentBuilder.getAccount(intent);
}
private static String getUser(Intent intent) {
return EntityIntentBuilder.getUser(intent);
}
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
...@@ -61,14 +73,14 @@ public class ContactSubscription extends SingleActivity implements View.OnClickL ...@@ -61,14 +73,14 @@ public class ContactSubscription extends SingleActivity implements View.OnClickL
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle(getString(R.string.subscription_request_message)); toolbar.setTitle(getString(R.string.subscription_request_message));
ActionBarPainter actionBarPainter = new ActionBarPainter(this); BarPainter barPainter = new BarPainter(this, toolbar);
actionBarPainter.updateWithAccountName(account); barPainter.updateWithAccountName(account);
View fakeToolbar = findViewById(R.id.fake_toolbar); View fakeToolbar = findViewById(R.id.fake_toolbar);
fakeToolbar.setBackgroundColor(actionBarPainter.getAccountColor(account)); fakeToolbar.setBackgroundColor(barPainter.getAccountColor(account));
toolbar.setBackgroundResource(android.R.color.transparent); toolbar.setBackgroundResource(android.R.color.transparent);
AbstractContact abstractContact = RosterManager.getInstance().getBestContact(account, user); AbstractContact abstractContact = RosterManager.getInstance().getBestContact(account, user);
...@@ -78,7 +90,7 @@ public class ContactSubscription extends SingleActivity implements View.OnClickL ...@@ -78,7 +90,7 @@ public class ContactSubscription extends SingleActivity implements View.OnClickL
((TextView)fakeToolbar.findViewById(R.id.dialog_message)).setText(subscriptionRequest.getConfirmation()); ((TextView)fakeToolbar.findViewById(R.id.dialog_message)).setText(subscriptionRequest.getConfirmation());
Button acceptButton = (Button) findViewById(R.id.accept_button); Button acceptButton = (Button) findViewById(R.id.accept_button);
acceptButton.setTextColor(actionBarPainter.getAccountColor(account)); acceptButton.setTextColor(barPainter.getAccountColor(account));
acceptButton.setOnClickListener(this); acceptButton.setOnClickListener(this);
findViewById(R.id.decline_button).setOnClickListener(this); findViewById(R.id.decline_button).setOnClickListener(this);
...@@ -128,18 +140,4 @@ public class ContactSubscription extends SingleActivity implements View.OnClickL ...@@ -128,18 +140,4 @@ public class ContactSubscription extends SingleActivity implements View.OnClickL
finish(); finish();
} }
public static Intent createIntent(Context context, String account,
String user) {
return new EntityIntentBuilder(context, ContactSubscription.class)
.setAccount(account).setUser(user).build();
}
private static String getAccount(Intent intent) {
return EntityIntentBuilder.getAccount(intent);
}
private static String getUser(Intent intent) {
return EntityIntentBuilder.getUser(intent);
}
} }
...@@ -62,28 +62,36 @@ public class FingerprintViewer extends ManagedActivity implements ...@@ -62,28 +62,36 @@ public class FingerprintViewer extends ManagedActivity implements
private static final String SAVED_REMOTE_FINGERPRINT = "com.xabber.android.ui.FingerprintViewer.SAVED_REMOTE_FINGERPRINT"; private static final String SAVED_REMOTE_FINGERPRINT = "com.xabber.android.ui.FingerprintViewer.SAVED_REMOTE_FINGERPRINT";
private static final String SAVED_LOCAL_FINGERPRINT = "com.xabber.android.ui.FingerprintViewer.SAVED_LOCAL_FINGERPRINT"; private static final String SAVED_LOCAL_FINGERPRINT = "com.xabber.android.ui.FingerprintViewer.SAVED_LOCAL_FINGERPRINT";
ContactTitleActionBarInflater contactTitleActionBarInflater;
private String account; private String account;
private String user; private String user;
private String remoteFingerprint; private String remoteFingerprint;
private String localFingerprint; private String localFingerprint;
/** /**
* UI update is in progress. * UI update is in progress.
*/ */
private boolean isUpdating; private boolean isUpdating;
private CheckBox verifiedView; private CheckBox verifiedView;
private View scanView; private View scanView;
private View showView; private View showView;
private View copyView; private View copyView;
/** /**
* QR code scanner and generator. * QR code scanner and generator.
*/ */
private IntentIntegrator integrator; private IntentIntegrator integrator;
ContactTitleActionBarInflater contactTitleActionBarInflater; public static Intent createIntent(Context context, String account, String user) {
return new EntityIntentBuilder(context, FingerprintViewer.class)
.setAccount(account).setUser(user).build();
}
private static String getAccount(Intent intent) {
return AccountIntentBuilder.getAccount(intent);
}
private static String getUser(Intent intent) {
return EntityIntentBuilder.getUser(intent);
}
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
...@@ -93,7 +101,6 @@ public class FingerprintViewer extends ManagedActivity implements ...@@ -93,7 +101,6 @@ public class FingerprintViewer extends ManagedActivity implements
} }
setContentView(R.layout.fingerprint_viewer); setContentView(R.layout.fingerprint_viewer);
setSupportActionBar((Toolbar) findViewById(R.id.toolbar_default));
integrator = new IntentIntegrator(this); integrator = new IntentIntegrator(this);
Intent intent = getIntent(); Intent intent = getIntent();
...@@ -121,7 +128,7 @@ public class FingerprintViewer extends ManagedActivity implements ...@@ -121,7 +128,7 @@ public class FingerprintViewer extends ManagedActivity implements
copyView.setOnClickListener(this); copyView.setOnClickListener(this);
isUpdating = false; isUpdating = false;
contactTitleActionBarInflater = new ContactTitleActionBarInflater(this); contactTitleActionBarInflater = new ContactTitleActionBarInflater(this, (Toolbar) findViewById(R.id.toolbar_default));
contactTitleActionBarInflater.setUpActionBarView(); contactTitleActionBarInflater.setUpActionBarView();
} }
...@@ -298,17 +305,4 @@ public class FingerprintViewer extends ManagedActivity implements ...@@ -298,17 +305,4 @@ public class FingerprintViewer extends ManagedActivity implements
isUpdating = false; isUpdating = false;
} }
public static Intent createIntent(Context context, String account, String user) {
return new EntityIntentBuilder(context, FingerprintViewer.class)
.setAccount(account).setUser(user).build();
}
private static String getAccount(Intent intent) {
return AccountIntentBuilder.getAccount(intent);
}
private static String getUser(Intent intent) {
return EntityIntentBuilder.getUser(intent);
}
} }
...@@ -37,18 +37,31 @@ import java.util.Collection; ...@@ -37,18 +37,31 @@ import java.util.Collection;
public class GroupEditor extends ManagedActivity implements OnContactChangedListener, public class GroupEditor extends ManagedActivity implements OnContactChangedListener,
OnAccountChangedListener { OnAccountChangedListener {
ContactTitleActionBarInflater contactTitleActionBarInflater;
private String account; private String account;
private String user; private String user;
ContactTitleActionBarInflater contactTitleActionBarInflater; public static Intent createIntent(Context context, String account, String user) {
Intent intent = new EntityIntentBuilder(context, GroupEditor.class)
.setAccount(account).setUser(user).build();
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
return intent;
}
private static String getAccount(Intent intent) {
return EntityIntentBuilder.getAccount(intent);
}
private static String getUser(Intent intent) {
return EntityIntentBuilder.getUser(intent);
}
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.group_editor); setContentView(R.layout.group_editor);
setSupportActionBar((Toolbar) findViewById(R.id.toolbar_default));
contactTitleActionBarInflater = new ContactTitleActionBarInflater(this); contactTitleActionBarInflater = new ContactTitleActionBarInflater(this, (Toolbar) findViewById(R.id.toolbar_default));
contactTitleActionBarInflater.setUpActionBarView(); contactTitleActionBarInflater.setUpActionBarView();
Intent intent = getIntent(); Intent intent = getIntent();
...@@ -107,19 +120,4 @@ public class GroupEditor extends ManagedActivity implements OnContactChangedList ...@@ -107,19 +120,4 @@ public class GroupEditor extends ManagedActivity implements OnContactChangedList
} }
} }
public static Intent createIntent(Context context, String account, String user) {
Intent intent = new EntityIntentBuilder(context, GroupEditor.class)
.setAccount(account).setUser(user).build();
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
return intent;
}
private static String getAccount(Intent intent) {
return EntityIntentBuilder.getAccount(intent);
}
private static String getUser(Intent intent) {
return EntityIntentBuilder.getUser(intent);
}
} }
...@@ -37,7 +37,7 @@ import com.xabber.android.data.intent.EntityIntentBuilder; ...@@ -37,7 +37,7 @@ import com.xabber.android.data.intent.EntityIntentBuilder;
import com.xabber.android.data.message.MessageManager; import com.xabber.android.data.message.MessageManager;
import com.xabber.android.data.notification.NotificationManager; import com.xabber.android.data.notification.NotificationManager;
import com.xabber.android.ui.adapter.AccountChooseAdapter; import com.xabber.android.ui.adapter.AccountChooseAdapter;
import com.xabber.android.ui.helper.ActionBarPainter; import com.xabber.android.ui.helper.BarPainter;
import com.xabber.android.ui.helper.ManagedActivity; import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
...@@ -67,7 +67,24 @@ public class MUCEditor extends ManagedActivity implements OnItemSelectedListener ...@@ -67,7 +67,24 @@ public class MUCEditor extends ManagedActivity implements OnItemSelectedListener
private EditText nickView; private EditText nickView;
private EditText passwordView; private EditText passwordView;
private ActionBarPainter actionBarPainter; private BarPainter barPainter;
public static Intent createIntent(Context context) {
return MUCEditor.createIntent(context, null, null);
}
public static Intent createIntent(Context context, String account,
String room) {
return new EntityIntentBuilder(context, MUCEditor.class).setAccount(account).setUser(room).build();
}
private static String getAccount(Intent intent) {
return AccountIntentBuilder.getAccount(intent);
}
private static String getUser(Intent intent) {
return EntityIntentBuilder.getUser(intent);
}
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
...@@ -77,11 +94,15 @@ public class MUCEditor extends ManagedActivity implements OnItemSelectedListener ...@@ -77,11 +94,15 @@ public class MUCEditor extends ManagedActivity implements OnItemSelectedListener
} }
setContentView(R.layout.muc_editor); setContentView(R.layout.muc_editor);
setSupportActionBar((Toolbar) findViewById(R.id.toolbar_default));
getSupportActionBar().setDisplayHomeAsUpEnabled(true); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_default);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_clear_white_24dp); toolbar.setNavigationIcon(R.drawable.ic_clear_white_24dp);
getSupportActionBar().setTitle(null); setTitle(null);
setSupportActionBar(toolbar);
barPainter = new BarPainter(this, toolbar);
barPainter.setDefaultColor();
accountView = (Spinner) findViewById(R.id.contact_account); accountView = (Spinner) findViewById(R.id.contact_account);
serverView = (EditText) findViewById(R.id.muc_server); serverView = (EditText) findViewById(R.id.muc_server);
...@@ -126,10 +147,8 @@ public class MUCEditor extends ManagedActivity implements OnItemSelectedListener ...@@ -126,10 +147,8 @@ public class MUCEditor extends ManagedActivity implements OnItemSelectedListener
} }
} }
actionBarPainter = new ActionBarPainter(this);
if (account != null) { if (account != null) {
actionBarPainter.updateWithAccountName(account); barPainter.updateWithAccountName(account);
for (int position = 0; position < accountView.getCount(); position++) { for (int position = 0; position < accountView.getCount(); position++) {
if (account.equals(accountView.getItemAtPosition(position))) { if (account.equals(accountView.getItemAtPosition(position))) {
...@@ -244,28 +263,11 @@ public class MUCEditor extends ManagedActivity implements OnItemSelectedListener ...@@ -244,28 +263,11 @@ public class MUCEditor extends ManagedActivity implements OnItemSelectedListener
} }
selectedAccount = accountView.getSelectedItemPosition(); selectedAccount = accountView.getSelectedItemPosition();
actionBarPainter.updateWithAccountName((String) accountView.getSelectedItem()); barPainter.updateWithAccountName((String) accountView.getSelectedItem());
} }
@Override @Override
public void onNothingSelected(AdapterView<?> parent) { public void onNothingSelected(AdapterView<?> parent) {
selectedAccount = accountView.getSelectedItemPosition(); selectedAccount = accountView.getSelectedItemPosition();
} }
public static Intent createIntent(Context context) {
return MUCEditor.createIntent(context, null, null);
}
public static Intent createIntent(Context context, String account,
String room) {
return new EntityIntentBuilder(context, MUCEditor.class).setAccount(account).setUser(room).build();
}
private static String getAccount(Intent intent) {
return AccountIntentBuilder.getAccount(intent);
}
private static String getUser(Intent intent) {
return EntityIntentBuilder.getUser(intent);
}
} }
...@@ -52,14 +52,53 @@ public class QuestionViewer extends ManagedActivity implements ...@@ -52,14 +52,53 @@ public class QuestionViewer extends ManagedActivity implements
private static final String EXTRA_FIELD_SHOW_QUESTION = "com.xabber.android.data.ui.QuestionViewer.SHOW_QUESTION"; private static final String EXTRA_FIELD_SHOW_QUESTION = "com.xabber.android.data.ui.QuestionViewer.SHOW_QUESTION";
private static final String EXTRA_FIELD_ANSWER_REQUEST = "com.xabber.android.data.ui.QuestionViewer.ANSWER_REQUEST"; private static final String EXTRA_FIELD_ANSWER_REQUEST = "com.xabber.android.data.ui.QuestionViewer.ANSWER_REQUEST";
private static final String EXTRA_FIELD_CANCEL = "com.xabber.android.data.ui.QuestionViewer.CANCEL"; private static final String EXTRA_FIELD_CANCEL = "com.xabber.android.data.ui.QuestionViewer.CANCEL";
ContactTitleActionBarInflater contactTitleActionBarInflater;
private String account; private String account;
private String user; private String user;
private boolean showQuestion; private boolean showQuestion;
private boolean answerRequest; private boolean answerRequest;
private EditText questionView; private EditText questionView;
ContactTitleActionBarInflater contactTitleActionBarInflater; /**
* @param context
* @param account
* @param user
* @return Intent to cancel negotiation.
*/
public static Intent createCancelIntent(Context context, String account, String user) {
Intent intent = new EntityIntentBuilder(context, QuestionViewer.class)
.setAccount(account).setUser(user).build();
intent.putExtra(EXTRA_FIELD_CANCEL, true);
return intent;
}
/**
* @param context
* @param account
* @param user
* @param showQuestion <code>false</code> is used for shared secret.
* @param answerRequest <code>false</code> is used to ask a question.
* @param question must be not <code>null</code> if showQuestion and
* answerRequest are <code>true</code>.
* @return
*/
public static Intent createIntent(Context context, String account, String user,
boolean showQuestion, boolean answerRequest, String question) {
Intent intent = new EntityIntentBuilder(context, QuestionViewer.class)
.setAccount(account).setUser(user).build();
intent.putExtra(EXTRA_FIELD_SHOW_QUESTION, showQuestion);
intent.putExtra(EXTRA_FIELD_ANSWER_REQUEST, answerRequest);
intent.putExtra(Intent.EXTRA_TEXT, question);
return intent;
}
private static String getAccount(Intent intent) {
return AccountIntentBuilder.getAccount(intent);
}
private static String getUser(Intent intent) {
return EntityIntentBuilder.getUser(intent);
}
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
...@@ -89,7 +128,6 @@ public class QuestionViewer extends ManagedActivity implements ...@@ -89,7 +128,6 @@ public class QuestionViewer extends ManagedActivity implements
answerRequest = intent.getBooleanExtra(EXTRA_FIELD_ANSWER_REQUEST, false); answerRequest = intent.getBooleanExtra(EXTRA_FIELD_ANSWER_REQUEST, false);
if (showQuestion) { if (showQuestion) {
setContentView(R.layout.question_viewer); setContentView(R.layout.question_viewer);
setSupportActionBar((Toolbar) findViewById(R.id.toolbar_default));
questionView = (EditText) findViewById(R.id.question); questionView = (EditText) findViewById(R.id.question);
questionView.setEnabled(!answerRequest); questionView.setEnabled(!answerRequest);
if (answerRequest) { if (answerRequest) {
...@@ -99,12 +137,12 @@ public class QuestionViewer extends ManagedActivity implements ...@@ -99,12 +137,12 @@ public class QuestionViewer extends ManagedActivity implements
} }
} else { } else {
setContentView(R.layout.secret_viewer); setContentView(R.layout.secret_viewer);
setSupportActionBar((Toolbar) findViewById(R.id.toolbar_default));
} }
findViewById(R.id.cancel).setOnClickListener(this); findViewById(R.id.cancel).setOnClickListener(this);
findViewById(R.id.send).setOnClickListener(this); findViewById(R.id.send).setOnClickListener(this);
contactTitleActionBarInflater = new ContactTitleActionBarInflater(this); contactTitleActionBarInflater = new ContactTitleActionBarInflater(this, (Toolbar) findViewById(R.id.toolbar_default));
contactTitleActionBarInflater.setUpActionBarView(); contactTitleActionBarInflater.setUpActionBarView();
} }
...@@ -175,45 +213,4 @@ public class QuestionViewer extends ManagedActivity implements ...@@ -175,45 +213,4 @@ public class QuestionViewer extends ManagedActivity implements
contactTitleActionBarInflater.update(abstractContact); contactTitleActionBarInflater.update(abstractContact);
} }
/**
* @param context
* @param account
* @param user
* @return Intent to cancel negotiation.
*/
public static Intent createCancelIntent(Context context, String account, String user) {
Intent intent = new EntityIntentBuilder(context, QuestionViewer.class)
.setAccount(account).setUser(user).build();
intent.putExtra(EXTRA_FIELD_CANCEL, true);
return intent;
}
/**
* @param context
* @param account
* @param user
* @param showQuestion <code>false</code> is used for shared secret.
* @param answerRequest <code>false</code> is used to ask a question.
* @param question must be not <code>null</code> if showQuestion and
* answerRequest are <code>true</code>.
* @return
*/
public static Intent createIntent(Context context, String account, String user,
boolean showQuestion, boolean answerRequest, String question) {
Intent intent = new EntityIntentBuilder(context, QuestionViewer.class)
.setAccount(account).setUser(user).build();
intent.putExtra(EXTRA_FIELD_SHOW_QUESTION, showQuestion);
intent.putExtra(EXTRA_FIELD_ANSWER_REQUEST, answerRequest);
intent.putExtra(Intent.EXTRA_TEXT, question);
return intent;
}
private static String getAccount(Intent intent) {
return AccountIntentBuilder.getAccount(intent);
}
private static String getUser(Intent intent) {
return EntityIntentBuilder.getUser(intent);
}
} }
...@@ -4,6 +4,7 @@ import android.app.Activity; ...@@ -4,6 +4,7 @@ import android.app.Activity;
import android.app.ListFragment; import android.app.ListFragment;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.NavUtils; import android.support.v4.app.NavUtils;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MenuItem; import android.view.MenuItem;
...@@ -14,6 +15,7 @@ import android.widget.Toast; ...@@ -14,6 +15,7 @@ import android.widget.Toast;
import com.xabber.android.data.message.AbstractChat; import com.xabber.android.data.message.AbstractChat;
import com.xabber.android.ui.adapter.ChatListAdapter; import com.xabber.android.ui.adapter.ChatListAdapter;
import com.xabber.android.ui.helper.BarPainter;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -22,10 +24,6 @@ import java.util.List; ...@@ -22,10 +24,6 @@ import java.util.List;
public class RecentChatFragment extends ListFragment implements Toolbar.OnMenuItemClickListener { public class RecentChatFragment extends ListFragment implements Toolbar.OnMenuItemClickListener {
private RecentChatFragmentInteractionListener listener; private RecentChatFragmentInteractionListener listener;
public static RecentChatFragment newInstance() {
return new RecentChatFragment();
}
/** /**
* Mandatory empty constructor for the fragment manager to instantiate the * Mandatory empty constructor for the fragment manager to instantiate the
* fragment (e.g. upon screen orientation changes). * fragment (e.g. upon screen orientation changes).
...@@ -33,6 +31,10 @@ public class RecentChatFragment extends ListFragment implements Toolbar.OnMenuIt ...@@ -33,6 +31,10 @@ public class RecentChatFragment extends ListFragment implements Toolbar.OnMenuIt
public RecentChatFragment() { public RecentChatFragment() {
} }
public static RecentChatFragment newInstance() {
return new RecentChatFragment();
}
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
...@@ -79,6 +81,9 @@ public class RecentChatFragment extends ListFragment implements Toolbar.OnMenuIt ...@@ -79,6 +81,9 @@ public class RecentChatFragment extends ListFragment implements Toolbar.OnMenuIt
toolbar.inflateMenu(R.menu.recent_chats); toolbar.inflateMenu(R.menu.recent_chats);
toolbar.setOnMenuItemClickListener(this); toolbar.setOnMenuItemClickListener(this);
BarPainter barPainter = new BarPainter((AppCompatActivity) getActivity(), toolbar);
toolbar.setBackgroundColor(barPainter.getDefaultColor());
return rootView; return rootView;
} }
...@@ -121,11 +126,11 @@ public class RecentChatFragment extends ListFragment implements Toolbar.OnMenuIt ...@@ -121,11 +126,11 @@ public class RecentChatFragment extends ListFragment implements Toolbar.OnMenuIt
return false; return false;
} }
public interface RecentChatFragmentInteractionListener {
void onChatSelected(AbstractChat chat);
}
public void updateChats(List<AbstractChat> chats) { public void updateChats(List<AbstractChat> chats) {
((ChatListAdapter) getListAdapter()).updateChats(chats); ((ChatListAdapter) getListAdapter()).updateChats(chats);
} }
public interface RecentChatFragmentInteractionListener {
void onChatSelected(AbstractChat chat);
}
} }
...@@ -41,7 +41,7 @@ import com.xabber.android.data.account.StatusMode; ...@@ -41,7 +41,7 @@ import com.xabber.android.data.account.StatusMode;
import com.xabber.android.data.intent.AccountIntentBuilder; import com.xabber.android.data.intent.AccountIntentBuilder;
import com.xabber.android.ui.adapter.StatusEditorAdapter; import com.xabber.android.ui.adapter.StatusEditorAdapter;
import com.xabber.android.ui.adapter.StatusModeAdapter; import com.xabber.android.ui.adapter.StatusModeAdapter;
import com.xabber.android.ui.helper.ActionBarPainter; import com.xabber.android.ui.helper.BarPainter;
import com.xabber.android.ui.helper.ManagedListActivity; import com.xabber.android.ui.helper.ManagedListActivity;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
...@@ -58,6 +58,18 @@ public class StatusEditor extends ManagedListActivity implements OnItemClickList ...@@ -58,6 +58,18 @@ public class StatusEditor extends ManagedListActivity implements OnItemClickList
private StatusEditorAdapter adapter; private StatusEditorAdapter adapter;
private View savedStatusesTextView; private View savedStatusesTextView;
public static Intent createIntent(Context context) {
return StatusEditor.createIntent(context, null);
}
public static Intent createIntent(Context context, String account) {
return new AccountIntentBuilder(context, StatusEditor.class).setAccount(account).build();
}
private static String getAccount(Intent intent) {
return AccountIntentBuilder.getAccount(intent);
}
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
...@@ -68,17 +80,21 @@ public class StatusEditor extends ManagedListActivity implements OnItemClickList ...@@ -68,17 +80,21 @@ public class StatusEditor extends ManagedListActivity implements OnItemClickList
actionWithItem = null; actionWithItem = null;
setContentView(R.layout.status_editor); setContentView(R.layout.status_editor);
setSupportActionBar((Toolbar) findViewById(R.id.top_toolbar));
getSupportActionBar().setDisplayHomeAsUpEnabled(true); Toolbar toolbar = (Toolbar) findViewById(R.id.top_toolbar);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_clear_white_24dp); toolbar.setNavigationIcon(R.drawable.ic_clear_white_24dp);
getSupportActionBar().setTitle(null); setTitle(null);
setSupportActionBar(toolbar);
Intent intent = getIntent(); Intent intent = getIntent();
account = StatusEditor.getAccount(intent); account = StatusEditor.getAccount(intent);
BarPainter barPainter = new BarPainter(this, toolbar);
if (account != null) { if (account != null) {
ActionBarPainter actionBarPainter = new ActionBarPainter(this); barPainter.updateWithAccountName(account);
actionBarPainter.updateWithAccountName(account); } else {
barPainter.setDefaultColor();
} }
ListView listView = getListView(); ListView listView = getListView();
...@@ -233,18 +249,6 @@ public class StatusEditor extends ManagedListActivity implements OnItemClickList ...@@ -233,18 +249,6 @@ public class StatusEditor extends ManagedListActivity implements OnItemClickList
finish(); finish();
} }
public static Intent createIntent(Context context) {
return StatusEditor.createIntent(context, null);
}
public static Intent createIntent(Context context, String account) {
return new AccountIntentBuilder(context, StatusEditor.class).setAccount(account).build();
}
private static String getAccount(Intent intent) {
return AccountIntentBuilder.getAccount(intent);
}
@Override @Override
public boolean onMenuItemClick(MenuItem menuItem) { public boolean onMenuItemClick(MenuItem menuItem) {
return onOptionsItemSelected(menuItem); return onOptionsItemSelected(menuItem);
......
package com.xabber.android.ui.helper; package com.xabber.android.ui.helper;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.graphics.drawable.ColorDrawable; import android.support.v7.app.AppCompatActivity;
import android.support.v7.app.ActionBarActivity; import android.support.v7.widget.Toolbar;
import com.xabber.android.data.account.AccountManager; import com.xabber.android.data.account.AccountManager;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
public class ActionBarPainter { import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
private int[] accountActionBarColors; public class BarPainter {
private final Toolbar toolbar;
private final int defaultSystemColor;
private int[] accountActionBarColors;
private String[] accountColorNames; private String[] accountColorNames;
private ColorDrawable defaultActionBarBackground;
private final ActionBarActivity activity;
private StatusBarPainter statusBarPainter; private StatusBarPainter statusBarPainter;
public ActionBarPainter(ActionBarActivity activity) { public BarPainter(AppCompatActivity activity, Toolbar toolbar) {
this.activity = activity; this.toolbar = toolbar;
statusBarPainter = new StatusBarPainter(activity); statusBarPainter = new StatusBarPainter(activity);
accountActionBarColors = activity.getResources().getIntArray(R.array.account_action_bar); accountActionBarColors = activity.getResources().getIntArray(R.array.account_action_bar);
accountColorNames = activity.getResources().getStringArray(R.array.account_color_names); accountColorNames = activity.getResources().getStringArray(R.array.account_color_names);
TypedArray a = activity.getTheme().obtainStyledAttributes(R.style.Theme, new int[]{R.attr.colorPrimary});
TypedArray a = activity.getTheme().obtainStyledAttributes(R.style.Theme, new int[] {R.attr.colorPrimary});
int attributeResourceId = a.getResourceId(0, 0); int attributeResourceId = a.getResourceId(0, 0);
defaultActionBarBackground = new ColorDrawable(activity.getResources().getColor(attributeResourceId)); a.recycle();
defaultSystemColor = activity.getResources().getColor(attributeResourceId);
}
public static String getFirstAccount() {
List<String> list = new ArrayList<>();
list.addAll(AccountManager.getInstance().getAccounts());
Collections.sort(list);
if (list.isEmpty()) {
return null;
} else {
return list.get(0);
}
} }
public void updateWithAccountName(String account) { public void updateWithAccountName(String account) {
...@@ -39,13 +47,18 @@ public class ActionBarPainter { ...@@ -39,13 +47,18 @@ public class ActionBarPainter {
} }
public void updateWithColorLevel(int colorLevel) { public void updateWithColorLevel(int colorLevel) {
activity.getSupportActionBar().setBackgroundDrawable(new ColorDrawable(accountActionBarColors[colorLevel])); toolbar.setBackgroundColor(accountActionBarColors[colorLevel]);
statusBarPainter.updateWithColorLevel(colorLevel); statusBarPainter.updateWithColorLevel(colorLevel);
} }
public void restore() { public void setDefaultColor() {
activity.getSupportActionBar().setBackgroundDrawable(defaultActionBarBackground); String firstAccount = getFirstAccount();
statusBarPainter.restore(); if (firstAccount == null) {
toolbar.setBackgroundColor(defaultSystemColor);
statusBarPainter.restore();
} else {
updateWithAccountName(firstAccount);
}
} }
public void updateWithColorName(String targetColorName) { public void updateWithColorName(String targetColorName) {
...@@ -61,4 +74,12 @@ public class ActionBarPainter { ...@@ -61,4 +74,12 @@ public class ActionBarPainter {
return accountActionBarColors[AccountManager.getInstance().getColorLevel(account)]; return accountActionBarColors[AccountManager.getInstance().getColorLevel(account)];
} }
public int getDefaultColor() {
String firstAccount = getFirstAccount();
if (firstAccount == null) {
return defaultSystemColor;
} else {
return accountActionBarColors[AccountManager.getInstance().getColorLevel(firstAccount)];
}
}
} }
package com.xabber.android.ui.helper; package com.xabber.android.ui.helper;
import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity; import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.TextView; import android.widget.TextView;
...@@ -11,21 +12,23 @@ import com.xabber.androiddev.R; ...@@ -11,21 +12,23 @@ import com.xabber.androiddev.R;
public class ContactTitleActionBarInflater { public class ContactTitleActionBarInflater {
private final ActionBarActivity activity; private final AppCompatActivity activity;
private final Toolbar toolbar;
private View actionBarView; private View actionBarView;
private BarPainter barPainter;
private ActionBarPainter actionBarPainter; public ContactTitleActionBarInflater(AppCompatActivity activity, Toolbar toolbar) {
public ContactTitleActionBarInflater(ActionBarActivity activity) {
this.activity = activity; this.activity = activity;
this.toolbar = toolbar;
} }
public void setUpActionBarView() { public void setUpActionBarView() {
actionBarPainter = new ActionBarPainter(activity); barPainter = new BarPainter(activity, toolbar);
activity.setSupportActionBar(toolbar);
ActionBar actionBar = activity.getSupportActionBar(); ActionBar actionBar = activity.getSupportActionBar();
actionBar.setDisplayShowHomeEnabled(false); actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true);
...@@ -37,7 +40,7 @@ public class ContactTitleActionBarInflater { ...@@ -37,7 +40,7 @@ public class ContactTitleActionBarInflater {
} }
public void update(AbstractContact abstractContact) { public void update(AbstractContact abstractContact) {
actionBarPainter.updateWithAccountName(abstractContact.getAccount()); barPainter.updateWithAccountName(abstractContact.getAccount());
activity.getSupportActionBar().setDisplayShowCustomEnabled(true); activity.getSupportActionBar().setDisplayShowCustomEnabled(true);
activity.getSupportActionBar().setDisplayShowTitleEnabled(false); activity.getSupportActionBar().setDisplayShowTitleEnabled(false);
......
...@@ -5,7 +5,7 @@ import android.content.res.Resources; ...@@ -5,7 +5,7 @@ import android.content.res.Resources;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.ColorDrawable;
import android.os.Build; import android.os.Build;
import android.support.v7.app.ActionBarActivity; import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.View; import android.view.View;
...@@ -13,7 +13,6 @@ import android.view.Window; ...@@ -13,7 +13,6 @@ import android.view.Window;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import com.github.ksoichiro.android.observablescrollview.ObservableListView;
import com.github.ksoichiro.android.observablescrollview.ObservableScrollView; import com.github.ksoichiro.android.observablescrollview.ObservableScrollView;
import com.github.ksoichiro.android.observablescrollview.ObservableScrollViewCallbacks; import com.github.ksoichiro.android.observablescrollview.ObservableScrollViewCallbacks;
import com.github.ksoichiro.android.observablescrollview.ScrollState; import com.github.ksoichiro.android.observablescrollview.ScrollState;
...@@ -28,7 +27,7 @@ import static java.lang.Math.sqrt; ...@@ -28,7 +27,7 @@ import static java.lang.Math.sqrt;
public class ContactTitleExpandableToolbarInflater implements ObservableScrollViewCallbacks { public class ContactTitleExpandableToolbarInflater implements ObservableScrollViewCallbacks {
private final ActionBarActivity activity; private final AppCompatActivity activity;
private View avatarView; private View avatarView;
private View titleView; private View titleView;
...@@ -44,7 +43,7 @@ public class ContactTitleExpandableToolbarInflater implements ObservableScrollVi ...@@ -44,7 +43,7 @@ public class ContactTitleExpandableToolbarInflater implements ObservableScrollVi
private int contactTitlePaddingBottomBig; private int contactTitlePaddingBottomBig;
private int contactTitlePaddingBottomSmall; private int contactTitlePaddingBottomSmall;
public ContactTitleExpandableToolbarInflater(ActionBarActivity activity) { public ContactTitleExpandableToolbarInflater(AppCompatActivity activity) {
this.activity = activity; this.activity = activity;
} }
......
...@@ -16,7 +16,7 @@ package com.xabber.android.ui.helper; ...@@ -16,7 +16,7 @@ package com.xabber.android.ui.helper;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.app.ActionBarActivity; import android.support.v7.app.AppCompatActivity;
import com.xabber.android.data.ActivityManager; import com.xabber.android.data.ActivityManager;
...@@ -27,7 +27,7 @@ import com.xabber.android.data.ActivityManager; ...@@ -27,7 +27,7 @@ import com.xabber.android.data.ActivityManager;
* *
* @author alexander.ivanov * @author alexander.ivanov
*/ */
public abstract class ManagedActivity extends ActionBarActivity { public abstract class ManagedActivity extends AppCompatActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
......
...@@ -25,16 +25,25 @@ import android.text.method.LinkMovementMethod; ...@@ -25,16 +25,25 @@ import android.text.method.LinkMovementMethod;
import android.view.MenuItem; import android.view.MenuItem;
import android.widget.TextView; import android.widget.TextView;
import com.xabber.android.ui.helper.BarPainter;
import com.xabber.android.ui.helper.ManagedActivity; import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
public class AboutViewer extends ManagedActivity { public class AboutViewer extends ManagedActivity {
public static Intent createIntent(Context context) {
return new Intent(context, AboutViewer.class);
}
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.about_viewer); setContentView(R.layout.about_viewer);
setSupportActionBar((Toolbar) findViewById(R.id.toolbar_default)); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_default);
setSupportActionBar(toolbar);
BarPainter barPainter = new BarPainter(this, toolbar);
barPainter.setDefaultColor();
((TextView) findViewById(R.id.about_version)) ((TextView) findViewById(R.id.about_version))
.setText(getString(R.string.about_version, getVersionName())); .setText(getString(R.string.about_version, getVersionName()));
...@@ -54,10 +63,6 @@ public class AboutViewer extends ManagedActivity { ...@@ -54,10 +63,6 @@ public class AboutViewer extends ManagedActivity {
return ""; return "";
} }
public static Intent createIntent(Context context) {
return new Intent(context, AboutViewer.class);
}
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
......
...@@ -27,24 +27,29 @@ import com.xabber.android.data.account.AccountManager; ...@@ -27,24 +27,29 @@ 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.BarPainter;
import com.xabber.android.ui.helper.ManagedActivity; import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
public class AccountEditor extends ManagedActivity implements public class AccountEditor extends ManagedActivity implements
OnPreferenceClickListener, AccountEditorFragment.AccountEditorFragmentInteractionListener { OnPreferenceClickListener, AccountEditorFragment.AccountEditorFragmentInteractionListener {
public static final String INVALIDATED_TOKEN = "com.xabber.android.ui.preferences.AccountEditor.INVALIDATED";
private static final int OAUTH_WML_REQUEST_CODE = 1; private static final int OAUTH_WML_REQUEST_CODE = 1;
private static final String SAVED_TOKEN = "com.xabber.android.ui.preferences.AccountEditor.TOKEN"; private static final String SAVED_TOKEN = "com.xabber.android.ui.preferences.AccountEditor.TOKEN";
public static final String INVALIDATED_TOKEN = "com.xabber.android.ui.preferences.AccountEditor.INVALIDATED";
private String account; private String account;
private AccountItem accountItem; private AccountItem accountItem;
private String token; private String token;
private ActionBarPainter actionBarPainter; private BarPainter barPainter;
private static String getAccount(Intent intent) {
return AccountIntentBuilder.getAccount(intent);
}
public static Intent createIntent(Context context, String account) {
return new AccountIntentBuilder(context, AccountEditor.class).setAccount(account).build();
}
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
...@@ -72,12 +77,13 @@ public class AccountEditor extends ManagedActivity implements ...@@ -72,12 +77,13 @@ public class AccountEditor extends ManagedActivity implements
} }
setContentView(R.layout.activity_preferences); setContentView(R.layout.activity_preferences);
setSupportActionBar((Toolbar) findViewById(R.id.toolbar_default)); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_default);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setTitle(AccountManager.getInstance().getVerboseName(account)); toolbar.setTitle(AccountManager.getInstance().getVerboseName(account));
actionBarPainter = new ActionBarPainter(this); barPainter = new BarPainter(this, toolbar);
actionBarPainter.updateWithAccountName(account); barPainter.updateWithAccountName(account);
} }
@Override @Override
...@@ -108,7 +114,6 @@ public class AccountEditor extends ManagedActivity implements ...@@ -108,7 +114,6 @@ public class AccountEditor extends ManagedActivity implements
} }
} }
@Override @Override
public boolean onPreferenceClick(Preference preference) { public boolean onPreferenceClick(Preference preference) {
if (getString(R.string.account_oauth_key).equals(preference.getKey())) { if (getString(R.string.account_oauth_key).equals(preference.getKey())) {
...@@ -119,14 +124,6 @@ public class AccountEditor extends ManagedActivity implements ...@@ -119,14 +124,6 @@ public class AccountEditor extends ManagedActivity implements
return false; return false;
} }
private static String getAccount(Intent intent) {
return AccountIntentBuilder.getAccount(intent);
}
public static Intent createIntent(Context context, String account) {
return new AccountIntentBuilder(context, AccountEditor.class).setAccount(account).build();
}
@Override @Override
public String getAccount() { public String getAccount() {
return account; return account;
...@@ -155,6 +152,6 @@ public class AccountEditor extends ManagedActivity implements ...@@ -155,6 +152,6 @@ public class AccountEditor extends ManagedActivity implements
@Override @Override
public void onColorChange(String colorName) { public void onColorChange(String colorName) {
actionBarPainter.updateWithColorName(colorName); barPainter.updateWithColorName(colorName);
} }
} }
...@@ -14,8 +14,6 @@ ...@@ -14,8 +14,6 @@
*/ */
package com.xabber.android.ui.preferences; package com.xabber.android.ui.preferences;
import java.util.Collection;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
...@@ -34,12 +32,17 @@ import com.xabber.android.ui.adapter.BaseListEditorAdapter; ...@@ -34,12 +32,17 @@ import com.xabber.android.ui.adapter.BaseListEditorAdapter;
import com.xabber.android.ui.helper.PreferenceSummaryHelper; import com.xabber.android.ui.helper.PreferenceSummaryHelper;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
public class AccountList extends BaseListEditor<String> implements import java.util.Collection;
OnAccountChangedListener {
public class AccountList extends BaseListEditor<String> implements OnAccountChangedListener {
private static final int CONTEXT_MENU_VIEW_ACCOUNT_ID = 0x20; private static final int CONTEXT_MENU_VIEW_ACCOUNT_ID = 0x20;
private static final int CONTEXT_MENU_STATUS_EDITOR_ID = 0x30; private static final int CONTEXT_MENU_STATUS_EDITOR_ID = 0x30;
public static Intent createIntent(Context context) {
return new Intent(context, AccountList.class);
}
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
...@@ -76,8 +79,7 @@ public class AccountList extends BaseListEditor<String> implements ...@@ -76,8 +79,7 @@ public class AccountList extends BaseListEditor<String> implements
@Override @Override
protected String getRemoveConfirmation(String actionWith) { protected String getRemoveConfirmation(String actionWith) {
return getString(R.string.account_delete_confirm, AccountManager return getString(R.string.account_delete_confirm, AccountManager.getInstance().getVerboseName(actionWith));
.getInstance().getVerboseName(actionWith));
} }
@Override @Override
...@@ -93,29 +95,24 @@ public class AccountList extends BaseListEditor<String> implements ...@@ -93,29 +95,24 @@ public class AccountList extends BaseListEditor<String> implements
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
Application.getInstance().addUIListener(OnAccountChangedListener.class, Application.getInstance().addUIListener(OnAccountChangedListener.class, this);
this);
} }
@Override @Override
protected void onPause() { protected void onPause() {
super.onPause(); super.onPause();
Application.getInstance().removeUIListener( Application.getInstance().removeUIListener(OnAccountChangedListener.class, this);
OnAccountChangedListener.class, this);
} }
@Override @Override
protected void onCreateContextMenu(ContextMenu menu, String actionWith) { protected void onCreateContextMenu(ContextMenu menu, String actionWith) {
final AccountItem accountItem = AccountManager.getInstance() final AccountItem accountItem = AccountManager.getInstance().getAccount(actionWith);
.getAccount(actionWith); menu.setHeaderTitle(AccountManager.getInstance().getVerboseName(actionWith));
menu.setHeaderTitle(AccountManager.getInstance().getVerboseName(
actionWith));
if (accountItem.isEnabled()) { if (accountItem.isEnabled()) {
menu.add(0, CONTEXT_MENU_STATUS_EDITOR_ID, 0, getResources() menu.add(0, CONTEXT_MENU_STATUS_EDITOR_ID, 0, getResources()
.getText(R.string.status_editor)); .getText(R.string.status_editor));
} }
menu.add(0, CONTEXT_MENU_VIEW_ACCOUNT_ID, 0, menu.add(0, CONTEXT_MENU_VIEW_ACCOUNT_ID, 0, getString(R.string.account_editor));
getString(R.string.account_editor));
super.onCreateContextMenu(menu, actionWith); super.onCreateContextMenu(menu, actionWith);
} }
...@@ -148,8 +145,4 @@ public class AccountList extends BaseListEditor<String> implements ...@@ -148,8 +145,4 @@ public class AccountList extends BaseListEditor<String> implements
bundle.putString(key, actionWith); bundle.putString(key, actionWith);
} }
public static Intent createIntent(Context context) {
return new Intent(context, AccountList.class);
}
} }
...@@ -31,6 +31,7 @@ import com.xabber.android.ui.adapter.BaseListEditorAdapter; ...@@ -31,6 +31,7 @@ import com.xabber.android.ui.adapter.BaseListEditorAdapter;
import com.xabber.android.ui.dialog.ConfirmDialogBuilder; import com.xabber.android.ui.dialog.ConfirmDialogBuilder;
import com.xabber.android.ui.dialog.ConfirmDialogListener; import com.xabber.android.ui.dialog.ConfirmDialogListener;
import com.xabber.android.ui.dialog.DialogBuilder; import com.xabber.android.ui.dialog.DialogBuilder;
import com.xabber.android.ui.helper.BarPainter;
import com.xabber.android.ui.helper.ManagedListActivity; import com.xabber.android.ui.helper.ManagedListActivity;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
...@@ -47,10 +48,9 @@ public abstract class BaseListEditor<T> extends ManagedListActivity implements ...@@ -47,10 +48,9 @@ public abstract class BaseListEditor<T> extends ManagedListActivity implements
private static final int CONTEXT_MENU_DELETE_ID = 0x10; private static final int CONTEXT_MENU_DELETE_ID = 0x10;
private static final int DIALOG_DELETE_ID = 0x100; private static final int DIALOG_DELETE_ID = 0x100;
private T actionWith;
protected BaseListEditorAdapter<T> adapter; protected BaseListEditorAdapter<T> adapter;
private T actionWith;
private BarPainter barPainter;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
...@@ -76,7 +76,12 @@ public abstract class BaseListEditor<T> extends ManagedListActivity implements ...@@ -76,7 +76,12 @@ public abstract class BaseListEditor<T> extends ManagedListActivity implements
*/ */
protected void onInflate(Bundle savedInstanceState) { protected void onInflate(Bundle savedInstanceState) {
setContentView(R.layout.list); setContentView(R.layout.list);
setSupportActionBar((Toolbar) findViewById(R.id.toolbar_default));
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_default);
setSupportActionBar(toolbar);
barPainter = new BarPainter(this, toolbar);
} }
protected abstract T getSavedValue(Bundle bundle, String key); protected abstract T getSavedValue(Bundle bundle, String key);
...@@ -108,6 +113,7 @@ public abstract class BaseListEditor<T> extends ManagedListActivity implements ...@@ -108,6 +113,7 @@ public abstract class BaseListEditor<T> extends ManagedListActivity implements
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
adapter.onChange(); adapter.onChange();
barPainter.setDefaultColor();
} }
@Override @Override
......
...@@ -5,6 +5,7 @@ import android.os.Bundle; ...@@ -5,6 +5,7 @@ import android.os.Bundle;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import com.xabber.android.data.message.phrase.Phrase; import com.xabber.android.data.message.phrase.Phrase;
import com.xabber.android.ui.helper.BarPainter;
import com.xabber.android.ui.helper.ManagedActivity; import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
...@@ -18,9 +19,15 @@ public abstract class BasePhrasePreferences extends ManagedActivity ...@@ -18,9 +19,15 @@ public abstract class BasePhrasePreferences extends ManagedActivity
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_preferences); setContentView(R.layout.activity_preferences);
setSupportActionBar((Toolbar) findViewById(R.id.toolbar_default));
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_default);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
BarPainter barPainter = new BarPainter(this, toolbar);
barPainter.setDefaultColor();
if (savedInstanceState == null) { if (savedInstanceState == null) {
getFragmentManager().beginTransaction() getFragmentManager().beginTransaction()
.add(R.id.preferences_activity_container, new PhraseEditorFragment()).commit(); .add(R.id.preferences_activity_container, new PhraseEditorFragment()).commit();
......
...@@ -23,7 +23,7 @@ import com.xabber.android.data.Application; ...@@ -23,7 +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.BarPainter;
import com.xabber.android.ui.helper.ManagedActivity; import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
...@@ -34,6 +34,20 @@ public class ChatEditor extends ManagedActivity ...@@ -34,6 +34,20 @@ public class ChatEditor extends ManagedActivity
private String user; private String user;
private AccountItem accountItem; private AccountItem accountItem;
public static Intent createIntent(Context context, String account,
String user) {
return new EntityIntentBuilder(context, ChatEditor.class)
.setAccount(account).setUser(user).build();
}
private static String getAccount(Intent intent) {
return EntityIntentBuilder.getAccount(intent);
}
private static String getUser(Intent intent) {
return EntityIntentBuilder.getUser(intent);
}
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
...@@ -49,11 +63,12 @@ public class ChatEditor extends ManagedActivity ...@@ -49,11 +63,12 @@ public class ChatEditor extends ManagedActivity
} }
setContentView(R.layout.activity_preferences); setContentView(R.layout.activity_preferences);
setSupportActionBar((Toolbar) findViewById(R.id.toolbar_default)); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_default);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ActionBarPainter actionBarPainter = new ActionBarPainter(this); BarPainter barPainter = new BarPainter(this, toolbar);
actionBarPainter.updateWithAccountName(account); barPainter.updateWithAccountName(account);
if (savedInstanceState == null) { if (savedInstanceState == null) {
getFragmentManager().beginTransaction() getFragmentManager().beginTransaction()
...@@ -61,20 +76,6 @@ public class ChatEditor extends ManagedActivity ...@@ -61,20 +76,6 @@ public class ChatEditor extends ManagedActivity
} }
} }
public static Intent createIntent(Context context, String account,
String user) {
return new EntityIntentBuilder(context, ChatEditor.class)
.setAccount(account).setUser(user).build();
}
private static String getAccount(Intent intent) {
return EntityIntentBuilder.getAccount(intent);
}
private static String getUser(Intent intent) {
return EntityIntentBuilder.getUser(intent);
}
@Override @Override
public String getAccount() { public String getAccount() {
return account; return account;
......
...@@ -3,6 +3,7 @@ package com.xabber.android.ui.preferences; ...@@ -3,6 +3,7 @@ package com.xabber.android.ui.preferences;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import com.xabber.android.ui.helper.BarPainter;
import com.xabber.android.ui.helper.ManagedActivity; import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.android.ui.helper.PreferenceSummaryHelper; import com.xabber.android.ui.helper.PreferenceSummaryHelper;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
...@@ -16,7 +17,13 @@ public class ChatSettings extends ManagedActivity { ...@@ -16,7 +17,13 @@ public class ChatSettings extends ManagedActivity {
return; return;
setContentView(R.layout.activity_preferences); setContentView(R.layout.activity_preferences);
setSupportActionBar((Toolbar) findViewById(R.id.toolbar_default));
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_default);
setSupportActionBar(toolbar);
BarPainter barPainter = new BarPainter(this, toolbar);
barPainter.setDefaultColor();
setTitle(PreferenceSummaryHelper.getPreferenceTitle(getString(R.string.chat_viewer))); setTitle(PreferenceSummaryHelper.getPreferenceTitle(getString(R.string.chat_viewer)));
......
...@@ -3,6 +3,7 @@ package com.xabber.android.ui.preferences; ...@@ -3,6 +3,7 @@ package com.xabber.android.ui.preferences;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import com.xabber.android.ui.helper.BarPainter;
import com.xabber.android.ui.helper.ManagedActivity; import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.android.ui.helper.PreferenceSummaryHelper; import com.xabber.android.ui.helper.PreferenceSummaryHelper;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
...@@ -16,7 +17,13 @@ public class ConnectionSettings extends ManagedActivity { ...@@ -16,7 +17,13 @@ public class ConnectionSettings extends ManagedActivity {
return; return;
setContentView(R.layout.activity_preferences); setContentView(R.layout.activity_preferences);
setSupportActionBar((Toolbar) findViewById(R.id.toolbar_default));
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_default);
setSupportActionBar(toolbar);
BarPainter barPainter = new BarPainter(this, toolbar);
barPainter.setDefaultColor();
setTitle(PreferenceSummaryHelper.getPreferenceTitle(getString(R.string.preference_connection))); setTitle(PreferenceSummaryHelper.getPreferenceTitle(getString(R.string.preference_connection)));
......
...@@ -3,6 +3,7 @@ package com.xabber.android.ui.preferences; ...@@ -3,6 +3,7 @@ package com.xabber.android.ui.preferences;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import com.xabber.android.ui.helper.BarPainter;
import com.xabber.android.ui.helper.ManagedActivity; import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.android.ui.helper.PreferenceSummaryHelper; import com.xabber.android.ui.helper.PreferenceSummaryHelper;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
...@@ -15,8 +16,14 @@ public class ContactListSettings extends ManagedActivity { ...@@ -15,8 +16,14 @@ public class ContactListSettings extends ManagedActivity {
return; return;
setContentView(R.layout.activity_preferences); setContentView(R.layout.activity_preferences);
setSupportActionBar((Toolbar) findViewById(R.id.toolbar_default));
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_default);
setSupportActionBar(toolbar);
BarPainter barPainter = new BarPainter(this, toolbar);
barPainter.setDefaultColor();
setTitle(PreferenceSummaryHelper.getPreferenceTitle(getString(R.string.preference_contacts))); setTitle(PreferenceSummaryHelper.getPreferenceTitle(getString(R.string.preference_contacts)));
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
......
...@@ -3,6 +3,7 @@ package com.xabber.android.ui.preferences; ...@@ -3,6 +3,7 @@ package com.xabber.android.ui.preferences;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import com.xabber.android.ui.helper.BarPainter;
import com.xabber.android.ui.helper.ManagedActivity; import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.android.ui.helper.PreferenceSummaryHelper; import com.xabber.android.ui.helper.PreferenceSummaryHelper;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
...@@ -16,7 +17,13 @@ public class DebugSettings extends ManagedActivity { ...@@ -16,7 +17,13 @@ public class DebugSettings extends ManagedActivity {
return; return;
setContentView(R.layout.activity_preferences); setContentView(R.layout.activity_preferences);
setSupportActionBar((Toolbar) findViewById(R.id.toolbar_default));
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_default);
setSupportActionBar(toolbar);
BarPainter barPainter = new BarPainter(this, toolbar);
barPainter.setDefaultColor();
setTitle(PreferenceSummaryHelper.getPreferenceTitle(getString(R.string.preference_debug))); setTitle(PreferenceSummaryHelper.getPreferenceTitle(getString(R.string.preference_debug)));
......
...@@ -4,6 +4,7 @@ package com.xabber.android.ui.preferences; ...@@ -4,6 +4,7 @@ package com.xabber.android.ui.preferences;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import com.xabber.android.ui.helper.BarPainter;
import com.xabber.android.ui.helper.ManagedActivity; import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.android.ui.helper.PreferenceSummaryHelper; import com.xabber.android.ui.helper.PreferenceSummaryHelper;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
...@@ -17,7 +18,13 @@ public class NotificationsSettings extends ManagedActivity { ...@@ -17,7 +18,13 @@ public class NotificationsSettings extends ManagedActivity {
return; return;
setContentView(R.layout.activity_preferences); setContentView(R.layout.activity_preferences);
setSupportActionBar((Toolbar) findViewById(R.id.toolbar_default));
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_default);
setSupportActionBar(toolbar);
BarPainter barPainter = new BarPainter(this, toolbar);
barPainter.setDefaultColor();
setTitle(PreferenceSummaryHelper.getPreferenceTitle(getString(R.string.preference_events))); setTitle(PreferenceSummaryHelper.getPreferenceTitle(getString(R.string.preference_events)));
......
...@@ -21,12 +21,19 @@ import android.os.Bundle; ...@@ -21,12 +21,19 @@ import android.os.Bundle;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import com.xabber.android.data.SettingsManager; import com.xabber.android.data.SettingsManager;
import com.xabber.android.ui.helper.BarPainter;
import com.xabber.android.ui.helper.ManagedActivity; import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
public class PreferenceEditor extends ManagedActivity public class PreferenceEditor extends ManagedActivity
implements PreferencesFragment.OnPreferencesFragmentInteractionListener { implements PreferencesFragment.OnPreferencesFragmentInteractionListener {
private BarPainter barPainter;
public static Intent createIntent(Context context) {
return new Intent(context, PreferenceEditor.class);
}
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
...@@ -34,7 +41,10 @@ public class PreferenceEditor extends ManagedActivity ...@@ -34,7 +41,10 @@ public class PreferenceEditor extends ManagedActivity
return; return;
setContentView(R.layout.activity_preferences); setContentView(R.layout.activity_preferences);
setSupportActionBar((Toolbar) findViewById(R.id.toolbar_default)); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_default);
setSupportActionBar(toolbar);
barPainter = new BarPainter(this, toolbar);
if (savedInstanceState == null) { if (savedInstanceState == null) {
getFragmentManager().beginTransaction() getFragmentManager().beginTransaction()
...@@ -48,8 +58,10 @@ public class PreferenceEditor extends ManagedActivity ...@@ -48,8 +58,10 @@ public class PreferenceEditor extends ManagedActivity
SettingsManager.chatsAttentionSound(); SettingsManager.chatsAttentionSound();
} }
public static Intent createIntent(Context context) { @Override
return new Intent(context, PreferenceEditor.class); protected void onResume() {
super.onResume();
barPainter.setDefaultColor();
} }
@Override @Override
......
...@@ -3,6 +3,7 @@ package com.xabber.android.ui.preferences; ...@@ -3,6 +3,7 @@ package com.xabber.android.ui.preferences;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import com.xabber.android.ui.helper.BarPainter;
import com.xabber.android.ui.helper.ManagedActivity; import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.android.ui.helper.PreferenceSummaryHelper; import com.xabber.android.ui.helper.PreferenceSummaryHelper;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
...@@ -16,7 +17,13 @@ public class SecuritySettings extends ManagedActivity { ...@@ -16,7 +17,13 @@ public class SecuritySettings extends ManagedActivity {
return; return;
setContentView(R.layout.activity_preferences); setContentView(R.layout.activity_preferences);
setSupportActionBar((Toolbar) findViewById(R.id.toolbar_default));
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_default);
setSupportActionBar(toolbar);
BarPainter barPainter = new BarPainter(this, toolbar);
barPainter.setDefaultColor();
setTitle(PreferenceSummaryHelper.getPreferenceTitle(getString(R.string.preference_security))); setTitle(PreferenceSummaryHelper.getPreferenceTitle(getString(R.string.preference_security)));
......
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