Skip to content
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

Alireza - UI for Case Study 2 Aggregate Stats #141

Merged
merged 10 commits into from
Apr 6, 2024
Merged
43 changes: 43 additions & 0 deletions .idea/navEditor.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ android {
buildFeatures {
viewBinding true
buildConfig true
dataBinding true
}

androidResources {
Expand Down Expand Up @@ -111,6 +112,10 @@ android {
}
}

viewBinding{
enabled = true
}

applicationVariants.configureEach { variant ->
variant.resValue "string", "applicationId", variant.applicationId

Expand All @@ -125,6 +130,9 @@ android {
}

dependencies {
implementation 'androidx.activity:activity:1.8.0'
implementation 'androidx.navigation:navigation-fragment:2.7.7'
implementation 'androidx.navigation:navigation-ui:2.7.7'
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.4'

implementation 'androidx.appcompat:appcompat:1.6.1'
Expand Down
15 changes: 13 additions & 2 deletions src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,30 @@ limitations under the License.

<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

<queries>
<intent>
<action android:name="android.intent.action.TTS_SERVICE" />
</intent>
</queries>

<application
android:name=".Startup"
android:allowBackup="true"
android:fullBackupContent="@xml/backup_rules_30_lower"
android:dataExtractionRules="@xml/backup_rules_31_higher"
android:enableOnBackInvokedCallback="true"
android:fullBackupContent="@xml/backup_rules_30_lower"
android:hardwareAccelerated="true"
android:hasFragileUserData="false"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/OpenTracksTheme">

<activity
android:name=".ui.aggregatedStatistics.SeasonStats.RunAndChairStatActivity"
android:exported="false" />
<activity
android:name=".ui.aggregatedStatistics.SeasonStats.SeasonStatActivity"
android:exported="false" />
<activity
android:name=".publicapi.StartRecording"
android:exported="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ private void drawPointer(final Canvas canvas) {
break;
}
}
if (firstChartSeries != null && chartPoints.isEmpty()) {
if (firstChartValueSeries != null && !chartPoints.isEmpty()) {
int dx = getX(maxX) - pointer.getIntrinsicWidth() / 2;
double value = firstChartSeries.extractDataFromChartPoint(last);
int dy = getY(firstChartSeries, value) - pointer.getIntrinsicHeight();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class CustomContentProvider extends ContentProvider {
* It computes the average for heart rate, cadence and power (duration-based average) and the maximum for heart rate, cadence and power.
* Finally, it ignores manual pause (SEGMENT_START_MANUAL).
*/
private static final String SENSOR_STATS_QUERY =
private final static String SENSOR_STATS_QUERY
"WITH time_select as " +
"(SELECT t1." + TrackPointsColumns.TIME + " * (t1." + TrackPointsColumns.TYPE + " NOT IN (" + TrackPoint.Type.SEGMENT_START_MANUAL.type_db + ")) time_value " +
"FROM " + TrackPointsColumns.TABLE_NAME + " t1 " +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package de.dennisguse.opentracks.ui.aggregatedStatistics;

import android.content.Context;
import android.content.Intent;
import android.util.Pair;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
Expand All @@ -18,6 +20,7 @@
import de.dennisguse.opentracks.databinding.AggregatedStatsListItemBinding;
import de.dennisguse.opentracks.settings.PreferencesUtils;
import de.dennisguse.opentracks.settings.UnitSystem;
import de.dennisguse.opentracks.ui.aggregatedStatistics.SeasonStats.SeasonStatActivity;
import de.dennisguse.opentracks.util.StringUtils;

public class AggregatedStatisticsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
Expand Down Expand Up @@ -79,6 +82,15 @@ private class ViewHolder extends RecyclerView.ViewHolder {
public ViewHolder(AggregatedStatsListItemBinding viewBinding) {
super(viewBinding.getRoot());
this.viewBinding = viewBinding;

viewBinding.listOfSeasonsBtn234.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Context context = viewBinding.getRoot().getContext();
Intent intent = new Intent(context, SeasonStatActivity.class);
context.startActivity(intent);
}
});
}

public void setSpeed(AggregatedStatistics.AggregatedStatistic aggregatedStatistic) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package de.dennisguse.opentracks.ui.aggregatedStatistics.SeasonStats;

import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import de.dennisguse.opentracks.R;

/**
* A simple {@link Fragment} subclass.
* Use the {@link ChairsStatFragment#newInstance} factory method to
* create an instance of this fragment.
*/
public class ChairsStatFragment extends Fragment {

// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";

// TODO: Rename and change types of parameters
private String mParam1;
private String mParam2;

public ChairsStatFragment() {
// Required empty public constructor
}

/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @param param1 Parameter 1.
* @param param2 Parameter 2.
* @return A new instance of fragment ChairsStatFragment.
*/
// TODO: Rename and change types and number of parameters
public static ChairsStatFragment newInstance(String param1, String param2) {
ChairsStatFragment fragment = new ChairsStatFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_chairs_stat, container, false);
}

public void setArguments(Bundle args) {
this.setArguments(args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package de.dennisguse.opentracks.ui.aggregatedStatistics.SeasonStats;

import android.content.Intent;
import android.os.Bundle;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import de.dennisguse.opentracks.R;
import de.dennisguse.opentracks.databinding.ActivityRunAndChairStatBinding;

public class RunAndChairStatActivity extends AppCompatActivity {

ActivityRunAndChairStatBinding binding;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityRunAndChairStatBinding.inflate(getLayoutInflater());

EdgeToEdge.enable(this);
setContentView(binding.getRoot());
binding.bottomNavigationViewSeasons.setOnItemSelectedListener(item -> {
if (item.getItemId() == R.id.runs_frag) {
replaceFragment(new RunsStatFragment());
} else if (item.getItemId() == R.id.chairs_frag) {
replaceFragment(new ChairsStatFragment());
}
return true;
});

ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});
}

private void replaceFragment(Fragment fragment){
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
if (fragment instanceof RunsStatFragment) {
Intent intent = this.getIntent();
String seasonName = "123";
String days = "123";
String runs = "123";
String resort = "123";
String vertical_m = "123";
String distance = "123";
String active= "123";
String max_Speed="123";
String max_alt="123";
String tallestRun="123";
String longestRun="123";
if (intent != null){

seasonName = intent.getStringExtra("seasonName");
active = intent.getStringExtra("active");
days = Integer.toString(intent.getIntExtra("days",-1));
runs = Integer.toString(intent.getIntExtra("runs", -1));
resort = Integer.toString(intent.getIntExtra("resort", -1));
vertical_m = Integer.toString(intent.getIntExtra("vertical_m", -1));
max_alt = Integer.toString(intent.getIntExtra("max_alt", -1));
tallestRun = Integer.toString(intent.getIntExtra("tallestRun", -1));
distance = Integer.toString((int)intent.getDoubleExtra("distance", -1.0));
max_Speed = Integer.toString((int)intent.getDoubleExtra("max_Speed", -1.0));
longestRun = Integer.toString((int)intent.getDoubleExtra("longestRun", -1.0));

}
// Pass the string as an argument if the fragment is RunsStatFragment
fragmentTransaction.replace(R.id.frame_nav_season, ((RunsStatFragment) fragment).newInstance(seasonName, days, runs, resort, vertical_m, distance, active, max_Speed, max_alt, tallestRun, longestRun));
} else {
fragmentTransaction.replace(R.id.frame_nav_season, fragment);
}
fragmentTransaction.commit();
}
}
Loading