Skip to content

Commit 598af81

Browse files
authored
Merge pull request #2552 from kiwix/feature/macgills/2545-tab-restoration
#2545 New Tabs & recreation is loading home page on other tabs
2 parents 8953853 + f3ce4f9 commit 598af81

File tree

2 files changed

+11
-20
lines changed

2 files changed

+11
-20
lines changed

app/src/main/java/org/kiwix/kiwixmobile/nav/destination/reader/KiwixReaderFragment.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,9 @@ class KiwixReaderFragment : CoreReaderFragment() {
251251
val zimFile = settings.getString(TAG_CURRENT_FILE, null)
252252

253253
if (zimFile != null) {
254-
openZimFile(File(zimFile))
254+
if (zimReaderContainer.zimFile == null) {
255+
openZimFile(File(zimFile))
256+
}
255257
} else {
256258
getCurrentWebView().snack(R.string.zim_not_opened)
257259
}

core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.java

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ private void newTabInBackground(String url) {
778778
private KiwixWebView newTab(String url, boolean selectTab) {
779779
KiwixWebView webView = initalizeWebView(url);
780780
webViewList.add(webView);
781-
if(selectTab) {
781+
if (selectTab) {
782782
selectTab(webViewList.size() - 1);
783783
}
784784
tabsAdapter.notifyDataSetChanged();
@@ -964,7 +964,6 @@ private boolean requestExternalStorageWritePermissionForNotes() {
964964
@SuppressWarnings("SameReturnValue")
965965
@OnLongClick(R2.id.bottom_toolbar_bookmark)
966966
boolean goToBookmarks() {
967-
saveTabStates();
968967
CoreMainActivity parentActivity = (CoreMainActivity) requireActivity();
969968
parentActivity.navigate(parentActivity.getBookmarksFragmentResId());
970969
return true;
@@ -1205,7 +1204,6 @@ private void updateBottomToolbarVisibility() {
12051204
}
12061205

12071206
private void goToSearch(boolean isVoice) {
1208-
saveTabStates();
12091207
openSearch("", false, isVoice);
12101208
}
12111209

@@ -1235,7 +1233,6 @@ private void startIntentBasedOnAction(Intent intent) {
12351233
break;
12361234
case Intent.ACTION_VIEW:
12371235
if (intent.getType() == null || !intent.getType().equals("application/octet-stream")) {
1238-
saveTabStates();
12391236
String searchString =
12401237
intent.getData() == null ? "" : intent.getData().getLastPathSegment();
12411238
openSearch(searchString, false, false);
@@ -1249,7 +1246,6 @@ private void openSearch(String searchString, Boolean isOpenedFromTabView, Boolea
12491246
}
12501247

12511248
private void goToSearchWithText(Intent intent) {
1252-
saveTabStates();
12531249
String searchString = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
12541250
? intent.getStringExtra(Intent.EXTRA_PROCESS_TEXT)
12551251
: "";
@@ -1570,21 +1566,14 @@ protected void restoreTabs(@Nullable String zimArticles, @Nullable String zimPos
15701566
try {
15711567
JSONArray urls = new JSONArray(zimArticles);
15721568
JSONArray positions = new JSONArray(zimPositions);
1573-
int i = 0;
1574-
// tabs are already restored if the webViewList includes more tabs than the default
1575-
if (webViewList.size() == 1) {
1576-
getCurrentWebView().setScrollY(positions.getInt(0));
1577-
i++;
1578-
while (i < urls.length()) {
1579-
newTab(UpdateUtils.reformatProviderUrl(urls.getString(i)));
1580-
safelyGetWebView(i).setScrollY(positions.getInt(i));
1581-
i++;
1582-
}
1569+
webViewList.clear();
1570+
currentWebViewIndex=0;
1571+
tabsAdapter.notifyItemRemoved(0);
1572+
tabsAdapter.notifyDataSetChanged();
1573+
for (int i = 0; i < urls.length(); i++) {
1574+
newTab(UpdateUtils.reformatProviderUrl(urls.getString(i)), i == currentTab)
1575+
.setScrollY(positions.getInt(i));
15831576
}
1584-
selectTab(currentTab);
1585-
safelyGetWebView(currentTab)
1586-
.loadUrl(UpdateUtils.reformatProviderUrl(urls.getString(currentTab)));
1587-
getCurrentWebView().setScrollY(positions.getInt(currentTab));
15881577
} catch (JSONException e) {
15891578
Log.w(TAG_KIWIX, "Kiwix shared preferences corrupted", e);
15901579
ContextExtensionsKt.toast(getActivity(), "Could not restore tabs.", Toast.LENGTH_LONG);

0 commit comments

Comments
 (0)