package net.squanchy;

import android.app.Activity;
import android.app.Notification;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;

import java.util.ArrayList;
import java.util.List;

import net.squanchy.eventdetails.domain.view.ExperienceLevel;
import net.squanchy.notification.NotificationCreator;
import net.squanchy.notification.NotificationsIntentService;
import net.squanchy.notification.Notifier;
import net.squanchy.schedule.domain.view.Event;
import net.squanchy.schedule.domain.view.Place;
import net.squanchy.speaker.domain.view.Speaker;
import net.squanchy.support.lang.Optional;

import org.joda.time.LocalDateTime;

@SuppressWarnings("checkstyle:magicnumber")
public class DebugActivity extends Activity {

    private NotificationCreator notificationCreator;

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

        Button buttonSingleNotification = (Button) findViewById(R.id.button_test_single_notification);
        buttonSingleNotification.setOnClickListener(view -> testSingleNotification());

        Button buttonMultipleNotifications = (Button) findViewById(R.id.button_test_multiple_notifications);
        buttonMultipleNotifications.setOnClickListener(view -> testMultipleNotifications());

        Button buttonService = (Button) findViewById(R.id.button_test_service);
        buttonService.setOnClickListener(view -> testService());

        notificationCreator = new NotificationCreator(this);
    }

    private void testSingleNotification() {
        createAndNotifyTalksCount(1);
    }

    private void testMultipleNotifications() {
        createAndNotifyTalksCount(3);
    }

    private void createAndNotifyTalksCount(int count) {
        List<Event> events = new ArrayList<>();
        for (int i = 0; i < count; i++) {
            events.add(createTestEvent(i));
        }
        List<Notification> notifications = notificationCreator.createFrom(events);

        Notifier notifier = Notifier.from(this);
        notifier.showNotifications(notifications);
    }

    private Event createTestEvent(int id) {
        LocalDateTime start = new LocalDateTime().plusMinutes(5);
        LocalDateTime end = new LocalDateTime().plusMinutes(45);
        return Event.create(
                String.valueOf(id),
                id,
                "1",
                start,
                end,
                "A very interesting talk",
                createPlace(),
                Optional.of(ExperienceLevel.ADVANCED),
                createTalkSpeakers(),
                Event.Type.TALK,
                true,
                Optional.absent(),
                Optional.absent()
        );
    }

    private Optional<Place> createPlace() {
        Place place = Place.create("1", "That room over there", Optional.absent());
        return Optional.of(place);
    }

    private List<Speaker> createTalkSpeakers() {
        List<Speaker> speakers = new ArrayList<>(2);
        speakers.add(Speaker.create(
                "1",
                101L,
                "Ajeje Brazorf",
                "https://yt3.ggpht.com/-d35Rq8vqvmE/AAAAAAAAAAI/AAAAAAAAAAA/zy1VyiRTNec/s900-c-k-no-mo-rj-c0xffffff/photo.jpg"
                )
        );
        return speakers;
    }

    private void testService() {
        Intent serviceIntent = new Intent(this, NotificationsIntentService.class);
        startService(serviceIntent);
    }
}

@@ -105,24 +105,55 @@
 ent.Intent;%0A
+import android.graphics.Color;%0A
 import andro
@@ -247,16 +247,41 @@
 il.List;
+%0Aimport java.util.Random;
 %0A%0Aimport
@@ -586,24 +586,72 @@
 view.Place;%0A
+import net.squanchy.schedule.domain.view.Track;%0A
 import net.s
@@ -2865,23 +2865,32 @@
 ptional.
-absent(
+of(createTrack()
 )%0A      
@@ -2893,32 +2893,33 @@
       );%0A    %7D%0A%0A
+%0A
     private Opti
@@ -3439,24 +3439,24 @@
 %0A        );%0A
-
         retu
@@ -3467,32 +3467,925 @@
 peakers;%0A    %7D%0A%0A
+    private Track createTrack() %7B%0A        return Track.create(%0A                %220%22,%0A                %22UI%22,%0A                Optional.of(generateColor()),%0A                Optional.of(generateColor()),%0A                Optional.of(%22gs://droidcon-italy-2017.appspot.com/tracks/0.webp%22)%0A                );%0A    %7D%0A%0A    public int getRandomColor() %7B%0A        Random rnd = new Random();%0A        return Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));%0A    %7D%0A%0A    private String generateColor() %7B%0A        Random r = new Random();%0A        final char%5B%5D hex = %7B'0', '1', '2', '3', '4', '5', '6', '7',%0A                '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'%7D;%0A        char%5B%5D s = new char%5B7%5D;%0A        int n = r.nextInt(0x1000000);%0A%0A        s%5B0%5D = '#';%0A        for (int i = 1; i %3C 7; i++) %7B%0A            s%5Bi%5D = hex%5Bn & 0xf%5D;%0A            n %3E%3E= 4;%0A        %7D%0A        return new String(s);%0A    %7D%0A%0A
     private void

Create debug track with random accent color