Skip to content

Commit

Permalink
* prevent FC if there are no profiles set
Browse files Browse the repository at this point in the history
  • Loading branch information
mikepenz committed Mar 7, 2015
1 parent b4bd523 commit 3938d99
Showing 1 changed file with 58 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -578,69 +578,71 @@ public Result build() {
*
*/
protected void calculateProfiles() {
IProfile[] previousActiveProfiles = new IProfile[]{
mCurrentProfile,
mProfileFirst,
mProfileSecond,
mProfileThird
};

IProfile[] newActiveProfiles = new IProfile[4];
Stack<IProfile> unusedProfiles = new Stack<>();

// try to keep existing active profiles in the same positions
for (int i = 0; i < mProfiles.size(); i++) {
IProfile p = mProfiles.get(i);
if (p.isSelectable()) {
boolean used = false;
for (int j = 0; j < 4; j++) {
if (previousActiveProfiles[j] == p) {
newActiveProfiles[j] = p;
used = true;
break;
if (mProfiles != null) {
IProfile[] previousActiveProfiles = new IProfile[]{
mCurrentProfile,
mProfileFirst,
mProfileSecond,
mProfileThird
};

IProfile[] newActiveProfiles = new IProfile[4];
Stack<IProfile> unusedProfiles = new Stack<>();

// try to keep existing active profiles in the same positions
for (int i = 0; i < mProfiles.size(); i++) {
IProfile p = mProfiles.get(i);
if (p.isSelectable()) {
boolean used = false;
for (int j = 0; j < 4; j++) {
if (previousActiveProfiles[j] == p) {
newActiveProfiles[j] = p;
used = true;
break;
}
}
if (!used) {
unusedProfiles.push(p);
}
}
if (!used) {
unusedProfiles.push(p);
}
}
}

Stack<IProfile> activeProfiles = new Stack<>();
// try to fill the gaps with new available profiles
for (int i = 0; i < 4; i++) {
if (newActiveProfiles[i] != null) {
activeProfiles.push(newActiveProfiles[i]);
} else if (!unusedProfiles.isEmpty()) {
activeProfiles.push(unusedProfiles.pop());
Stack<IProfile> activeProfiles = new Stack<>();
// try to fill the gaps with new available profiles
for (int i = 0; i < 4; i++) {
if (newActiveProfiles[i] != null) {
activeProfiles.push(newActiveProfiles[i]);
} else if (!unusedProfiles.isEmpty()) {
activeProfiles.push(unusedProfiles.pop());
}
}
}

Stack<IProfile> reversedActiveProfiles = new Stack<IProfile>();
while (!activeProfiles.empty()) {
reversedActiveProfiles.push(activeProfiles.pop());
}
Stack<IProfile> reversedActiveProfiles = new Stack<IProfile>();
while (!activeProfiles.empty()) {
reversedActiveProfiles.push(activeProfiles.pop());
}

// reassign active profiles
if (reversedActiveProfiles.isEmpty()) {
mCurrentProfile = null;
} else {
mCurrentProfile = reversedActiveProfiles.pop();
}
if (reversedActiveProfiles.isEmpty()) {
mProfileFirst = null;
} else {
mProfileFirst = reversedActiveProfiles.pop();
}
if (reversedActiveProfiles.isEmpty()) {
mProfileSecond = null;
} else {
mProfileSecond = reversedActiveProfiles.pop();
}
if (reversedActiveProfiles.isEmpty()) {
mProfileThird = null;
} else {
mProfileThird = reversedActiveProfiles.pop();
// reassign active profiles
if (reversedActiveProfiles.isEmpty()) {
mCurrentProfile = null;
} else {
mCurrentProfile = reversedActiveProfiles.pop();
}
if (reversedActiveProfiles.isEmpty()) {
mProfileFirst = null;
} else {
mProfileFirst = reversedActiveProfiles.pop();
}
if (reversedActiveProfiles.isEmpty()) {
mProfileSecond = null;
} else {
mProfileSecond = reversedActiveProfiles.pop();
}
if (reversedActiveProfiles.isEmpty()) {
mProfileThird = null;
} else {
mProfileThird = reversedActiveProfiles.pop();
}
}
}

Expand Down

0 comments on commit 3938d99

Please sign in to comment.