mirror of
https://github.com/russok/FitoTrack.git
synced 2025-10-29 00:32:11 -07:00
ListWorkoutActivity
This commit is contained in:
parent
cc39f89a77
commit
dcf53816a5
@ -9,7 +9,8 @@
|
|||||||
android:roundIcon="@mipmap/ic_launcher_round"
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/AppTheme">
|
android:theme="@style/AppTheme">
|
||||||
<activity android:name=".ListWorkoutsActivity"></activity>
|
<activity android:name=".RecordWorkoutActivity"></activity>
|
||||||
|
<activity android:name=".ListWorkoutsActivity" />
|
||||||
<activity android:name=".LauncherActivity">
|
<activity android:name=".LauncherActivity">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|||||||
@ -20,6 +20,7 @@
|
|||||||
package de.tadris.fitness;
|
package de.tadris.fitness;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
public class LauncherActivity extends Activity {
|
public class LauncherActivity extends Activity {
|
||||||
@ -28,5 +29,7 @@ public class LauncherActivity extends Activity {
|
|||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
|
|
||||||
|
startActivity(new Intent(this, ListWorkoutsActivity.class));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,7 +31,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import de.tadris.fitness.data.Workout;
|
import de.tadris.fitness.data.Workout;
|
||||||
|
|
||||||
public class ListWorkoutsActivity extends Activity {
|
public class ListWorkoutsActivity extends Activity implements WorkoutAdapter.WorkoutAdapterListener {
|
||||||
|
|
||||||
private RecyclerView listView;
|
private RecyclerView listView;
|
||||||
private RecyclerView.Adapter mAdapter;
|
private RecyclerView.Adapter mAdapter;
|
||||||
@ -50,8 +50,12 @@ public class ListWorkoutsActivity extends Activity {
|
|||||||
layoutManager= new LinearLayoutManager(this);
|
layoutManager= new LinearLayoutManager(this);
|
||||||
listView.setLayoutManager(layoutManager);
|
listView.setLayoutManager(layoutManager);
|
||||||
|
|
||||||
Instance.getInstance(this).db.workoutDao().getWorkouts();
|
workouts= Instance.getInstance(this).db.workoutDao().getWorkouts();
|
||||||
listView.setAdapter(new WorkoutAdapter());
|
listView.setAdapter(new WorkoutAdapter(workouts, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onItemClick(Workout workout) {
|
||||||
|
// TODO: open detail View
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,19 @@
|
|||||||
|
package de.tadris.fitness;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
public class RecordWorkoutActivity extends Activity {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_record_workout);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void onMenuCreate(){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,17 +1,69 @@
|
|||||||
package de.tadris.fitness;
|
package de.tadris.fitness;
|
||||||
|
|
||||||
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
public class WorkoutAdapter {
|
import de.tadris.fitness.data.Workout;
|
||||||
|
import de.tadris.fitness.util.UnitUtils;
|
||||||
|
|
||||||
|
public class WorkoutAdapter extends RecyclerView.Adapter<WorkoutAdapter.WorkoutViewHolder>{
|
||||||
|
|
||||||
|
|
||||||
public static class WorkoutViewHolder extends RecyclerView.ViewHolder{
|
public static class WorkoutViewHolder extends RecyclerView.ViewHolder{
|
||||||
|
|
||||||
|
View root;
|
||||||
|
TextView lengthText, timeText;
|
||||||
|
|
||||||
public WorkoutViewHolder(@NonNull View itemView) {
|
public WorkoutViewHolder(@NonNull View itemView) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
|
this.root= itemView;
|
||||||
|
lengthText= itemView.findViewById(R.id.workoutLength);
|
||||||
|
timeText= itemView.findViewById(R.id.workoutTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Workout[] workouts;
|
||||||
|
WorkoutAdapterListener listener;
|
||||||
|
|
||||||
|
public WorkoutAdapter(Workout[] workouts, WorkoutAdapterListener listener) {
|
||||||
|
this.workouts = workouts;
|
||||||
|
this.listener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WorkoutAdapter.WorkoutViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||||
|
// create a new view
|
||||||
|
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.view_workout, parent, false);
|
||||||
|
return new WorkoutViewHolder(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Replace the contents of a view (invoked by the layout manager)
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(WorkoutViewHolder holder, final int position) {
|
||||||
|
holder.lengthText.setText(workouts[position].length + "km");
|
||||||
|
holder.timeText.setText(UnitUtils.getHourMinuteTime(workouts[position].getTime()));
|
||||||
|
holder.root.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
listener.onItemClick(workouts[position]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the size of your dataset (invoked by the layout manager)
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return workouts.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface WorkoutAdapterListener{
|
||||||
|
void onItemClick(Workout workout);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -38,5 +38,9 @@ public class Workout{
|
|||||||
public double avgPace;
|
public double avgPace;
|
||||||
public String workoutType;
|
public String workoutType;
|
||||||
|
|
||||||
|
public long getTime(){
|
||||||
|
return end - start;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
20
app/src/main/java/de/tadris/fitness/util/UnitUtils.java
Normal file
20
app/src/main/java/de/tadris/fitness/util/UnitUtils.java
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package de.tadris.fitness.util;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
public class UnitUtils {
|
||||||
|
|
||||||
|
public static String getHourMinuteTime(long time){
|
||||||
|
long seks= time / 1000;
|
||||||
|
long mins= seks / 60;
|
||||||
|
int hours= (int)mins / 60;
|
||||||
|
int remainingMinutes= (int)mins % 60;
|
||||||
|
|
||||||
|
if(hours > 0){
|
||||||
|
return hours + "h " + remainingMinutes + "m";
|
||||||
|
}else{
|
||||||
|
return remainingMinutes + "min";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
9
app/src/main/res/layout/activity_record_workout.xml
Normal file
9
app/src/main/res/layout/activity_record_workout.xml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
tools:context=".RecordWorkoutActivity">
|
||||||
|
|
||||||
|
</android.support.constraint.ConstraintLayout>
|
||||||
@ -1,3 +1,34 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent" android:layout_height="match_parent"/>
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/workoutLength"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="8km"
|
||||||
|
android:textSize="36sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/workoutTime"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="27min"
|
||||||
|
android:textColor="@color/textLighterBlack"
|
||||||
|
android:textSize="30sp" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
</LinearLayout>
|
||||||
7
app/src/main/res/menu/list_workout_menu.xml
Normal file
7
app/src/main/res/menu/list_workout_menu.xml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:showAsAction="always"
|
||||||
|
android:title="@string/workout_add" />
|
||||||
|
</menu>
|
||||||
@ -3,4 +3,5 @@
|
|||||||
<color name="colorPrimary">#008577</color>
|
<color name="colorPrimary">#008577</color>
|
||||||
<color name="colorPrimaryDark">#00574B</color>
|
<color name="colorPrimaryDark">#00574B</color>
|
||||||
<color name="colorAccent">#D81B60</color>
|
<color name="colorAccent">#D81B60</color>
|
||||||
|
<color name="textLighterBlack">#C8000000</color>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">FitoTrack</string>
|
<string name="app_name">FitoTrack</string>
|
||||||
|
<string name="workout_add">Add</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user