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) {
|
if (intentFilterActions != null) {
|
||||||
mIntentFilterActions.addAll(Arrays.asList(intentFilterActions));
|
mIntentFilterActions.addAll(Arrays.asList(intentFilterActions));
|
||||||
}
|
}
|
||||||
mIntentFilterActions.add(ChartsHost.DATE_NEXT);
|
mIntentFilterActions.add(ChartsHost.DATE_NEXT_DAY);
|
||||||
mIntentFilterActions.add(ChartsHost.DATE_PREV);
|
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);
|
mIntentFilterActions.add(ChartsHost.REFRESH);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,10 +254,18 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
|||||||
String action = intent.getAction();
|
String action = intent.getAction();
|
||||||
if (ChartsHost.REFRESH.equals(action)) {
|
if (ChartsHost.REFRESH.equals(action)) {
|
||||||
refresh();
|
refresh();
|
||||||
} else if (ChartsHost.DATE_NEXT.equals(action)) {
|
} else if (ChartsHost.DATE_NEXT_DAY.equals(action)) {
|
||||||
handleDateNext(getStartDate(), getEndDate());
|
handleDate(getStartDate(), getEndDate(),+1);
|
||||||
} else if (ChartsHost.DATE_PREV.equals(action)) {
|
} else if (ChartsHost.DATE_PREV_DAY.equals(action)) {
|
||||||
handleDatePrev(getStartDate(), getEndDate());
|
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 startDate
|
||||||
* @param endDate
|
* @param endDate
|
||||||
|
* @param Offset
|
||||||
*/
|
*/
|
||||||
protected void handleDatePrev(Date startDate, Date endDate) {
|
protected void handleDate(Date startDate, Date endDate, Integer Offset) {
|
||||||
if (isVisibleInActivity()) {
|
if (isVisibleInActivity()) {
|
||||||
if (!shiftDates(startDate, endDate, -1)) {
|
if (!shiftDates(startDate, endDate, Offset)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
refreshIfVisible();
|
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() {
|
protected void refreshIfVisible() {
|
||||||
if (isVisibleInActivity()) {
|
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() {
|
mPrevButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
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() {
|
mNextButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
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() {
|
private String formatDetailedDuration() {
|
||||||
@ -229,12 +261,8 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts
|
|||||||
return mEndDate;
|
return mEndDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleNextButtonClicked() {
|
private void handleButtonClicked(String Action) {
|
||||||
LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(DATE_NEXT));
|
LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(Action));
|
||||||
}
|
|
||||||
|
|
||||||
private void handlePrevButtonClicked() {
|
|
||||||
LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(DATE_PREV));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -23,8 +23,14 @@ import java.util.Date;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
|
|
||||||
public interface ChartsHost {
|
public interface ChartsHost {
|
||||||
String DATE_PREV = ChartsActivity.class.getName().concat(".date_prev");
|
String DATE_PREV_DAY = ChartsActivity.class.getName().concat(".date_prev_day");
|
||||||
String DATE_NEXT = ChartsActivity.class.getName().concat(".date_next");
|
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");
|
String REFRESH = ChartsActivity.class.getName().concat(".refresh");
|
||||||
|
|
||||||
GBDevice getDevice();
|
GBDevice getDevice();
|
||||||
|
@ -34,12 +34,6 @@
|
|||||||
android:gravity="fill_horizontal"
|
android:gravity="fill_horizontal"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/charts_previous"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="<" />
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/charts_text_date"
|
android:id="@+id/charts_text_date"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
@ -48,11 +42,55 @@
|
|||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:text="Today" />
|
android:text="Today" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
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
|
<Button
|
||||||
android:id="@+id/charts_next"
|
android:id="@+id/charts_previous_month"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="<<<" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
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:layout_height="wrap_content"
|
||||||
android:text=">" />
|
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>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
Loading…
Reference in New Issue
Block a user