diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ActivitySummariesActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ActivitySummariesActivity.java index 678f8e74b..caceb102a 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ActivitySummariesActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ActivitySummariesActivity.java @@ -72,6 +72,7 @@ public class ActivitySummariesActivity extends AbstractListActivity activityKindMap = new LinkedHashMap<>(1); + int activityFilter=0; private final BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override @@ -130,7 +131,7 @@ public class ActivitySummariesActivity extends AbstractListActivity parent, View view, int pos,long id) { - setActivityKindFilter(activityKindMap.get(parent.getItemAtPosition(pos))); + activityFilter=activityKindMap.get(parent.getItemAtPosition(pos)); + setActivityKindFilter(activityFilter); refresh(); } @@ -317,16 +319,13 @@ public class ActivitySummariesActivity extends AbstractListActivity. */ package nodomain.freeyourgadget.gadgetbridge.activities; +import android.annotation.SuppressLint; import android.content.Intent; import android.graphics.Color; import android.graphics.Typeface; import android.os.Bundle; import android.view.Gravity; import android.view.View; +import android.view.animation.Animation; +import android.view.animation.AnimationUtils; import android.widget.Button; import android.widget.ImageView; +import android.widget.RelativeLayout; import android.widget.TableLayout; import android.widget.TableRow; import android.widget.TextView; @@ -43,26 +47,94 @@ import java.util.Iterator; import java.util.concurrent.TimeUnit; import nodomain.freeyourgadget.gadgetbridge.R; +import nodomain.freeyourgadget.gadgetbridge.entities.BaseActivitySummary; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind; +import nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryItems; import nodomain.freeyourgadget.gadgetbridge.util.AndroidUtils; import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils; import nodomain.freeyourgadget.gadgetbridge.util.GB; +import nodomain.freeyourgadget.gadgetbridge.util.SwipeEvents; public class ActivitySummaryDetail extends AbstractGBActivity { private static final Logger LOG = LoggerFactory.getLogger(ActivitySummaryDetail.class); private GBDevice mGBDevice; private JSONObject groupData = setGroups(); private boolean show_raw_data = false; + BaseActivitySummary currentItem = null; + @SuppressLint("ClickableViewAccessibility") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_summary_details); Intent intent = getIntent(); mGBDevice = intent.getParcelableExtra(GBDevice.EXTRA_DEVICE); + final int filter = intent.getIntExtra("filter",0); + final int position = intent.getIntExtra("position",0); + final ActivitySummaryItems items = new ActivitySummaryItems(this, mGBDevice, filter); + final RelativeLayout layout = findViewById(R.id.activity_summary_detail_relative_layout); - final String gpxTrack = intent.getStringExtra("GpxTrack"); + final Animation animFadein; + final Animation animFadeout; + animFadein = AnimationUtils.loadAnimation( + this, + R.anim.flyright); + animFadeout = AnimationUtils.loadAnimation( + this, + R.anim.flyleft); + + layout.setOnTouchListener(new SwipeEvents(this) { + @Override + public void onSwipeRight() { + currentItem = items.getNextItem(); + if (currentItem != null) { + makeSummaryHeader(currentItem); + makeSummaryContent(currentItem); + layout.startAnimation(animFadein); + + }else{ + GB.toast("No more items", Toast.LENGTH_SHORT,0); + } + } + @Override + public void onSwipeLeft() { + currentItem = items.getPrevItem(); + if (currentItem != null) { + makeSummaryHeader(currentItem); + makeSummaryContent(currentItem); + layout.startAnimation(animFadeout); + }else{ + GB.toast("No more items", Toast.LENGTH_SHORT,0); + } + } + }); + + currentItem = items.getItem(position); + if (currentItem != null) { + makeSummaryHeader(currentItem); + makeSummaryContent(currentItem); + } + + //allows long-press.switch of data being in raw form or recalculated + ImageView activity_icon = (ImageView) findViewById(R.id.item_image); + activity_icon.setOnLongClickListener(new View.OnLongClickListener() { + public boolean onLongClick(View v) { + show_raw_data=!show_raw_data; + if (currentItem != null) { + makeSummaryHeader(currentItem); + makeSummaryContent(currentItem); + } + return false; + } + }); + + + } + + private void makeSummaryHeader(BaseActivitySummary item){ + //make view of data from main part of item + final String gpxTrack = item.getGpxTrack(); Button show_track_btn = (Button) findViewById(R.id.showTrack); show_track_btn.setVisibility(View.GONE); @@ -78,15 +150,16 @@ public class ActivitySummaryDetail extends AbstractGBActivity { } }); } - String activitykindname = ActivityKind.asString(intent.getIntExtra("ActivityKind",0), getApplicationContext()); - Date starttime = (Date) intent.getSerializableExtra("StartTime"); - Date endtime = (Date) intent.getSerializableExtra("EndTime"); + String activitykindname = ActivityKind.asString(item.getActivityKind(), getApplicationContext()); + Date starttime = (Date) item.getStartTime(); + Date endtime = (Date) item.getEndTime(); String starttimeS = DateTimeUtils.formatDateTime(starttime); String endtimeS = DateTimeUtils.formatDateTime(endtime); String durationhms = DateTimeUtils.formatDurationHoursMinutes((endtime.getTime() - starttime.getTime()), TimeUnit.MILLISECONDS); ImageView activity_icon = (ImageView) findViewById(R.id.item_image); - activity_icon.setImageResource(ActivityKind.getIconId(intent.getIntExtra("ActivityKind",0))); + activity_icon.setImageResource(ActivityKind.getIconId(item.getActivityKind())); + TextView activity_kind = (TextView) findViewById(R.id.activitykind); activity_kind.setText(activitykindname); TextView start_time = (TextView) findViewById(R.id.starttime); @@ -96,37 +169,32 @@ public class ActivitySummaryDetail extends AbstractGBActivity { TextView activity_duration = (TextView) findViewById(R.id.duration); activity_duration.setText(durationhms); - JSONObject summaryData = null; - String sumData = intent.getStringExtra("SummaryData"); + } + + private void makeSummaryContent (BaseActivitySummary item){ + //make view of data from summaryData of item + + TableLayout fieldLayout = findViewById(R.id.summaryDetails); + fieldLayout.removeAllViews(); //remove old widgets + + JSONObject summarySubdata = null; + JSONObject data = null; + + String sumData = item.getSummaryData(); + if (sumData != null) { try { - summaryData = new JSONObject(sumData); + summarySubdata = new JSONObject(sumData); } catch (JSONException e) { LOG.error("SportsActivity", e); } } - if (summaryData == null) return; + if (summarySubdata == null) return; + data = makeSummaryList(summarySubdata); //make new list, grouped by groups - JSONObject listOfSummaries = makeSummaryList(summaryData); - makeSummaryContent(listOfSummaries); + if (data == null) return; - final JSONObject finalSummaryData = summaryData; - activity_icon.setOnLongClickListener(new View.OnLongClickListener() { - public boolean onLongClick(View v) { - show_raw_data=!show_raw_data; - TableLayout fieldLayout = findViewById(R.id.summaryDetails); - fieldLayout.removeAllViews(); - JSONObject listOfSummaries = makeSummaryList(finalSummaryData); - makeSummaryContent(listOfSummaries); - return false; - } - }); - - } - - private void makeSummaryContent (JSONObject data){ - //build view, use localized names Iterator keys = data.keys(); DecimalFormat df = new DecimalFormat("#.##"); @@ -136,7 +204,6 @@ public class ActivitySummaryDetail extends AbstractGBActivity { LOG.error("SportsActivity:" + key + ": " + data.get(key) + "\n"); JSONArray innerList = (JSONArray) data.get(key); - TableLayout fieldLayout = findViewById(R.id.summaryDetails); TableRow label_row = new TableRow(ActivitySummaryDetail.this); TextView label_field = new TextView(ActivitySummaryDetail.this); label_field.setTextSize(16); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/ActivitySummary.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/ActivitySummary.java index f3f14d69f..a9846c110 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/ActivitySummary.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/ActivitySummary.java @@ -27,6 +27,7 @@ import java.util.Date; * // TODO: split into separate entities? */ public interface ActivitySummary extends Serializable { + Long getId(); String getName(); Date getStartTime(); Date getEndTime(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/ActivitySummaryItems.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/ActivitySummaryItems.java new file mode 100644 index 000000000..f47be17a7 --- /dev/null +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/ActivitySummaryItems.java @@ -0,0 +1,57 @@ +package nodomain.freeyourgadget.gadgetbridge.model; + +import android.content.Context; + +import java.util.List; + +import nodomain.freeyourgadget.gadgetbridge.adapter.ActivitySummariesAdapter; +import nodomain.freeyourgadget.gadgetbridge.entities.BaseActivitySummary; +import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; + +public class ActivitySummaryItems { + private final GBDevice device; + private int activityKindFilter; + List allItems; + ActivitySummariesAdapter itemsAdapter; + private int current_position = 0; + + public ActivitySummaryItems(Context context, GBDevice device, int activityKindFilter) { + this.device = device; + this.activityKindFilter = activityKindFilter; + this.itemsAdapter = new ActivitySummariesAdapter(context, device, activityKindFilter); + } + + public BaseActivitySummary getItem(int position){ + current_position=position; + return itemsAdapter.getItem(position); + } + + public int getPosition(BaseActivitySummary item){ + return itemsAdapter.getPosition(item); + } + + public List getAllItems(){ + return itemsAdapter.getItems(); + } + + public BaseActivitySummary getNextItem(){ + if (current_position+1 < itemsAdapter.getCount()){ + current_position+=1; + return itemsAdapter.getItem(current_position); + } + return null; + } + + public BaseActivitySummary getPrevItem(){ + if (current_position-1 >= 0){ + current_position-=1; + return itemsAdapter.getItem(current_position); + } + return null; + } + + public int getCurrent_position(){ + return current_position; + } + +} diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/SwipeEvents.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/SwipeEvents.java new file mode 100644 index 000000000..c8e2c3d55 --- /dev/null +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/SwipeEvents.java @@ -0,0 +1,50 @@ +package nodomain.freeyourgadget.gadgetbridge.util; + +import android.content.Context; +import android.view.GestureDetector; +import android.view.MotionEvent; +import android.view.View; + +//simple swipe detector based on GestureDetector, inspired by https://stackoverflow.com/a/19506010 +public class SwipeEvents implements View.OnTouchListener { + + private final GestureDetector gestureDetector; + + public SwipeEvents(Context context) { + gestureDetector = new GestureDetector(context, new GestureListener()); + } + + public void onSwipeLeft() { + } + + public void onSwipeRight() { + } + + public boolean onTouch(View v, MotionEvent event) { + return gestureDetector.onTouchEvent(event); + } + private final class GestureListener extends GestureDetector.SimpleOnGestureListener { + + private static final int SWIPE_DISTANCE_THRESHOLD = 100; + private static final int SWIPE_VELOCITY_THRESHOLD = 100; + + @Override + public boolean onDown(MotionEvent e) { + return true; + } + + @Override + public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { + float distanceX = e2.getX() - e1.getX(); + float distanceY = e2.getY() - e1.getY(); + if (Math.abs(distanceX) > Math.abs(distanceY) && Math.abs(distanceX) > SWIPE_DISTANCE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) { + if (distanceX > 0) + onSwipeRight(); + else + onSwipeLeft(); + return true; + } + return false; + } + } +} \ No newline at end of file diff --git a/app/src/main/res/anim/flyleft.xml b/app/src/main/res/anim/flyleft.xml new file mode 100644 index 000000000..80f8e28ef --- /dev/null +++ b/app/src/main/res/anim/flyleft.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/anim/flyright.xml b/app/src/main/res/anim/flyright.xml new file mode 100644 index 000000000..63523f308 --- /dev/null +++ b/app/src/main/res/anim/flyright.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_summary_details.xml b/app/src/main/res/layout/activity_summary_details.xml index 1a7885aa7..9f064f22b 100644 --- a/app/src/main/res/layout/activity_summary_details.xml +++ b/app/src/main/res/layout/activity_summary_details.xml @@ -1,8 +1,11 @@ + android:layout_height="wrap_content"> + android:layout_height="match_parent"> + +