Skip to content

Commit

Permalink
added notify before time
Browse files Browse the repository at this point in the history
  • Loading branch information
FazziCLAY committed Dec 30, 2021
1 parent 48c965f commit d0fe6a5
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 1 deletion.
1 change: 1 addition & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void notificationTick() {
notificationData.sub = getString(R.string.mainNotification_lesson_sub_ending);
}

} else if (state.isRest()) {
} else if (state.isRest() && selectedLocalSchedule.getTimeBeforeStartLesson() <= settingsProvider.getNotifyBeforeTime()) {
isNotificationVisible = true;
notificationData.isProgress = false;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ru.fazziclay.schoolguide.android.activity.settings;

import android.app.TimePickerDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
Expand All @@ -23,6 +24,7 @@
import ru.fazziclay.schoolguide.data.settings.NotificationClickAction;
import ru.fazziclay.schoolguide.data.settings.SettingsProvider;
import ru.fazziclay.schoolguide.databinding.ActivitySettingsBinding;
import ru.fazziclay.schoolguide.util.TimeUtil;

public class SettingsActivity extends AppCompatActivity {
ActivitySettingsBinding binding;
Expand Down Expand Up @@ -85,6 +87,12 @@ private void initLayout() {
binding.isSyncDeveloperSchedule.setChecked(false);
}
});

binding.notifyBeforeTime.setOnClickListener(ignore -> timePicker(settingsProvider.getNotifyBeforeTime(), getString(R.string.settings_notifyBeforeTime_title), seconds -> {
settingsProvider.setNotifyBeforeTime(seconds);
initNotifyBeforeTimeText();
}));
initNotifyBeforeTimeText();
}

private void initNotificationClickActionSpinner() {
Expand Down Expand Up @@ -131,4 +139,23 @@ public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l)
});
}
}

private void initNotifyBeforeTimeText() {
binding.notifyBeforeTime.setText(getString(R.string.settings_notifyBeforeTime, TimeUtil.secondsToHumanTime(settingsProvider.getNotifyBeforeTime(), true)));
}

interface TimePickedInterface {
void run(int seconds);
}

private void timePicker(int defaultTime, String dialogTitle, TimePickedInterface pickedInterface) {
TimePickerDialog timePickerDialog = new TimePickerDialog(this,
(timePicker, hour, minute) -> {
int seconds = (hour*60*60) + minute*60;
pickedInterface.run(seconds);
}, TimeUtil.getHoursInSeconds(defaultTime), TimeUtil.getMinutesInSeconds(defaultTime), true);

timePickerDialog.setMessage(dialogTitle);
timePickerDialog.show();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ public class Settings extends BaseData {
List<Integer> versionsHistory = new ArrayList<>();
boolean isSyncDeveloperSchedule = false;
NotificationStyle notificationStyle = new NotificationStyle();
int notifyBeforeTime = 3*60*60;
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,15 @@ public void setSyncDeveloperSchedule(boolean syncDeveloperSchedule) {
public NotificationStyle getNotificationStyle() {
return getSettings().notificationStyle;
}


public int getNotifyBeforeTime() {
return getSettings().notifyBeforeTime;
}

public void setNotifyBeforeTime(int notifyBeforeTime) {
getSettings().notifyBeforeTime = notifyBeforeTime;
save();
}

}
12 changes: 12 additions & 0 deletions app/src/main/res/layout/activity_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,17 @@
android:background="#0C0C0C"
android:layout_margin="4sp"
tools:ignore="SpeakableTextPresentCheck" />

<TextView
android:id="@+id/notifyBeforeTime"
android:background="?attr/textViewButtonBackgroundColor"
android:layout_width="match_parent"
android:layout_height="40sp"
android:layout_margin="2sp"
android:gravity="center"
android:textColor="?attr/textViewButtonTextColor"
android:textAllCaps="false"
android:textSize="20sp"
android:text="@string/settings_notifyBeforeTime" />
</LinearLayout>
</ScrollView>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,6 @@
<string name="settings_selectedLocalSchedule">Selected schedule</string>
<string name="settings_isVibration">Vibration</string>
<string name="settings_notificationStyle_clickAction">Notification Click Action</string>
<string name="settings_notifyBeforeTime">Начинать уведомлять за %s до</string>
<string name="settings_notifyBeforeTime_title">Начинать уведомлять за столько время до...</string>
</resources>

0 comments on commit d0fe6a5

Please sign in to comment.