1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-28 12:56:49 +01:00

Add edit Sport Summary Name. Add filtering by this name.

This commit is contained in:
vanous 2020-08-24 00:09:10 +02:00
parent c990a4f6fc
commit 9b30369a88
11 changed files with 259 additions and 72 deletions

View File

@ -47,6 +47,10 @@ public abstract class AbstractListActivity<T> extends AbstractGBActivity {
this.itemAdapter.setDateToFilter(date); this.itemAdapter.setDateToFilter(date);
} }
public void setNameContainsFilter(String name){
this.itemAdapter.setNameContainsFilter(name);
}
public AbstractItemAdapter<T> getItemAdapter() { public AbstractItemAdapter<T> getItemAdapter() {
return itemAdapter; return itemAdapter;
} }

View File

@ -84,7 +84,11 @@ public class ActivitySummariesActivity extends AbstractListActivity<BaseActivity
int activityFilter=0; int activityFilter=0;
long dateFromFilter=0; long dateFromFilter=0;
long dateToFilter=0; long dateToFilter=0;
String nameContainsFilter;
boolean offscreen = true; boolean offscreen = true;
static final int ACTIVITY_FILTER=1;
static final int ACTIVITY_DETAIL=11;
private final BroadcastReceiver mReceiver = new BroadcastReceiver() { private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override @Override
@ -141,8 +145,9 @@ public class ActivitySummariesActivity extends AbstractListActivity<BaseActivity
bundle.putInt("activityFilter",activityFilter); bundle.putInt("activityFilter",activityFilter);
bundle.putLong("dateFromFilter",dateFromFilter); bundle.putLong("dateFromFilter",dateFromFilter);
bundle.putLong("dateToFilter",dateToFilter); bundle.putLong("dateToFilter",dateToFilter);
bundle.putString("nameContainsFilter",nameContainsFilter);
filterIntent.putExtras(bundle); filterIntent.putExtras(bundle);
startActivityForResult(filterIntent,1); startActivityForResult(filterIntent,ACTIVITY_FILTER);
return true; return true;
case R.id.activity_action_calculate_summary_stats: case R.id.activity_action_calculate_summary_stats:
processSummaryStatistics(); processSummaryStatistics();
@ -224,15 +229,21 @@ public class ActivitySummariesActivity extends AbstractListActivity<BaseActivity
@Override @Override
public void onActivityResult(int requestCode, int resultCode, Intent resultData) { public void onActivityResult(int requestCode, int resultCode, Intent resultData) {
super.onActivityResult(requestCode, resultCode, resultData); super.onActivityResult(requestCode, resultCode, resultData);
if (requestCode == 1 && resultData!=null) { if (requestCode == ACTIVITY_FILTER && resultData != null) {
activityFilter= resultData.getIntExtra("activityFilter",0); activityFilter = resultData.getIntExtra("activityFilter", 0);
dateFromFilter = resultData.getLongExtra("dateFromFilter",0); dateFromFilter = resultData.getLongExtra("dateFromFilter", 0);
dateToFilter = resultData.getLongExtra("dateToFilter",0); dateToFilter = resultData.getLongExtra("dateToFilter", 0);
setActivityKindFilter((int) activityFilter); nameContainsFilter = resultData.getStringExtra("nameContainsFilter");
setDateFromFilter((long) dateFromFilter); setActivityKindFilter(activityFilter);
setDateToFilter((long) dateToFilter); setDateFromFilter(dateFromFilter);
setDateToFilter(dateToFilter);
setNameContainsFilter(nameContainsFilter);
refresh(); refresh();
} }
if (requestCode == ACTIVITY_DETAIL) {
refresh();
}
} }
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -249,7 +260,7 @@ public class ActivitySummariesActivity extends AbstractListActivity<BaseActivity
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setItemAdapter(new ActivitySummariesAdapter(this, mGBDevice,activityFilter,dateFromFilter,dateToFilter)); setItemAdapter(new ActivitySummariesAdapter(this, mGBDevice,activityFilter,dateFromFilter,dateToFilter,nameContainsFilter));
getItemListView().setOnItemClickListener(new AdapterView.OnItemClickListener() { getItemListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override @Override
@ -416,12 +427,14 @@ public class ActivitySummariesActivity extends AbstractListActivity<BaseActivity
ActivitySummaryDetailIntent.putExtra("filter", activityFilter); ActivitySummaryDetailIntent.putExtra("filter", activityFilter);
ActivitySummaryDetailIntent.putExtra("dateFromFilter",dateFromFilter); ActivitySummaryDetailIntent.putExtra("dateFromFilter",dateFromFilter);
ActivitySummaryDetailIntent.putExtra("dateToFilter",dateToFilter); ActivitySummaryDetailIntent.putExtra("dateToFilter",dateToFilter);
ActivitySummaryDetailIntent.putExtra("nameContainsFilter",nameContainsFilter);
ActivitySummaryDetailIntent.putExtra(GBDevice.EXTRA_DEVICE, mGBDevice); ActivitySummaryDetailIntent.putExtra(GBDevice.EXTRA_DEVICE, mGBDevice);
startActivity(ActivitySummaryDetailIntent); startActivityForResult(ActivitySummaryDetailIntent,ACTIVITY_DETAIL);
} }
private void fetchTrackData() { private void fetchTrackData() {
if (mGBDevice.isInitialized() && !mGBDevice.isBusy()) { if (mGBDevice.isInitialized() && !mGBDevice.isBusy()) {
GBApplication.deviceService().onFetchRecordedData(RecordedDataTypes.TYPE_GPS_TRACKS); GBApplication.deviceService().onFetchRecordedData(RecordedDataTypes.TYPE_GPS_TRACKS);

View File

@ -16,13 +16,14 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. */ along with this program. If not, see <http://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.activities; package nodomain.freeyourgadget.gadgetbridge.activities;
import android.app.Activity;
import android.app.DatePickerDialog; import android.app.DatePickerDialog;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.Color; import android.graphics.Color;
import android.os.Bundle; import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
@ -30,8 +31,8 @@ import android.widget.AdapterView;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.Button;
import android.widget.DatePicker; import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
@ -48,7 +49,6 @@ import java.util.Objects;
import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.util.AndroidUtils;
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils; import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
@ -59,6 +59,7 @@ public class ActivitySummariesFilter extends AbstractGBActivity {
int activityFilter = 0; int activityFilter = 0;
long dateFromFilter = 0; long dateFromFilter = 0;
long dateToFilter = 0; long dateToFilter = 0;
String nameContainsFilter;
HashMap<String, Integer> activityKindMap = new HashMap<>(1); HashMap<String, Integer> activityKindMap = new HashMap<>(1);
int BACKGROUND_COLOR; int BACKGROUND_COLOR;
@ -78,12 +79,14 @@ public class ActivitySummariesFilter extends AbstractGBActivity {
activityFilter = bundle.getInt("activityFilter", 0); activityFilter = bundle.getInt("activityFilter", 0);
dateFromFilter = bundle.getLong("dateFromFilter", 0); dateFromFilter = bundle.getLong("dateFromFilter", 0);
dateToFilter = bundle.getLong("dateToFilter", 0); dateToFilter = bundle.getLong("dateToFilter", 0);
nameContainsFilter = bundle.getString("nameContainsFilter");
Context appContext = this.getApplicationContext(); Context appContext = this.getApplicationContext();
if (appContext instanceof GBApplication) { if (appContext instanceof GBApplication) {
setContentView(R.layout.sport_activity_filter); setContentView(R.layout.sport_activity_filter);
} }
BACKGROUND_COLOR = GBApplication.getBackgroundColor(appContext);; BACKGROUND_COLOR = GBApplication.getBackgroundColor(appContext);
;
//get spinner ready - assign data, set selected item... //get spinner ready - assign data, set selected item...
final Spinner filterKindSpinner = findViewById(R.id.select_kind); final Spinner filterKindSpinner = findViewById(R.id.select_kind);
@ -98,19 +101,39 @@ public class ActivitySummariesFilter extends AbstractGBActivity {
final TextView filterfromlabel = findViewById(R.id.textViewFromData); final TextView filterfromlabel = findViewById(R.id.textViewFromData);
final LinearLayout filterto = findViewById(R.id.filterto); final LinearLayout filterto = findViewById(R.id.filterto);
final TextView filtertolabel = findViewById(R.id.textViewToData); final TextView filtertolabel = findViewById(R.id.textViewToData);
final EditText nameContainsFilterdata = findViewById(R.id.textViewNameData);
nameContainsFilterdata.setBackgroundDrawable(null);
final Button reset_filter_button = findViewById(R.id.reset_filter_button); final Button reset_filter_button = findViewById(R.id.reset_filter_button);
final Button apply_filter_button = findViewById(R.id.apply_filter_button); final Button apply_filter_button = findViewById(R.id.apply_filter_button);
apply_filter_button.setBackgroundColor(this.getResources().getColor(R.color.accent)); apply_filter_button.setBackgroundColor(this.getResources().getColor(R.color.accent));
nameContainsFilterdata.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
}
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
}
public void onTextChanged(CharSequence s, int start,
int before, int count) {
nameContainsFilter = s.toString();
update_filter_fields();
}
});
reset_filter_button.setOnClickListener(new View.OnClickListener() { reset_filter_button.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
activityFilter = 0; activityFilter = 0;
dateFromFilter = 0; dateFromFilter = 0;
dateToFilter = 0; dateToFilter = 0;
nameContainsFilter = "";
filterKindSpinner.setSelection(0); filterKindSpinner.setSelection(0);
update_filter_fields(); update_filter_fields();
} }
@ -119,10 +142,16 @@ public class ActivitySummariesFilter extends AbstractGBActivity {
apply_filter_button.setOnClickListener(new View.OnClickListener() { apply_filter_button.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
String text = nameContainsFilterdata.getText().toString();
if (text != null && text.length() > 0) {
nameContainsFilter = text;
}
Intent intent = new Intent(); Intent intent = new Intent();
intent.putExtra("activityFilter", activityFilter); intent.putExtra("activityFilter", activityFilter);
intent.putExtra("dateFromFilter", dateFromFilter); intent.putExtra("dateFromFilter", dateFromFilter);
intent.putExtra("dateToFilter", dateToFilter); intent.putExtra("dateToFilter", dateToFilter);
intent.putExtra("nameContainsFilter", nameContainsFilter);
setResult(1, intent); setResult(1, intent);
finish(); finish();
} }
@ -167,6 +196,7 @@ public class ActivitySummariesFilter extends AbstractGBActivity {
TextView filterDateFromDataView = findViewById(R.id.textViewFromData); TextView filterDateFromDataView = findViewById(R.id.textViewFromData);
TextView filterDateToDataView = findViewById(R.id.textViewToData); TextView filterDateToDataView = findViewById(R.id.textViewToData);
Button reset_filter_button = findViewById(R.id.reset_filter_button); Button reset_filter_button = findViewById(R.id.reset_filter_button);
final EditText nameContainsFilterdata = findViewById(R.id.textViewNameData);
if (dateFromFilter > 0) { if (dateFromFilter > 0) {
filterDateFromDataView.setText(DateTimeUtils.formatDate(new Date(dateFromFilter))); filterDateFromDataView.setText(DateTimeUtils.formatDate(new Date(dateFromFilter)));
@ -187,8 +217,10 @@ public class ActivitySummariesFilter extends AbstractGBActivity {
filterDateFromDataView.setBackgroundColor(BACKGROUND_COLOR); filterDateFromDataView.setBackgroundColor(BACKGROUND_COLOR);
filterDateToDataView.setBackgroundColor(BACKGROUND_COLOR); filterDateToDataView.setBackgroundColor(BACKGROUND_COLOR);
} }
if (nameContainsFilter != null && !nameContainsFilter.equals(nameContainsFilterdata.getText().toString())) {
if (dateToFilter != 0 || dateFromFilter != 0 || activityFilter != 0) { nameContainsFilterdata.setText(nameContainsFilter);
}
if (dateToFilter != 0 || dateFromFilter != 0 || activityFilter != 0 || nameContainsFilterdata.length() > 0) {
reset_filter_button.setBackgroundColor(this.getResources().getColor(R.color.accent)); reset_filter_button.setBackgroundColor(this.getResources().getColor(R.color.accent));
} else { } else {
@ -220,6 +252,17 @@ public class ActivitySummariesFilter extends AbstractGBActivity {
}, currentDate.get(Calendar.YEAR), currentDate.get(Calendar.MONTH), currentDate.get(Calendar.DATE)).show(); }, currentDate.get(Calendar.YEAR), currentDate.get(Calendar.MONTH), currentDate.get(Calendar.DATE)).show();
} }
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// back button
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
public class CustomOnItemSelectedListener implements AdapterView.OnItemSelectedListener { public class CustomOnItemSelectedListener implements AdapterView.OnItemSelectedListener {
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
@ -234,15 +277,4 @@ public class ActivitySummariesFilter extends AbstractGBActivity {
} }
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// back button
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
} }

View File

@ -18,11 +18,14 @@
package nodomain.freeyourgadget.gadgetbridge.activities; package nodomain.freeyourgadget.gadgetbridge.activities;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.os.Bundle; import android.os.Bundle;
import android.text.InputType;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.Gravity; import android.view.Gravity;
import android.view.MenuItem; import android.view.MenuItem;
@ -30,6 +33,7 @@ import android.view.View;
import android.view.animation.Animation; import android.view.animation.Animation;
import android.view.animation.AnimationUtils; import android.view.animation.AnimationUtils;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TableLayout; import android.widget.TableLayout;
@ -49,6 +53,7 @@ import java.util.Date;
import java.util.Iterator; import java.util.Iterator;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.entities.BaseActivitySummary; import nodomain.freeyourgadget.gadgetbridge.entities.BaseActivitySummary;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
@ -62,7 +67,7 @@ import nodomain.freeyourgadget.gadgetbridge.util.SwipeEvents;
public class ActivitySummaryDetail extends AbstractGBActivity { public class ActivitySummaryDetail extends AbstractGBActivity {
private static final Logger LOG = LoggerFactory.getLogger(ActivitySummaryDetail.class); private static final Logger LOG = LoggerFactory.getLogger(ActivitySummaryDetail.class);
private GBDevice gbDevice;
private boolean show_raw_data = false; private boolean show_raw_data = false;
BaseActivitySummary currentItem = null; BaseActivitySummary currentItem = null;
@ -73,15 +78,20 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_summary_details); final Context appContext = this.getApplicationContext();
if (appContext instanceof GBApplication) {
setContentView(R.layout.activity_summary_details);
}
Intent intent = getIntent(); Intent intent = getIntent();
GBDevice gbDevice = intent.getParcelableExtra(GBDevice.EXTRA_DEVICE); gbDevice = intent.getParcelableExtra(GBDevice.EXTRA_DEVICE);
final int filter = intent.getIntExtra("filter", 0); final int filter = intent.getIntExtra("filter", 0);
final int position = intent.getIntExtra("position", 0); final int position = intent.getIntExtra("position", 0);
final long dateFromFilter = intent.getLongExtra("dateFromFilter", 0); final long dateFromFilter = intent.getLongExtra("dateFromFilter", 0);
final long dateToFilter = intent.getLongExtra("dateToFilter", 0); final long dateToFilter = intent.getLongExtra("dateToFilter", 0);
final String nameContainsFilter = intent.getStringExtra("nameContainsFilter");
final ActivitySummaryItems items = new ActivitySummaryItems(this, gbDevice, filter, dateFromFilter, dateToFilter); final ActivitySummaryItems items = new ActivitySummaryItems(this, gbDevice, filter, dateFromFilter, dateToFilter, nameContainsFilter);
final LinearLayout layout = findViewById(R.id.activity_summary_detail_relative_layout); final LinearLayout layout = findViewById(R.id.activity_summary_detail_relative_layout);
alternateColor = getAlternateColor(this); alternateColor = getAlternateColor(this);
@ -113,10 +123,11 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
makeSummaryContent(currentItem); makeSummaryContent(currentItem);
layout.startAnimation(animFadeRight); layout.startAnimation(animFadeRight);
}else{ } else {
layout.startAnimation(animBounceRight); layout.startAnimation(animBounceRight);
} }
} }
@Override @Override
public void onSwipeLeft() { public void onSwipeLeft() {
currentItem = items.getPrevItem(); currentItem = items.getPrevItem();
@ -124,7 +135,7 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
makeSummaryHeader(currentItem); makeSummaryHeader(currentItem);
makeSummaryContent(currentItem); makeSummaryContent(currentItem);
layout.startAnimation(animFadeLeft); layout.startAnimation(animFadeLeft);
}else{ } else {
layout.startAnimation(animBounceLeft); layout.startAnimation(animBounceLeft);
} }
} }
@ -141,7 +152,7 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
ImageView activity_icon = findViewById(R.id.item_image); ImageView activity_icon = findViewById(R.id.item_image);
activity_icon.setOnLongClickListener(new View.OnLongClickListener() { activity_icon.setOnLongClickListener(new View.OnLongClickListener() {
public boolean onLongClick(View v) { public boolean onLongClick(View v) {
show_raw_data=!show_raw_data; show_raw_data = !show_raw_data;
if (currentItem != null) { if (currentItem != null) {
makeSummaryHeader(currentItem); makeSummaryHeader(currentItem);
makeSummaryContent(currentItem); makeSummaryContent(currentItem);
@ -150,10 +161,45 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
} }
}); });
ImageView activity_summary_detail_edit_name_image = findViewById(R.id.activity_summary_detail_edit_name);
activity_summary_detail_edit_name_image.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final EditText input = new EditText(ActivitySummaryDetail.this);
input.setInputType(InputType.TYPE_CLASS_TEXT);
String name = currentItem.getName();
input.setText((name != null) ? name : "");
new AlertDialog.Builder(ActivitySummaryDetail.this) // TODO: very raw at this point, make better drawable layout, already started here: R.style.GadgetbridgeTheme_DialogTheme)
.setView(input)
.setCancelable(true)
.setTitle(ActivitySummaryDetail.this.getString(R.string.activity_summary_edit_name_title))
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String name = input.getText().toString();
currentItem.setName(name);
currentItem.update();
makeSummaryHeader(currentItem);
makeSummaryContent(currentItem);
}
})
.setNegativeButton(R.string.Cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// do nothing
}
})
.show();
}
});
} }
private void makeSummaryHeader(BaseActivitySummary item){ private void makeSummaryHeader(BaseActivitySummary item) {
//make view of data from main part of item //make view of data from main part of item
final String gpxTrack = item.getGpxTrack(); final String gpxTrack = item.getGpxTrack();
Button show_track_btn = findViewById(R.id.showTrack); Button show_track_btn = findViewById(R.id.showTrack);
@ -172,6 +218,7 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
}); });
} }
String activitykindname = ActivityKind.asString(item.getActivityKind(), getApplicationContext()); String activitykindname = ActivityKind.asString(item.getActivityKind(), getApplicationContext());
String activityname = item.getName();
Date starttime = item.getStartTime(); Date starttime = item.getStartTime();
Date endtime = item.getEndTime(); Date endtime = item.getEndTime();
String starttimeS = DateTimeUtils.formatDateTime(starttime); String starttimeS = DateTimeUtils.formatDateTime(starttime);
@ -183,6 +230,10 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
TextView activity_kind = findViewById(R.id.activitykind); TextView activity_kind = findViewById(R.id.activitykind);
activity_kind.setText(activitykindname); activity_kind.setText(activitykindname);
TextView activity_name = findViewById(R.id.activityname);
activity_name.setText(activityname);
TextView start_time = findViewById(R.id.starttime); TextView start_time = findViewById(R.id.starttime);
start_time.setText(starttimeS); start_time.setText(starttimeS);
TextView end_time = findViewById(R.id.endtime); TextView end_time = findViewById(R.id.endtime);
@ -239,7 +290,7 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
unit = "km_h"; unit = "km_h";
break; break;
case "seconds_m": case "seconds_m":
value = value * (1000/60); value = value * (1000 / 60);
unit = "minutes_km"; unit = "minutes_km";
break; break;
case "seconds_km": case "seconds_km":
@ -277,8 +328,6 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
} }
public static int getAlternateColor(Context context) { public static int getAlternateColor(Context context) {
TypedValue typedValue = new TypedValue(); TypedValue typedValue = new TypedValue();
Resources.Theme theme = context.getTheme(); Resources.Theme theme = context.getTheme();
@ -289,10 +338,10 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
private String getStringResourceByName(String aString) { private String getStringResourceByName(String aString) {
String packageName = getPackageName(); String packageName = getPackageName();
int resId = getResources().getIdentifier(aString, "string", packageName); int resId = getResources().getIdentifier(aString, "string", packageName);
if (resId==0){ if (resId == 0) {
//LOG.warn("SportsActivity " + "Missing string in strings:" + aString); //LOG.warn("SportsActivity " + "Missing string in strings:" + aString);
return aString; return aString;
}else{ } else {
return getString(resId); return getString(resId);
} }
} }
@ -308,4 +357,5 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
} }

View File

@ -71,6 +71,10 @@ public abstract class AbstractItemAdapter<T> extends ArrayAdapter<T> {
this.setDateToFilter(date); this.setDateToFilter(date);
} }
public void setNameContainsFilter(String name){
this.setNameContainsFilter(name);
}
@Override @Override
public View getView(int position, View view, ViewGroup parent) { public View getView(int position, View view, ViewGroup parent) {
T item = getItem(position); T item = getItem(position);

View File

@ -40,13 +40,15 @@ public class ActivitySummariesAdapter extends AbstractItemAdapter<BaseActivitySu
private int activityKindFilter; private int activityKindFilter;
long dateFromFilter=0; long dateFromFilter=0;
long dateToFilter=0; long dateToFilter=0;
String nameContainsFilter;
public ActivitySummariesAdapter(Context context, GBDevice device, int activityKindFilter, long dateFromFilter, long dateToFilter) { public ActivitySummariesAdapter(Context context, GBDevice device, int activityKindFilter, long dateFromFilter, long dateToFilter, String nameContainsFilter) {
super(context); super(context);
this.device = device; this.device = device;
this.activityKindFilter = activityKindFilter; this.activityKindFilter = activityKindFilter;
this.dateFromFilter=dateFromFilter; this.dateFromFilter=dateFromFilter;
this.dateToFilter=dateToFilter; this.dateToFilter=dateToFilter;
this.nameContainsFilter=nameContainsFilter;
loadItems(); loadItems();
} }
@ -74,6 +76,10 @@ public class ActivitySummariesAdapter extends AbstractItemAdapter<BaseActivitySu
qb.where( qb.where(
BaseActivitySummaryDao.Properties.EndTime.lt(new Date(dateToFilter))); BaseActivitySummaryDao.Properties.EndTime.lt(new Date(dateToFilter)));
} }
if (nameContainsFilter !=null && nameContainsFilter.length() > 0) {
qb.where(
BaseActivitySummaryDao.Properties.Name.like("%" + nameContainsFilter + "%"));
}
List<BaseActivitySummary> allSummaries = qb.build().list(); List<BaseActivitySummary> allSummaries = qb.build().list();
setItems(allSummaries, true); setItems(allSummaries, true);
@ -91,18 +97,26 @@ public class ActivitySummariesAdapter extends AbstractItemAdapter<BaseActivitySu
public void setDateToFilter(long date){ public void setDateToFilter(long date){
this.dateToFilter=date; this.dateToFilter=date;
} }
public void setNameContainsFilter(String name){
this.nameContainsFilter=name;
}
@Override @Override
protected String getName(BaseActivitySummary item) { protected String getName(BaseActivitySummary item) {
String name = item.getName(); String name = item.getName();
if (name != null && name.length() > 0) { if (name == null) name="";
return name; String gpxTrack = item.getGpxTrack();
String hasGps = " ";
if (gpxTrack != null) {
hasGps=" 🛰️ ";
} }
return ActivityKind.asString(item.getActivityKind(), getContext())+ hasGps + name;
}
@Override
protected String getDetails(BaseActivitySummary item) {
Date startTime = item.getStartTime(); Date startTime = item.getStartTime();
Long duration = (item.getEndTime().getTime() - item.getStartTime().getTime()); Long duration = (item.getEndTime().getTime() - item.getStartTime().getTime());
@ -111,21 +125,9 @@ public class ActivitySummariesAdapter extends AbstractItemAdapter<BaseActivitySu
return DateTimeUtils.formatDateTime(startTime) + " (" + DateTimeUtils.formatDurationHoursMinutes(duration, TimeUnit.MILLISECONDS) + ")"; return DateTimeUtils.formatDateTime(startTime) + " (" + DateTimeUtils.formatDurationHoursMinutes(duration, TimeUnit.MILLISECONDS) + ")";
} }
return "Unknown activity"; return "Unknown activity";
} }
@Override
protected String getDetails(BaseActivitySummary item) {
String gpxTrack = item.getGpxTrack();
String hasGps = "";
if (gpxTrack != null) {
hasGps=" 🛰️";
}
return ActivityKind.asString(item.getActivityKind(), getContext())+ hasGps;
}
@Override @Override
protected int getIcon(BaseActivitySummary item) { protected int getIcon(BaseActivitySummary item) {
return ActivityKind.getIconId(item.getActivityKind()); return ActivityKind.getIconId(item.getActivityKind());

View File

@ -18,13 +18,12 @@ public class ActivitySummaryItems {
long dateToFilter=0; long dateToFilter=0;
public ActivitySummaryItems(Context context, GBDevice device, int activityKindFilter, long dateFromFilter, long dateToFilter) { public ActivitySummaryItems(Context context, GBDevice device, int activityKindFilter, long dateFromFilter, long dateToFilter, String nameContainsFilter) {
this.device = device; this.device = device;
this.activityKindFilter = activityKindFilter; this.activityKindFilter = activityKindFilter;
this.dateFromFilter=dateFromFilter; this.dateFromFilter=dateFromFilter;
this.dateToFilter=dateToFilter; this.dateToFilter=dateToFilter;
this.itemsAdapter = new ActivitySummariesAdapter(context, device, activityKindFilter, dateFromFilter, dateToFilter); this.itemsAdapter = new ActivitySummariesAdapter(context, device, activityKindFilter, dateFromFilter, dateToFilter, nameContainsFilter);
} }
public BaseActivitySummary getItem(int position){ public BaseActivitySummary getItem(int position){

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_summary_detail_relative_layout" android:id="@+id/activity_summary_detail_relative_layout"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
@ -36,14 +37,42 @@
android:paddingEnd="8dp"> android:paddingEnd="8dp">
<TextView <LinearLayout
android:id="@+id/activitykind" android:layout_width="match_parent"
android:layout_width="wrap_content" android:layout_height="match_parent"
android:layout_height="wrap_content" android:orientation="horizontal">
android:fontFamily="sans-serif-black"
android:maxLines="1" <TextView
android:scrollHorizontally="false" android:id="@+id/activitykind"
android:textSize="18sp" /> android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-black"
android:maxLines="1"
android:paddingEnd="10dp"
android:scrollHorizontally="false"
android:textSize="18sp" />
<TextView
android:id="@+id/activityname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-black"
android:maxLines="1"
android:scrollHorizontally="false"
android:textSize="18sp" />
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1" />
<ImageView
android:id="@+id/activity_summary_detail_edit_name"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right"
android:layout_weight="0.1"
android:scaleType="fitEnd"
app:srcCompat="@android:drawable/ic_menu_edit" />
</LinearLayout>
<TableLayout <TableLayout
android:id="@+id/summaryHeader" android:id="@+id/summaryHeader"

View File

@ -27,6 +27,41 @@
android:spinnerMode="dropdown" android:spinnerMode="dropdown"
android:textAlignment="gravity" /> android:textAlignment="gravity" />
<LinearLayout
android:id="@+id/filtername"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/abc_spinner_textfield_background_material"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical"
android:paddingStart="10dp"
android:paddingEnd="4dp"
android:paddingBottom="20dp">
<TextView
android:id="@+id/textViewNamelabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/activity_filter_name_contains"
android:textAlignment="textStart"
android:textSize="18sp" />
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<EditText
android:id="@+id/textViewNameData"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:textAlignment="textStart"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout <LinearLayout
android:id="@+id/filterfrom" android:id="@+id/filterfrom"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -706,6 +706,7 @@
<string name="activity_type_unknown">Unknown activity</string> <string name="activity_type_unknown">Unknown activity</string>
<string name="activity_summaries">Sport Activities</string> <string name="activity_summaries">Sport Activities</string>
<string name="activity_summary_detail">Sport Activity Detail</string> <string name="activity_summary_detail">Sport Activity Detail</string>
<string name="activity_summary_edit_name_title">Edit name</string>
<string name="activity_type_biking">Biking</string> <string name="activity_type_biking">Biking</string>
<string name="activity_type_treadmill">Treadmill</string> <string name="activity_type_treadmill">Treadmill</string>
<string name="activity_type_exercise">Exercise</string> <string name="activity_type_exercise">Exercise</string>
@ -982,8 +983,10 @@
<string name="activity_filter_date_to">To</string> <string name="activity_filter_date_to">To</string>
<string name="activity_filter_reset_filter">Reset Filter</string> <string name="activity_filter_reset_filter">Reset Filter</string>
<string name="activity_filter_filter_title">Filter</string> <string name="activity_filter_filter_title">Filter</string>
<string name="activity_filter_name_contains">Name</string>
<string name="activity_filter_apply_filter">Apply Filter</string> <string name="activity_filter_apply_filter">Apply Filter</string>
<string name="activity_summaries_statistics">Statistics</string> <string name="activity_summaries_statistics">Statistics</string>
<!-- swim styles --> <!-- swim styles -->
<string name="breaststroke">Breaststroke</string> <string name="breaststroke">Breaststroke</string>
<string name="freestyle">Freestyle</string> <string name="freestyle">Freestyle</string>

View File

@ -66,4 +66,20 @@
<item name="android:windowBackground">@drawable/splash</item> <item name="android:windowBackground">@drawable/splash</item>
</style> </style>
<!-- initial start of work on a Dialog Alert popup, TODO: continue -->
<style name="GadgetbridgeTheme.DialogTheme">
<!-- Fill the screen -->
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<!-- No backgrounds, titles or window float
<item name="android:windowBackground">@null</item>
-->
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<!-- Just to prove it's working
<item name="android:background">#ff0000</item>
-->
</style>
</resources> </resources>