Skip to content

Commit

Permalink
Alarm and notify fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Romidorka committed Apr 15, 2023
1 parent cbe9deb commit a3c7963
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.view.View;
import android.webkit.WebView;
import android.widget.ImageButton;
import android.widget.TextView;

import com.example.medicineremindernew.fragments.HomeFragment;
import com.example.medicineremindernew.R;
Expand All @@ -19,13 +20,21 @@ public class AlarmActivity extends AppCompatActivity {
public String fileName = "a2.html";
Ringtone ringtone;
ImageButton back;
TextView nameTextView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_alarm);
back=findViewById(R.id.imageButton);
Intent intent = new Intent(this, HomeFragment.class);

back=findViewById(R.id.imageButton);
nameTextView = findViewById(R.id.textView);

Bundle extras = getIntent().getExtras();
String name = extras.getString("name");
nameTextView.setText(name);

Intent intent = new Intent(this, HomeFragment.class);
back.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Expand All @@ -34,6 +43,7 @@ public void onClick(View view) {
finish();
}
});

Uri notificationUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
ringtone = RingtoneManager.getRingtone(this, notificationUri);
if (ringtone == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,20 @@ public void refresh(){
String times = cursor.getString(12);


System.out.println("ID: " + id);
System.out.println("Name: " + name);
System.out.println("Value: " + value);
System.out.println("Dosage: " + dosage);
System.out.println("Date 1: " + date1);
System.out.println("Date 2: " + date2);
System.out.println("Time 1: " + time1);
System.out.println("Time 2: " + time2);
System.out.println("Time 3: " + time3);
System.out.println("Time 4: " + time4);
System.out.println("Time 5: " + time5);
System.out.println("Time 6: " + time6);
System.out.println("Times : " + times);
System.out.println();
// System.out.println("ID: " + id);
// System.out.println("Name: " + name);
// System.out.println("Value: " + value);
// System.out.println("Dosage: " + dosage);
// System.out.println("Date 1: " + date1);
// System.out.println("Date 2: " + date2);
// System.out.println("Time 1: " + time1);
// System.out.println("Time 2: " + time2);
// System.out.println("Time 3: " + time3);
// System.out.println("Time 4: " + time4);
// System.out.println("Time 5: " + time5);
// System.out.println("Time 6: " + time6);
// System.out.println("Times : " + times);
// System.out.println();

add_alarm(new Pill(id, name, value, dosage, date1, date2, time1));
add_alarm(new Pill(id, name, value, dosage, date1, date2, time2));
Expand Down Expand Up @@ -130,7 +130,7 @@ void add_alarm(Pill pill){
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

AlarmManager.AlarmClockInfo alarmClockInfo = new AlarmManager.AlarmClockInfo(alarm_calendar.getTimeInMillis(), getAlarmInfoPendingIntent());
alarmManager.setAlarmClock(alarmClockInfo, getAlarmActionPendingIntent());
alarmManager.setAlarmClock(alarmClockInfo, getAlarmActionPendingIntent(pill.name));
}
}

Expand All @@ -144,8 +144,9 @@ private PendingIntent getAlarmInfoPendingIntent() {
}
}

private PendingIntent getAlarmActionPendingIntent() {
private PendingIntent getAlarmActionPendingIntent(String name) {
Intent intent = new Intent(context, AlarmActivity.class);
intent.putExtra("name", name);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
return PendingIntent.getActivity(context, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
pillsManager.setListener((pills) -> {
System.out.println("PILLS CHANGED");
pillAdapter.notifyDataSetChanged();
alarmController.refresh();
onCalendarItem(db);
pillAdapter.notifyDataSetChanged();
return null;
Expand All @@ -152,7 +151,7 @@ public void onCalendarItem(SQLiteDatabase db) {
int length = testCursor.getCount();
System.out.println("selectedDate " + selectedDate);
ArrayList<PillsView> arrayList = new ArrayList<PillsView>();
pillAdapter = new PillSimpleAdapter(getContext(), arrayList);
pillAdapter = new PillSimpleAdapter(getActivity(), arrayList);
pillList.setAdapter(pillAdapter);
for (int i = 1; i <= length; i++) {

Expand Down Expand Up @@ -186,7 +185,7 @@ public void onCalendarItem(SQLiteDatabase db) {
testCursor.moveToNext();

}

alarmController.refresh();
}
// @Override
// public void onDestroy() {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/activity_alarm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
android:layout_height="wrap_content"
android:layout_below="@id/imageButton"
android:layout_marginTop="250dp"
android:textSize="32sp"
android:text="Время" />
android:textSize="42sp"
android:text="Боярошник" />
<RelativeLayout
android:id="@+id/rl2"
android:layout_width="300dp"
Expand Down

0 comments on commit a3c7963

Please sign in to comment.