package com.kevoroid.andhackernews.ui.main;

import android.os.Bundle;
import androidx.fragment.app.Fragment;

import com.kevoroid.andhackernews.R;
import com.kevoroid.andhackernews.adapters.StoryListAdapter;
import com.kevoroid.andhackernews.ui.BaseActivity;
import com.kevoroid.andhackernews.ui.storydetail.StoryDetailFragment;
import com.kevoroid.andhackernews.ui.storydetail.StoryWebViewFragment;

public class MainActivity extends BaseActivity implements StoryListAdapter.StoryListAdapterInterface {

    public static final String TYPE_CONSTANT_STORY = "story";
    public static final String TYPE_CONSTANT_COMMENT = "comment";

	private Fragment mStoryListFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setTheme(R.style.AppTheme);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        if (mStoryListFragment == null) {
            mStoryListFragment = StoryListFragment.newInstance();
            addFragment(mStoryListFragment);
        } else {
            addFragment(mStoryListFragment);
        }
    }

	@Override
	public void onItemClick(String type, String title, String url, int commentsCount, String commentsList) {
		switch (type) {
			case TYPE_CONSTANT_STORY:
				replaceFragment(StoryWebViewFragment.newInstance(title, url, commentsCount, commentsList));
				break;
			case TYPE_CONSTANT_COMMENT:
				replaceFragment(StoryDetailFragment.newInstance(title, commentsCount, commentsList));
				break;
		}
	}

	@Override
	public void onBackPressed() {
		if (mStoryListFragment.isVisible()) {
			finish();
		} else {
			super.onBackPressed();
		}
	}
}

@@ -742,44 +742,8 @@
 ) %7B%0A
-        setTheme(R.style.AppTheme);%0A
     
@@ -835,193 +835,135 @@
 );%0A%0A
-        if (mStoryListFragment == null) %7B%0A            mStoryListFragment = StoryListFragment.newInstance();%0A            addFragment(mStoryListFragment);%0A        %7D else %7B%0A            add
+%09%09addMainFragment();%0A    %7D%0A%0A%09private void addMainFragment() %7B%0A%09%09mStoryListFragment = StoryListFragment.newInstance();%0A%09%09replace
 Frag
@@ -992,22 +992,9 @@
 t);%0A
-        %7D%0A    
+%09
 %7D%0A%0A%09

update to main activity fragment init calls