private void setStateFromView() { PostState state = PostState.getState(); state.removeListener(); state .beginTransaction() .setText(editText.getText().toString()) .setSelection(editText.getSelectionStart(), editText.getSelectionEnd()) .commit(); state.setListener(this); }
private void submitPost() { hideIME(); setStateFromView(); PostState state = PostState.getState(); StatusUpdate statusUpdate = state.toStatusUpdate(); MainActivity activity = (MainActivity) getActivity(); final Account account = activity.getAccount(); final Consumer consumer = activity.getConsumer(); Twitter twitter = TwitterApi.getTwitter(consumer, account); TweetTask tweetTask = new TweetTask(twitter, statusUpdate, state.getMediaFilePath(), activity); tweetTask.execute(); PostState.newState().beginTransaction().commit(); activity.setSelectedPageIndex(MainActivity.ADAPTER_HOME); }
@Override public void onViewStateRestored(Bundle savedInstanceState) { Logger.debug("PostFragment ViewStateRestored"); super.onViewStateRestored(savedInstanceState); PostState state = PostState.getState(); onPostStateChange(state); }
@Override public void onDestroyView() { Logger.debug("PostFragment DestroyView"); super.onDestroyView(); setStateFromView(); PostState.getState().removeListener(); }
private void displayImage() { Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.setDataAndType( Uri.fromFile(new File(PostState.getState().getMediaFilePath())), "image/*"); IntentUtils.startActivityIfFound(getActivity(), intent); }
public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Logger.debug("PostFragment CreateView"); MainActivity activity = (MainActivity) getActivity(); PostState.getState().setListener(this); UserPreferenceHelper preferenceHelper = new UserPreferenceHelper(activity); View v = inflater.inflate(R.layout.fragment_post, null); buttonTweet = getTweetButton(v); buttonTweet.setOnClickListener(this); editText = getEditText(v); textViewCount = getCountTextView(v); int textSize = preferenceHelper.getValue(R.string.key_setting_text_size, 10); editText.addTextChangedListener(this); editText.setOnFocusChangeListener(this); editText.setTextSize(textSize + 4); editText.setMovementMethod( new ArrowKeyMovementMethod() { @Override protected boolean right(TextView widget, Spannable buffer) { // Don't back to Home return widget.getSelectionEnd() == widget.length() || super.right(widget, buffer); } }); ImageButton imageButtonDeleteText = (ImageButton) v.findViewById(R.id.button_post_delete); imageButtonDeleteText.setOnClickListener(this); ImageButton imageButtonMedia = (ImageButton) v.findViewById(R.id.button_post_media); imageButtonMedia.setOnClickListener(this); ImageButton imageButtonMenu = (ImageButton) v.findViewById(R.id.button_post_menu); imageButtonMenu.setOnClickListener(this); // Reply view viewGroupReply = getReplyViewGroup(v); ImageButton imageButtonDeleteReply = (ImageButton) viewGroupReply.findViewById(R.id.button_post_reply_delete); imageButtonDeleteReply.setOnClickListener(this); // Media view viewGroupMedia = getMediaViewGroup(v); ImageView imageViewMedia = (ImageView) viewGroupMedia.findViewById(R.id.image_post_media); ImageButton imageButtonDeleteMedia = (ImageButton) viewGroupMedia.findViewById(R.id.button_post_media_delete); imageViewMedia.setOnClickListener(this); imageButtonDeleteMedia.setOnClickListener(this); editText.requestFocus(); return v; }
public void updateTextCount(CharSequence s) { int remainingCount = 140 - TwitterUtils.getFixedTextLength(s.toString()); if (!TextUtils.isEmpty(PostState.getState().getMediaFilePath())) { remainingCount -= new Validator().getShortUrlLength(); } textViewCount.setText(String.valueOf(remainingCount)); if (remainingCount == 140) { textViewCount.setTextColor(getResources().getColor(R.color.red)); buttonTweet.setEnabled(false); } else if (remainingCount < 0) { textViewCount.setTextColor(getResources().getColor(R.color.red)); buttonTweet.setEnabled(false); } else { textViewCount.setTextAppearance( getActivity(), android.R.style.TextAppearance_Widget_TextView); buttonTweet.setEnabled(true); } setStateFromView(); }
private void removeImage() { hideIME(); viewGroupMedia.setVisibility(View.GONE); ((ImageView) viewGroupMedia.findViewById(R.id.image_post_media)).setImageBitmap(null); PostState.getState().beginTransaction().setMediaFilePath("").commit(); }
private void deleteReply() { viewGroupReply.setVisibility(View.GONE); PostState.getState().beginTransaction().setInReplyToStatusID(-1).commit(); }
private void deletePost() { editText.setText(""); PostState.getState().beginTransaction().setText("").setCursor(0).commit(); deleteReply(); }
@Override public void onPostStateChange(final PostState postState) { Logger.debug("PostFragment PostStateChange"); final MainActivity activity = (MainActivity) getActivity(); if (editText != null) { final int start = postState.getSelectionStart(); final int end = postState.getSelectionEnd(); editText.removeTextChangedListener(this); editText.setTextKeepState(postState.getText()); editText.addTextChangedListener(this); updateTextCount(editText.getText()); new UIHandler() { @Override public void run() { editText.setSelection(start, end); } }.postAtFrontOfQueue(); } if (viewGroupReply != null) { if (postState.getInReplyToStatusID() >= 0) { viewGroupReply.setVisibility(View.VISIBLE); final Account account = activity.getAccount(); final Consumer consumer = activity.getConsumer(); Twitter twitter = TwitterApi.getTwitter(consumer, account); TwitterUtils.tryGetStatus( twitter, account, postState.getInReplyToStatusID(), new TwitterUtils.StatusCallback() { @Override public void success(Status status) { View header = viewGroupReply.findViewById(R.id.layout_post_reply_status); header = new StatusViewModel(status, account) .getView(activity, activity.getLayoutInflater(), header); header.setBackgroundColor(getResources().getColor(R.color.transparent)); header.setClickable(false); } @Override public void error() { viewGroupReply.setVisibility(View.GONE); } }); ImageButton imageButtonDeleteReply = (ImageButton) viewGroupReply.findViewById(R.id.button_post_reply_delete); imageButtonDeleteReply.setOnClickListener(this); } else { viewGroupReply.setVisibility(View.GONE); } } if (viewGroupMedia != null) { ImageView imageViewMedia = (ImageView) viewGroupMedia.findViewById(R.id.image_post_media); if (TextUtils.isEmpty(postState.getMediaFilePath())) { viewGroupMedia.setVisibility(View.GONE); } else { viewGroupMedia.setVisibility(View.VISIBLE); } new BitmapThumbnailTask(activity, postState.getMediaFilePath(), imageViewMedia).execute(); } }