package com.basgeekball.screenshotsnanny;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import com.basgeekball.screenshotsnanny.activityassistant.ActivityCounter;
import com.basgeekball.screenshotsnanny.core.Constants;
import com.basgeekball.screenshotsnanny.demo.R;
import com.basgeekball.screenshotsnanny.demo.activities.AccountActivity;
import com.basgeekball.screenshotsnanny.demo.activities.MainActivity;
import com.basgeekball.screenshotsnanny.demo.activities.MapsActivity;
import com.basgeekball.screenshotsnanny.demo.activities.NetworkActivity;
import com.basgeekball.screenshotsnanny.demo.activities.SecondActivity;
import com.basgeekball.screenshotsnanny.demo.models.AccountManager;
import com.basgeekball.screenshotsnanny.demo.network.GithubService;
import com.basgeekball.screenshotsnanny.helper.Callback;
import com.basgeekball.screenshotsnanny.helper.LanguageSwitcher;
import com.basgeekball.screenshotsnanny.helper.ParameterizedCallback;
import com.basgeekball.screenshotsnanny.helper.PowerChanger;
import com.basgeekball.screenshotsnanny.helper.ResourceReader;
import com.basgeekball.screenshotsnanny.mockserver.MockServerWrapper;

import static com.basgeekball.screenshotsnanny.activityassistant.ActivityLauncher.startActivityAndTakeScreenshot;
import static com.basgeekball.screenshotsnanny.activityassistant.ActivityLauncher.startActivityContainsMapAndTakeScreenshot;

public class ScreenshotsPrimeActivity extends AppCompatActivity {

    private MockServerWrapper mServer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_screenshots_prime);

        // if you want to have screenshots contents in different language
        // LanguageSwitcher.change(this, "de");

        mServer = new MockServerWrapper();
        String response = ResourceReader.readFromRawResource(ScreenshotsPrimeActivity.this, R.raw.github_user);
        ParameterizedCallback changeUrlCallback = new ParameterizedCallback() {
            @Override
            public void execute(String value) {
                PowerChanger.changeFinalString(GithubService.class, "API_URL", value);
            }
        };
        mServer.start(changeUrlCallback, response);
    }

    @Override
    protected void onResume() {
        super.onResume();

        startActivityAndTakeScreenshot(MainActivity.class, new Callback() {
            @Override
            public void execute() {
                startActivity(new Intent(ScreenshotsPrimeActivity.this, MainActivity.class));
            }
        });

        startActivityAndTakeScreenshot(SecondActivity.class, new Callback() {
            @Override
            public void execute() {
                startActivity(SecondActivity.createIntent(ScreenshotsPrimeActivity.this, "London bridge is falling down"));
            }
        });

        startActivityAndTakeScreenshot(NetworkActivity.class, new Callback() {
            @Override
            public void execute() {
                startActivity(new Intent(ScreenshotsPrimeActivity.this, NetworkActivity.class));
            }
        });

        startActivityAndTakeScreenshot(AccountActivity.class, new Callback() {
            @Override
            public void execute() {
                AccountManager.create(getApplicationContext(), "Bruce Lee");
                AccountManager.update(getApplicationContext(), 1048576);
                startActivity(new Intent(ScreenshotsPrimeActivity.this, AccountActivity.class));
            }
        });

        startActivityContainsMapAndTakeScreenshot(MapsActivity.class, new Callback() {
            @Override
            public void execute() {
                startActivity(new Intent(ScreenshotsPrimeActivity.this, MapsActivity.class));
            }
        }, R.id.map);

        if (!ActivityCounter.isAnyActivityRunning) {
            Log.i(Constants.LOG_TAG, "⚙ Done.");
            mServer.stop();
            finish();
        }
    }
}

@@ -1767,78 +1767,141 @@
  // 
-if you want to have screenshots contents in different language
+Set up the screenshot fixture%0A%0A        // Set language (resources configuration) other than the default one if it's necessary
 %0A       
  // 
@@ -1896,19 +1896,16 @@
 %0A       
- //
  Languag
@@ -1947,42 +1947,133 @@
     
-mServer = new MockServerWrapper();
+// Set up the mock server%0A        mServer = new MockServerWrapper();%0A        // Read mock response(s) from resource directory
 %0A   
@@ -2327,24 +2327,187 @@
 ng value) %7B%0A
+                // The MockServer runs on arbitrary port each time%0A                // We have to change production's base URL to the MockServer URL via reflection%0A
             
@@ -2606,16 +2606,104 @@
      %7D;%0A
+        // Start mock server with canned response(s), it accepts response(s) as varargs%0A
         

Add comments to demo activity