mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-04 03:06:41 -04:00
Revert "Merged new features from wmhack to master"
This reverts commit 7b4fcd90c38641b8dc9d29661587149ed71b0f0d.
This commit is contained in:
parent
5225c719ac
commit
abaa3da9ab
@ -20,7 +20,6 @@
|
|||||||
package org.kiwix.kiwixmobile;
|
package org.kiwix.kiwixmobile;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.Dialog;
|
|
||||||
import android.content.ActivityNotFoundException;
|
import android.content.ActivityNotFoundException;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
@ -37,7 +36,6 @@ 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;
|
||||||
@ -70,7 +68,6 @@ 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;
|
||||||
@ -86,7 +83,6 @@ 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 java.util.prefs.Preferences;
|
|
||||||
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;
|
||||||
@ -95,7 +91,6 @@ import org.kiwix.kiwixmobile.utils.KiwixTextToSpeech;
|
|||||||
import org.kiwix.kiwixmobile.utils.LanguageUtils;
|
import org.kiwix.kiwixmobile.utils.LanguageUtils;
|
||||||
import org.kiwix.kiwixmobile.utils.files.FileReader;
|
import org.kiwix.kiwixmobile.utils.files.FileReader;
|
||||||
import org.kiwix.kiwixmobile.utils.files.FileUtils;
|
import org.kiwix.kiwixmobile.utils.files.FileUtils;
|
||||||
import org.kiwix.kiwixmobile.utils.files.RateAppCounter;
|
|
||||||
import org.kiwix.kiwixmobile.views.AnimatedProgressBar;
|
import org.kiwix.kiwixmobile.views.AnimatedProgressBar;
|
||||||
import org.kiwix.kiwixmobile.views.CompatFindActionModeCallback;
|
import org.kiwix.kiwixmobile.views.CompatFindActionModeCallback;
|
||||||
import org.kiwix.kiwixmobile.views.KiwixWebView;
|
import org.kiwix.kiwixmobile.views.KiwixWebView;
|
||||||
@ -197,10 +192,7 @@ 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;
|
|
||||||
private RateAppCounter visitCounterPref;
|
|
||||||
private int tempVisitCount;
|
|
||||||
@Override
|
@Override
|
||||||
public void onActionModeStarted(ActionMode mode) {
|
public void onActionModeStarted(ActionMode mode) {
|
||||||
if (mActionMode == null) {
|
if (mActionMode == null) {
|
||||||
@ -248,17 +240,6 @@ public class KiwixMobileActivity extends AppCompatActivity
|
|||||||
|
|
||||||
toolbar = (Toolbar) findViewById(R.id.toolbar);
|
toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
|
|
||||||
visitCounterPref = new RateAppCounter(this);
|
|
||||||
tempVisitCount = visitCounterPref.getCount();
|
|
||||||
++tempVisitCount;
|
|
||||||
visitCounterPref.setCount(tempVisitCount);
|
|
||||||
|
|
||||||
if(tempVisitCount >= 5 && !visitCounterPref.getNoThanksState()){
|
|
||||||
showRateDialog(this,visitCounterPref.getEditor());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bookmarks = new ArrayList<>();
|
bookmarks = new ArrayList<>();
|
||||||
requestClearHistoryAfterLoad = false;
|
requestClearHistoryAfterLoad = false;
|
||||||
requestWebReloadOnFinished = 0;
|
requestWebReloadOnFinished = 0;
|
||||||
@ -275,11 +256,6 @@ public class KiwixMobileActivity extends AppCompatActivity
|
|||||||
FileReader fileReader = new FileReader();
|
FileReader fileReader = new FileReader();
|
||||||
jsContent = fileReader.readFile("www/js/jsfile.js", this);
|
jsContent = fileReader.readFile("www/js/jsfile.js", this);
|
||||||
|
|
||||||
tempForUndo =
|
|
||||||
new KiwixWebView(getApplicationContext()); /** initializing temporary tab value **/
|
|
||||||
snackbarLayout =
|
|
||||||
(LinearLayout) findViewById(R.id.linearlayout_main); /** Linear 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() {
|
||||||
|
|
||||||
@ -390,73 +366,6 @@ public class KiwixMobileActivity extends AppCompatActivity
|
|||||||
updateTitle(ZimContentProvider.getZimFileTitle());
|
updateTitle(ZimContentProvider.getZimFileTitle());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showRateDialog(final Context mContext, final SharedPreferences.Editor editor) {
|
|
||||||
AlertDialog alertDialog = new AlertDialog.Builder(mContext).create();
|
|
||||||
|
|
||||||
alertDialog.setTitle("Please Rate");
|
|
||||||
|
|
||||||
alertDialog.setMessage("If you enjoy using "
|
|
||||||
+ getString(R.string.app_name)
|
|
||||||
+ ", please take a moment to rate it. Thanks for your support!");
|
|
||||||
|
|
||||||
alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "Rate!",
|
|
||||||
new DialogInterface.OnClickListener() {
|
|
||||||
|
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
|
||||||
visitCounterPref.setNoThanksState(true);
|
|
||||||
goToRateApp();
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "No, thanks",
|
|
||||||
new DialogInterface.OnClickListener() {
|
|
||||||
|
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
|
||||||
|
|
||||||
visitCounterPref.setNoThanksState(true);
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "Remind me later",
|
|
||||||
new DialogInterface.OnClickListener() {
|
|
||||||
|
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
|
||||||
|
|
||||||
tempVisitCount = 0;
|
|
||||||
visitCounterPref.setCount(tempVisitCount);
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
alertDialog.show();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void goToRateApp() {
|
|
||||||
|
|
||||||
Uri uri = Uri.parse("market://details?id=" + getPackageName());
|
|
||||||
Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
|
|
||||||
|
|
||||||
goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY |
|
|
||||||
Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET |
|
|
||||||
Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
|
|
||||||
|
|
||||||
try {
|
|
||||||
startActivity(goToMarket);
|
|
||||||
} catch (ActivityNotFoundException e) {
|
|
||||||
startActivity(new Intent(Intent.ACTION_VIEW,
|
|
||||||
Uri.parse("http://play.google.com/store/apps/details?id=" + getPackageName())));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateTitle(String zimFileTitle) {
|
private void updateTitle(String zimFileTitle) {
|
||||||
if (zimFileTitle == null || zimFileTitle.trim().isEmpty()) {
|
if (zimFileTitle == null || zimFileTitle.trim().isEmpty()) {
|
||||||
getSupportActionBar().setTitle(getString(R.string.app_name));
|
getSupportActionBar().setTitle(getString(R.string.app_name));
|
||||||
@ -538,42 +447,19 @@ public class KiwixMobileActivity extends AppCompatActivity
|
|||||||
return webView;
|
return webView;
|
||||||
}
|
}
|
||||||
|
|
||||||
private KiwixWebView restoreTabAtIndex(String url, int index) {
|
|
||||||
KiwixWebView webView = new KiwixWebView(KiwixMobileActivity.this);
|
|
||||||
webView.setWebViewClient(new KiwixWebViewClient(KiwixMobileActivity.this, mLeftArrayAdapter));
|
|
||||||
webView.setWebChromeClient(new KiwixWebChromeClient());
|
|
||||||
webView.loadUrl(url);
|
|
||||||
webView.loadPrefs();
|
|
||||||
|
|
||||||
mWebViews.add(index,webView);
|
|
||||||
mLeftArrayAdapter.notifyDataSetChanged();
|
|
||||||
selectTab(mWebViews.size() - 1);
|
|
||||||
setUpWebView();
|
|
||||||
return webView;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void closeTab(int index) {
|
private void closeTab(int index) {
|
||||||
|
|
||||||
if (mWebViews.size() > 1) {
|
if (mWebViews.size() > 1) {
|
||||||
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);
|
||||||
undoSnackbar(index);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
selectTab(mCurrentWebViewIndex + 1);
|
selectTab(mCurrentWebViewIndex + 1);
|
||||||
mWebViews.remove(index);
|
mWebViews.remove(index);
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
tempForUndo = mWebViews.get(index);
|
|
||||||
mWebViews.remove(index);
|
mWebViews.remove(index);
|
||||||
selectTab(mCurrentWebViewIndex - 1);
|
|
||||||
undoSnackbar(index);
|
|
||||||
if (index < mCurrentWebViewIndex) {
|
if (index < mCurrentWebViewIndex) {
|
||||||
mCurrentWebViewIndex--;
|
mCurrentWebViewIndex--;
|
||||||
}
|
}
|
||||||
@ -587,20 +473,6 @@ public class KiwixMobileActivity extends AppCompatActivity
|
|||||||
mLeftArrayAdapter.notifyDataSetChanged();
|
mLeftArrayAdapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void undoSnackbar(final int index) {
|
|
||||||
Snackbar undoSnackbar =
|
|
||||||
Snackbar.make(snackbarLayout, "Tab closed", Snackbar.LENGTH_LONG)
|
|
||||||
.setAction("Undo", new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
restoreTabAtIndex(tempForUndo.getUrl(), index);
|
|
||||||
selectTab(index);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
undoSnackbar.setActionTextColor(getResources().getColor(R.color.white_undo));
|
|
||||||
undoSnackbar.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void selectTab(int position) {
|
private void selectTab(int position) {
|
||||||
mCurrentWebViewIndex = position;
|
mCurrentWebViewIndex = position;
|
||||||
mLeftDrawerList.setItemChecked(position, true);
|
mLeftDrawerList.setItemChecked(position, true);
|
||||||
@ -1150,15 +1022,12 @@ public class KiwixMobileActivity extends AppCompatActivity
|
|||||||
break;
|
break;
|
||||||
case REQUEST_FILE_SEARCH:
|
case REQUEST_FILE_SEARCH:
|
||||||
if (resultCode == RESULT_OK) {
|
if (resultCode == RESULT_OK) {
|
||||||
String title =
|
String title = data.getStringExtra(TAG_FILE_SEARCHED).replace("<b>", "").replace("</b>", "");
|
||||||
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 {
|
} else articleUrl = ZimContentProvider.getPageUrlFromTitle(title);
|
||||||
articleUrl = ZimContentProvider.getPageUrlFromTitle(title);
|
|
||||||
}
|
|
||||||
|
|
||||||
//System.out.println("Opening "+articleUrl + " (" + title + ")");
|
//System.out.println("Opening "+articleUrl + " (" + title + ")");
|
||||||
|
|
||||||
@ -1291,13 +1160,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());
|
||||||
}
|
}
|
||||||
@ -1311,28 +1180,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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1404,7 +1271,8 @@ public class KiwixMobileActivity extends AppCompatActivity
|
|||||||
.setPositiveButton(getString(R.string.go_to_play_store),
|
.setPositiveButton(getString(R.string.go_to_play_store),
|
||||||
new DialogInterface.OnClickListener() {
|
new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
String market_uri = "market://details?id=" + Constants.CUSTOM_APP_ID;
|
String market_uri = "market://details?id="
|
||||||
|
+ Constants.CUSTOM_APP_ID;
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||||
intent.setData(Uri.parse(market_uri));
|
intent.setData(Uri.parse(market_uri));
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
@ -1427,6 +1295,8 @@ public class KiwixMobileActivity extends AppCompatActivity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
@ -1525,7 +1395,8 @@ public class KiwixMobileActivity extends AppCompatActivity
|
|||||||
String failingUrl) {
|
String failingUrl) {
|
||||||
|
|
||||||
String errorString = String
|
String errorString = String
|
||||||
.format(getResources().getString(R.string.error_articleurlnotfound), failingUrl);
|
.format(getResources().getString(R.string.error_articleurlnotfound),
|
||||||
|
failingUrl);
|
||||||
// TODO apparently screws up back/forward
|
// TODO apparently screws up back/forward
|
||||||
getCurrentWebView().loadDataWithBaseURL("file://error",
|
getCurrentWebView().loadDataWithBaseURL("file://error",
|
||||||
"<html><body>" + errorString + "</body></html>", "text/html", "utf-8",
|
"<html><body>" + errorString + "</body></html>", "text/html", "utf-8",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user