-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds a new Statistics Page #940
Open
akshat22
wants to merge
32
commits into
fields_modifications
Choose a base branch
from
issue/871
base: fields_modifications
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 28 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
f365ecb
intial files for statistics page
akshat22 1e4473f
added adapter pattern and recycler view
akshat22 3b3afa7
added date selection for start of season
akshat22 4bd67a4
resized grid to 2x4
akshat22 0854378
replaced date picker dialog with month and year toggle
akshat22 3dea62b
added dialogs and toast messages for indivdual stats
akshat22 1f1a057
fixed logic of 'fields' and 'entries'
akshat22 274f8c6
save individual statistics card
akshat22 34e41b1
export image with FB logo
akshat22 22d33ce
added snackbar
akshat22 5fec245
Merge branch 'main' of https://github.com/PhenoApps/Field-Book into i…
akshat22 2106b56
Merge branch 'main' of https://github.com/PhenoApps/Field-Book into i…
akshat22 0116aaa
improved UI for card view
akshat22 a66adf5
added calendar style heatmap dialog
akshat22 cb50c1d
changed horizontal heatmap dialog to vertical fragment
akshat22 6a2f1ad
added loading stats dialog
akshat22 cac3b98
replaced long press to export with a button
akshat22 a4a4ce9
fixed binding issue with text and highlight color
akshat22 bae95fe
updated dialogs and toasts
akshat22 2f99449
changed month number to name in month view cards
akshat22 9dfe91f
added scroll to first and last date functionality
akshat22 32bbc7e
added counter button to the heatmap
akshat22 64a072c
date range picker added for heatmap
akshat22 237ae2c
added tab layout and total section
akshat22 1c1b905
resolved merge conflicts
akshat22 65fa946
swapped field and plot icons
akshat22 3880c83
replaced statistics card with adapter-recycler view pattern
akshat22 8230658
change card title when exporting
akshat22 fdc6834
fixed crashing on single date selection
akshat22 508647a
modularized code
akshat22 9f80988
fixed heatmap color issue and changed icons
akshat22 aa449df
fixed merge conflicts
akshat22 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
157 changes: 157 additions & 0 deletions
157
app/src/main/java/com/fieldbook/tracker/activities/StatisticsActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
package com.fieldbook.tracker.activities; | ||
|
||
import android.app.AlertDialog; | ||
import android.os.Bundle; | ||
import android.os.Handler; | ||
import android.os.Looper; | ||
import android.view.Menu; | ||
import android.view.MenuItem; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.appcompat.widget.Toolbar; | ||
import androidx.recyclerview.widget.LinearLayoutManager; | ||
import androidx.recyclerview.widget.RecyclerView; | ||
|
||
import com.fieldbook.tracker.R; | ||
import com.fieldbook.tracker.adapters.StatisticsAdapter; | ||
import com.fieldbook.tracker.database.DataHelper; | ||
import com.fieldbook.tracker.database.models.ObservationModel; | ||
import com.fieldbook.tracker.dialogs.StatisticsCalendarFragment; | ||
import com.google.android.material.tabs.TabLayout; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.TreeSet; | ||
|
||
import javax.inject.Inject; | ||
|
||
import dagger.hilt.android.AndroidEntryPoint; | ||
|
||
@AndroidEntryPoint | ||
public class StatisticsActivity extends ThemedActivity { | ||
public static String TAG = "Statistics Activity"; | ||
@Inject | ||
DataHelper database; | ||
List<String> seasons = new ArrayList<>(); | ||
RecyclerView rvStatisticsCard; | ||
private int toggleVariable = 0; // 0: Total, 1: Year, 2: Month | ||
AlertDialog loadingDialog; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_statistics); | ||
Toolbar toolbar = findViewById(R.id.toolbar); | ||
setSupportActionBar(toolbar); | ||
|
||
if (getSupportActionBar() != null) { | ||
getSupportActionBar().setTitle(getString(R.string.settings_statistics)); | ||
getSupportActionBar().getThemedContext(); | ||
getSupportActionBar().setDisplayHomeAsUpEnabled(true); | ||
getSupportActionBar().setHomeButtonEnabled(true); | ||
} | ||
|
||
rvStatisticsCard = findViewById(R.id.statistics_card_rv); | ||
rvStatisticsCard.setLayoutManager(new LinearLayoutManager(this)); | ||
|
||
TabLayout tabLayout = findViewById(R.id.tab_layout); | ||
|
||
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.stats_tab_layout_total))); | ||
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.stats_tab_layout_year))); | ||
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.stats_tab_layout_month))); | ||
|
||
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { | ||
@Override | ||
public void onTabSelected(TabLayout.Tab tab) { | ||
switch (tab.getPosition()) { | ||
case 0: toggleVariable = 0; break; | ||
case 1: toggleVariable = 1; break; | ||
case 2: toggleVariable = 2; break; | ||
} | ||
loadData(); | ||
} | ||
|
||
@Override | ||
public void onTabUnselected(TabLayout.Tab tab) { | ||
|
||
} | ||
|
||
@Override | ||
public void onTabReselected(TabLayout.Tab tab) { | ||
|
||
} | ||
}); | ||
|
||
AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.AppAlertDialog); | ||
builder.setView(getLayoutInflater().inflate(R.layout.dialog_loading, null)); | ||
loadingDialog = builder.create(); | ||
|
||
loadData(); | ||
|
||
} | ||
|
||
@Override | ||
public boolean onCreateOptionsMenu(Menu menu) { | ||
getMenuInflater().inflate(R.menu.menu_statistics, menu); | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean onOptionsItemSelected(@NonNull MenuItem item) { | ||
|
||
final int heatmapId = R.id.stats_heatmap; | ||
|
||
int itemId = item.getItemId(); | ||
|
||
if (itemId == heatmapId) { | ||
StatisticsCalendarFragment calendarFragment = new StatisticsCalendarFragment(this); | ||
getSupportFragmentManager().beginTransaction().replace(android.R.id.content, calendarFragment).addToBackStack(null).commit(); | ||
} else if (itemId == android.R.id.home) { | ||
onBackPressed(); | ||
} | ||
return super.onOptionsItemSelected(item); | ||
} | ||
|
||
@NonNull | ||
public DataHelper getDatabase() { | ||
return database; | ||
} | ||
|
||
/** | ||
* Displays the loading screen and loads the statistics asynchronously | ||
*/ | ||
public void loadData() { | ||
loadingDialog.show(); | ||
|
||
Handler mainHandler = new Handler(Looper.getMainLooper()); | ||
mainHandler.post(this::setSeasons); | ||
} | ||
|
||
public void setSeasons() { | ||
|
||
if (toggleVariable == 0) { | ||
seasons.clear(); | ||
seasons.add(""); | ||
} else { | ||
Set<String> uniqueSeasons = new TreeSet<>(Comparator.reverseOrder()); | ||
|
||
ObservationModel[] observations = database.getAllObservations(); | ||
for (ObservationModel observation : observations) { | ||
String timeStamp = observation.getObservation_time_stamp(); | ||
if (toggleVariable == 1) | ||
uniqueSeasons.add(timeStamp.substring(0, 4)); | ||
else | ||
uniqueSeasons.add(timeStamp.substring(0, 7)); | ||
} | ||
|
||
seasons = new ArrayList<>(uniqueSeasons); | ||
} | ||
rvStatisticsCard.setAdapter(new StatisticsAdapter(this, seasons)); | ||
|
||
// Dismiss the dialog after the recycler view loads all its children | ||
rvStatisticsCard.post(() -> loadingDialog.dismiss()); | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be best to define an enum here