Add custom module

This commit is contained in:
Sean Mac Gillicuddy 2019-09-27 15:28:40 +01:00
parent 73595a2a11
commit 8bb9bca68a
24 changed files with 443 additions and 125 deletions

View File

@ -34,39 +34,6 @@ apply plugin: 'kotlin-kapt'
apply plugin: 'jacoco-android'
apply plugin: "org.jlleitschuh.gradle.ktlint"
repositories {
google()
mavenCentral()
maven {
url "https://maven.google.com"
}
jcenter()
}
String[] archs = ['arm64-v8a', 'armeabi-v7a', 'x86', 'x86_64']
// Set custom app import directory
def map = [:]
def custom = new File("app/src")
if (project.hasProperty("customDir")) {
custom = file(project.property("customDir"))
}
// Set up flavours for each custom app in the directory
if (custom.listFiles()) {
custom.eachFile() { file ->
def fileName = file.getName()
if (fileName.startsWith(".") ||
fileName.contains("test") ||
fileName == "main" ||
fileName.contains("Test")) {
return
}
map.put(fileName, file.getAbsolutePath())
}
}
jacoco {
toolVersion = "0.8.3"
}
@ -75,9 +42,6 @@ tasks.withType(Test) {
jacoco.includeNoLocationClasses = true
}
def branchName = System.getenv('TRAVIS_PULL_REQUEST') ?: "false" == "false"
? System.getenv('TRAVIS_BRANCH') ?: "local"
: System.getenv('TRAVIS_PULL_REQUEST_BRANCH')
def buildNumber = System.getenv('TRAVIS_BUILD_NUMBER') ?: "dev"
ext {
@ -228,96 +192,7 @@ android {
}
}
// Custom apps built from a json file, zim file and icon set
map.each { name, directory ->
"$name" {
println "Configuring $name"
if (name == "kiwix") {
return
}
if (file(directory + "/build.gradle").exists()) {
apply from: directory + "/build.gradle"
}
def jsonFile
if (project.hasProperty("jsonFile")) {
// Read json file from properties e.g command line
jsonFile = file(project.property("jsonFile"))
} else {
// If no file provided use the test file
jsonFile = file(directory + "/info.json")
}
def parsedJson = new JsonSlurper().parseText(jsonFile.text)
def sourceFile = file(parsedJson.zim_file)
if (!sourceFile.exists()) {
sourceFile = file(directory + "/" + parsedJson.zim_file)
}
if (parsedJson.embed_zim) {
// Place content in each lib directory for embeded zims
for (String archName : archs) {
copy {
from sourceFile
into file(directory + "/jniLibs/" + archName)
rename { String filename -> "libcontent.so" }
}
}
parsedJson.zim_file = "libcontent.so"
}
// Set custom config from json
applicationId "$parsedJson.package"
buildConfigField "boolean", "IS_CUSTOM_APP", "true"
buildConfigField "boolean", "HAS_EMBEDDED_ZIM", "$parsedJson.embed_zim"
def filename
if (parsedJson.zim_file.lastIndexOf("/") >= 0) {
filename = parsedJson.zim_file.substring(parsedJson.zim_file.lastIndexOf("/") + 1)
} else {
filename = parsedJson.zim_file
}
buildConfigField "String", "ZIM_FILE_NAME", "\"$filename\""
if (project.hasProperty("zim_file_size")) {
def length = Long.parseLong(project.property("zim_file_size"))
buildConfigField "long", "ZIM_FILE_SIZE", "${length}L"
} else {
long length = sourceFile.length()
buildConfigField "long", "ZIM_FILE_SIZE", "${length}L"
}
if (project.hasProperty("version_code")) {
def version_code = project.property("version_code")
versionCode version_code.toInteger()
} else {
versionCode parsedJson.version_code.toInteger()
}
if (project.hasProperty("version_name")) {
versionName project.property("version_name")
} else {
versionName parsedJson.version_name
}
if (project.hasProperty("content_version_code")) {
def content_version_code = project.property("content_version_code")
buildConfigField "int", "CONTENT_VERSION_CODE", "$content_version_code"
} else if (parsedJson.content_version_code != null) {
buildConfigField "int", "CONTENT_VERSION_CODE", "$parsedJson.content_version_code"
} else if (project.hasProperty('version_code')) {
def version_code = project.property('version_code')
buildConfigField "int", "CONTENT_VERSION_CODE", "$version_code"
} else if (parsedJson.version_code != null) {
buildConfigField "int", "CONTENT_VERSION_CODE", "$parsedJson.version_code"
}
buildConfigField "String", "ENFORCED_LANG", "\"$parsedJson.enforced_lang\""
resValue "string", "app_name", "$parsedJson.app_name"
resValue "string", "app_search_string", "Search " + "$parsedJson.app_name"
}
}
}
// Set each custom apps respective source directory
sourceSets {
map.each { name, directory ->
"$name" {
setRoot directory
jni.srcDirs = []
jniLibs.srcDir directory + "/jniLibs"
}
}
}
compileOptions {

View File

@ -45,6 +45,7 @@ allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}

1
custom/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/build

150
custom/build.gradle Normal file
View File

@ -0,0 +1,150 @@
import groovy.json.JsonSlurper
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
String[] archs = ['arm64-v8a', 'armeabi-v7a', 'x86', 'x86_64']
// Set custom app import directory
def map = [:]
def custom = new File("custom/src")
if (project.hasProperty("customDir")) {
custom = file(project.property("customDir"))
}
// Set up flavours for each custom app in the directory
if (custom.listFiles()) {
custom.eachFile() { file ->
def fileName = file.getName()
if (fileName.startsWith(".") ||
fileName.contains("test") ||
fileName == "main" ||
fileName.contains("Test")) {
return
}
map.put(fileName, file.getAbsolutePath())
}
}
android {
compileSdkVersion 28
defaultConfig {
applicationId "org.kiwix.kiwixmobile.custom"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
flavorDimensions "default"
productFlavors {
// Custom apps built from a json file, zim file and icon set
map.each { name, directory ->
"$name" {
println "Configuring $name"
if (file(directory + "/build.gradle").exists()) {
apply from: directory + "/build.gradle"
}
def jsonFile
if (project.hasProperty("jsonFile")) {
// Read json file from properties e.g command line
jsonFile = file(project.property("jsonFile"))
} else {
// If no file provided use the test file
jsonFile = file(directory + "/info.json")
}
def parsedJson = new JsonSlurper().parseText(jsonFile.text)
def sourceFile = file(parsedJson.zim_file)
if (!sourceFile.exists()) {
sourceFile = file(directory + "/" + parsedJson.zim_file)
}
if (parsedJson.embed_zim) {
// Place content in each lib directory for embeded zims
for (String archName : archs) {
copy {
from sourceFile
into file(directory + "/jniLibs/" + archName)
rename { String filename -> "libcontent.so" }
}
}
parsedJson.zim_file = "libcontent.so"
}
// Set custom config from json
applicationId "$parsedJson.package"
buildConfigField "boolean", "IS_CUSTOM_APP", "true"
buildConfigField "boolean", "HAS_EMBEDDED_ZIM", "$parsedJson.embed_zim"
def filename
if (parsedJson.zim_file.lastIndexOf("/") >= 0) {
filename = parsedJson.zim_file.substring(parsedJson.zim_file.lastIndexOf("/") + 1)
} else {
filename = parsedJson.zim_file
}
buildConfigField "String", "ZIM_FILE_NAME", "\"$filename\""
if (project.hasProperty("zim_file_size")) {
def length = Long.parseLong(project.property("zim_file_size"))
buildConfigField "long", "ZIM_FILE_SIZE", "${length}L"
} else {
long length = sourceFile.length()
buildConfigField "long", "ZIM_FILE_SIZE", "${length}L"
}
if (project.hasProperty("version_code")) {
def version_code = project.property("version_code")
versionCode version_code.toInteger()
} else {
versionCode parsedJson.version_code.toInteger()
}
if (project.hasProperty("version_name")) {
versionName project.property("version_name")
} else {
versionName parsedJson.version_name
}
if (project.hasProperty("content_version_code")) {
def content_version_code = project.property("content_version_code")
buildConfigField "int", "CONTENT_VERSION_CODE", "$content_version_code"
} else if (parsedJson.content_version_code != null) {
buildConfigField "int", "CONTENT_VERSION_CODE", "$parsedJson.content_version_code"
} else if (project.hasProperty('version_code')) {
def version_code = project.property('version_code')
buildConfigField "int", "CONTENT_VERSION_CODE", "$version_code"
} else if (parsedJson.version_code != null) {
buildConfigField "int", "CONTENT_VERSION_CODE", "$parsedJson.version_code"
}
buildConfigField "String", "ENFORCED_LANG", "\"$parsedJson.enforced_lang\""
resValue "string", "app_name", "$parsedJson.app_name"
resValue "string", "app_search_string", "Search " + "$parsedJson.app_name"
}
}
}
// Set each custom apps respective source directory
sourceSets {
map.each { name, directory ->
"$name" {
setRoot directory
jni.srcDirs = []
jniLibs.srcDir directory + "/jniLibs"
}
}
}
compileOptions {
encoding = "UTF-8"
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation project(':core')
}

21
custom/proguard-rules.pro vendored Normal file
View File

@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

View File

@ -0,0 +1,24 @@
package org.kiwix.kiwixmobile.custom
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("org.kiwix.kiwixmobile.custom", appContext.packageName)
}
}

View File

Before

Width:  |  Height:  |  Size: 6.8 KiB

After

Width:  |  Height:  |  Size: 6.8 KiB

View File

Before

Width:  |  Height:  |  Size: 6.8 KiB

After

Width:  |  Height:  |  Size: 6.8 KiB

View File

Before

Width:  |  Height:  |  Size: 9.6 KiB

After

Width:  |  Height:  |  Size: 9.6 KiB

View File

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

View File

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 32 KiB

View File

Before

Width:  |  Height:  |  Size: 6.8 KiB

After

Width:  |  Height:  |  Size: 6.8 KiB

View File

Before

Width:  |  Height:  |  Size: 6.8 KiB

After

Width:  |  Height:  |  Size: 6.8 KiB

View File

Before

Width:  |  Height:  |  Size: 9.6 KiB

After

Width:  |  Height:  |  Size: 9.6 KiB

View File

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

View File

@ -0,0 +1,228 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.kiwix.kiwixmobile"
android:installLocation="auto">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<!-- Device with versions >= Pie need this permission -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<application
android:name=".KiwixApplication"
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="@mipmap/kiwix_icon"
android:label="@string/app_name"
android:networkSecurityConfig="@xml/network_security_config"
android:roundIcon="@mipmap/kiwix_icon_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".splash.SplashActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.Launcher">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.MONKEY" />
</intent-filter>
<meta-data
android:name="android.app.shortcuts"
android:resource="@xml/shortcuts" />
</activity>
<activity
android:name=".main.MainActivity"
android:configChanges="orientation|keyboardHidden|screenSize|locale"
android:label="@string/app_name"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="content" />
<data android:mimeType="application/octet-stream" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="file" />
<data android:mimeType="*/*" />
<data android:pathPattern=".*\\.zim" />
<data android:pathPattern=".*\\..*\\.zim" />
<data android:pathPattern=".*\\..*\\..*\\.zim" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.zim" />
<data android:host="*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="file" />
<data android:mimeType="*/*" />
<data android:pathPattern=".*\\.zimaa" />
<data android:pathPattern=".*\\..*\\.zimaa" />
<data android:pathPattern=".*\\..*\\..*\\.zimaa" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.zimaa" />
<data android:host="*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:host="*" />
<data android:pathPattern=".*\\.zim(aa|)" />
<data android:pathPattern=".*\\..*\\.zim(aa|)" />
<data android:pathPattern=".*\\..*\\..*\\.zim(aa|)" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.zim(aa|)" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" />
<data android:host="*" />
<data android:pathPattern=".*\\.zim(aa|)" />
<data android:pathPattern=".*\\..*\\.zim(aa|)" />
<data android:pathPattern=".*\\..*\\..*\\.zim(aa|)" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.zim(aa|)" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="content" />
<data android:host="*" />
<data android:pathPattern=".*\\.zim(aa|)" />
<data android:pathPattern=".*\\..*\\.zim(aa|)" />
<data android:pathPattern=".*\\..*\\..*\\.zim(aa|)" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.zim(aa|)" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="search"
android:scheme="kiwix" />
</intent-filter>
<intent-filter android:label="@string/app_search_string">
<action android:name="android.intent.action.PROCESS_TEXT" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
<activity
android:name=".zim_manager.ZimManageActivity"
android:label="@string/choose_file"
android:launchMode="singleTop">
<!-- TODO -->
<intent-filter>
<action android:name="android.intent.action.GET_CONTENT" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.OPENABLE" />
<data android:mimeType="*/*" />
</intent-filter>
<intent-filter>
<action android:name="org.kiwix.kiwixmobile.utils.KiwixSearchWidget.TEXT_CLICKED" />
<action android:name="org.kiwix.kiwixmobile.utils.KiwixSearchWidget.ICON_CLICKED" />
<action android:name="org.kiwix.kiwixmobile.utils.KiwixSearchWidget.MIC_CLICKED" />
<action android:name="org.kiwix.kiwixmobile.utils.KiwixSearchWidget.STAR_CLICKED" />
</intent-filter>
</activity>
<activity android:name=".settings.KiwixSettingsActivity" />
<activity android:name=".search.SearchActivity" />
<activity android:name=".bookmark.BookmarksActivity" />
<activity android:name=".webserver.ZimHostActivity" />
<provider
android:name=".data.ZimContentProvider"
android:authorities="${applicationId}.zim.base"
android:exported="true" />
<receiver android:name=".main.KiwixSearchWidget">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
<action android:name="org.kiwix.kiwixmobile.utils.KiwixSearchWidget.TEXT_CLICKED" />
<action android:name="org.kiwix.kiwixmobile.utils.KiwixSearchWidget.ICON_CLICKED" />
<action android:name="org.kiwix.kiwixmobile.utils.KiwixSearchWidget.MIC_CLICKED" />
<action android:name="org.kiwix.kiwixmobile.utils.KiwixSearchWidget.STAR_CLICKED" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/kiwix_widget_provider_info" />
</receiver>
<service android:name=".wifi_hotspot.HotspotService" />
<activity
android:name=".error.ErrorActivity"
android:process=":error_activity" />
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>
<activity android:name=".intro.IntroActivity" />
<activity android:name=".language.LanguageActivity" />
<activity android:name=".history.HistoryActivity" />
<activity android:name=".help.HelpActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="main.MainActivity" />
</activity>
<activity
android:name=".zim_manager.local_file_transfer.LocalFileTransferActivity"
android:label="Send to nearby device"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/octet-stream" />
<data android:pathPattern=".*\\.zim" />
<data android:pathPattern=".*\\..*\\.zim" />
<data android:pathPattern=".*\\..*\\..*\\.zim" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.zim" />
<data android:host="*" />
</intent-filter>
</activity>
</application>
</manifest>

View File

@ -0,0 +1,17 @@
package org.kiwix.kiwixmobile.custom
import org.junit.Test
import org.junit.Assert.*
/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}

View File

@ -1,2 +1,3 @@
include ':core'
include ':app'
include ':custom'