Skip to content

Conversation

@falsefox13
Copy link
Owner

Implemented posting of new goods and uploading images to them.

Copy link

@nvipash nvipash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First review of Laboratory work #4

Comment on lines +153 to +182
boolean valid = true;
if (Utils.validateString(title)) {
titleField.setError(null);
} else {
titleField.setError(getString(R.string.title_error));
valid = false;
}

if (Utils.validateString(place)) {
placeField.setError(null);
} else {
placeField.setError(getString(R.string.place_error));
valid = false;
}

if (!date.isEmpty()) {
dateField.setError(null);
} else {
dateField.setError(getString(R.string.date_error));
valid = false;
}

if (Utils.validatePrice(price)) {
priceField.setError(null);
} else {
priceField.setError(getString(R.string.price_error));
valid = false;
}

return valid;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

завеликий методи виходить, варто розбити на менші валідатори

Comment on lines 199 to 233
private class UploadImageTask extends AsyncTask<Uri, Void, Void> {
protected void onPreExecute() {
progressBar.setVisibility(View.VISIBLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
}

protected Void doInBackground(Uri... blobName) {
ServiceAccountCredentials credentials;
try {
credentials = ServiceAccountCredentials.fromStream(getResources().openRawResource(R.raw.bowlingsite));
Storage storage = StorageOptions.newBuilder().setProjectId("bowlingsite")
.setCredentials(credentials)
.build()
.getService();
final Bucket bucket = storage.get("www.bowling-iot.pp.ua");
final String imgPath = "img/" + blobName[0].getLastPathSegment() + "." + getFileExtension(blobName[0]);
final BlobId blobId = BlobId.of(bucket.getName(), imgPath);
final InputStream imageStream = getContentResolver().openInputStream(blobName[0]);
final BlobInfo blobInfo = BlobInfo.newBuilder(blobId).setContentType("image/jpeg").build();
final Blob blob = storage.create(blobInfo, imageStream);
imgDownloadLink = blob.getMediaLink();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}

@Override
protected void onPostExecute(Void result) {
showImage(imgDownloadLink);
progressBar.setVisibility(View.INVISIBLE);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

цей клас варто винести в окремий файл

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

трохи не розумію цілі винесення - цей клас використовує багато полів і методів класу в якому знаходиться і використання в його для інших класів не буде потрібно

Comment on lines +95 to +116
if (!validate(title, place, date, price)) {
return;
}
final GoodsService service = getApplicationEx().getApiService();
Good good = new Good(title, place, date, price, imgPath);
Call<Good> call = service.addGood(good);
progressBar.setVisibility(View.VISIBLE);
call.enqueue(new Callback<Good>() {
@Override
public void onResponse(Call<Good> call, Response<Good> response) {
progressBar.setVisibility(View.INVISIBLE);
if (response.isSuccessful()) {
openMainActivity();
}
}

@Override
public void onFailure(Call<Good> call, Throwable t) {
progressBar.setVisibility(View.INVISIBLE);
Snackbar.make(findViewById(R.id.item_view), R.string.post_failed, Snackbar.LENGTH_LONG).show();
}
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

цей метод троошки великий, треба подумати, якусь частину виокремити

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

чесно кажучи, не знайшла способу розділити цей метод. на мою думку 20 стрічок це не критично.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants