Skip to content

Commit 107c11f

Browse files
committed
fix expiring settings bug
improve itemdetail navigation animation
1 parent acda4ce commit 107c11f

File tree

6 files changed

+25
-52
lines changed

6 files changed

+25
-52
lines changed

app/src/main/java/com/example/digitalrefrige/services/AlarmBroadcastReceiver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ public void onReceive(Context context, Intent intent) {
5252
if (expiringItems!= null && !expiringItems.isEmpty()) {
5353
if (intent.getAction().equals("NOTIFY")) {
5454
Intent mIntent = new Intent(context, MainActivity.class);
55-
PendingIntent mPendingIntent = PendingIntent.getActivity(context, 0, mIntent, PendingIntent.FLAG_UPDATE_CURRENT);
55+
PendingIntent mPendingIntent = PendingIntent.getActivity(context, 0, mIntent, PendingIntent.FLAG_MUTABLE);
5656
createNotificationChannel();
5757
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
5858
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID)
5959
.setSmallIcon(R.drawable.ic_document)
6060
.setContentTitle("Expiring")
61-
.setContentText("You have item(s) expiring in "+intervalString+" days")
61+
.setContentText("You have expiring item(s)")
6262
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
6363
.setContentIntent(mPendingIntent)
6464
.setAutoCancel(true);

app/src/main/java/com/example/digitalrefrige/viewModel/adapters/ItemListAdapter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ public void onBindViewHolder(@NonNull ItemHolder holder, int position) {
7373
*/
7474
class ItemHolder extends RecyclerView.ViewHolder {
7575
private TextView textViewName;
76-
private TextView textViewDescription;
76+
// private TextView textViewDescription;
7777
private TextView expireDate;
7878
private ImageView itemImage;
7979
private long itemID;
8080

8181
public ItemHolder(@NonNull ItemCardBinding binding) {
8282
super(binding.getRoot());
8383
textViewName = binding.textViewTitle;
84-
textViewDescription = binding.textViewDescription;
84+
// textViewDescription = binding.textViewDescription;
8585
expireDate = binding.textViewExpireDate;
8686
itemImage = binding.imageViewFoodPhoto;
8787

@@ -97,7 +97,7 @@ public ItemHolder(@NonNull ItemCardBinding binding) {
9797
public void bind(Item item) {
9898
// bond item content into to this holder
9999
textViewName.setText(item.getName());
100-
textViewDescription.setText(item.getDescription());
100+
// textViewDescription.setText(item.getDescription());
101101
expireDate.setText(Converters.dateToString(item.getExpireDate()));
102102
itemID = item.getItemId();
103103
String uri = item.getImgUrl();

app/src/main/java/com/example/digitalrefrige/views/itemList/ItemDetailActivity.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import androidx.fragment.app.Fragment;
2929
import androidx.lifecycle.Observer;
3030
import androidx.lifecycle.ViewModelProvider;
31+
import androidx.navigation.ActivityNavigator;
3132
import androidx.navigation.Navigation;
3233
import androidx.recyclerview.widget.GridLayoutManager;
3334
import androidx.recyclerview.widget.LinearLayoutManager;
@@ -334,6 +335,12 @@ protected void onPause() {
334335
nfcUtils.disableForegroundDispatch();
335336
}
336337

338+
@Override
339+
public void finish() {
340+
super.finish();
341+
ActivityNavigator.applyPopAnimationsToPendingTransition(this);
342+
}
343+
337344
@Override
338345
protected void onNewIntent(Intent intent) {
339346
super.onNewIntent(intent);

app/src/main/java/com/example/digitalrefrige/views/login/ExpireFragment.java

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import android.view.ViewGroup;
2424
import android.widget.CompoundButton;
2525
import android.widget.EditText;
26+
import android.widget.Toast;
2627

2728
import com.example.digitalrefrige.MainActivity;
2829
import com.example.digitalrefrige.R;
@@ -56,9 +57,6 @@ public void onBindEditText(@NonNull EditText editText) {
5657
editText.setInputType(InputType.TYPE_CLASS_NUMBER);
5758
}
5859
});
59-
if(PreferenceManager.getDefaultSharedPreferences(getActivity()).getBoolean("notifications",false)){
60-
dayExpireEditText.setVisible(true);
61-
}
6260
}
6361

6462
@Override
@@ -85,9 +83,6 @@ public void onPause() {
8583
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
8684
if (key.equals("notifications")) {
8785
if (sharedPreferences.getBoolean(key, false)){
88-
dayExpireEditText.setVisible(true);
89-
90-
Log.i("preference", "notification preference value was updated to: True");
9186
// Setting Alarm for daily notification
9287
alarmManager = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);
9388
// Set the alarm to start at approximately time.
@@ -96,15 +91,13 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
9691

9792
Intent alarmIntent = new Intent(getContext(), AlarmBroadcastReceiver.class);
9893
alarmIntent.setAction("NOTIFY");
99-
PendingIntent pendingIntent = PendingIntent.getBroadcast(getContext(), 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
94+
PendingIntent pendingIntent = PendingIntent.getBroadcast(getContext(), 0, alarmIntent, PendingIntent.FLAG_MUTABLE);
10095
alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),AlarmManager.INTERVAL_DAY, pendingIntent);
101-
}else {
102-
dayExpireEditText.setVisible(false);
96+
Toast.makeText(getContext(),"Notification enabled",Toast.LENGTH_SHORT).show();
10397
}
10498
}
10599
if (key.equals("expire_day")) {
106-
Log.i("preference", "notification preference value was updated to: "+sharedPreferences.getString(key,"7"));
107-
100+
Toast.makeText(getContext(),"Expiring deadline update to "+sharedPreferences.getString(key,"7"),Toast.LENGTH_SHORT).show();
108101
}
109102

110103

@@ -117,29 +110,4 @@ private void setCalendarHour(int hour, Calendar calendar){
117110
calendar.set(Calendar.SECOND, 0);
118111
calendar.set(Calendar.MILLISECOND, 0);
119112
}
120-
121-
// @Override
122-
// public View onCreateView(LayoutInflater inflater, ViewGroup container,
123-
// Bundle savedInstanceState) {
124-
// binding = FragmentExpireBinding.inflate(inflater, container, false);
125-
//
126-
// binding.switchNotification.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
127-
// @Override
128-
// public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
129-
// if (isChecked){
130-
// binding.notificationSettings.setVisibility(View.VISIBLE);
131-
// }else {
132-
// binding.notificationSettings.setVisibility(View.INVISIBLE);
133-
// }
134-
// }
135-
// });
136-
//
137-
// binding.confirmButton.setOnClickListener(new View.OnClickListener() {
138-
// @Override
139-
// public void onClick(View v) {
140-
//
141-
// }
142-
// });
143-
// return binding.getRoot();
144-
// }
145113
}

app/src/main/res/layout/item_card.xml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@
3737
android:text="title"
3838
android:textAppearance="@style/TextAppearance.AppCompat.Large" />
3939

40-
<TextView
41-
android:id="@+id/text_view_description"
42-
android:layout_width="wrap_content"
43-
android:layout_height="wrap_content"
44-
android:layout_below="@id/text_view_title"
45-
android:layout_marginLeft="76dp"
46-
android:text="Description" />
40+
<!-- <TextView-->
41+
<!-- android:id="@+id/text_view_description"-->
42+
<!-- android:layout_width="wrap_content"-->
43+
<!-- android:layout_height="wrap_content"-->
44+
<!-- android:layout_below="@id/text_view_title"-->
45+
<!-- android:layout_marginLeft="76dp"-->
46+
<!-- android:text="Description" />-->
4747
<androidx.cardview.widget.CardView
4848
android:layout_width="60dp"
4949
android:layout_height="60dp"

app/src/main/res/xml/preferences.xml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
<SwitchPreference
66
android:defaultValue="false"
77
android:key="notifications"
8-
android:title="Enable message notifications" />
8+
android:title="Notification" />
99
<EditTextPreference
10-
11-
app:isPreferenceVisible="false"
1210
android:defaultValue="3"
1311
android:key="expire_day"
14-
android:title="Set notification deadline"/>
12+
android:title="Set expiring deadline"/>
1513

1614
</PreferenceScreen>

0 commit comments

Comments
 (0)