package com.joker.fourfun.ui;

import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.RadioButton;

import com.joker.fourfun.R;
import com.joker.fourfun.base.BaseMvpFragment;
import com.joker.fourfun.ui.fragment.PictureFragment;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import me.yokeyword.fragmentation.SupportActivity;

public class MainActivity extends SupportActivity {
    @BindView(R.id.fl_content)
    FrameLayout mFlContent;
    @BindView(R.id.rb_pic)
    RadioButton mRbPic;
    @BindView(R.id.rb_article)
    RadioButton mRbArticle;
    @BindView(R.id.rb_music)
    RadioButton mRbMusic;
    @BindView(R.id.rb_movie)
    RadioButton mRbMovie;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        ButterKnife.bind(this);
        BaseMvpFragment[] mFragments = new BaseMvpFragment[2];
        if (savedInstanceState == null) {
            mFragments[0] = new PictureFragment();
            loadMultipleRootFragment(getContainerId(), 0, mFragments[0]);
        } else {
            mFragments[0] = findFragment(PictureFragment.class);
        }
    }

    protected int getContainerId() {
        return R.id.fl_content;
    }

    @OnClick({R.id.rb_pic, R.id.rb_article, R.id.rb_music, R.id.rb_movie})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.rb_pic:
                break;
            case R.id.rb_article:
                break;
            case R.id.rb_music:
                break;
            case R.id.rb_movie:
                break;
        }
    }
}

@@ -315,16 +315,67 @@
 ragment;
+%0Aimport com.joker.fourfun.ui.fragment.ReadFragment;
 %0A%0Aimport
@@ -561,16 +561,174 @@
 ivity %7B%0A
+    public static final int FIRST = 0;%0A    public static final int SECOND = 1;%0A    public static final int THIRD = 2;%0A    public static final int FOURTH = 3;%0A
     @Bin
@@ -997,16 +997,99 @@
 RbMovie;
+%0A    private int showingPosition = FIRST;%0A    private BaseMvpFragment%5B%5D mFragments;
 %0A%0A    @O
@@ -1359,34 +1359,16 @@
 %0A       
- BaseMvpFragment%5B%5D
  mFragme
@@ -1397,12 +1397,45 @@
 ent%5B
-2
+3
 %5D;%0A
+        mRbPic.setChecked(true);%0A
     
@@ -1491,25 +1491,29 @@
  mFragments%5B
-0
+FIRST
 %5D = new Pict
@@ -1527,16 +1527,69 @@
 ment();%0A
+            mFragments%5BSECOND%5D = new ReadFragment();%0A
         
@@ -1635,17 +1635,21 @@
 erId(), 
-0
+FIRST
 , mFragm
@@ -1653,17 +1653,41 @@
 agments%5B
-0
+FIRST%5D, mFragments%5BSECOND
 %5D);%0A    
@@ -1722,17 +1722,21 @@
 agments%5B
-0
+FIRST
 %5D = find
@@ -1764,24 +1764,91 @@
 ent.class);%0A
+            mFragments%5BSECOND%5D = findFragment(ReadFragment.class);%0A
         %7D%0A  
@@ -2098,24 +2098,61 @@
 .id.rb_pic:%0A
+                showFragment(FIRST);%0A
             
@@ -2196,16 +2196,54 @@
 rticle:%0A
+                showFragment(SECOND);%0A
         
@@ -2383,10 +2383,236 @@
 %7D%0A    %7D%0A
-%7D
 %0A
+    private void showFragment(int position) %7B%0A        if (position != showingPosition) %7B%0A            showHideFragment(mFragments%5Bposition%5D, mFragments%5BshowingPosition%5D);%0A            showingPosition = position;%0A        %7D%0A    %7D%0A%7D

refactor code