This file contains hidden or 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
val requestBody = ModelRequestBody(PayloadRequest(ModelImage(imgString))) | |
Network("https://automl.googleapis.com/v1beta1/",true).getRetrofitClient().create(Endpoint::class.java).classifyImage(requestBody).enqueue(object : Callback<PayloadResult> { | |
override fun onResponse(call: Call<PayloadResult>?, response: Response<PayloadResult>?) { | |
if (response!!.isSuccessful) { | |
result_textview.text = "${response?.body()?.items?.first()?.displayName} Score: ${(response?.body()?.items?.first()?.classification?.let { it.score * 100 })}" | |
} | |
} | |
override fun onFailure(call: Call<PayloadResult>, t: Throwable) { | |
print(t!!.message) |
This file contains hidden or 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
private fun getBytesFromBitmap(bitmap: Bitmap): ByteArray { | |
val stream = ByteArrayOutputStream() | |
bitmap.compress(CompressFormat.JPEG, 70, stream) | |
return stream.toByteArray() | |
} | |
val bitmap = MediaStore.Images.Media.getBitmap(this.contentResolver, contentURI) | |
Toast.makeText(this@MainActivity, "Image Saved!", Toast.LENGTH_SHORT).show() | |
imageView.setImageBitmap(bitmap) |
This file contains hidden or 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
fun getRetrofitClient(): Retrofit { | |
return Retrofit.Builder() | |
.baseUrl(baseUrl) | |
.client(okHttpClient) | |
.addCallAdapterFactory(CoroutineCallAdapterFactory()) | |
.addConverterFactory(gsonConverterFactory) | |
.build() | |
} |
This file contains hidden or 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
internal interface Endpoint { | |
@Headers("Content-Type: application/json") | |
@POST("projects/{ProjectName}/locations/{region}/models/{AutoML_Model_ID}:predict") | |
fun classifyImage(@Body body: ModelRequestBody): Call<PayloadResult> | |
} |
This file contains hidden or 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
data class SearchRepoResponse( | |
@field:SerializedName("total_count") | |
val totalCount: Int, | |
@field:SerializedName("incomplete_results") | |
val incompleteResults: Boolean, | |
@field:SerializedName("items") | |
val items: List<UserItem> |
This file contains hidden or 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
public class SearchResult { | |
@SerializedName("id") | |
@Expose | |
private Integer id; | |
@SerializedName("name") | |
@Expose | |
private String name; | |
@SerializedName("full_name") | |
@Expose | |
private String fullName; |
This file contains hidden or 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
override func setUp() { | |
super.setUp() | |
Resolver.reset() | |
DepedencyContainer.instance.register(depedency: ProductsRepository.self, implemenation: { | |
MockProductsRepository() | |
}) | |
} | |
func testGivenAProductTheProductsPriceWillBeFiveHundred() { | |
let expectedPrice = 100.0 |
This file contains hidden or 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
let container = DepedencyContainer.instance | |
container.register(depedency: ProductsRepository.self, implemenation: { | |
ProductsRepositoryImplementation() | |
}) |
This file contains hidden or 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
extension ProductsRepositoryInjectable { | |
var products : ProductsRepository { | |
return Resolver.resolve(dependency: ProductsRepository.self) | |
} | |
} |
NewerOlder