From 1b770020ed9a6bc6a5d6eb375a097b5620d94d1c Mon Sep 17 00:00:00 2001 From: RemoMeijer Date: Mon, 4 Jan 2021 15:37:09 +0100 Subject: [PATCH] Added List button on Home --- app/src/main/assets/routes.json | 2 +- .../fragments/CouponFragment.java | 8 ++++++++ .../nextlocation/fragments/HomeFragment.java | 13 ++++++++++-- .../fragments/LocationDetailFragment.java | 16 +++++++++++++-- .../fragments/LocationFragment.java | 8 ++++++++ .../fragments/StatisticFragment.java | 2 ++ .../recyclerview/LocationAdapter.java | 6 +++--- app/src/main/res/layout/fragment_home.xml | 20 ++++++++++++++++++- app/src/main/res/layout/fragment_location.xml | 4 ++-- .../main/res/layout/fragment_statistic.xml | 10 ---------- 10 files changed, 68 insertions(+), 21 deletions(-) diff --git a/app/src/main/assets/routes.json b/app/src/main/assets/routes.json index 9c84f63..46c734f 100644 --- a/app/src/main/assets/routes.json +++ b/app/src/main/assets/routes.json @@ -3,7 +3,7 @@ "name": "rondje stad", "locations": [ { - "name": "kees kroket", + "name": "KesCrOkĂŠt breeda", "coordinates": "2.4654645,6.2342323", "description": "lekkere patatjes" } diff --git a/app/src/main/java/com/a1/nextlocation/fragments/CouponFragment.java b/app/src/main/java/com/a1/nextlocation/fragments/CouponFragment.java index 7d132ee..1faea7f 100644 --- a/app/src/main/java/com/a1/nextlocation/fragments/CouponFragment.java +++ b/app/src/main/java/com/a1/nextlocation/fragments/CouponFragment.java @@ -12,6 +12,7 @@ import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.ImageButton; import com.a1.nextlocation.R; import com.a1.nextlocation.data.Coupon; @@ -26,6 +27,7 @@ public class CouponFragment extends Fragment { private RecyclerView.LayoutManager layoutManager; private List couponList; private CouponAdapter couponAdapter; + private ImageButton imageButton; @Override public void onCreate(Bundle savedInstanceState) { @@ -40,6 +42,12 @@ public class CouponFragment extends Fragment { this.couponRecyclerView.setHasFixedSize(true); this.layoutManager = new LinearLayoutManager(this.getContext()); + this.imageButton = view.findViewById(R.id.couponBackButton); + this.imageButton.setOnClickListener(v -> { + StatisticFragment statisticFragment = new StatisticFragment(); + ((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, statisticFragment).addToBackStack(null).commit(); + }); + CouponListManager.INSTANCE.setContext(this.getContext()); CouponListManager.INSTANCE.load(); this.couponList = CouponListManager.INSTANCE.getCouponList(); diff --git a/app/src/main/java/com/a1/nextlocation/fragments/HomeFragment.java b/app/src/main/java/com/a1/nextlocation/fragments/HomeFragment.java index 8f5ba7d..ffcbc7c 100644 --- a/app/src/main/java/com/a1/nextlocation/fragments/HomeFragment.java +++ b/app/src/main/java/com/a1/nextlocation/fragments/HomeFragment.java @@ -13,12 +13,14 @@ import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.ImageButton; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentActivity; import com.a1.nextlocation.R; import com.a1.nextlocation.data.Route; @@ -42,6 +44,7 @@ import java.util.ArrayList; public class HomeFragment extends Fragment { private final String userAgent = "com.ai.nextlocation.fragments"; + private ImageButton imageButton; private MapView mapView; private final int REQUEST_PERMISSIONS_REQUEST_CODE = 1; private final String TAG = HomeFragment.class.getCanonicalName(); @@ -60,10 +63,16 @@ public class HomeFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - // Inflate the layout for this fragment - return inflater.inflate(R.layout.fragment_home, container, false); + View view = inflater.inflate(R.layout.fragment_home, container, false); + this.imageButton = view.findViewById(R.id.location_list_button); + this.imageButton.setOnClickListener(v -> { + LocationFragment locationFragment = new LocationFragment(); + ((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, locationFragment).addToBackStack(null).commit(); + }); + + return view; } @Override diff --git a/app/src/main/java/com/a1/nextlocation/fragments/LocationDetailFragment.java b/app/src/main/java/com/a1/nextlocation/fragments/LocationDetailFragment.java index ea2fae9..62b6313 100644 --- a/app/src/main/java/com/a1/nextlocation/fragments/LocationDetailFragment.java +++ b/app/src/main/java/com/a1/nextlocation/fragments/LocationDetailFragment.java @@ -3,15 +3,19 @@ package com.a1.nextlocation.fragments; import android.os.Bundle; import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentActivity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.ImageButton; import com.a1.nextlocation.R; public class LocationDetailFragment extends Fragment { + private ImageButton imageButton; + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -21,7 +25,15 @@ public class LocationDetailFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - // Inflate the layout for this fragment - return inflater.inflate(R.layout.fragment_location_detail, container, false); + + View view = inflater.inflate(R.layout.fragment_location_detail, container, false); +// +// this.imageButton = view.findViewById(R.id.detail_location_back_button); +// this.imageButton.setOnClickListener(v -> { +// LocationFragment locationFragment = new LocationFragment(); +// ((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, locationFragment).addToBackStack(null).commit(); +// }); + + return view; } } \ No newline at end of file diff --git a/app/src/main/java/com/a1/nextlocation/fragments/LocationFragment.java b/app/src/main/java/com/a1/nextlocation/fragments/LocationFragment.java index 26c53a2..3a026d5 100644 --- a/app/src/main/java/com/a1/nextlocation/fragments/LocationFragment.java +++ b/app/src/main/java/com/a1/nextlocation/fragments/LocationFragment.java @@ -10,6 +10,7 @@ import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.ImageButton; import com.a1.nextlocation.R; import com.a1.nextlocation.data.Location; @@ -25,6 +26,7 @@ public class LocationFragment extends Fragment { private LocationAdapter locationAdapter; private RecyclerView.LayoutManager layoutManager; private List locationList; + private ImageButton imageButton; @Override public void onCreate(Bundle savedInstanceState) { @@ -40,6 +42,12 @@ public class LocationFragment extends Fragment { this.locationRecyclerView.setHasFixedSize(true); this.layoutManager = new LinearLayoutManager(this.getContext()); +// this.imageButton = view.findViewById(R.id.locationBackButton); +// this.imageButton.setOnClickListener(v -> { +// HomeFragment homeFragment = new HomeFragment(); +// ((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, homeFragment).addToBackStack(null).commit(); +// }); + LocationListManager.INSTANCE.setContext(this.getContext()); LocationListManager.INSTANCE.load(); this.locationList = LocationListManager.INSTANCE.getLocationList(); diff --git a/app/src/main/java/com/a1/nextlocation/fragments/StatisticFragment.java b/app/src/main/java/com/a1/nextlocation/fragments/StatisticFragment.java index ad3f5e7..a4080c5 100644 --- a/app/src/main/java/com/a1/nextlocation/fragments/StatisticFragment.java +++ b/app/src/main/java/com/a1/nextlocation/fragments/StatisticFragment.java @@ -10,6 +10,7 @@ import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; @@ -23,6 +24,7 @@ import java.util.List; public class StatisticFragment extends Fragment { private List couponList; + private ImageView imageButton; @Override diff --git a/app/src/main/java/com/a1/nextlocation/recyclerview/LocationAdapter.java b/app/src/main/java/com/a1/nextlocation/recyclerview/LocationAdapter.java index 9148dc7..b39feae 100644 --- a/app/src/main/java/com/a1/nextlocation/recyclerview/LocationAdapter.java +++ b/app/src/main/java/com/a1/nextlocation/recyclerview/LocationAdapter.java @@ -40,6 +40,7 @@ public class LocationAdapter extends RecyclerView.Adapter + android:layout_height="match_parent"> + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_location.xml b/app/src/main/res/layout/fragment_location.xml index b64896e..7f03472 100644 --- a/app/src/main/res/layout/fragment_location.xml +++ b/app/src/main/res/layout/fragment_location.xml @@ -14,11 +14,11 @@ android:layout_margin="9dp" android:text="Locations" android:textSize="20sp" - app:layout_constraintStart_toEndOf="@id/routeBackButton" + app:layout_constraintStart_toEndOf="@id/locationBackButton" app:layout_constraintTop_toTopOf="parent" /> - -