Obtaining intent extras is wrapped in a function that returns an associative array.
This commit is contained in:
parent
cc1c55c30b
commit
bafcb5dc14
@ -8,6 +8,9 @@ import android.view.MenuItem;
|
|||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import ru.volgorobot.vrcatalog.R;
|
import ru.volgorobot.vrcatalog.R;
|
||||||
|
|
||||||
public class DetailActivity extends AppCompatActivity {
|
public class DetailActivity extends AppCompatActivity {
|
||||||
@ -29,13 +32,15 @@ public class DetailActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
|
|
||||||
nameView.setText(intent.getStringExtra("detailName"));
|
HashMap<String, String> extrasMap = getIntentExtras(intent);
|
||||||
quantityView.setText(intent.getStringExtra("detailQuantity").equals("0") ? "Нет на складе" : intent.getStringExtra("detailQuantity"));
|
|
||||||
priceView.setText(intent.getStringExtra("detailPrice"));
|
nameView.setText(extrasMap.get("detailName"));
|
||||||
countryView.setText(intent.getStringExtra("detailCountry"));
|
quantityView.setText(extrasMap.get("detailQuantity"));
|
||||||
analogueView.setText(intent.getStringExtra("detailAnalogue").equals("") ? "Нет аналогов" : intent.getStringExtra("detailAnalogue"));
|
priceView.setText(extrasMap.get("detailPrice"));
|
||||||
datasheetView.setText(intent.getStringExtra("detailDatasheet").equals(" ") ? "Нет" : intent.getStringExtra("detailDatasheet"));
|
countryView.setText(extrasMap.get("detailCountry"));
|
||||||
notesView.setText(intent.getStringExtra("detailNotes").equals("") ? "Нет описания" : intent.getStringExtra("detailNotes"));
|
analogueView.setText(extrasMap.get("detailAnalogue"));
|
||||||
|
datasheetView.setText(extrasMap.get("detailDatasheet"));
|
||||||
|
notesView.setText(extrasMap.get("detailNotes"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void initializeViews() {
|
void initializeViews() {
|
||||||
@ -49,6 +54,54 @@ public class DetailActivity extends AppCompatActivity {
|
|||||||
datasheetView.setMovementMethod(LinkMovementMethod.getInstance());
|
datasheetView.setMovementMethod(LinkMovementMethod.getInstance());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HashMap<String, String> getIntentExtras(Intent intent) {
|
||||||
|
HashMap<String, String> hashMap = new HashMap<>();
|
||||||
|
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);
|
||||||
|
|
||||||
|
tmp = intent.getStringExtra("detailCountry");
|
||||||
|
if(tmp.equals("")) {
|
||||||
|
tmp = "Не указано";
|
||||||
|
}
|
||||||
|
hashMap.put("detailCountry", tmp);
|
||||||
|
|
||||||
|
tmp = intent.getStringExtra("detailAnalogue");
|
||||||
|
if(tmp.equals("")) {
|
||||||
|
tmp = "Нет аналогов";
|
||||||
|
}
|
||||||
|
hashMap.put("detailAnalogue", tmp);
|
||||||
|
|
||||||
|
tmp = intent.getStringExtra("detailDatasheet");
|
||||||
|
if(!tmp.matches("\\S")) {
|
||||||
|
tmp = "Не указано";
|
||||||
|
}
|
||||||
|
hashMap.put("detailDatasheet", tmp);
|
||||||
|
|
||||||
|
tmp = intent.getStringExtra("detailNotes");
|
||||||
|
if(tmp != null && tmp.equals("")) {
|
||||||
|
tmp = "Нет описания";
|
||||||
|
} else if (tmp == null){
|
||||||
|
tmp = "Нет описания";
|
||||||
|
}
|
||||||
|
hashMap.put("detailNotes", tmp);
|
||||||
|
|
||||||
|
return hashMap;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
switch(item.getItemId()) {
|
switch(item.getItemId()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user