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.graphics.BitmapFactory;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.provider.MediaStore;
import android.util.Base64; 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.ArrayList;
import java.util.UUID;
import ru.volgorobot.vrcatalog.additional.NetworkErrorException; import ru.volgorobot.vrcatalog.additional.NetworkErrorException;
import ru.volgorobot.vrcatalog.additional.ResultWithErrorCode; import ru.volgorobot.vrcatalog.additional.ResultWithErrorCode;
@ -60,8 +63,8 @@ public class ItemPresenter implements MainContract.ItemPresenter {
byte[] imageStream = Base64.decode(imageItem.getImage(), Base64.DEFAULT); byte[] imageStream = Base64.decode(imageItem.getImage(), Base64.DEFAULT);
bitmaps.add(BitmapFactory.decodeByteArray(imageStream, 0, imageStream.length)); bitmaps.add(BitmapFactory.decodeByteArray(imageStream, 0, imageStream.length));
} }
for (Bitmap bitmap : bitmaps) { for (int i = 0; i < bitmaps.size(); i++) {
uriStrings.add(processImages(bitmap).toString()); uriStrings.add(processImages(bitmaps.get(i)).toString());
} }
String[] uriStringsArray = new String[uriStrings.size()]; String[] uriStringsArray = new String[uriStrings.size()];
uriStrings.toArray(uriStringsArray); uriStrings.toArray(uriStringsArray);
@ -86,9 +89,18 @@ public class ItemPresenter implements MainContract.ItemPresenter {
} }
private Uri processImages(Bitmap bitmap) { private Uri processImages(Bitmap bitmap) {
ByteArrayOutputStream bytes = new ByteArrayOutputStream(); File cacheDir = context.getCacheDir();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes); File cacheObject = new File(cacheDir, UUID.randomUUID().toString());
String path = MediaStore.Images.Media.insertImage(context.getContentResolver(), bitmap, "Title", null); try {
return Uri.parse(path); 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 @Override
public Object instantiateItem(@NonNull ViewGroup container, int position) { public Object instantiateItem(@NonNull ViewGroup container, int position) {
ImageView imageView = new ImageView(context); ImageView imageView = new ImageView(context);
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(313, 313);
imageView.setLayoutParams(params);
Picasso.get() Picasso.get()
.load(imageUris[position]) .load(imageUris[position])
.fit() .resize(0, 313)
.centerCrop() .centerCrop()
.into(imageView); .into(imageView);
container.addView(imageView); container.addView(imageView);

View File

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

View File

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

View File

@ -8,7 +8,7 @@ buildscript {
mavenCentral() mavenCentral()
} }
dependencies { 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 // NOTE: Do not place your application dependencies here; they belong