mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-18 03:45:33 -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"
|
||||
}
|
||||
|
||||
|
||||
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 {
|
||||
abortOnError false
|
||||
}
|
||||
|
@ -150,7 +150,7 @@
|
||||
|
||||
<provider
|
||||
android:name=".ZimContentProvider"
|
||||
android:authorities="org.kiwix.zim.base"
|
||||
android:authorities="${applicationId}.zim.base"
|
||||
android:exported="true" />
|
||||
|
||||
<receiver android:name=".utils.KiwixSearchWidget">
|
||||
|
@ -85,7 +85,6 @@ import org.json.JSONArray;
|
||||
import org.kiwix.kiwixmobile.database.BookmarksDao;
|
||||
import org.kiwix.kiwixmobile.database.KiwixDatabase;
|
||||
import org.kiwix.kiwixmobile.di.components.ApplicationComponent;
|
||||
import org.kiwix.kiwixmobile.settings.Constants;
|
||||
import org.kiwix.kiwixmobile.settings.KiwixSettingsActivity;
|
||||
import org.kiwix.kiwixmobile.utils.DimenUtils;
|
||||
import org.kiwix.kiwixmobile.utils.DocumentParser;
|
||||
@ -864,7 +863,7 @@ public class KiwixMobileActivity extends BaseActivity implements WebViewCallback
|
||||
|
||||
|
||||
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)) {
|
||||
if (file.exists()) {
|
||||
if (ZimContentProvider.setZimFile(file.getAbsolutePath()) != null) {
|
||||
@ -906,7 +905,7 @@ public class KiwixMobileActivity extends BaseActivity implements WebViewCallback
|
||||
ActivityCompat.requestPermissions(this,
|
||||
new String[] { Manifest.permission.READ_EXTERNAL_STORAGE },
|
||||
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)
|
||||
.show();
|
||||
} else {
|
||||
@ -1403,7 +1402,7 @@ public class KiwixMobileActivity extends BaseActivity implements WebViewCallback
|
||||
inflater.inflate(R.menu.menu_main, menu);
|
||||
this.menu = menu;
|
||||
StyleMenuButtons(menu);
|
||||
if (Constants.IS_CUSTOM_APP) {
|
||||
if (BuildConfig.IS_CUSTOM_APP) {
|
||||
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.
|
||||
} 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.");
|
||||
|
||||
String currentLocaleCode = Locale.getDefault().toString();
|
||||
// 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)) {
|
||||
|
||||
// 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
|
||||
SharedPreferences sharedPreferences =
|
||||
PreferenceManager.getDefaultSharedPreferences(this);
|
||||
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();
|
||||
|
||||
// restart activity for new locale to take effect
|
||||
@ -1624,22 +1623,22 @@ public class KiwixMobileActivity extends BaseActivity implements WebViewCallback
|
||||
}
|
||||
|
||||
String filePath = "";
|
||||
if (Constants.CUSTOM_APP_HAS_EMBEDDED_ZIM) {
|
||||
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() + "/" + Constants.CUSTOM_APP_ZIM_FILE_NAME;
|
||||
filePath = libDir.listFiles()[0].getPath() + "/" + BuildConfig.ZIM_FILE_NAME;
|
||||
}
|
||||
if (filePath.isEmpty() || !new File(filePath).exists()) {
|
||||
filePath = String.format("/data/data/%s/lib/%s", Constants.CUSTOM_APP_ID,
|
||||
Constants.CUSTOM_APP_ZIM_FILE_NAME);
|
||||
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);
|
||||
}
|
||||
|
||||
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());
|
||||
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),
|
||||
new DialogInterface.OnClickListener() {
|
||||
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.setData(Uri.parse(market_uri));
|
||||
startActivity(intent);
|
||||
|
@ -4,7 +4,6 @@ import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.webkit.MimeTypeMap;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
@ -12,7 +11,6 @@ import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.HashMap;
|
||||
import org.kiwix.kiwixmobile.settings.Constants;
|
||||
import org.kiwix.kiwixmobile.utils.StyleUtils;
|
||||
|
||||
public class KiwixWebViewClient extends WebViewClient {
|
||||
@ -67,13 +65,13 @@ public class KiwixWebViewClient extends WebViewClient {
|
||||
|
||||
@Override
|
||||
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();
|
||||
return;
|
||||
}
|
||||
if (!url.equals("file:///android_res/raw/help.html")) {
|
||||
view.removeView(help);
|
||||
} else if (!Constants.IS_CUSTOM_APP) {
|
||||
} else if (!BuildConfig.IS_CUSTOM_APP) {
|
||||
LayoutInflater inflater = LayoutInflater.from(view.getContext());
|
||||
help = (LinearLayout) inflater.inflate(R.layout.help, null);
|
||||
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 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/");
|
||||
|
||||
|
@ -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 java.io.File;
|
||||
import java.util.Locale;
|
||||
import org.kiwix.kiwixmobile.BuildConfig;
|
||||
import org.kiwix.kiwixmobile.KiwixMobileActivity;
|
||||
import org.kiwix.kiwixmobile.LibraryFragment;
|
||||
import org.kiwix.kiwixmobile.R;
|
||||
@ -137,7 +138,7 @@ public class KiwixSettingsActivity extends AppCompatActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
addPreferencesFromResource(R.xml.preferences);
|
||||
|
||||
if (Constants.CUSTOM_APP_ENFORCED_LANG.equals("")) {
|
||||
if (BuildConfig.ENFORCED_LANG.equals("")) {
|
||||
setUpLanguageChooser(PREF_LANG);
|
||||
} else {
|
||||
getPreferenceScreen().removePreference(getPrefrence("pref_language"));
|
||||
@ -156,7 +157,7 @@ public class KiwixSettingsActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void setStorage(){
|
||||
if (Constants.IS_CUSTOM_APP){
|
||||
if (BuildConfig.IS_CUSTOM_APP){
|
||||
getPreferenceScreen().removePreference(getPrefrence("pref_storage"));
|
||||
} else {
|
||||
if (Environment.isExternalStorageEmulated()) {
|
||||
|
@ -13,7 +13,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import org.kiwix.kiwixmobile.settings.Constants;
|
||||
import org.kiwix.kiwixmobile.BuildConfig;
|
||||
|
||||
public class FileUtils {
|
||||
|
||||
@ -79,8 +79,8 @@ public class FileUtils {
|
||||
* @return String the file name of the expansion file
|
||||
*/
|
||||
public static String getExpansionAPKFileName(boolean mainFile) {
|
||||
return (mainFile ? "main." : "patch.") + Constants.CUSTOM_APP_CONTENT_VERSION_CODE + "."
|
||||
+ Constants.CUSTOM_APP_ID + ".obb";
|
||||
return (mainFile ? "main." : "patch.") + BuildConfig.CONTENT_VERSION_CODE + "."
|
||||
+ BuildConfig.APPLICATION_ID + ".obb";
|
||||
}
|
||||
|
||||
/**
|
||||
@ -93,7 +93,7 @@ public class FileUtils {
|
||||
static public String getSaveFilePath() {
|
||||
String obbFolder = File.separator + "Android" + File.separator + "obb" + File.separator;
|
||||
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