Search in sources :

Example 1 with AutoCompleteHashtagAdapter

use of com.klinker.android.twitter.adapters.AutoCompleteHashtagAdapter in project Talon-for-Twitter by klinker24.

the class ComposeActivity method setUpLayout.

public void setUpLayout() {
    setContentView(R.layout.compose_activity);
    setUpSimilar();
    // number of accounts logged in
    int count = 0;
    if (sharedPrefs.getBoolean("is_logged_in_1", false)) {
        count++;
    }
    if (sharedPrefs.getBoolean("is_logged_in_2", false)) {
        count++;
    }
    if (count == 2) {
        findViewById(R.id.accounts).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                String[] options = new String[3];
                options[0] = "@" + settings.myScreenName;
                options[1] = "@" + settings.secondScreenName;
                options[2] = getString(R.string.both_accounts);
                AlertDialog.Builder builder = new AlertDialog.Builder(context);
                builder.setItems(options, new DialogInterface.OnClickListener() {

                    public void onClick(final DialogInterface dialog, final int item) {
                        NetworkedCacheableImageView pic = (NetworkedCacheableImageView) findViewById(R.id.profile_pic);
                        HoloTextView currentName = (HoloTextView) findViewById(R.id.current_name);
                        switch(item) {
                            case 0:
                                useAccOne = true;
                                useAccTwo = false;
                                if (settings.roundContactImages) {
                                    pic.loadImage(settings.myProfilePicUrl, false, null, NetworkedCacheableImageView.CIRCLE);
                                } else {
                                    pic.loadImage(settings.myProfilePicUrl, false, null);
                                }
                                currentName.setText("@" + settings.myScreenName);
                                break;
                            case 1:
                                useAccOne = false;
                                useAccTwo = true;
                                if (settings.roundContactImages) {
                                    pic.loadImage(settings.secondProfilePicUrl, false, null, NetworkedCacheableImageView.CIRCLE);
                                } else {
                                    pic.loadImage(settings.secondProfilePicUrl, false, null);
                                }
                                currentName.setText("@" + settings.secondScreenName);
                                break;
                            case 2:
                                useAccOne = true;
                                useAccTwo = true;
                                TypedArray a = getTheme().obtainStyledAttributes(new int[] { R.attr.favUser });
                                int resource = a.getResourceId(0, 0);
                                a.recycle();
                                pic.setImageResource(resource);
                                currentName.setText(getString(R.string.both_accounts));
                                break;
                        }
                    }
                });
                AlertDialog alert = builder.create();
                alert.show();
            }
        });
    }
    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int width = size.x;
    UserAutoCompleteHelper.applyTo(this, reply);
    hashtagAutoComplete = new ListPopupWindow(context);
    hashtagAutoComplete.setAnchorView(reply);
    hashtagAutoComplete.setHeight(toDP(200));
    hashtagAutoComplete.setWidth((int) (width * .75));
    hashtagAutoComplete.setAdapter(new AutoCompleteHashtagAdapter(context, HashtagDataSource.getInstance(context).getCursor(reply.getText().toString()), reply));
    hashtagAutoComplete.setPromptPosition(ListPopupWindow.POSITION_PROMPT_ABOVE);
    hashtagAutoComplete.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            hashtagAutoComplete.dismiss();
        }
    });
    // watcher for the @
    reply.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            String searchText = reply.getText().toString();
            try {
                int position = reply.getSelectionStart() - 1;
                if (searchText.charAt(position) == '#') {
                    hashtagAutoComplete.show();
                } else if (searchText.charAt(position) == ' ') {
                    hashtagAutoComplete.dismiss();
                } else if (hashtagAutoComplete.isShowing()) {
                    String adapterText = "";
                    do {
                        adapterText = searchText.charAt(position--) + adapterText;
                    } while (searchText.charAt(position) != '#');
                    adapterText = adapterText.replace("#", "");
                    hashtagAutoComplete.setAdapter(new AutoCompleteHashtagAdapter(context, HashtagDataSource.getInstance(context).getCursor(adapterText), reply));
                }
            } catch (Exception e) {
                // there is no text
                try {
                    hashtagAutoComplete.dismiss();
                } catch (Exception x) {
                // something went really wrong I guess haha
                }
            }
        }
    });
    overflow = (ImageButton) findViewById(R.id.overflow_button);
    overflow.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
        }
    });
    attachButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            attachImage();
        }
    });
    gifButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            findGif();
        }
    });
    ImageButton at = (ImageButton) findViewById(R.id.at_button);
    at.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            int start = reply.getSelectionStart();
            reply.getText().insert(start, "@");
            reply.setSelection(start + 1);
        }
    });
    ImageButton hashtag = (ImageButton) findViewById(R.id.hashtag_button);
    hashtag.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            int start = reply.getSelectionStart();
            reply.getText().insert(start, "#");
            reply.setSelection(start + 1);
        }
    });
    final int SAVE_DRAFT = 0;
    final int VIEW_DRAFTS = 1;
    final int VIEW_QUEUE = 2;
    final int SCHEDULE = 3;
    final ImageButton overflow = (ImageButton) findViewById(R.id.overflow_button);
    overflow.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final PopupMenu menu = new PopupMenu(context, findViewById(R.id.discard_button));
            menu.getMenu().add(Menu.NONE, SAVE_DRAFT, Menu.NONE, context.getString(R.string.menu_save_draft));
            menu.getMenu().add(Menu.NONE, VIEW_DRAFTS, Menu.NONE, context.getString(R.string.menu_view_drafts));
            menu.getMenu().add(Menu.NONE, VIEW_QUEUE, Menu.NONE, context.getString(R.string.menu_view_queued));
            menu.getMenu().add(Menu.NONE, SCHEDULE, Menu.NONE, context.getString(R.string.menu_schedule_tweet));
            menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem menuItem) {
                    switch(menuItem.getItemId()) {
                        case SAVE_DRAFT:
                            if (reply.getText().length() > 0) {
                                QueuedDataSource.getInstance(context).createDraft(reply.getText().toString(), currentAccount);
                                Toast.makeText(context, getResources().getString(R.string.saved_draft), Toast.LENGTH_SHORT).show();
                                reply.setText("");
                                finish();
                            } else {
                                Toast.makeText(context, getResources().getString(R.string.no_tweet), Toast.LENGTH_SHORT).show();
                            }
                            break;
                        case VIEW_DRAFTS:
                            final String[] drafts = QueuedDataSource.getInstance(context).getDrafts();
                            if (drafts.length > 0) {
                                final String[] draftsAndDelete = new String[drafts.length + 1];
                                draftsAndDelete[0] = getString(R.string.delete_all);
                                for (int i = 1; i < draftsAndDelete.length; i++) {
                                    draftsAndDelete[i] = drafts[i - 1];
                                }
                                AlertDialog.Builder builder = new AlertDialog.Builder(context);
                                builder.setItems(draftsAndDelete, new DialogInterface.OnClickListener() {

                                    public void onClick(final DialogInterface dialog, final int item) {
                                        if (item == 0) {
                                            // clicked the delete all item
                                            new AlertDialog.Builder(context).setMessage(getString(R.string.delete_all) + "?").setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

                                                @Override
                                                public void onClick(DialogInterface dialogInterface, int i) {
                                                    QueuedDataSource.getInstance(context).deleteAllDrafts();
                                                    dialogInterface.dismiss();
                                                }
                                            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

                                                @Override
                                                public void onClick(DialogInterface dialogInterface, int i) {
                                                    dialogInterface.dismiss();
                                                }
                                            }).create().show();
                                            dialog.dismiss();
                                        } else {
                                            new AlertDialog.Builder(context).setTitle(context.getResources().getString(R.string.apply)).setMessage(draftsAndDelete[item]).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

                                                @Override
                                                public void onClick(DialogInterface dialogInterface, int i) {
                                                    reply.setText(draftsAndDelete[item]);
                                                    reply.setSelection(reply.getText().length());
                                                    QueuedDataSource.getInstance(context).deleteDraft(draftsAndDelete[item]);
                                                    dialogInterface.dismiss();
                                                }
                                            }).setNegativeButton(R.string.delete_draft, new DialogInterface.OnClickListener() {

                                                @Override
                                                public void onClick(DialogInterface dialogInterface, int i) {
                                                    QueuedDataSource.getInstance(context).deleteDraft(draftsAndDelete[item]);
                                                    dialogInterface.dismiss();
                                                }
                                            }).create().show();
                                            dialog.dismiss();
                                        }
                                    }
                                });
                                AlertDialog alert = builder.create();
                                alert.show();
                            } else {
                                Toast.makeText(context, R.string.no_drafts, Toast.LENGTH_SHORT).show();
                            }
                            break;
                        case SCHEDULE:
                            Intent schedule = new Intent(context, ViewScheduledTweets.class);
                            if (!reply.getText().toString().isEmpty()) {
                                schedule.putExtra("has_text", true);
                                schedule.putExtra("text", reply.getText().toString());
                            }
                            startActivity(schedule);
                            finish();
                            break;
                        case VIEW_QUEUE:
                            final String[] queued = QueuedDataSource.getInstance(context).getQueuedTweets(currentAccount);
                            if (queued.length > 0) {
                                AlertDialog.Builder builder = new AlertDialog.Builder(context);
                                builder.setItems(queued, new DialogInterface.OnClickListener() {

                                    public void onClick(final DialogInterface dialog, final int item) {
                                        new AlertDialog.Builder(context).setTitle(context.getResources().getString(R.string.keep_queued_tweet)).setMessage(queued[item]).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

                                            @Override
                                            public void onClick(DialogInterface dialogInterface, int i) {
                                                dialogInterface.dismiss();
                                            }
                                        }).setNegativeButton(R.string.delete_draft, new DialogInterface.OnClickListener() {

                                            @Override
                                            public void onClick(DialogInterface dialogInterface, int i) {
                                                QueuedDataSource.getInstance(context).deleteQueuedTweet(queued[item]);
                                                dialogInterface.dismiss();
                                            }
                                        }).create().show();
                                        dialog.dismiss();
                                    }
                                });
                                AlertDialog alert = builder.create();
                                alert.show();
                            } else {
                                Toast.makeText(context, R.string.no_queued, Toast.LENGTH_SHORT).show();
                            }
                            break;
                    }
                    return false;
                }
            });
            menu.show();
        }
    });
    final ImageButton location = (ImageButton) findViewById(R.id.location);
    location.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (!addLocation) {
                sharedPrefs.edit().putBoolean("share_location", true).commit();
                addLocation = true;
                if (!settings.addonTheme) {
                    location.setColorFilter(context.getResources().getColor(R.color.app_color));
                } else {
                    location.setColorFilter(settings.accentInt);
                }
            } else {
                sharedPrefs.edit().putBoolean("share_location", false).commit();
                addLocation = false;
                location.clearColorFilter();
            }
        }
    });
    if (sharedPrefs.getBoolean("share_location", false)) {
        location.performClick();
    }
    if (!settings.useEmoji) {
        emojiButton.setVisibility(View.GONE);
    } else {
        emojiKeyboard.setAttached((HoloEditText) reply);
        reply.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                if (emojiKeyboard.isShowing()) {
                    emojiKeyboard.setVisibility(false);
                    TypedArray a = getTheme().obtainStyledAttributes(new int[] { R.attr.emoji_button_changing });
                    int resource = a.getResourceId(0, 0);
                    a.recycle();
                    emojiButton.setImageResource(resource);
                }
            }
        });
        emojiButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                if (emojiKeyboard.isShowing()) {
                    emojiKeyboard.setVisibility(false);
                    new Handler().postDelayed(new Runnable() {

                        @Override
                        public void run() {
                            InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
                            imm.showSoftInput(reply, 0);
                        }
                    }, 250);
                    TypedArray a = getTheme().obtainStyledAttributes(new int[] { R.attr.emoji_button_changing });
                    int resource = a.getResourceId(0, 0);
                    a.recycle();
                    emojiButton.setImageResource(resource);
                } else {
                    InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(reply.getWindowToken(), 0);
                    new Handler().postDelayed(new Runnable() {

                        @Override
                        public void run() {
                            emojiKeyboard.setVisibility(true);
                        }
                    }, 250);
                    TypedArray a = getTheme().obtainStyledAttributes(new int[] { R.attr.keyboard_button_changing });
                    int resource = a.getResourceId(0, 0);
                    a.recycle();
                    emojiButton.setImageResource(resource);
                }
            }
        });
    }
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) InputMethodManager(android.view.inputmethod.InputMethodManager) AutoCompleteHashtagAdapter(com.klinker.android.twitter.adapters.AutoCompleteHashtagAdapter) TypedArray(android.content.res.TypedArray) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) Handler(android.os.Handler) Intent(android.content.Intent) Point(android.graphics.Point) HoloTextView(com.klinker.android.twitter.views.HoloTextView) NetworkedCacheableImageView(com.klinker.android.twitter.views.NetworkedCacheableImageView) HoloTextView(com.klinker.android.twitter.views.HoloTextView) Point(android.graphics.Point) IOException(java.io.IOException) NetworkedCacheableImageView(com.klinker.android.twitter.views.NetworkedCacheableImageView)

Example 2 with AutoCompleteHashtagAdapter

use of com.klinker.android.twitter.adapters.AutoCompleteHashtagAdapter in project Talon-for-Twitter by klinker24.

the class TweetFragment method setUIElements.

public void setUIElements(final View layout) {
    TextView nametv;
    TextView screennametv;
    TextView tweettv;
    ImageButton attachButton;
    ImageButton at;
    ImageButton quote = null;
    ImageButton viewRetweeters = null;
    final TextView retweetertv;
    final LinearLayout background;
    final ImageButton expand;
    final View favoriteButton;
    final View retweetButton;
    final TextView favoriteCount;
    final TextView retweetCount;
    final ImageButton overflow;
    final LinearLayout buttons;
    if (!addonTheme) {
        nametv = (TextView) layout.findViewById(R.id.name);
        screennametv = (TextView) layout.findViewById(R.id.screen_name);
        tweettv = (TextView) layout.findViewById(R.id.tweet);
        retweetertv = (TextView) layout.findViewById(R.id.retweeter);
        background = (LinearLayout) layout.findViewById(R.id.linLayout);
        expand = (ImageButton) layout.findViewById(R.id.expand);
        profilePic = (ImageView) layout.findViewById(R.id.profile_pic_contact);
        favoriteButton = (ImageButton) layout.findViewById(R.id.favorite);
        quote = (ImageButton) layout.findViewById(R.id.quote_button);
        retweetButton = (ImageButton) layout.findViewById(R.id.retweet);
        favoriteCount = (TextView) layout.findViewById(R.id.fav_count);
        retweetCount = (TextView) layout.findViewById(R.id.retweet_count);
        reply = (EditText) layout.findViewById(R.id.reply);
        replyButton = (ImageButton) layout.findViewById(R.id.reply_button);
        attachButton = (ImageButton) layout.findViewById(R.id.attach_button);
        overflow = (ImageButton) layout.findViewById(R.id.overflow_button);
        buttons = (LinearLayout) layout.findViewById(R.id.buttons);
        charRemaining = (TextView) layout.findViewById(R.id.char_remaining);
        at = (ImageButton) layout.findViewById(R.id.at_button);
        emojiButton = (ImageButton) layout.findViewById(R.id.emoji);
        emojiKeyboard = (EmojiKeyboard) layout.findViewById(R.id.emojiKeyboard);
        timetv = (TextView) layout.findViewById(R.id.time);
        pictureIv = (ImageView) layout.findViewById(R.id.imageView);
        attachImage = (ImageView) layout.findViewById(R.id.attach);
        viewRetweeters = (ImageButton) layout.findViewById(R.id.view_retweeters);
    } else {
        Resources res;
        try {
            res = context.getPackageManager().getResourcesForApplication(settings.addonThemePackage);
        } catch (Exception e) {
            res = null;
        }
        nametv = (TextView) layout.findViewById(res.getIdentifier("name", "id", settings.addonThemePackage));
        screennametv = (TextView) layout.findViewById(res.getIdentifier("screen_name", "id", settings.addonThemePackage));
        tweettv = (TextView) layout.findViewById(res.getIdentifier("tweet", "id", settings.addonThemePackage));
        retweetertv = (TextView) layout.findViewById(res.getIdentifier("retweeter", "id", settings.addonThemePackage));
        background = (LinearLayout) layout.findViewById(res.getIdentifier("linLayout", "id", settings.addonThemePackage));
        expand = (ImageButton) layout.findViewById(res.getIdentifier("expand", "id", settings.addonThemePackage));
        profilePic = (ImageView) layout.findViewById(res.getIdentifier("profile_pic", "id", settings.addonThemePackage));
        favoriteButton = layout.findViewById(res.getIdentifier("favorite", "id", settings.addonThemePackage));
        retweetButton = layout.findViewById(res.getIdentifier("retweet", "id", settings.addonThemePackage));
        favoriteCount = (TextView) layout.findViewById(res.getIdentifier("fav_count", "id", settings.addonThemePackage));
        retweetCount = (TextView) layout.findViewById(res.getIdentifier("retweet_count", "id", settings.addonThemePackage));
        reply = (EditText) layout.findViewById(res.getIdentifier("reply", "id", settings.addonThemePackage));
        replyButton = (ImageButton) layout.findViewById(res.getIdentifier("reply_button", "id", settings.addonThemePackage));
        attachButton = (ImageButton) layout.findViewById(res.getIdentifier("attach_button", "id", settings.addonThemePackage));
        overflow = (ImageButton) layout.findViewById(res.getIdentifier("overflow_button", "id", settings.addonThemePackage));
        buttons = (LinearLayout) layout.findViewById(res.getIdentifier("buttons", "id", settings.addonThemePackage));
        charRemaining = (TextView) layout.findViewById(res.getIdentifier("char_remaining", "id", settings.addonThemePackage));
        at = (ImageButton) layout.findViewById(res.getIdentifier("at_button", "id", settings.addonThemePackage));
        emojiButton = null;
        emojiKeyboard = null;
        timetv = (TextView) layout.findViewById(res.getIdentifier("time", "id", settings.addonThemePackage));
        pictureIv = (ImageView) layout.findViewById(res.getIdentifier("imageView", "id", settings.addonThemePackage));
        attachImage = (ImageView) layout.findViewById(res.getIdentifier("attach", "id", settings.addonThemePackage));
        try {
            viewRetweeters = (ImageButton) layout.findViewById(res.getIdentifier("view_retweeters", "id", settings.addonThemePackage));
        } catch (Exception e) {
        // it doesn't exist in the theme;
        }
        try {
            quote = (ImageButton) layout.findViewById(res.getIdentifier("quote_button", "id", settings.addonThemePackage));
        } catch (Exception e) {
        // didn't exist when the theme was created.
        }
    }
    Display display = ((Activity) context).getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int width = size.x;
    if (reply != null) {
        userAutocomplete = new ListPopupWindow(context);
        userAutocomplete.setAnchorView(layout.findViewById(R.id.prompt_pos));
        userAutocomplete.setHeight(Utils.toDP(100, context));
        userAutocomplete.setWidth((int) (width * .75));
        userAutocomplete.setAdapter(new AutoCompletePeopleAdapter(context, FollowersDataSource.getInstance(context).getCursor(settings.currentAccount, reply.getText().toString()), reply));
        userAutocomplete.setPromptPosition(ListPopupWindow.POSITION_PROMPT_ABOVE);
        userAutocomplete.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                userAutocomplete.dismiss();
            }
        });
        hashtagAutocomplete = new ListPopupWindow(context);
        hashtagAutocomplete.setAnchorView(layout.findViewById(R.id.prompt_pos));
        hashtagAutocomplete.setHeight(Utils.toDP(100, context));
        hashtagAutocomplete.setWidth((int) (width * .75));
        hashtagAutocomplete.setAdapter(new AutoCompleteHashtagAdapter(context, HashtagDataSource.getInstance(context).getCursor(reply.getText().toString()), reply));
        hashtagAutocomplete.setPromptPosition(ListPopupWindow.POSITION_PROMPT_ABOVE);
        hashtagAutocomplete.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                hashtagAutocomplete.dismiss();
            }
        });
        reply.addTextChangedListener(new TextWatcher() {

            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            }

            @Override
            public void afterTextChanged(Editable editable) {
                String searchText = reply.getText().toString();
                try {
                    if (searchText.substring(searchText.length() - 1, searchText.length()).equals("@")) {
                        userAutocomplete.show();
                    } else if (searchText.substring(searchText.length() - 1, searchText.length()).equals(" ")) {
                        userAutocomplete.dismiss();
                    } else if (userAutocomplete.isShowing()) {
                        String[] split = reply.getText().toString().split(" ");
                        String adapterText;
                        if (split.length > 1) {
                            adapterText = split[split.length - 1];
                        } else {
                            adapterText = split[0];
                        }
                        adapterText = adapterText.replace("@", "");
                        userAutocomplete.setAdapter(new AutoCompletePeopleAdapter(context, FollowersDataSource.getInstance(context).getCursor(settings.currentAccount, adapterText), reply));
                    }
                    if (searchText.substring(searchText.length() - 1, searchText.length()).equals("#")) {
                        hashtagAutocomplete.show();
                    } else if (searchText.substring(searchText.length() - 1, searchText.length()).equals(" ")) {
                        hashtagAutocomplete.dismiss();
                    } else if (hashtagAutocomplete.isShowing()) {
                        String[] split = reply.getText().toString().split(" ");
                        String adapterText;
                        if (split.length > 1) {
                            adapterText = split[split.length - 1];
                        } else {
                            adapterText = split[0];
                        }
                        adapterText = adapterText.replace("#", "");
                        hashtagAutocomplete.setAdapter(new AutoCompleteHashtagAdapter(context, HashtagDataSource.getInstance(context).getCursor(adapterText), reply));
                    }
                } catch (Exception e) {
                    // there is no text
                    try {
                        userAutocomplete.dismiss();
                    } catch (Exception x) {
                    // something went really wrong i guess haha
                    }
                    try {
                        hashtagAutocomplete.dismiss();
                    } catch (Exception x) {
                    }
                }
            }
        });
    }
    nametv.setTextSize(settings.textSize + 2);
    screennametv.setTextSize(settings.textSize);
    tweettv.setTextSize(settings.textSize);
    timetv.setTextSize(settings.textSize - 3);
    retweetertv.setTextSize(settings.textSize - 3);
    favoriteCount.setTextSize(13);
    retweetCount.setTextSize(13);
    if (reply != null) {
        reply.setTextSize(settings.textSize);
    }
    if (settings.addonTheme) {
        try {
            Resources resourceAddon = context.getPackageManager().getResourcesForApplication(settings.addonThemePackage);
            int back = resourceAddon.getIdentifier("reply_entry_background", "drawable", settings.addonThemePackage);
            reply.setBackgroundDrawable(resourceAddon.getDrawable(back));
        } catch (Exception e) {
        // theme does not include a reply entry box
        }
    }
    if (viewRetweeters != null) {
        viewRetweeters.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                //open up the activity to see who retweeted it
                Intent viewRetweeters = new Intent(context, ViewUsersPopup.class);
                viewRetweeters.putExtra("id", tweetId);
                startActivity(viewRetweeters);
            }
        });
    }
    if (quote != null) {
        quote.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                String text = tweet;
                switch(settings.quoteStyle) {
                    case AppSettings.QUOTE_STYLE_TWITTER:
                        text = " " + "https://twitter.com/" + screenName + "/status/" + tweetId;
                        break;
                    case AppSettings.QUOTE_STYLE_TALON:
                        text = "\"@" + screenName + ": " + text + "\" ";
                        break;
                    case AppSettings.QUOTE_STYLE_RT:
                        text = " RT @" + screenName + ": " + text;
                        break;
                }
                Intent intent;
                if (!secondAcc) {
                    intent = new Intent(context, ComposeActivity.class);
                } else {
                    intent = new Intent(context, ComposeSecAccActivity.class);
                }
                intent.putExtra("user", text);
                intent.putExtra("id", tweetId);
                startActivity(intent);
            }
        });
    }
    if (overflow != null) {
        overflow.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                if (buttons.getVisibility() == View.VISIBLE) {
                    Animation ranim = AnimationUtils.loadAnimation(context, R.anim.compose_rotate_back);
                    ranim.setFillAfter(true);
                    overflow.startAnimation(ranim);
                    Animation anim = AnimationUtils.loadAnimation(context, R.anim.slide_out_left);
                    anim.setDuration(300);
                    buttons.startAnimation(anim);
                    buttons.setVisibility(View.GONE);
                } else {
                    buttons.setVisibility(View.VISIBLE);
                    Animation ranim = AnimationUtils.loadAnimation(context, R.anim.compose_rotate);
                    ranim.setFillAfter(true);
                    overflow.startAnimation(ranim);
                    Animation anim = AnimationUtils.loadAnimation(context, R.anim.slide_in_right);
                    anim.setDuration(300);
                    buttons.startAnimation(anim);
                }
            }
        });
    }
    if (settings.theme == 0 && !addonTheme) {
        nametv.setTextColor(getResources().getColor(android.R.color.black));
        nametv.setShadowLayer(0, 0, 0, getResources().getColor(android.R.color.transparent));
        screennametv.setTextColor(getResources().getColor(android.R.color.black));
        screennametv.setShadowLayer(0, 0, 0, getResources().getColor(android.R.color.transparent));
    }
    View.OnClickListener profile = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent viewProfile = new Intent(context, ProfilePager.class);
            viewProfile.putExtra("name", name);
            viewProfile.putExtra("screenname", screenName);
            viewProfile.putExtra("proPic", proPic);
            viewProfile.putExtra("tweetid", tweetId);
            viewProfile.putExtra("retweet", retweetertv.getVisibility() == View.VISIBLE);
            context.startActivity(viewProfile);
        }
    };
    if (picture && settings.combineProPicAndImage) {
        profilePic.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                context.startActivity(new Intent(context, PhotoViewerActivity.class).putExtra("url", webpage));
            }
        });
    } else {
        profilePic.setOnClickListener(profile);
    }
    nametv.setOnClickListener(profile);
    screennametv.setOnClickListener(profile);
    if (picture && pictureIv != null) {
        // if there is a picture already loaded
        Log.v("talon_picture_loading", "picture load started");
        mAttacher = new PhotoViewAttacher(pictureIv);
        mAttacher.setOnViewTapListener(new PhotoViewAttacher.OnViewTapListener() {

            @Override
            public void onViewTap(View view, float x, float y) {
                context.startActivity(new Intent(context, PhotoViewerActivity.class).putExtra("url", webpage));
            }
        });
        pictureIv.setVisibility(View.VISIBLE);
        ImageUtils.loadImage(context, pictureIv, webpage, App.getInstance(context).getBitmapCache());
        final Handler expansionHandler = new Handler();
        if (expand != null) {
            expand.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    if (!canUseExpand) {
                        return;
                    } else {
                        canUseExpand = false;
                    }
                    if (background.getVisibility() == View.VISIBLE) {
                        Animation ranim = AnimationUtils.loadAnimation(context, R.anim.drawer_rotate);
                        ranim.setFillAfter(true);
                        expand.startAnimation(ranim);
                        expansionHandler.removeCallbacksAndMessages(null);
                        expansionHandler.postDelayed(new Runnable() {

                            @Override
                            public void run() {
                                canUseExpand = true;
                            }
                        }, 400);
                    } else {
                        Animation ranim = AnimationUtils.loadAnimation(context, R.anim.drawer_rotate_back);
                        ranim.setFillAfter(true);
                        expand.startAnimation(ranim);
                        expansionHandler.removeCallbacksAndMessages(null);
                        expansionHandler.postDelayed(new Runnable() {

                            @Override
                            public void run() {
                                canUseExpand = true;
                            }
                        }, 400);
                    }
                    ExpansionAnimation expandAni = new ExpansionAnimation(background, 300);
                    background.startAnimation(expandAni);
                }
            });
        }
    } else {
        if (expand != null) {
            expand.setVisibility(View.GONE);
        }
    }
    nametv.setText(name);
    screennametv.setText("@" + screenName);
    tweettv.setText(tweet);
    tweettv.setTextIsSelectable(true);
    if (settings.useEmoji && (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT || EmojiUtils.ios)) {
        if (EmojiUtils.emojiPattern.matcher(tweet).find()) {
            final Spannable span = EmojiUtils.getSmiledText(context, Html.fromHtml(tweet.replaceAll("\n", "<br/>")));
            tweettv.setText(span);
        }
    }
    //Date tweetDate = new Date(time);
    String timeDisplay;
    if (!settings.militaryTime) {
        timeDisplay = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.US).format(time) + " " + DateFormat.getTimeInstance(DateFormat.SHORT, Locale.US).format(time);
    } else {
        timeDisplay = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.GERMAN).format(time) + " " + DateFormat.getTimeInstance(DateFormat.SHORT, Locale.GERMAN).format(time);
    }
    timetv.setText(timeDisplay);
    timetv.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            String data = "twitter.com/" + screenName + "/status/" + tweetId;
            Uri weburi = Uri.parse("http://" + data);
            Intent launchBrowser = new Intent(Intent.ACTION_VIEW, weburi);
            launchBrowser.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(launchBrowser);
        }
    });
    timetv.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View view) {
            if (status != null) {
                // we allow them to mute the client
                final String client = android.text.Html.fromHtml(status.getSource()).toString();
                new AlertDialog.Builder(context).setTitle(context.getResources().getString(R.string.mute_client) + "?").setMessage(client).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        String current = sharedPrefs.getString("muted_clients", "");
                        sharedPrefs.edit().putString("muted_clients", current + client + "   ").commit();
                        sharedPrefs.edit().putBoolean("refresh_me", true).commit();
                        dialogInterface.dismiss();
                        ((Activity) context).finish();
                    }
                }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        dialogInterface.dismiss();
                    }
                }).create().show();
            } else {
                // tell them the client hasn't been found
                Toast.makeText(context, R.string.client_not_found, Toast.LENGTH_SHORT).show();
            }
            return false;
        }
    });
    if (retweeter.length() > 0) {
        retweetertv.setText(getResources().getString(R.string.retweeter) + retweeter);
        retweetertv.setVisibility(View.VISIBLE);
        isRetweet = true;
    }
    favoriteButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (isFavorited || !settings.crossAccActions) {
                favoriteStatus(favoriteCount, favoriteButton, tweetId, secondAcc ? TYPE_ACC_TWO : TYPE_ACC_ONE);
            } else if (settings.crossAccActions) {
                // dialog for favoriting
                String[] options = new String[3];
                options[0] = "@" + settings.myScreenName;
                options[1] = "@" + settings.secondScreenName;
                options[2] = context.getString(R.string.both_accounts);
                new AlertDialog.Builder(context).setItems(options, new DialogInterface.OnClickListener() {

                    public void onClick(final DialogInterface dialog, final int item) {
                        favoriteStatus(favoriteCount, favoriteButton, tweetId, item + 1);
                    }
                }).create().show();
            }
        }
    });
    retweetButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (!settings.crossAccActions) {
                retweetStatus(retweetCount, tweetId, retweetButton, secondAcc ? TYPE_ACC_TWO : TYPE_ACC_ONE);
            } else {
                // dialog for favoriting
                String[] options = new String[3];
                options[0] = "@" + settings.myScreenName;
                options[1] = "@" + settings.secondScreenName;
                options[2] = context.getString(R.string.both_accounts);
                new AlertDialog.Builder(context).setItems(options, new DialogInterface.OnClickListener() {

                    public void onClick(final DialogInterface dialog, final int item) {
                        retweetStatus(retweetCount, tweetId, retweetButton, item + 1);
                    }
                }).create().show();
            }
        }
    });
    retweetButton.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View view) {
            new AlertDialog.Builder(context).setTitle(context.getResources().getString(R.string.remove_retweet)).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    new RemoveRetweet(tweetId, retweetButton).execute();
                }
            }).setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    dialogInterface.dismiss();
                }
            }).create().show();
            return false;
        }
    });
    //profilePic.loadImage(proPic, false, null);
    if (settings.addonTheme && settings.combineProPicAndImage && picture) {
        ImageUtils.loadImage(context, profilePic, webpage, App.getInstance(context).getBitmapCache());
    } else {
        ImageUtils.loadImage(context, profilePic, proPic, App.getInstance(context).getBitmapCache());
    }
    getInfo(favoriteButton, favoriteCount, retweetCount, tweetId, retweetButton);
    String text = tweet;
    String extraNames = "";
    String screenNameToUse;
    if (secondAcc) {
        screenNameToUse = settings.secondScreenName;
    } else {
        screenNameToUse = settings.myScreenName;
    }
    if (text.contains("@")) {
        for (String s : users) {
            if (!s.equals(screenNameToUse) && !extraNames.contains(s) && !s.equals(screenName)) {
                extraNames += "@" + s + " ";
            }
        }
    }
    if (retweeter != null && !retweeter.equals("") && !retweeter.equals(screenNameToUse) && !extraNames.contains(retweeter)) {
        extraNames += "@" + retweeter + " ";
    }
    String sendString = "";
    if (!screenName.equals(screenNameToUse)) {
        if (reply != null) {
            reply.setText("@" + screenName + " " + extraNames);
        }
        sendString = "@" + screenName + " " + extraNames;
    } else {
        if (reply != null) {
            reply.setText(extraNames);
        }
        sendString = extraNames;
    }
    if (settings.autoInsertHashtags && hashtags != null) {
        for (String s : hashtags) {
            if (!s.equals("")) {
                if (reply != null) {
                    reply.append("#" + s + " ");
                }
                sendString += "#" + s + " ";
            }
        }
    }
    final String fSendString = sendString;
    if (reply != null) {
        reply.setSelection(reply.getText().length());
    }
    if (!settings.sendToComposeWindow) {
        replyButton.setEnabled(false);
        replyButton.setAlpha(.4f);
    }
    replyButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (!settings.sendToComposeWindow) {
                try {
                    if (Integer.parseInt(charRemaining.getText().toString()) >= 0 || settings.twitlonger) {
                        if (Integer.parseInt(charRemaining.getText().toString()) < 0) {
                            new AlertDialog.Builder(context).setTitle(context.getResources().getString(R.string.tweet_to_long)).setMessage(context.getResources().getString(R.string.select_shortening_service)).setPositiveButton(R.string.twitlonger, new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    replyToStatus(reply, tweetId, Integer.parseInt(charRemaining.getText().toString()));
                                }
                            }).setNeutralButton(R.string.pwiccer, new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    try {
                                        Intent pwiccer = new Intent("com.t3hh4xx0r.pwiccer.requestImagePost");
                                        pwiccer.putExtra("POST_CONTENT", reply.getText().toString());
                                        startActivityForResult(pwiccer, 420);
                                    } catch (Throwable e) {
                                        // open the play store here
                                        // they don't have pwiccer installed
                                        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=com.t3hh4xx0r.pwiccer&hl=en")));
                                    }
                                }
                            }).setNegativeButton(R.string.edit, new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    dialogInterface.dismiss();
                                }
                            }).create().show();
                        } else {
                            replyToStatus(reply, tweetId, Integer.parseInt(charRemaining.getText().toString()));
                        }
                    } else {
                        Toast.makeText(context, getResources().getString(R.string.tweet_to_long), Toast.LENGTH_SHORT).show();
                    }
                } catch (Exception e) {
                    Toast.makeText(context, getResources().getString(R.string.error), Toast.LENGTH_SHORT).show();
                }
            } else {
                Intent compose;
                if (!secondAcc) {
                    compose = new Intent(context, ComposeActivity.class);
                } else {
                    compose = new Intent(context, ComposeSecAccActivity.class);
                }
                if (fSendString.length() > 0) {
                    // for some reason it puts a extra space here
                    compose.putExtra("user", fSendString.substring(0, fSendString.length() - 1));
                }
                compose.putExtra("id", tweetId);
                compose.putExtra("reply_to_text", "@" + screenName + ": " + tweet);
                startActivity(compose);
            }
        }
    });
    if (attachButton != null) {
        attachButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                attachClick();
                overflow.performClick();
            }
        });
    }
    if (settings.openKeyboard) {
        new Handler().postDelayed(new Runnable() {

            @Override
            public void run() {
                if (reply != null) {
                    reply.requestFocus();
                    InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
                    inputMethodManager.toggleSoftInputFromWindow(reply.getApplicationWindowToken(), InputMethodManager.SHOW_FORCED, 0);
                }
            }
        }, 500);
    }
    if (charRemaining != null) {
        charRemaining.setText(140 - reply.getText().length() + "");
    }
    if (reply != null) {
        reply.setHint(context.getResources().getString(R.string.reply));
        reply.addTextChangedListener(new TextWatcher() {

            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            }

            @Override
            public void afterTextChanged(Editable editable) {
                if (!replyButton.isEnabled()) {
                    replyButton.setEnabled(true);
                    replyButton.setAlpha(1.0f);
                }
                countHandler.removeCallbacks(getCount);
                countHandler.postDelayed(getCount, 200);
            }
        });
    }
    if (!settings.useEmoji || emojiButton == null) {
        try {
            emojiButton.setVisibility(View.GONE);
        } catch (Exception e) {
        // it is a custom layout, so the emoji isn't gonna work :(
        }
    } else {
        emojiKeyboard.setAttached((HoloEditText) reply);
        reply.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                if (emojiKeyboard.isShowing()) {
                    emojiKeyboard.setVisibility(false);
                    TypedArray a = context.getTheme().obtainStyledAttributes(new int[] { R.attr.emoji_button });
                    int resource = a.getResourceId(0, 0);
                    a.recycle();
                    emojiButton.setImageDrawable(getResources().getDrawable(R.drawable.ic_emoji_keyboard_dark));
                }
            }
        });
        emojiButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                if (emojiKeyboard.isShowing()) {
                    emojiKeyboard.setVisibility(false);
                    new Handler().postDelayed(new Runnable() {

                        @Override
                        public void run() {
                            InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
                            imm.showSoftInput(reply, 0);
                        }
                    }, 250);
                    TypedArray a = context.getTheme().obtainStyledAttributes(new int[] { R.attr.emoji_button });
                    int resource = a.getResourceId(0, 0);
                    a.recycle();
                    emojiButton.setImageDrawable(getResources().getDrawable(R.drawable.ic_emoji_keyboard_dark));
                } else {
                    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(reply.getWindowToken(), 0);
                    new Handler().postDelayed(new Runnable() {

                        @Override
                        public void run() {
                            emojiKeyboard.setVisibility(true);
                        }
                    }, 250);
                    TypedArray a = context.getTheme().obtainStyledAttributes(new int[] { R.attr.keyboardButton });
                    int resource = a.getResourceId(0, 0);
                    a.recycle();
                    emojiButton.setImageDrawable(getResources().getDrawable(R.drawable.ic_keyboard_light));
                }
            }
        });
    }
    if (at != null) {
        at.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                final QustomDialogBuilder qustomDialogBuilder = new QustomDialogBuilder(context, sharedPrefs.getInt("current_account", 1)).setTitle(getResources().getString(R.string.type_user)).setTitleColor(getResources().getColor(R.color.app_color)).setDividerColor(getResources().getColor(R.color.app_color));
                qustomDialogBuilder.setNegativeButton(getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        dialogInterface.dismiss();
                    }
                });
                qustomDialogBuilder.setPositiveButton(getResources().getString(R.string.add_user), new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        reply.append(qustomDialogBuilder.text.getText().toString());
                    }
                });
                qustomDialogBuilder.show();
                overflow.performClick();
            }
        });
    }
    // last bool is whether it should open in the external browser or not
    TextUtils.linkifyText(context, retweetertv, null, true, "", true);
    TextUtils.linkifyText(context, tweettv, null, true, "", true);
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) QustomDialogBuilder(com.klinker.android.twitter.utils.QustomDialogBuilder) InputMethodManager(android.view.inputmethod.InputMethodManager) Uri(android.net.Uri) AutoCompleteHashtagAdapter(com.klinker.android.twitter.adapters.AutoCompleteHashtagAdapter) PhotoViewerActivity(com.klinker.android.twitter.activities.photo_viewer.PhotoViewerActivity) ImageButton(android.widget.ImageButton) ViewUsersPopup(com.klinker.android.twitter.activities.tweet_viewer.users_popup.ViewUsersPopup) ListPopupWindow(android.widget.ListPopupWindow) TypedArray(android.content.res.TypedArray) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextView(android.widget.TextView) ExpansionAnimation(com.klinker.android.twitter.utils.ExpansionAnimation) Handler(android.os.Handler) AutoCompletePeopleAdapter(com.klinker.android.twitter.adapters.AutoCompletePeopleAdapter) Intent(android.content.Intent) Point(android.graphics.Point) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) PhotoViewAttacher(uk.co.senab.photoview.PhotoViewAttacher) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Point(android.graphics.Point) QustomDialogBuilder(com.klinker.android.twitter.utils.QustomDialogBuilder) Animation(android.view.animation.Animation) ExpansionAnimation(com.klinker.android.twitter.utils.ExpansionAnimation) AdapterView(android.widget.AdapterView) Resources(android.content.res.Resources) LinearLayout(android.widget.LinearLayout) Spannable(android.text.Spannable) Display(android.view.Display)

Aggregations

AlertDialog (android.app.AlertDialog)2 DialogInterface (android.content.DialogInterface)2 Intent (android.content.Intent)2 TypedArray (android.content.res.TypedArray)2 Point (android.graphics.Point)2 Handler (android.os.Handler)2 Editable (android.text.Editable)2 TextWatcher (android.text.TextWatcher)2 InputMethodManager (android.view.inputmethod.InputMethodManager)2 AutoCompleteHashtagAdapter (com.klinker.android.twitter.adapters.AutoCompleteHashtagAdapter)2 IOException (java.io.IOException)2 Resources (android.content.res.Resources)1 Uri (android.net.Uri)1 Spannable (android.text.Spannable)1 Display (android.view.Display)1 View (android.view.View)1 Animation (android.view.animation.Animation)1 AdapterView (android.widget.AdapterView)1 ImageButton (android.widget.ImageButton)1 ImageView (android.widget.ImageView)1