Skip to content

Commit

Permalink
Add navigation, navigation-debug and reflect modules (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
mirland authored May 26, 2020
1 parent 05502c4 commit 1444baa
Show file tree
Hide file tree
Showing 86 changed files with 2,601 additions and 1 deletion.
613 changes: 613 additions & 0 deletions .detekt/detekt-config.yml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @xmartlabs/android-open-source
33 changes: 33 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## :link: Github Issue reference:
<!---
If the pr fix an existing issue you should put it here:
Fixes: #issue-number
-->


## Description:

<!---
Add a description of the feature or bug you are tackling. First in high level perspective and then you can describe your solution. Include acceptance criteria, diagrams of the code, or anything else you consider that might help other developers understand your decisions.
-->


## :camera_flash: UI preview

<!--- Add a GIF or screenshot -->


## :pushpin: Notes:

<!---
* Include pending tasks, TODOs, assumptions, or comments like 'Needs migrating'
-->


## :warning: Warnings:

<!---
* Include a list of considerations for reviewers or future developers. For example:
* The feature in production triggers a service call so it will charge the account credit card
* The service X is mocked so this part is not tested
-->
48 changes: 48 additions & 0 deletions .github/workflows/check_and_compile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Check and compile
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Cache gradle cache
uses: actions/[email protected]
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Cache gradle wrapper
uses: actions/[email protected]
with:
path: ~/.gradle/wrapper
key: ${{ runner.os }}-gradlewrapper-${{ hashFiles('**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradlegradlewrapper-
- name: Cache android cache
uses: actions/[email protected]
with:
path: ~/.android/build-cache
key: ${{ runner.os }}-android-cache
restore-keys: |
${{ runner.os }}-gradlegradlewrapper-
- name: Gradle Initialization
run: ./gradlew
- name: Detekt
run: ./gradlew detekt
- name: Upload Detekt report
uses: actions/upload-artifact@v1
if: failure()
with:
name: Detekt report
path: build/reports/detekt/detekt.html
- name: Android Lints
run: ./gradlew lint
- name: Upload Lint report
uses: actions/upload-artifact@v1
if: failure()
with:
name: Lints report
path: app/build/reports/lint-results-devDebug.html
- name: Build
run: ./gradlew build
39 changes: 39 additions & 0 deletions .github/workflows/test_master_dependencies.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Check master Jitpack's dependency
on:
push:
branches:
- master
jobs:
check_jitpack_master_build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Cache gradle cache
uses: actions/[email protected]
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Cache gradle wrapper
uses: actions/[email protected]
with:
path: ~/.gradle/wrapper
key: ${{ runner.os }}-gradlewrapper-${{ hashFiles('**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradlegradlewrapper-
- name: Cache android cache
uses: actions/[email protected]
with:
path: ~/.android/build-cache
key: ${{ runner.os }}-android-cache
restore-keys: |
${{ runner.os }}-gradlegradlewrapper-
- name: Use master dependencies in app
run: |
perl -i -pe "s/project\(\"\:core\"\)/\"com.github.xmartlabs.AndroidSwissKnife:core:master-SNAPSHOT\"/gi" app/build.gradle
perl -i -pe "s/project\(\"\:navigation\"\)/\"com.github.xmartlabs.AndroidSwissKnife:navigation:master-SNAPSHOT\"/gi" app/build.gradle
perl -i -pe "s/project\(\"\:navigation-debug\"\)/\"com.github.xmartlabs.AndroidSwissKnife:navigation-debug:master-SNAPSHOT\"/gi" app/build.gradle
perl -i -pe "s/project\(\"\:reflection\"\)/\"com.github.xmartlabs.AndroidSwissKnife:reflection:master-SNAPSHOT\"/gi" app/build.gradle
- name: Build Sample app with master dependencies
run: ./gradlew build -Dhttp.socketTimeout=80000 -Dhttp.connectionTimeout=80000 --refresh-dependencies
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
*.iml
*/obj
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild
.idea
build
/reports
/secrets
34 changes: 33 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,33 @@
# AndroidSwissKnife
# AndroidSwissKnife
![Check and compile](https://github.com/xmartlabs/AndroidSwissKnife/workflows/Check%20and%20compile/badge.svg)
![Check and compile](https://github.com/xmartlabs/AndroidSwissKnife/workflows/Check%20and%20compile/badge.svg?branch=master)
[![Release](https://jitpack.io/v/xmartlabs/AndroidSwissKnife.svg)](https://jitpack.io/#xmartlabs/AndroidSwissKnife)

A library that contains a series of extensions, helpers, and useful classes used in most of [Xmartlabs' Android Projects](https://www.xmartlabs.com/).

It's divided into a series of modules with different proposes:
- [Core](/core): Core extensions of the application, for example view's and resource's extensions.
- [Navigation](/navigation): Navigation extensions and useful helper classes related to [Navigation Architecture Component].
- [Navigation-debug](/navigation-debug): A series of extensions and useful tools to debug and log important information of the [Navigation Architecture Component].
- [Reflection](/reflection): A series of extensions useful when you are dealing with Reflection.

## Setup
Add library to project dependencies with JitPack.

```groovy
repositories {
maven { url "https://jitpack.io" }
}
dependencies {
implementation "com.github.xmartlabs.AndroidSwissKnife:core:${master-latest-hash-commit}"
implementation "com.github.xmartlabs.AndroidSwissKnife:navigation:${master-latest-hash-commit}"
implementation "com.github.xmartlabs.AndroidSwissKnife:navigation-debug:${master-latest-hash-commit}"
implementation "com.github.xmartlabs.AndroidSwissKnife:reflection:${master-latest-hash-commit}"
}
```

## About
Made with ❤️ by [XMARTLABS](http://xmartlabs.com)

[Navigation Architecture Component]: https://developer.android.com/guide/navigation/navigation-getting-started
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
52 changes: 52 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion androidVersions.compileSdk
buildToolsVersion androidVersions.buildTools

defaultConfig {
applicationId "com.xmartlabs.swissknife.sample"
minSdkVersion androidVersions.minSdk
targetSdkVersion androidVersions.targetSdk
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}

dependencies {
implementation project(":core")
implementation project(":navigation")
implementation project(":navigation-debug")
implementation project(":reflection")

implementation deps.androidX.appcompat
implementation deps.androidX.constraintLayout
implementation deps.androidX.core
implementation deps.androidX.navigation.fragment
implementation deps.androidX.navigation.ui
implementation deps.kotlin.core
implementation deps.material
implementation deps.timber

testImplementation deps.junit
androidTestImplementation deps.androidX.test.junit
androidTestImplementation deps.androidX.test.espresso
}
21 changes: 21 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.xmartlabs.swissknife.sample

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith

/**
* 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("com.xmartlabs.swissknife.sample", appContext.packageName)
}
}
28 changes: 28 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xmartlabs.swissknife.sample"
>

<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"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

</manifest>
21 changes: 21 additions & 0 deletions app/src/main/java/com/xmartlabs/swissknife/sample/FirstFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.xmartlabs.swissknife.sample

import android.os.Bundle
import android.view.View
import android.widget.Button
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import com.xmartlabs.swissknife.navigation.navigateSafe

/**
* A simple [Fragment] subclass as the default destination in the navigation.
*/
class FirstFragment : Fragment(R.layout.fragment_first) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

view.findViewById<Button>(R.id.button_first).setOnClickListener {
findNavController().navigateSafe(R.id.action_FirstFragment_to_SecondFragment)
}
}
}
33 changes: 33 additions & 0 deletions app/src/main/java/com/xmartlabs/swissknife/sample/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.xmartlabs.swissknife.sample

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.findNavController
import com.google.android.material.snackbar.Snackbar
import com.xmartlabs.swissknife.core.Logger
import com.xmartlabs.swissknife.navigationdebug.setupOnDestinationChangedLogger
import kotlinx.android.synthetic.main.activity_main.*
import timber.log.Timber

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setSupportActionBar(toolbar)
setupTimber()

findNavController(R.id.nav_host_fragment)
.setupOnDestinationChangedLogger(object : Logger {
override fun log(message: String) = Timber
.tag("Nav-Path")
.d(message)
})

fab.setOnClickListener { view ->
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show()
}
}

private fun setupTimber() = Timber.plant(Timber.DebugTree())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.xmartlabs.swissknife.sample

import android.os.Bundle
import android.view.View
import android.widget.Button
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import com.xmartlabs.swissknife.navigation.navigateSafe

/**
* A simple [Fragment] subclass as the second destination in the navigation.
*/
class SecondFragment : Fragment(R.layout.fragment_second) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

view.findViewById<Button>(R.id.button_second).setOnClickListener {
findNavController().navigateSafe(R.id.action_SecondFragment_to_FirstFragment)
}
}
}
Loading

0 comments on commit 1444baa

Please sign in to comment.