package eu.e43.impeller.uikit;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import org.json.JSONObject;

import eu.e43.impeller.R;
import eu.e43.impeller.Utils;
import eu.e43.impeller.activity.ActivityWithAccount;
import eu.e43.impeller.activity.MainActivity;

/**
 * Created by OShepherd on 07/12/13.
 */
public class InReplyToView extends RelativeLayout implements View.OnClickListener {
    MainActivity m_activity;
    JSONObject   m_inReplyTo;

    public InReplyToView(MainActivity context, JSONObject inReplyTo) {
        super(context);
        m_activity  = context;
        m_inReplyTo = inReplyTo;

        LayoutInflater.from(context).inflate(R.layout.view_object_in_reply_to, this);

        setBackgroundResource(R.drawable.card_top_accent_bg);

        JSONObject author = inReplyTo.optJSONObject("author");
        if(author != null) {
            AvatarView parentAvatar = (AvatarView) findViewById(R.id.authorAvatar);
            TextView parentAuthor = (TextView)     findViewById(R.id.authorName);

            parentAuthor.setText(author.optString("displayName"));
            JSONObject img = author.optJSONObject("image");
            if(img != null) {
                m_activity.getImageLoader().setImage(parentAvatar, Utils.getImageUrl(img));
            }
        }

        setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        String url = m_inReplyTo.optString("id");

        if(url != null) {
            m_activity.showObjectInMode(MainActivity.Mode.OBJECT, Uri.parse(url));
        } else {
            url = m_inReplyTo.optString("url");
            if(url != null) {
                m_activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
            }
        }
    }
}

@@ -29,40 +29,8 @@
 t;%0A%0A
-import android.content.Context;%0A
 impo
@@ -52,24 +52,24 @@
 ent.Intent;%0A
+
 import andro
@@ -146,75 +146,8 @@
 ew;%0A
-import android.view.ViewGroup;%0Aimport android.widget.LinearLayout;%0A
 impo
@@ -268,16 +268,16 @@
 ller.R;%0A
+
 import e
@@ -302,61 +302,8 @@
 ls;%0A
-import eu.e43.impeller.activity.ActivityWithAccount;%0A
 impo

Tidy up some imports