This repository has been archived by the owner on May 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from iZettle/feature/wrench_core_java
Revert wrench-core into pure java
- Loading branch information
Showing
16 changed files
with
229 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
wrench-core/src/main/java/com/izettle/wrench/core/Bolt.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
wrench-core/src/main/java/com/izettle/wrench/core/ColumnNames.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
16
wrench-core/src/main/java/com/izettle/wrench/core/ColumnNames.kt
This file was deleted.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
wrench-core/src/main/java/com/izettle/wrench/core/Nut.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
42 changes: 42 additions & 0 deletions
42
wrench-core/src/main/java/com/izettle/wrench/core/WrenchProviderContract.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Oops, something went wrong.