Skip to content

Commit dbeed45

Browse files
committed
Reworked Progress class
1 parent 9abd38e commit dbeed45

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

app/src/main/java/com/phikal/regex/models/Progress.java

+13-10
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,42 @@
33
import android.content.Context;
44
import android.content.SharedPreferences;
55
import android.preference.PreferenceManager;
6+
import android.util.Log;
67

78
import static com.phikal.regex.Util.COUNT;
89
import static com.phikal.regex.Util.PROGRESS;
910

1011
public class Progress {
1112

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;
1414

1515
private String name;
16-
private Context ctx;
16+
private transient Context ctx;
1717
private double difficulty;
1818
private int rounds;
1919

2020
public Progress(Context ctx, String name) {
2121
SharedPreferences pm = PreferenceManager.getDefaultSharedPreferences(ctx);
2222

23-
this.difficulty = pm.getFloat(name + PROGRESS, 0f);
23+
this.difficulty = pm.getFloat(name + PROGRESS, Q);
2424
this.rounds = pm.getInt(name + COUNT, 1);
2525

2626
this.ctx = ctx;
2727
this.name = name;
28+
Log.d("progress", name + ": " + difficulty + "/" + rounds);
2829
}
2930

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) {
3432
this.name = name;
33+
this.ctx = ctx;
34+
this.difficulty = difficulty;
35+
this.rounds = rounds;
3536
}
3637

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);
3942
}
4043

4144
public double getDifficutly() {

0 commit comments

Comments
 (0)