use of im.actor.core.viewmodel.CommandCallback in project actor-platform by actorapp.
the class EditNameFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
type = getArguments().getInt("EXTRA_TYPE");
id = getArguments().getInt("EXTRA_ID");
helper = new KeyboardHelper(getActivity());
View res = inflater.inflate(R.layout.fragment_edit_name, container, false);
res.setBackgroundColor(ActorSDK.sharedActor().style.getMainBackgroundColor());
nameEdit = (EditText) res.findViewById(R.id.nameEdit);
nameEdit.setTextColor(ActorSDK.sharedActor().style.getTextPrimaryColor());
hintTv = (TextView) res.findViewById(R.id.hint);
hintTv.setTextColor(ActorSDK.sharedActor().style.getTextHintColor());
if (type == EditNameActivity.TYPE_ME) {
UserVM userModel = users().get(myUid());
nameEdit.setText(userModel.getName().get());
} else if (type == EditNameActivity.TYPE_NICK) {
UserVM userModel = users().get(myUid());
nameEdit.setText(userModel.getNick().get());
nameEdit.setHint(getString(R.string.nickname_edittext_hint));
hintTv.setText(getString(R.string.nickname_hint).replace("{appName}", ActorSDK.sharedActor().getAppName()));
} else if (type == EditNameActivity.TYPE_USER) {
UserVM userModel = users().get(id);
nameEdit.setText(userModel.getName().get());
} else if (type == EditNameActivity.TYPE_GROUP) {
GroupVM group = groups().get(id);
nameEdit.setText(group.getName().get());
} else if (type == EditNameActivity.TYPE_GROUP_THEME) {
GroupVM group = groups().get(id);
nameEdit.setText(group.getTheme().get());
}
res.findViewById(R.id.dividerTop).setBackgroundColor(ActorSDK.sharedActor().style.getDividerColor());
res.findViewById(R.id.dividerBot).setBackgroundColor(ActorSDK.sharedActor().style.getDividerColor());
res.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getActivity().finish();
}
});
((TextView) res.findViewById(R.id.cancel)).setTextColor(ActorSDK.sharedActor().style.getTextPrimaryColor());
res.findViewById(R.id.ok).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String name = nameEdit.getText().toString().trim();
if (name.length() == 0) {
Toast.makeText(getActivity(), R.string.toast_empty_name, Toast.LENGTH_SHORT).show();
return;
}
if (type == EditNameActivity.TYPE_ME) {
execute(messenger().editMyName(name), R.string.edit_name_process, new CommandCallback<Boolean>() {
@Override
public void onResult(Boolean res) {
getActivity().finish();
}
@Override
public void onError(Exception e) {
Toast.makeText(getActivity(), R.string.toast_unable_change, Toast.LENGTH_SHORT).show();
}
});
} else if (type == EditNameActivity.TYPE_NICK) {
execute(messenger().editMyNick(name), R.string.edit_nick_process, new CommandCallback<Boolean>() {
@Override
public void onResult(Boolean res) {
getActivity().finish();
}
@Override
public void onError(Exception e) {
Toast.makeText(getActivity(), R.string.toast_unable_change_nick, Toast.LENGTH_SHORT).show();
}
});
} else if (type == EditNameActivity.TYPE_USER) {
execute(messenger().editName(id, name), R.string.edit_name_process, new CommandCallback<Boolean>() {
@Override
public void onResult(Boolean res) {
getActivity().finish();
}
@Override
public void onError(Exception e) {
Toast.makeText(getActivity(), R.string.toast_unable_change, Toast.LENGTH_SHORT).show();
}
});
} else if (type == EditNameActivity.TYPE_GROUP_THEME) {
execute(messenger().editGroupTheme(id, name), R.string.edit_theme_process, new CommandCallback<Void>() {
@Override
public void onResult(Void res) {
getActivity().finish();
}
@Override
public void onError(Exception e) {
Toast.makeText(getActivity(), R.string.toast_unable_change, Toast.LENGTH_SHORT).show();
}
});
}
}
});
((TextView) res.findViewById(R.id.ok)).setTextColor(ActorSDK.sharedActor().style.getTextPrimaryColor());
return res;
}
use of im.actor.core.viewmodel.CommandCallback in project actor-platform by actorapp.
the class MessagesDefaultFragment method onLongClick.
@Override
public boolean onLongClick(final Message message, final boolean hasMyReaction) {
if (actionMode == null) {
messagesAdapter.clearSelection();
messagesAdapter.setSelected(message, true);
actionMode = ((AppCompatActivity) getActivity()).startSupportActionMode(new ActionMode.Callback() {
@Override
public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
getActivity().getMenuInflater().inflate(R.menu.messages_context, menu);
return true;
}
@Override
public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
Message[] selected = messagesAdapter.getSelected();
if (selected.length > 0) {
actionMode.setTitle("" + selected.length);
}
boolean isAllText = true;
for (Message k : selected) {
if (!(k.getContent() instanceof TextContent)) {
isAllText = false;
break;
}
}
menu.findItem(R.id.copy).setVisible(isAllText);
menu.findItem(R.id.quote).setVisible(isAllText);
menu.findItem(R.id.forward).setVisible(selected.length == 1 || isAllText);
menu.findItem(R.id.like).setVisible(selected.length == 1);
return false;
}
@Override
public boolean onActionItemClicked(final ActionMode actionMode, MenuItem menuItem) {
if (menuItem.getItemId() == R.id.delete) {
Message[] selected = messagesAdapter.getSelected();
final long[] rids = new long[selected.length];
for (int i = 0; i < rids.length; i++) {
rids[i] = selected[i].getRid();
}
new AlertDialog.Builder(getActivity()).setMessage(getString(R.string.alert_delete_messages_text).replace("{0}", "" + rids.length)).setPositiveButton(R.string.alert_delete_messages_yes, (dialog, which) -> {
messenger().deleteMessages(peer, rids);
actionMode.finish();
}).setNegativeButton(R.string.dialog_cancel, null).show().setCanceledOnTouchOutside(true);
return true;
} else if (menuItem.getItemId() == R.id.copy) {
String text = messenger().getFormatter().formatMessagesExport(messagesAdapter.getSelected());
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
android.content.ClipData clip = android.content.ClipData.newPlainText("Messages", text);
clipboard.setPrimaryClip(clip);
Toast.makeText(getActivity(), R.string.toast_messages_copied, Toast.LENGTH_SHORT).show();
actionMode.finish();
return true;
} else if (menuItem.getItemId() == R.id.like) {
Message currentMessage = messagesAdapter.getSelected()[0];
if (hasMyReaction) {
ActorSDK.sharedActor().getMessenger().removeReaction(getPeer(), currentMessage.getRid(), "❤").start(new CommandCallback<Void>() {
@Override
public void onResult(Void res) {
}
@Override
public void onError(Exception e) {
}
});
} else {
ActorSDK.sharedActor().getMessenger().addReaction(getPeer(), currentMessage.getRid(), "❤").start(new CommandCallback<Void>() {
@Override
public void onResult(Void res) {
}
@Override
public void onError(Exception e) {
}
});
}
actionMode.finish();
return true;
} else if (menuItem.getItemId() == R.id.quote) {
String rawQuote = "";
int i = 0;
for (Message m : messagesAdapter.getSelected()) {
if (m.getContent() instanceof TextContent) {
UserVM user = users().get(m.getSenderId());
String nick = user.getNick().get();
String name = (nick != null && !nick.isEmpty()) ? "@" + nick : user.getName().get();
String text = ((TextContent) m.getContent()).getText();
rawQuote = rawQuote + name + ": " + text + "\n";
}
}
Fragment fragment = getParentFragment();
if (fragment instanceof MessagesFragmentCallback) {
((MessagesFragmentCallback) fragment).onMessageQuote(rawQuote);
}
actionMode.finish();
return true;
} else if (menuItem.getItemId() == R.id.forward) {
Intent i = new Intent(getActivity(), ShareActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
if (messagesAdapter.getSelected().length == 1) {
Message m = messagesAdapter.getSelected()[0];
if (m.getContent() instanceof TextContent) {
UserVM user = users().get(m.getSenderId());
String nick = user.getNick().get();
String name = (nick != null && !nick.isEmpty()) ? "@".concat(nick) : user.getName().get();
String text = ((TextContent) m.getContent()).getText();
String forward = name.concat(": ").concat(text).concat("\n");
i.putExtra(Intents.EXTRA_FORWARD_TEXT, forward);
i.putExtra(Intents.EXTRA_FORWARD_TEXT_RAW, forward);
} else if (!(m.getContent() instanceof UnsupportedContent)) {
AbsContent fileMessage = m.getContent();
try {
i.putExtra(Intents.EXTRA_FORWARD_CONTENT, AbsContent.serialize(fileMessage));
} catch (IOException e) {
e.printStackTrace();
}
}
} else {
String quote = "";
String rawQuote = "";
int j = 0;
for (Message m : messagesAdapter.getSelected()) {
if (m.getContent() instanceof TextContent) {
UserVM user = users().get(m.getSenderId());
String nick = user.getNick().get();
String name = (nick != null && !nick.isEmpty()) ? "@".concat(nick) : user.getName().get();
String text = ((TextContent) m.getContent()).getText();
quote = quote.concat(name).concat(": ").concat(text);
rawQuote = rawQuote.concat(name).concat(": ").concat(text).concat("\n");
if (j++ != messagesAdapter.getSelectedCount() - 1) {
quote += ";\n";
} else {
quote += "\n";
}
}
}
i.putExtra(Intents.EXTRA_FORWARD_TEXT, quote);
i.putExtra(Intents.EXTRA_FORWARD_TEXT_RAW, rawQuote);
}
actionMode.finish();
startActivity(i);
getActivity().finish();
return true;
}
return false;
}
@Override
public void onDestroyActionMode(ActionMode actionMode) {
MessagesDefaultFragment.this.actionMode = null;
messagesAdapter.clearSelection();
}
});
} else {
if (messagesAdapter.isSelected(message)) {
messagesAdapter.setSelected(message, false);
if (messagesAdapter.getSelectedCount() == 0) {
actionMode.finish();
actionMode = null;
} else {
actionMode.invalidate();
}
} else {
messagesAdapter.setSelected(message, true);
actionMode.invalidate();
}
}
return true;
}
use of im.actor.core.viewmodel.CommandCallback in project actor-platform by actorapp.
the class BaseActorSettingsFragment method onCreateView.
@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
messenger().onUserVisible(myUid());
View view = inflater.inflate(R.layout.fragment_settings, container, false);
shp = getActivity().getSharedPreferences("wallpaper", Context.MODE_PRIVATE);
baseColor = getResources().getColor(R.color.primary);
final ActorStyle style = ActorSDK.sharedActor().style;
final UserVM userModel = users().get(myUid());
final TextView nameView = (TextView) view.findViewById(R.id.name);
nameView.setShadowLayer(1, 1, 1, style.getDividerColor());
nameView.setTextColor(style.getProfileTitleColor());
bind(nameView, userModel.getName());
view.findViewById(R.id.notifications).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(getActivity(), NotificationsActivity.class));
}
});
view.findViewById(R.id.helpSettings).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(getActivity(), HelpActivity.class));
}
});
final LinearLayout nickContainer = (LinearLayout) view.findViewById(R.id.nickContainer);
final LinearLayout contactsContainer = (LinearLayout) view.findViewById(R.id.phoneContainer);
final LinearLayout about = (LinearLayout) view.findViewById(R.id.about);
// TODO: Move bindings to onResume
bind(userModel.getNick(), new ValueChangedListener<String>() {
@Override
public void onChanged(final String val, Value<String> Value) {
final View recordView = inflater.inflate(R.layout.contact_record, nickContainer, false);
ImageView nickIcon = (ImageView) recordView.findViewById(R.id.recordIcon);
Drawable drawable = DrawableCompat.wrap(getResources().getDrawable(R.drawable.ic_mention_24_dp));
drawable.mutate();
DrawableCompat.setTint(drawable, style.getSettingsIconColor());
nickIcon.setImageDrawable(drawable);
String value = (val != null && !val.isEmpty()) ? val : getString(R.string.nickname_empty);
String title = getString(R.string.nickname);
TextView nickValue = (TextView) recordView.findViewById(R.id.value);
nickValue.setText(value);
nickValue.setTextColor(style.getTextPrimaryColor());
TextView nickTitle = (TextView) recordView.findViewById(R.id.title);
nickTitle.setText(title);
nickTitle.setTextColor(style.getTextSecondaryColor());
nickContainer.removeAllViews();
nickContainer.addView(recordView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Screen.dp(72)));
recordView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getActivity().startActivity(Intents.editUserNick(getActivity()));
}
});
}
});
final TextView aboutTitle = (TextView) about.findViewById(R.id.value);
ImageView nickIcon = (ImageView) about.findViewById(R.id.recordIcon);
Drawable drawable = DrawableCompat.wrap(getResources().getDrawable(R.drawable.ic_info_black_24dp));
drawable.mutate();
DrawableCompat.setTint(drawable, style.getSettingsIconColor());
nickIcon.setImageDrawable(drawable);
aboutTitle.setTextColor(style.getTextPrimaryColor());
about.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getActivity().startActivity(Intents.editUserAbout(getActivity()));
}
});
bind(userModel.getAbout(), new ValueChangedListener<String>() {
@Override
public void onChanged(String val, Value<String> valueModel) {
if (val != null && !val.isEmpty()) {
aboutTitle.setTextColor(style.getTextPrimaryColor());
aboutTitle.setText(val);
} else {
aboutTitle.setTextColor(style.getTextSecondaryColor());
aboutTitle.setText(getString(R.string.edit_about_edittext_hint));
}
}
});
bind(userModel.getPhones(), new ValueChangedListener<ArrayListUserPhone>() {
@Override
public void onChanged(ArrayListUserPhone val, Value<ArrayListUserPhone> Value) {
if (val.size() == 0) {
noPhones = true;
} else {
contactsContainer.setVisibility(View.VISIBLE);
for (int i = 0; i < val.size(); i++) {
final UserPhone record = val.get(i);
View recordView = inflater.inflate(R.layout.contact_record, contactsContainer, false);
ImageView tintImageView = (ImageView) recordView.findViewById(R.id.recordIcon);
if (i == 0) {
Drawable drawable = DrawableCompat.wrap(getResources().getDrawable(R.drawable.ic_phone_white_24dp));
drawable = drawable.mutate();
DrawableCompat.setTint(drawable, style.getSettingsIconColor());
tintImageView.setImageDrawable(drawable);
} else {
tintImageView.setVisibility(View.INVISIBLE);
}
View divider = recordView.findViewById(R.id.divider);
if (i == val.size() - 1 && (userModel.getEmails().get() == null || userModel.getEmails().get().isEmpty())) {
divider.setVisibility(View.GONE);
} else {
divider.setVisibility(View.VISIBLE);
}
divider.setBackgroundColor(style.getDividerColor());
String _phoneNumber;
try {
Phonenumber.PhoneNumber number = PhoneNumberUtil.getInstance().parse("+" + record.getPhone(), "us");
_phoneNumber = PhoneNumberUtil.getInstance().format(number, PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL);
} catch (NumberParseException e) {
e.printStackTrace();
_phoneNumber = "+" + record.getPhone();
}
final String phoneNumber = _phoneNumber;
TextView value = (TextView) recordView.findViewById(R.id.value);
value.setTextColor(style.getTextPrimaryColor());
value.setText(phoneNumber);
TextView title = (TextView) recordView.findViewById(R.id.title);
title.setTextColor(style.getTextSecondaryColor());
title.setText(record.getTitle().replace("Mobile phone", getString(R.string.settings_mobile_phone)));
contactsContainer.addView(recordView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Screen.dp(72)));
recordView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new AlertDialog.Builder(getActivity()).setItems(new CharSequence[] { getString(R.string.phone_menu_call).replace("{0}", phoneNumber), getString(R.string.phone_menu_sms).replace("{0}", phoneNumber), getString(R.string.phone_menu_share).replace("{0}", phoneNumber), getString(R.string.phone_menu_copy) }, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == 0) {
startActivity(new Intent(Intent.ACTION_DIAL).setData(Uri.parse("tel:+" + record.getPhone())));
} else if (which == 1) {
startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("sms:+" + record.getPhone())));
} else if (which == 2) {
startActivity(new Intent(Intent.ACTION_SEND).setType("text/plain").putExtra(Intent.EXTRA_TEXT, getString(R.string.settings_share_text).replace("{0}", phoneNumber).replace("{1}", userModel.getName().get())));
} else if (which == 3) {
ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Phone number", phoneNumber);
clipboard.setPrimaryClip(clip);
Toast.makeText(getActivity(), R.string.toast_phone_copied, Toast.LENGTH_SHORT).show();
}
}
}).show().setCanceledOnTouchOutside(true);
}
});
recordView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Phone number", "+" + record.getPhone());
clipboard.setPrimaryClip(clip);
Toast.makeText(getActivity(), R.string.toast_phone_copied, Toast.LENGTH_SHORT).show();
return true;
}
});
}
}
}
});
bind(userModel.getEmails(), new ValueChangedListener<ArrayListUserEmail>() {
@Override
public void onChanged(ArrayListUserEmail val, Value<ArrayListUserEmail> Value) {
if (val.size() == 0) {
noEmails = true;
} else {
contactsContainer.setVisibility(View.VISIBLE);
for (int i = 0; i < val.size(); i++) {
final UserEmail record = val.get(i);
View recordView = inflater.inflate(R.layout.contact_record, contactsContainer, false);
ImageView tintImageView = (ImageView) recordView.findViewById(R.id.recordIcon);
if (i == 0) {
Drawable drawable = DrawableCompat.wrap(getResources().getDrawable(R.drawable.ic_email_white_24dp));
drawable.mutate();
DrawableCompat.setTint(drawable, style.getSettingsIconColor());
tintImageView.setImageDrawable(drawable);
} else {
tintImageView.setVisibility(View.INVISIBLE);
}
View divider = recordView.findViewById(R.id.divider);
if (i != val.size() - 1) {
divider.setVisibility(View.VISIBLE);
} else {
divider.setVisibility(View.GONE);
}
divider.setBackgroundColor(style.getDividerColor());
final String email = record.getEmail();
TextView value = (TextView) recordView.findViewById(R.id.value);
value.setTextColor(style.getTextPrimaryColor());
value.setText(email);
TextView title = (TextView) recordView.findViewById(R.id.title);
title.setTextColor(style.getTextSecondaryColor());
title.setText(record.getTitle());
contactsContainer.addView(recordView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Screen.dp(72)));
recordView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new AlertDialog.Builder(getActivity()).setItems(new CharSequence[] { getString(R.string.email_menu_email).replace("{0}", email), getString(R.string.phone_menu_copy) }, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == 0) {
startActivity(new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", record.getEmail(), null)));
} else if (which == 1) {
ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Email", email);
clipboard.setPrimaryClip(clip);
Toast.makeText(getActivity(), R.string.toast_email_copied, Toast.LENGTH_SHORT).show();
}
}
}).show().setCanceledOnTouchOutside(true);
}
});
recordView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Email", "+" + record.getEmail());
clipboard.setPrimaryClip(clip);
Toast.makeText(getActivity(), R.string.toast_email_copied, Toast.LENGTH_SHORT).show();
return true;
}
});
}
}
}
});
view.findViewById(R.id.chatSettings).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(getActivity(), ChatSettingsActivity.class));
}
});
view.findViewById(R.id.encryption).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ActorSDK.sharedActor().startSecuritySettingsActivity(getActivity());
}
});
// view.findViewById(R.id.encryption).setOnLongClickListener(new View.OnLongClickListener() {
// @Override
// public boolean onLongClick(View v) {
// if (AndroidLogProvider.isSendLogsEnabled()) {
// AndroidLogProvider.setSendLogs(null);
// Toast.makeText(getActivity(), "send logs off", Toast.LENGTH_LONG).show();
// } else {
//
// android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(getActivity());
// builder.setTitle("Send logs integration url");
//
// LinearLayout ll = new LinearLayout(getActivity());
// ll.setPadding(Screen.dp(20), 0, Screen.dp(20), 0);
//
// final EditText input = new EditText(getActivity());
// ll.addView(input, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
// builder.setView(ll);
//
// builder.setPositiveButton(getString(R.string.dialog_ok), new DialogInterface.OnClickListener() {
// @Override
// public void onClick(DialogInterface dialog, int which) {
// AndroidLogProvider.setSendLogs(input.getText().toString());
// Toast.makeText(getActivity(), "send logs on", Toast.LENGTH_LONG).show();
//
// }
// });
// builder.setNegativeButton(R.string.dialog_cancel, new DialogInterface.OnClickListener() {
// @Override
// public void onClick(DialogInterface dialog, int which) {
// dialog.cancel();
// }
// });
//
// builder.create().show();
//
//
// }
// return true;
// }
// });
view.findViewById(R.id.blockedList).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(getActivity(), BlockedListActivity.class));
}
});
// view.findViewById(R.id.chatSettings).setOnLongClickListener(new View.OnLongClickListener() {
// @Override
// public boolean onLongClick(View v) {
// Toast.makeText(getActivity(), AndroidLogProvider.toggleWriteLogs() ? "write logs on" : "write logs off", Toast.LENGTH_LONG).show();
// return true;
// }
// });
View askQuestion = view.findViewById(R.id.askQuestion);
if (ActorSDK.sharedActor().getHelpPhone() == null || ActorSDK.sharedActor().getHelpPhone().isEmpty()) {
askQuestion.setVisibility(View.GONE);
view.findViewById(R.id.divider3).setVisibility(View.GONE);
}
askQuestion.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
execute(messenger().findUsers(ActorSDK.sharedActor().getHelpPhone()), R.string.progress_common, new CommandCallback<UserVM[]>() {
@Override
public void onResult(UserVM[] res) {
if (res.length >= 1) {
startActivity(Intents.openPrivateDialog(res[0].getId(), true, getActivity()));
}
}
@Override
public void onError(Exception e) {
}
});
}
});
//Twitter
View twitterView = view.findViewById(R.id.twitter);
if (ActorSDK.sharedActor().getTwitterAcc() == null || ActorSDK.sharedActor().getTwitterAcc().isEmpty()) {
twitterView.setVisibility(View.GONE);
}
twitterView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent viewIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/" + ActorSDK.sharedActor().getTwitterAcc()));
startActivity(viewIntent);
}
});
TextView twitterTitle = (TextView) view.findViewById(R.id.settings_twitter);
twitterTitle.setTextColor(style.getSettingsTitleColor());
TintImageView twitterIcon = (TintImageView) view.findViewById(R.id.settings_twitter_icon);
twitterIcon.setTint(style.getSettingsIconColor());
//Home page
View homePageView = view.findViewById(R.id.home_page);
if (ActorSDK.sharedActor().getHomePage() == null || ActorSDK.sharedActor().getHomePage().isEmpty()) {
homePageView.setVisibility(View.GONE);
}
homePageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent viewIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(ActorSDK.sharedActor().getHomePage()));
startActivity(viewIntent);
}
});
TextView homePageTitle = (TextView) view.findViewById(R.id.settings_home_page);
homePageTitle.setTextColor(style.getSettingsTitleColor());
TintImageView homePageIcon = (TintImageView) view.findViewById(R.id.settings_home_page_icon);
homePageIcon.setTint(style.getSettingsIconColor());
TextView profileHeaderText = (TextView) view.findViewById(R.id.profile_info_header_text);
profileHeaderText.setTextColor(style.getSettingsCategoryTextColor());
TextView settingsHeaderText = (TextView) view.findViewById(R.id.settings_header_text);
settingsHeaderText.setTextColor(style.getSettingsCategoryTextColor());
TextView aboutHeaderText = (TextView) view.findViewById(R.id.about_header_text);
aboutHeaderText.setTextColor(style.getSettingsCategoryTextColor());
TextView settingsNotificationsTitle = (TextView) view.findViewById(R.id.settings_notifications_title);
settingsNotificationsTitle.setTextColor(style.getSettingsTitleColor());
TextView settingsChatTitle = (TextView) view.findViewById(R.id.settings_chat_title);
settingsChatTitle.setTextColor(style.getSettingsTitleColor());
TextView securityTitle = (TextView) view.findViewById(R.id.settings_security_title);
securityTitle.setTextColor(style.getSettingsTitleColor());
TintImageView securityIcon = (TintImageView) view.findViewById(R.id.settings_security_icon);
securityIcon.setTint(style.getSettingsIconColor());
TextView blockedListTitle = (TextView) view.findViewById(R.id.settings_blocked_title);
blockedListTitle.setTextColor(style.getSettingsTitleColor());
TintImageView blockedListIcon = (TintImageView) view.findViewById(R.id.settings_blocked_icon);
blockedListIcon.setTint(style.getSettingsIconColor());
TextView helpTitle = (TextView) view.findViewById(R.id.settings_help_title);
helpTitle.setTextColor(style.getSettingsTitleColor());
TintImageView helpIcon = (TintImageView) view.findViewById(R.id.settings_help_icon);
helpIcon.setTint(style.getSettingsIconColor());
TextView askTitle = (TextView) view.findViewById(R.id.settings_ask_title);
askTitle.setTextColor(style.getSettingsTitleColor());
TintImageView askIcon = (TintImageView) view.findViewById(R.id.settings_ask_icon);
askIcon.setTint(style.getSettingsIconColor());
TintImageView notificationsSettingsIcon = (TintImageView) view.findViewById(R.id.settings_notification_icon);
notificationsSettingsIcon.setTint(style.getSettingsIconColor());
TintImageView chatSettingsIcon = (TintImageView) view.findViewById(R.id.settings_chat_icon);
chatSettingsIcon.setTint(style.getSettingsIconColor());
if (getBeforeNickSettingsView() != null) {
FrameLayout beforeNick = (FrameLayout) view.findViewById(R.id.before_nick_container);
beforeNick.addView(getBeforeNickSettingsView(), FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
}
if (getBeforeNickSettingsView() != null) {
FrameLayout afterPhone = (FrameLayout) view.findViewById(R.id.after_phone_container);
afterPhone.addView(getAfterPhoneSettingsView(), FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
}
if (getSettingsTopView() != null) {
FrameLayout settingsTop = (FrameLayout) view.findViewById(R.id.settings_top_container);
settingsTop.addView(getSettingsTopView(), FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
}
if (getSettingsBottomView() != null) {
FrameLayout settingsBot = (FrameLayout) view.findViewById(R.id.settings_bottom_container);
settingsBot.addView(getSettingsBottomView(), FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
}
if (getBeforeSettingsCategories() != null) {
LinearLayout beforeSettings = (LinearLayout) view.findViewById(R.id.before_settings_container);
addCategories(beforeSettings, getBeforeSettingsCategories(), inflater);
}
if (getAfterSettingsCategories() != null) {
LinearLayout afterSettings = (LinearLayout) view.findViewById(R.id.after_settings_container);
addCategories(afterSettings, getAfterSettingsCategories(), inflater);
}
view.findViewById(R.id.avatarContainer).setBackgroundColor(style.getToolBarColor());
avatarView = (AvatarView) view.findViewById(R.id.avatar);
avatarView.init(Screen.dp(96), 44);
avatarView.bind(users().get(myUid()));
//Wallpaper
if (showWallpaperCategory()) {
((TextView) view.findViewById(R.id.settings_wallpaper_title)).setTextColor(style.getSettingsCategoryTextColor());
RecyclerView wallpapers = (RecyclerView) view.findViewById(R.id.wallpapers_list);
wallpaperAdapter = new HeaderViewRecyclerAdapter(new WallpapersAdapter());
FrameLayout fl = new FrameLayout(getActivity());
ImageView icon = new ImageView(getActivity());
icon.setImageResource(R.drawable.ic_image_black_24dp);
icon.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
icon.setColorFilter(ActorSDK.sharedActor().style.getSettingsIconColor(), PorterDuff.Mode.SRC_IN);
fl.addView(icon, new FrameLayout.LayoutParams(Screen.dp(72), Screen.dp(85), Gravity.CENTER));
fl.setLayoutParams(new ViewGroup.LayoutParams(Screen.dp(72), Screen.dp(85)));
wallpaperAdapter.addHeaderView(fl);
wallpapers.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false));
wallpapers.setAdapter(wallpaperAdapter);
} else {
view.findViewById(R.id.wallpapers_list).setVisibility(View.GONE);
view.findViewById(R.id.settings_wallpaper_title).setVisibility(View.GONE);
}
view.findViewById(R.id.avatar).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(ViewAvatarActivity.viewAvatar(myUid(), getActivity()));
}
});
final ScrollView scrollView = ((ScrollView) view.findViewById(R.id.scrollContainer));
scrollView.setBackgroundColor(style.getMainBackgroundColor());
scrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
@Override
public void onScrollChanged() {
updateActionBar(scrollView.getScrollY());
}
});
updateActionBar(scrollView.getScrollY());
return view;
}
use of im.actor.core.viewmodel.CommandCallback in project actor-platform by actorapp.
the class GlobalSearchBaseFragment method onCreateOptionsMenu.
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.fragment_global_search, menu);
searchMenu = menu.findItem(R.id.search);
if (messenger().getAppState().getIsAppEmpty().get()) {
searchMenu.setVisible(false);
} else {
searchMenu.setVisible(true);
}
searchView = (SearchView) searchMenu.getActionView();
searchView.setIconifiedByDefault(true);
MenuItemCompat.setOnActionExpandListener(searchMenu, new MenuItemCompat.OnActionExpandListener() {
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
showSearch();
return true;
}
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
hideSearch();
return true;
}
});
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String s) {
return false;
}
@Override
public boolean onQueryTextChange(String s) {
searchQuery = s.trim();
if (isSearchVisible) {
if (s.trim().length() > 0) {
String activeSearchQuery = searchQuery;
searchDisplay.initSearch(s.trim().toLowerCase(), false);
scrolledToEnd = false;
searchAdapter.setQuery(s.trim().toLowerCase());
globalSearchResults.clear();
messenger().findPeers(s).start(new CommandCallback<List<PeerSearchEntity>>() {
@Override
public void onResult(List<PeerSearchEntity> res) {
if (searchQuery.equals(activeSearchQuery)) {
int order = 0;
outer: for (PeerSearchEntity pse : res) {
for (int i = 0; i < searchDisplay.getSize(); i++) {
if (searchDisplay.getItem(i).getPeer().equals(pse.getPeer())) {
continue outer;
}
}
Avatar avatar;
Peer peer = pse.getPeer();
String name;
if (peer.getPeerType() == PeerType.PRIVATE) {
UserVM userVM = users().get(peer.getPeerId());
name = userVM.getName().get();
avatar = userVM.getAvatar().get();
} else if (peer.getPeerType() == PeerType.GROUP) {
GroupVM groupVM = groups().get(peer.getPeerId());
name = groupVM.getName().get();
avatar = groupVM.getAvatar().get();
} else {
continue;
}
String optMatchString = pse.getOptMatchString();
globalSearchResults.add(new SearchEntity(pse.getPeer(), order++, avatar, optMatchString == null ? name : optMatchString));
}
if (globalSearchResults.size() > 0) {
globalSearchResults.add(new SearchEntityHeader(order++));
}
checkGlobalSearch();
onSearchChanged();
}
}
@Override
public void onError(Exception e) {
}
});
} else {
searchDisplay.initEmpty();
}
}
return false;
}
});
}
use of im.actor.core.viewmodel.CommandCallback in project actor-platform by actorapp.
the class EditAboutFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
type = getArguments().getInt("EXTRA_TYPE");
id = getArguments().getInt("EXTRA_ID");
helper = new KeyboardHelper(getActivity());
View res = inflater.inflate(R.layout.fragment_edit_about, container, false);
res.setBackgroundColor(ActorSDK.sharedActor().style.getMainBackgroundColor());
aboutEdit = (EditText) res.findViewById(R.id.nameEdit);
aboutEdit.setTextColor(ActorSDK.sharedActor().style.getTextPrimaryColor());
hintTv = (TextView) res.findViewById(R.id.hint);
hintTv.setTextColor(ActorSDK.sharedActor().style.getTextHintColor());
if (type == EditAboutActivity.TYPE_ME) {
UserVM userModel = users().get(myUid());
aboutEdit.setText(userModel.getAbout().get());
aboutEdit.setHint(getString(R.string.edit_about_edittext_hint));
} else if (type == EditAboutActivity.TYPE_GROUP) {
GroupVM group = groups().get(id);
aboutEdit.setText(group.getAbout().get());
}
res.findViewById(R.id.dividerTop).setBackgroundColor(ActorSDK.sharedActor().style.getDividerColor());
res.findViewById(R.id.dividerBot).setBackgroundColor(ActorSDK.sharedActor().style.getDividerColor());
res.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getActivity().finish();
}
});
((TextView) res.findViewById(R.id.cancel)).setTextColor(ActorSDK.sharedActor().style.getTextPrimaryColor());
res.findViewById(R.id.ok).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String about = aboutEdit.getText().toString().trim();
if (about.length() == 0) {
about = null;
}
if (type == EditAboutActivity.TYPE_ME) {
execute(messenger().editMyAbout(about), R.string.progress_common, new CommandCallback<Boolean>() {
@Override
public void onResult(Boolean res) {
getActivity().finish();
}
@Override
public void onError(Exception e) {
Toast.makeText(getActivity(), R.string.toast_unable_change, Toast.LENGTH_SHORT).show();
}
});
//TODO: set group about
}
}
});
((TextView) res.findViewById(R.id.ok)).setTextColor(ActorSDK.sharedActor().style.getTextPrimaryColor());
return res;
}
Aggregations