Skip to content

Commit 028cca9

Browse files
authored
Merge pull request #73 from ZafraniTechLLC/develop
v0.0.7 develop
2 parents 44998ba + 2e7d763 commit 028cca9

File tree

12 files changed

+103
-60
lines changed

12 files changed

+103
-60
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ android {
77
applicationId "tech.zafrani.companionforpubg"
88
minSdkVersion 18
99
targetSdkVersion 25
10-
versionCode 6
11-
versionName "0.0.6"
10+
versionCode 7
11+
versionName "0.0.7"
1212
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1313
}
1414

app/src/main/java/tech/zafrani/companionforpubg/activities/BaseActivity.java

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
import butterknife.ButterKnife;
1414
import butterknife.Unbinder;
15-
import tech.zafrani.companionforpubg.R;
1615

1716
public abstract class BaseActivity extends AppCompatActivity {
1817

@@ -35,7 +34,15 @@ protected void onDestroy() {
3534
unbinder.unbind();
3635
}
3736

38-
//endregion
37+
@CallSuper
38+
@Override
39+
public void onBackPressed() {
40+
super.onBackPressed();
41+
if (getTopFragment() == null) {
42+
finish();
43+
}
44+
}
45+
//endregion
3946

4047
//region Methods
4148
@LayoutRes
@@ -44,11 +51,30 @@ protected void onDestroy() {
4451
@IdRes
4552
protected abstract int getContentView();
4653

47-
protected void showFragment(@NonNull final Fragment fragment) {
54+
55+
protected void showFragment(@NonNull final Fragment fragment,
56+
@NonNull final String tag) {
57+
showFragment(fragment, getContentView(), tag);
58+
59+
}
60+
61+
public void showFragment(@NonNull final Fragment fragment,
62+
@IdRes final int contentView,
63+
@NonNull final String tag) {
4864
final FragmentTransaction fragTransaction = getFragmentManager().beginTransaction();
49-
fragTransaction.replace(getContentView(), fragment);
65+
final Fragment topFragment = getTopFragment();
66+
if (topFragment == null) {
67+
fragTransaction.add(contentView, fragment, tag);
68+
} else {
69+
fragTransaction.replace(contentView, fragment, tag);
70+
}
5071
fragTransaction.commit();
5172
getFragmentManager().executePendingTransactions();
5273
}
74+
75+
@Nullable
76+
private Fragment getTopFragment() {
77+
return getFragmentManager().findFragmentById(getContentView());
78+
}
5379
//endregion
5480
}

app/src/main/java/tech/zafrani/companionforpubg/activities/DrawerActivity.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ protected final void onCreate(@Nullable final Bundle savedInstanceState) {
4949
actionBar.setDisplayHomeAsUpEnabled(true);
5050
}
5151

52-
if(this.navigationView != null) {
52+
if (this.navigationView != null) {
5353
this.navigationView.setNavigationItemSelectedListener(this);
5454
this.navigationView.setCheckedItem(R.id.drawer_map);
5555
}
@@ -58,7 +58,7 @@ protected final void onCreate(@Nullable final Bundle savedInstanceState) {
5858

5959
@Override
6060
protected void onDestroy() {
61-
if(this.navigationView != null) {
61+
if (this.navigationView != null) {
6262
this.navigationView.setNavigationItemSelectedListener(null);
6363
}
6464

@@ -79,7 +79,7 @@ protected int getContentView() {
7979
public boolean onOptionsItemSelected(final MenuItem item) {
8080
switch (item.getItemId()) {
8181
case android.R.id.home:
82-
if(drawerLayout != null) {
82+
if (drawerLayout != null) {
8383
this.drawerLayout.openDrawer(GravityCompat.START);
8484
}
8585
return true;
@@ -124,38 +124,39 @@ public boolean onNavigationItemSelected(@NonNull final MenuItem item) {
124124

125125
//region methods
126126
private void mapSelected() {
127-
if(contentLayout == null) {
127+
if (this.contentLayout == null) {
128128
return;
129129
}
130130
final Fragment fragment = getFragmentManager().findFragmentByTag(PUBGMapFragment.TAG);
131131
if (fragment == null) {
132-
showFragment(new PUBGMapFragment());
132+
showFragment(new PUBGMapFragment(), PUBGMapFragment.TAG);
133133
} else {
134-
showFragment(fragment);
134+
showFragment(fragment, PUBGMapFragment.TAG);
135135
}
136136
}
137137

138138
private void itemsSelected() {
139-
if(contentLayout == null) {
139+
if (this.contentLayout == null) {
140140
return;
141141
}
142142

143143
final Fragment fragment = getFragmentManager().findFragmentByTag(ItemFragment.TAG);
144144
if (fragment == null) {
145-
showFragment(new ItemFragment());
145+
showFragment(new ItemFragment(), ItemFragment.TAG);
146146
} else {
147-
showFragment(fragment);
147+
showFragment(fragment, ItemFragment.TAG);
148148
}
149149
}
150+
150151
private void newsSelected() {
151152
if (this.contentLayout == null) {
152153
return;
153154
}
154155
final Fragment fragment = getFragmentManager().findFragmentByTag(NewsFragment.TAG);
155156
if (fragment == null) {
156-
showFragment(new NewsFragment());
157+
showFragment(new NewsFragment(), NewsFragment.TAG);
157158
} else {
158-
showFragment(fragment);
159+
showFragment(fragment, NewsFragment.TAG);
159160
}
160161
}
161162

app/src/main/java/tech/zafrani/companionforpubg/activities/ItemDetailActivity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ public void onCreate(@Nullable final Bundle savedInstanceState) {
5353
}
5454
final Item item = (Item) intent.getSerializableExtra(EXTRA_ITEM);
5555
if (item instanceof Weapon) {
56-
showFragment(WeaponDetailFragment.newInstance((Weapon) item));
56+
showFragment(WeaponDetailFragment.newInstance((Weapon) item), WeaponDetailFragment.TAG);
5757
} else if (item instanceof Ammo) {
58-
showFragment(AmmoDetailFragment.newInstance((Ammo) item));
58+
showFragment(AmmoDetailFragment.newInstance((Ammo) item), WeaponDetailFragment.TAG);
5959
} else {
6060
Toast.makeText(this, "We're still working on this feature!", Toast.LENGTH_SHORT).show();
6161
finish();

app/src/main/java/tech/zafrani/companionforpubg/activities/NewsDetailActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
5454
throw new IllegalStateException("Missing intent");
5555
}
5656
final String newsItemSrc = intent.getStringExtra(EXTRA_NEWSITEM_SRC);
57-
showFragment(NewsDetailFragment.newInstance(newsItemSrc));
57+
showFragment(NewsDetailFragment.newInstance(newsItemSrc), NewsDetailFragment.TAG);
5858

5959
}
6060

app/src/main/java/tech/zafrani/companionforpubg/fragments/NewsDetailFragment.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
import android.view.View;
88
import android.webkit.WebSettings;
99
import android.webkit.WebView;
10+
import android.widget.Toast;
1011

1112
import butterknife.BindView;
1213
import tech.zafrani.companionforpubg.R;
1314

1415
public class NewsDetailFragment extends BaseFragment {
16+
public static final String TAG = NewsDetailFragment.class.getSimpleName();
1517
public static final String ARG_NEWS_SRC = NewsDetailFragment.class.getSimpleName() + ".ARG_NEWS_SRC";
1618

1719
@Nullable
@@ -36,20 +38,23 @@ protected int getLayoutRes() {
3638
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
3739
super.onViewCreated(view, savedInstanceState);
3840
final Bundle args = getArguments();
39-
if (args==null) {
41+
if (args == null) {
4042
throw new IllegalStateException("Missing arguments");
4143
}
42-
if (args.getString(ARG_NEWS_SRC) == null) {
44+
if (!args.containsKey(ARG_NEWS_SRC)) {
4345
throw new IllegalStateException("Missing key");
4446
}
4547
final String newsSrc = args.getString(ARG_NEWS_SRC);
48+
if (newsSrc == null) {
49+
Toast.makeText(getActivity(), "Failed to load.", Toast.LENGTH_SHORT).show();
50+
getActivity().finish();
51+
return;
52+
}
4653
setWebView(newsSrc);
4754

4855
}
4956

5057

51-
52-
5358
private void setWebView(@NonNull final String newsSrc) {
5459
if (newsWebView != null) {
5560
WebSettings settings = this.newsWebView.getSettings();

app/src/main/java/tech/zafrani/companionforpubg/fragments/PUBGMapFragment.java

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import butterknife.BindView;
1717
import tech.zafrani.companionforpubg.R;
18+
import tech.zafrani.companionforpubg.activities.BaseActivity;
1819
import tech.zafrani.companionforpubg.maps.GoogleMapControllerImpl;
1920

2021

@@ -55,26 +56,32 @@ public void onViewCreated(final View view,
5556
super.onViewCreated(view, savedInstanceState);
5657
this.sharedPreferences = getActivity().getSharedPreferences("temp", Context.MODE_PRIVATE); //todo not this.
5758

58-
final MapFragment mapFragment = (MapFragment) getChildFragmentManager().findFragmentById(R.id.map_fragment_map);
59-
mapFragment.getMapAsync(this);
59+
final MapFragment mapFragment = (MapFragment) getActivity().getFragmentManager().findFragmentById(R.id.map_fragment_map);
60+
if (mapFragment == null) {
61+
final MapFragment newMapFragment = new MapFragment();
62+
((BaseActivity) getActivity()).showFragment(newMapFragment, R.id.map_fragment_map, MapFragment.class.getSimpleName());
63+
newMapFragment.getMapAsync(this);
64+
} else {
65+
mapFragment.getMapAsync(this);
66+
}
6067

61-
if(this.vehicleIcon != null) {
68+
if (this.vehicleIcon != null) {
6269
this.vehicleIcon.setOnClickListener(new View.OnClickListener() {
6370
@Override
6471
public void onClick(View view) {
6572
toggleVehicles();
6673
}
6774
});
6875
}
69-
if(this.boatIcon != null) {
76+
if (this.boatIcon != null) {
7077
this.boatIcon.setOnClickListener(new View.OnClickListener() {
7178
@Override
7279
public void onClick(View view) {
7380
toggleBoats();
7481
}
7582
});
7683
}
77-
if(this.runDistanceIcon != null) {
84+
if (this.runDistanceIcon != null) {
7885
this.runDistanceIcon.setOnClickListener(new View.OnClickListener() {
7986
@Override
8087
public void onClick(View view) {
@@ -161,27 +168,27 @@ private void updateUi() {
161168
if (this.mapController == null) {
162169
return;
163170
}
164-
if(vehicleIcon != null) {
171+
if (this.vehicleIcon != null) {
165172
if (this.mapController.isShowingVehicles()) {
166-
vehicleIcon.setColorFilter(ContextCompat.getColor(getActivity(), R.color.accent));
173+
this.vehicleIcon.setColorFilter(ContextCompat.getColor(getActivity(), R.color.accent));
167174
} else {
168-
vehicleIcon.setColorFilter(ContextCompat.getColor(getActivity(), R.color.white));
175+
this.vehicleIcon.setColorFilter(ContextCompat.getColor(getActivity(), R.color.white));
169176
}
170177
}
171178

172-
if(boatIcon != null) {
179+
if (this.boatIcon != null) {
173180
if (this.mapController.isShowingBoats()) {
174-
boatIcon.setColorFilter(ContextCompat.getColor(getActivity(), R.color.accent));
181+
this.boatIcon.setColorFilter(ContextCompat.getColor(getActivity(), R.color.accent));
175182
} else {
176-
boatIcon.setColorFilter(ContextCompat.getColor(getActivity(), R.color.white));
183+
this.boatIcon.setColorFilter(ContextCompat.getColor(getActivity(), R.color.white));
177184
}
178185
}
179186

180-
if(runDistanceIcon != null) {
187+
if (this.runDistanceIcon != null) {
181188
if (this.mapController.isShowingDistance()) {
182-
runDistanceIcon.setColorFilter(ContextCompat.getColor(getActivity(), R.color.accent));
189+
this.runDistanceIcon.setColorFilter(ContextCompat.getColor(getActivity(), R.color.accent));
183190
} else {
184-
runDistanceIcon.setColorFilter(ContextCompat.getColor(getActivity(), R.color.white));
191+
this.runDistanceIcon.setColorFilter(ContextCompat.getColor(getActivity(), R.color.white));
185192
}
186193
}
187194
}

app/src/main/java/tech/zafrani/companionforpubg/fragments/WeaponDetailFragment.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import tech.zafrani.companionforpubg.widgets.BarValueView;
2424

2525
public class WeaponDetailFragment extends BaseFragment {
26+
public static final String TAG = WeaponDetailFragment.class.getSimpleName();
2627
private static final String ARG_WEAPON = WeaponDetailFragment.class.getSimpleName() + ".ARG_WEAPON";
2728

2829
public static WeaponDetailFragment newInstance(@NonNull final Weapon weapon) {

app/src/main/res/layout/activity_newsdetails.xml

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3-
xmlns:app="http://schemas.android.com/apk/res-auto"
4-
android:orientation="vertical"
5-
android:layout_width="match_parent"
6-
android:layout_height="match_parent">
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent"
6+
android:orientation="vertical">
7+
78
<android.support.design.widget.CoordinatorLayout
8-
android:layout_width="match_parent"
9-
android:layout_height="match_parent">
9+
android:layout_width="match_parent"
10+
android:layout_height="match_parent">
1011

1112
<RelativeLayout
1213
android:layout_width="match_parent"
@@ -27,10 +28,12 @@
2728
app:layout_scrollFlags="scroll|enterAlways|snap"
2829
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
2930
</android.support.design.widget.AppBarLayout>
30-
<FrameLayout
31-
android:id="@+id/activity_newsdetails_content"
32-
android:layout_width="match_parent"
33-
android:layout_height="wrap_content"/>
31+
32+
<FrameLayout
33+
android:id="@+id/activity_newsdetails_content"
34+
android:layout_width="match_parent"
35+
android:layout_height="wrap_content"
36+
android:layout_below="@id/activity_newsdetails_appbar"/>
3437
</RelativeLayout>
3538
</android.support.design.widget.CoordinatorLayout>
3639
</LinearLayout>

app/src/main/res/layout/fragment_item.xml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3-
android:orientation="vertical"
4-
android:layout_width="match_parent"
5-
android:layout_height="match_parent">
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
android:background="@color/primary"
6+
android:orientation="vertical">
67

78
<android.support.design.widget.TabLayout
89
android:id="@+id/fragment_item_tablayout"
10+
style="@style/TabLayout"
911
android:layout_width="match_parent"
10-
android:layout_height="wrap_content"
11-
style="@style/TabLayout"/>
12+
android:layout_height="wrap_content"/>
1213

1314
<android.support.v4.view.ViewPager
1415
android:id="@+id/fragment_item_viewpager"

app/src/main/res/layout/fragment_map.xml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3-
xmlns:tools="http://schemas.android.com/tools"
43
android:layout_width="match_parent"
54
android:layout_height="match_parent">
65

7-
<fragment
6+
<FrameLayout
87
android:id="@+id/map_fragment_map"
98
android:name="com.google.android.gms.maps.MapFragment"
109
android:layout_width="match_parent"
1110
android:layout_height="match_parent"
12-
android:layout_above="@+id/fragment_map_icons"
13-
tools:context="tech.zafrani.companionforpubg.activities.MainActivity"/>
11+
android:layout_above="@+id/fragment_map_icons"/>
1412

1513

1614
<LinearLayout

app/src/main/res/layout/fragment_news.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3-
android:orientation="vertical"
4-
android:layout_width="match_parent"
5-
android:layout_height="match_parent">
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
android:background="@color/primary"
6+
android:orientation="vertical">
67

78
<android.support.v7.widget.RecyclerView
89
android:id="@+id/fragment_news_recyclerview"

0 commit comments

Comments
 (0)