Merge pull request #1578 from kiwix/feature/macgills/1577-custom-tab-behaviour

#1577 Custom Apps try to open Home - move HomeUrl related code to app
This commit is contained in:
Seán Mac Gillicuddy 2019-11-06 10:20:43 +00:00 committed by GitHub
commit 188252345e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 97 additions and 87 deletions

View File

@ -11,6 +11,7 @@
<inspection_tool class="AndroidLintAnimatorKeep" enabled="true" level="ERROR" enabled_by_default="true" /> <inspection_tool class="AndroidLintAnimatorKeep" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="AndroidLintAppCompatMethod" enabled="true" level="ERROR" enabled_by_default="true" /> <inspection_tool class="AndroidLintAppCompatMethod" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="AndroidLintAppIndexingService" enabled="true" level="ERROR" enabled_by_default="true" /> <inspection_tool class="AndroidLintAppIndexingService" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="AndroidLintAppLinkUrlError" enabled="false" level="ERROR" enabled_by_default="false" />
<inspection_tool class="AndroidLintAppLinksAutoVerifyError" enabled="true" level="ERROR" enabled_by_default="true" /> <inspection_tool class="AndroidLintAppLinksAutoVerifyError" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="AndroidLintAppLinksAutoVerifyWarning" enabled="true" level="ERROR" enabled_by_default="true" /> <inspection_tool class="AndroidLintAppLinksAutoVerifyWarning" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="AndroidLintApplySharedPref" enabled="true" level="ERROR" enabled_by_default="true" /> <inspection_tool class="AndroidLintApplySharedPref" enabled="true" level="ERROR" enabled_by_default="true" />
@ -57,8 +58,8 @@
<inspection_tool class="AndroidLintFontValidationWarning" enabled="true" level="ERROR" enabled_by_default="true" /> <inspection_tool class="AndroidLintFontValidationWarning" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="AndroidLintGetInstance" enabled="true" level="ERROR" enabled_by_default="true" /> <inspection_tool class="AndroidLintGetInstance" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="AndroidLintGifUsage" enabled="true" level="ERROR" enabled_by_default="true" /> <inspection_tool class="AndroidLintGifUsage" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="AndroidLintGoogleAppIndexingApiWarning" enabled="true" level="ERROR" enabled_by_default="true" /> <inspection_tool class="AndroidLintGoogleAppIndexingApiWarning" enabled="false" level="ERROR" enabled_by_default="false" />
<inspection_tool class="AndroidLintGoogleAppIndexingWarning" enabled="true" level="ERROR" enabled_by_default="true" /> <inspection_tool class="AndroidLintGoogleAppIndexingWarning" enabled="false" level="ERROR" enabled_by_default="false" />
<inspection_tool class="AndroidLintGradleDependency" enabled="true" level="ERROR" enabled_by_default="true" /> <inspection_tool class="AndroidLintGradleDependency" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="AndroidLintGradleDeprecated" enabled="true" level="ERROR" enabled_by_default="true" /> <inspection_tool class="AndroidLintGradleDeprecated" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="AndroidLintGradleDynamicVersion" enabled="true" level="ERROR" enabled_by_default="true" /> <inspection_tool class="AndroidLintGradleDynamicVersion" enabled="true" level="ERROR" enabled_by_default="true" />

View File

@ -21,6 +21,7 @@ package org.kiwix.kiwixmobile.main
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.util.Log import android.util.Log
import android.view.View
import android.widget.Toast import android.widget.Toast
import androidx.core.net.toFile import androidx.core.net.toFile
import androidx.core.net.toUri import androidx.core.net.toUri
@ -30,6 +31,7 @@ import org.kiwix.kiwixmobile.core.extensions.start
import org.kiwix.kiwixmobile.core.extensions.toast import org.kiwix.kiwixmobile.core.extensions.toast
import org.kiwix.kiwixmobile.core.main.CoreMainActivity import org.kiwix.kiwixmobile.core.main.CoreMainActivity
import org.kiwix.kiwixmobile.core.main.WebViewCallback import org.kiwix.kiwixmobile.core.main.WebViewCallback
import org.kiwix.kiwixmobile.core.reader.ZimFileReader
import org.kiwix.kiwixmobile.core.reader.ZimReaderContainer import org.kiwix.kiwixmobile.core.reader.ZimReaderContainer
import org.kiwix.kiwixmobile.core.utils.Constants.EXTRA_ZIM_FILE import org.kiwix.kiwixmobile.core.utils.Constants.EXTRA_ZIM_FILE
import org.kiwix.kiwixmobile.core.utils.Constants.TAG_CURRENT_ARTICLES import org.kiwix.kiwixmobile.core.utils.Constants.TAG_CURRENT_ARTICLES
@ -45,6 +47,7 @@ import org.kiwix.kiwixmobile.zim_manager.ZimManageActivity
import java.io.File import java.io.File
class KiwixMainActivity : CoreMainActivity() { class KiwixMainActivity : CoreMainActivity() {
private val homeUrl = "file:///android_asset/home.html"
override fun injection() { override fun injection() {
kiwixActivityComponent.inject(this) kiwixActivityComponent.inject(this)
@ -55,6 +58,21 @@ class KiwixMainActivity : CoreMainActivity() {
manageExternalLaunchAndRestoringViewState() manageExternalLaunchAndRestoringViewState()
} }
override fun onResume() {
super.onResume()
if (zimReaderContainer.zimFile == null && homeUrl != currentWebView.url) {
showHomePage()
}
if (webViewList.isNotEmpty() && currentWebViewIndex < webViewList.size &&
webViewList[currentWebViewIndex].url != null &&
webViewList[currentWebViewIndex].url == homeUrl &&
webViewList[currentWebViewIndex].findViewById<View>(R.id.get_content_card) != null
) {
webViewList[currentWebViewIndex].findViewById<View>(R.id.get_content_card).isEnabled = true
}
}
override fun createWebClient( override fun createWebClient(
webViewCallback: WebViewCallback, webViewCallback: WebViewCallback,
zimReaderContainer: ZimReaderContainer zimReaderContainer: ZimReaderContainer
@ -95,6 +113,24 @@ class KiwixMainActivity : CoreMainActivity() {
} }
} }
override fun hasValidFileAndUrl(url: String?, zimFileReader: ZimFileReader?) =
super.hasValidFileAndUrl(url, zimFileReader) && url != homeUrl
override fun urlIsInvalid() =
super.urlIsInvalid() || currentWebView.url == homeUrl
override fun showHomePage() {
currentWebView.removeAllViews()
currentWebView.loadUrl(homeUrl)
}
override fun createNewTab() {
newTab(homeUrl)
}
override fun isInvalidTitle(zimFileTitle: String?) =
super.isInvalidTitle(zimFileTitle) || homeUrl == currentWebView.url
private fun uriFromIntent() = private fun uriFromIntent() =
intent.data ?: intent.getStringExtra(EXTRA_ZIM_FILE)?.let { intent.data ?: intent.getStringExtra(EXTRA_ZIM_FILE)?.let {
File(FileUtils.getFileName(it)).toUri() File(FileUtils.getFileName(it)).toUri()
@ -133,9 +169,7 @@ class KiwixMainActivity : CoreMainActivity() {
} }
override fun manageZimFiles(tab: Int) { override fun manageZimFiles(tab: Int) {
start<ZimManageActivity> { start<ZimManageActivity> { putExtra(ZimManageActivity.TAB_EXTRA, tab) }
putExtra(ZimManageActivity.TAB_EXTRA, tab)
}
} }
override fun onNewIntent(intent: Intent?) { override fun onNewIntent(intent: Intent?) {

View File

@ -155,8 +155,6 @@ import static org.kiwix.kiwixmobile.core.utils.StyleUtils.dialogStyle;
public abstract class CoreMainActivity extends BaseActivity implements WebViewCallback, public abstract class CoreMainActivity extends BaseActivity implements WebViewCallback,
MainContract.View { MainContract.View {
private static final String NEW_TAB = "NEW_TAB";
private static final String HOME_URL = "file:///android_asset/home.html";
public static boolean isFullscreenOpened; public static boolean isFullscreenOpened;
public static boolean refresh; public static boolean refresh;
public static boolean wifiOnly; public static boolean wifiOnly;
@ -186,9 +184,9 @@ public abstract class CoreMainActivity extends BaseActivity implements WebViewCa
@BindView(R2.id.activity_main_nav_view) @BindView(R2.id.activity_main_nav_view)
NavigationView tableDrawerRightContainer; NavigationView tableDrawerRightContainer;
@BindView(R2.id.activity_main_content_frame) @BindView(R2.id.activity_main_content_frame)
FrameLayout contentFrame; protected FrameLayout contentFrame;
@BindView(R2.id.bottom_toolbar) @BindView(R2.id.bottom_toolbar)
LinearLayout bottomToolbar; protected LinearLayout bottomToolbar;
@BindView(R2.id.bottom_toolbar_bookmark) @BindView(R2.id.bottom_toolbar_bookmark)
ImageView bottomToolbarBookmark; ImageView bottomToolbarBookmark;
@BindView(R2.id.bottom_toolbar_arrow_back) @BindView(R2.id.bottom_toolbar_arrow_back)
@ -198,7 +196,7 @@ public abstract class CoreMainActivity extends BaseActivity implements WebViewCa
@BindView(R2.id.tab_switcher_recycler_view) @BindView(R2.id.tab_switcher_recycler_view)
RecyclerView tabRecyclerView; RecyclerView tabRecyclerView;
@BindView(R2.id.activity_main_tab_switcher) @BindView(R2.id.activity_main_tab_switcher)
View tabSwitcherRoot; protected View tabSwitcherRoot;
@BindView(R2.id.tab_switcher_close_all_tabs) @BindView(R2.id.tab_switcher_close_all_tabs)
FloatingActionButton closeAllTabsButton; FloatingActionButton closeAllTabsButton;
@BindView(R2.id.snackbar_root) @BindView(R2.id.snackbar_root)
@ -211,7 +209,7 @@ public abstract class CoreMainActivity extends BaseActivity implements WebViewCa
@Inject @Inject
StorageObserver storageObserver; StorageObserver storageObserver;
@Inject @Inject
ZimReaderContainer zimReaderContainer; protected ZimReaderContainer zimReaderContainer;
private CountDownTimer hideBackToTopTimer = new CountDownTimer(1200, 1200) { private CountDownTimer hideBackToTopTimer = new CountDownTimer(1200, 1200) {
@Override @Override
@ -238,7 +236,7 @@ public abstract class CoreMainActivity extends BaseActivity implements WebViewCa
private KiwixTextToSpeech tts; private KiwixTextToSpeech tts;
private CompatFindActionModeCallback compatCallback; private CompatFindActionModeCallback compatCallback;
private TabsAdapter tabsAdapter; private TabsAdapter tabsAdapter;
private int currentWebViewIndex = 0; protected int currentWebViewIndex = 0;
private File file; private File file;
private ActionMode actionMode = null; private ActionMode actionMode = null;
private KiwixWebView tempForUndo; private KiwixWebView tempForUndo;
@ -392,11 +390,11 @@ public abstract class CoreMainActivity extends BaseActivity implements WebViewCa
selectTab(webViewList.size() - 1); selectTab(webViewList.size() - 1);
} }
if (intent.hasExtra(EXTRA_CHOSE_X_URL)) { if (intent.hasExtra(EXTRA_CHOSE_X_URL)) {
newTab(); newMainPageTab();
getCurrentWebView().loadUrl(intent.getStringExtra(EXTRA_CHOSE_X_URL)); getCurrentWebView().loadUrl(intent.getStringExtra(EXTRA_CHOSE_X_URL));
} }
if (intent.hasExtra(EXTRA_CHOSE_X_TITLE)) { if (intent.hasExtra(EXTRA_CHOSE_X_TITLE)) {
newTab(); newMainPageTab();
getCurrentWebView().loadUrl(intent.getStringExtra(EXTRA_CHOSE_X_TITLE)); getCurrentWebView().loadUrl(intent.getStringExtra(EXTRA_CHOSE_X_TITLE));
} }
} }
@ -507,7 +505,7 @@ public abstract class CoreMainActivity extends BaseActivity implements WebViewCa
} }
} }
private void hideTabSwitcher() { protected void hideTabSwitcher() {
actionBar.setDisplayHomeAsUpEnabled(false); actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.setDisplayShowTitleEnabled(true); actionBar.setDisplayShowTitleEnabled(true);
@ -644,15 +642,15 @@ public abstract class CoreMainActivity extends BaseActivity implements WebViewCa
} }
private void updateTitle() { private void updateTitle() {
String zimFileTitle = zimReaderContainer.getZimFileTitle(); actionBar.setTitle(createMenuText(getValidTitle(zimReaderContainer.getZimFileTitle())));
if (zimFileTitle == null) { }
zimFileTitle = getString(R.string.app_name);
} private String getValidTitle(String zimFileTitle) {
if (zimFileTitle.trim().isEmpty() || HOME_URL.equals(getCurrentWebView().getUrl())) { return isInvalidTitle(zimFileTitle) ? getString(R.string.app_name) : zimFileTitle;
actionBar.setTitle(createMenuText(getString(R.string.app_name))); }
} else {
actionBar.setTitle(createMenuText(zimFileTitle)); protected boolean isInvalidTitle(String zimFileTitle) {
} return zimFileTitle == null || zimFileTitle.trim().isEmpty();
} }
private void setUpTTS() { private void setUpTTS() {
@ -768,7 +766,7 @@ public abstract class CoreMainActivity extends BaseActivity implements WebViewCa
WebViewCallback webViewCallback, WebViewCallback webViewCallback,
ZimReaderContainer zimReaderContainer); ZimReaderContainer zimReaderContainer);
private KiwixWebView newTab() { protected KiwixWebView newMainPageTab() {
return newTab(contentUrl(zimReaderContainer.getMainPage())); return newTab(contentUrl(zimReaderContainer.getMainPage()));
} }
@ -830,7 +828,7 @@ public abstract class CoreMainActivity extends BaseActivity implements WebViewCa
} }
protected KiwixWebView getCurrentWebView() { protected KiwixWebView getCurrentWebView() {
if (webViewList.size() == 0) return newTab(); if (webViewList.size() == 0) return newMainPageTab();
if (currentWebViewIndex < webViewList.size()) { if (currentWebViewIndex < webViewList.size()) {
return webViewList.get(currentWebViewIndex); return webViewList.get(currentWebViewIndex);
} else { } else {
@ -845,7 +843,7 @@ public abstract class CoreMainActivity extends BaseActivity implements WebViewCa
if (tabSwitcherRoot.getVisibility() == View.VISIBLE) { if (tabSwitcherRoot.getVisibility() == View.VISIBLE) {
hideTabSwitcher(); hideTabSwitcher();
} }
newTab(HOME_URL); createNewTab();
return true; return true;
} else if (itemId == R.id.menu_add_note) { } else if (itemId == R.id.menu_add_note) {
if (requestExternalStorageWritePermissionForNotes()) { if (requestExternalStorageWritePermissionForNotes()) {
@ -898,6 +896,8 @@ public abstract class CoreMainActivity extends BaseActivity implements WebViewCa
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
protected abstract void createNewTab();
/** 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();
@ -986,12 +986,6 @@ public abstract class CoreMainActivity extends BaseActivity implements WebViewCa
} }
} }
@Override
public void showHomePage() {
getCurrentWebView().removeAllViews();
getCurrentWebView().loadUrl(HOME_URL);
}
@Override @Override
public void openExternalUrl(Intent intent) { public void openExternalUrl(Intent intent) {
if (intent.resolveActivity(getPackageManager()) != null) { if (intent.resolveActivity(getPackageManager()) != null) {
@ -1219,12 +1213,13 @@ public abstract class CoreMainActivity extends BaseActivity implements WebViewCa
private void openHomeScreen() { private void openHomeScreen() {
new Handler().postDelayed(() -> { new Handler().postDelayed(() -> {
if (webViewList.size() == 0) { if (webViewList.size() == 0) {
newTab(HOME_URL); createNewTab();
hideTabSwitcher(); hideTabSwitcher();
} }
}, 300); }, 300);
} }
@OnClick(R2.id.bottom_toolbar_bookmark) @OnClick(R2.id.bottom_toolbar_bookmark)
public void toggleBookmark() { public void toggleBookmark() {
//Check maybe need refresh //Check maybe need refresh
@ -1277,17 +1272,7 @@ public abstract class CoreMainActivity extends BaseActivity implements WebViewCa
recreate(); recreate();
} }
presenter.loadCurrentZimBookmarksUrl(); presenter.loadCurrentZimBookmarksUrl();
if (zimReaderContainer.getZimFile() == null &&
!HOME_URL.equals(getCurrentWebView().getUrl())) {
showHomePage();
}
if (!webViewList.isEmpty() && currentWebViewIndex < webViewList.size() &&
webViewList.get(currentWebViewIndex).getUrl() != null &&
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).setEnabled(true);
}
updateBottomToolbarVisibility(); updateBottomToolbarVisibility();
presenter.loadBooks(); presenter.loadBooks();
@ -1324,9 +1309,6 @@ public abstract class CoreMainActivity extends BaseActivity implements WebViewCa
startActivityForResult(i, REQUEST_FILE_SEARCH); startActivityForResult(i, REQUEST_FILE_SEARCH);
} }
break; break;
case NEW_TAB:
newTab(HOME_URL);
break;
} }
} }
updateWidgets(this); updateWidgets(this);
@ -1334,8 +1316,7 @@ public abstract class CoreMainActivity extends BaseActivity implements WebViewCa
private void updateBottomToolbarVisibility() { private void updateBottomToolbarVisibility() {
if (checkNull(bottomToolbar)) { if (checkNull(bottomToolbar)) {
if (!HOME_URL.equals( if (!urlIsInvalid()
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) {
@ -1507,7 +1488,7 @@ public abstract class CoreMainActivity extends BaseActivity implements WebViewCa
} }
if (resultCode == RESULT_HISTORY_CLEARED) { if (resultCode == RESULT_HISTORY_CLEARED) {
webViewList.clear(); webViewList.clear();
newTab(); newMainPageTab();
tabsAdapter.notifyDataSetChanged(); tabsAdapter.notifyDataSetChanged();
} }
loadPrefs(); loadPrefs();
@ -1522,7 +1503,7 @@ public abstract class CoreMainActivity extends BaseActivity implements WebViewCa
kiwixWebView.clearHistory(); kiwixWebView.clearHistory();
} }
webViewList.clear(); webViewList.clear();
newTab(HOME_URL); createNewTab();
} else { } else {
String title = data.getStringExtra(EXTRA_CHOSE_X_TITLE); String title = data.getStringExtra(EXTRA_CHOSE_X_TITLE);
String url = data.getStringExtra(EXTRA_CHOSE_X_URL); String url = data.getStringExtra(EXTRA_CHOSE_X_URL);
@ -1550,7 +1531,7 @@ public abstract class CoreMainActivity extends BaseActivity implements WebViewCa
finish(); finish();
return; return;
} }
newTab(); newMainPageTab();
if (url != null) { if (url != null) {
getCurrentWebView().loadUrl(url); getCurrentWebView().loadUrl(url);
} else if (title != null) { } else if (title != null) {
@ -1608,7 +1589,7 @@ public abstract class CoreMainActivity extends BaseActivity implements WebViewCa
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_fullscreen).setVisible(true); menu.findItem(R.id.menu_fullscreen).setVisible(true);
if (urlIsHomeOrNull()) { if (urlIsInvalid()) {
menu.findItem(R.id.menu_search).setVisible(false); menu.findItem(R.id.menu_search).setVisible(false);
menu.findItem(R.id.menu_read_aloud).setVisible(false); menu.findItem(R.id.menu_read_aloud).setVisible(false);
menu.findItem(R.id.menu_random_article).setVisible(false); menu.findItem(R.id.menu_random_article).setVisible(false);
@ -1621,9 +1602,8 @@ public abstract class CoreMainActivity extends BaseActivity implements WebViewCa
return true; return true;
} }
private boolean urlIsHomeOrNull() { protected boolean urlIsInvalid(){
return getCurrentWebView().getUrl() == null || return getCurrentWebView().getUrl() == null;
getCurrentWebView().getUrl().equals(HOME_URL);
} }
private void updateTabSwitcherIcon() { private void updateTabSwitcherIcon() {
@ -1638,15 +1618,10 @@ public abstract class CoreMainActivity extends BaseActivity implements WebViewCa
private void refreshBookmarkSymbol() { private void refreshBookmarkSymbol() {
if (checkNull(bottomToolbarBookmark)) { if (checkNull(bottomToolbarBookmark)) {
if (getCurrentWebView().getUrl() != null && bottomToolbarBookmark.setImageResource(
zimReaderContainer.getId() != null && bookmarks.contains(getCurrentWebView().getUrl()) ? R.drawable.ic_bookmark_24dp
!getCurrentWebView().getUrl().equals(HOME_URL)) { : R.drawable.ic_bookmark_border_24dp
int icon = bookmarks.contains(getCurrentWebView().getUrl()) ? R.drawable.ic_bookmark_24dp );
: R.drawable.ic_bookmark_border_24dp;
bottomToolbarBookmark.setImageResource(icon);
} else {
bottomToolbarBookmark.setImageResource(R.drawable.ic_bookmark_border_24dp);
}
} }
} }
@ -1734,7 +1709,7 @@ public abstract class CoreMainActivity extends BaseActivity implements WebViewCa
updateBottomToolbarArrowsAlpha(); updateBottomToolbarArrowsAlpha();
String url = getCurrentWebView().getUrl(); String url = getCurrentWebView().getUrl();
final ZimFileReader zimFileReader = zimReaderContainer.getZimFileReader(); final ZimFileReader zimFileReader = zimReaderContainer.getZimFileReader();
if (url != null && !url.equals(HOME_URL) && zimFileReader != null) { if (hasValidFileAndUrl(url, zimFileReader)) {
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));
@ -1750,6 +1725,10 @@ public abstract class CoreMainActivity extends BaseActivity implements WebViewCa
updateBottomToolbarVisibility(); updateBottomToolbarVisibility();
} }
protected boolean hasValidFileAndUrl(String url, ZimFileReader zimFileReader) {
return url != null && zimFileReader != null;
}
@Override @Override
public void webViewFailedLoading(String url) { public void webViewFailedLoading(String url) {
String error = String.format(getString(R.string.error_article_url_not_found), url); String error = String.format(getString(R.string.error_article_url_not_found), url);

View File

@ -26,7 +26,6 @@ import android.os.Build.VERSION_CODES
import android.os.Environment import android.os.Environment
import android.provider.DocumentsContract import android.provider.DocumentsContract
import android.util.Log import android.util.Log
import org.kiwix.kiwixmobile.core.CoreApp
import org.kiwix.kiwixmobile.core.downloader.ChunkUtils import org.kiwix.kiwixmobile.core.downloader.ChunkUtils
import org.kiwix.kiwixmobile.core.entity.LibraryNetworkEntity.Book import org.kiwix.kiwixmobile.core.entity.LibraryNetworkEntity.Book
import org.kiwix.kiwixmobile.core.extensions.get import org.kiwix.kiwixmobile.core.extensions.get
@ -37,10 +36,6 @@ import java.util.ArrayList
object FileUtils { object FileUtils {
private val saveFilePath =
"${Environment.getExternalStorageDirectory()}${File.separator}Android" +
"${File.separator}obb${File.separator}${CoreApp.getInstance().packageName}"
@JvmStatic fun getFileCacheDir(context: Context): File? = @JvmStatic fun getFileCacheDir(context: Context): File? =
if (Environment.MEDIA_MOUNTED == Environment.getExternalStorageState()) { if (Environment.MEDIA_MOUNTED == Environment.getExternalStorageState()) {
context.externalCacheDir context.externalCacheDir
@ -95,11 +90,6 @@ object FileUtils {
return false return false
} }
/**
* Returns the filename (where the file should be saved) from info about a download
*/
@JvmStatic fun generateSaveFileName(fileName: String) = "$saveFilePath${File.separator}$fileName"
/** /**
* Helper function to ascertain the existence of a file and return true/false appropriately * Helper function to ascertain the existence of a file and return true/false appropriately
* *

View File

@ -4,7 +4,7 @@
"version_name": "2017-07", "version_name": "2017-07",
"version_code": "1", "version_code": "1",
"zim_file": "wikipedia_fr_test_2017-07.zim", "zim_file": "wikipedia_fr_test_2017-07.zim",
"embed_zim": true, "embed_zim": false,
"ic_launcher": "icon.png", "ic_launcher": "icon.png",
"enforced_lang": "en" "enforced_lang": "en"
} }

View File

@ -39,6 +39,15 @@ import java.io.File
import java.util.Locale import java.util.Locale
class CustomMainActivity : CoreMainActivity() { class CustomMainActivity : CoreMainActivity() {
override fun showHomePage() {
Log.e("CustomMain", "tried to show home page")
}
override fun createNewTab() {
newMainPageTab()
}
override fun injection() { override fun injection() {
customActivityComponent.inject(this) customActivityComponent.inject(this)
} }
@ -111,8 +120,7 @@ class CustomMainActivity : CoreMainActivity() {
) )
} }
} else { } else {
val fileName = getExpansionAPKFileName() filePath = generateExpansionFilePath()
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)
@ -146,12 +154,10 @@ class CustomMainActivity : CoreMainActivity() {
} }
companion object { companion object {
/** private fun getExpansionAPKFileName() =
* Returns the file name (without full path) for an Expansion APK file from the given context. "main.${BuildConfig.CONTENT_VERSION_CODE}.${CoreApp.getInstance().packageName}.obb"
*
* @return String the file name of the expansion file fun generateExpansionFilePath(fileName: String = getExpansionAPKFileName()) =
*/ "${CoreApp.getInstance().obbDir}${File.separator}$fileName"
@JvmStatic fun getExpansionAPKFileName() =
"patch.${BuildConfig.CONTENT_VERSION_CODE}.${CoreApp.getInstance().packageName}.obb"
} }
} }