mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 10:46:53 -04:00
Fix provider domain when updating from 2.2
(cherry picked from commit f37cf86)
This commit is contained in:
parent
2e68ab949d
commit
3e4b8be1fc
@ -36,6 +36,7 @@ import org.kiwix.kiwixmobile.data.local.entity.LibraryDatabaseEntity;
|
||||
import org.kiwix.kiwixmobile.data.local.entity.NetworkLanguageDatabaseEntity;
|
||||
import org.kiwix.kiwixmobile.data.local.entity.RecentSearch;
|
||||
import org.kiwix.kiwixmobile.library.entity.LibraryNetworkEntity;
|
||||
import org.kiwix.kiwixmobile.utils.UpdateUtils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileNotFoundException;
|
||||
@ -52,7 +53,7 @@ import static org.kiwix.kiwixmobile.utils.Constants.TAG_KIWIX;
|
||||
@Singleton
|
||||
public class KiwixDatabase extends SquidDatabase {
|
||||
|
||||
private static final int VERSION = 16;
|
||||
private static final int VERSION = 17;
|
||||
private final Context context;
|
||||
|
||||
@Inject
|
||||
@ -125,6 +126,8 @@ public class KiwixDatabase extends SquidDatabase {
|
||||
tryAddColumn(Bookmark.ZIM_FILE_PATH);
|
||||
tryAddColumn(Bookmark.FAVICON);
|
||||
migrateBookmarksVersion16();
|
||||
case 16:
|
||||
new BookmarksDao(this).processBookmark(UpdateUtils::reformatProviderUrl);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ package org.kiwix.kiwixmobile.data.local.dao;
|
||||
|
||||
import com.yahoo.squidb.data.SquidCursor;
|
||||
import com.yahoo.squidb.sql.Query;
|
||||
import com.yahoo.squidb.sql.Update;
|
||||
|
||||
import org.kiwix.kiwixmobile.data.ZimContentProvider;
|
||||
import org.kiwix.kiwixmobile.data.local.KiwixDatabase;
|
||||
@ -107,4 +108,23 @@ public class BookmarksDao {
|
||||
kiwixDatabase.deleteWhere(Bookmark.class, Bookmark.BOOKMARK_URL.eq(bookmark.getBookmarkUrl())
|
||||
.and(Bookmark.ZIM_ID.eq(bookmark.getZimId())));
|
||||
}
|
||||
|
||||
public void processBookmark(StringOperation operation) {
|
||||
try (SquidCursor<Bookmark> bookmarkCursor = kiwixDatabase.query(Bookmark.class,
|
||||
Query.select(Bookmark.ID, Bookmark.BOOKMARK_URL))) {
|
||||
while (bookmarkCursor.moveToNext()) {
|
||||
String url = bookmarkCursor.get(Bookmark.BOOKMARK_URL);
|
||||
url = operation.apply(url);
|
||||
if (url != null) {
|
||||
kiwixDatabase.update(Update.table(Bookmark.TABLE)
|
||||
.where(Bookmark.ID.eq(bookmarkCursor.get(Bookmark.ID)))
|
||||
.set(Bookmark.BOOKMARK_URL, url));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface StringOperation {
|
||||
String apply(String string);
|
||||
}
|
||||
}
|
||||
|
@ -141,6 +141,7 @@ import static org.kiwix.kiwixmobile.utils.Constants.TAG_CURRENT_TAB;
|
||||
import static org.kiwix.kiwixmobile.utils.Constants.TAG_FILE_SEARCHED;
|
||||
import static org.kiwix.kiwixmobile.utils.Constants.TAG_KIWIX;
|
||||
import static org.kiwix.kiwixmobile.utils.StyleUtils.dialogStyle;
|
||||
import static org.kiwix.kiwixmobile.utils.UpdateUtils.reformatProviderUrl;
|
||||
|
||||
public class MainActivity extends BaseActivity implements WebViewCallback,
|
||||
MainContract.View, BooksAdapter.OnItemClickListener {
|
||||
@ -1604,11 +1605,11 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
||||
JSONArray urls = new JSONArray(zimArticles);
|
||||
JSONArray positions = new JSONArray(zimPositions);
|
||||
int i = 0;
|
||||
getCurrentWebView().loadUrl(urls.getString(i));
|
||||
getCurrentWebView().loadUrl(reformatProviderUrl(urls.getString(i)));
|
||||
getCurrentWebView().setScrollY(positions.getInt(i));
|
||||
i++;
|
||||
for (; i < urls.length(); i++) {
|
||||
newTab(urls.getString(i));
|
||||
newTab(reformatProviderUrl(urls.getString(i)));
|
||||
getCurrentWebView().setScrollY(positions.getInt(i));
|
||||
}
|
||||
selectTab(currentTab);
|
||||
|
@ -17,6 +17,8 @@
|
||||
*/
|
||||
package org.kiwix.kiwixmobile.utils;
|
||||
|
||||
import org.kiwix.kiwixmobile.BuildConfig;
|
||||
|
||||
public final class Constants {
|
||||
|
||||
public static final String TAG_KIWIX = "kiwix";
|
||||
@ -125,4 +127,8 @@ public final class Constants {
|
||||
// Notification Channel Constants
|
||||
public static final String ONGOING_DOWNLOAD_CHANNEL_ID = "ongoing_downloads_channel_id";
|
||||
|
||||
public static final String OLD_PROVIDER_DOMAIN = "org.kiwix.zim.base";
|
||||
|
||||
public static final String NEW_PROVIDER_DOMAIN = BuildConfig.APPLICATION_ID + ".zim.base";
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,10 @@
|
||||
package org.kiwix.kiwixmobile.utils;
|
||||
|
||||
import static org.kiwix.kiwixmobile.utils.Constants.NEW_PROVIDER_DOMAIN;
|
||||
import static org.kiwix.kiwixmobile.utils.Constants.OLD_PROVIDER_DOMAIN;
|
||||
|
||||
public class UpdateUtils {
|
||||
public static String reformatProviderUrl(String url) {
|
||||
return url.replace(OLD_PROVIDER_DOMAIN, NEW_PROVIDER_DOMAIN);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user