Skip to content

Commit

Permalink
Updates to exported settings for arisuchan
Browse files Browse the repository at this point in the history
v4.8.0
  • Loading branch information
Adamantcheese committed Sep 30, 2019
1 parent 266d9ad commit 8265adb
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Kuroba/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ android {
//or if there are big application level changes like tearing out/adding major features
//bump the PATCH (ZZ) version otherwise, for anything small
int major = 4
int minor = 7
int patch = 1
int minor = 8
int patch = 0

/**
* ------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,6 @@ public void deleteBoard(Board board) throws SQLException {
if (!(split.length == 2 && Integer.parseInt(split[0]) == board.site.id()
&& split[1].equals(board.code))) {
keep.add(uniqueId);
break;
}
}
filter.boards = TextUtils.join(",", keep);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

@Nullable
public String getCode() {
return code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ public boolean isEnabled() {
return enabled;
}

public void setEnabled(boolean enabled) {
this.enabled = enabled;
}

public int getType() {
return type;
}
Expand All @@ -95,6 +99,10 @@ public String getBoards() {
return boards;
}

public void setBoards(String boards) {
this.boards = boards;
}

public int getAction() {
return action;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class ImportExportRepository {

// Don't forget to change this when changing any of the Export models.
// Also, don't forget to handle the change in the onUpgrade or onDowngrade methods
public static final int CURRENT_EXPORT_SETTINGS_VERSION = 4;
public static final int CURRENT_EXPORT_SETTINGS_VERSION = 5;

private DatabaseManager databaseManager;
private DatabaseHelper databaseHelper;
Expand Down Expand Up @@ -368,6 +368,40 @@ private ExportedAppSettings onUpgrade(int version, ExportedAppSettings appSettin
deleteExportedSite(chan8, appSettings);
}
}

if (version < 5) {
List<ExportedBoard> toRemove = new ArrayList<>();
for (ExportedSite site : appSettings.getExportedSites()) {
if (site.getSiteId() == 3) {
for (ExportedBoard board : appSettings.getExportedBoards()) {
if (board.getSiteId() == site.getSiteId()) {
if (board.getCode().equals("cyb")
|| board.getCode().equals("feels")
|| board.getCode().equals("x")
|| board.getCode().equals("z")) {
toRemove.add(board);
continue;
}
if(board.getCode().equals("art")) {
board.setName("art and creative");
}
if(board.getCode().equals("tech")) {
board.setName("technology");
}
if(board.getCode().equals("Δ")) {
board.setName("shape your world");
}
if(board.getCode().equals("ru")) {
board.setName("Киберпанк");
}
}
}
}
}
for(ExportedBoard board : toRemove) {
deleteExportedBoard(board, appSettings);
}
}
return appSettings;
}

Expand Down Expand Up @@ -623,4 +657,69 @@ private void deleteExportedSite(ExportedSite site, ExportedAppSettings appSettin
//site (also removes pins and loadables)
appSettings.getExportedSites().remove(site);
}

private void deleteExportedBoard(ExportedBoard board, ExportedAppSettings appSettings) {
ExportedSite exportedSite = null;
for(ExportedSite site : appSettings.getExportedSites()) {
if(site.getSiteId() == board.getSiteId()) {
exportedSite = site;
break;
}
}
if(exportedSite == null) return;

//filters
for (ExportedFilter filter : appSettings.getExportedFilters()) {
if (filter.isAllBoards() || TextUtils.isEmpty(filter.getBoards())) {
continue;
}

List<String> keep = new ArrayList<>();
for (String uniqueId : filter.getBoards().split(",")) {
String[] split = uniqueId.split(":");
if (!(split.length == 2 && Integer.parseInt(split[0]) == board.getSiteId()
&& split[1].equals(board.getCode()))) {
keep.add(uniqueId);
}
}
filter.setBoards(TextUtils.join(",", keep));
//disable, but don't delete filters in case they're still wanted
if (TextUtils.isEmpty(filter.getBoards())) {
filter.setEnabled(true);
}
}

//loadables for saved threads
List<ExportedLoadable> loadables = new ArrayList<>();
for (ExportedPin pin : exportedSite.getExportedPins()) {
if (pin.getExportedLoadable().getBoardCode().equals(board.getCode())) {
loadables.add(pin.getExportedLoadable());
}
}

if (!loadables.isEmpty()) {
List<ExportedSavedThread> savedThreadToDelete = new ArrayList<>();
for (ExportedLoadable loadable : loadables) {
//saved threads
for (ExportedSavedThread savedThread : appSettings.getExportedSavedThreads()) {
if (loadable.getLoadableId() == savedThread.getLoadableId()) {
savedThreadToDelete.add(savedThread);
}
}
}
appSettings.getExportedSavedThreads().removeAll(savedThreadToDelete);
}

//post hides
List<ExportedPostHide> hidesToDelete = new ArrayList<>();
for (ExportedPostHide hide : appSettings.getExportedPostHides()) {
if (hide.getBoard().equals(board.getCode())) {
hidesToDelete.add(hide);
}
}
appSettings.getExportedPostHides().removeAll(hidesToDelete);

//board itself
appSettings.getExportedBoards().remove(board);
}
}

0 comments on commit 8265adb

Please sign in to comment.