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 #51 from iZettle/feature/wrench_core_java
Browse files Browse the repository at this point in the history
Revert wrench-core into pure java
  • Loading branch information
warting authored Apr 20, 2018
2 parents 7780d63 + d1e00e6 commit af0f2f0
Show file tree
Hide file tree
Showing 16 changed files with 229 additions and 172 deletions.
4 changes: 2 additions & 2 deletions wrench-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ android {
dependencies {
testImplementation 'junit:junit:4.12'

androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2-alpha1'
androidTestImplementation 'com.android.support.test:runner:1.0.2-alpha1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2-beta1'
androidTestImplementation 'com.android.support.test:runner:1.0.2-beta1'
androidTestImplementation 'android.arch.persistence.room:testing:1.1.0-beta2'

annotationProcessor "android.arch.lifecycle:compiler:1.1.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,6 @@ private Nut getNut(String value) {
}

private Bolt getBolt(String key) {
return new Bolt(0, "bolttype", key, "boltvalue");
return new Bolt(0L, "bolttype", key, "boltvalue");
}
}
6 changes: 1 addition & 5 deletions wrench-core/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 27

defaultConfig {
minSdkVersion 15
minSdkVersion 1
targetSdkVersion 27
versionCode 1
versionName "1.0"

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

Expand Down Expand Up @@ -43,7 +40,6 @@ android {
dependencies {
testImplementation 'junit:junit:4.12'
implementation 'com.android.support:support-annotations:27.1.1'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
}

apply from: rootProject.file('gradle/gradle-mvn-push.gradle')
Expand Down
123 changes: 123 additions & 0 deletions wrench-core/src/main/java/com/izettle/wrench/core/Bolt.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package com.izettle.wrench.core;

import android.content.ContentValues;
import android.database.Cursor;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StringDef;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

public class Bolt {
@NonNull
@BoltType
private final String type;
@NonNull
private final String key;
@Nullable
private final String value;
private long id;

public Bolt(Long id, @NonNull String type, @NonNull String key, @Nullable String value) {
this.id = id;
this.type = type;
this.key = key;
this.value = value;
}

public Bolt() {
type = "";
key = "";
value = null;
}

public static Bolt fromContentValues(ContentValues values) {
Long id = values.getAsLong(ColumnNames.Bolt.COL_ID);
@BoltType
String type = values.getAsString(ColumnNames.Bolt.COL_TYPE);
String key = values.getAsString(ColumnNames.Bolt.COL_KEY);
String value = values.getAsString(ColumnNames.Bolt.COL_VALUE);

return new Bolt(id, type, key, value);
}

public static Bolt fromCursor(Cursor cursor) {
long id = getNullsafeLong(cursor, ColumnNames.Bolt.COL_ID);
@BoltType
String type = getNullsafeString(cursor, ColumnNames.Bolt.COL_TYPE);
String key = getNullsafeString(cursor, ColumnNames.Bolt.COL_KEY);
String value = cursor.getString(cursor.getColumnIndexOrThrow(ColumnNames.Bolt.COL_VALUE));

return new Bolt(id, type, key, value);
}

@NonNull
private static Long getNullsafeLong(Cursor cursor, String columnName) {
int columnIndex = cursor.getColumnIndexOrThrow(columnName);
if (cursor.isNull(columnIndex)) {
throw new IllegalStateException(columnName + " was null");
}
return cursor.getLong(columnIndex);
}

@NonNull
private static String getNullsafeString(Cursor cursor, String columnName) {
int columnIndex = cursor.getColumnIndexOrThrow(columnName);
if (cursor.isNull(columnIndex)) {
throw new IllegalStateException(columnName + " was null");
}
return cursor.getString(columnIndex);
}

@NonNull
public String getKey() {
return key;
}

@NonNull
public String getType() {
return type;
}

@Nullable
public String getValue() {
return value;
}

public ContentValues toContentValues() {
ContentValues contentValues = new ContentValues();

contentValues.put(ColumnNames.Bolt.COL_ID, id);
contentValues.put(ColumnNames.Bolt.COL_KEY, key);
contentValues.put(ColumnNames.Bolt.COL_VALUE, value);
contentValues.put(ColumnNames.Bolt.COL_TYPE, type);

return contentValues;
}

public Long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}

@NonNull
public Bolt copy(Long id, String type, String key, String value) {
return new Bolt(id, type, key, value);
}

@Retention(RetentionPolicy.SOURCE)
@StringDef({TYPE.BOOLEAN, TYPE.STRING, TYPE.INTEGER, TYPE.ENUM})
public @interface BoltType {
}

public interface TYPE {
String BOOLEAN = "boolean";
String STRING = "string";
String INTEGER = "integer";
String ENUM = "enum";
}
}
70 changes: 0 additions & 70 deletions wrench-core/src/main/java/com/izettle/wrench/core/Bolt.kt

This file was deleted.

16 changes: 16 additions & 0 deletions wrench-core/src/main/java/com/izettle/wrench/core/ColumnNames.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.izettle.wrench.core;

public final class ColumnNames {
public interface Bolt {
String COL_KEY = "configurationKey";
String COL_ID = "id";
String COL_VALUE = "value";
String COL_TYPE = "configurationType";
}

public interface Nut {
String COL_ID = "id";
String COL_VALUE = "value";
String COL_CONFIG_ID = "configurationId";
}
}
16 changes: 0 additions & 16 deletions wrench-core/src/main/java/com/izettle/wrench/core/ColumnNames.kt

This file was deleted.

33 changes: 33 additions & 0 deletions wrench-core/src/main/java/com/izettle/wrench/core/Nut.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.izettle.wrench.core;

import android.content.ContentValues;

public class Nut {
private final long id;
private final long configurationId;
private final String value;

public Nut(long configurationId, String value) {
this.id = 0;
this.configurationId = configurationId;
this.value = value;
}

public Nut(long id, long configurationId, String value) {
this.id = id;
this.configurationId = configurationId;
this.value = value;
}

public ContentValues toContentValues() {
ContentValues contentValues = new ContentValues();
if (id > 0) {
contentValues.put(ColumnNames.Nut.COL_ID, id);
}

contentValues.put(ColumnNames.Nut.COL_CONFIG_ID, configurationId);
contentValues.put(ColumnNames.Nut.COL_VALUE, value);

return contentValues;
}
}
21 changes: 0 additions & 21 deletions wrench-core/src/main/java/com/izettle/wrench/core/Nut.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.izettle.wrench.core;

import android.net.Uri;

public final class WrenchProviderContract {
public static final String WRENCH_AUTHORITY = BuildConfig.WRENCH_AUTHORITY;

public static final String WRENCH_API_VERSION = "API_VERSION";

private static Uri boltUri = Uri.parse("content://" + WRENCH_AUTHORITY + "/currentConfiguration");
private static Uri nutUri = Uri.parse("content://" + WRENCH_AUTHORITY + "/predefinedConfigurationValue");

public static Uri boltUri(long id) {
return boltUri
.buildUpon()
.appendPath(String.valueOf(id))
.appendQueryParameter(WRENCH_API_VERSION, String.valueOf(BuildConfig.WRENCH_API_VERSION))
.build();
}

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

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

public static Uri nutUri() {
return nutUri
.buildUpon()
.appendQueryParameter(WRENCH_API_VERSION, String.valueOf(BuildConfig.WRENCH_API_VERSION))
.build();
}
}
Loading

0 comments on commit af0f2f0

Please sign in to comment.