Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove random #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 8 additions & 16 deletions contents/ui/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@ QQC2.StackView {
onBlurChanged: Qt.callLater(loadImage);
onRefreshSignalChanged: refreshTimer.restart();
onSortingChanged: {
if (sorting != "random") {
currentPage = 1;
currentIndex = 0;
}
}

Component.onCompleted: refreshImage();
Expand Down Expand Up @@ -128,9 +126,7 @@ QQC2.StackView {

url += `sorting=${wallpaper.configuration.Sorting}&`

if (wallpaper.configuration.Sorting != "random") {
url += `page=${root.currentPage}&`
}
url += `page=${root.currentPage}&`

url += `atleast=${root.sourceSize.width}x${root.sourceSize.height}&`

Expand Down Expand Up @@ -175,18 +171,14 @@ QQC2.StackView {
function pickImage(d) {
if (d.data.length > 0) {
var index = 0;
if (wallpaper.configuration.Sorting != "random") {
index = root.currentIndex;
if (index > 24) {
root.currentPage += 1;
root.currentIndex = 0;
refreshTimer.restart();
return;
}
root.currentIndex += 1;
} else {
index = Math.floor(Math.random() * d.data.length);
index = root.currentIndex;
if (index > 24) {
root.currentPage += 1;
root.currentIndex = 0;
refreshTimer.restart();
return;
}
root.currentIndex += 1;
Comment on lines +174 to +181
Copy link
Author

@chrisemke chrisemke Nov 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, but since we're always going to get the wallpaper from page 1 starting from 0, this part needs to be within the if condition

Suggested change
index = root.currentIndex;
if (index > 24) {
root.currentPage += 1;
root.currentIndex = 0;
refreshTimer.restart();
return;
}
root.currentIndex += 1;
if (wallpaper.configuration.Sorting != "random") {
index = root.currentIndex;
if (index > 24) {
root.currentPage += 1;
root.currentIndex = 0;
refreshTimer.restart();
return;
}
root.currentIndex += 1;
} else {
root.currentPage = 1;
root.currentIndex = 0;
}

const imageObj = d.data[index] || {};
root.currentUrl = imageObj.path;
root.currentPage = d.meta.current_page;
Expand Down