-
Notifications
You must be signed in to change notification settings - Fork 0
Added code of milestone4 #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
nvipash
left a comment
There was a problem hiding this 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
| 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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
завеликий методи виходить, варто розбити на менші валідатори
| 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); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
цей клас варто винести в окремий файл
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
трохи не розумію цілі винесення - цей клас використовує багато полів і методів класу в якому знаходиться і використання в його для інших класів не буде потрібно
| 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(); | ||
| } | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
цей метод троошки великий, треба подумати, якусь частину виокремити
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
чесно кажучи, не знайшла способу розділити цей метод. на мою думку 20 стрічок це не критично.
Implemented posting of new goods and uploading images to them.