mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-12 00:48:29 -04:00
implemented snackbar - UNDO on closing tab
https://sourceforge.net/p/kiwix/feature-requests/232/
This commit is contained in:
parent
f47f9406f4
commit
3ade093fce
@ -23,6 +23,7 @@ dependencies {
|
|||||||
compile 'com.android.support:support-v4:22.2.0'
|
compile 'com.android.support:support-v4:22.2.0'
|
||||||
compile files("$buildDir/native-libs/native-libs.jar")
|
compile files("$buildDir/native-libs/native-libs.jar")
|
||||||
compile 'com.yahoo.squidb:squidb:2.0.0'
|
compile 'com.yahoo.squidb:squidb:2.0.0'
|
||||||
|
compile 'com.android.support:design:22.2.0'
|
||||||
compile 'com.yahoo.squidb:squidb-annotations:2.0.0'
|
compile 'com.yahoo.squidb:squidb-annotations:2.0.0'
|
||||||
apt 'com.yahoo.squidb:squidb-processor:2.0.0'
|
apt 'com.yahoo.squidb:squidb-processor:2.0.0'
|
||||||
// compile fileTree(dir: '.', include: 'content-libs.jar') // DO NOT REMOVE !!
|
// compile fileTree(dir: '.', include: 'content-libs.jar') // DO NOT REMOVE !!
|
||||||
|
@ -2,7 +2,8 @@
|
|||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical"
|
||||||
|
android:id="@+id/linearlayout_main">
|
||||||
|
|
||||||
<include layout="@layout/toolbar"/>
|
<include layout="@layout/toolbar"/>
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
<color name="secondary_text">#727272</color>
|
<color name="secondary_text">#727272</color>
|
||||||
<color name="icons">#212121</color>
|
<color name="icons">#212121</color>
|
||||||
<color name="divider">#B6B6B6</color>
|
<color name="divider">#B6B6B6</color>
|
||||||
|
<color name="white_undo">#FAFAFA</color>
|
||||||
<color name="gray_list_bg">#0d000000</color>
|
<color name="gray_list_bg">#0d000000</color>
|
||||||
<color name="drawer_background">#ffffff</color>
|
<color name="drawer_background">#ffffff</color>
|
||||||
<color name="selected_light">#0F000000</color>
|
<color name="selected_light">#0F000000</color>
|
||||||
|
@ -32,6 +32,7 @@ import android.os.Bundle;
|
|||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
import android.support.design.widget.Snackbar;
|
||||||
import android.support.v4.view.GravityCompat;
|
import android.support.v4.view.GravityCompat;
|
||||||
import android.support.v4.widget.DrawerLayout;
|
import android.support.v4.widget.DrawerLayout;
|
||||||
import android.support.v7.app.ActionBarDrawerToggle;
|
import android.support.v7.app.ActionBarDrawerToggle;
|
||||||
@ -63,10 +64,12 @@ import android.widget.Button;
|
|||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.RelativeLayout;
|
import android.widget.RelativeLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
@ -78,6 +81,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.kiwix.kiwixmobile.settings.Constants;
|
import org.kiwix.kiwixmobile.settings.Constants;
|
||||||
import org.kiwix.kiwixmobile.settings.KiwixSettingsActivity;
|
import org.kiwix.kiwixmobile.settings.KiwixSettingsActivity;
|
||||||
@ -169,6 +173,8 @@ public class KiwixMobileActivity extends AppCompatActivity
|
|||||||
|
|
||||||
// Initialized when onActionModeStarted is triggered.
|
// Initialized when onActionModeStarted is triggered.
|
||||||
private ActionMode mActionMode = null;
|
private ActionMode mActionMode = null;
|
||||||
|
private KiwixWebView tempForUndo;
|
||||||
|
private LinearLayout snackbarLayout;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActionModeStarted(ActionMode mode) {
|
public void onActionModeStarted(ActionMode mode) {
|
||||||
@ -229,7 +235,9 @@ public class KiwixMobileActivity extends AppCompatActivity
|
|||||||
mToolbarContainer = (RelativeLayout) findViewById(R.id.toolbar_layout);
|
mToolbarContainer = (RelativeLayout) findViewById(R.id.toolbar_layout);
|
||||||
mProgressBar = (AnimatedProgressBar) findViewById(R.id.progress_view);
|
mProgressBar = (AnimatedProgressBar) findViewById(R.id.progress_view);
|
||||||
exitFullscreenButton = (ImageButton) findViewById(R.id.FullscreenControlButton);
|
exitFullscreenButton = (ImageButton) findViewById(R.id.FullscreenControlButton);
|
||||||
|
tempForUndo = new KiwixWebView(getApplicationContext()); /** initializing temporary tab value **/
|
||||||
|
|
||||||
|
snackbarLayout = (LinearLayout) findViewById(R.id.linearlayout_main); /** Coordinator layout definition**/
|
||||||
RelativeLayout newTabButton = (RelativeLayout) findViewById(R.id.new_tab_button);
|
RelativeLayout newTabButton = (RelativeLayout) findViewById(R.id.new_tab_button);
|
||||||
newTabButton.setOnClickListener(new View.OnClickListener() {
|
newTabButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
|
||||||
@ -372,7 +380,21 @@ public class KiwixMobileActivity extends AppCompatActivity
|
|||||||
if (mCurrentWebViewIndex == index) {
|
if (mCurrentWebViewIndex == index) {
|
||||||
if (mCurrentWebViewIndex >= 1) {
|
if (mCurrentWebViewIndex >= 1) {
|
||||||
selectTab(mCurrentWebViewIndex - 1);
|
selectTab(mCurrentWebViewIndex - 1);
|
||||||
|
|
||||||
|
tempForUndo = mWebViews.get(index);
|
||||||
|
|
||||||
mWebViews.remove(index);
|
mWebViews.remove(index);
|
||||||
|
Snackbar undoSnackbar = Snackbar.make(snackbarLayout, "Click to restore tab", Snackbar.LENGTH_LONG)
|
||||||
|
.setAction("Undo", new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
newTab(tempForUndo.getUrl());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
undoSnackbar.setActionTextColor(getResources().getColor(R.color.white_undo));
|
||||||
|
undoSnackbar.show();
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
selectTab(mCurrentWebViewIndex + 1);
|
selectTab(mCurrentWebViewIndex + 1);
|
||||||
mWebViews.remove(index);
|
mWebViews.remove(index);
|
||||||
@ -930,7 +952,7 @@ public class KiwixMobileActivity extends AppCompatActivity
|
|||||||
String title = data.getStringExtra(TAG_FILE_SEARCHED).replace("<b>", "").replace("</b>", "");
|
String title = data.getStringExtra(TAG_FILE_SEARCHED).replace("<b>", "").replace("</b>", "");
|
||||||
String articleUrl = "";
|
String articleUrl = "";
|
||||||
|
|
||||||
if(title.startsWith("A/")) {
|
if (title.startsWith("A/")) {
|
||||||
articleUrl = title;
|
articleUrl = title;
|
||||||
} else articleUrl = ZimContentProvider.getPageUrlFromTitle(title);
|
} else articleUrl = ZimContentProvider.getPageUrlFromTitle(title);
|
||||||
|
|
||||||
@ -979,7 +1001,7 @@ public class KiwixMobileActivity extends AppCompatActivity
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refreshBookmarkSymbol(Menu menu){
|
public void refreshBookmarkSymbol(Menu menu) {
|
||||||
if (menu.findItem(R.id.menu_bookmarks) != null &&
|
if (menu.findItem(R.id.menu_bookmarks) != null &&
|
||||||
getCurrentWebView().getUrl() != null &&
|
getCurrentWebView().getUrl() != null &&
|
||||||
!getCurrentWebView().getUrl().equals("file:///android_res/raw/help.html") &&
|
!getCurrentWebView().getUrl().equals("file:///android_res/raw/help.html") &&
|
||||||
@ -1044,13 +1066,13 @@ public class KiwixMobileActivity extends AppCompatActivity
|
|||||||
startActivityForResult(i, REQUEST_PREFERENCES);
|
startActivityForResult(i, REQUEST_PREFERENCES);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveTabStates(){
|
public void saveTabStates() {
|
||||||
SharedPreferences settings = getSharedPreferences(PREF_KIWIX_MOBILE, 0);
|
SharedPreferences settings = getSharedPreferences(PREF_KIWIX_MOBILE, 0);
|
||||||
SharedPreferences.Editor editor = settings.edit();
|
SharedPreferences.Editor editor = settings.edit();
|
||||||
|
|
||||||
JSONArray urls = new JSONArray();
|
JSONArray urls = new JSONArray();
|
||||||
JSONArray positions = new JSONArray();
|
JSONArray positions = new JSONArray();
|
||||||
for (KiwixWebView view : mWebViews){
|
for (KiwixWebView view : mWebViews) {
|
||||||
urls.put(view.getUrl());
|
urls.put(view.getUrl());
|
||||||
positions.put(view.getScrollY());
|
positions.put(view.getScrollY());
|
||||||
}
|
}
|
||||||
@ -1064,26 +1086,26 @@ public class KiwixMobileActivity extends AppCompatActivity
|
|||||||
editor.apply();
|
editor.apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void restoreTabStates(){
|
public void restoreTabStates() {
|
||||||
SharedPreferences settings = getSharedPreferences(PREF_KIWIX_MOBILE, 0);
|
SharedPreferences settings = getSharedPreferences(PREF_KIWIX_MOBILE, 0);
|
||||||
String zimFile = settings.getString(TAG_CURRENT_FILE, null);
|
String zimFile = settings.getString(TAG_CURRENT_FILE, null);
|
||||||
String zimArticles = settings.getString(TAG_CURRENT_ARTICLES, null);
|
String zimArticles = settings.getString(TAG_CURRENT_ARTICLES, null);
|
||||||
String zimPositions = settings.getString(TAG_CURRENT_POSITIONS, null);
|
String zimPositions = settings.getString(TAG_CURRENT_POSITIONS, null);
|
||||||
int currentTab = settings.getInt(TAG_CURRENT_TAB, 0 );
|
int currentTab = settings.getInt(TAG_CURRENT_TAB, 0);
|
||||||
openZimFile( new File(zimFile), false);
|
openZimFile(new File(zimFile), false);
|
||||||
try {
|
try {
|
||||||
JSONArray urls = new JSONArray(zimArticles);
|
JSONArray urls = new JSONArray(zimArticles);
|
||||||
JSONArray positions = new JSONArray(zimPositions);
|
JSONArray positions = new JSONArray(zimPositions);
|
||||||
int i=0;
|
int i = 0;
|
||||||
getCurrentWebView().loadUrl(urls.getString(i));
|
getCurrentWebView().loadUrl(urls.getString(i));
|
||||||
getCurrentWebView().setScrollY(positions.getInt(i));
|
getCurrentWebView().setScrollY(positions.getInt(i));
|
||||||
i++;
|
i++;
|
||||||
for (;i<urls.length();i++){
|
for (; i < urls.length(); i++) {
|
||||||
newTab(urls.getString(i));
|
newTab(urls.getString(i));
|
||||||
getCurrentWebView().setScrollY(positions.getInt(i));
|
getCurrentWebView().setScrollY(positions.getInt(i));
|
||||||
}
|
}
|
||||||
selectTab(currentTab);
|
selectTab(currentTab);
|
||||||
} catch (Exception e ) {
|
} catch (Exception e) {
|
||||||
Log.d(TAG_KIWIX, " Kiwix sharedpreferences corrupted");
|
Log.d(TAG_KIWIX, " Kiwix sharedpreferences corrupted");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1180,7 +1202,6 @@ public class KiwixMobileActivity extends AppCompatActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user