Search in sources :

Example 1 with TwitterMultipleImageHelper

use of com.klinker.android.twitter.utils.api_helper.TwitterMultipleImageHelper in project Talon-for-Twitter by klinker24.

the class TweetFragment method getInfo.

public void getInfo(final View favButton, final TextView favCount, final TextView retweetCount, final long tweetId, final View retweetButton) {
    Thread getInfo = new Thread(new Runnable() {

        @Override
        public void run() {
            String location = "";
            String via = "";
            long realTime = 0;
            boolean retweetedByMe = false;
            try {
                Twitter twitter = getTwitter();
                TwitterMultipleImageHelper helper = new TwitterMultipleImageHelper();
                status = twitter.showStatus(tweetId);
                ArrayList<String> i = new ArrayList<String>();
                if (picture) {
                    i = helper.getImageURLs(status, twitter);
                }
                final ArrayList<String> images = i;
                GeoLocation loc = status.getGeoLocation();
                try {
                    Geocoder geocoder = new Geocoder(context, Locale.getDefault());
                    List<Address> addresses = geocoder.getFromLocation(loc.getLatitude(), loc.getLongitude(), 1);
                    if (addresses.size() > 0) {
                        Address address = addresses.get(0);
                        location += address.getLocality() + ", " + address.getCountryName();
                    } else {
                        location = "";
                    }
                } catch (Exception x) {
                    location = "";
                }
                via = android.text.Html.fromHtml(status.getSource()).toString();
                final String sfavCount;
                if (status.isRetweet()) {
                    twitter4j.Status status2 = status.getRetweetedStatus();
                    via = android.text.Html.fromHtml(status2.getSource()).toString();
                    realTime = status2.getCreatedAt().getTime();
                    sfavCount = status2.getFavoriteCount() + "";
                } else {
                    realTime = status.getCreatedAt().getTime();
                    sfavCount = status.getFavoriteCount() + "";
                }
                retweetedByMe = status.isRetweetedByMe();
                final String retCount = "" + status.getRetweetCount();
                final String timeDisplay;
                if (!settings.militaryTime) {
                    timeDisplay = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.US).format(realTime) + " " + DateFormat.getTimeInstance(DateFormat.SHORT, Locale.US).format(realTime);
                } else {
                    timeDisplay = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.GERMAN).format(realTime) + " " + DateFormat.getTimeInstance(DateFormat.SHORT, Locale.GERMAN).format(realTime);
                }
                final String fVia = " " + getResources().getString(R.string.via) + " " + via;
                final String fLoc = location.equals("") ? "" : "\n" + location;
                final boolean fRet = retweetedByMe;
                final long fTime = realTime;
                final Status fStatus = status;
                ((Activity) context).runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        retweetCount.setText(" " + retCount);
                        if (retweetButton instanceof ImageButton) {
                            if (fRet) {
                                if (!settings.addonTheme) {
                                    ((ImageButton) retweetButton).setColorFilter(context.getResources().getColor(R.color.app_color));
                                } else {
                                    ((ImageButton) retweetButton).setColorFilter(settings.accentInt);
                                }
                            } else {
                                ((ImageButton) retweetButton).clearColorFilter();
                            }
                        } else {
                            if (fRet) {
                                if (!settings.addonTheme) {
                                    retweetButton.setBackgroundColor(context.getResources().getColor(R.color.app_color));
                                } else {
                                    retweetButton.setBackgroundColor(settings.accentInt);
                                }
                            } else {
                                retweetButton.setBackgroundColor(getResources().getColor(android.R.color.transparent));
                            }
                        }
                        timetv.setText(timeDisplay + fVia);
                        timetv.append(fLoc);
                        favCount.setText(" " + sfavCount);
                        if (favButton instanceof ImageButton) {
                            if (fStatus.isFavorited()) {
                                TypedArray a = context.getTheme().obtainStyledAttributes(new int[] { R.attr.favoritedButton });
                                int resource = a.getResourceId(0, 0);
                                a.recycle();
                                if (!settings.addonTheme) {
                                    ((ImageButton) favButton).setColorFilter(context.getResources().getColor(R.color.app_color));
                                } else {
                                    ((ImageButton) favButton).setColorFilter(settings.accentInt);
                                }
                                ((ImageButton) favButton).setImageDrawable(context.getResources().getDrawable(resource));
                                isFavorited = true;
                            } else {
                                TypedArray a = context.getTheme().obtainStyledAttributes(new int[] { R.attr.notFavoritedButton });
                                int resource = a.getResourceId(0, 0);
                                a.recycle();
                                ((ImageButton) favButton).setImageDrawable(context.getResources().getDrawable(resource));
                                isFavorited = false;
                                ((ImageButton) favButton).clearColorFilter();
                            }
                        } else {
                            if (fStatus.isFavorited()) {
                                TypedArray a = context.getTheme().obtainStyledAttributes(new int[] { R.attr.favoritedButton });
                                int resource = a.getResourceId(0, 0);
                                a.recycle();
                                if (!settings.addonTheme) {
                                    favButton.setBackgroundColor(context.getResources().getColor(R.color.app_color));
                                } else {
                                    favButton.setBackgroundColor(settings.accentInt);
                                }
                                isFavorited = true;
                            } else {
                                isFavorited = false;
                                favButton.setBackgroundColor(getResources().getColor(android.R.color.transparent));
                            }
                        }
                        for (String s : images) {
                            Log.v("talon_image", s);
                        }
                        if (images.size() > 1) {
                            Log.v("talon_images", "size: " + images.size());
                            try {
                                mAttacher.setOnViewTapListener(new PhotoViewAttacher.OnViewTapListener() {

                                    @Override
                                    public void onViewTap(View view, float x, float y) {
                                        Intent viewPics = new Intent(context, ViewPictures.class);
                                        viewPics.putExtra("images", images);
                                        startActivity(viewPics);
                                    }
                                });
                            } catch (Exception e) {
                                // addon theme without the attacher
                                profilePic.setOnClickListener(new View.OnClickListener() {

                                    @Override
                                    public void onClick(View v) {
                                        Intent viewPics = new Intent(context, ViewPictures.class);
                                        viewPics.putExtra("images", images);
                                        startActivity(viewPics);
                                    }
                                });
                            }
                        }
                    }
                });
            } catch (Exception e) {
            }
        }
    });
    getInfo.setPriority(Thread.MAX_PRIORITY);
    getInfo.start();
}
Also used : ViewPictures(com.klinker.android.twitter.activities.tweet_viewer.ViewPictures) Address(android.location.Address) ArrayList(java.util.ArrayList) TwitterMultipleImageHelper(com.klinker.android.twitter.utils.api_helper.TwitterMultipleImageHelper) Intent(android.content.Intent) Geocoder(android.location.Geocoder) PhotoViewAttacher(uk.co.senab.photoview.PhotoViewAttacher) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Point(android.graphics.Point) ImageButton(android.widget.ImageButton) TypedArray(android.content.res.TypedArray) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

Intent (android.content.Intent)1 TypedArray (android.content.res.TypedArray)1 Point (android.graphics.Point)1 Address (android.location.Address)1 Geocoder (android.location.Geocoder)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ImageButton (android.widget.ImageButton)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 ViewPictures (com.klinker.android.twitter.activities.tweet_viewer.ViewPictures)1 TwitterMultipleImageHelper (com.klinker.android.twitter.utils.api_helper.TwitterMultipleImageHelper)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 PhotoViewAttacher (uk.co.senab.photoview.PhotoViewAttacher)1