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;
import android.view.MenuItem;
import com.xabber.android.data.intent.AccountIntentBuilder;
import com.xabber.android.ui.helper.BarPainter;
import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.androiddev.R;
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
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -40,10 +49,15 @@ public class AccountAdd extends ManagedActivity {
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().setHomeAsUpIndicator(R.drawable.ic_clear_white_24dp);
getSupportActionBar().setTitle(null);
BarPainter barPainter = new BarPainter(this, toolbar);
barPainter.setDefaultColor();
}
@Override
......@@ -67,12 +81,4 @@ public class AccountAdd extends ManagedActivity {
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;
import com.xabber.android.data.roster.OnContactChangedListener;
import com.xabber.android.ui.adapter.ChatScrollIndicatorAdapter;
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.StatusBarPainter;
import com.xabber.androiddev.R;
......@@ -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_EXIT_ON_SEND = "com.xabber.android.ui.ChatViewer.EXIT_ON_SEND";
private boolean exitOnSend;
private String extraText = null;
ChatScrollIndicatorAdapter chatScrollIndicatorAdapter;
ChatViewerAdapter chatViewerAdapter;
ViewPager viewPager;
Collection<ChatViewerFragment> registeredChats = new HashSet<>();
Collection<RecentChatFragment> recentChatFragments = new HashSet<>();
private boolean exitOnSend;
private String extraText = null;
private BaseEntity initialChat = null;
private BaseEntity selectedChat = null;
......@@ -92,6 +86,78 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
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
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -318,11 +384,13 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
}
private void updateStatusBar() {
String account;
if (isRecentChatsSelected) {
statusBarPainter.restore();
account = BarPainter.getFirstAccount();
} else {
statusBarPainter.updateWithAccountName(selectedChat.getAccount());
account = selectedChat.getAccount();
}
statusBarPainter.updateWithAccountName(account);
}
private void updateRegisteredChats() {
......@@ -349,7 +417,6 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
recentChatFragments.remove(recentChatFragment);
}
@Override
public void onChatViewAdapterFinishUpdate() {
insertExtraText();
......@@ -380,19 +447,11 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
public void onChatSelected(AbstractChat chat) {
selectChatPage(chat, true);
}
public ChatViewerAdapter getChatViewerAdapter() {
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
public void onCloseChat() {
close();
......@@ -415,7 +474,6 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
registeredChats.remove(chat);
}
private void close() {
finish();
if (!Intent.ACTION_SEND.equals(getIntent().getAction())) {
......@@ -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;
import android.content.Context;
import android.os.Bundle;
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.RecyclerView;
import android.support.v7.widget.Toolbar;
......@@ -50,7 +50,7 @@ import com.xabber.android.data.roster.AbstractContact;
import com.xabber.android.data.roster.RosterManager;
import com.xabber.android.ui.adapter.ChatMessageAdapter;
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.preferences.ChatEditor;
import com.xabber.androiddev.R;
......@@ -62,17 +62,12 @@ public class ChatViewerFragment extends Fragment implements PopupMenu.OnMenuItem
public static final String ARGUMENT_USER = "ARGUMENT_USER";
private static final int MINIMUM_MESSAGES_TO_LOAD = 10;
boolean isInputEmpty = true;
private EditText inputView;
private ChatMessageAdapter chatMessageAdapter;
private boolean skipOnTextChanges;
private String account;
private String user;
boolean isInputEmpty = true;
private ImageButton sendButton;
private ImageButton securityButton;
private Toolbar toolbar;
......@@ -127,10 +122,7 @@ public class ChatViewerFragment extends Fragment implements PopupMenu.OnMenuItem
abstractContact = RosterManager.getInstance().getBestContact(account, user);
contactTitleView.findViewById(R.id.avatar).setOnClickListener(this);
ActionBarPainter actionBarPainter = new ActionBarPainter((ActionBarActivity) getActivity());
toolbar = (Toolbar) view.findViewById(R.id.toolbar_default);
toolbar.setBackgroundColor(actionBarPainter.getAccountColor(account));
toolbar.inflateMenu(R.menu.chat);
toolbar.setOnMenuItemClickListener(this);
toolbar.setNavigationIcon(R.drawable.ic_arrow_left_white_24dp);
......@@ -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.setImageResource(R.drawable.ic_button_send_inactive_24dp);
......@@ -613,17 +608,20 @@ public class ChatViewerFragment extends Fragment implements PopupMenu.OnMenuItem
unregisterForContextMenu(caller);
}
public interface ChatViewerFragmentListener {
void onCloseChat();
void onMessageSent();
void registerChat(ChatViewerFragment chat);
void unregisterChat(ChatViewerFragment chat);
}
public void playIncomingAnimation() {
if (shakeAnimation == null) {
shakeAnimation = AnimationUtils.loadAnimation(getActivity(), R.anim.shake);
}
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;
import android.view.MenuItem;
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.androiddev.R;
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
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.contact_add);
setSupportActionBar((Toolbar) findViewById(R.id.toolbar_default));
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_clear_white_24dp);
getSupportActionBar().setTitle(null);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_default);
toolbar.setNavigationIcon(R.drawable.ic_clear_white_24dp);
setTitle(null);
barPainter = new BarPainter(this, toolbar);
barPainter.setDefaultColor();
setSupportActionBar(toolbar);
actionBarPainter = new ActionBarPainter(this);
Intent intent = getIntent();
......@@ -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
public void onAccountSelected(String account) {
actionBarPainter.updateWithAccountName(account);
barPainter.updateWithAccountName(account);
}
}
......@@ -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.ContactIntegrationDialogFragment;
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.preferences.PreferenceEditor;
import com.xabber.androiddev.R;
......@@ -100,6 +101,34 @@ public class ContactList extends ManagedActivity implements OnAccountChangedList
private String sendText;
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
public void onCreate(Bundle savedInstanceState) {
......@@ -117,10 +146,12 @@ public class ContactList extends ManagedActivity implements OnAccountChangedList
setContentView(R.layout.contact_list);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_default);
toolbar.setLogo(R.drawable.ic_xabber_logo);
toolbar.setOnClickListener(this);
setSupportActionBar(toolbar);
barPainter = new BarPainter(this, toolbar);
barPainter.setDefaultColor();
setTitle(getString(R.string.production_title));
if (savedInstanceState != null) {
......@@ -214,6 +245,7 @@ public class ContactList extends ManagedActivity implements OnAccountChangedList
@Override
protected void onResume() {
super.onResume();
barPainter.setDefaultColor();
rebuildAccountToggle();
Application.getInstance().addUIListener(OnAccountChangedListener.class, this);
......@@ -500,6 +532,7 @@ public class ContactList extends ManagedActivity implements OnAccountChangedList
@Override
public void onAccountsChanged(Collection<String> accounts) {
((ContactListFragment)getSupportFragmentManager().findFragmentById(R.id.container)).onAccountsChanged();
barPainter.setDefaultColor();
}
@Override
......@@ -511,31 +544,4 @@ public class ContactList extends ManagedActivity implements OnAccountChangedList
((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;
import com.xabber.android.data.roster.PresenceManager;
import com.xabber.android.data.roster.RosterManager;
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.androiddev.R;
import org.w3c.dom.Text;
public class ContactSubscription extends SingleActivity implements View.OnClickListener {
private String account;
private String user;
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
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -61,14 +73,14 @@ public class ContactSubscription extends SingleActivity implements View.OnClickL
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle(getString(R.string.subscription_request_message));
toolbar.setTitle(getString(R.string.subscription_request_message));
ActionBarPainter actionBarPainter = new ActionBarPainter(this);
actionBarPainter.updateWithAccountName(account);
BarPainter barPainter = new BarPainter(this, toolbar);
barPainter.updateWithAccountName(account);
View fakeToolbar = findViewById(R.id.fake_toolbar);
fakeToolbar.setBackgroundColor(actionBarPainter.getAccountColor(account));
fakeToolbar.setBackgroundColor(barPainter.getAccountColor(account));
toolbar.setBackgroundResource(android.R.color.transparent);
AbstractContact abstractContact = RosterManager.getInstance().getBestContact(account, user);
......@@ -78,7 +90,7 @@ public class ContactSubscription extends SingleActivity implements View.OnClickL
((TextView)fakeToolbar.findViewById(R.id.dialog_message)).setText(subscriptionRequest.getConfirmation());
Button acceptButton = (Button) findViewById(R.id.accept_button);
acceptButton.setTextColor(actionBarPainter.getAccountColor(account));
acceptButton.setTextColor(barPainter.getAccountColor(account));
acceptButton.setOnClickListener(this);
findViewById(R.id.decline_button).setOnClickListener(this);
......@@ -128,18 +140,4 @@ public class ContactSubscription extends SingleActivity implements View.OnClickL
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
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";
ContactTitleActionBarInflater contactTitleActionBarInflater;
private String account;
private String user;
private String remoteFingerprint;
private String localFingerprint;
/**
* UI update is in progress.
*/
private boolean isUpdating;
private CheckBox verifiedView;
private View scanView;
private View showView;
private View copyView;
/**
* QR code scanner and generator.
*/
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
protected void onCreate(Bundle savedInstanceState) {
......@@ -93,7 +101,6 @@ public class FingerprintViewer extends ManagedActivity implements
}
setContentView(R.layout.fingerprint_viewer);
setSupportActionBar((Toolbar) findViewById(R.id.toolbar_default));
integrator = new IntentIntegrator(this);
Intent intent = getIntent();
......@@ -121,7 +128,7 @@ public class FingerprintViewer extends ManagedActivity implements
copyView.setOnClickListener(this);
isUpdating = false;
contactTitleActionBarInflater = new ContactTitleActionBarInflater(this);
contactTitleActionBarInflater = new ContactTitleActionBarInflater(this, (Toolbar) findViewById(R.id.toolbar_default));
contactTitleActionBarInflater.setUpActionBarView();
}
......@@ -298,17 +305,4 @@ public class FingerprintViewer extends ManagedActivity implements
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;
public class GroupEditor extends ManagedActivity implements OnContactChangedListener,
OnAccountChangedListener {
ContactTitleActionBarInflater contactTitleActionBarInflater;
private String account;
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) {
super.onCreate(savedInstanceState);
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();
Intent intent = getIntent();
......@@ -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;
import com.xabber.android.data.message.MessageManager;
import com.xabber.android.data.notification.NotificationManager;
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.androiddev.R;
......@@ -67,7 +67,24 @@ public class MUCEditor extends ManagedActivity implements OnItemSelectedListener
private EditText nickView;
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
protected void onCreate(Bundle savedInstanceState) {
......@@ -77,11 +94,15 @@ public class MUCEditor extends ManagedActivity implements OnItemSelectedListener
}
setContentView(R.layout.muc_editor);
setSupportActionBar((Toolbar) findViewById(R.id.toolbar_default));
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_clear_white_24dp);
getSupportActionBar().setTitle(null);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_default);
toolbar.setNavigationIcon(R.drawable.ic_clear_white_24dp);
setTitle(null);
setSupportActionBar(toolbar);
barPainter = new BarPainter(this, toolbar);
barPainter.setDefaultColor();
accountView = (Spinner) findViewById(R.id.contact_account);
serverView = (EditText) findViewById(R.id.muc_server);
......@@ -126,10 +147,8 @@ public class MUCEditor extends ManagedActivity implements OnItemSelectedListener
}
}
actionBarPainter = new ActionBarPainter(this);
if (account != null) {
actionBarPainter.updateWithAccountName(account);
barPainter.updateWithAccountName(account);
for (int position = 0; position < accountView.getCount(); position++) {
if (account.equals(accountView.getItemAtPosition(position))) {
......@@ -244,28 +263,11 @@ public class MUCEditor extends ManagedActivity implements OnItemSelectedListener
}
selectedAccount = accountView.getSelectedItemPosition();
actionBarPainter.updateWithAccountName((String) accountView.getSelectedItem());
barPainter.updateWithAccountName((String) accountView.getSelectedItem());
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
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
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_CANCEL = "com.xabber.android.data.ui.QuestionViewer.CANCEL";
ContactTitleActionBarInflater contactTitleActionBarInflater;
private String account;
private String user;
private boolean showQuestion;
private boolean answerRequest;
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
protected void onCreate(Bundle savedInstanceState) {
......@@ -89,7 +128,6 @@ public class QuestionViewer extends ManagedActivity implements
answerRequest = intent.getBooleanExtra(EXTRA_FIELD_ANSWER_REQUEST, false);
if (showQuestion) {
setContentView(R.layout.question_viewer);
setSupportActionBar((Toolbar) findViewById(R.id.toolbar_default));
questionView = (EditText) findViewById(R.id.question);
questionView.setEnabled(!answerRequest);
if (answerRequest) {
......@@ -99,12 +137,12 @@ public class QuestionViewer extends ManagedActivity implements
}
} else {
setContentView(R.layout.secret_viewer);
setSupportActionBar((Toolbar) findViewById(R.id.toolbar_default));
}
findViewById(R.id.cancel).setOnClickListener(this);
findViewById(R.id.send).setOnClickListener(this);
contactTitleActionBarInflater = new ContactTitleActionBarInflater(this);
contactTitleActionBarInflater = new ContactTitleActionBarInflater(this, (Toolbar) findViewById(R.id.toolbar_default));
contactTitleActionBarInflater.setUpActionBarView();
}
......@@ -175,45 +213,4 @@ public class QuestionViewer extends ManagedActivity implements
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;
import android.app.ListFragment;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.MenuItem;
......@@ -14,6 +15,7 @@ import android.widget.Toast;
import com.xabber.android.data.message.AbstractChat;
import com.xabber.android.ui.adapter.ChatListAdapter;
import com.xabber.android.ui.helper.BarPainter;
import com.xabber.androiddev.R;
import java.util.ArrayList;
......@@ -22,10 +24,6 @@ import java.util.List;
public class RecentChatFragment extends ListFragment implements Toolbar.OnMenuItemClickListener {
private RecentChatFragmentInteractionListener listener;
public static RecentChatFragment newInstance() {
return new RecentChatFragment();
}
/**
* Mandatory empty constructor for the fragment manager to instantiate the
* fragment (e.g. upon screen orientation changes).
......@@ -33,6 +31,10 @@ public class RecentChatFragment extends ListFragment implements Toolbar.OnMenuIt
public RecentChatFragment() {
}
public static RecentChatFragment newInstance() {
return new RecentChatFragment();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -79,6 +81,9 @@ public class RecentChatFragment extends ListFragment implements Toolbar.OnMenuIt
toolbar.inflateMenu(R.menu.recent_chats);
toolbar.setOnMenuItemClickListener(this);
BarPainter barPainter = new BarPainter((AppCompatActivity) getActivity(), toolbar);
toolbar.setBackgroundColor(barPainter.getDefaultColor());
return rootView;
}
......@@ -121,11 +126,11 @@ public class RecentChatFragment extends ListFragment implements Toolbar.OnMenuIt
return false;
}
public interface RecentChatFragmentInteractionListener {
void onChatSelected(AbstractChat chat);
}
public void updateChats(List<AbstractChat> chats) {
((ChatListAdapter) getListAdapter()).updateChats(chats);
}
public interface RecentChatFragmentInteractionListener {
void onChatSelected(AbstractChat chat);
}
}
......@@ -41,7 +41,7 @@ import com.xabber.android.data.account.StatusMode;
import com.xabber.android.data.intent.AccountIntentBuilder;
import com.xabber.android.ui.adapter.StatusEditorAdapter;
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.androiddev.R;
......@@ -58,6 +58,18 @@ public class StatusEditor extends ManagedListActivity implements OnItemClickList
private StatusEditorAdapter adapter;
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
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -68,17 +80,21 @@ public class StatusEditor extends ManagedListActivity implements OnItemClickList
actionWithItem = null;
setContentView(R.layout.status_editor);
setSupportActionBar((Toolbar) findViewById(R.id.top_toolbar));
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_clear_white_24dp);
getSupportActionBar().setTitle(null);
Toolbar toolbar = (Toolbar) findViewById(R.id.top_toolbar);
toolbar.setNavigationIcon(R.drawable.ic_clear_white_24dp);
setTitle(null);
setSupportActionBar(toolbar);
Intent intent = getIntent();
account = StatusEditor.getAccount(intent);
BarPainter barPainter = new BarPainter(this, toolbar);
if (account != null) {
ActionBarPainter actionBarPainter = new ActionBarPainter(this);
actionBarPainter.updateWithAccountName(account);
barPainter.updateWithAccountName(account);
} else {
barPainter.setDefaultColor();
}
ListView listView = getListView();
......@@ -233,18 +249,6 @@ public class StatusEditor extends ManagedListActivity implements OnItemClickList
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
public boolean onMenuItemClick(MenuItem menuItem) {
return onOptionsItemSelected(menuItem);
......
package com.xabber.android.ui.helper;
import android.content.res.TypedArray;
import android.graphics.drawable.ColorDrawable;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import com.xabber.android.data.account.AccountManager;
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 ColorDrawable defaultActionBarBackground;
private final ActionBarActivity activity;
private StatusBarPainter statusBarPainter;
public ActionBarPainter(ActionBarActivity activity) {
this.activity = activity;
public BarPainter(AppCompatActivity activity, Toolbar toolbar) {
this.toolbar = toolbar;
statusBarPainter = new StatusBarPainter(activity);
accountActionBarColors = activity.getResources().getIntArray(R.array.account_action_bar);
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);
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) {
......@@ -39,13 +47,18 @@ public class ActionBarPainter {
}
public void updateWithColorLevel(int colorLevel) {
activity.getSupportActionBar().setBackgroundDrawable(new ColorDrawable(accountActionBarColors[colorLevel]));
toolbar.setBackgroundColor(accountActionBarColors[colorLevel]);
statusBarPainter.updateWithColorLevel(colorLevel);
}
public void restore() {
activity.getSupportActionBar().setBackgroundDrawable(defaultActionBarBackground);
statusBarPainter.restore();
public void setDefaultColor() {
String firstAccount = getFirstAccount();
if (firstAccount == null) {
toolbar.setBackgroundColor(defaultSystemColor);
statusBarPainter.restore();
} else {
updateWithAccountName(firstAccount);
}
}
public void updateWithColorName(String targetColorName) {
......@@ -61,4 +74,12 @@ public class ActionBarPainter {
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;
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.View;
import android.widget.TextView;
......@@ -11,21 +12,23 @@ import com.xabber.androiddev.R;
public class ContactTitleActionBarInflater {
private final ActionBarActivity activity;
private final AppCompatActivity activity;
private final Toolbar toolbar;
private View actionBarView;
private BarPainter barPainter;
private ActionBarPainter actionBarPainter;
public ContactTitleActionBarInflater(ActionBarActivity activity) {
public ContactTitleActionBarInflater(AppCompatActivity activity, Toolbar toolbar) {
this.activity = activity;
this.toolbar = toolbar;
}
public void setUpActionBarView() {
actionBarPainter = new ActionBarPainter(activity);
barPainter = new BarPainter(activity, toolbar);
activity.setSupportActionBar(toolbar);
ActionBar actionBar = activity.getSupportActionBar();
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(true);
......@@ -37,7 +40,7 @@ public class ContactTitleActionBarInflater {
}
public void update(AbstractContact abstractContact) {
actionBarPainter.updateWithAccountName(abstractContact.getAccount());
barPainter.updateWithAccountName(abstractContact.getAccount());
activity.getSupportActionBar().setDisplayShowCustomEnabled(true);
activity.getSupportActionBar().setDisplayShowTitleEnabled(false);
......
......@@ -5,7 +5,7 @@ import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.TypedValue;
import android.view.View;
......@@ -13,7 +13,6 @@ import android.view.Window;
import android.view.WindowManager;
import android.widget.RelativeLayout;
import com.github.ksoichiro.android.observablescrollview.ObservableListView;
import com.github.ksoichiro.android.observablescrollview.ObservableScrollView;
import com.github.ksoichiro.android.observablescrollview.ObservableScrollViewCallbacks;
import com.github.ksoichiro.android.observablescrollview.ScrollState;
......@@ -28,7 +27,7 @@ import static java.lang.Math.sqrt;
public class ContactTitleExpandableToolbarInflater implements ObservableScrollViewCallbacks {
private final ActionBarActivity activity;
private final AppCompatActivity activity;
private View avatarView;
private View titleView;
......@@ -44,7 +43,7 @@ public class ContactTitleExpandableToolbarInflater implements ObservableScrollVi
private int contactTitlePaddingBottomBig;
private int contactTitlePaddingBottomSmall;
public ContactTitleExpandableToolbarInflater(ActionBarActivity activity) {
public ContactTitleExpandableToolbarInflater(AppCompatActivity activity) {
this.activity = activity;
}
......
......@@ -16,7 +16,7 @@ package com.xabber.android.ui.helper;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.AppCompatActivity;
import com.xabber.android.data.ActivityManager;
......@@ -27,7 +27,7 @@ import com.xabber.android.data.ActivityManager;
*
* @author alexander.ivanov
*/
public abstract class ManagedActivity extends ActionBarActivity {
public abstract class ManagedActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
......
......@@ -25,16 +25,25 @@ import android.text.method.LinkMovementMethod;
import android.view.MenuItem;
import android.widget.TextView;
import com.xabber.android.ui.helper.BarPainter;
import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.androiddev.R;
public class AboutViewer extends ManagedActivity {
public static Intent createIntent(Context context) {
return new Intent(context, AboutViewer.class);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
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))
.setText(getString(R.string.about_version, getVersionName()));
......@@ -54,10 +63,6 @@ public class AboutViewer extends ManagedActivity {
return "";
}
public static Intent createIntent(Context context) {
return new Intent(context, AboutViewer.class);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
......
......@@ -27,24 +27,29 @@ import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.intent.AccountIntentBuilder;
import com.xabber.android.ui.OAuthActivity;
import com.xabber.android.ui.dialog.OrbotInstallerDialogBuilder;
import com.xabber.android.ui.helper.ActionBarPainter;
import com.xabber.android.ui.helper.BarPainter;
import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.androiddev.R;
public class AccountEditor extends ManagedActivity implements
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 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 AccountItem accountItem;
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
protected void onCreate(Bundle savedInstanceState) {
......@@ -72,12 +77,13 @@ public class AccountEditor extends ManagedActivity implements
}
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);
setTitle(AccountManager.getInstance().getVerboseName(account));
toolbar.setTitle(AccountManager.getInstance().getVerboseName(account));
actionBarPainter = new ActionBarPainter(this);
actionBarPainter.updateWithAccountName(account);
barPainter = new BarPainter(this, toolbar);
barPainter.updateWithAccountName(account);
}
@Override
......@@ -108,7 +114,6 @@ public class AccountEditor extends ManagedActivity implements
}
}
@Override
public boolean onPreferenceClick(Preference preference) {
if (getString(R.string.account_oauth_key).equals(preference.getKey())) {
......@@ -119,14 +124,6 @@ public class AccountEditor extends ManagedActivity implements
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
public String getAccount() {
return account;
......@@ -155,6 +152,6 @@ public class AccountEditor extends ManagedActivity implements
@Override
public void onColorChange(String colorName) {
actionBarPainter.updateWithColorName(colorName);
barPainter.updateWithColorName(colorName);
}
}
......@@ -14,8 +14,6 @@
*/
package com.xabber.android.ui.preferences;
import java.util.Collection;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
......@@ -34,12 +32,17 @@ import com.xabber.android.ui.adapter.BaseListEditorAdapter;
import com.xabber.android.ui.helper.PreferenceSummaryHelper;
import com.xabber.androiddev.R;
public class AccountList extends BaseListEditor<String> implements
OnAccountChangedListener {
import java.util.Collection;
public class AccountList extends BaseListEditor<String> implements OnAccountChangedListener {
private static final int CONTEXT_MENU_VIEW_ACCOUNT_ID = 0x20;
private static final int CONTEXT_MENU_STATUS_EDITOR_ID = 0x30;
public static Intent createIntent(Context context) {
return new Intent(context, AccountList.class);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -76,8 +79,7 @@ public class AccountList extends BaseListEditor<String> implements
@Override
protected String getRemoveConfirmation(String actionWith) {
return getString(R.string.account_delete_confirm, AccountManager
.getInstance().getVerboseName(actionWith));
return getString(R.string.account_delete_confirm, AccountManager.getInstance().getVerboseName(actionWith));
}
@Override
......@@ -93,29 +95,24 @@ public class AccountList extends BaseListEditor<String> implements
@Override
protected void onResume() {
super.onResume();
Application.getInstance().addUIListener(OnAccountChangedListener.class,
this);
Application.getInstance().addUIListener(OnAccountChangedListener.class, this);
}
@Override
protected void onPause() {
super.onPause();
Application.getInstance().removeUIListener(
OnAccountChangedListener.class, this);
Application.getInstance().removeUIListener(OnAccountChangedListener.class, this);
}
@Override
protected void onCreateContextMenu(ContextMenu menu, String actionWith) {
final AccountItem accountItem = AccountManager.getInstance()
.getAccount(actionWith);
menu.setHeaderTitle(AccountManager.getInstance().getVerboseName(
actionWith));
final AccountItem accountItem = AccountManager.getInstance().getAccount(actionWith);
menu.setHeaderTitle(AccountManager.getInstance().getVerboseName(actionWith));
if (accountItem.isEnabled()) {
menu.add(0, CONTEXT_MENU_STATUS_EDITOR_ID, 0, getResources()
.getText(R.string.status_editor));
}
menu.add(0, CONTEXT_MENU_VIEW_ACCOUNT_ID, 0,
getString(R.string.account_editor));
menu.add(0, CONTEXT_MENU_VIEW_ACCOUNT_ID, 0, getString(R.string.account_editor));
super.onCreateContextMenu(menu, actionWith);
}
......@@ -148,8 +145,4 @@ public class AccountList extends BaseListEditor<String> implements
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;
import com.xabber.android.ui.dialog.ConfirmDialogBuilder;
import com.xabber.android.ui.dialog.ConfirmDialogListener;
import com.xabber.android.ui.dialog.DialogBuilder;
import com.xabber.android.ui.helper.BarPainter;
import com.xabber.android.ui.helper.ManagedListActivity;
import com.xabber.androiddev.R;
......@@ -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 DIALOG_DELETE_ID = 0x100;
private T actionWith;
protected BaseListEditorAdapter<T> adapter;
private T actionWith;
private BarPainter barPainter;
@Override
public void onCreate(Bundle savedInstanceState) {
......@@ -76,7 +76,12 @@ public abstract class BaseListEditor<T> extends ManagedListActivity implements
*/
protected void onInflate(Bundle savedInstanceState) {
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);
......@@ -108,6 +113,7 @@ public abstract class BaseListEditor<T> extends ManagedListActivity implements
protected void onResume() {
super.onResume();
adapter.onChange();
barPainter.setDefaultColor();
}
@Override
......
......@@ -5,6 +5,7 @@ import android.os.Bundle;
import android.support.v7.widget.Toolbar;
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.androiddev.R;
......@@ -18,9 +19,15 @@ public abstract class BasePhrasePreferences extends ManagedActivity
super.onCreate(savedInstanceState);
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);
BarPainter barPainter = new BarPainter(this, toolbar);
barPainter.setDefaultColor();
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.preferences_activity_container, new PhraseEditorFragment()).commit();
......
......@@ -23,7 +23,7 @@ import com.xabber.android.data.Application;
import com.xabber.android.data.account.AccountItem;
import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.intent.EntityIntentBuilder;
import com.xabber.android.ui.helper.ActionBarPainter;
import com.xabber.android.ui.helper.BarPainter;
import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.androiddev.R;
......@@ -34,6 +34,20 @@ public class ChatEditor extends ManagedActivity
private String user;
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
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -49,11 +63,12 @@ public class ChatEditor extends ManagedActivity
}
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);
ActionBarPainter actionBarPainter = new ActionBarPainter(this);
actionBarPainter.updateWithAccountName(account);
BarPainter barPainter = new BarPainter(this, toolbar);
barPainter.updateWithAccountName(account);
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
......@@ -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
public String getAccount() {
return account;
......
......@@ -3,6 +3,7 @@ package com.xabber.android.ui.preferences;
import android.os.Bundle;
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.PreferenceSummaryHelper;
import com.xabber.androiddev.R;
......@@ -16,7 +17,13 @@ public class ChatSettings extends ManagedActivity {
return;
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)));
......
......@@ -3,6 +3,7 @@ package com.xabber.android.ui.preferences;
import android.os.Bundle;
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.PreferenceSummaryHelper;
import com.xabber.androiddev.R;
......@@ -16,7 +17,13 @@ public class ConnectionSettings extends ManagedActivity {
return;
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)));
......
......@@ -3,6 +3,7 @@ package com.xabber.android.ui.preferences;
import android.os.Bundle;
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.PreferenceSummaryHelper;
import com.xabber.androiddev.R;
......@@ -15,8 +16,14 @@ public class ContactListSettings extends ManagedActivity {
return;
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)));
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
......
......@@ -3,6 +3,7 @@ package com.xabber.android.ui.preferences;
import android.os.Bundle;
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.PreferenceSummaryHelper;
import com.xabber.androiddev.R;
......@@ -16,7 +17,13 @@ public class DebugSettings extends ManagedActivity {
return;
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)));
......
......@@ -4,6 +4,7 @@ package com.xabber.android.ui.preferences;
import android.os.Bundle;
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.PreferenceSummaryHelper;
import com.xabber.androiddev.R;
......@@ -17,7 +18,13 @@ public class NotificationsSettings extends ManagedActivity {
return;
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)));
......
......@@ -21,12 +21,19 @@ import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import com.xabber.android.data.SettingsManager;
import com.xabber.android.ui.helper.BarPainter;
import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.androiddev.R;
public class PreferenceEditor extends ManagedActivity
implements PreferencesFragment.OnPreferencesFragmentInteractionListener {
private BarPainter barPainter;
public static Intent createIntent(Context context) {
return new Intent(context, PreferenceEditor.class);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -34,7 +41,10 @@ public class PreferenceEditor extends ManagedActivity
return;
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) {
getFragmentManager().beginTransaction()
......@@ -48,8 +58,10 @@ public class PreferenceEditor extends ManagedActivity
SettingsManager.chatsAttentionSound();
}
public static Intent createIntent(Context context) {
return new Intent(context, PreferenceEditor.class);
@Override
protected void onResume() {
super.onResume();
barPainter.setDefaultColor();
}
@Override
......
......@@ -3,6 +3,7 @@ package com.xabber.android.ui.preferences;
import android.os.Bundle;
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.PreferenceSummaryHelper;
import com.xabber.androiddev.R;
......@@ -16,7 +17,13 @@ public class SecuritySettings extends ManagedActivity {
return;
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)));
......
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