Skip to content
This repository has been archived by the owner on May 8, 2023. It is now read-only.

Commit

Permalink
Merge pull request #52 from iZettle/feature/remove_kotin_from_wrench_…
Browse files Browse the repository at this point in the history
…prefs

Feature/remove kotin from wrench prefs
  • Loading branch information
warting authored Apr 23, 2018
2 parents af0f2f0 + 1b4c583 commit 36281f1
Show file tree
Hide file tree
Showing 25 changed files with 317 additions and 201 deletions.
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include ':wrench-app', ':wrench-prefs', ':wrench-sample', ':wrench-prefs-no-op', ':wrench-service', ':wrench-core'
include ':wrench-app', ':wrench-prefs', ':wrench-sample', ':wrench-prefs-no-op', ':wrench-service', ':wrench-core', ':wrench-livedata'
44 changes: 0 additions & 44 deletions wrench-app/lint-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,48 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<issues format="4" by="lint 3.1.0-alpha04">

<issue
id="CheckResult"
message="The result of `inject` is not used"
errorLine1=" AndroidInjection.inject(activity);"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/com/izettle/wrench/di/AppInjector.java"
line="86"
column="13"/>
</issue>

<issue
id="CheckResult"
message="The result of `inject` is not used"
errorLine1=" AndroidSupportInjection.inject(f);"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/com/izettle/wrench/di/AppInjector.java"
line="96"
column="41"/>
</issue>

<issue
id="CheckResult"
message="The result of `onCreate` is not used"
errorLine1=" super.onCreate();"
errorLine2=" ~~~~~~~~~~~~~~~~">
<location
file="src/main/java/com/izettle/wrench/WrenchApplication.java"
line="14"
column="9"/>
</issue>

<issue
id="CheckResult"
message="The result of `inject` is not used"
errorLine1=" AndroidInjection.inject(this);"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/com/izettle/wrench/provider/WrenchProvider.java"
line="139"
column="13"/>
</issue>

</issues>
2 changes: 1 addition & 1 deletion wrench-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ android {
compileSdkVersion 27

defaultConfig {
minSdkVersion 1
minSdkVersion 14
targetSdkVersion 27

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class Bolt {
private final String value;
private long id;

public Bolt(Long id, @NonNull String type, @NonNull String key, @Nullable String value) {
public Bolt(long id, @NonNull String type, @NonNull String key, @Nullable String value) {
this.id = id;
this.type = type;
this.key = key;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.izettle.wrench.core;

import android.net.Uri;
import android.support.annotation.NonNull;

public final class WrenchProviderContract {
public static final String WRENCH_AUTHORITY = BuildConfig.WRENCH_AUTHORITY;
Expand All @@ -10,6 +11,7 @@ public final class WrenchProviderContract {
private static Uri boltUri = Uri.parse("content://" + WRENCH_AUTHORITY + "/currentConfiguration");
private static Uri nutUri = Uri.parse("content://" + WRENCH_AUTHORITY + "/predefinedConfigurationValue");

@NonNull
public static Uri boltUri(long id) {
return boltUri
.buildUpon()
Expand All @@ -18,6 +20,7 @@ public static Uri boltUri(long id) {
.build();
}

@NonNull
public static Uri boltUri(String key) {
return boltUri
.buildUpon()
Expand All @@ -26,13 +29,15 @@ public static Uri boltUri(String key) {
.build();
}

@NonNull
public static Uri boltUri() {
return boltUri
.buildUpon()
.appendQueryParameter(WRENCH_API_VERSION, String.valueOf(BuildConfig.WRENCH_API_VERSION))
.build();
}

@NonNull
public static Uri nutUri() {
return nutUri
.buildUpon()
Expand Down
1 change: 1 addition & 0 deletions wrench-livedata/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
36 changes: 36 additions & 0 deletions wrench-livedata/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 27

defaultConfig {
minSdkVersion 14
targetSdkVersion 27

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
baseline file("lint-baseline.xml")
checkReleaseBuilds true
abortOnError true
warningsAsErrors true
lintConfig file("../lint.xml")
}
}

dependencies {
testImplementation 'junit:junit:4.12'
implementation project(":wrench-core")
implementation 'com.android.support:support-annotations:27.1.1'
api 'android.arch.lifecycle:livedata-core:1.1.1'
}

// The api of this module should be discussed before any potential release
// apply from: rootProject.file('gradle/gradle-mvn-push.gradle')
4 changes: 4 additions & 0 deletions wrench-livedata/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# These names should be discussed before any potential release.
# POM_ARTIFACT_ID=wrench-livedata
#POM_NAME=Wrench LiveData
#POM_PACKAGING=aar
4 changes: 4 additions & 0 deletions wrench-livedata/lint-baseline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<issues by="lint 3.2.0-alpha11" format="4">

</issues>
21 changes: 21 additions & 0 deletions wrench-livedata/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
5 changes: 5 additions & 0 deletions wrench-livedata/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.izettle.wrench.livedata">

<uses-permission android:name="com.izettle.wrench.permission" />
</manifest>
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
package com.example.wrench.BoltLiveData;
package com.izettle.wrench.livedata;

import android.content.Context;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.izettle.wrench.core.Bolt;
import com.izettle.wrench.core.WrenchProviderContract;

class WrenchBooleanLiveData extends WrenchLiveData<Boolean> {
private final boolean defValue;

WrenchBooleanLiveData(Context context, String key, boolean defValue) {
WrenchBooleanLiveData(@NonNull Context context, @NonNull String key, boolean defValue) {
super(context, key, Bolt.TYPE.BOOLEAN);

this.defValue = defValue;
}

@Override
void boltChanged(Bolt bolt) {
void boltChanged(@Nullable Bolt bolt) {
if (bolt == null) {
setValue(defValue);
return;
Expand All @@ -25,6 +27,9 @@ void boltChanged(Bolt bolt) {
if (bolt.getId() == 0) {
bolt = bolt.copy(bolt.getId(), getType(), getKey(), String.valueOf(defValue));
Uri uri = getContext().getContentResolver().insert(WrenchProviderContract.boltUri(), bolt.toContentValues());
if (uri == null) {
throw new IllegalStateException("uri was null after insert");
}
bolt.setId(Long.parseLong(uri.getLastPathSegment()));
}
setValue(Boolean.valueOf(bolt.getValue()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
package com.example.wrench.BoltLiveData;
package com.izettle.wrench.livedata;

import android.content.Context;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.izettle.wrench.core.Bolt;
import com.izettle.wrench.core.Nut;
import com.izettle.wrench.core.WrenchProviderContract;

import java.util.Objects;

class WrenchEnumLiveData<T extends Enum<T>> extends WrenchLiveData<T> {
@NonNull
private final Class<T> enumClass;
@NonNull
private final T defValue;

WrenchEnumLiveData(Context context, String key, Class<T> enumClass, T defValue) {
WrenchEnumLiveData(@NonNull Context context, @NonNull String key, @NonNull Class<T> enumClass, @NonNull T defValue) {
super(context, key, Bolt.TYPE.ENUM);
this.enumClass = enumClass;
this.defValue = defValue;
}

private Uri insertBolt(Bolt bolt) {
@Nullable
private Uri insertBolt(@NonNull Bolt bolt) {
return getContext().getContentResolver().insert(WrenchProviderContract.boltUri(), bolt.toContentValues());
}

private void insertNut(Nut nut) {
private void insertNut(@NonNull Nut nut) {
getContext().getContentResolver().insert(WrenchProviderContract.nutUri(), nut.toContentValues());
}

@Override
void boltChanged(Bolt bolt) {
void boltChanged(@Nullable Bolt bolt) {
if (bolt == null) {
setValue(defValue);
return;
Expand All @@ -37,13 +40,19 @@ void boltChanged(Bolt bolt) {
if (bolt.getId() == 0) {
bolt = bolt.copy(bolt.getId(), getType(), getKey(), String.valueOf(defValue));
Uri uri = insertBolt(bolt);
if (uri == null) {
throw new IllegalStateException("uri was null after insert");
}
bolt.setId(Long.parseLong(uri.getLastPathSegment()));

for (T t : enumClass.getEnumConstants()) {
insertNut(new Nut(bolt.getId(), t.toString()));
}
}

setValue(Enum.valueOf(enumClass, Objects.requireNonNull(bolt.getValue())));
if (bolt.getValue() == null) {
throw new IllegalStateException("bolt value cannot be null for enum");
}
setValue(Enum.valueOf(enumClass, bolt.getValue()));
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
package com.example.wrench.BoltLiveData;
package com.izettle.wrench.livedata;

import android.content.Context;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.izettle.wrench.core.Bolt;
import com.izettle.wrench.core.WrenchProviderContract;

class WrenchIntLiveData extends WrenchLiveData<Integer> {
private final int defValue;

WrenchIntLiveData(Context context, String key, int defValue) {
WrenchIntLiveData(@NonNull Context context, @NonNull String key, int defValue) {
super(context, key, Bolt.TYPE.INTEGER);

this.defValue = defValue;
}

@Override
void boltChanged(Bolt bolt) {
void boltChanged(@Nullable Bolt bolt) {
if (bolt == null) {
setValue(defValue);
return;
Expand All @@ -25,6 +27,9 @@ void boltChanged(Bolt bolt) {
if (bolt.getId() == 0) {
bolt = bolt.copy(bolt.getId(), getType(), getKey(), String.valueOf(defValue));
Uri uri = getContext().getContentResolver().insert(WrenchProviderContract.boltUri(), bolt.toContentValues());
if (uri == null) {
throw new IllegalStateException("uri was null after insert");
}
bolt.setId(Long.parseLong(uri.getLastPathSegment()));
}
setValue(Integer.valueOf(bolt.getValue()));
Expand Down
Loading

0 comments on commit 36281f1

Please sign in to comment.