mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-11 00:23:58 -04:00
#1383 remove rendundant menu items + reorganise items/constants + clear notes in KiwixSettingsActivity
This commit is contained in:
parent
c2b8e60e1e
commit
ba7275b775
@ -35,12 +35,11 @@ import java.io.File;
|
|||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import org.kiwix.kiwixmobile.BuildConfig;
|
import org.kiwix.kiwixmobile.BuildConfig;
|
||||||
|
import org.kiwix.kiwixmobile.KiwixApplication;
|
||||||
import org.kiwix.kiwixmobile.R;
|
import org.kiwix.kiwixmobile.R;
|
||||||
import org.kiwix.kiwixmobile.data.ZimContentProvider;
|
import org.kiwix.kiwixmobile.data.ZimContentProvider;
|
||||||
import org.kiwix.kiwixmobile.utils.SharedPreferenceUtil;
|
import org.kiwix.kiwixmobile.utils.SharedPreferenceUtil;
|
||||||
|
|
||||||
import static org.kiwix.kiwixmobile.utils.Constants.NOTES_DIRECTORY;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by @author Aditya-Sood (21/05/19) as a part of GSoC 2019
|
* Created by @author Aditya-Sood (21/05/19) as a part of GSoC 2019
|
||||||
*
|
*
|
||||||
@ -53,6 +52,8 @@ import static org.kiwix.kiwixmobile.utils.Constants.NOTES_DIRECTORY;
|
|||||||
public class AddNoteDialog extends DialogFragment
|
public class AddNoteDialog extends DialogFragment
|
||||||
implements ConfirmationAlertDialogFragment.UserClickListener {
|
implements ConfirmationAlertDialogFragment.UserClickListener {
|
||||||
|
|
||||||
|
public static final String NOTES_DIRECTORY =
|
||||||
|
Environment.getExternalStorageDirectory() + "/Kiwix/Notes/";
|
||||||
public static final String TAG = "AddNoteDialog";
|
public static final String TAG = "AddNoteDialog";
|
||||||
|
|
||||||
private SharedPreferenceUtil sharedPreferenceUtil;
|
private SharedPreferenceUtil sharedPreferenceUtil;
|
||||||
@ -298,7 +299,7 @@ public class AddNoteDialog extends DialogFragment
|
|||||||
* "{External Storage}/Kiwix/Notes/ZimFileTitle/ArticleTitle.txt"
|
* "{External Storage}/Kiwix/Notes/ZimFileTitle/ArticleTitle.txt"
|
||||||
* */
|
* */
|
||||||
|
|
||||||
if (isExternalStorageWritable()) {
|
if (KiwixApplication.getInstance().isExternalStorageWritable()) {
|
||||||
|
|
||||||
if (ContextCompat.checkSelfPermission(getContext(),
|
if (ContextCompat.checkSelfPermission(getContext(),
|
||||||
Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
||||||
@ -415,10 +416,6 @@ public class AddNoteDialog extends DialogFragment
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean isExternalStorageWritable() {
|
|
||||||
return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void showToast(int stringResource, int duration) {
|
private void showToast(int stringResource, int duration) {
|
||||||
Toast.makeText(getActivity(), stringResource, duration).show();
|
Toast.makeText(getActivity(), stringResource, duration).show();
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,6 @@ import android.appwidget.AppWidgetManager;
|
|||||||
import android.content.ActivityNotFoundException;
|
import android.content.ActivityNotFoundException;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
@ -86,7 +85,6 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
|||||||
import com.google.android.material.navigation.NavigationView;
|
import com.google.android.material.navigation.NavigationView;
|
||||||
import com.google.android.material.snackbar.Snackbar;
|
import com.google.android.material.snackbar.Snackbar;
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -136,8 +134,6 @@ import static org.kiwix.kiwixmobile.utils.Constants.EXTRA_LIBRARY;
|
|||||||
import static org.kiwix.kiwixmobile.utils.Constants.EXTRA_SEARCH;
|
import static org.kiwix.kiwixmobile.utils.Constants.EXTRA_SEARCH;
|
||||||
import static org.kiwix.kiwixmobile.utils.Constants.EXTRA_ZIM_FILE;
|
import static org.kiwix.kiwixmobile.utils.Constants.EXTRA_ZIM_FILE;
|
||||||
import static org.kiwix.kiwixmobile.utils.Constants.EXTRA_ZIM_FILE_2;
|
import static org.kiwix.kiwixmobile.utils.Constants.EXTRA_ZIM_FILE_2;
|
||||||
import static org.kiwix.kiwixmobile.utils.Constants.NOTES_DIRECTORY;
|
|
||||||
import static org.kiwix.kiwixmobile.utils.Constants.PREF_KIWIX_MOBILE;
|
|
||||||
import static org.kiwix.kiwixmobile.utils.Constants.REQUEST_FILE_SEARCH;
|
import static org.kiwix.kiwixmobile.utils.Constants.REQUEST_FILE_SEARCH;
|
||||||
import static org.kiwix.kiwixmobile.utils.Constants.REQUEST_FILE_SELECT;
|
import static org.kiwix.kiwixmobile.utils.Constants.REQUEST_FILE_SELECT;
|
||||||
import static org.kiwix.kiwixmobile.utils.Constants.REQUEST_HISTORY_ITEM_CHOSEN;
|
import static org.kiwix.kiwixmobile.utils.Constants.REQUEST_HISTORY_ITEM_CHOSEN;
|
||||||
@ -154,11 +150,12 @@ 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_FILE_SEARCHED;
|
||||||
import static org.kiwix.kiwixmobile.utils.Constants.TAG_KIWIX;
|
import static org.kiwix.kiwixmobile.utils.Constants.TAG_KIWIX;
|
||||||
import static org.kiwix.kiwixmobile.utils.LanguageUtils.getResourceString;
|
import static org.kiwix.kiwixmobile.utils.LanguageUtils.getResourceString;
|
||||||
|
import static org.kiwix.kiwixmobile.utils.SharedPreferenceUtil.PREF_KIWIX_MOBILE;
|
||||||
import static org.kiwix.kiwixmobile.utils.StyleUtils.dialogStyle;
|
import static org.kiwix.kiwixmobile.utils.StyleUtils.dialogStyle;
|
||||||
import static org.kiwix.kiwixmobile.utils.UpdateUtils.reformatProviderUrl;
|
import static org.kiwix.kiwixmobile.utils.UpdateUtils.reformatProviderUrl;
|
||||||
|
|
||||||
public class MainActivity extends BaseActivity implements WebViewCallback,
|
public class MainActivity extends BaseActivity implements WebViewCallback,
|
||||||
MainContract.View {
|
MainContract.View {
|
||||||
|
|
||||||
private static final String NEW_TAB = "NEW_TAB";
|
private static final String NEW_TAB = "NEW_TAB";
|
||||||
private static final String HOME_URL = "file:///android_asset/home.html";
|
private static final String HOME_URL = "file:///android_asset/home.html";
|
||||||
@ -256,21 +253,21 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
private ItemTouchHelper.Callback tabCallback = new ItemTouchHelper.Callback() {
|
private ItemTouchHelper.Callback tabCallback = new ItemTouchHelper.Callback() {
|
||||||
@Override
|
@Override
|
||||||
public int getMovementFlags(@NonNull RecyclerView recyclerView,
|
public int getMovementFlags(@NonNull RecyclerView recyclerView,
|
||||||
@NonNull RecyclerView.ViewHolder viewHolder) {
|
@NonNull RecyclerView.ViewHolder viewHolder) {
|
||||||
return makeMovementFlags(0, ItemTouchHelper.UP | ItemTouchHelper.DOWN);
|
return makeMovementFlags(0, ItemTouchHelper.UP | ItemTouchHelper.DOWN);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onChildDraw(@NonNull Canvas c, @NonNull RecyclerView recyclerView,
|
public void onChildDraw(@NonNull Canvas c, @NonNull RecyclerView recyclerView,
|
||||||
@NonNull RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState,
|
@NonNull RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState,
|
||||||
boolean isCurrentlyActive) {
|
boolean isCurrentlyActive) {
|
||||||
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
|
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
|
||||||
viewHolder.itemView.setAlpha(1 - Math.abs(dY) / viewHolder.itemView.getMeasuredHeight());
|
viewHolder.itemView.setAlpha(1 - Math.abs(dY) / viewHolder.itemView.getMeasuredHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onMove(@NonNull RecyclerView recyclerView,
|
public boolean onMove(@NonNull RecyclerView recyclerView,
|
||||||
@NonNull RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder target) {
|
@NonNull RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder target) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -314,13 +311,13 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
private void readAloudSelection(Menu menu) {
|
private void readAloudSelection(Menu menu) {
|
||||||
if (menu != null) {
|
if (menu != null) {
|
||||||
menu.findItem(R.id.menu_speak_text)
|
menu.findItem(R.id.menu_speak_text)
|
||||||
.setOnMenuItemClickListener(item -> {
|
.setOnMenuItemClickListener(item -> {
|
||||||
tts.readSelection(getCurrentWebView());
|
tts.readSelection(getCurrentWebView());
|
||||||
if (actionMode != null) {
|
if (actionMode != null) {
|
||||||
actionMode.finish();
|
actionMode.finish();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -347,7 +344,7 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
});
|
});
|
||||||
|
|
||||||
tableDrawerRight =
|
tableDrawerRight =
|
||||||
tableDrawerRightContainer.getHeaderView(0).findViewById(R.id.right_drawer_list);
|
tableDrawerRightContainer.getHeaderView(0).findViewById(R.id.right_drawer_list);
|
||||||
|
|
||||||
checkForRateDialog();
|
checkForRateDialog();
|
||||||
|
|
||||||
@ -364,7 +361,7 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
setupDocumentParser();
|
setupDocumentParser();
|
||||||
|
|
||||||
if (BuildConfig.IS_CUSTOM_APP) {
|
if (BuildConfig.IS_CUSTOM_APP) {
|
||||||
Log.d(TAG_KIWIX, "This is a custom app:" +BuildConfig.APPLICATION_ID);
|
Log.d(TAG_KIWIX, "This is a custom app:" + BuildConfig.APPLICATION_ID);
|
||||||
if (loadCustomAppContent()) {
|
if (loadCustomAppContent()) {
|
||||||
Log.d(TAG_KIWIX, "Found custom content, continuing...");
|
Log.d(TAG_KIWIX, "Found custom content, continuing...");
|
||||||
// Continue
|
// Continue
|
||||||
@ -375,7 +372,6 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
// it didn't crash yet today the app crashes because it tries to load books
|
// it didn't crash yet today the app crashes because it tries to load books
|
||||||
// in onResume();
|
// in onResume();
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
manageExternalLaunchAndRestoringViewState();
|
manageExternalLaunchAndRestoringViewState();
|
||||||
@ -388,14 +384,14 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
|
|
||||||
wasHideToolbar = isHideToolbar;
|
wasHideToolbar = isHideToolbar;
|
||||||
booksAdapter = new BooksOnDiskAdapter(
|
booksAdapter = new BooksOnDiskAdapter(
|
||||||
new BookOnDiskDelegate.BookDelegate(sharedPreferenceUtil,
|
new BookOnDiskDelegate.BookDelegate(sharedPreferenceUtil,
|
||||||
bookOnDiskItem -> {
|
bookOnDiskItem -> {
|
||||||
open(bookOnDiskItem);
|
open(bookOnDiskItem);
|
||||||
return Unit.INSTANCE;
|
return Unit.INSTANCE;
|
||||||
},
|
},
|
||||||
null,
|
null,
|
||||||
null),
|
null),
|
||||||
BookOnDiskDelegate.LanguageDelegate.INSTANCE
|
BookOnDiskDelegate.LanguageDelegate.INSTANCE
|
||||||
);
|
);
|
||||||
|
|
||||||
searchFiles();
|
searchFiles();
|
||||||
@ -513,8 +509,8 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
@Override
|
@Override
|
||||||
public void onSectionClick(View view, int position) {
|
public void onSectionClick(View view, int position) {
|
||||||
getCurrentWebView().loadUrl("javascript:document.getElementById('"
|
getCurrentWebView().loadUrl("javascript:document.getElementById('"
|
||||||
+ documentSections.get(position).id
|
+ documentSections.get(position).id
|
||||||
+ "').scrollIntoView();");
|
+ "').scrollIntoView();");
|
||||||
drawerLayout.closeDrawers();
|
drawerLayout.closeDrawers();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -524,7 +520,7 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
private void showTabSwitcher() {
|
private void showTabSwitcher() {
|
||||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||||
actionBar.setHomeAsUpIndicator(
|
actionBar.setHomeAsUpIndicator(
|
||||||
ContextCompat.getDrawable(this, R.drawable.ic_round_add_white_36dp));
|
ContextCompat.getDrawable(this, R.drawable.ic_round_add_white_36dp));
|
||||||
actionBar.setDisplayShowTitleEnabled(false);
|
actionBar.setDisplayShowTitleEnabled(false);
|
||||||
|
|
||||||
drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
|
drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
|
||||||
@ -535,7 +531,7 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
tabSwitcherRoot.setVisibility(View.VISIBLE);
|
tabSwitcherRoot.setVisibility(View.VISIBLE);
|
||||||
supportInvalidateOptionsMenu();
|
supportInvalidateOptionsMenu();
|
||||||
if (tabsAdapter.getSelected() < webViewList.size() &&
|
if (tabsAdapter.getSelected() < webViewList.size() &&
|
||||||
tabRecyclerView.getLayoutManager() != null) {
|
tabRecyclerView.getLayoutManager() != null) {
|
||||||
tabRecyclerView.getLayoutManager().scrollToPosition(tabsAdapter.getSelected());
|
tabRecyclerView.getLayoutManager().scrollToPosition(tabsAdapter.getSelected());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -546,7 +542,7 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
|
|
||||||
drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
|
drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
|
||||||
closeAllTabsButton.setImageDrawable(
|
closeAllTabsButton.setImageDrawable(
|
||||||
ContextCompat.getDrawable(this, R.drawable.ic_close_black_24dp));
|
ContextCompat.getDrawable(this, R.drawable.ic_close_black_24dp));
|
||||||
tabSwitcherRoot.setVisibility(View.GONE);
|
tabSwitcherRoot.setVisibility(View.GONE);
|
||||||
progressBar.setVisibility(View.VISIBLE);
|
progressBar.setVisibility(View.VISIBLE);
|
||||||
contentFrame.setVisibility(View.VISIBLE);
|
contentFrame.setVisibility(View.VISIBLE);
|
||||||
@ -598,8 +594,8 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
visitCounterPref.setCount(tempVisitCount);
|
visitCounterPref.setCount(tempVisitCount);
|
||||||
|
|
||||||
if (tempVisitCount >= 10
|
if (tempVisitCount >= 10
|
||||||
&& !visitCounterPref.getNoThanksState()
|
&& !visitCounterPref.getNoThanksState()
|
||||||
&& NetworkUtils.isNetworkAvailable(this) && !BuildConfig.DEBUG) {
|
&& NetworkUtils.isNetworkAvailable(this) && !BuildConfig.DEBUG) {
|
||||||
showRateDialog();
|
showRateDialog();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -607,26 +603,26 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
private void showRateDialog() {
|
private void showRateDialog() {
|
||||||
String title = getString(R.string.rate_dialog_title);
|
String title = getString(R.string.rate_dialog_title);
|
||||||
String message = getString(R.string.rate_dialog_msg_1) + " "
|
String message = getString(R.string.rate_dialog_msg_1) + " "
|
||||||
+ getString(R.string.app_name)
|
+ getString(R.string.app_name)
|
||||||
+ getString(R.string.rate_dialog_msg_2);
|
+ getString(R.string.rate_dialog_msg_2);
|
||||||
String positive = getString(R.string.rate_dialog_positive);
|
String positive = getString(R.string.rate_dialog_positive);
|
||||||
String negative = getString(R.string.rate_dialog_negative);
|
String negative = getString(R.string.rate_dialog_negative);
|
||||||
String neutral = getString(R.string.rate_dialog_neutral);
|
String neutral = getString(R.string.rate_dialog_neutral);
|
||||||
|
|
||||||
new AlertDialog.Builder(this, dialogStyle())
|
new AlertDialog.Builder(this, dialogStyle())
|
||||||
.setTitle(title)
|
.setTitle(title)
|
||||||
.setMessage(message)
|
.setMessage(message)
|
||||||
.setPositiveButton(positive, (dialog, id) -> {
|
.setPositiveButton(positive, (dialog, id) -> {
|
||||||
visitCounterPref.setNoThanksState(true);
|
visitCounterPref.setNoThanksState(true);
|
||||||
goToRateApp();
|
goToRateApp();
|
||||||
})
|
})
|
||||||
.setNegativeButton(negative, (dialog, id) -> visitCounterPref.setNoThanksState(true))
|
.setNegativeButton(negative, (dialog, id) -> visitCounterPref.setNoThanksState(true))
|
||||||
.setNeutralButton(neutral, (dialog, id) -> {
|
.setNeutralButton(neutral, (dialog, id) -> {
|
||||||
tempVisitCount = 0;
|
tempVisitCount = 0;
|
||||||
visitCounterPref.setCount(tempVisitCount);
|
visitCounterPref.setCount(tempVisitCount);
|
||||||
})
|
})
|
||||||
.setIcon(ContextCompat.getDrawable(this, R.mipmap.kiwix_icon))
|
.setIcon(ContextCompat.getDrawable(this, R.mipmap.kiwix_icon))
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void goToSearch(boolean isVoice) {
|
private void goToSearch(boolean isVoice) {
|
||||||
@ -641,22 +637,21 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void goToRateApp() {
|
private void goToRateApp() {
|
||||||
Uri kiwixLocalMarketUri = Uri.parse("market://details?id=" + getPackageName());
|
Uri kiwixLocalMarketUri = Uri.parse("market://details?id=" + getPackageName());
|
||||||
Uri kiwixBrowserMarketUri =
|
Uri kiwixBrowserMarketUri =
|
||||||
Uri.parse("http://play.google.com/store/apps/details?id=" + getPackageName());
|
Uri.parse("http://play.google.com/store/apps/details?id=" + getPackageName());
|
||||||
|
|
||||||
|
Intent goToMarket = new Intent(Intent.ACTION_VIEW, kiwixLocalMarketUri);
|
||||||
Intent goToMarket = new Intent(Intent.ACTION_VIEW, kiwixLocalMarketUri);
|
|
||||||
|
|
||||||
goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY |
|
goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY |
|
||||||
Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET |
|
Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET |
|
||||||
Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
|
Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
startActivity(goToMarket);
|
startActivity(goToMarket);
|
||||||
} catch (ActivityNotFoundException e) {
|
} catch (ActivityNotFoundException e) {
|
||||||
startActivity(new Intent(Intent.ACTION_VIEW,
|
startActivity(new Intent(Intent.ACTION_VIEW,
|
||||||
kiwixBrowserMarketUri));
|
kiwixBrowserMarketUri));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -683,7 +678,7 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
isSpeaking = true;
|
isSpeaking = true;
|
||||||
runOnUiThread(() -> {
|
runOnUiThread(() -> {
|
||||||
menu.findItem(R.id.menu_read_aloud)
|
menu.findItem(R.id.menu_read_aloud)
|
||||||
.setTitle(createMenuItem(getResources().getString(R.string.menu_read_aloud_stop)));
|
.setTitle(createMenuItem(getResources().getString(R.string.menu_read_aloud_stop)));
|
||||||
TTSControls.setVisibility(View.VISIBLE);
|
TTSControls.setVisibility(View.VISIBLE);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -693,7 +688,7 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
isSpeaking = false;
|
isSpeaking = false;
|
||||||
runOnUiThread(() -> {
|
runOnUiThread(() -> {
|
||||||
menu.findItem(R.id.menu_read_aloud)
|
menu.findItem(R.id.menu_read_aloud)
|
||||||
.setTitle(createMenuItem(getResources().getString(R.string.menu_read_aloud)));
|
.setTitle(createMenuItem(getResources().getString(R.string.menu_read_aloud)));
|
||||||
TTSControls.setVisibility(View.GONE);
|
TTSControls.setVisibility(View.GONE);
|
||||||
pauseTTSButton.setText(R.string.tts_pause);
|
pauseTTSButton.setText(R.string.tts_pause);
|
||||||
});
|
});
|
||||||
@ -768,8 +763,8 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
KiwixWebView webView;
|
KiwixWebView webView;
|
||||||
if (!isHideToolbar) {
|
if (!isHideToolbar) {
|
||||||
webView =
|
webView =
|
||||||
new ToolbarScrollingKiwixWebView(MainActivity.this, this, toolbarContainer, bottomToolbar,
|
new ToolbarScrollingKiwixWebView(MainActivity.this, this, toolbarContainer, bottomToolbar,
|
||||||
attrs);
|
attrs);
|
||||||
} else {
|
} else {
|
||||||
webView = new ToolbarStaticKiwixWebView(MainActivity.this, this, attrs);
|
webView = new ToolbarStaticKiwixWebView(MainActivity.this, this, attrs);
|
||||||
}
|
}
|
||||||
@ -780,7 +775,7 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
|
|
||||||
private KiwixWebView newTab() {
|
private KiwixWebView newTab() {
|
||||||
String mainPage =
|
String mainPage =
|
||||||
Uri.parse(ZimContentProvider.CONTENT_URI + ZimContentProvider.getMainPage()).toString();
|
Uri.parse(ZimContentProvider.CONTENT_URI + ZimContentProvider.getMainPage()).toString();
|
||||||
return newTab(mainPage);
|
return newTab(mainPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -808,13 +803,13 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
tabsAdapter.notifyItemRemoved(index);
|
tabsAdapter.notifyItemRemoved(index);
|
||||||
tabsAdapter.notifyItemRangeChanged(index, webViewList.size());
|
tabsAdapter.notifyItemRangeChanged(index, webViewList.size());
|
||||||
Snackbar.make(snackbarRoot, R.string.tab_closed, Snackbar.LENGTH_LONG)
|
Snackbar.make(snackbarRoot, R.string.tab_closed, Snackbar.LENGTH_LONG)
|
||||||
.setAction(R.string.undo, v -> {
|
.setAction(R.string.undo, v -> {
|
||||||
webViewList.add(index, tempForUndo);
|
webViewList.add(index, tempForUndo);
|
||||||
tabsAdapter.notifyItemInserted(index);
|
tabsAdapter.notifyItemInserted(index);
|
||||||
setUpWebView();
|
setUpWebView();
|
||||||
updateTabSwitcherIcon();
|
updateTabSwitcherIcon();
|
||||||
})
|
})
|
||||||
.show();
|
.show();
|
||||||
openHomeScreen();
|
openHomeScreen();
|
||||||
updateTabSwitcherIcon();
|
updateTabSwitcherIcon();
|
||||||
}
|
}
|
||||||
@ -853,7 +848,6 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.menu_new_tab:
|
|
||||||
case android.R.id.home:
|
case android.R.id.home:
|
||||||
if (tabSwitcherRoot.getVisibility() == View.VISIBLE) {
|
if (tabSwitcherRoot.getVisibility() == View.VISIBLE) {
|
||||||
hideTabSwitcher();
|
hideTabSwitcher();
|
||||||
@ -861,17 +855,6 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
newTab(HOME_URL);
|
newTab(HOME_URL);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case R.id.menu_home:
|
|
||||||
openMainPage();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case R.id.menu_searchintext:
|
|
||||||
compatCallback.setActive();
|
|
||||||
compatCallback.setWebView(getCurrentWebView());
|
|
||||||
startSupportActionMode(compatCallback);
|
|
||||||
compatCallback.showSoftInput();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case R.id.menu_add_note:
|
case R.id.menu_add_note:
|
||||||
if (requestExternalStorageWritePermissionForNotes()) {
|
if (requestExternalStorageWritePermissionForNotes()) {
|
||||||
// Check permission since notes are stored in the public-external storage
|
// Check permission since notes are stored in the public-external storage
|
||||||
@ -879,12 +862,6 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case R.id.menu_clear_notes:
|
|
||||||
if (requestExternalStorageWritePermissionForNotes()) { // Check permission since notes are stored in the public-external storage
|
|
||||||
showClearAllNotesDialog();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case R.id.menu_bookmarks_list:
|
case R.id.menu_bookmarks_list:
|
||||||
goToBookmarks();
|
goToBookmarks();
|
||||||
break;
|
break;
|
||||||
@ -928,7 +905,7 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
|
|
||||||
case R.id.menu_history:
|
case R.id.menu_history:
|
||||||
startActivityForResult(new Intent(this, HistoryActivity.class),
|
startActivityForResult(new Intent(this, HistoryActivity.class),
|
||||||
REQUEST_HISTORY_ITEM_CHOSEN);
|
REQUEST_HISTORY_ITEM_CHOSEN);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case R.id.menu_support_kiwix:
|
case R.id.menu_support_kiwix:
|
||||||
@ -950,75 +927,6 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Dialog to take user confirmation before deleting all notes */
|
|
||||||
private void showClearAllNotesDialog() {
|
|
||||||
|
|
||||||
AlertDialog.Builder builder;
|
|
||||||
if (sharedPreferenceUtil != null && sharedPreferenceUtil.nightMode()) { // Night Mode support
|
|
||||||
builder = new AlertDialog.Builder(this, R.style.AppTheme_Dialog_Night);
|
|
||||||
} else {
|
|
||||||
builder = new AlertDialog.Builder(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.setMessage(R.string.delete_notes_confirmation_msg)
|
|
||||||
.setNegativeButton(android.R.string.cancel, null) // Do nothing for 'Cancel' button
|
|
||||||
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
clearAllNotes();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Method to delete all user notes */
|
|
||||||
void clearAllNotes() {
|
|
||||||
|
|
||||||
boolean result = true; // Result of all delete() calls is &&-ed to this variable
|
|
||||||
|
|
||||||
if (AddNoteDialog.isExternalStorageWritable()) {
|
|
||||||
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
|
||||||
!= PackageManager.PERMISSION_GRANTED) {
|
|
||||||
Log.d("MainActivity", "WRITE_EXTERNAL_STORAGE permission not granted");
|
|
||||||
showToast(R.string.ext_storage_permission_not_granted, Toast.LENGTH_LONG);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Replace below code with Kotlin's deleteRecursively() method
|
|
||||||
|
|
||||||
File notesDirectory = new File(NOTES_DIRECTORY);
|
|
||||||
File[] filesInNotesDirectory = notesDirectory.listFiles();
|
|
||||||
|
|
||||||
if (filesInNotesDirectory == null) { // Notes folder doesn't exist
|
|
||||||
showToast(R.string.notes_deletion_none_found, Toast.LENGTH_LONG);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (File wikiFileDirectory : filesInNotesDirectory) {
|
|
||||||
if (wikiFileDirectory.isDirectory()) {
|
|
||||||
File[] filesInWikiDirectory = wikiFileDirectory.listFiles();
|
|
||||||
|
|
||||||
for (File noteFile : filesInWikiDirectory) {
|
|
||||||
if (noteFile.isFile()) {
|
|
||||||
result = result && noteFile.delete();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
result = result && wikiFileDirectory.delete(); // Wiki specific notes directory deleted
|
|
||||||
}
|
|
||||||
|
|
||||||
result =
|
|
||||||
result && notesDirectory.delete(); // "{External Storage}/Kiwix/Notes" directory deleted
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result) {
|
|
||||||
showToast(R.string.notes_deletion_successful, Toast.LENGTH_SHORT);
|
|
||||||
} else {
|
|
||||||
showToast(R.string.notes_deletion_unsuccessful, Toast.LENGTH_SHORT);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Creates the full screen AddNoteDialog, which is a DialogFragment */
|
/** Creates the full screen AddNoteDialog, which is a DialogFragment */
|
||||||
private void showAddNoteDialog() {
|
private void showAddNoteDialog() {
|
||||||
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
|
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
|
||||||
@ -1039,7 +947,7 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
if (Build.VERSION.SDK_INT >= 23) { // For Marshmallow & higher API levels
|
if (Build.VERSION.SDK_INT >= 23) { // For Marshmallow & higher API levels
|
||||||
|
|
||||||
if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||||
== PackageManager.PERMISSION_GRANTED) {
|
== PackageManager.PERMISSION_GRANTED) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
||||||
@ -1051,7 +959,7 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
}
|
}
|
||||||
|
|
||||||
requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
|
requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
|
||||||
REQUEST_WRITE_STORAGE_PERMISSION_ADD_NOTE);
|
REQUEST_WRITE_STORAGE_PERMISSION_ADD_NOTE);
|
||||||
}
|
}
|
||||||
} else { // For Android versions below Marshmallow 6.0 (API 23)
|
} else { // For Android versions below Marshmallow 6.0 (API 23)
|
||||||
return true; // As already requested at install time
|
return true; // As already requested at install time
|
||||||
@ -1122,8 +1030,8 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
// Show popup with warning that this url is external and could lead to additional costs
|
// Show popup with warning that this url is external and could lead to additional costs
|
||||||
// or may event not work when the user is offline.
|
// or may event not work when the user is offline.
|
||||||
if (intent.hasExtra(EXTRA_EXTERNAL_LINK)
|
if (intent.hasExtra(EXTRA_EXTERNAL_LINK)
|
||||||
&& intent.getBooleanExtra(EXTRA_EXTERNAL_LINK, false)
|
&& intent.getBooleanExtra(EXTRA_EXTERNAL_LINK, false)
|
||||||
&& isExternalLinkPopup) {
|
&& isExternalLinkPopup) {
|
||||||
externalLinkPopup(intent);
|
externalLinkPopup(intent);
|
||||||
} else {
|
} else {
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
@ -1139,25 +1047,25 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
? R.drawable.ic_warning_white : R.drawable.ic_warning_black;
|
? R.drawable.ic_warning_white : R.drawable.ic_warning_black;
|
||||||
|
|
||||||
new AlertDialog.Builder(this, dialogStyle())
|
new AlertDialog.Builder(this, dialogStyle())
|
||||||
.setTitle(R.string.external_link_popup_dialog_title)
|
.setTitle(R.string.external_link_popup_dialog_title)
|
||||||
.setMessage(R.string.external_link_popup_dialog_message)
|
.setMessage(R.string.external_link_popup_dialog_message)
|
||||||
.setNegativeButton(android.R.string.no, (dialogInterface, i) -> {
|
.setNegativeButton(android.R.string.no, (dialogInterface, i) -> {
|
||||||
// do nothing
|
// do nothing
|
||||||
})
|
})
|
||||||
.setNeutralButton(R.string.do_not_ask_anymore, (dialogInterface, i) -> {
|
.setNeutralButton(R.string.do_not_ask_anymore, (dialogInterface, i) -> {
|
||||||
sharedPreferenceUtil.putPrefExternalLinkPopup(false);
|
sharedPreferenceUtil.putPrefExternalLinkPopup(false);
|
||||||
isExternalLinkPopup = false;
|
isExternalLinkPopup = false;
|
||||||
|
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
})
|
})
|
||||||
.setPositiveButton(android.R.string.yes, (dialogInterface, i) -> startActivity(intent))
|
.setPositiveButton(android.R.string.yes, (dialogInterface, i) -> startActivity(intent))
|
||||||
.setIcon(warningResId)
|
.setIcon(warningResId)
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void openZimFile(File file, boolean clearHistory) {
|
private void openZimFile(File file, boolean clearHistory) {
|
||||||
if (file.canRead() || Build.VERSION.SDK_INT < 19 || (BuildConfig.IS_CUSTOM_APP
|
if (file.canRead() || Build.VERSION.SDK_INT < 19 || (BuildConfig.IS_CUSTOM_APP
|
||||||
&& Build.VERSION.SDK_INT != 23)) {
|
&& Build.VERSION.SDK_INT != 23)) {
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
if (ZimContentProvider.setZimFile(file.getAbsolutePath()) != null) {
|
if (ZimContentProvider.setZimFile(file.getAbsolutePath()) != null) {
|
||||||
|
|
||||||
@ -1175,40 +1083,40 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
presenter.loadCurrentZimBookmarksUrl();
|
presenter.loadCurrentZimBookmarksUrl();
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(this, getResources().getString(R.string.error_file_invalid),
|
Toast.makeText(this, getResources().getString(R.string.error_file_invalid),
|
||||||
Toast.LENGTH_LONG).show();
|
Toast.LENGTH_LONG).show();
|
||||||
showHomePage();
|
showHomePage();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.w(TAG_KIWIX, "ZIM file doesn't exist at " + file.getAbsolutePath());
|
Log.w(TAG_KIWIX, "ZIM file doesn't exist at " + file.getAbsolutePath());
|
||||||
|
|
||||||
Toast.makeText(this, getResources().getString(R.string.error_file_not_found),
|
Toast.makeText(this, getResources().getString(R.string.error_file_not_found),
|
||||||
Toast.LENGTH_LONG)
|
Toast.LENGTH_LONG)
|
||||||
.show();
|
.show();
|
||||||
showHomePage();
|
showHomePage();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.file = file;
|
this.file = file;
|
||||||
ActivityCompat.requestPermissions(this,
|
ActivityCompat.requestPermissions(this,
|
||||||
new String[] { Manifest.permission.READ_EXTERNAL_STORAGE },
|
new String[] { Manifest.permission.READ_EXTERNAL_STORAGE },
|
||||||
REQUEST_STORAGE_PERMISSION);
|
REQUEST_STORAGE_PERMISSION);
|
||||||
if (BuildConfig.IS_CUSTOM_APP && Build.VERSION.SDK_INT == Build.VERSION_CODES.M) {
|
if (BuildConfig.IS_CUSTOM_APP && Build.VERSION.SDK_INT == Build.VERSION_CODES.M) {
|
||||||
Toast.makeText(this, getResources().getString(R.string.request_storage_custom),
|
Toast.makeText(this, getResources().getString(R.string.request_storage_custom),
|
||||||
Toast.LENGTH_LONG)
|
Toast.LENGTH_LONG)
|
||||||
.show();
|
.show();
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(this, getResources().getString(R.string.request_storage), Toast.LENGTH_LONG)
|
Toast.makeText(this, getResources().getString(R.string.request_storage), Toast.LENGTH_LONG)
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRequestPermissionsResult(int requestCode,
|
public void onRequestPermissionsResult(int requestCode,
|
||||||
@NonNull String[] permissions, @NonNull int[] grantResults) {
|
@NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||||
switch (requestCode) {
|
switch (requestCode) {
|
||||||
case REQUEST_STORAGE_PERMISSION: {
|
case REQUEST_STORAGE_PERMISSION: {
|
||||||
if (grantResults.length > 0
|
if (grantResults.length > 0
|
||||||
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||||
finish();
|
finish();
|
||||||
Intent newZimFile = new Intent(MainActivity.this, MainActivity.class);
|
Intent newZimFile = new Intent(MainActivity.this, MainActivity.class);
|
||||||
newZimFile.setData(Uri.fromFile(file));
|
newZimFile.setData(Uri.fromFile(file));
|
||||||
@ -1224,17 +1132,17 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
|
|
||||||
case REQUEST_READ_STORAGE_PERMISSION: {
|
case REQUEST_READ_STORAGE_PERMISSION: {
|
||||||
if (grantResults.length > 0
|
if (grantResults.length > 0
|
||||||
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||||
scanStorageForZims();
|
scanStorageForZims();
|
||||||
} else {
|
} else {
|
||||||
Snackbar.make(snackbarRoot, R.string.request_storage, Snackbar.LENGTH_LONG)
|
Snackbar.make(snackbarRoot, R.string.request_storage, Snackbar.LENGTH_LONG)
|
||||||
.setAction(R.string.menu_settings, view -> {
|
.setAction(R.string.menu_settings, view -> {
|
||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
||||||
Uri uri = Uri.fromParts("package", getPackageName(), null);
|
Uri uri = Uri.fromParts("package", getPackageName(), null);
|
||||||
intent.setData(uri);
|
intent.setData(uri);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}).show();
|
}).show();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1246,7 +1154,8 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
showAddNoteDialog();
|
showAddNoteDialog();
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(getApplicationContext(),
|
Toast.makeText(getApplicationContext(),
|
||||||
getString(R.string.ext_storage_write_permission_denied_add_note), Toast.LENGTH_LONG);
|
getString(R.string.ext_storage_write_permission_denied_add_note), Toast.LENGTH_LONG)
|
||||||
|
.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -1256,9 +1165,9 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
|
|
||||||
private void scanStorageForZims() {
|
private void scanStorageForZims() {
|
||||||
storageObserver.getBooksOnFileSystem()
|
storageObserver.getBooksOnFileSystem()
|
||||||
.take(1)
|
.take(1)
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(presenter::saveBooks, Throwable::printStackTrace);
|
.subscribe(presenter::saveBooks, Throwable::printStackTrace);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Workaround for popup bottom menu on older devices
|
// Workaround for popup bottom menu on older devices
|
||||||
@ -1290,9 +1199,7 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
private void initAllMenuItems() {
|
private void initAllMenuItems() {
|
||||||
try {
|
try {
|
||||||
menu.findItem(R.id.menu_fullscreen).setVisible(true);
|
menu.findItem(R.id.menu_fullscreen).setVisible(true);
|
||||||
menu.findItem(R.id.menu_home).setVisible(true);
|
|
||||||
menu.findItem(R.id.menu_random_article).setVisible(true);
|
menu.findItem(R.id.menu_random_article).setVisible(true);
|
||||||
menu.findItem(R.id.menu_searchintext).setVisible(true);
|
|
||||||
|
|
||||||
MenuItem searchItem = menu.findItem(R.id.menu_search);
|
MenuItem searchItem = menu.findItem(R.id.menu_search);
|
||||||
searchItem.setVisible(true);
|
searchItem.setVisible(true);
|
||||||
@ -1309,7 +1216,7 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
menu.findItem(R.id.menu_read_aloud).setVisible(true);
|
menu.findItem(R.id.menu_read_aloud).setVisible(true);
|
||||||
if (isSpeaking) {
|
if (isSpeaking) {
|
||||||
menu.findItem(R.id.menu_read_aloud)
|
menu.findItem(R.id.menu_read_aloud)
|
||||||
.setTitle(createMenuItem(getResources().getString(R.string.menu_read_aloud_stop)));
|
.setTitle(createMenuItem(getResources().getString(R.string.menu_read_aloud_stop)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -1368,7 +1275,8 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
boolean isBookmark = false;
|
boolean isBookmark = false;
|
||||||
if (articleUrl != null && !bookmarks.contains(articleUrl)) {
|
if (articleUrl != null && !bookmarks.contains(articleUrl)) {
|
||||||
if (ZimContentProvider.getId() != null) {
|
if (ZimContentProvider.getId() != null) {
|
||||||
presenter.saveBookmark( BookmarkItem.fromZimContentProvider(getCurrentWebView().getTitle(), articleUrl));
|
presenter.saveBookmark(
|
||||||
|
BookmarkItem.fromZimContentProvider(getCurrentWebView().getTitle(), articleUrl));
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(this, R.string.unable_to_add_to_bookmarks, Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, R.string.unable_to_add_to_bookmarks, Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
@ -1384,12 +1292,12 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
private void popBookmarkSnackbar(boolean isBookmark) {
|
private void popBookmarkSnackbar(boolean isBookmark) {
|
||||||
if (isBookmark) {
|
if (isBookmark) {
|
||||||
Snackbar.make(snackbarRoot, R.string.bookmark_added, Snackbar.LENGTH_LONG)
|
Snackbar.make(snackbarRoot, R.string.bookmark_added, Snackbar.LENGTH_LONG)
|
||||||
.setAction(getString(R.string.open), v -> goToBookmarks())
|
.setAction(getString(R.string.open), v -> goToBookmarks())
|
||||||
.setActionTextColor(getResources().getColor(R.color.white))
|
.setActionTextColor(getResources().getColor(R.color.white))
|
||||||
.show();
|
.show();
|
||||||
} else {
|
} else {
|
||||||
Snackbar.make(snackbarRoot, R.string.bookmark_removed, Snackbar.LENGTH_LONG)
|
Snackbar.make(snackbarRoot, R.string.bookmark_removed, Snackbar.LENGTH_LONG)
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1421,9 +1329,9 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!webViewList.isEmpty() && currentWebViewIndex < webViewList.size() &&
|
if (!webViewList.isEmpty() && currentWebViewIndex < webViewList.size() &&
|
||||||
webViewList.get(currentWebViewIndex).getUrl() != null &&
|
webViewList.get(currentWebViewIndex).getUrl() != null &&
|
||||||
webViewList.get(currentWebViewIndex).getUrl().equals(HOME_URL) &&
|
webViewList.get(currentWebViewIndex).getUrl().equals(HOME_URL) &&
|
||||||
webViewList.get(currentWebViewIndex).findViewById(R.id.get_content_card) != null) {
|
webViewList.get(currentWebViewIndex).findViewById(R.id.get_content_card) != null) {
|
||||||
webViewList.get(currentWebViewIndex).findViewById(R.id.get_content_card).setEnabled(true);
|
webViewList.get(currentWebViewIndex).findViewById(R.id.get_content_card).setEnabled(true);
|
||||||
}
|
}
|
||||||
updateBottomToolbarVisibility();
|
updateBottomToolbarVisibility();
|
||||||
@ -1482,12 +1390,12 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
private void updateBottomToolbarVisibility() {
|
private void updateBottomToolbarVisibility() {
|
||||||
if (checkNull(bottomToolbar)) {
|
if (checkNull(bottomToolbar)) {
|
||||||
if (!HOME_URL.equals(
|
if (!HOME_URL.equals(
|
||||||
getCurrentWebView().getUrl())
|
getCurrentWebView().getUrl())
|
||||||
&& tabSwitcherRoot.getVisibility() != View.VISIBLE) {
|
&& tabSwitcherRoot.getVisibility() != View.VISIBLE) {
|
||||||
bottomToolbar.setVisibility(View.VISIBLE);
|
bottomToolbar.setVisibility(View.VISIBLE);
|
||||||
if (getCurrentWebView() instanceof ToolbarStaticKiwixWebView) {
|
if (getCurrentWebView() instanceof ToolbarStaticKiwixWebView) {
|
||||||
contentFrame.setPadding(0, 0, 0,
|
contentFrame.setPadding(0, 0, 0,
|
||||||
(int) getResources().getDimension(R.dimen.bottom_toolbar_height));
|
(int) getResources().getDimension(R.dimen.bottom_toolbar_height));
|
||||||
} else {
|
} else {
|
||||||
contentFrame.setPadding(0, 0, 0, 0);
|
contentFrame.setPadding(0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
@ -1528,10 +1436,10 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this, dialogStyle());
|
AlertDialog.Builder builder = new AlertDialog.Builder(this, dialogStyle());
|
||||||
builder.setMessage(getString(R.string.hint_contents_drawer_message))
|
builder.setMessage(getString(R.string.hint_contents_drawer_message))
|
||||||
.setPositiveButton(getString(R.string.got_it), (dialog, id) -> {
|
.setPositiveButton(getString(R.string.got_it), (dialog, id) -> {
|
||||||
})
|
})
|
||||||
.setTitle(getString(R.string.did_you_know))
|
.setTitle(getString(R.string.did_you_know))
|
||||||
.setIcon(R.drawable.icon_question);
|
.setIcon(R.drawable.icon_question);
|
||||||
AlertDialog alert = builder.create();
|
AlertDialog alert = builder.create();
|
||||||
alert.show();
|
alert.show();
|
||||||
}
|
}
|
||||||
@ -1539,7 +1447,7 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
private void openArticle(String articleUrl) {
|
private void openArticle(String articleUrl) {
|
||||||
if (articleUrl != null) {
|
if (articleUrl != null) {
|
||||||
getCurrentWebView().loadUrl(
|
getCurrentWebView().loadUrl(
|
||||||
Uri.parse(ZimContentProvider.CONTENT_URI + articleUrl).toString());
|
Uri.parse(ZimContentProvider.CONTENT_URI + articleUrl).toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1590,13 +1498,10 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
private void toggleActionItemsConfig() {
|
private void toggleActionItemsConfig() {
|
||||||
if (menu != null) {
|
if (menu != null) {
|
||||||
MenuItem random = menu.findItem(R.id.menu_random_article);
|
MenuItem random = menu.findItem(R.id.menu_random_article);
|
||||||
MenuItem home = menu.findItem(R.id.menu_home);
|
|
||||||
if (getResources().getConfiguration().orientation == ORIENTATION_LANDSCAPE) {
|
if (getResources().getConfiguration().orientation == ORIENTATION_LANDSCAPE) {
|
||||||
random.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
|
random.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
|
||||||
home.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
|
|
||||||
} else {
|
} else {
|
||||||
random.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
|
random.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
|
||||||
home.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1621,7 +1526,7 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
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>", "");
|
||||||
boolean isSearchInText = data.getBooleanExtra(EXTRA_SEARCH_IN_TEXT, false);
|
boolean isSearchInText = data.getBooleanExtra(EXTRA_SEARCH_IN_TEXT, false);
|
||||||
if (isSearchInText) {
|
if (isSearchInText) {
|
||||||
//if the search is localized trigger find in page UI.
|
//if the search is localized trigger find in page UI.
|
||||||
@ -1738,7 +1643,7 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
this.menu = menu;
|
this.menu = menu;
|
||||||
|
|
||||||
if (getCurrentWebView().getUrl() == null ||
|
if (getCurrentWebView().getUrl() == null ||
|
||||||
getCurrentWebView().getUrl().equals(HOME_URL)) {
|
getCurrentWebView().getUrl().equals(HOME_URL)) {
|
||||||
menu.findItem(R.id.menu_read_aloud).setVisible(false);
|
menu.findItem(R.id.menu_read_aloud).setVisible(false);
|
||||||
} else {
|
} else {
|
||||||
menu.findItem(R.id.menu_read_aloud).setVisible(true);
|
menu.findItem(R.id.menu_read_aloud).setVisible(true);
|
||||||
@ -1747,25 +1652,19 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
if (tabSwitcherRoot.getVisibility() == View.VISIBLE) {
|
if (tabSwitcherRoot.getVisibility() == View.VISIBLE) {
|
||||||
menu.findItem(R.id.menu_search).setVisible(false);
|
menu.findItem(R.id.menu_search).setVisible(false);
|
||||||
menu.findItem(R.id.menu_fullscreen).setVisible(false);
|
menu.findItem(R.id.menu_fullscreen).setVisible(false);
|
||||||
menu.findItem(R.id.menu_home).setVisible(false);
|
|
||||||
menu.findItem(R.id.menu_random_article).setVisible(false);
|
menu.findItem(R.id.menu_random_article).setVisible(false);
|
||||||
menu.findItem(R.id.menu_searchintext).setVisible(false);
|
|
||||||
menu.findItem(R.id.menu_read_aloud).setVisible(false);
|
menu.findItem(R.id.menu_read_aloud).setVisible(false);
|
||||||
} else {
|
} else {
|
||||||
menu.findItem(R.id.menu_search).setVisible(true);
|
menu.findItem(R.id.menu_search).setVisible(true);
|
||||||
menu.findItem(R.id.menu_fullscreen).setVisible(true);
|
menu.findItem(R.id.menu_fullscreen).setVisible(true);
|
||||||
if (getCurrentWebView().getUrl() == null ||
|
if (getCurrentWebView().getUrl() == null ||
|
||||||
getCurrentWebView().getUrl().equals(HOME_URL)) {
|
getCurrentWebView().getUrl().equals(HOME_URL)) {
|
||||||
menu.findItem(R.id.menu_read_aloud).setVisible(false);
|
menu.findItem(R.id.menu_read_aloud).setVisible(false);
|
||||||
menu.findItem(R.id.menu_home).setVisible(false);
|
|
||||||
menu.findItem(R.id.menu_random_article).setVisible(false);
|
menu.findItem(R.id.menu_random_article).setVisible(false);
|
||||||
menu.findItem(R.id.menu_searchintext).setVisible(false);
|
|
||||||
menu.findItem(R.id.menu_host_books).setVisible(true);
|
menu.findItem(R.id.menu_host_books).setVisible(true);
|
||||||
} else {
|
} else {
|
||||||
menu.findItem(R.id.menu_read_aloud).setVisible(true);
|
menu.findItem(R.id.menu_read_aloud).setVisible(true);
|
||||||
menu.findItem(R.id.menu_home).setVisible(true);
|
|
||||||
menu.findItem(R.id.menu_random_article).setVisible(true);
|
menu.findItem(R.id.menu_random_article).setVisible(true);
|
||||||
menu.findItem(R.id.menu_searchintext).setVisible(true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -1784,10 +1683,10 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
private void refreshBookmarkSymbol() {
|
private void refreshBookmarkSymbol() {
|
||||||
if (checkNull(bottomToolbarBookmark)) {
|
if (checkNull(bottomToolbarBookmark)) {
|
||||||
if (getCurrentWebView().getUrl() != null &&
|
if (getCurrentWebView().getUrl() != null &&
|
||||||
ZimContentProvider.getId() != null &&
|
ZimContentProvider.getId() != null &&
|
||||||
!getCurrentWebView().getUrl().equals(HOME_URL)) {
|
!getCurrentWebView().getUrl().equals(HOME_URL)) {
|
||||||
int icon = bookmarks.contains(getCurrentWebView().getUrl()) ? R.drawable.ic_bookmark_24dp
|
int icon = bookmarks.contains(getCurrentWebView().getUrl()) ? R.drawable.ic_bookmark_24dp
|
||||||
: R.drawable.ic_bookmark_border_24dp;
|
: R.drawable.ic_bookmark_border_24dp;
|
||||||
bottomToolbarBookmark.setImageResource(icon);
|
bottomToolbarBookmark.setImageResource(icon);
|
||||||
} else {
|
} else {
|
||||||
bottomToolbarBookmark.setImageResource(R.drawable.ic_bookmark_border_24dp);
|
bottomToolbarBookmark.setImageResource(R.drawable.ic_bookmark_border_24dp);
|
||||||
@ -1905,100 +1804,100 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
* loadCustomAppContent Return true if all's well, else false.
|
* loadCustomAppContent Return true if all's well, else false.
|
||||||
*/
|
*/
|
||||||
private boolean loadCustomAppContent() {
|
private boolean loadCustomAppContent() {
|
||||||
Log.d(TAG_KIWIX, "Kiwix Custom App starting for the first time. Checking Companion ZIM: "
|
Log.d(TAG_KIWIX, "Kiwix Custom App starting for the first time. Checking Companion ZIM: "
|
||||||
+ BuildConfig.ZIM_FILE_NAME);
|
+ BuildConfig.ZIM_FILE_NAME);
|
||||||
|
|
||||||
String currentLocaleCode = Locale.getDefault().toString();
|
String currentLocaleCode = Locale.getDefault().toString();
|
||||||
// Custom App recommends to start off a specific language
|
// Custom App recommends to start off a specific language
|
||||||
if (BuildConfig.ENFORCED_LANG.length() > 0 && !BuildConfig.ENFORCED_LANG
|
if (BuildConfig.ENFORCED_LANG.length() > 0 && !BuildConfig.ENFORCED_LANG
|
||||||
.equals(currentLocaleCode)) {
|
.equals(currentLocaleCode)) {
|
||||||
|
|
||||||
// change the locale machinery
|
// change the locale machinery
|
||||||
LanguageUtils.handleLocaleChange(this, BuildConfig.ENFORCED_LANG);
|
LanguageUtils.handleLocaleChange(this, BuildConfig.ENFORCED_LANG);
|
||||||
|
|
||||||
// save new locale into preferences for next startup
|
// save new locale into preferences for next startup
|
||||||
sharedPreferenceUtil.putPrefLanguage(BuildConfig.ENFORCED_LANG);
|
sharedPreferenceUtil.putPrefLanguage(BuildConfig.ENFORCED_LANG);
|
||||||
|
|
||||||
// restart activity for new locale to take effect
|
// restart activity for new locale to take effect
|
||||||
this.setResult(1236);
|
this.setResult(1236);
|
||||||
this.finish();
|
this.finish();
|
||||||
this.startActivity(new Intent(this, this.getClass()));
|
this.startActivity(new Intent(this, this.getClass()));
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
String filePath = "";
|
||||||
|
if (BuildConfig.HAS_EMBEDDED_ZIM) {
|
||||||
|
String appPath = getPackageResourcePath();
|
||||||
|
File libDir = new File(appPath.substring(0, appPath.lastIndexOf("/")) + "/lib/");
|
||||||
|
if (libDir.exists() && libDir.listFiles().length > 0) {
|
||||||
|
filePath = libDir.listFiles()[0].getPath() + "/" + BuildConfig.ZIM_FILE_NAME;
|
||||||
}
|
}
|
||||||
|
if (filePath.isEmpty() || !new File(filePath).exists()) {
|
||||||
String filePath = "";
|
filePath = String.format("/data/data/%s/lib/%s", BuildConfig.APPLICATION_ID,
|
||||||
if (BuildConfig.HAS_EMBEDDED_ZIM) {
|
BuildConfig.ZIM_FILE_NAME);
|
||||||
String appPath = getPackageResourcePath();
|
|
||||||
File libDir = new File(appPath.substring(0, appPath.lastIndexOf("/")) + "/lib/");
|
|
||||||
if (libDir.exists() && libDir.listFiles().length > 0) {
|
|
||||||
filePath = libDir.listFiles()[0].getPath() + "/" + BuildConfig.ZIM_FILE_NAME;
|
|
||||||
}
|
|
||||||
if (filePath.isEmpty() || !new File(filePath).exists()) {
|
|
||||||
filePath = String.format("/data/data/%s/lib/%s", BuildConfig.APPLICATION_ID,
|
|
||||||
BuildConfig.ZIM_FILE_NAME);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
String fileName = FileUtils.getExpansionAPKFileName(true);
|
|
||||||
filePath = FileUtils.generateSaveFileName(fileName);
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
String fileName = FileUtils.getExpansionAPKFileName(true);
|
||||||
|
filePath = FileUtils.generateSaveFileName(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
Log.d(TAG_KIWIX, "BuildConfig.ZIM_FILE_SIZE = " + BuildConfig.ZIM_FILE_SIZE);
|
Log.d(TAG_KIWIX, "BuildConfig.ZIM_FILE_SIZE = " + BuildConfig.ZIM_FILE_SIZE);
|
||||||
if (!FileUtils.doesFileExist(filePath, BuildConfig.ZIM_FILE_SIZE, false)) {
|
if (!FileUtils.doesFileExist(filePath, BuildConfig.ZIM_FILE_SIZE, false)) {
|
||||||
|
|
||||||
AlertDialog.Builder zimFileMissingBuilder =
|
AlertDialog.Builder zimFileMissingBuilder =
|
||||||
new AlertDialog.Builder(this, dialogStyle());
|
new AlertDialog.Builder(this, dialogStyle());
|
||||||
zimFileMissingBuilder.setTitle(R.string.app_name);
|
zimFileMissingBuilder.setTitle(R.string.app_name);
|
||||||
zimFileMissingBuilder.setMessage(R.string.custom_app_missing_content);
|
zimFileMissingBuilder.setMessage(R.string.custom_app_missing_content);
|
||||||
zimFileMissingBuilder.setIcon(R.mipmap.kiwix_icon);
|
zimFileMissingBuilder.setIcon(R.mipmap.kiwix_icon);
|
||||||
final Activity activity = this;
|
final Activity activity = this;
|
||||||
zimFileMissingBuilder.setPositiveButton(getString(R.string.go_to_play_store),
|
zimFileMissingBuilder.setPositiveButton(getString(R.string.go_to_play_store),
|
||||||
(dialog, which) -> {
|
(dialog, which) -> {
|
||||||
String market_uri = "market://details?id=" + BuildConfig.APPLICATION_ID;
|
String market_uri = "market://details?id=" + BuildConfig.APPLICATION_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);
|
||||||
activity.finish();
|
activity.finish();
|
||||||
});
|
});
|
||||||
zimFileMissingBuilder.setCancelable(false);
|
zimFileMissingBuilder.setCancelable(false);
|
||||||
AlertDialog zimFileMissingDialog = zimFileMissingBuilder.create();
|
AlertDialog zimFileMissingDialog = zimFileMissingBuilder.create();
|
||||||
zimFileMissingDialog.show();
|
zimFileMissingDialog.show();
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
openZimFile(new File(filePath), true);
|
openZimFile(new File(filePath), true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void manageExternalLaunchAndRestoringViewState() {
|
private void manageExternalLaunchAndRestoringViewState() {
|
||||||
|
|
||||||
if (getIntent().getData() != null) {
|
if (getIntent().getData() != null) {
|
||||||
String filePath =
|
String filePath =
|
||||||
FileUtils.getLocalFilePathByUri(getApplicationContext(), getIntent().getData());
|
FileUtils.getLocalFilePathByUri(getApplicationContext(), getIntent().getData());
|
||||||
|
|
||||||
if (filePath == null || !new File(filePath).exists()) {
|
if (filePath == null || !new File(filePath).exists()) {
|
||||||
Toast.makeText(MainActivity.this, getString(R.string.error_file_not_found), Toast.LENGTH_LONG)
|
Toast.makeText(MainActivity.this, getString(R.string.error_file_not_found),
|
||||||
.show();
|
Toast.LENGTH_LONG)
|
||||||
|
.show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.d(TAG_KIWIX, "Kiwix started from a file manager. Intent filePath: "
|
Log.d(TAG_KIWIX, "Kiwix started from a file manager. Intent filePath: "
|
||||||
+ filePath
|
+ filePath
|
||||||
+ " -> open this zim file and load menu_main page");
|
+ " -> open this zim file and load menu_main page");
|
||||||
openZimFile(new File(filePath), false);
|
openZimFile(new File(filePath), false);
|
||||||
} else {
|
} else {
|
||||||
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);
|
||||||
if (zimFile != null && new File(zimFile).exists()) {
|
if (zimFile != null && new File(zimFile).exists()) {
|
||||||
Log.d(TAG_KIWIX,
|
Log.d(TAG_KIWIX,
|
||||||
"Kiwix normal start, zimFile loaded last time -> Open last used zimFile " + zimFile);
|
"Kiwix normal start, zimFile loaded last time -> Open last used zimFile " + zimFile);
|
||||||
restoreTabStates();
|
restoreTabStates();
|
||||||
// Alternative would be to restore webView state. But more effort to implement, and actually
|
// Alternative would be to restore webView state. But more effort to implement, and actually
|
||||||
// fits better normal android behavior if after closing app ("back" button) state is not maintained.
|
// fits better normal android behavior if after closing app ("back" button) state is not maintained.
|
||||||
} else {
|
} else {
|
||||||
Log.d(TAG_KIWIX, "Kiwix normal start, no zimFile loaded last time -> display home page");
|
Log.d(TAG_KIWIX, "Kiwix normal start, no zimFile loaded last time -> display home page");
|
||||||
showHomePage();
|
showHomePage();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2007,7 +1906,7 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
super.onPause();
|
super.onPause();
|
||||||
saveTabStates();
|
saveTabStates();
|
||||||
Log.d(TAG_KIWIX,
|
Log.d(TAG_KIWIX,
|
||||||
"onPause Save current zim file to preferences: " + ZimContentProvider.getZimFile());
|
"onPause Save current zim file to preferences: " + ZimContentProvider.getZimFile());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -2029,18 +1928,18 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
if (url != null && !url.equals(HOME_URL)) {
|
if (url != null && !url.equals(HOME_URL)) {
|
||||||
final long timeStamp = System.currentTimeMillis();
|
final long timeStamp = System.currentTimeMillis();
|
||||||
SimpleDateFormat sdf =
|
SimpleDateFormat sdf =
|
||||||
new SimpleDateFormat("d MMM yyyy", LanguageUtils.getCurrentLocale(this));
|
new SimpleDateFormat("d MMM yyyy", LanguageUtils.getCurrentLocale(this));
|
||||||
HistoryListItem.HistoryItem history = new HistoryListItem.HistoryItem(
|
HistoryListItem.HistoryItem history = new HistoryListItem.HistoryItem(
|
||||||
0L,
|
0L,
|
||||||
ZimContentProvider.getId(),
|
ZimContentProvider.getId(),
|
||||||
ZimContentProvider.getName(),
|
ZimContentProvider.getName(),
|
||||||
ZimContentProvider.getZimFile(),
|
ZimContentProvider.getZimFile(),
|
||||||
ZimContentProvider.getFavicon(),
|
ZimContentProvider.getFavicon(),
|
||||||
getCurrentWebView().getTitle(),
|
getCurrentWebView().getTitle(),
|
||||||
getCurrentWebView().getUrl(),
|
getCurrentWebView().getUrl(),
|
||||||
sdf.format(new Date(timeStamp)),
|
sdf.format(new Date(timeStamp)),
|
||||||
timeStamp,
|
timeStamp,
|
||||||
0L
|
0L
|
||||||
);
|
);
|
||||||
presenter.saveHistory(history);
|
presenter.saveHistory(history);
|
||||||
}
|
}
|
||||||
@ -2060,7 +1959,7 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
if (progress == 100) {
|
if (progress == 100) {
|
||||||
if (requestClearHistoryAfterLoad) {
|
if (requestClearHistoryAfterLoad) {
|
||||||
Log.d(TAG_KIWIX,
|
Log.d(TAG_KIWIX,
|
||||||
"Loading article finished and requestClearHistoryAfterLoad -> clearHistory");
|
"Loading article finished and requestClearHistoryAfterLoad -> clearHistory");
|
||||||
getCurrentWebView().clearHistory();
|
getCurrentWebView().clearHistory();
|
||||||
requestClearHistoryAfterLoad = false;
|
requestClearHistoryAfterLoad = false;
|
||||||
}
|
}
|
||||||
@ -2082,8 +1981,8 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
hideBackToTopTimer.start();
|
hideBackToTopTimer.start();
|
||||||
if (getCurrentWebView().getScrollY() > 200) {
|
if (getCurrentWebView().getScrollY() > 200) {
|
||||||
if ((backToTopButton.getVisibility() == View.GONE
|
if ((backToTopButton.getVisibility() == View.GONE
|
||||||
|| backToTopButton.getVisibility() == View.INVISIBLE)
|
|| backToTopButton.getVisibility() == View.INVISIBLE)
|
||||||
&& TTSControls.getVisibility() == View.GONE) {
|
&& TTSControls.getVisibility() == View.GONE) {
|
||||||
backToTopButton.show();
|
backToTopButton.show();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -2114,11 +2013,11 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
if (isOpenNewTabInBackground) {
|
if (isOpenNewTabInBackground) {
|
||||||
newTabInBackground(url);
|
newTabInBackground(url);
|
||||||
Snackbar.make(snackbarRoot, R.string.new_tab_snack_bar, Snackbar.LENGTH_LONG)
|
Snackbar.make(snackbarRoot, R.string.new_tab_snack_bar, Snackbar.LENGTH_LONG)
|
||||||
.setAction(getString(R.string.open), v -> {
|
.setAction(getString(R.string.open), v -> {
|
||||||
if (webViewList.size() > 1) selectTab(webViewList.size() - 1);
|
if (webViewList.size() > 1) selectTab(webViewList.size() - 1);
|
||||||
})
|
})
|
||||||
.setActionTextColor(getResources().getColor(R.color.white))
|
.setActionTextColor(getResources().getColor(R.color.white))
|
||||||
.show();
|
.show();
|
||||||
} else {
|
} else {
|
||||||
newTab(url);
|
newTab(url);
|
||||||
}
|
}
|
||||||
@ -2154,11 +2053,11 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
|
|
||||||
private void searchFiles() {
|
private void searchFiles() {
|
||||||
if (Build.VERSION.SDK_INT >= VERSION_CODES.M && ContextCompat.checkSelfPermission(this,
|
if (Build.VERSION.SDK_INT >= VERSION_CODES.M && ContextCompat.checkSelfPermission(this,
|
||||||
Manifest.permission.READ_EXTERNAL_STORAGE)
|
Manifest.permission.READ_EXTERNAL_STORAGE)
|
||||||
!= PackageManager.PERMISSION_GRANTED) {
|
!= PackageManager.PERMISSION_GRANTED) {
|
||||||
ActivityCompat.requestPermissions(this,
|
ActivityCompat.requestPermissions(this,
|
||||||
new String[] { Manifest.permission.READ_EXTERNAL_STORAGE },
|
new String[] { Manifest.permission.READ_EXTERNAL_STORAGE },
|
||||||
REQUEST_READ_STORAGE_PERMISSION);
|
REQUEST_READ_STORAGE_PERMISSION);
|
||||||
} else {
|
} else {
|
||||||
scanStorageForZims();
|
scanStorageForZims();
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package org.kiwix.kiwixmobile.settings;
|
package org.kiwix.kiwixmobile.settings;
|
||||||
|
|
||||||
|
import android.Manifest;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
@ -37,6 +38,7 @@ import android.widget.Toast;
|
|||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.appcompat.widget.Toolbar;
|
import androidx.appcompat.widget.Toolbar;
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
import eu.mhutti1.utils.storage.StorageDevice;
|
import eu.mhutti1.utils.storage.StorageDevice;
|
||||||
import eu.mhutti1.utils.storage.StorageSelectDialog;
|
import eu.mhutti1.utils.storage.StorageSelectDialog;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -44,27 +46,27 @@ import java.util.List;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import kotlin.Unit;
|
import kotlin.Unit;
|
||||||
|
import kotlin.io.FilesKt;
|
||||||
import org.kiwix.kiwixmobile.BuildConfig;
|
import org.kiwix.kiwixmobile.BuildConfig;
|
||||||
import org.kiwix.kiwixmobile.KiwixApplication;
|
import org.kiwix.kiwixmobile.KiwixApplication;
|
||||||
import org.kiwix.kiwixmobile.R;
|
import org.kiwix.kiwixmobile.R;
|
||||||
import org.kiwix.kiwixmobile.base.BaseActivity;
|
import org.kiwix.kiwixmobile.base.BaseActivity;
|
||||||
|
import org.kiwix.kiwixmobile.extensions.ContextExtensionsKt;
|
||||||
|
import org.kiwix.kiwixmobile.main.AddNoteDialog;
|
||||||
import org.kiwix.kiwixmobile.main.MainActivity;
|
import org.kiwix.kiwixmobile.main.MainActivity;
|
||||||
import org.kiwix.kiwixmobile.utils.LanguageUtils;
|
import org.kiwix.kiwixmobile.utils.LanguageUtils;
|
||||||
import org.kiwix.kiwixmobile.utils.SharedPreferenceUtil;
|
import org.kiwix.kiwixmobile.utils.SharedPreferenceUtil;
|
||||||
|
|
||||||
import static org.kiwix.kiwixmobile.utils.Constants.EXTRA_WEBVIEWS_LIST;
|
import static org.kiwix.kiwixmobile.utils.Constants.EXTRA_WEBVIEWS_LIST;
|
||||||
import static org.kiwix.kiwixmobile.utils.Constants.PREF_AUTONIGHTMODE;
|
|
||||||
import static org.kiwix.kiwixmobile.utils.Constants.PREF_CLEAR_ALL_HISTORY;
|
|
||||||
import static org.kiwix.kiwixmobile.utils.Constants.PREF_CREDITS;
|
|
||||||
import static org.kiwix.kiwixmobile.utils.Constants.PREF_LANG;
|
|
||||||
import static org.kiwix.kiwixmobile.utils.Constants.PREF_NIGHTMODE;
|
|
||||||
import static org.kiwix.kiwixmobile.utils.Constants.PREF_STORAGE;
|
|
||||||
import static org.kiwix.kiwixmobile.utils.Constants.PREF_VERSION;
|
|
||||||
import static org.kiwix.kiwixmobile.utils.Constants.PREF_WIFI_ONLY;
|
|
||||||
import static org.kiwix.kiwixmobile.utils.Constants.PREF_ZOOM;
|
|
||||||
import static org.kiwix.kiwixmobile.utils.Constants.PREF_ZOOM_ENABLED;
|
|
||||||
import static org.kiwix.kiwixmobile.utils.Constants.RESULT_HISTORY_CLEARED;
|
import static org.kiwix.kiwixmobile.utils.Constants.RESULT_HISTORY_CLEARED;
|
||||||
import static org.kiwix.kiwixmobile.utils.Constants.RESULT_RESTART;
|
import static org.kiwix.kiwixmobile.utils.Constants.RESULT_RESTART;
|
||||||
|
import static org.kiwix.kiwixmobile.utils.SharedPreferenceUtil.PREF_AUTONIGHTMODE;
|
||||||
|
import static org.kiwix.kiwixmobile.utils.SharedPreferenceUtil.PREF_LANG;
|
||||||
|
import static org.kiwix.kiwixmobile.utils.SharedPreferenceUtil.PREF_NIGHTMODE;
|
||||||
|
import static org.kiwix.kiwixmobile.utils.SharedPreferenceUtil.PREF_STORAGE;
|
||||||
|
import static org.kiwix.kiwixmobile.utils.SharedPreferenceUtil.PREF_WIFI_ONLY;
|
||||||
|
import static org.kiwix.kiwixmobile.utils.SharedPreferenceUtil.PREF_ZOOM;
|
||||||
|
import static org.kiwix.kiwixmobile.utils.SharedPreferenceUtil.PREF_ZOOM_ENABLED;
|
||||||
import static org.kiwix.kiwixmobile.utils.StyleUtils.dialogStyle;
|
import static org.kiwix.kiwixmobile.utils.StyleUtils.dialogStyle;
|
||||||
|
|
||||||
public class KiwixSettingsActivity extends BaseActivity {
|
public class KiwixSettingsActivity extends BaseActivity {
|
||||||
@ -112,6 +114,10 @@ public class KiwixSettingsActivity extends BaseActivity {
|
|||||||
SettingsContract.View,
|
SettingsContract.View,
|
||||||
SharedPreferences.OnSharedPreferenceChangeListener {
|
SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
|
|
||||||
|
public static final String PREF_VERSION = "pref_version";
|
||||||
|
public static final String PREF_CLEAR_ALL_HISTORY = "pref_clear_all_history";
|
||||||
|
public static final String PREF_CLEAR_ALL_NOTES = "pref_clear_all_notes";
|
||||||
|
public static final String PREF_CREDITS = "pref_credits";
|
||||||
@Inject
|
@Inject
|
||||||
SettingsPresenter presenter;
|
SettingsPresenter presenter;
|
||||||
@Inject
|
@Inject
|
||||||
@ -298,6 +304,40 @@ public class KiwixSettingsActivity extends BaseActivity {
|
|||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void showClearAllNotesDialog() {
|
||||||
|
AlertDialog.Builder builder;
|
||||||
|
if (sharedPreferenceUtil.nightMode()) { // Night Mode support
|
||||||
|
builder = new AlertDialog.Builder(getActivity(), R.style.AppTheme_Dialog_Night);
|
||||||
|
} else {
|
||||||
|
builder = new AlertDialog.Builder(getActivity());
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.setMessage(R.string.delete_notes_confirmation_msg)
|
||||||
|
.setNegativeButton(android.R.string.cancel, null) // Do nothing for 'Cancel' button
|
||||||
|
.setPositiveButton(R.string.yes, (dialog, which) -> clearAllNotes())
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void clearAllNotes() {
|
||||||
|
if (KiwixApplication.getInstance().isExternalStorageWritable()) {
|
||||||
|
if (ContextCompat.checkSelfPermission(getActivity(),
|
||||||
|
Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||||
|
!= PackageManager.PERMISSION_GRANTED) {
|
||||||
|
ContextExtensionsKt.toast(getActivity(), R.string.ext_storage_permission_not_granted,
|
||||||
|
Toast.LENGTH_LONG);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (FilesKt.deleteRecursively(new File(AddNoteDialog.NOTES_DIRECTORY))) {
|
||||||
|
ContextExtensionsKt.toast(getActivity(), R.string.notes_deletion_successful,
|
||||||
|
Toast.LENGTH_SHORT);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ContextExtensionsKt.toast(getActivity(), R.string.notes_deletion_unsuccessful,
|
||||||
|
Toast.LENGTH_SHORT);
|
||||||
|
}
|
||||||
|
|
||||||
public void openCredits() {
|
public void openCredits() {
|
||||||
WebView view =
|
WebView view =
|
||||||
(WebView) LayoutInflater.from(getActivity()).inflate(R.layout.credits_webview, null);
|
(WebView) LayoutInflater.from(getActivity()).inflate(R.layout.credits_webview, null);
|
||||||
@ -318,6 +358,9 @@ public class KiwixSettingsActivity extends BaseActivity {
|
|||||||
if (preference.getKey().equalsIgnoreCase(PREF_CLEAR_ALL_HISTORY)) {
|
if (preference.getKey().equalsIgnoreCase(PREF_CLEAR_ALL_HISTORY)) {
|
||||||
clearAllHistoryDialog();
|
clearAllHistoryDialog();
|
||||||
}
|
}
|
||||||
|
if (preference.getKey().equalsIgnoreCase(PREF_CLEAR_ALL_NOTES)) {
|
||||||
|
showClearAllNotesDialog();
|
||||||
|
}
|
||||||
|
|
||||||
if (preference.getKey().equalsIgnoreCase(PREF_CREDITS)) {
|
if (preference.getKey().equalsIgnoreCase(PREF_CREDITS)) {
|
||||||
openCredits();
|
openCredits();
|
||||||
@ -332,15 +375,12 @@ public class KiwixSettingsActivity extends BaseActivity {
|
|||||||
|
|
||||||
public void openFolderSelect() {
|
public void openFolderSelect() {
|
||||||
StorageSelectDialog dialogFragment = new StorageSelectDialog();
|
StorageSelectDialog dialogFragment = new StorageSelectDialog();
|
||||||
dialogFragment.setOnSelectListener(storageDevice -> {
|
dialogFragment.setOnSelectListener(this::onStorageDeviceSelected);
|
||||||
selectionCallback(storageDevice);
|
|
||||||
return Unit.INSTANCE;
|
|
||||||
});
|
|
||||||
dialogFragment.show(((AppCompatActivity) getActivity()).getSupportFragmentManager(),
|
dialogFragment.show(((AppCompatActivity) getActivity()).getSupportFragmentManager(),
|
||||||
getResources().getString(R.string.pref_storage));
|
getResources().getString(R.string.pref_storage));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void selectionCallback(StorageDevice storageDevice) {
|
private Unit onStorageDeviceSelected(StorageDevice storageDevice) {
|
||||||
findPreference(PREF_STORAGE).setSummary(
|
findPreference(PREF_STORAGE).setSummary(
|
||||||
storageCalculator.calculateAvailableSpace(storageDevice.getFile())
|
storageCalculator.calculateAvailableSpace(storageDevice.getFile())
|
||||||
);
|
);
|
||||||
@ -354,6 +394,7 @@ public class KiwixSettingsActivity extends BaseActivity {
|
|||||||
sharedPreferenceUtil.putPrefStorageTitle(
|
sharedPreferenceUtil.putPrefStorageTitle(
|
||||||
getResources().getString(R.string.external_storage));
|
getResources().getString(R.string.external_storage));
|
||||||
}
|
}
|
||||||
|
return Unit.INSTANCE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,8 +17,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.kiwix.kiwixmobile.utils;
|
package org.kiwix.kiwixmobile.utils;
|
||||||
|
|
||||||
import android.os.Environment;
|
|
||||||
|
|
||||||
import org.kiwix.kiwixmobile.BuildConfig;
|
import org.kiwix.kiwixmobile.BuildConfig;
|
||||||
|
|
||||||
public final class Constants {
|
public final class Constants {
|
||||||
@ -49,46 +47,6 @@ public final class Constants {
|
|||||||
|
|
||||||
public static final int RESULT_HISTORY_CLEARED = 1239;
|
public static final int RESULT_HISTORY_CLEARED = 1239;
|
||||||
|
|
||||||
// Prefs
|
|
||||||
public static final String PREF_LANG = "pref_language_chooser";
|
|
||||||
|
|
||||||
public static final String PREF_VERSION = "pref_version";
|
|
||||||
|
|
||||||
public static final String PREF_CLEAR_ALL_HISTORY = "pref_clear_all_history";
|
|
||||||
|
|
||||||
public static final String PREF_CREDITS = "pref_credits";
|
|
||||||
|
|
||||||
public static final String PREF_STORAGE = "pref_select_folder";
|
|
||||||
|
|
||||||
public static final String PREF_AUTONIGHTMODE = "pref_auto_nightmode";
|
|
||||||
|
|
||||||
public static final String PREF_NIGHTMODE = "pref_nightmode";
|
|
||||||
|
|
||||||
public static final String PREF_WIFI_ONLY = "pref_wifi_only";
|
|
||||||
|
|
||||||
public static final String PREF_KIWIX_MOBILE = "kiwix-mobile";
|
|
||||||
|
|
||||||
public static final String PREF_BACK_TO_TOP = "pref_backtotop";
|
|
||||||
|
|
||||||
public static final String PREF_HIDE_TOOLBAR = "pref_hidetoolbar";
|
|
||||||
|
|
||||||
public static final String PREF_ZOOM = "pref_zoom_slider";
|
|
||||||
|
|
||||||
public static final String PREF_ZOOM_ENABLED = "pref_zoom_enabled";
|
|
||||||
|
|
||||||
public static final String PREF_FULLSCREEN = "pref_fullscreen";
|
|
||||||
|
|
||||||
public static final String PREF_NEW_TAB_BACKGROUND = "pref_newtab_background";
|
|
||||||
|
|
||||||
public static final String PREF_FULL_TEXT_SEARCH = "pref_full_text_search";
|
|
||||||
|
|
||||||
public static final String PREF_STORAGE_TITLE = "pref_selected_title";
|
|
||||||
|
|
||||||
public static final String PREF_EXTERNAL_LINK_POPUP = "pref_external_link_popup";
|
|
||||||
|
|
||||||
public static final String PREF_IS_FIRST_RUN = "isFirstRun";
|
|
||||||
|
|
||||||
public static final String PREF_SHOW_INTRO = "showIntro";
|
|
||||||
|
|
||||||
// Tags
|
// Tags
|
||||||
public static final String TAG_FILE_SEARCHED = "searchedarticle";
|
public static final String TAG_FILE_SEARCHED = "searchedarticle";
|
||||||
@ -138,7 +96,4 @@ public final class Constants {
|
|||||||
public static final String OLD_PROVIDER_DOMAIN = "org.kiwix.zim.base";
|
public static final String OLD_PROVIDER_DOMAIN = "org.kiwix.zim.base";
|
||||||
|
|
||||||
public static final String NEW_PROVIDER_DOMAIN = BuildConfig.APPLICATION_ID + ".zim.base";
|
public static final String NEW_PROVIDER_DOMAIN = BuildConfig.APPLICATION_ID + ".zim.base";
|
||||||
|
|
||||||
// Path Constants
|
|
||||||
public static final String NOTES_DIRECTORY = Environment.getExternalStorageDirectory() + "/Kiwix/Notes/";
|
|
||||||
}
|
}
|
||||||
|
@ -5,34 +5,35 @@ import android.content.SharedPreferences;
|
|||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import io.reactivex.Flowable;
|
import io.reactivex.Flowable;
|
||||||
import io.reactivex.processors.BehaviorProcessor;
|
|
||||||
import io.reactivex.processors.PublishProcessor;
|
import io.reactivex.processors.PublishProcessor;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import static org.kiwix.kiwixmobile.utils.Constants.PREF_AUTONIGHTMODE;
|
|
||||||
import static org.kiwix.kiwixmobile.utils.Constants.PREF_BACK_TO_TOP;
|
|
||||||
import static org.kiwix.kiwixmobile.utils.Constants.PREF_EXTERNAL_LINK_POPUP;
|
|
||||||
import static org.kiwix.kiwixmobile.utils.Constants.PREF_FULLSCREEN;
|
|
||||||
import static org.kiwix.kiwixmobile.utils.Constants.PREF_HIDE_TOOLBAR;
|
|
||||||
import static org.kiwix.kiwixmobile.utils.Constants.PREF_IS_FIRST_RUN;
|
|
||||||
import static org.kiwix.kiwixmobile.utils.Constants.PREF_LANG;
|
|
||||||
import static org.kiwix.kiwixmobile.utils.Constants.PREF_NEW_TAB_BACKGROUND;
|
|
||||||
import static org.kiwix.kiwixmobile.utils.Constants.PREF_NIGHTMODE;
|
|
||||||
import static org.kiwix.kiwixmobile.utils.Constants.PREF_SHOW_INTRO;
|
|
||||||
import static org.kiwix.kiwixmobile.utils.Constants.PREF_STORAGE;
|
|
||||||
import static org.kiwix.kiwixmobile.utils.Constants.PREF_STORAGE_TITLE;
|
|
||||||
import static org.kiwix.kiwixmobile.utils.Constants.PREF_WIFI_ONLY;
|
|
||||||
import static org.kiwix.kiwixmobile.utils.Constants.PREF_ZOOM;
|
|
||||||
import static org.kiwix.kiwixmobile.utils.Constants.PREF_ZOOM_ENABLED;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manager for the Default Shared Preferences of the application.
|
* Manager for the Default Shared Preferences of the application.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
public class SharedPreferenceUtil {
|
public class SharedPreferenceUtil {
|
||||||
|
// Prefs
|
||||||
|
public static final String PREF_LANG = "pref_language_chooser";
|
||||||
|
public static final String PREF_STORAGE = "pref_select_folder";
|
||||||
|
public static final String PREF_AUTONIGHTMODE = "pref_auto_nightmode";
|
||||||
|
public static final String PREF_NIGHTMODE = "pref_nightmode";
|
||||||
|
public static final String PREF_WIFI_ONLY = "pref_wifi_only";
|
||||||
|
public static final String PREF_KIWIX_MOBILE = "kiwix-mobile";
|
||||||
|
public static final String PREF_BACK_TO_TOP = "pref_backtotop";
|
||||||
|
public static final String PREF_HIDE_TOOLBAR = "pref_hidetoolbar";
|
||||||
|
public static final String PREF_ZOOM = "pref_zoom_slider";
|
||||||
|
public static final String PREF_ZOOM_ENABLED = "pref_zoom_enabled";
|
||||||
|
public static final String PREF_FULLSCREEN = "pref_fullscreen";
|
||||||
|
public static final String PREF_NEW_TAB_BACKGROUND = "pref_newtab_background";
|
||||||
|
public static final String PREF_FULL_TEXT_SEARCH = "pref_full_text_search";
|
||||||
|
public static final String PREF_STORAGE_TITLE = "pref_selected_title";
|
||||||
|
public static final String PREF_EXTERNAL_LINK_POPUP = "pref_external_link_popup";
|
||||||
|
public static final String PREF_IS_FIRST_RUN = "isFirstRun";
|
||||||
|
public static final String PREF_SHOW_INTRO = "showIntro";
|
||||||
private static final String PREF_SHOW_BOOKMARKS_CURRENT_BOOK = "show_bookmarks_current_book";
|
private static final String PREF_SHOW_BOOKMARKS_CURRENT_BOOK = "show_bookmarks_current_book";
|
||||||
private static final String PREF_SHOW_HISTORY_CURRENT_BOOK = "show_history_current_book";
|
private static final String PREF_SHOW_HISTORY_CURRENT_BOOK = "show_history_current_book";
|
||||||
private SharedPreferences sharedPreferences;
|
private SharedPreferences sharedPreferences;
|
||||||
@ -59,7 +60,6 @@ public class SharedPreferenceUtil {
|
|||||||
return sharedPreferences.getBoolean(PREF_FULLSCREEN, false);
|
return sharedPreferences.getBoolean(PREF_FULLSCREEN, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean getPrefBackToTop() {
|
public boolean getPrefBackToTop() {
|
||||||
return sharedPreferences.getBoolean(PREF_BACK_TO_TOP, false);
|
return sharedPreferences.getBoolean(PREF_BACK_TO_TOP, false);
|
||||||
}
|
}
|
||||||
@ -86,7 +86,7 @@ public class SharedPreferenceUtil {
|
|||||||
|
|
||||||
public String getPrefStorage() {
|
public String getPrefStorage() {
|
||||||
return sharedPreferences.getString(PREF_STORAGE,
|
return sharedPreferences.getString(PREF_STORAGE,
|
||||||
Environment.getExternalStorageDirectory().getPath());
|
Environment.getExternalStorageDirectory().getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean getPrefNightMode() {
|
private boolean getPrefNightMode() {
|
||||||
@ -127,7 +127,7 @@ public class SharedPreferenceUtil {
|
|||||||
prefStorages.onNext(storage);
|
prefStorages.onNext(storage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Flowable<String> getPrefStorages(){
|
public Flowable<String> getPrefStorages() {
|
||||||
return prefStorages.startWith(getPrefStorage());
|
return prefStorages.startWith(getPrefStorage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,8 +153,8 @@ public class SharedPreferenceUtil {
|
|||||||
|
|
||||||
public void setShowHistoryCurrentBook(boolean prefShowHistoryCurrentBook) {
|
public void setShowHistoryCurrentBook(boolean prefShowHistoryCurrentBook) {
|
||||||
sharedPreferences.edit()
|
sharedPreferences.edit()
|
||||||
.putBoolean(PREF_SHOW_HISTORY_CURRENT_BOOK, prefShowHistoryCurrentBook)
|
.putBoolean(PREF_SHOW_HISTORY_CURRENT_BOOK, prefShowHistoryCurrentBook)
|
||||||
.apply();
|
.apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean nightMode() {
|
public boolean nightMode() {
|
||||||
@ -174,7 +174,7 @@ public class SharedPreferenceUtil {
|
|||||||
|
|
||||||
public void setShowBookmarksCurrentBook(boolean prefShowBookmarksFromCurrentBook) {
|
public void setShowBookmarksCurrentBook(boolean prefShowBookmarksFromCurrentBook) {
|
||||||
sharedPreferences.edit()
|
sharedPreferences.edit()
|
||||||
.putBoolean(PREF_SHOW_BOOKMARKS_CURRENT_BOOK, prefShowBookmarksFromCurrentBook)
|
.putBoolean(PREF_SHOW_BOOKMARKS_CURRENT_BOOK, prefShowBookmarksFromCurrentBook)
|
||||||
.apply();
|
.apply();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:width="24dp"
|
|
||||||
android:height="24dp"
|
|
||||||
android:viewportWidth="24"
|
|
||||||
android:viewportHeight="24">
|
|
||||||
<path
|
|
||||||
android:fillColor="#FF000000"
|
|
||||||
android:pathData="M15,16h4v2h-4zM15,8h7v2h-7zM15,12h6v2h-6zM3,18c0,1.1 0.9,2 2,2h6c1.1,0 2,-0.9 2,-2L13,8L3,8v10zM14,5h-3l-1,-1L6,4L5,5L2,5v2h12z"/>
|
|
||||||
</vector>
|
|
@ -1,102 +1,85 @@
|
|||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_search"
|
android:id="@+id/menu_search"
|
||||||
android:icon="@drawable/action_search"
|
android:icon="@drawable/action_search"
|
||||||
android:title="@string/menu_search"
|
android:title="@string/menu_search"
|
||||||
android:visible="false"
|
android:visible="false"
|
||||||
app:showAsAction="always"/>
|
tools:visible="true"
|
||||||
|
app:showAsAction="always" />
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_tab_switcher"
|
android:id="@+id/menu_tab_switcher"
|
||||||
android:title="@string/switch_tabs"
|
android:title="@string/switch_tabs"
|
||||||
app:actionLayout="@layout/ic_tab_switcher"
|
app:actionLayout="@layout/ic_tab_switcher"
|
||||||
app:showAsAction="always"/>
|
app:showAsAction="always" />
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_bookmarks_list"
|
||||||
|
android:title="@string/menu_bookmarks_list"
|
||||||
|
app:showAsAction="never" />
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_history"
|
||||||
|
android:title="@string/history"
|
||||||
|
app:showAsAction="never" />
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_openfile"
|
||||||
|
android:icon="@drawable/action_open_file"
|
||||||
|
android:title="@string/menu_zim_manager"
|
||||||
|
app:showAsAction="never" />
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_add_note"
|
android:id="@+id/menu_add_note"
|
||||||
android:title="@string/add_note"
|
|
||||||
android:icon="@drawable/ic_add_note"
|
android:icon="@drawable/ic_add_note"
|
||||||
app:showAsAction="ifRoom"/>
|
android:title="@string/note"
|
||||||
|
app:showAsAction="ifRoom" />
|
||||||
|
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_clear_notes"
|
android:id="@+id/menu_random_article"
|
||||||
android:title="@string/clear_all_notes"
|
android:icon="@drawable/action_randomarticle"
|
||||||
android:icon="@drawable/ic_baseline_delete_sweep_24px"
|
android:title="@string/menu_random_article"
|
||||||
app:showAsAction="ifRoom"/>
|
android:visible="false"
|
||||||
|
tools:visible="true"
|
||||||
|
app:showAsAction="never" />
|
||||||
|
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_new_tab"
|
android:id="@+id/menu_fullscreen"
|
||||||
android:title="@string/new_tab"
|
android:title="@string/menu_full_screen"
|
||||||
app:showAsAction="never"/>
|
android:visible="false"
|
||||||
|
tools:visible="true"
|
||||||
|
app:showAsAction="never" />
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_bookmarks_list"
|
android:id="@+id/menu_read_aloud"
|
||||||
android:title="@string/menu_bookmarks_list"
|
android:title="@string/menu_read_aloud"
|
||||||
app:showAsAction="never"/>
|
android:visible="false"
|
||||||
|
tools:visible="true"
|
||||||
|
app:showAsAction="never" />
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_history"
|
android:id="@+id/menu_host_books"
|
||||||
android:title="@string/history"
|
android:title="@string/menu_host_books"
|
||||||
app:showAsAction="never"/>
|
app:showAsAction="never" />
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_home"
|
android:id="@+id/menu_help"
|
||||||
android:icon="@drawable/action_home"
|
android:title="@string/menu_help"
|
||||||
android:title="@string/menu_home"
|
app:showAsAction="never" />
|
||||||
android:visible="false"
|
|
||||||
app:showAsAction="never"/>
|
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_random_article"
|
android:id="@+id/menu_settings"
|
||||||
android:icon="@drawable/action_randomarticle"
|
android:title="@string/menu_settings"
|
||||||
android:title="@string/menu_random_article"
|
app:showAsAction="never" />
|
||||||
android:visible="false"
|
|
||||||
app:showAsAction="never"/>
|
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_openfile"
|
android:id="@+id/menu_support_kiwix"
|
||||||
android:icon="@drawable/action_open_file"
|
android:title="@string/menu_support_kiwix"
|
||||||
android:title="@string/menu_zim_manager"
|
app:showAsAction="never" />
|
||||||
app:showAsAction="never"/>
|
|
||||||
|
|
||||||
<item
|
|
||||||
android:id="@+id/menu_searchintext"
|
|
||||||
android:title="@string/menu_search_in_text"
|
|
||||||
android:visible="false"
|
|
||||||
app:showAsAction="never"/>
|
|
||||||
|
|
||||||
<item
|
|
||||||
android:id="@+id/menu_fullscreen"
|
|
||||||
android:title="@string/menu_full_screen"
|
|
||||||
android:visible="false"
|
|
||||||
app:showAsAction="never"/>
|
|
||||||
|
|
||||||
<item
|
|
||||||
android:id="@+id/menu_read_aloud"
|
|
||||||
android:title="@string/menu_read_aloud"
|
|
||||||
android:visible="false"
|
|
||||||
app:showAsAction="never"/>
|
|
||||||
|
|
||||||
<item
|
|
||||||
android:id="@+id/menu_host_books"
|
|
||||||
android:title="@string/menu_host_books"
|
|
||||||
app:showAsAction="never"/>
|
|
||||||
|
|
||||||
<item
|
|
||||||
android:id="@+id/menu_help"
|
|
||||||
android:title="@string/menu_help"
|
|
||||||
app:showAsAction="never"/>
|
|
||||||
|
|
||||||
<item
|
|
||||||
android:id="@+id/menu_settings"
|
|
||||||
android:title="@string/menu_settings"
|
|
||||||
app:showAsAction="never"/>
|
|
||||||
|
|
||||||
<item
|
|
||||||
android:id="@+id/menu_support_kiwix"
|
|
||||||
android:title="@string/menu_support_kiwix"
|
|
||||||
app:showAsAction="never"/>
|
|
||||||
|
|
||||||
</menu>
|
</menu>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?xml version='1.0' encoding='UTF-8'?>
|
<?xml version='1.0' encoding='UTF-8'?>
|
||||||
<resources xmlns:tools="http://schemas.android.com/tools">
|
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||||
<string name="kiwi">Kiwi</string>
|
<string name="kiwi">Kiwi</string>
|
||||||
<string name="menu_zim_manager">Get Content</string>
|
<string name="menu_zim_manager">Library</string>
|
||||||
<string name="menu_help">Help</string>
|
<string name="menu_help">Help</string>
|
||||||
<string name="menu_home">Home</string>
|
<string name="menu_home">Home</string>
|
||||||
<string name="menu_settings">Settings</string>
|
<string name="menu_settings">Settings</string>
|
||||||
@ -237,7 +237,6 @@
|
|||||||
</string-array>
|
</string-array>
|
||||||
<string name="bookmarks_from_current_book">Bookmarks from current book</string>
|
<string name="bookmarks_from_current_book">Bookmarks from current book</string>
|
||||||
<string name="search_bookmarks">Search bookmarks</string>
|
<string name="search_bookmarks">Search bookmarks</string>
|
||||||
<string name="new_tab">New tab</string>
|
|
||||||
<string name="switch_tabs">Switch tabs</string>
|
<string name="switch_tabs">Switch tabs</string>
|
||||||
<string name="smiling_face">:D</string>
|
<string name="smiling_face">:D</string>
|
||||||
<string name="close_all_tabs">Close all tabs</string>
|
<string name="close_all_tabs">Close all tabs</string>
|
||||||
@ -260,7 +259,6 @@
|
|||||||
<string name="failed_unhandled_http_code">Unknown HTTP code received</string>
|
<string name="failed_unhandled_http_code">Unknown HTTP code received</string>
|
||||||
<string name="failed_unknown">Unknown</string>
|
<string name="failed_unknown">Unknown</string>
|
||||||
<string name="failed_http_code">HTTP code %s</string>
|
<string name="failed_http_code">HTTP code %s</string>
|
||||||
<string name="add_note">Add Note</string>
|
|
||||||
<string name="save">Save</string>
|
<string name="save">Save</string>
|
||||||
<string name="note">Note</string>
|
<string name="note">Note</string>
|
||||||
<string name="wiki_article_title">Wiki Article Title</string>
|
<string name="wiki_article_title">Wiki Article Title</string>
|
||||||
@ -272,10 +270,8 @@
|
|||||||
<string name="note_share_error_file_missing">Note file doesn\'t exist</string>
|
<string name="note_share_error_file_missing">Note file doesn\'t exist</string>
|
||||||
<string name="note_share_app_chooser_title">Share note file with:</string>
|
<string name="note_share_app_chooser_title">Share note file with:</string>
|
||||||
<string name="confirmation_alert_dialog_message">Discard unsaved changes?</string>
|
<string name="confirmation_alert_dialog_message">Discard unsaved changes?</string>
|
||||||
<string name="clear_all_notes">Clear All Notes</string>
|
|
||||||
<string name="delete_notes_confirmation_msg">Delete all notes?</string>
|
<string name="delete_notes_confirmation_msg">Delete all notes?</string>
|
||||||
<string name="ext_storage_permission_not_granted">Error: Storage permissions not granted</string>
|
<string name="ext_storage_permission_not_granted">Error: Storage permissions not granted</string>
|
||||||
<string name="notes_deletion_none_found">No notes found for deletion</string>
|
|
||||||
<string name="notes_deletion_successful">Entire notes folder deleted</string>
|
<string name="notes_deletion_successful">Entire notes folder deleted</string>
|
||||||
<string name="notes_deletion_unsuccessful">Some files not deleted</string>
|
<string name="notes_deletion_unsuccessful">Some files not deleted</string>
|
||||||
<plurals name="books_count">
|
<plurals name="books_count">
|
||||||
@ -308,4 +304,6 @@
|
|||||||
<string name="performing_handshake">Performing handshake....</string>
|
<string name="performing_handshake">Performing handshake....</string>
|
||||||
<string name="local_zim_sharing">Local ZIM Sharing</string>
|
<string name="local_zim_sharing">Local ZIM Sharing</string>
|
||||||
<string name="status">Status</string>
|
<string name="status">Status</string>
|
||||||
|
<string name="pref_clear_all_notes_summary">Clears all notes on all articles</string>
|
||||||
|
<string name="pref_clear_all_notes_title">Clear all notes</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -101,6 +101,16 @@
|
|||||||
android:summary="@string/pref_clear_all_history_summary"
|
android:summary="@string/pref_clear_all_history_summary"
|
||||||
android:title="@string/pref_clear_all_history_title"/>
|
android:title="@string/pref_clear_all_history_title"/>
|
||||||
|
|
||||||
|
</PreferenceCategory>
|
||||||
|
<PreferenceCategory
|
||||||
|
android:key="pref_notes"
|
||||||
|
android:title="Notes">
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
android:key="pref_clear_all_notes"
|
||||||
|
android:summary="@string/pref_clear_all_notes_summary"
|
||||||
|
android:title="@string/pref_clear_all_notes_title"/>
|
||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="pref_language"
|
android:key="pref_language"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user