mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-18 11:55:38 -04:00
Transformed constants into build variables
This commit is contained in:
parent
6514cc885e
commit
b0e8d967a8
@ -76,6 +76,27 @@ dependencies {
|
|||||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
productFlavors {
|
||||||
|
kiwix {
|
||||||
|
buildConfigField "boolean", "IS_CUSTOM_APP", "false"
|
||||||
|
buildConfigField "boolean", "HAS_EMBEDDED_ZIM", "false"
|
||||||
|
buildConfigField "String", "ZIM_FILE_NAME", "\"\""
|
||||||
|
buildConfigField "long", "ZIM_FILE_SIZE", "0"
|
||||||
|
buildConfigField "int", "CONTENT_VERSION_CODE", "0"
|
||||||
|
buildConfigField "String", "ENFORCED_LANG", "\"\""
|
||||||
|
}
|
||||||
|
custom {
|
||||||
|
applicationId "org.kiwix.kiwixcustomtest"
|
||||||
|
buildConfigField "boolean", "IS_CUSTOM_APP", "true"
|
||||||
|
buildConfigField "boolean", "HAS_EMBEDDED_ZIM", "false"
|
||||||
|
buildConfigField "String", "ZIM_FILE_NAME", "\"\""
|
||||||
|
buildConfigField "long", "ZIM_FILE_SIZE", "0"
|
||||||
|
buildConfigField "int", "CONTENT_VERSION_CODE", "0"
|
||||||
|
buildConfigField "String", "ENFORCED_LANG", "\"\""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
lintOptions {
|
lintOptions {
|
||||||
abortOnError false
|
abortOnError false
|
||||||
}
|
}
|
||||||
|
@ -150,7 +150,7 @@
|
|||||||
|
|
||||||
<provider
|
<provider
|
||||||
android:name=".ZimContentProvider"
|
android:name=".ZimContentProvider"
|
||||||
android:authorities="org.kiwix.zim.base"
|
android:authorities="${applicationId}.zim.base"
|
||||||
android:exported="true" />
|
android:exported="true" />
|
||||||
|
|
||||||
<receiver android:name=".utils.KiwixSearchWidget">
|
<receiver android:name=".utils.KiwixSearchWidget">
|
||||||
|
@ -85,7 +85,6 @@ import org.json.JSONArray;
|
|||||||
import org.kiwix.kiwixmobile.database.BookmarksDao;
|
import org.kiwix.kiwixmobile.database.BookmarksDao;
|
||||||
import org.kiwix.kiwixmobile.database.KiwixDatabase;
|
import org.kiwix.kiwixmobile.database.KiwixDatabase;
|
||||||
import org.kiwix.kiwixmobile.di.components.ApplicationComponent;
|
import org.kiwix.kiwixmobile.di.components.ApplicationComponent;
|
||||||
import org.kiwix.kiwixmobile.settings.Constants;
|
|
||||||
import org.kiwix.kiwixmobile.settings.KiwixSettingsActivity;
|
import org.kiwix.kiwixmobile.settings.KiwixSettingsActivity;
|
||||||
import org.kiwix.kiwixmobile.utils.DimenUtils;
|
import org.kiwix.kiwixmobile.utils.DimenUtils;
|
||||||
import org.kiwix.kiwixmobile.utils.DocumentParser;
|
import org.kiwix.kiwixmobile.utils.DocumentParser;
|
||||||
@ -864,7 +863,7 @@ public class KiwixMobileActivity extends BaseActivity implements WebViewCallback
|
|||||||
|
|
||||||
|
|
||||||
public boolean openZimFile(File file, boolean clearHistory) {
|
public boolean openZimFile(File file, boolean clearHistory) {
|
||||||
if (file.canRead() || Build.VERSION.SDK_INT < 19 || (Constants.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) {
|
||||||
@ -906,7 +905,7 @@ public class KiwixMobileActivity extends BaseActivity implements WebViewCallback
|
|||||||
ActivityCompat.requestPermissions(this,
|
ActivityCompat.requestPermissions(this,
|
||||||
new String[] { Manifest.permission.READ_EXTERNAL_STORAGE },
|
new String[] { Manifest.permission.READ_EXTERNAL_STORAGE },
|
||||||
KiwixMobileActivity.REQUEST_STORAGE_PERMISSION);
|
KiwixMobileActivity.REQUEST_STORAGE_PERMISSION);
|
||||||
if (Constants.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.LENGTH_LONG)
|
Toast.makeText(this, getResources().getString(R.string.request_storage_custom), Toast.LENGTH_LONG)
|
||||||
.show();
|
.show();
|
||||||
} else {
|
} else {
|
||||||
@ -1403,7 +1402,7 @@ public class KiwixMobileActivity extends BaseActivity implements WebViewCallback
|
|||||||
inflater.inflate(R.menu.menu_main, menu);
|
inflater.inflate(R.menu.menu_main, menu);
|
||||||
this.menu = menu;
|
this.menu = menu;
|
||||||
StyleMenuButtons(menu);
|
StyleMenuButtons(menu);
|
||||||
if (Constants.IS_CUSTOM_APP) {
|
if (BuildConfig.IS_CUSTOM_APP) {
|
||||||
menu.findItem(R.id.menu_help).setVisible(false);
|
menu.findItem(R.id.menu_help).setVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1599,22 +1598,22 @@ public class KiwixMobileActivity extends BaseActivity implements WebViewCallback
|
|||||||
// 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 {
|
||||||
|
|
||||||
if (Constants.IS_CUSTOM_APP) {
|
if (BuildConfig.IS_CUSTOM_APP) {
|
||||||
Log.d(TAG_KIWIX, "Kiwix Custom App starting for the first time. Check Companion ZIM.");
|
Log.d(TAG_KIWIX, "Kiwix Custom App starting for the first time. Check Companion ZIM.");
|
||||||
|
|
||||||
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 (Constants.CUSTOM_APP_ENFORCED_LANG.length() > 0 && !Constants.CUSTOM_APP_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, Constants.CUSTOM_APP_ENFORCED_LANG);
|
LanguageUtils.handleLocaleChange(this, BuildConfig.ENFORCED_LANG);
|
||||||
|
|
||||||
// save new locale into preferences for next startup
|
// save new locale into preferences for next startup
|
||||||
SharedPreferences sharedPreferences =
|
SharedPreferences sharedPreferences =
|
||||||
PreferenceManager.getDefaultSharedPreferences(this);
|
PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||||
editor.putString("pref_language_chooser", Constants.CUSTOM_APP_ENFORCED_LANG);
|
editor.putString("pref_language_chooser", BuildConfig.ENFORCED_LANG);
|
||||||
editor.apply();
|
editor.apply();
|
||||||
|
|
||||||
// restart activity for new locale to take effect
|
// restart activity for new locale to take effect
|
||||||
@ -1624,22 +1623,22 @@ public class KiwixMobileActivity extends BaseActivity implements WebViewCallback
|
|||||||
}
|
}
|
||||||
|
|
||||||
String filePath = "";
|
String filePath = "";
|
||||||
if (Constants.CUSTOM_APP_HAS_EMBEDDED_ZIM) {
|
if (BuildConfig.HAS_EMBEDDED_ZIM) {
|
||||||
String appPath = getPackageResourcePath();
|
String appPath = getPackageResourcePath();
|
||||||
File libDir = new File(appPath.substring(0, appPath.lastIndexOf("/")) + "/lib/");
|
File libDir = new File(appPath.substring(0, appPath.lastIndexOf("/")) + "/lib/");
|
||||||
if (libDir.exists() && libDir.listFiles().length > 0) {
|
if (libDir.exists() && libDir.listFiles().length > 0) {
|
||||||
filePath = libDir.listFiles()[0].getPath() + "/" + Constants.CUSTOM_APP_ZIM_FILE_NAME;
|
filePath = libDir.listFiles()[0].getPath() + "/" + BuildConfig.ZIM_FILE_NAME;
|
||||||
}
|
}
|
||||||
if (filePath.isEmpty() || !new File(filePath).exists()) {
|
if (filePath.isEmpty() || !new File(filePath).exists()) {
|
||||||
filePath = String.format("/data/data/%s/lib/%s", Constants.CUSTOM_APP_ID,
|
filePath = String.format("/data/data/%s/lib/%s", BuildConfig.APPLICATION_ID,
|
||||||
Constants.CUSTOM_APP_ZIM_FILE_NAME);
|
BuildConfig.ZIM_FILE_NAME);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
String fileName = FileUtils.getExpansionAPKFileName(true);
|
String fileName = FileUtils.getExpansionAPKFileName(true);
|
||||||
filePath = FileUtils.generateSaveFileName(fileName);
|
filePath = FileUtils.generateSaveFileName(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!FileUtils.doesFileExist(filePath, Constants.CUSTOM_APP_ZIM_FILE_SIZE, false)) {
|
if (!FileUtils.doesFileExist(filePath, BuildConfig.ZIM_FILE_SIZE, false)) {
|
||||||
|
|
||||||
AlertDialog.Builder zimFileMissingBuilder = new AlertDialog.Builder(this, dialogStyle());
|
AlertDialog.Builder zimFileMissingBuilder = new AlertDialog.Builder(this, dialogStyle());
|
||||||
zimFileMissingBuilder.setTitle(R.string.app_name);
|
zimFileMissingBuilder.setTitle(R.string.app_name);
|
||||||
@ -1649,7 +1648,7 @@ public class KiwixMobileActivity extends BaseActivity implements WebViewCallback
|
|||||||
zimFileMissingBuilder.setPositiveButton(getString(R.string.go_to_play_store),
|
zimFileMissingBuilder.setPositiveButton(getString(R.string.go_to_play_store),
|
||||||
new DialogInterface.OnClickListener() {
|
new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
String market_uri = "market://details?id=" + Constants.CUSTOM_APP_ID;
|
String market_uri = "market://details?id=" + 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);
|
||||||
|
@ -4,7 +4,6 @@ import android.content.Intent;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
|
||||||
import android.webkit.MimeTypeMap;
|
import android.webkit.MimeTypeMap;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
import android.webkit.WebViewClient;
|
import android.webkit.WebViewClient;
|
||||||
@ -12,7 +11,6 @@ import android.widget.LinearLayout;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import org.kiwix.kiwixmobile.settings.Constants;
|
|
||||||
import org.kiwix.kiwixmobile.utils.StyleUtils;
|
import org.kiwix.kiwixmobile.utils.StyleUtils;
|
||||||
|
|
||||||
public class KiwixWebViewClient extends WebViewClient {
|
public class KiwixWebViewClient extends WebViewClient {
|
||||||
@ -67,13 +65,13 @@ public class KiwixWebViewClient extends WebViewClient {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPageFinished(WebView view, String url) {
|
public void onPageFinished(WebView view, String url) {
|
||||||
if ((url.equals("content://org.kiwix.zim.base/null")) && !Constants.IS_CUSTOM_APP) {
|
if ((url.equals("content://" + BuildConfig.APPLICATION_ID + ".zim.base/null")) && !BuildConfig.IS_CUSTOM_APP) {
|
||||||
callback.showHelpPage();
|
callback.showHelpPage();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!url.equals("file:///android_res/raw/help.html")) {
|
if (!url.equals("file:///android_res/raw/help.html")) {
|
||||||
view.removeView(help);
|
view.removeView(help);
|
||||||
} else if (!Constants.IS_CUSTOM_APP) {
|
} else if (!BuildConfig.IS_CUSTOM_APP) {
|
||||||
LayoutInflater inflater = LayoutInflater.from(view.getContext());
|
LayoutInflater inflater = LayoutInflater.from(view.getContext());
|
||||||
help = (LinearLayout) inflater.inflate(R.layout.help, null);
|
help = (LinearLayout) inflater.inflate(R.layout.help, null);
|
||||||
help.findViewById(R.id.get_content_card)
|
help.findViewById(R.id.get_content_card)
|
||||||
|
@ -46,7 +46,7 @@ public class ZimContentProvider extends ContentProvider {
|
|||||||
|
|
||||||
public static final String TAG_KIWIX = "kiwix";
|
public static final String TAG_KIWIX = "kiwix";
|
||||||
|
|
||||||
public static final Uri CONTENT_URI = Uri.parse("content://org.kiwix.zim.base/");
|
public static final Uri CONTENT_URI = Uri.parse("content://" + BuildConfig.APPLICATION_ID + ".zim.base/");
|
||||||
|
|
||||||
public static final Uri UI_URI = Uri.parse("content://org.kiwix.ui/");
|
public static final Uri UI_URI = Uri.parse("content://org.kiwix.ui/");
|
||||||
|
|
||||||
|
@ -1,28 +0,0 @@
|
|||||||
package org.kiwix.kiwixmobile.settings;
|
|
||||||
|
|
||||||
public class Constants {
|
|
||||||
|
|
||||||
public static final boolean IS_CUSTOM_APP = false;
|
|
||||||
|
|
||||||
public static final String CUSTOM_APP_ID = "~package~";
|
|
||||||
|
|
||||||
public static final boolean CUSTOM_APP_HAS_EMBEDDED_ZIM = false;
|
|
||||||
|
|
||||||
public static final String CUSTOM_APP_ZIM_FILE_NAME = "~zim_name~";
|
|
||||||
|
|
||||||
public static final long CUSTOM_APP_ZIM_FILE_SIZE = 0;
|
|
||||||
|
|
||||||
public static final String CUSTOM_APP_VERSION_NAME = "~version_name~";
|
|
||||||
|
|
||||||
public static final int CUSTOM_APP_VERSION_CODE = 2;
|
|
||||||
|
|
||||||
public static final int CUSTOM_APP_CONTENT_VERSION_CODE = 0;
|
|
||||||
|
|
||||||
public static final String CUSTOM_APP_WEBSITE = "~website~";
|
|
||||||
|
|
||||||
public static final String CUSTOM_APP_EMAIL = "~support_email~";
|
|
||||||
|
|
||||||
public static final String CUSTOM_APP_SUPPORT_EMAIL = "~support_email~";
|
|
||||||
|
|
||||||
public static final String CUSTOM_APP_ENFORCED_LANG = "";
|
|
||||||
}
|
|
@ -44,6 +44,7 @@ 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;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import org.kiwix.kiwixmobile.BuildConfig;
|
||||||
import org.kiwix.kiwixmobile.KiwixMobileActivity;
|
import org.kiwix.kiwixmobile.KiwixMobileActivity;
|
||||||
import org.kiwix.kiwixmobile.LibraryFragment;
|
import org.kiwix.kiwixmobile.LibraryFragment;
|
||||||
import org.kiwix.kiwixmobile.R;
|
import org.kiwix.kiwixmobile.R;
|
||||||
@ -137,7 +138,7 @@ public class KiwixSettingsActivity extends AppCompatActivity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
addPreferencesFromResource(R.xml.preferences);
|
addPreferencesFromResource(R.xml.preferences);
|
||||||
|
|
||||||
if (Constants.CUSTOM_APP_ENFORCED_LANG.equals("")) {
|
if (BuildConfig.ENFORCED_LANG.equals("")) {
|
||||||
setUpLanguageChooser(PREF_LANG);
|
setUpLanguageChooser(PREF_LANG);
|
||||||
} else {
|
} else {
|
||||||
getPreferenceScreen().removePreference(getPrefrence("pref_language"));
|
getPreferenceScreen().removePreference(getPrefrence("pref_language"));
|
||||||
@ -156,7 +157,7 @@ public class KiwixSettingsActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setStorage(){
|
private void setStorage(){
|
||||||
if (Constants.IS_CUSTOM_APP){
|
if (BuildConfig.IS_CUSTOM_APP){
|
||||||
getPreferenceScreen().removePreference(getPrefrence("pref_storage"));
|
getPreferenceScreen().removePreference(getPrefrence("pref_storage"));
|
||||||
} else {
|
} else {
|
||||||
if (Environment.isExternalStorageEmulated()) {
|
if (Environment.isExternalStorageEmulated()) {
|
||||||
|
@ -13,7 +13,7 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import org.kiwix.kiwixmobile.settings.Constants;
|
import org.kiwix.kiwixmobile.BuildConfig;
|
||||||
|
|
||||||
public class FileUtils {
|
public class FileUtils {
|
||||||
|
|
||||||
@ -79,8 +79,8 @@ public class FileUtils {
|
|||||||
* @return String the file name of the expansion file
|
* @return String the file name of the expansion file
|
||||||
*/
|
*/
|
||||||
public static String getExpansionAPKFileName(boolean mainFile) {
|
public static String getExpansionAPKFileName(boolean mainFile) {
|
||||||
return (mainFile ? "main." : "patch.") + Constants.CUSTOM_APP_CONTENT_VERSION_CODE + "."
|
return (mainFile ? "main." : "patch.") + BuildConfig.CONTENT_VERSION_CODE + "."
|
||||||
+ Constants.CUSTOM_APP_ID + ".obb";
|
+ BuildConfig.APPLICATION_ID + ".obb";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -93,7 +93,7 @@ public class FileUtils {
|
|||||||
static public String getSaveFilePath() {
|
static public String getSaveFilePath() {
|
||||||
String obbFolder = File.separator + "Android" + File.separator + "obb" + File.separator;
|
String obbFolder = File.separator + "Android" + File.separator + "obb" + File.separator;
|
||||||
File root = Environment.getExternalStorageDirectory();
|
File root = Environment.getExternalStorageDirectory();
|
||||||
return root.toString() + obbFolder + Constants.CUSTOM_APP_ID;
|
return root.toString() + obbFolder + BuildConfig.APPLICATION_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user