|
3 | 3 | import android.content.Context;
|
4 | 4 | import android.content.SharedPreferences;
|
5 | 5 | import android.preference.PreferenceManager;
|
| 6 | +import android.util.Log; |
6 | 7 |
|
7 | 8 | import static com.phikal.regex.Util.COUNT;
|
8 | 9 | import static com.phikal.regex.Util.PROGRESS;
|
9 | 10 |
|
10 | 11 | public class Progress {
|
11 | 12 |
|
12 |
| - private static final int MAX_TASKS = 12; |
13 |
| - private static final double A = 1, Q = 1 / 2; |
| 13 | + private static final float Q = 0.01f; |
14 | 14 |
|
15 | 15 | private String name;
|
16 |
| - private Context ctx; |
| 16 | + private transient Context ctx; |
17 | 17 | private double difficulty;
|
18 | 18 | private int rounds;
|
19 | 19 |
|
20 | 20 | public Progress(Context ctx, String name) {
|
21 | 21 | SharedPreferences pm = PreferenceManager.getDefaultSharedPreferences(ctx);
|
22 | 22 |
|
23 |
| - this.difficulty = pm.getFloat(name + PROGRESS, 0f); |
| 23 | + this.difficulty = pm.getFloat(name + PROGRESS, Q); |
24 | 24 | this.rounds = pm.getInt(name + COUNT, 1);
|
25 | 25 |
|
26 | 26 | this.ctx = ctx;
|
27 | 27 | this.name = name;
|
| 28 | + Log.d("progress", name + ": " + difficulty + "/" + rounds); |
28 | 29 | }
|
29 | 30 |
|
30 |
| - public Progress(Context ctx, String name, Progress p) { |
31 |
| - this.difficulty = p.getDifficutly() + A * Math.pow(Q, p.getRound()); |
32 |
| - this.rounds = 1; |
33 |
| - this.ctx = ctx; |
| 31 | + private Progress(String name, Context ctx, double difficulty, int rounds) { |
34 | 32 | this.name = name;
|
| 33 | + this.ctx = ctx; |
| 34 | + this.difficulty = difficulty; |
| 35 | + this.rounds = rounds; |
35 | 36 | }
|
36 | 37 |
|
37 |
| - public int getMaxTasks() { |
38 |
| - return (int) (Math.pow(difficulty, 2) * MAX_TASKS); |
| 38 | + public Progress next(double factor) { |
| 39 | + return new Progress(name, ctx, |
| 40 | + difficulty + factor * Q * Math.pow(1 / (Q + 1), rounds), |
| 41 | + rounds + 1); |
39 | 42 | }
|
40 | 43 |
|
41 | 44 | public double getDifficutly() {
|
|
0 commit comments