package net.squanchy.contest;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import net.squanchy.R;
import net.squanchy.support.debug.DebugPreferences;

import io.reactivex.android.schedulers.AndroidSchedulers;

class ContestTester {

    private final Activity activity;
    private final DebugPreferences debugPreferences;

    ContestTester(Activity activity) {
        this.activity = activity;
        this.debugPreferences = new DebugPreferences(this.activity);
    }

    boolean testingEnabled() {
        return debugPreferences.contestTestingEnabled();
    }

    void appendDebugControls(ViewGroup viewGroup, ContestService contestService) {
        LayoutInflater factory = LayoutInflater.from(activity);
        View controlsContainer = factory.inflate(R.layout.view_contest_tester, viewGroup, false);
        viewGroup.addView(controlsContainer);

        controlsContainer.findViewById(R.id.contest_testing_add_one)
                .setOnClickListener(view -> unlockRandomAchievement(contestService));
    }

    private void unlockRandomAchievement(ContestService contestService) {
        contestService.addAchievement(String.valueOf(Math.random() * Integer.MAX_VALUE))
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe();
    }
}

@@ -147,16 +147,42 @@
 Group;%0A%0A
+import java.util.Random;%0A%0A
 import n
@@ -331,16 +331,86 @@
 ster %7B%0A%0A
+    private static final int MAX_ACHIEVEMENT_ID = Integer.MAX_VALUE;%0A%0A
     priv
@@ -490,16 +490,49 @@
 erences;
+%0A    private final Random random;
 %0A%0A    Co
@@ -663,24 +663,60 @@
 .activity);%0A
+        this.random = new Random();%0A
     %7D%0A%0A    b
@@ -1375,56 +1375,36 @@
 ent(
-String.valueOf(Math.random() * Integer.MAX_VALUE
+generateRandomAchievementId(
 ))%0A 
@@ -1496,11 +1496,136 @@
 );%0A    %7D
+%0A%0A    private String generateRandomAchievementId() %7B%0A        return String.valueOf(random.nextInt(MAX_ACHIEVEMENT_ID));%0A    %7D
 %0A%7D%0A

Fix issues in achievement ID generation