@@ -778,7 +778,7 @@ private void newTabInBackground(String url) {
778
778
private KiwixWebView newTab (String url , boolean selectTab ) {
779
779
KiwixWebView webView = initalizeWebView (url );
780
780
webViewList .add (webView );
781
- if (selectTab ) {
781
+ if (selectTab ) {
782
782
selectTab (webViewList .size () - 1 );
783
783
}
784
784
tabsAdapter .notifyDataSetChanged ();
@@ -964,7 +964,6 @@ private boolean requestExternalStorageWritePermissionForNotes() {
964
964
@ SuppressWarnings ("SameReturnValue" )
965
965
@ OnLongClick (R2 .id .bottom_toolbar_bookmark )
966
966
boolean goToBookmarks () {
967
- saveTabStates ();
968
967
CoreMainActivity parentActivity = (CoreMainActivity ) requireActivity ();
969
968
parentActivity .navigate (parentActivity .getBookmarksFragmentResId ());
970
969
return true ;
@@ -1205,7 +1204,6 @@ private void updateBottomToolbarVisibility() {
1205
1204
}
1206
1205
1207
1206
private void goToSearch (boolean isVoice ) {
1208
- saveTabStates ();
1209
1207
openSearch ("" , false , isVoice );
1210
1208
}
1211
1209
@@ -1235,7 +1233,6 @@ private void startIntentBasedOnAction(Intent intent) {
1235
1233
break ;
1236
1234
case Intent .ACTION_VIEW :
1237
1235
if (intent .getType () == null || !intent .getType ().equals ("application/octet-stream" )) {
1238
- saveTabStates ();
1239
1236
String searchString =
1240
1237
intent .getData () == null ? "" : intent .getData ().getLastPathSegment ();
1241
1238
openSearch (searchString , false , false );
@@ -1249,7 +1246,6 @@ private void openSearch(String searchString, Boolean isOpenedFromTabView, Boolea
1249
1246
}
1250
1247
1251
1248
private void goToSearchWithText (Intent intent ) {
1252
- saveTabStates ();
1253
1249
String searchString = Build .VERSION .SDK_INT >= Build .VERSION_CODES .M
1254
1250
? intent .getStringExtra (Intent .EXTRA_PROCESS_TEXT )
1255
1251
: "" ;
@@ -1570,21 +1566,14 @@ protected void restoreTabs(@Nullable String zimArticles, @Nullable String zimPos
1570
1566
try {
1571
1567
JSONArray urls = new JSONArray (zimArticles );
1572
1568
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 ));
1583
1576
}
1584
- selectTab (currentTab );
1585
- safelyGetWebView (currentTab )
1586
- .loadUrl (UpdateUtils .reformatProviderUrl (urls .getString (currentTab )));
1587
- getCurrentWebView ().setScrollY (positions .getInt (currentTab ));
1588
1577
} catch (JSONException e ) {
1589
1578
Log .w (TAG_KIWIX , "Kiwix shared preferences corrupted" , e );
1590
1579
ContextExtensionsKt .toast (getActivity (), "Could not restore tabs." , Toast .LENGTH_LONG );
0 commit comments