mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-14 05:59:26 +01:00
Add forward/backward buttons to charts
This commit is contained in:
parent
6ce486992a
commit
c1d024876d
@ -152,8 +152,12 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
||||
if (intentFilterActions != null) {
|
||||
mIntentFilterActions.addAll(Arrays.asList(intentFilterActions));
|
||||
}
|
||||
mIntentFilterActions.add(ChartsHost.DATE_NEXT);
|
||||
mIntentFilterActions.add(ChartsHost.DATE_PREV);
|
||||
mIntentFilterActions.add(ChartsHost.DATE_NEXT_DAY);
|
||||
mIntentFilterActions.add(ChartsHost.DATE_PREV_DAY);
|
||||
mIntentFilterActions.add(ChartsHost.DATE_NEXT_WEEK);
|
||||
mIntentFilterActions.add(ChartsHost.DATE_PREV_WEEK);
|
||||
mIntentFilterActions.add(ChartsHost.DATE_NEXT_MONTH);
|
||||
mIntentFilterActions.add(ChartsHost.DATE_PREV_MONTH);
|
||||
mIntentFilterActions.add(ChartsHost.REFRESH);
|
||||
}
|
||||
|
||||
@ -250,10 +254,18 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
||||
String action = intent.getAction();
|
||||
if (ChartsHost.REFRESH.equals(action)) {
|
||||
refresh();
|
||||
} else if (ChartsHost.DATE_NEXT.equals(action)) {
|
||||
handleDateNext(getStartDate(), getEndDate());
|
||||
} else if (ChartsHost.DATE_PREV.equals(action)) {
|
||||
handleDatePrev(getStartDate(), getEndDate());
|
||||
} else if (ChartsHost.DATE_NEXT_DAY.equals(action)) {
|
||||
handleDate(getStartDate(), getEndDate(),+1);
|
||||
} else if (ChartsHost.DATE_PREV_DAY.equals(action)) {
|
||||
handleDate(getStartDate(), getEndDate(),-1);
|
||||
} else if (ChartsHost.DATE_NEXT_WEEK.equals(action)) {
|
||||
handleDate(getStartDate(), getEndDate(),+7);
|
||||
} else if (ChartsHost.DATE_PREV_WEEK.equals(action)) {
|
||||
handleDate(getStartDate(), getEndDate(),-7);
|
||||
} else if (ChartsHost.DATE_NEXT_MONTH.equals(action)) {
|
||||
handleDate(getStartDate(), getEndDate(),+30);
|
||||
} else if (ChartsHost.DATE_PREV_MONTH.equals(action)) {
|
||||
handleDate(getStartDate(), getEndDate(),-30);
|
||||
}
|
||||
}
|
||||
|
||||
@ -263,31 +275,17 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
||||
*
|
||||
* @param startDate
|
||||
* @param endDate
|
||||
* @param Offset
|
||||
*/
|
||||
protected void handleDatePrev(Date startDate, Date endDate) {
|
||||
protected void handleDate(Date startDate, Date endDate, Integer Offset) {
|
||||
if (isVisibleInActivity()) {
|
||||
if (!shiftDates(startDate, endDate, -1)) {
|
||||
if (!shiftDates(startDate, endDate, Offset)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
refreshIfVisible();
|
||||
}
|
||||
|
||||
/**
|
||||
* Default implementation shifts the dates by one day, if visible
|
||||
* and calls #refreshIfVisible().
|
||||
*
|
||||
* @param startDate
|
||||
* @param endDate
|
||||
*/
|
||||
protected void handleDateNext(Date startDate, Date endDate) {
|
||||
if (isVisibleInActivity()) {
|
||||
if (!shiftDates(startDate, endDate, +1)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
refreshIfVisible();
|
||||
}
|
||||
|
||||
protected void refreshIfVisible() {
|
||||
if (isVisibleInActivity()) {
|
||||
|
@ -175,20 +175,52 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts
|
||||
}
|
||||
});
|
||||
|
||||
Button mPrevButton = findViewById(R.id.charts_previous);
|
||||
Button mPrevButton = findViewById(R.id.charts_previous_day);
|
||||
mPrevButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
handlePrevButtonClicked();
|
||||
handleButtonClicked(DATE_PREV_DAY);
|
||||
}
|
||||
});
|
||||
Button mNextButton = findViewById(R.id.charts_next);
|
||||
Button mNextButton = findViewById(R.id.charts_next_day);
|
||||
mNextButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
handleNextButtonClicked();
|
||||
handleButtonClicked(DATE_NEXT_DAY);
|
||||
}
|
||||
});
|
||||
|
||||
Button mPrevWeekButton = findViewById(R.id.charts_previous_week);
|
||||
mPrevWeekButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
handleButtonClicked(DATE_PREV_WEEK);
|
||||
}
|
||||
});
|
||||
Button mNextWeekButton = findViewById(R.id.charts_next_week);
|
||||
mNextWeekButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
handleButtonClicked(DATE_NEXT_WEEK);
|
||||
}
|
||||
});
|
||||
|
||||
Button mPrevMonthButton = findViewById(R.id.charts_previous_month);
|
||||
mPrevMonthButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
handleButtonClicked(DATE_PREV_MONTH);
|
||||
}
|
||||
});
|
||||
Button mNextMonthButton = findViewById(R.id.charts_next_month);
|
||||
mNextMonthButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
handleButtonClicked(DATE_NEXT_MONTH);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
private String formatDetailedDuration() {
|
||||
@ -229,12 +261,8 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts
|
||||
return mEndDate;
|
||||
}
|
||||
|
||||
private void handleNextButtonClicked() {
|
||||
LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(DATE_NEXT));
|
||||
}
|
||||
|
||||
private void handlePrevButtonClicked() {
|
||||
LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(DATE_PREV));
|
||||
private void handleButtonClicked(String Action) {
|
||||
LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(Action));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -23,8 +23,14 @@ import java.util.Date;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
|
||||
public interface ChartsHost {
|
||||
String DATE_PREV = ChartsActivity.class.getName().concat(".date_prev");
|
||||
String DATE_NEXT = ChartsActivity.class.getName().concat(".date_next");
|
||||
String DATE_PREV_DAY = ChartsActivity.class.getName().concat(".date_prev_day");
|
||||
String DATE_NEXT_DAY = ChartsActivity.class.getName().concat(".date_next_day");
|
||||
String DATE_PREV_WEEK = ChartsActivity.class.getName().concat(".date_prev_week");
|
||||
String DATE_NEXT_WEEK = ChartsActivity.class.getName().concat(".date_next_week");
|
||||
String DATE_PREV_MONTH = ChartsActivity.class.getName().concat(".date_prev_month");
|
||||
String DATE_NEXT_MONTH = ChartsActivity.class.getName().concat(".date_next_month");
|
||||
|
||||
|
||||
String REFRESH = ChartsActivity.class.getName().concat(".refresh");
|
||||
|
||||
GBDevice getDevice();
|
||||
|
@ -27,32 +27,70 @@
|
||||
app:tabMode="scrollable" />
|
||||
</nodomain.freeyourgadget.gadgetbridge.activities.charts.NonSwipeableViewPager>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/charts_date_bar"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="fill_horizontal"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/charts_text_date"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_horizontal"
|
||||
android:layout_weight="1"
|
||||
android:text="Today" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/charts_date_bar"
|
||||
android:id="@+id/charts_date_button_bar"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="fill_horizontal"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Button
|
||||
android:id="@+id/charts_previous"
|
||||
android:id="@+id/charts_previous_month"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="<" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/charts_text_date"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_horizontal"
|
||||
android:layout_weight="1"
|
||||
android:text="Today" />
|
||||
android:layout_height="wrap_content"
|
||||
android:text="<<<" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/charts_next"
|
||||
android:id="@+id/charts_previous_week"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="<<" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/charts_previous_day"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="<" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/charts_next_day"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:text=">" />
|
||||
<Button
|
||||
android:id="@+id/charts_next_week"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:text=">>" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/charts_next_month"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:text=">>>" />
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
Loading…
Reference in New Issue
Block a user