Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

feat(templates): Add Android template #73

Merged
merged 10 commits into from
Jul 5, 2018
Merged
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,231 changes: 1,231 additions & 0 deletions scripts/__snapshots__/e2e-templates.test.js.snap

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions scripts/e2e-templates.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,12 @@ describe('Templates', () => {
const image = fs.readFileSync(`${templatePath}/${filePath}`);

expect(image).toMatchImageSnapshot({
customSnapshotIdentifier: `e2e-installs-${
templateConfig.templateName
}-${path.basename(filePath)}`,
customSnapshotsDir: path.resolve(
`./scripts/__image_snapshots__/${
templateConfig.templateName
}/${path.dirname(filePath)}`
),
customSnapshotIdentifier: path.basename(filePath),
});
} else {
const fileContent = fs
Expand Down
19 changes: 19 additions & 0 deletions src/tasks/android/teardown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const chalk = require('chalk');

module.exports = function teardown(config) {
if (!config.silent) {
console.log();
console.log(
`🎉 Created ${chalk.bold.cyan(config.name)} at ${chalk.green(
config.path
)}.`
);
console.log();

console.log('Begin by opening the new project.');
console.log();
console.log('⚡️ Start building something awesome!');
}

return Promise.resolve();
};
19 changes: 12 additions & 7 deletions src/tasks/common/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,28 @@ module.exports = function build(config) {
// Add the `.hbs` extension to any templating files that need
// their placeholders to get filled with `metalsmith-in-place`
rename([
// `npx` renames `.gitignore` files to `.npmignore`
// See https://github.com/algolia/create-instantsearch-app/issues/48
['.gitignore.template', '.gitignore'],
[/\.md$/, '.md.hbs'],
[/\.json$/, '.json.hbs'],
// For the web
[/\.webmanifest$/, '.webmanifest.hbs'],
[/\.html$/, '.html.hbs'],
[/\.css$/, '.css.hbs'],
[/\.js$/, '.js.hbs'],
[/\.ts$/, '.ts.hbs'],
[/\.vue$/, '.vue.hbs'],
[/\.swift$/, '.swift.hbs'],
[/\.md$/, '.md.hbs'],
[/\.json$/, '.json.hbs'],
[/\.webmanifest$/, '.webmanifest.hbs'],
// Use `.babelrc.template` as name to not trigger babel
// when requiring the file `.template.js` in end-to-end tests
// and rename it `.babelrc` afterwards
['.babelrc.template', '.babelrc'],
// `npx` renames `.gitignore` files to `.npmignore`
// See https://github.com/algolia/create-instantsearch-app/issues/48
['.gitignore.template', '.gitignore'],
['.eslintrc.js.hbs', '.eslintrc.js'],
// For iOS
[/\.swift$/, '.swift.hbs'],
// For Android
[/\.java$/, '.java.hbs'],
[/\.xml$/, '.xml.hbs'],
])
)
.use(inPlace())
Expand Down
17 changes: 17 additions & 0 deletions src/templates/InstantSearch Android/.gitignore.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# IDE Files
*.iml
.idea/*
projectFilesBackup

# Build
.gradle
/.idea/workspace.xml
/.idea/libraries
/build
/captures

# Local setup
/local.properties

# OS Files
.DS_Store
11 changes: 11 additions & 0 deletions src/templates/InstantSearch Android/.template.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const setup = require('../../tasks/ios/setup');
const install = require('../../tasks/ios/install');
const teardown = require('../../tasks/android/teardown');

module.exports = {
templateName: 'instantsearch-android',
appName: 'instantsearch-android-app',
tasks: {
teardown,
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
32 changes: 32 additions & 0 deletions src/templates/InstantSearch Android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apply plugin: 'com.android.application'

android {
dataBinding.enabled true
compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
applicationId "com.algolia.instantsearch.app"
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.algolia:instantsearch-android:1.12.0'
testImplementation 'junit:junit:4.12'
}
25 changes: 25 additions & 0 deletions src/templates/InstantSearch Android/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/pln/Library/Android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.algolia.instantsearch.app;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumentation test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();

assertEquals("com.algolia.instantsearch.app", appContext.getPackageName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.algolia.instantsearch.app"
xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.algolia.instantsearch.app;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import com.algolia.instantsearch.helpers.Searcher;
import com.algolia.instantsearch.helpers.InstantSearch;

public class MainActivity extends AppCompatActivity {
private static final String ALGOLIA_APP_ID = "{{appId}}";
private static final String ALGOLIA_SEARCH_API_KEY = "{{apiKey}}";
private static final String ALGOLIA_INDEX_NAME = "{{indexName}}";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Searcher searcher = Searcher.create(ALGOLIA_APP_ID, ALGOLIA_SEARCH_API_KEY, ALGOLIA_INDEX_NAME);
final InstantSearch helper = new InstantSearch(this, searcher);
helper.search(); // First empty search to display default results
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/activity_main"
xmlns:algolia="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.algolia.instantsearch.app.MainActivity">

<com.algolia.instantsearch.ui.views.SearchBox
android:id="@+id/search_box"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"/>

<com.algolia.instantsearch.ui.views.Hits
android:id="@+id/hits"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/search_box"
algolia:itemLayout="@layout/hits_item"/>
</RelativeLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:algolia="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:id="@+id/{{mainAttribute}}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="{{mainAttribute}}"
android:textSize="20sp"
algolia:attribute='@{"{{mainAttribute}}"}'
algolia:highlightColor="@color/colorAccent"
algolia:highlighted="@{true}"/>
</LinearLayout>
</layout>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<resources>
<string name="app_name">{{name}}</string>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.algolia.instantsearch.app;

import org.junit.Test;

import static org.junit.Assert.*;

/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
}
}
25 changes: 25 additions & 0 deletions src/templates/InstantSearch Android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
jcenter()
google()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}
17 changes: 17 additions & 0 deletions src/templates/InstantSearch Android/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Project-wide Gradle settings.

# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Tue Jul 03 16:02:11 CEST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
Loading