Esempio n. 1
0
  public void setBuffer(int bufferId) {
    Log.d(TAG, "Setting buffer and chat is visible: " + getUserVisibleHint());
    this.bufferId = bufferId;
    if (adapter != null && networks != null) {
      if (adapter.buffer != null && bufferId != adapter.buffer.getInfo().id) {
        updateMarkerLine();
      }
      adapter.clearBuffer();
      Buffer buffer = networks.getBufferById(bufferId);
      if (buffer != null) {
        adapter.setBuffer(buffer, networks);
        nickCompletionHelper = new NickCompletionHelper(buffer.getUsers().getUniqueUsers());
        autoCompleteButton.setEnabled(true);
        inputField.setEnabled(true);
        if (getUserVisibleHint() == true) buffer.setDisplayed(true);
        BusProvider.getInstance()
            .post(new ManageChannelEvent(buffer.getInfo().id, ChannelAction.HIGHLIGHTS_READ));

        // Move list to correct position
        if (adapter.buffer.getTopMessageShown() == 0) {
          backlogList.setSelection(adapter.getCount() - 1);
        } else {
          adapter.setListTopMessage(adapter.buffer.getTopMessageShown());
        }
      } else {
        resetFragment();
      }
    }
  }
Esempio n. 2
0
 public void clearBuffer() {
   if (buffer != null) {
     buffer.deleteObserver(this);
     buffer.setDisplayed(false);
     buffer = null;
     notifyDataSetChanged();
   }
 }
Esempio n. 3
0
 public void setBuffer(Buffer buffer, NetworkCollection networks) {
   this.buffer = buffer;
   buffer.addObserver(this);
   setTopic();
   notifyDataSetChanged();
   backlogList.scrollTo(backlogList.getScrollX(), backlogList.getScrollY());
 }
Esempio n. 4
0
  /**
   * Checks if there is a highlight in the message and then sets the flag of that message to
   * highlight
   *
   * @param buffer the buffer the message belongs to
   * @param message the message to check
   */
  public void checkMessageForHighlight(Buffer buffer, IrcMessage message) {
    if (message.type == IrcMessage.Type.Plain) {
      String nick = coreConn.getNick(buffer.getInfo().networkId);
      if (nick == null) {
        Log.e(TAG, "Nick is null in check message for highlight");
        return;
      } else if (nick.equals("")) return;
      Pattern regexHighlight =
          Pattern.compile(
              ".*(?<!(\\w|\\d))" + coreConn.getNick(buffer.getInfo().networkId) + "(?!(\\w|\\d)).*",
              Pattern.CASE_INSENSITIVE);
      Matcher matcher = regexHighlight.matcher(message.content);
      if (matcher.find()) {
        message.setFlag(IrcMessage.Flag.Highlight);

        // FIXME: move to somewhere proper
      }
    }
  }
Esempio n. 5
0
 public void setTopic() {
   String topic = "";
   if (buffer.getInfo().type == BufferInfo.Type.QueryBuffer) {
     topic = buffer.getInfo().name;
   } else if (buffer.getInfo().type == BufferInfo.Type.StatusBuffer) {
     Network network = networks.getNetworkById(buffer.getInfo().networkId);
     topic =
         network.getName()
             + " ("
             + network.getServer()
             + ") | "
             + getResources().getString(R.string.users)
             + ": "
             + network.getCountUsers()
             + " | "
             + Helper.formatLatency(network.getLatency(), getResources());
   } else {
     topic = buffer.getInfo().name + ": " + buffer.getTopic();
   }
   topicView.setText(topic);
   topicViewFull.setText(topic);
 }
Esempio n. 6
0
 public void addFilter(Type type) {
   buffer.addFilterType(type);
 }
Esempio n. 7
0
 public void removeFilter(Type type) {
   buffer.removeFilterType(type);
 }
Esempio n. 8
0
 public int getBufferId() {
   return buffer.getInfo().id;
 }
Esempio n. 9
0
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      ViewHolder holder = null;

      if (convertView == null) {
        convertView = inflater.inflate(R.layout.backlog_item, null);
        holder = new ViewHolder();
        holder.timeView = (TextView) convertView.findViewById(R.id.backlog_time_view);
        holder.timeView.setTextColor(ThemeUtil.chatTimestampColor);
        holder.nickView = (TextView) convertView.findViewById(R.id.backlog_nick_view);
        holder.msgView = (TextView) convertView.findViewById(R.id.backlog_msg_view);
        holder.separatorView = (TextView) convertView.findViewById(R.id.backlog_list_separator);
        holder.item_layout =
            (LinearLayout) convertView.findViewById(R.id.backlog_item_linearlayout);
        convertView.setTag(holder);
      } else {
        holder = (ViewHolder) convertView.getTag();
      }

      // Set separator line here
      if (position != (getCount() - 1)
          && (buffer.getMarkerLineMessage() == getItem(position).messageId
              || (buffer.isMarkerLineFiltered()
                  && getItem(position).messageId < buffer.getMarkerLineMessage()
                  && getItem(position + 1).messageId > buffer.getMarkerLineMessage()))) {
        holder.separatorView.getLayoutParams().height = 1;
      } else {
        holder.separatorView.getLayoutParams().height = 0;
      }

      IrcMessage entry = this.getItem(position);
      holder.messageID = entry.messageId;
      holder.timeView.setText(entry.getTime());

      switch (entry.type) {
        case Action:
          holder.nickView.setText("-*-");
          holder.msgView.setTextColor(ThemeUtil.chatActionColor);
          holder.nickView.setTextColor(ThemeUtil.chatActionColor);
          holder.msgView.setText(entry.getNick() + " " + entry.content);
          break;
        case Error:
          holder.nickView.setText("*");
          holder.msgView.setTextColor(ThemeUtil.chatErrorColor);
          holder.nickView.setTextColor(ThemeUtil.chatErrorColor);
          holder.msgView.setText(entry.content);
          break;
        case Server:
        case Info:
          holder.nickView.setText("*");
          holder.msgView.setTextColor(ThemeUtil.chatServerColor);
          holder.nickView.setTextColor(ThemeUtil.chatServerColor);
          holder.msgView.setText(entry.content);
          break;
        case Topic:
          holder.nickView.setText("*");
          holder.msgView.setTextColor(ThemeUtil.chatTopicColor);
          holder.nickView.setTextColor(ThemeUtil.chatTopicColor);
          holder.msgView.setText(entry.content);
          break;
        case Notice:
          holder.nickView.setText("[" + entry.getNick() + "]");
          holder.msgView.setTextColor(ThemeUtil.chatNoticeColor);
          holder.nickView.setTextColor(ThemeUtil.chatNoticeColor);
          holder.msgView.setText(entry.content);
          break;
        case Join:
          holder.nickView.setText("-->");
          holder.msgView.setText(
              entry.getNick() + " (" + entry.getHostmask() + ") has joined " + entry.content);
          holder.msgView.setTextColor(ThemeUtil.chatJoinColor);
          holder.nickView.setTextColor(ThemeUtil.chatJoinColor);
          break;
        case Part:
          holder.nickView.setText("<--");
          holder.msgView.setText(
              entry.getNick() + " (" + entry.getHostmask() + ") has left (" + entry.content + ")");
          holder.msgView.setTextColor(ThemeUtil.chatPartColor);
          holder.nickView.setTextColor(ThemeUtil.chatPartColor);
          break;
        case Quit:
          holder.nickView.setText("<--");
          holder.msgView.setText(
              entry.getNick() + " (" + entry.getHostmask() + ") has quit (" + entry.content + ")");
          holder.msgView.setTextColor(ThemeUtil.chatQuitColor);
          holder.nickView.setTextColor(ThemeUtil.chatQuitColor);
          break;
        case Kill:
          holder.nickView.setText("<--");
          holder.msgView.setText(
              entry.getNick()
                  + " ("
                  + entry.getHostmask()
                  + ") was killed ("
                  + entry.content
                  + ")");
          holder.msgView.setTextColor(ThemeUtil.chatKillColor);
          holder.nickView.setTextColor(ThemeUtil.chatKillColor);
          break;
        case Kick:
          holder.nickView.setText("<-*");
          String nick = "", reason = "";
          int nickEnd = entry.content.toString().indexOf(" ");
          if (nickEnd >= 0) {
            nick = entry.content.toString().substring(0, nickEnd);
            reason = " (" + entry.content.toString().substring(nickEnd + 1) + ")";
          } else {
            nick = entry.content.toString();
          }
          holder.msgView.setText(
              entry.getNick() + " has kicked " + nick + " from " + entry.bufferInfo.name + reason);
          holder.msgView.setTextColor(ThemeUtil.chatKickColor);
          holder.nickView.setTextColor(ThemeUtil.chatKickColor);
          break;
        case Mode:
          holder.nickView.setText("***");
          holder.msgView.setText("Mode " + entry.content.toString() + " by " + entry.getNick());
          holder.msgView.setTextColor(ThemeUtil.chatModeColor);
          holder.nickView.setTextColor(ThemeUtil.chatModeColor);
          break;
        case Nick:
          holder.nickView.setText("<->");
          if (entry.getNick().equals(entry.content.toString())) {
            holder.msgView.setText("You are now known as " + entry.content.toString());
          } else {
            holder.msgView.setText(
                entry.getNick() + " is now known as " + entry.content.toString());
          }
          holder.msgView.setTextColor(ThemeUtil.chatNickColor);
          holder.nickView.setTextColor(ThemeUtil.chatNickColor);
          break;
        case NetsplitJoin:
          holder.nickView.setText("=>");
          holder.msgView.setText(new NetsplitHelper(entry.content.toString()).formatJoinMessage());
          holder.msgView.setTextColor(ThemeUtil.chatNetsplitJoinColor);
          holder.nickView.setTextColor(ThemeUtil.chatNetsplitJoinColor);
          break;
        case NetsplitQuit:
          holder.nickView.setText("<=");
          holder.msgView.setText(new NetsplitHelper(entry.content.toString()).formatQuitMessage());
          holder.msgView.setTextColor(ThemeUtil.chatNetsplitQuitColor);
          holder.nickView.setTextColor(ThemeUtil.chatNetsplitQuitColor);
          break;
        case DayChange:
          holder.nickView.setText("-");
          holder.msgView.setText("{Day changed to " + entry.content.toString() + "}");
          holder.msgView.setTextColor(ThemeUtil.chatDayChangeColor);
          holder.nickView.setTextColor(ThemeUtil.chatDayChangeColor);
        case Plain:
        default:
          if (entry.isSelf()) {
            holder.nickView.setTextColor(ThemeUtil.chatSelfColor);
          } else {
            holder.nickView.setTextColor(entry.senderColor);
          }
          holder.msgView.setTextColor(ThemeUtil.chatPlainColor);
          holder.msgView.setTypeface(Typeface.DEFAULT);

          holder.nickView.setText("<" + entry.getNick() + ">");
          holder.msgView.setText(entry.content);
          break;
      }
      if (entry.isHighlighted()) {
        holder.item_layout.setBackgroundColor(ThemeUtil.chatHighlightColor);
      } else {
        holder.item_layout.setBackgroundResource(0);
      }
      // Log.i(TAG, "CONTENT:" + entry.content);
      return convertView;
    }
Esempio n. 10
0
 @Override
 public long getItemId(int position) {
   return buffer.getBacklogEntry(position).messageId;
 }
Esempio n. 11
0
 @Override
 public IrcMessage getItem(int position) {
   // TODO: PriorityQueue is f****d, we don't want to convert to array here, so change later
   return (IrcMessage) buffer.getBacklogEntry(position);
 }
Esempio n. 12
0
 @Override
 public int getCount() {
   if (this.buffer == null) return 0;
   return buffer.getSize();
 }
Esempio n. 13
0
    @Override
    public void handleMessage(Message msg) {
      if (msg == null) {
        Log.e(TAG, "Msg was null?");
        return;
      }

      Buffer buffer;
      IrcMessage message;
      switch (msg.what) {
        case R.id.CORECONNECTION_NEW_BACKLOGITEM_TO_SERVICE:
          /** New message on one buffer so update that buffer with the new message */
          message = (IrcMessage) msg.obj;
          buffer = bufferCollection.getBuffer(message.bufferInfo.id);
          if (buffer == null) {
            Log.e(TAG, "A messages buffer is null:" + message);
            return;
          }

          if (!buffer.hasMessage(message)) {
            /**
             * Check if we are highlighted in the message, TODO: Add support for custom highlight
             * masks
             */
            checkMessageForHighlight(buffer, message);
            checkForURL(message);
            parseColorCodes(message);
            parseStyleCodes(message);
            buffer.addBacklogMessage(message);
          } else {
            Log.e(TAG, "Getting message buffer already have " + buffer.getInfo().name);
          }
          break;
        case R.id.CORECONNECTION_NEW_MESSAGE_TO_SERVICE:
          /** New message on one buffer so update that buffer with the new message */
          message = (IrcMessage) msg.obj;
          buffer = bufferCollection.getBuffer(message.bufferInfo.id);
          if (buffer == null) {
            Log.e(TAG, "A messages buffer is null: " + message);
            return;
          }

          if (!buffer.hasMessage(message)) {
            /**
             * Check if we are highlighted in the message, TODO: Add support for custom highlight
             * masks
             */
            checkMessageForHighlight(buffer, message);
            parseColorCodes(message);
            parseStyleCodes(message);
            if (message.isHighlighted()) {
              // Create a notification about the highlight
              String text =
                  buffer.getInfo().name + ": <" + message.getNick() + "> " + message.content;
              Notification notification =
                  new Notification(R.drawable.highlight, text, System.currentTimeMillis());
              Intent launch = new Intent(CoreConnService.this, BufferActivity.class);
              launch.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
              PendingIntent contentIntent =
                  PendingIntent.getActivity(CoreConnService.this, 0, launch, 0);
              // Set the info for the views that show in the
              // notification panel.
              notification.setLatestEventInfo(
                  CoreConnService.this, getText(R.string.app_name), text, contentIntent);
              // Send the notification.
              notifyManager.notify(R.id.NOTIFICATION_HIGHLIGHT, notification);
            }

            checkForURL(message);
            buffer.addMessage(message);
          } else {
            Log.e(TAG, "Getting message buffer already have " + buffer.toString());
          }
          break;

        case R.id.CORECONNECTION_NEW_BUFFER_TO_SERVICE:
          /** New buffer received, so update out channel holder with the new buffer */
          buffer = (Buffer) msg.obj;
          bufferCollection.addBuffer(buffer);

          break;
        case R.id.CORECONNECTION_ADD_MULTIPLE_BUFFERS:
          /** Complete list of buffers received */
          bufferCollection.addBuffers((Collection<Buffer>) msg.obj);
          break;

        case R.id.CORECONNECTION_SET_LAST_SEEN_TO_SERVICE:
          /** Setting last seen message id in a buffer */
          if (bufferCollection.hasBuffer(msg.arg1)) {
            bufferCollection.getBuffer(msg.arg1).setLastSeenMessage(msg.arg2);
          } else {
            Log.e(TAG, "Getting set last seen message on unknown buffer: " + msg.arg1);
          }
          break;
        case R.id.CORECONNECTION_SET_MARKERLINE_TO_SERVICE:
          /** Setting marker line message id in a buffer */
          if (bufferCollection.hasBuffer(msg.arg1)) {
            bufferCollection.getBuffer(msg.arg1).setMarkerLineMessage(msg.arg2);
          } else {
            Log.e(TAG, "Getting set marker line message on unknown buffer: " + msg.arg1);
          }
          break;

        case R.id.CORECONNECTION_CONNECTED:
          /** CoreConn has connected to a core */
          showNotification(true);
          for (ResultReceiver statusReceiver : statusReceivers) {
            statusReceiver.send(CoreConnService.CONNECTION_CONNECTED, null);
          }
          break;

        case R.id.CORECONNECTION_LOST_CONNECTION:
          /** Lost connection with core, update notification */
          for (ResultReceiver statusReceiver : statusReceivers) {
            if (msg.obj != null) { // Have description of what is wrong,
              // used only for login atm
              Bundle bundle = new Bundle();
              bundle.putString(CoreConnService.STATUS_KEY, (String) msg.obj);
              statusReceiver.send(CoreConnService.CONNECTION_DISCONNECTED, bundle);
            } else {
              statusReceiver.send(CoreConnService.CONNECTION_DISCONNECTED, null);
            }
          }
          showNotification(false);
          break;

        case R.id.CORECONNECTION_NEW_USERLIST_ADDED:
          /** Initial list of users */
          ArrayList<IrcUser> users = (ArrayList<IrcUser>) msg.obj;
          for (IrcUser user : users) {
            newUser(user);
          }
          break;

        case R.id.CORECONNECTION_NEW_USER_ADDED:
          /** New IrcUser added */
          IrcUser user = (IrcUser) msg.obj;
          newUser(user);
          break;

        case R.id.CORECONNECTION_SET_BUFFER_ORDER:
          /** Buffer order changed so set the new one */
          bufferCollection.getBuffer(msg.arg1).setOrder(msg.arg2);
          break;

        case R.id.CORECONNECTION_SET_BUFFER_TEMP_HIDDEN:
          /** Buffer has been marked as temporary hidden, update buffer */
          bufferCollection.getBuffer(msg.arg1).setTemporarilyHidden((Boolean) msg.obj);
          break;

        case R.id.CORECONNECTION_SET_BUFFER_PERM_HIDDEN:
          /** Buffer has been marked as permanently hidden, update buffer */
          bufferCollection.getBuffer(msg.arg1).setPermanentlyHidden((Boolean) msg.obj);
          break;

        case R.id.CORECONNECTION_INVALID_CERTIFICATE:
          /** Received a mismatching certificate */
        case R.id.CORECONNECTION_NEW_CERTIFICATE:
          /** Received a new, unseen certificate */
          Bundle bundle = new Bundle();
          bundle.putString(CERT_KEY, (String) msg.obj);
          for (ResultReceiver statusReceiver : statusReceivers) {
            statusReceiver.send(CoreConnService.NEW_CERTIFICATE, bundle);
          }
          break;
        case R.id.CORECONNECTION_SET_BUFFER_ACTIVE:
          /** Set buffer as active or parted */
          bufferCollection.getBuffer(msg.arg1).setActive((Boolean) msg.obj);
          break;
        case R.id.CORECONNECTION_UNSUPPORTED_PROTOCOL:
          /** The protocol version of the core is not supported so tell user it is to old */
          for (ResultReceiver statusReceiver : statusReceivers) {
            statusReceiver.send(CoreConnService.UNSUPPORTED_PROTOCOL, null);
          }
      }
    }