MeteoriteDB

Log | Files | Refs | README

commit 47c027315110f83194fcc07538cca340cb2e95e6
parent 303ad083d519d212d6bcec6b9e2c208a8ac580f3
Author: William Lindholm <william_lindholm@outlook.com>
Date:   Fri,  5 May 2023 01:57:58 +0200

Added sortingbuttons.

Diffstat:
Mapp/src/main/java/com/example/project_assignment/MainActivity.java | 49++++++++++++++++++++++++++++++++++++++++++++++---
Mapp/src/main/res/layout/activity_main.xml | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 97 insertions(+), 3 deletions(-)

diff --git a/app/src/main/java/com/example/project_assignment/MainActivity.java b/app/src/main/java/com/example/project_assignment/MainActivity.java @@ -16,10 +16,13 @@ import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.util.Log; +import android.view.View; import android.widget.Toast; import com.example.project_assignment.comparators.SortByLocation; +import com.example.project_assignment.comparators.SortByName; import com.example.project_assignment.comparators.SortByWeight; +import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; @@ -63,6 +66,49 @@ public class MainActivity extends AppCompatActivity implements JsonTask.JsonTask return; } locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); + + FloatingActionButton showSortingOptionsButton = findViewById(R.id.showSortingOptionsButton); + FloatingActionButton locationSortButton = findViewById(R.id.locationSortButton); + FloatingActionButton nameSortButton = findViewById(R.id.nameSortButton); + FloatingActionButton masSortButton = findViewById(R.id.masSortButton); + showSortingOptionsButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (locationSortButton.getVisibility() == View.VISIBLE) { + locationSortButton.setVisibility(View.INVISIBLE); + nameSortButton.setVisibility(View.INVISIBLE); + masSortButton.setVisibility(View.INVISIBLE); + } else { + locationSortButton.setVisibility(View.VISIBLE); + nameSortButton.setVisibility(View.VISIBLE); + masSortButton.setVisibility(View.VISIBLE); + } + } + }); + + locationSortButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Collections.sort(meteorites, new SortByLocation(MainActivity.this)); + adapter.notifyDataSetChanged(); + } + }); + + nameSortButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Collections.sort(meteorites, new SortByName()); + adapter.notifyDataSetChanged(); + } + }); + + masSortButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Collections.sort(meteorites, new SortByWeight()); + adapter.notifyDataSetChanged(); + } + }); } @Override @@ -94,9 +140,6 @@ public class MainActivity extends AppCompatActivity implements JsonTask.JsonTask preferenceEditor.putString("latitude", String.valueOf(location.getLatitude())); preferenceEditor.putString("longitude", String.valueOf(location.getLongitude())); preferenceEditor.apply(); - - Collections.sort(meteorites, new SortByLocation(MainActivity.this)); - adapter.notifyDataSetChanged(); } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml @@ -14,4 +14,55 @@ app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> + + <com.google.android.material.floatingactionbutton.FloatingActionButton + android:id="@+id/showSortingOptionsButton" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginBottom="32dp" + android:clickable="true" + app:layout_constraintBottom_toBottomOf="@+id/recyclerView" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintHorizontal_bias="0.923" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintVertical_bias="1.0" + app:srcCompat="@android:drawable/ic_menu_add" + android:contentDescription="Show sorting options" /> + + <com.google.android.material.floatingactionbutton.FloatingActionButton + android:id="@+id/locationSortButton" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginBottom="16dp" + android:clickable="true" + android:visibility="invisible" + app:layout_constraintBottom_toTopOf="@+id/showSortingOptionsButton" + app:layout_constraintEnd_toEndOf="@+id/showSortingOptionsButton" + app:srcCompat="@android:drawable/ic_menu_mylocation" + android:contentDescription="Sort by location" /> + + <com.google.android.material.floatingactionbutton.FloatingActionButton + android:id="@+id/nameSortButton" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginBottom="16dp" + android:clickable="true" + android:visibility="invisible" + app:layout_constraintBottom_toTopOf="@+id/locationSortButton" + app:layout_constraintEnd_toEndOf="@+id/showSortingOptionsButton" + app:srcCompat="@android:drawable/ic_menu_sort_alphabetically" + android:contentDescription="Sort by name" /> + + <com.google.android.material.floatingactionbutton.FloatingActionButton + android:id="@+id/masSortButton" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginBottom="16dp" + android:clickable="true" + android:visibility="invisible" + app:layout_constraintBottom_toTopOf="@+id/nameSortButton" + app:layout_constraintEnd_toEndOf="@+id/showSortingOptionsButton" + app:srcCompat="@android:drawable/ic_menu_sort_by_size" + android:contentDescription="Sort by mass" /> </androidx.constraintlayout.widget.ConstraintLayout> \ No newline at end of file