@Override
 MessageEditorData executeAsync(MyAccount maIn, long msgId) {
   MyAccount ma =
       MyContextHolder.get()
           .persistentAccounts()
           .fromUserId(MyQuery.msgIdToLongColumnValue(MyDatabase.Msg.SENDER_ID, msgId));
   CommandData commandData = CommandData.updateStatus(ma.getAccountName(), msgId);
   MyServiceManager.sendManualForegroundCommand(commandData);
   return null;
 }
 @Override
 protected void setUp() throws Exception {
   super.setUp();
   MyLog.i(this, "setUp started");
   TestSuite.initializeWithData(this);
   ma =
       MyContextHolder.get()
           .persistentAccounts()
           .fromAccountName(TestSuite.CONVERSATION_ACCOUNT_NAME);
   assertTrue(ma.isValid());
   selectedMessageId =
       MyQuery.oidToId(
           OidEnum.MSG_OID, ma.getOriginId(), TestSuite.CONVERSATION_ENTRY_MESSAGE_OID);
   assertTrue("Selected message exists", selectedMessageId != 0);
   MyLog.i(this, "setUp ended");
 }
  @Override
  protected void setUp() throws Exception {
    super.setUp();
    TestSuite.initializeWithData(this);
    iteration = (iteration >= 4 ? 1 : iteration + 1);
    switch (iteration) {
      case 2:
        showAttachedImages = showAttachedImagesOld;
        showAvatars = !showAvatarsOld;
        break;
      case 3:
        showAttachedImages = !showAttachedImagesOld;
        showAvatars = showAvatarsOld;
        break;
      case 4:
        showAttachedImages = !showAttachedImagesOld;
        showAvatars = !showAvatarsOld;
        break;
      default:
        showAttachedImagesOld = MyPreferences.showAttachedImages();
        showAvatarsOld = MyPreferences.showAvatars();
        showAttachedImages = showAttachedImagesOld;
        showAvatars = showAvatarsOld;
        break;
    }
    setPreferences();
    MyLog.setLogToFile(true);
    logStartStop("setUp started");

    MyAccount ma =
        MyContextHolder.get()
            .persistentAccounts()
            .fromAccountName(TestSuite.CONVERSATION_ACCOUNT_NAME);
    assertTrue(ma.isValid());
    MyContextHolder.get().persistentAccounts().setCurrentAccount(ma);

    Intent intent =
        new Intent(
            Intent.ACTION_VIEW,
            MatchedUri.getTimelineUri(ma.getUserId(), TimelineType.HOME, false, 0));
    setActivityIntent(intent);

    activity = getActivity();

    assertTrue("MyService is available", MyServiceManager.isServiceAvailable());
    logStartStop("setUp ended");
  }
 @Override
 MessageEditorData executeAsync(MyAccount ma, long msgId) {
   String body = MyQuery.msgIdToStringColumnValue(MyDatabase.Msg.BODY, msgId);
   if (ma.getOrigin().isHtmlContentAllowed()) {
     body = MyHtml.fromHtml(body);
   }
   return MessageEditorData.newEmpty(ma).setBody(body);
 }
예제 #5
0
 public boolean onContextItemSelected(MenuItem item) {
   MyAccount ma = getMyActor();
   if (ma.isValid()) {
     UserListContextMenuItem contextMenuItem = UserListContextMenuItem.fromId(item.getItemId());
     MyLog.v(
         this,
         "onContextItemSelected: "
             + contextMenuItem
             + "; actor="
             + ma.getAccountName()
             + "; user="
             + getViewItem().mbUser.getNamePreferablyWebFingerId());
     return contextMenuItem.execute(this, ma);
   } else {
     return false;
   }
 }
 @Override
 protected void setUp() throws Exception {
   super.setUp();
   MyLog.i(this, "setUp started");
   TestSuite.initializeWithData(this);
   ma =
       MyContextHolder.get()
           .persistentAccounts()
           .fromAccountName(TestSuite.GNUSOCIAL_TEST_ACCOUNT_NAME);
   assertTrue(TestSuite.GNUSOCIAL_TEST_ACCOUNT_NAME + " exists", ma.isValid());
 }
예제 #7
0
 private void loadMessageFromDatabase(ConversationOneMessage oMsg) {
   Uri uri = MyProvider.getTimelineMsgUri(ma.getUserId(), TimelineTypeEnum.ALL, true, oMsg.msgId);
   Cursor cursor = null;
   try {
     cursor = context.getContentResolver().query(uri, PROJECTION, null, null, null);
     if (cursor != null && cursor.moveToFirst()) {
       loadMessageFromCursor(oMsg, cursor);
     }
   } finally {
     DbUtils.closeSilently(cursor);
   }
 }
예제 #8
0
 public static void selectTimeline(
     FragmentActivity activity,
     ActivityRequestCode requestCode,
     Timeline timeline,
     MyAccount currentMyAccount) {
   SelectorDialog selector = new TimelineSelector();
   selector.setRequestCode(requestCode);
   selector.getArguments().putLong(IntentExtra.TIMELINE_ID.key, timeline.getId());
   selector
       .getArguments()
       .putString(IntentExtra.ACCOUNT_NAME.key, currentMyAccount.getAccountName());
   selector.show(activity);
 }
예제 #9
0
 @Override
 protected MyAccount findBestAccountForDownload() {
   long originId = MyQuery.msgIdToOriginId(data.msgId);
   boolean subscribedFound = false;
   MyAccount bestAccount =
       MyContextHolder.get().persistentAccounts().findFirstSucceededMyAccountByOriginId(originId);
   for (MyAccount ma : MyContextHolder.get().persistentAccounts().collection()) {
     if (ma.getOriginId() == originId && ma.isValidAndSucceeded()) {
       MessageForAccount msg = new MessageForAccount(data.msgId, ma);
       if (msg.hasPrivateAccess()) {
         bestAccount = ma;
         break;
       }
       if (msg.isSubscribed) {
         bestAccount = ma;
         subscribedFound = true;
       }
       if (msg.isTiedToThisAccount() && !subscribedFound) {
         bestAccount = ma;
       }
     }
   }
   return bestAccount;
 }
예제 #10
0
  /** Formats message as a View suitable for a conversation list */
  private View oneMessageToView(ConversationOneMessage oMsg) {
    final String method = "oneMessageToView";
    if (MyLog.isLoggable(this, MyLog.VERBOSE)) {
      MyLog.v(
          this,
          method
              + ": msgId="
              + oMsg.msgId
              + (oMsg.avatarDrawable != null
                  ? ", avatar=" + oMsg.avatarDrawable.getFileName()
                  : ""));
    }
    LayoutInflater inflater = LayoutInflater.from(context);
    int layoutResource = R.layout.message_conversation;
    if (!Activity.class.isAssignableFrom(context.getClass())) {
      MyLog.w(this, "Context should be from an Activity");
    }
    View messageView = inflater.inflate(layoutResource, null);
    messageView.setOnCreateContextMenuListener(contextMenu);

    float displayDensity = context.getResources().getDisplayMetrics().density;
    // See
    // http://stackoverflow.com/questions/2238883/what-is-the-correct-way-to-specify-dimensions-in-dip-from-java-code
    int indent0 = (int) (10 * displayDensity);
    int indentPixels = indent0 * oMsg.indentLevel;

    LinearLayout messageIndented = (LinearLayout) messageView.findViewById(R.id.message_indented);
    if (oMsg.msgId == selectedMessageId && oMsgs.size() > 1) {
      messageIndented.setBackgroundDrawable(
          context.getResources().getDrawable(R.drawable.message_current_background));
    }

    int viewToTheLeftId = 0;
    if (oMsg.indentLevel > 0) {
      View divider = messageView.findViewById(R.id.divider);
      RelativeLayout.LayoutParams layoutParams =
          new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1);
      layoutParams.leftMargin = indentPixels - 4;
      divider.setLayoutParams(layoutParams);

      if (MyLog.isLoggable(this, MyLog.VERBOSE)) {
        MyLog.v(this, "density=" + displayDensity);
      }
      viewToTheLeftId = 2;
      ImageView indentView =
          new ConversationIndentImageView(context, messageIndented, indentPixels);
      indentView.setId(viewToTheLeftId);
      ((ViewGroup) messageIndented.getParent()).addView(indentView);
    }

    if (MyPreferences.showAvatars()) {
      ImageView avatarView = new ImageView(context);
      int size = Math.round(AvatarDrawable.AVATAR_SIZE_DIP * displayDensity);
      avatarView.setScaleType(ScaleType.FIT_CENTER);
      RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(size, size);
      layoutParams.topMargin = 3;
      if (oMsg.indentLevel > 0) {
        layoutParams.leftMargin = 1;
      }
      if (viewToTheLeftId == 0) {
        layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
      } else {
        layoutParams.addRule(RelativeLayout.RIGHT_OF, viewToTheLeftId);
      }
      avatarView.setLayoutParams(layoutParams);
      avatarView.setImageDrawable(oMsg.avatarDrawable.getDrawable());
      indentPixels += size;
      ((ViewGroup) messageIndented.getParent()).addView(avatarView);
    }
    messageIndented.setPadding(indentPixels + 6, 2, 6, 2);

    TextView id = (TextView) messageView.findViewById(R.id.id);
    id.setText(Long.toString(oMsg.msgId));
    TextView linkedUserId = (TextView) messageView.findViewById(R.id.linked_user_id);
    linkedUserId.setText(Long.toString(oMsg.linkedUserId));

    TextView author = (TextView) messageView.findViewById(R.id.message_author);
    TextView body = (TextView) messageView.findViewById(R.id.message_body);
    TextView details = (TextView) messageView.findViewById(R.id.message_details);

    author.setText(oMsg.author);

    TextView number = (TextView) messageView.findViewById(R.id.message_number);
    number.setText(Integer.toString(oMsg.historyOrder));

    if (!TextUtils.isEmpty(oMsg.body)) {
      body.setLinksClickable(true);
      body.setMovementMethod(LinkMovementMethod.getInstance());
      body.setFocusable(true);
      body.setFocusableInTouchMode(true);
      Spanned spanned = Html.fromHtml(oMsg.body);
      body.setText(spanned);
      if (!MbMessage.hasUrlSpans(spanned)) {
        Linkify.addLinks(body, Linkify.ALL);
      }
    }

    // Everything else goes to messageDetails
    String messageDetails = RelativeTime.getDifference(context, oMsg.createdDate);
    if (!SharedPreferencesUtil.isEmpty(oMsg.via)) {
      messageDetails +=
          " "
              + String.format(
                  MyContextHolder.get().getLocale(),
                  context.getText(R.string.message_source_from).toString(),
                  oMsg.via);
    }
    if (oMsg.inReplyToMsgId != 0) {
      String inReplyToName = oMsg.inReplyToName;
      if (SharedPreferencesUtil.isEmpty(inReplyToName)) {
        inReplyToName = "...";
      }
      messageDetails +=
          " "
              + String.format(
                  MyContextHolder.get().getLocale(),
                  context.getText(R.string.message_source_in_reply_to).toString(),
                  oMsg.inReplyToName)
              + " ("
              + msgIdToHistoryOrder(oMsg.inReplyToMsgId)
              + ")";
    }
    if (!SharedPreferencesUtil.isEmpty(oMsg.rebloggersString)
        && !oMsg.rebloggersString.equals(oMsg.author)) {
      if (!SharedPreferencesUtil.isEmpty(oMsg.inReplyToName)) {
        messageDetails += ";";
      }
      messageDetails +=
          " "
              + String.format(
                  MyContextHolder.get().getLocale(),
                  context
                      .getText(ma.alternativeTermForResourceId(R.string.reblogged_by))
                      .toString(),
                  oMsg.rebloggersString);
    }
    if (!SharedPreferencesUtil.isEmpty(oMsg.recipientName)) {
      messageDetails +=
          " "
              + String.format(
                  MyContextHolder.get().getLocale(),
                  context.getText(R.string.message_source_to).toString(),
                  oMsg.recipientName);
    }
    if (MyLog.isLoggable(this, MyLog.VERBOSE)) {
      messageDetails = messageDetails + " (i" + oMsg.indentLevel + ",r" + oMsg.replyLevel + ")";
    }
    details.setText(messageDetails);
    ImageView favorited = (ImageView) messageView.findViewById(R.id.message_favorited);
    favorited.setImageResource(
        oMsg.favorited ? android.R.drawable.star_on : android.R.drawable.star_off);
    return messageView;
  }
예제 #11
0
 private void retrieveFromInternet(long msgId) {
   MyLog.v(this, "Message id=" + msgId + " should be retrieved from the Internet");
   MyServiceManager.sendCommand(
       new CommandData(CommandEnum.GET_STATUS, ma.getAccountName(), msgId));
 }
예제 #12
0
  @Override
  public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    final String method = "onCreateContextMenu";
    super.onCreateContextMenu(menu, v, menuInfo);
    if (getViewItem() == null) {
      return;
    }
    MyAccount myActor = getMyActor();
    if (!myActor.isValid() || !myActor.getOrigin().equals(getOrigin())) {
      setMyActor(getMyContext().persistentAccounts().getFirstSucceededForOrigin(getOrigin()));
    }

    int order = 0;
    try {
      new ContextMenuHeader(getActivity(), menu)
          .setTitle(getViewItem().mbUser.toUserTitle(false))
          .setSubtitle(getMyActor().getAccountName());
      String shortName = getViewItem().mbUser.getUserName();
      if (getViewItem().mbUser.isIdentified()) {
        UserListContextMenuItem.USER_MESSAGES.addTo(
            menu,
            order++,
            String.format(
                getActivity().getText(R.string.menu_item_user_messages).toString(), shortName));
        UserListContextMenuItem.FRIENDS.addTo(
            menu,
            order++,
            String.format(getActivity().getText(R.string.friends_of).toString(), shortName));
        UserListContextMenuItem.FOLLOWERS.addTo(
            menu,
            order++,
            String.format(getActivity().getText(R.string.followers_of).toString(), shortName));
        if (getViewItem().userIsFollowedBy(getMyActor())) {
          UserListContextMenuItem.STOP_FOLLOWING.addTo(
              menu,
              order++,
              String.format(
                  getActivity().getText(R.string.menu_item_stop_following_user).toString(),
                  shortName));
        } else if (getViewItem().getUserId() != getMyActor().getUserId()) {
          UserListContextMenuItem.FOLLOW.addTo(
              menu,
              order++,
              String.format(
                  getActivity().getText(R.string.menu_item_follow_user).toString(), shortName));
        }
        switch (getMyActor().numberOfAccountsOfThisOrigin()) {
          case 0:
          case 1:
            break;
          case 2:
            UserListContextMenuItem.ACT_AS_FIRST_OTHER_USER.addTo(
                menu,
                order++,
                String.format(
                    getActivity().getText(R.string.menu_item_act_as_user).toString(),
                    getMyActor()
                        .firstOtherAccountOfThisOrigin()
                        .getShortestUniqueAccountName(getMyContext())));
            break;
          default:
            UserListContextMenuItem.ACT_AS.addTo(menu, order++, R.string.menu_item_act_as);
            break;
        }
      }
      UserListContextMenuItem.GET_USER.addTo(menu, order++, R.string.get_user);
    } catch (Exception e) {
      MyLog.e(this, method, e);
    }
  }