Skip to content

Commit

Permalink
Added no-op version of library for release builds.
Browse files Browse the repository at this point in the history
  • Loading branch information
girish3 committed Dec 2, 2020
1 parent 8f7ba12 commit 23ca823
Show file tree
Hide file tree
Showing 54 changed files with 246 additions and 25 deletions.
6 changes: 6 additions & 0 deletions .idea/copyright/mit_copyright.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/copyright/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation project(path: ':vlog')
implementation "androidx.core:core-ktx:+"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.google.android.material:material:1.2.1'

// Vlog library
implementation 'com.github.girish3:Vlog:v0.1.1'
// implementation project(path: ':library-no-op')
// implementation project(path: ':library')
}
repositories {
mavenCentral()
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ allprojects {
repositories {
google()
jcenter()

maven { url 'https://jitpack.io' }
}

apply plugin: "org.jlleitschuh.gradle.ktlint"
Expand Down
1 change: 1 addition & 0 deletions library-no-op/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
44 changes: 44 additions & 0 deletions library-no-op/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
plugins {
id 'com.android.library'
id 'kotlin-android'
}

android {
compileSdkVersion 30
buildToolsVersion "30.0.2"

defaultConfig {
minSdkVersion 19
targetSdkVersion 30
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}

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 "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
File renamed without changes.
21 changes: 21 additions & 0 deletions library-no-op/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,24 @@
package com.android.girish.vlog

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("com.android.girish.vlog_no_op.test", appContext.packageName)
}
}
5 changes: 5 additions & 0 deletions library-no-op/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.girish.vlog">

</manifest>
66 changes: 66 additions & 0 deletions library-no-op/src/main/java/com/android/girish/vlog/Vlog.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2020 Girish Budhwani
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package com.android.girish.vlog

import android.content.Context

/**
* No-op implementation.
*/
class Vlog private constructor(val mApplicationContext: Context) {

fun start() {}

fun stop() {}

fun isEnabled(): Boolean {
return false
}

fun v(tag: String, msg: String) {}

fun d(tag: String, msg: String) {}

fun i(tag: String, msg: String) {}

fun w(tag: String, msg: String) {}

fun e(tag: String, msg: String) {}

companion object {
private var instance: Vlog? = null

@JvmStatic
fun getInstance(context: Context): Vlog {
synchronized(this) {
if (instance == null) {
instance = Vlog(context)
}

return instance!!
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.android.girish.vlog

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)
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2020 Girish Budhwani
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.android.girish.vlog

import android.content.ComponentName
Expand Down Expand Up @@ -38,34 +61,15 @@ class Vlog private constructor(val mApplicationContext: Context) {
}
}

fun isEnabled(): Boolean {
return isEnabled.get()
}

private fun startService() {
mServiceIntent = Intent(mApplicationContext, VlogService::class.java)
// TODO: is there a need to pass token as an extra?
mApplicationContext.bindService(mServiceIntent, mServerConn, Context.BIND_AUTO_CREATE)
mApplicationContext.startService(mServiceIntent)
}

// TODO: pass the context once, introduce an initializer or use builder pattern.
fun start() {
if (!canDrawOverOtherApp()) {
requestDrawOverPermission()
Log.d(TAG, "Please grant Vlog permission to draw over other apps")
return
}

// Ignore if already started
if (isEnabled.getAndSet(true)) {
Log.d(TAG, "Vlog is already started")
return
}
Log.d(TAG, "Initializing Vlog")
startService()

// initialize other resources if any
fun isEnabled(): Boolean {
return isEnabled.get()
}

private fun requestDrawOverPermission() {
Expand All @@ -90,6 +94,25 @@ class Vlog private constructor(val mApplicationContext: Context) {
mVlogRepository.feedLog(model)
}

// TODO: pass the context once, introduce an initializer or use builder pattern.
fun start() {
if (!canDrawOverOtherApp()) {
requestDrawOverPermission()
Log.d(TAG, "Please grant Vlog permission to draw over other apps")
return
}

// Ignore if already started
if (isEnabled.getAndSet(true)) {
Log.d(TAG, "Vlog is already started")
return
}
Log.d(TAG, "Initializing Vlog")
startService()

// initialize other resources if any
}

fun stop() {
if (!isEnabled.get()) {
Log.d(TAG, "Vlog is not started, cannot stop")
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 2 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
include ':app', ':vlog'
include ':library-no-op'
include ':app', ':library'
rootProject.name='VlogSample'

0 comments on commit 23ca823

Please sign in to comment.