New UI finished, and image showing!

This commit is contained in:
ChronosX88 2019-02-08 21:49:44 +04:00
parent b987854fb2
commit d513b00711
No known key found for this signature in database
GPG Key ID: 8F92E090A87804AA
6 changed files with 57 additions and 53 deletions

Binary file not shown.

View File

@ -6,11 +6,14 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.AsyncTask;
import android.provider.MediaStore;
import android.util.Base64;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.UUID;
import ru.volgorobot.vrcatalog.additional.NetworkErrorException;
import ru.volgorobot.vrcatalog.additional.ResultWithErrorCode;
@ -60,8 +63,8 @@ public class ItemPresenter implements MainContract.ItemPresenter {
byte[] imageStream = Base64.decode(imageItem.getImage(), Base64.DEFAULT);
bitmaps.add(BitmapFactory.decodeByteArray(imageStream, 0, imageStream.length));
}
for (Bitmap bitmap : bitmaps) {
uriStrings.add(processImages(bitmap).toString());
for (int i = 0; i < bitmaps.size(); i++) {
uriStrings.add(processImages(bitmaps.get(i)).toString());
}
String[] uriStringsArray = new String[uriStrings.size()];
uriStrings.toArray(uriStringsArray);
@ -86,9 +89,18 @@ public class ItemPresenter implements MainContract.ItemPresenter {
}
private Uri processImages(Bitmap bitmap) {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
String path = MediaStore.Images.Media.insertImage(context.getContentResolver(), bitmap, "Title", null);
return Uri.parse(path);
File cacheDir = context.getCacheDir();
File cacheObject = new File(cacheDir, UUID.randomUUID().toString());
try {
FileOutputStream fileOutputStream = new FileOutputStream(cacheObject);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream);
fileOutputStream.flush();
fileOutputStream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return Uri.fromFile(cacheObject);
}
}

View File

@ -41,9 +41,11 @@ public class ImagePagerAdapter extends PagerAdapter {
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position) {
ImageView imageView = new ImageView(context);
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(313, 313);
imageView.setLayoutParams(params);
Picasso.get()
.load(imageUris[position])
.fit()
.resize(0, 313)
.centerCrop()
.into(imageView);
container.addView(imageView);

View File

@ -7,27 +7,27 @@ import android.support.v7.app.AppCompatActivity;
import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import java.util.HashMap;
import java.util.LinkedHashMap;
import ru.volgorobot.vrcatalog.ItemPresenter;
import ru.volgorobot.vrcatalog.MainContract;
import ru.volgorobot.vrcatalog.R;
import ru.volgorobot.vrcatalog.additional.ImagePagerAdapter;
import ru.volgorobot.vrcatalog.additional.PropertiesListAdapter;
public class DetailActivity extends AppCompatActivity implements MainContract.ItemView {
TextView nameView;
TextView quantityView;
TextView priceView;
TextView countryView;
TextView analogueView;
TextView datasheetView;
EditText notesView;
private MainContract.ItemPresenter mPresenter;
private ViewPager viewPager;
private ListView propertiesList;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -39,66 +39,53 @@ public class DetailActivity extends AppCompatActivity implements MainContract.It
mPresenter = new ItemPresenter(DetailActivity.this, this);
Intent intent = getIntent();
HashMap<String, String> extrasMap = getIntentExtras(intent);
((TextView) findViewById(R.id.itemName)).setText(intent.getStringExtra("detailName"));
String tmp = intent.getStringExtra("detailPrice");
if(tmp.equals("0")) {
tmp = "Уточните у продавца";
}
((TextView) findViewById(R.id.itemPrice)).setText(tmp);
nameView.setText(extrasMap.get("detailName"));
quantityView.setText(extrasMap.get("detailQuantity"));
priceView.setText(extrasMap.get("detailPrice"));
countryView.setText(extrasMap.get("detailCountry"));
analogueView.setText(extrasMap.get("detailAnalogue"));
datasheetView.setText(extrasMap.get("detailDatasheet"));
notesView.setText(extrasMap.get("detailNotes"));
mPresenter.getImagesByItemID(Integer.parseInt(extrasMap.get("itemID")));
LinkedHashMap<String, String> extrasMap = getIntentExtras(intent);
propertiesList = findViewById(R.id.propertiesList);
PropertiesListAdapter propertiesListAdapter = new PropertiesListAdapter(extrasMap);
propertiesList.setAdapter(propertiesListAdapter);
mPresenter.getImagesByItemID(Integer.parseInt(intent.getStringExtra("itemID")));
}
void initializeViews() {
nameView = findViewById(R.id.name);
quantityView = findViewById(R.id.quantity);
priceView = findViewById(R.id.price);
notesView = findViewById(R.id.notes);
countryView = findViewById(R.id.country);
analogueView = findViewById(R.id.analogue);
datasheetView = findViewById(R.id.datasheet);
datasheetView.setMovementMethod(LinkMovementMethod.getInstance());
viewPager = findViewById(R.id.viewPager);
}
HashMap<String, String> getIntentExtras(Intent intent) {
HashMap<String, String> hashMap = new HashMap<>();
LinkedHashMap<String, String> getIntentExtras(Intent intent) {
LinkedHashMap<String, String> hashMap = new LinkedHashMap<>();
String tmp;
tmp = intent.getStringExtra("detailName");
hashMap.put("detailName", tmp);
tmp = intent.getStringExtra("detailQuantity");
if(tmp.equals("0")) {
tmp = "Под заказ";
}
hashMap.put("detailQuantity", tmp);
tmp = intent.getStringExtra("detailPrice");
if(tmp.equals("0")) {
tmp = "Уточните у продавца";
}
hashMap.put("detailPrice", tmp);
hashMap.put("Количество", tmp);
tmp = intent.getStringExtra("detailCountry");
if(tmp.equals("")) {
tmp = "Не указано";
}
hashMap.put("detailCountry", tmp);
hashMap.put("Страна изготовления", tmp);
tmp = intent.getStringExtra("detailAnalogue");
if(tmp.equals("")) {
tmp = "Нет аналогов";
}
hashMap.put("detailAnalogue", tmp);
hashMap.put("Аналоги", tmp);
tmp = intent.getStringExtra("detailDatasheet");
if(!tmp.matches("\\S")) {
tmp = "Не указано";
}
hashMap.put("detailDatasheet", tmp);
hashMap.put("Техническая спецификация", tmp);
tmp = intent.getStringExtra("detailNotes");
if(tmp != null && tmp.equals("")) {
@ -106,7 +93,7 @@ public class DetailActivity extends AppCompatActivity implements MainContract.It
} else if (tmp == null){
tmp = "Нет описания";
}
hashMap.put("detailNotes", tmp);
hashMap.put("Описание", tmp);
return hashMap;
}
@ -148,4 +135,5 @@ public class DetailActivity extends AppCompatActivity implements MainContract.It
viewPager.setAdapter(imagePagerAdapter);
imagePagerAdapter.notifyDataSetChanged();
}
}

View File

@ -3,7 +3,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v4.view.ViewPager
@ -26,6 +26,8 @@
android:text="Item Price"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textSize="24sp" />
<ListView
android:id="@+id/propertiesList"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>

View File

@ -8,7 +8,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
classpath 'com.android.tools.build:gradle:3.3.1'
// NOTE: Do not place your application dependencies here; they belong