package com.nantaphop.pantipfanapp;

import android.graphics.Color;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.FrameLayout;

import com.nantaphop.pantipfanapp.fragment.UserFragment;
import com.nantaphop.pantipfanapp.fragment.UserFragment_;
import com.nantaphop.pantipfanapp.view.BaseActivity;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.App;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.Extra;
import org.androidannotations.annotations.NonConfigurationInstance;
import org.androidannotations.annotations.ViewById;

/**
 * Created by nantaphop on 24-Oct-14.
 */
@EActivity(R.layout.activity_fragment)
public class UserActivity extends BaseActivity {


    @ViewById
    Toolbar toolbar;
    @ViewById
    FrameLayout contentFrame;
    @App
    BaseApplication app;

    @Extra
    int userId;
    @Extra
    String avatar;
    @Extra
    String user;

    @NonConfigurationInstance
    UserFragment userFragment;
    @ViewById
    View toolbarPadding;


    @Override
    public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
        super.onCreate(savedInstanceState, persistentState);
    }

    @AfterViews
    void init() {
        setSupportActionBar(toolbar);
        toolbarPadding.setVisibility(View.GONE);
        if (userFragment == null) {
            userFragment = UserFragment_.builder().userId(userId).avatar(avatar).user(user).build();
            getSupportFragmentManager()
                    .beginTransaction()
                    .add(R.id.content_frame, userFragment, null)
                    .commit();
        }
        toolbar.setBackgroundColor(Color.parseColor("#00000000"));
        setTitle("");
    }

    @Override
    protected void onResume() {
        super.onResume();
        app.getEventBus().register(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        app.getEventBus().unregister(this);
    }


}

@@ -30,16 +30,47 @@
 anapp;%0A%0A
+import android.content.Intent;%0A
 import a
@@ -92,16 +92,16 @@
 .Color;%0A
-
 import a
@@ -197,16 +197,41 @@
 oolbar;%0A
+import android.util.Log;%0A
 import a
@@ -284,16 +284,72 @@
 ayout;%0A%0A
+import com.nantaphop.pantipfanapp.event.OpenTopicEvent;%0A
 import c
@@ -455,16 +455,16 @@
 gment_;%0A
-
 import c
@@ -507,16 +507,52 @@
 ctivity;
+%0Aimport com.squareup.otto.Subscribe;
 %0A%0Aimport
@@ -2260,11 +2260,297 @@
 %0A    %7D%0A%0A
+    @Subscribe%0A    public void openTopic(OpenTopicEvent e) %7B%0A        Intent i = new Intent(this, TopicActivity_.class);%0A        i.putExtra(%22topic%22, e.getTopic());%0A        startActivity(i);%0A        overrideAnimationBeforeStartActivity();%0A        Log.d(%22fragment%22, %22open topic%22);%0A%0A    %7D%0A%0A
 %0A%7D%0A

Fix OpenTopic Bug in UserActivity