Skip to content

Commit

Permalink
Fix for "on/off all styles" function
Browse files Browse the repository at this point in the history
  • Loading branch information
Pmmlabs committed Jul 29, 2014
1 parent 74f4ae8 commit 0e8f99c
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions src/ru/pmmlabs/stylish/StylishAddonService.java
Original file line number Diff line number Diff line change
Expand Up @@ -581,14 +581,31 @@ protected void deleteStyle(String styleName) throws RemoteException {

protected void switchStateAllStyles() throws RemoteException {
AddonEnabled = !AddonEnabled;
if (currentStyles != null) { // apply changes to current tab
IWebView webView = browser.tabs.getCurrent().getWebView();
HashMap<String, Boolean> cStyles = currentStyles.get(webView.getId());
for (final String style : cStyles.keySet())
if (cStyles.get(style)) // for all enabled styles on current page, inject or remove css
for (int i=0;i<10;i++)
if (AddonEnabled) injectCSS(webView, style+i);
else removeCSS(webView, styleName2fileName(style));
}

SQLiteDatabase db = sbHelper.getReadableDatabase();
int[] getalltabs = browser.tabs.getAllTabIds();
if (getalltabs != null && currentStyles != null)
for (int tab_id : getalltabs) { // for every tab
IWebView webview = browser.tabs.get(tab_id).getWebView();
HashMap<String, Boolean> tabStyles = currentStyles.get(webview.getId());
if (tabStyles != null)
for (final String style : tabStyles.keySet()) //for every style in tab
if (AddonEnabled) {
Cursor cursor = db.query(StylesTable.TABLE_NAME,
new String[] { StylesTable.COLUMN_NAME_FILENAME }, // The columns to return
StylesTable.COLUMN_NAME_NAME + " = ?",
new String[] {style},
null,
null,
null
);
if (cursor.moveToFirst()) {
do injectCSS(webview, cursor.getString(cursor.getColumnIndexOrThrow(StylesTable.COLUMN_NAME_FILENAME)));
while (cursor.moveToNext());
}
cursor.close();
}
else removeCSS(webview, styleName2fileName(style));
}
}
}

0 comments on commit 0e8f99c

Please # to comment.