diff --git a/app/build.gradle b/app/build.gradle index 423e029..9e6425e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -7,8 +7,8 @@ android { applicationId "tech.zafrani.companionforpubg" minSdkVersion 18 targetSdkVersion 25 - versionCode 7 - versionName "0.0.7" + versionCode 8 + versionName "0.0.8" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } diff --git a/app/src/main/assets/items.json b/app/src/main/assets/items.json index 4b3b1e2..dc023b0 100644 --- a/app/src/main/assets/items.json +++ b/app/src/main/assets/items.json @@ -7,7 +7,7 @@ "id": 0, "type": "AssaultRifle", "image_url": "Icon_weapon_AKM.png", - "magazine": 30, + "magazine_size": 30, "ammo_id": 4, "range": 60, "stability": 34, @@ -24,14 +24,32 @@ "head1": 80, "head2": 68, "head3": 51 - } + }, + "magazine_ids": [ + 13, + 18, + 27 + ], + "muzzle_ids": [ + 9, + 22, + 35 + ], + "sight_ids": [ + 0, + 1, + 2, + 3, + 26, + 33 + ] }, { "name": "AWM", "id": 1, "type": "SniperRifle", "image_url": "Icon_weapon_AWM.png", - "magazine": 5, + "magazine_size": 5, "ammo_id": 0, "range": 100, "stability": 34, @@ -48,14 +66,35 @@ "head1": 229, "head2": 197, "head3": 147 - } + }, + "magazine_ids": [ + 17, + 20, + 32 + ], + "muzzle_ids": [ + 10, + 24, + 38 + ], + "sight_ids": [ + 0, + 1, + 2, + 3, + 26, + 33 + ], + "stock_ids": [ + 7 + ] }, { "name": "Crossbow", "id": 2, "type": "Crossbow", "image_url": "Icon_weapon_Crossbow.png", - "magazine": 1, + "magazine_size": 1, "ammo_id": 6, "range": 4, "reload": 0, @@ -72,7 +111,19 @@ "head1": 184, "head2": 158, "head3": 118 - } + }, + "magazine_ids": [ + 28 + ], + "grip_ids": [ + 25 + ], + "sight_ids": [ + 1, + 2, + 26, + 33 + ] }, { "name": "Crowbar", @@ -108,7 +159,7 @@ "id": 5, "type": "SniperRifle", "image_url": "Icon_weapon_Kar98k.png", - "magazine": 5, + "magazine_size": 5, "ammo_id": 4, "range": 79, "stability": 34, @@ -125,14 +176,30 @@ "head1": 126, "head2": 108, "head3": 81 - } + }, + "muzzle_ids": [ + 10, + 24, + 38 + ], + "sight_ids": [ + 0, + 1, + 2, + 3, + 26, + 33 + ], + "stock_ids": [ + 7 + ] }, { "name": "M16A4", "id": 6, "type": "AssaultRifle", "image_url": "Icon_weapon_M16A4.png", - "magazine": 30, + "magazine_size": 30, "ammo_id": 3, "range": 62, "stability": 28, @@ -149,14 +216,32 @@ "head1": 72, "head2": 62, "head3": 46 - } + }, + "magazine_ids": [ + 13, + 18, + 27 + ], + "muzzle_ids": [ + 9, + 22, + 35 + ], + "sight_ids": [ + 0, + 1, + 2, + 3, + 26, + 33 + ] }, { "name": "M24", "id": 7, "type": "SniperRifle", "image_url": "Icon_weapon_M24.png", - "magazine": 5, + "magazine_size": 5, "ammo_id": 4, "range": 96, "stability": 32, @@ -173,14 +258,35 @@ "head1": 147, "head2": 126, "head3": 95 - } + }, + "magazine_ids": [ + 17, + 20, + 32 + ], + "muzzle_ids": [ + 10, + 24, + 38 + ], + "sight_ids": [ + 0, + 1, + 2, + 3, + 26, + 33 + ], + "stock_ids": [ + 7 + ] }, { "name": "M249", "id": 8, "type": "LMG", "image_url": "Icon_weapon_M249.png", - "magazine": 100, + "magazine_size": 100, "ammo_id": 3, "range": 71, "stability": 44, @@ -197,14 +303,22 @@ "head1": 77, "head2": 66, "head3": 50 - } + }, + "sight_ids": [ + 0, + 1, + 2, + 3, + 26, + 33 + ] }, { "name": "M416", "id": 9, "type": "AssaultRifle", "image_url": "Icon_weapon_M416.png", - "magazine": 30, + "magazine_size": 30, "ammo_id": 3, "range": 57, "reload": 0, @@ -221,7 +335,32 @@ "head1": 72, "head2": 62, "head3": 46 - } + }, + "magazine_ids": [ + 13, + 18, + 27 + ], + "muzzle_ids": [ + 9, + 22, + 35 + ], + "grip_ids": [ + 4, + 40 + ], + "sight_ids": [ + 0, + 1, + 2, + 3, + 26, + 33 + ], + "stock_ids": [ + 39 + ] }, { "name": "Machete", @@ -247,7 +386,7 @@ "id": 11, "type": "SMG", "image_url": "Icon_weapon_UZI.png", - "magazine": 30, + "magazine_size": 30, "ammo_id": 5, "range": 22, "stability": 31, @@ -264,7 +403,19 @@ "head1": 40, "head2": 35, "head3": 26 - } + }, + "magazine_ids": [ + 16, + 21, + 31 + ], + "muzzle_ids": [ + 23, + 37 + ], + "stock_ids": [ + 34 + ] }, { "name": "Molotov Cocktail", @@ -282,9 +433,9 @@ "id": 13, "type": "Pistol", "image_url": "Icon_weapon_P1911.png", - "magazine": 7, + "magazine_size": 7, "ammo_id": 1, - "range":15, + "range": 15, "stability": 25, "rate": 53, "reload": 0, @@ -299,14 +450,22 @@ "head1": 61, "head2": 53, "head3": 39 - } + }, + "magazine_ids": [ + 15, + 19, + 30 + ], + "muzzle_ids": [ + 36 + ] }, { "name": "P92", "id": 14, "type": "Pistol", "image_url": "Icon_weapon_P92.png", - "magazine": 15, + "magazine_size": 15, "ammo_id": 5, "range": 15, "stability": 25, @@ -323,7 +482,15 @@ "head1": 51, "head2": 44, "head3": 33 - } + }, + "magazine_ids": [ + 15, + 19, + 30 + ], + "muzzle_ids": [ + 36 + ] }, { "name": "Pan", @@ -349,7 +516,7 @@ "id": 16, "type": "Pistol", "image_url": "Icon_weapon_R1895.png", - "magazine": 5, + "magazine_size": 5, "ammo_id": 4, "range": 31, "stability": 29, @@ -366,14 +533,17 @@ "head1": 81, "head2": 69, "head3": 52 - } + }, + "muzzle_ids": [ + 36 + ] }, { "name": "S12K", "id": 17, "type": "Shotgun", "image_url": "Icon_weapon_S12K.png", - "magazine": 5, + "magazine_size": 5, "ammo_id": 2, "range": 9, "stability": 86, @@ -390,14 +560,32 @@ "head1": 999, "head2": 999, "head3": 999 - } + }, + "magazine_ids": [ + 13, + 18, + 27 + ], + "muzzle_ids": [ + 9, + 22, + 35 + ], + "sight_ids": [ + 0, + 1, + 2, + 3, + 26, + 33 + ] }, { "name": "S1897", "id": 18, "type": "Shotgun", "image_url": "Icon_weapon_S1897.png", - "magazine": 2, + "magazine_size": 2, "ammo_id": 2, "range": 8, "stability": 77, @@ -414,14 +602,20 @@ "head1": 999, "head2": 999, "head3": 999 - } + }, + "loop_ids": [ + 6 + ], + "muzzle_ids": [ + 8 + ] }, { "name": "S686", "id": 19, "type": "Shotgun", "image_url": "Icon_weapon_S686.png", - "magazine": 5, + "magazine_size": 5, "ammo_id": 2, "range": 13, "stability": 77, @@ -438,14 +632,20 @@ "head1": 999, "head2": 999, "head3": 999 - } + }, + "loop_ids": [ + 6 + ], + "muzzle_ids": [ + 8 + ] }, { "name": "SCAR-L", "id": 20, "type": "AssaultRifle", "image_url": "Icon_weapon_SCAR-L.png", - "magazine": 30, + "magazine_size": 30, "ammo_id": 3, "range": 55, "stability": 31, @@ -462,7 +662,29 @@ "head1": 72, "head2": 62, "head3": 46 - } + }, + "magazine_ids": [ + 13, + 18, + 27 + ], + "muzzle_ids": [ + 9, + 22, + 35 + ], + "grip_ids": [ + 4, + 40 + ], + "sight_ids": [ + 0, + 1, + 2, + 3, + 26, + 33 + ] }, { "name": "Sickle", @@ -488,7 +710,7 @@ "id": 22, "type": "DMR", "image_url": "Icon_weapon_SKS.png", - "magazine": 5, + "magazine_size": 5, "ammo_id": 4, "range": 64, "stability": 48, @@ -505,7 +727,25 @@ "head1": 96, "head2": 83, "head3": 62 - } + }, + "magazine_ids": [ + 17, + 20, + 32 + ], + "muzzle_ids": [ + 10, + 24, + 38 + ], + "sight_ids": [ + 0, + 1, + 2, + 3, + 26, + 33 + ] }, { "name": "Smoke Grenade", @@ -532,7 +772,7 @@ "id": 25, "type": "SMG", "image_url": "Icon_weapon_TommyGun.png", - "magazine": 30, + "magazine_size": 30, "ammo_id": 1, "range": 46, "stability": 31, @@ -549,14 +789,23 @@ "head1": 67, "head2": 57, "head3": 43 - } + }, + "magazine_ids": [ + 16, + 21, + 31 + ], + "muzzle_ids": [ + 23, + 37 + ] }, { "name": "UMP9", "id": 26, "type": "SMG", "image_url": "Icon_weapon_UMP.png", - "magazine": 30, + "magazine_size": 30, "ammo_id": 5, "range": 30, "stability": 31, @@ -573,14 +822,33 @@ "head1": "58", "head2": "50", "head3": "37" - } + }, + "grip_ids": [ + 4, + 40 + ], + "magazine_ids": [ + 16, + 21, + 31 + ], + "muzzle_ids": [ + 23, + 37 + ], + "sight_ids": [ + 1, + 2, + 26, + 33 + ] }, { "name": "Vector", "id": 27, "type": "SMG", "image_url": "Icon_weapon_Vector.png", - "magazine": 13, + "magazine_size": 13, "ammo_id": 1, "range": 65, "stability": 35, @@ -597,7 +865,26 @@ "head1": 63, "head2": 54, "head3": 41 - } + }, + "grip_ids": [ + 4, + 40 + ], + "magazine_ids": [ + 16, + 21, + 31 + ], + "muzzle_ids": [ + 23, + 37 + ], + "sight_ids": [ + 1, + 2, + 26, + 33 + ] } ] }, @@ -679,7 +966,7 @@ }, { "id": 4, - "type": "Grip", + "type": "Grips", "name": "Angled Foregrip", "image_url": "Icon_attach_AngledForeGrip.png", "capacity": 500 @@ -700,7 +987,7 @@ }, { "id": 7, - "type": "Stock", + "type": "Stocks", "name": "Cheek Pad for Sniper Rifle", "image_url": "Icon_attach_CheekPadSniperRifle.png", "capacity": 500 @@ -728,7 +1015,7 @@ }, { "id": 11, - "type": "Stock", + "type": "Stocks", "name": "Composite Stock for Assault Rifle", "image_url": "Icon_attach_CompositeAR.png", "capacity": 500 @@ -826,7 +1113,7 @@ }, { "id": 25, - "type": "Grip", + "type": "Grips", "name": "Foregrip for Crossbow", "image_url": "Icon_attach_ForegripCrossbow.png", "capacity": 500 @@ -836,7 +1123,7 @@ "type": "Sights", "name": "Holographic Sight", "image_url": "Icon_attach_Holo.png", - "capacity": 500 + "capacity": 10 }, { "id": 27, @@ -885,11 +1172,11 @@ "type": "Sights", "name": "Red Dot Sight", "image_url": "Icon_attach_RedDot.png", - "capacity": 500 + "capacity": 10 }, { "id": 34, - "type": "Stock", + "type": "Stocks", "name": "Stock for Micro Uzi", "image_url": "Icon_attach_StockUzi.png", "capacity": 500 @@ -924,15 +1211,15 @@ }, { "id": 39, - "type": "Stock", - "name": "Tactical Stock for M416", + "type": "Stocks", + "name": "Tactical Stock for M416, Vector", "image_url": "", - "capacity": 500 + "capacity": 12 }, { "id": 40, - "type": "Grip", - "name": "Verticle Foregrip", + "type": "Grips", + "name": "Vertical Foregrip", "image_url": "Icon_attach_VerticalForegrip.png", "capacity": 500 } @@ -1239,7 +1526,7 @@ "vehicle_category": { "vehicles": [ { - "id":0, + "id": 0, "type": "Default", "name": "Buggy", "image_url": "", @@ -1250,7 +1537,7 @@ "capacity": 0 }, { - "id":1, + "id": 1, "type": "Default", "name": "Dacia", "image_url": "", @@ -1261,7 +1548,7 @@ "capacity": 0 }, { - "id":2, + "id": 2, "type": "Default", "name": "Motorcycle (No sidecar)", "image_url": "", @@ -1272,7 +1559,7 @@ "capacity": 0 }, { - "id":3, + "id": 3, "type": "Default", "name": "Motorcycle (w/ sidecar)", "image_url": "", @@ -1283,7 +1570,7 @@ "capacity": 0 }, { - "id":4, + "id": 4, "type": "Default", "name": "Speed Boat", "image_url": "", @@ -1294,7 +1581,7 @@ "capacity": 0 }, { - "id":5, + "id": 5, "type": "Default", "name": "UAZ", "image_url": "", diff --git a/app/src/main/java/tech/zafrani/companionforpubg/adapters/ItemRecyclerViewAdapter.java b/app/src/main/java/tech/zafrani/companionforpubg/adapters/ItemRecyclerViewAdapter.java index 5544163..b841274 100644 --- a/app/src/main/java/tech/zafrani/companionforpubg/adapters/ItemRecyclerViewAdapter.java +++ b/app/src/main/java/tech/zafrani/companionforpubg/adapters/ItemRecyclerViewAdapter.java @@ -10,6 +10,7 @@ import com.squareup.picasso.Picasso; +import java.util.ArrayList; import java.util.List; import tech.zafrani.companionforpubg.R; @@ -21,6 +22,10 @@ public ItemRecyclerViewAdapter(@NonNull final List items) { super(items); } + public ItemRecyclerViewAdapter() { + this(new ArrayList()); + } + @Override public ItemRecyclerViewAdapter.ItemViewHolder onCreateViewHolder(final ViewGroup parent, final int viewType) { diff --git a/app/src/main/java/tech/zafrani/companionforpubg/adapters/RecyclerViewAdapter.java b/app/src/main/java/tech/zafrani/companionforpubg/adapters/RecyclerViewAdapter.java index a6940fe..390423b 100644 --- a/app/src/main/java/tech/zafrani/companionforpubg/adapters/RecyclerViewAdapter.java +++ b/app/src/main/java/tech/zafrani/companionforpubg/adapters/RecyclerViewAdapter.java @@ -43,12 +43,17 @@ public int getItemCount() { //endregion //region methods + public void clear() { + this.models.clear(); + notifyDataSetChanged(); + } + public void add(@NonNull final Model model) { this.models.add(model); notifyItemChanged(this.models.size() - 1); } - public void addAll(@NonNull final List models) { + public void addAll(@NonNull final List models) { final int startPosition = getItemCount(); this.models.addAll(models); notifyItemRangeInserted(startPosition, models.size()); diff --git a/app/src/main/java/tech/zafrani/companionforpubg/fragments/WeaponDetailFragment.java b/app/src/main/java/tech/zafrani/companionforpubg/fragments/WeaponDetailFragment.java index 7781536..08a6249 100644 --- a/app/src/main/java/tech/zafrani/companionforpubg/fragments/WeaponDetailFragment.java +++ b/app/src/main/java/tech/zafrani/companionforpubg/fragments/WeaponDetailFragment.java @@ -12,15 +12,21 @@ import com.squareup.picasso.Picasso; +import java.util.ArrayList; +import java.util.List; + import butterknife.BindView; import tech.zafrani.companionforpubg.PUBGApplication; import tech.zafrani.companionforpubg.R; import tech.zafrani.companionforpubg.activities.ItemDetailActivity; import tech.zafrani.companionforpubg.models.items.ammo.Ammo; +import tech.zafrani.companionforpubg.models.items.attachments.Attachment; +import tech.zafrani.companionforpubg.models.items.attachments.AttachmentCategory; import tech.zafrani.companionforpubg.models.items.weapons.ProjectileWeapon; import tech.zafrani.companionforpubg.models.items.weapons.Weapon; import tech.zafrani.companionforpubg.utils.Constants; import tech.zafrani.companionforpubg.widgets.BarValueView; +import tech.zafrani.companionforpubg.widgets.ItemPickerView; public class WeaponDetailFragment extends BaseFragment { public static final String TAG = WeaponDetailFragment.class.getSimpleName(); @@ -78,6 +84,34 @@ public static WeaponDetailFragment newInstance(@NonNull final Weapon weapon) { @BindView(R.id.fragment_weapon_detail_weapon_magazine_bar_value) BarValueView magazineBarValueView; + @Nullable + @BindView(R.id.fragment_weapon_detail_weapon_loops_item_picker) + ItemPickerView loopsPickerView; + + @Nullable + @BindView(R.id.fragment_weapon_detail_weapon_magazine_item_picker) + ItemPickerView magazinePickerView; + + @Nullable + @BindView(R.id.fragment_weapon_detail_weapon_muzzle_item_picker) + ItemPickerView muzzlePickerView; + + @Nullable + @BindView(R.id.fragment_weapon_detail_weapon_grip_item_picker) + ItemPickerView gripPickerView; + + @Nullable + @BindView(R.id.fragment_weapon_detail_weapon_sight_item_picker) + ItemPickerView sightPickerView; + + @Nullable + @BindView(R.id.fragment_weapon_detail_weapon_stock_item_picker) + ItemPickerView stockPickerView; + + @Nullable + @BindView(R.id.fragment_weapon_detail_attachment_divider) + View attachmentDivider; + //region BaseFragment @Override @@ -112,13 +146,21 @@ public void onViewCreated(final View view, setBarValue(this.rangeBarValueView, R.string.row_item_range, projectileWeapon.getRange()); setBarValue(this.stabilityBarValueView, R.string.row_item_stability, projectileWeapon.getStability()); setBarValue(this.rateBarValueView, R.string.row_item_rate, projectileWeapon.getRate()); - setBarValue(this.magazineBarValueView, R.string.row_item_magazine, projectileWeapon.getMagazine()); + setBarValue(this.magazineBarValueView, R.string.row_item_magazine, projectileWeapon.getMagazineSize()); setAmmoClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ItemDetailActivity.startActivity(getActivity(), ammo); } }); + setLoopsPickerView(getAttachmentsFor(projectileWeapon.getLoopIds())); + setMagazinePickerView(getAttachmentsFor(projectileWeapon.getMagazinesIds())); + setMuzzlePickerView(getAttachmentsFor(projectileWeapon.getMuzzleIds())); + setGripPickerView(getAttachmentsFor(projectileWeapon.getGripIds())); + setSightPickerView(getAttachmentsFor(projectileWeapon.getSightIds())); + setStockPickerView(getAttachmentsFor(projectileWeapon.getStockIds())); + } else { + setAttachmentDividerVisible(false); } } //endregion @@ -180,5 +222,78 @@ private void setBarValue(@Nullable final BarValueView barValue, barValue.setValue(text, value); } + private void setLoopsPickerView(@Nullable final List loops) { + if (this.loopsPickerView == null || loops == null) { + return; + } + this.loopsPickerView.setVisibility(View.VISIBLE); + this.loopsPickerView.setItems(loops); + } + + private void setMagazinePickerView(@Nullable final List attachments) { + if (this.magazinePickerView == null || attachments == null) { + return; + } + this.magazinePickerView.setVisibility(View.VISIBLE); + this.magazinePickerView.setItems(attachments); + } + + private void setMuzzlePickerView(@Nullable final List muzzles) { + if (this.muzzlePickerView == null || muzzles == null) { + return; + } + this.muzzlePickerView.setVisibility(View.VISIBLE); + this.muzzlePickerView.setItems(muzzles); + } + + private void setGripPickerView(@Nullable final List grips) { + if (this.gripPickerView == null || grips == null) { + return; + } + this.gripPickerView.setVisibility(View.VISIBLE); + this.gripPickerView.setItems(grips); + } + + private void setStockPickerView(@Nullable final List stocks) { + if (this.stockPickerView == null || stocks == null) { + return; + } + this.stockPickerView.setVisibility(View.VISIBLE); + this.stockPickerView.setItems(stocks); + } + + + private void setSightPickerView(@Nullable final List sights) { + if (this.sightPickerView == null || sights == null) { + return; + } + this.sightPickerView.setVisibility(View.VISIBLE); + this.sightPickerView.setItems(sights); + } + + private void setAttachmentDividerVisible(final boolean visible) { + if (this.attachmentDivider == null) { + return; + } + this.attachmentDivider.setVisibility(visible ? View.VISIBLE : View.GONE); + } + + @Nullable + private List getAttachmentsFor(@Nullable final int[] attachmentIds) { + if (attachmentIds == null) { + return null; + } + final List attachments = new ArrayList<>(); + final AttachmentCategory attachmentCategory = PUBGApplication.getInstance().getItems().getCategories().getAttachmentCategory(); + + for (int attachmentId : attachmentIds) { + final Attachment attachment = attachmentCategory.getAttachmentWithId(attachmentId); + if (attachment != null) { + attachments.add(attachment); + } + } + return attachments; + } + //endregion } diff --git a/app/src/main/java/tech/zafrani/companionforpubg/models/items/Categories.java b/app/src/main/java/tech/zafrani/companionforpubg/models/items/Categories.java index a7f4e9b..abcc07c 100644 --- a/app/src/main/java/tech/zafrani/companionforpubg/models/items/Categories.java +++ b/app/src/main/java/tech/zafrani/companionforpubg/models/items/Categories.java @@ -5,6 +5,7 @@ import java.util.EnumMap; import tech.zafrani.companionforpubg.models.items.ammo.AmmoCategory; +import tech.zafrani.companionforpubg.models.items.attachments.AttachmentCategory; import tech.zafrani.companionforpubg.models.items.weapons.WeaponCategory; public class Categories extends EnumMap> { @@ -40,4 +41,9 @@ public AmmoCategory getAmmoCategory() { return ((AmmoCategory) (Category) get(Category.Name.AMMO_CATEGORY)); } + @NonNull + public AttachmentCategory getAttachmentCategory() { + return ((AttachmentCategory) (Category) get(Category.Name.ATTACHMENT_CATEGORY)); + } + } diff --git a/app/src/main/java/tech/zafrani/companionforpubg/models/items/attachments/AttachmentCategory.java b/app/src/main/java/tech/zafrani/companionforpubg/models/items/attachments/AttachmentCategory.java index 72cd6c4..6a4ea89 100644 --- a/app/src/main/java/tech/zafrani/companionforpubg/models/items/attachments/AttachmentCategory.java +++ b/app/src/main/java/tech/zafrani/companionforpubg/models/items/attachments/AttachmentCategory.java @@ -2,12 +2,14 @@ import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import com.google.gson.annotations.SerializedName; import java.util.List; import tech.zafrani.companionforpubg.models.items.Category; +import tech.zafrani.companionforpubg.models.items.ammo.Ammo; public class AttachmentCategory implements Category { @@ -22,12 +24,22 @@ public AttachmentCategory(@NonNull final AttachmentList attachmentList) { @Override public String toString() { return "AttachmentCategory{" + - "attachmentList=" + this.attachmentList.toString() + - '}'; + "attachmentList=" + this.attachmentList.toString() + + '}'; } @Override public List getItems() { return this.attachmentList; } + + @Nullable + public Attachment getAttachmentWithId(final int id) { + for (final Attachment attachment : attachmentList) { + if (attachment.getId() == id) { + return attachment; + } + } + return null; + } } diff --git a/app/src/main/java/tech/zafrani/companionforpubg/models/items/weapons/ProjectileWeapon.java b/app/src/main/java/tech/zafrani/companionforpubg/models/items/weapons/ProjectileWeapon.java index 7e64c13..56f42d9 100644 --- a/app/src/main/java/tech/zafrani/companionforpubg/models/items/weapons/ProjectileWeapon.java +++ b/app/src/main/java/tech/zafrani/companionforpubg/models/items/weapons/ProjectileWeapon.java @@ -2,14 +2,15 @@ import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import com.google.gson.annotations.SerializedName; public class ProjectileWeapon extends Weapon { - @SerializedName("magazine") - private final int magazine; + @SerializedName("magazine_size") + private final int magazineSize; @SerializedName("ammo_id") private final int ammoId; @@ -30,32 +31,68 @@ public class ProjectileWeapon extends Weapon { @SerializedName("damage") private final Damage damage; + @Nullable + @SerializedName("loop_ids") + private final int[] loopIds; + + @Nullable + @SerializedName("magazine_ids") + private final int[] magazinesIds; + + @Nullable + @SerializedName("muzzle_ids") + private final int[] muzzleIds; + + @Nullable + @SerializedName("grip_ids") + private final int[] gripIds; + + @Nullable + @SerializedName("sight_ids") + private final int[] sightIds; + + @Nullable + @SerializedName("stock_ids") + private final int[] stockIds; + public ProjectileWeapon(@NonNull final String name, final int id, @NonNull final String imageUrl, final int capacity, @NonNull final Type type, - final int magazine, + final int magazineSize, final int ammoId, final int range, final int stability, final int rate, final int reload, - @NonNull final Damage damage) { + @NonNull final Damage damage, + @Nullable final int[] loopIds, + @Nullable final int[] magazinesIds, + @Nullable final int[] muzzleIds, + @Nullable final int[] gripIds, + @Nullable final int[] sightIds, + @Nullable final int[] stockIds) { super(name, id, imageUrl, capacity, type); - this.magazine = magazine; + this.magazineSize = magazineSize; this.ammoId = ammoId; this.range = range; this.stability = stability; this.rate = rate; this.reload = reload; this.damage = damage; + this.loopIds = loopIds; + this.magazinesIds = magazinesIds; + this.muzzleIds = muzzleIds; + this.gripIds = gripIds; + this.sightIds = sightIds; + this.stockIds = stockIds; } @Override public String toString() { return "ProjectileWeapon{" + - "magazine=" + magazine + + "magazineSize=" + magazineSize + ", ammoId=" + ammoId + ", range=" + range + ", stability=" + stability + @@ -68,8 +105,8 @@ public int getRate() { return this.rate; } - public int getMagazine() { - return magazine; + public int getMagazineSize() { + return magazineSize; } public int getAmmoId() { @@ -88,6 +125,36 @@ public int getReload() { return reload; } + @Nullable + public int[] getLoopIds() { + return loopIds; + } + + @Nullable + public int[] getMagazinesIds() { + return magazinesIds; + } + + @Nullable + public int[] getMuzzleIds() { + return muzzleIds; + } + + @Nullable + public int[] getGripIds() { + return gripIds; + } + + @Nullable + public int[] getSightIds() { + return sightIds; + } + + @Nullable + public int[] getStockIds() { + return stockIds; + } + @NonNull public Damage getDamage() { return damage; diff --git a/app/src/main/java/tech/zafrani/companionforpubg/widgets/BarValueView.java b/app/src/main/java/tech/zafrani/companionforpubg/widgets/BarValueView.java index 7f6bd04..771ac49 100644 --- a/app/src/main/java/tech/zafrani/companionforpubg/widgets/BarValueView.java +++ b/app/src/main/java/tech/zafrani/companionforpubg/widgets/BarValueView.java @@ -13,6 +13,7 @@ public class BarValueView extends FrameLayout { + @NonNull private final TextView textView; diff --git a/app/src/main/java/tech/zafrani/companionforpubg/widgets/ItemPickerView.java b/app/src/main/java/tech/zafrani/companionforpubg/widgets/ItemPickerView.java new file mode 100644 index 0000000..cb4bc3a --- /dev/null +++ b/app/src/main/java/tech/zafrani/companionforpubg/widgets/ItemPickerView.java @@ -0,0 +1,118 @@ +package tech.zafrani.companionforpubg.widgets; + + +import android.content.Context; +import android.content.res.TypedArray; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.util.AttributeSet; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.FrameLayout; +import android.widget.ImageView; +import android.widget.TextView; + +import com.squareup.picasso.Picasso; + +import java.util.List; + +import tech.zafrani.companionforpubg.R; +import tech.zafrani.companionforpubg.models.items.Item; +import tech.zafrani.companionforpubg.utils.Constants; + +public class ItemPickerView extends FrameLayout + implements ItemPickerViewAlertDialog.Listener { + @NonNull + private final TextView titleTextView; + + @NonNull + private final TextView valueTextView; + + @NonNull + private final ImageView itemImageView; + @NonNull + private final ImageView clearImageView; + + @NonNull + private final ItemPickerViewAlertDialog alertDialog; + + //region FrameLayout + public ItemPickerView(@NonNull final Context context) { + this(context, null); + } + + public ItemPickerView(@NonNull final Context context, + @Nullable final AttributeSet attrs) { + this(context, attrs, 0); + } + + public ItemPickerView(@NonNull final Context context, + @Nullable final AttributeSet attrs, + final int defStyleAttr) { + super(context, attrs, defStyleAttr); + LayoutInflater.from(context).inflate(R.layout.view_item_picker, this, true); + this.titleTextView = (TextView) findViewById(R.id.view_item_picker_title_text); + this.valueTextView = (TextView) findViewById(R.id.view_item_picker_value_text); + this.itemImageView = (ImageView) findViewById(R.id.view_item_picker_image); + this.clearImageView = (ImageView) findViewById(R.id.view_item_picker_clear); + this.alertDialog = new ItemPickerViewAlertDialog(getContext(), ItemPickerView.this, this); + final TypedArray typedArray = context.getTheme().obtainStyledAttributes( + attrs, + R.styleable.ItemPickerView, + 0, + 0); + + if (typedArray == null) { + return; + } + + try { + final String text = typedArray.getString(R.styleable.ItemPickerView_titleText); + titleTextView.setText(text); + } finally { + typedArray.recycle(); + } + setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + alertDialog.show(); + } + }); + this.clearImageView.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + clear(); + } + }); + } + //endregion + + //region ItemPickerViewAlertDialog.Listener + @Override + public void onItemSelected(@NonNull final Item item) { + this.clearImageView.setVisibility(VISIBLE); + this.alertDialog.dismiss(); + this.valueTextView.setText(item.getName()); + Picasso.with(getContext()) + .load(Constants.ITEM_IMAGE_URL + item.getImageUrl()) + .into(this.itemImageView); + } + //endregion + + //region Methods + private void clear() { + this.clearImageView.setVisibility(INVISIBLE); + this.itemImageView.setImageDrawable(null); + this.valueTextView.setText(null); + } + + public void setValueTextView(@Nullable final String text) { + this.valueTextView.setText(text); + } + + public void setItems(@NonNull final List items) { + this.alertDialog.setItems(items); + } + //endregion + +} diff --git a/app/src/main/java/tech/zafrani/companionforpubg/widgets/ItemPickerViewAlertDialog.java b/app/src/main/java/tech/zafrani/companionforpubg/widgets/ItemPickerViewAlertDialog.java new file mode 100644 index 0000000..c37f49d --- /dev/null +++ b/app/src/main/java/tech/zafrani/companionforpubg/widgets/ItemPickerViewAlertDialog.java @@ -0,0 +1,97 @@ +package tech.zafrani.companionforpubg.widgets; + + +import android.content.Context; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.annotation.StyleRes; +import android.support.v7.app.AlertDialog; +import android.support.v7.widget.DividerItemDecoration; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import java.util.List; + +import tech.zafrani.companionforpubg.R; +import tech.zafrani.companionforpubg.adapters.ItemRecyclerViewAdapter; +import tech.zafrani.companionforpubg.adapters.RecyclerViewAdapter; +import tech.zafrani.companionforpubg.models.items.Item; + +public class ItemPickerViewAlertDialog extends AlertDialog + implements RecyclerViewAdapter.Listener { + + @NonNull + private final RecyclerView recyclerView; + + @NonNull + private final ItemRecyclerViewAdapter adapter; + + @NonNull + private final Listener listener; + + //region AlertDialog + protected ItemPickerViewAlertDialog(@NonNull final Context context, + @NonNull final ViewGroup parent, + @NonNull final Listener listener) { + this(context, 0, parent, listener); + } + + protected ItemPickerViewAlertDialog(@NonNull final Context context, + @StyleRes final int themeResId, + @NonNull final ViewGroup parent, + @NonNull final Listener listener) { + super(context, themeResId); + final View view = LayoutInflater.from(context).inflate(R.layout.alert_dialog_item_picker_view, parent, false); + setView(view); + this.listener = listener; + this.adapter = new ItemRecyclerViewAdapter<>(); + this.recyclerView = (RecyclerView) view.findViewById(R.id.alert_dialog_item_picker_view_recycler); + init(); + + } + + protected ItemPickerViewAlertDialog(@NonNull final Context context, + final boolean cancelable, + @Nullable final OnCancelListener cancelListener, + @NonNull final ViewGroup parent, + @NonNull final Listener listener) { + super(context, cancelable, cancelListener); + final View view = LayoutInflater.from(context).inflate(R.layout.alert_dialog_item_picker_view, parent, false); + setView(view); + this.listener = listener; + this.adapter = new ItemRecyclerViewAdapter<>(); + this.recyclerView = (RecyclerView) view.findViewById(R.id.alert_dialog_item_picker_view_recycler); + init(); + } + //endregion + + // region RecyclerViewAdapter.Listener + + @Override + public void onClick(@NonNull final Item item) { + this.listener.onItemSelected(item); + } + + //endregion + + //region Methods + private void init() { + this.recyclerView.setLayoutManager(new LinearLayoutManager(this.recyclerView.getContext())); + this.recyclerView.addItemDecoration(new DividerItemDecoration(this.recyclerView.getContext(), DividerItemDecoration.VERTICAL)); + this.recyclerView.setAdapter(this.adapter); + this.adapter.setListener(this); + } + + public void setItems(@NonNull final List items) { + this.adapter.clear(); + this.adapter.addAll(items); + } + //endregion + + public interface Listener { + void onItemSelected(@NonNull final Item item); + } +} diff --git a/app/src/main/res/drawable-hdpi/ic_close_white_24dp.png b/app/src/main/res/drawable-hdpi/ic_close_white_24dp.png new file mode 100644 index 0000000..ceb1a1e Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_close_white_24dp.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_close_white_24dp.png b/app/src/main/res/drawable-mdpi/ic_close_white_24dp.png new file mode 100644 index 0000000..af7f828 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_close_white_24dp.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_close_white_24dp.png b/app/src/main/res/drawable-xhdpi/ic_close_white_24dp.png new file mode 100644 index 0000000..b7c7ffd Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_close_white_24dp.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_close_white_24dp.png b/app/src/main/res/drawable-xxhdpi/ic_close_white_24dp.png new file mode 100644 index 0000000..6b717e0 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_close_white_24dp.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/ic_close_white_24dp.png b/app/src/main/res/drawable-xxxhdpi/ic_close_white_24dp.png new file mode 100644 index 0000000..3964192 Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_close_white_24dp.png differ diff --git a/app/src/main/res/layout/alert_dialog_item_picker_view.xml b/app/src/main/res/layout/alert_dialog_item_picker_view.xml new file mode 100644 index 0000000..c469181 --- /dev/null +++ b/app/src/main/res/layout/alert_dialog_item_picker_view.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_weapon_detail.xml b/app/src/main/res/layout/fragment_weapon_detail.xml index ee7c3c7..70619ff 100644 --- a/app/src/main/res/layout/fragment_weapon_detail.xml +++ b/app/src/main/res/layout/fragment_weapon_detail.xml @@ -1,125 +1,201 @@ - + - + android:orientation="vertical" + android:paddingBottom="@dimen/standard_margin"> - - - - - + android:padding="@dimen/standard_margin"> - - - - + + android:textSize="@dimen/title_text_size"/> - + - - - + - + + + + + + + + - + - + + + + + + + + + - - + - \ No newline at end of file + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/row_item.xml b/app/src/main/res/layout/row_item.xml index b7088b4..1005fec 100644 --- a/app/src/main/res/layout/row_item.xml +++ b/app/src/main/res/layout/row_item.xml @@ -5,6 +5,7 @@ android:gravity="center_vertical" android:orientation="horizontal" android:paddingBottom="@dimen/small_margin" + android:background="?selectableItemBackground" android:paddingTop="@dimen/small_margin"> + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml new file mode 100644 index 0000000..e39d867 --- /dev/null +++ b/app/src/main/res/values/attrs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 9dec67f..5c86eb8 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -7,11 +7,11 @@ 30dp + 48dp 80dp 80dp 48dp - 10pt 8pt 4pt diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3691955..7a63808 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -21,6 +21,12 @@ Contact Us Send Email Ammo + Bullet Loops + Magazine + Muzzle + Grip + Sight + Stock Tap two locations on the map. Tap a third time to restart. Assault Rifle