Skip to content

Commit

Permalink
v18 (#170)
Browse files Browse the repository at this point in the history
* Update butterknife to latest version

* Update eventbus to latest version

* Update firebase to latest version

* Update appcompat library to latest version

* Update material library to latest version

* Update to latest buildToolsVersion

* Replace old crashlytics with firebase crashlytics

* Add dark mode (#157)

This PR adds dark mode for devices running Android Q and later.

Co-authored-by: John Slavick <[email protected]>

* Force Dark Mode Tweaks (#160)

* Disable forced dark mode on StreakWidget

* Add isAppInDarkMode

* Change moving average color to be more legible in dark mode

* Only call `setForceDarkAllowed` if device SDK >= 29

* Disable force dark mode on food and tweak history calendars and set card background to gray

* Revert "Force Dark Mode Tweaks (#160)"

This reverts commit 6171f76.

* Revert "Add dark mode (#157)"

This reverts commit 13aefb5.

* Polish Translation with some correlated Android/Apple updates (#166)

* [email protected]:marc-medley/daily-dozen-android.git

* Add Polish translation. Sets Chickpeas/Garbanzo Beans as a single synonym item. Treats arrays with <item>@.../... as translatable="false".

* Update gradle and third party libs

* Update version

* Remove outdated version history

* Remove randomly selected icon for notification

* Add multiple reminders (#168)

* WIP

* Implement getNextAlarmTimeInMillis

* Migrate old reminder setting

* Disable reminder notification when last reminder time is deleted

* Fix migrate old setting

* Change to use png notification icon to prevent crashes on lower android sdk versions

* Change FAB `layout_width` to `wrap_content`

* Remove Nullable attribute

* Add support for 24 hour time format when specifying reminder times

* Remove vibrate and sound options for the notification

* Update dependencies

* versionName 18

* Replace ButterKnife with View Binding (#169)

* Enable View Binding

* Update AboutActivity to use View Binding

* Update DailyReminderSettingsActivity to use View Binding

* Update DebugActivity to use View Binding

* Update FoodHistoryActivity to use View Binding

* Update FoodInfoActivity to use View Binding

* Update MainActivity to use View Binding

* Update ServingsHistoryActivity to use View Binding

* Update TweakHistoryActivity to use View Binding

* Update TweakInfoActivity to use View Binding

* Update TweakServingsHistoryActivity to use View Binding

* Update WeightHistoryActivity to use View Binding

* Remove ButterKnife strings

* Update to use View Binding

* Update to use View Binding

* Update to use View Binding

* Remove ButterKnife library

* Fix incorrect view binding

* Remove some about text

* Remove unused context

* Simplify code with lambda expressions
  • Loading branch information
slavick authored Apr 3, 2021
1 parent f9c6c2c commit 123a187
Show file tree
Hide file tree
Showing 55 changed files with 837 additions and 1,692 deletions.
10 changes: 5 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ android {
compileSdkVersion 29
buildToolsVersion '29.0.3'

viewBinding.enabled = true

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
Expand All @@ -37,8 +39,8 @@ android {
minSdkVersion 16
targetSdkVersion 29
vectorDrawables.useSupportLibrary = true
versionCode 55
versionName "17.3"
versionCode 56
versionName "18"
}
buildTypes {
debug {
Expand All @@ -65,7 +67,7 @@ android {

dependencies {
implementation 'com.google.firebase:firebase-analytics:18.0.2'
implementation 'com.google.firebase:firebase-crashlytics:17.3.1'
implementation 'com.google.firebase:firebase-crashlytics:17.4.1'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.android.material:material:1.3.0'
Expand All @@ -75,8 +77,6 @@ dependencies {
implementation('com.joanzapata.iconify:android-iconify-fontawesome:2.2.2') { exclude group: "com.android.support" }
implementation('com.github.PhilJay:MPAndroidChart:v2.2.5') { exclude group: "com.android.support" }
implementation('org.greenrobot:eventbus:3.2.0') { exclude group: "com.android.support" }
implementation 'com.jakewharton:butterknife:10.2.3'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.3'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.jakewharton.timber:timber:4.7.1'
}
1 change: 0 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
Expand Down
24 changes: 5 additions & 19 deletions app/src/main/java/org/nutritionfacts/dailydozen/Common.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
Expand Down Expand Up @@ -83,25 +82,12 @@ public static void askUserToRateApp(final Context context) {
new AlertDialog.Builder(context)
.setTitle(R.string.dialog_ask_user_to_rate_app_title)
.setMessage(R.string.dialog_ask_user_to_rate_app_message)
.setPositiveButton(R.string.rate_now, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Common.openPlayStore(context);
dialog.dismiss();
}
})
.setNegativeButton(R.string.not_now, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
})
.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
userIsBeingAsked = false;
}
.setPositiveButton(R.string.rate_now, (dialog, which) -> {
Common.openPlayStore(context);
dialog.dismiss();
})
.setNegativeButton(R.string.not_now, (dialog, which) -> dialog.dismiss())
.setOnDismissListener(dialog -> userIsBeingAsked = false)
.create().show();

userIsBeingAsked = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,16 @@
import org.nutritionfacts.dailydozen.BuildConfig;
import org.nutritionfacts.dailydozen.Common;
import org.nutritionfacts.dailydozen.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import org.nutritionfacts.dailydozen.databinding.ActivityAboutBinding;

public class AboutActivity extends AppCompatActivity {
@BindView(R.id.about_welcome)
protected TextView tvWelcome;
@BindView(R.id.about_header)
protected TextView tvHeader;
@BindView(R.id.about_version)
protected TextView tvVersion;
@BindView(R.id.about_text)
protected TextView tvAbout;
private ActivityAboutBinding binding;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);
ButterKnife.bind(this);
binding = ActivityAboutBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());

initActionBar();

Expand Down Expand Up @@ -62,8 +53,8 @@ private void initActionBar() {
}

private void initHeader() {
tvHeader.setText(getString(R.string.app_name));
tvVersion.setText(getString(R.string.format_version, BuildConfig.VERSION_NAME));
binding.aboutHeader.setText(getString(R.string.app_name));
binding.aboutVersion.setText(getString(R.string.format_version, BuildConfig.VERSION_NAME));
}

private void initLinksInWelcome() {
Expand All @@ -72,8 +63,8 @@ private void initLinksInWelcome() {

initLink(welcomeText, ssb, R.string.title_how_not_to_die, R.string.url_how_not_to_die);

tvWelcome.setMovementMethod(LinkMovementMethod.getInstance());
tvWelcome.setText(ssb, TextView.BufferType.SPANNABLE);
binding.aboutWelcome.setMovementMethod(LinkMovementMethod.getInstance());
binding.aboutWelcome.setText(ssb, TextView.BufferType.SPANNABLE);
}

private void initLinksInText() {
Expand All @@ -84,13 +75,12 @@ private void initLinksInText() {
initLink(aboutText, ssb, R.string.name_john_slavick, R.string.url_john_slavick);
initLink(aboutText, ssb, R.string.library_activeandroid, R.string.url_activeandroid);
initLink(aboutText, ssb, R.string.library_android_iconify, R.string.url_android_iconify);
initLink(aboutText, ssb, R.string.library_butterknife, R.string.url_butterknife);
initLink(aboutText, ssb, R.string.library_eventbus, R.string.url_eventbus);
initLink(aboutText, ssb, R.string.library_likeanimation, R.string.url_likeanimation);
initLink(aboutText, ssb, R.string.library_mpandroidchart, R.string.url_mpandroidchart);

tvAbout.setMovementMethod(LinkMovementMethod.getInstance());
tvAbout.setText(ssb, TextView.BufferType.SPANNABLE);
binding.aboutText.setMovementMethod(LinkMovementMethod.getInstance());
binding.aboutText.setText(ssb, TextView.BufferType.SPANNABLE);
}

private void initLink(final String textToSearch, final SpannableStringBuilder ssb, final int textToFindId, final int urlId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,53 @@
import android.app.TimePickerDialog;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TimePicker;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.SwitchCompat;
import androidx.recyclerview.widget.LinearLayoutManager;

import org.nutritionfacts.dailydozen.R;
import org.greenrobot.eventbus.Subscribe;
import org.nutritionfacts.dailydozen.adapter.DailyReminderAdapter;
import org.nutritionfacts.dailydozen.controller.Bus;
import org.nutritionfacts.dailydozen.controller.Prefs;
import org.nutritionfacts.dailydozen.databinding.ActivityNotificationSettingsBinding;
import org.nutritionfacts.dailydozen.event.ReminderRemovedEvent;
import org.nutritionfacts.dailydozen.model.pref.UpdateReminderPref;
import org.nutritionfacts.dailydozen.util.DateUtil;
import org.nutritionfacts.dailydozen.util.NotificationUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnCheckedChanged;
import butterknife.OnClick;

public class DailyReminderSettingsActivity extends AppCompatActivity implements TimePickerDialog.OnTimeSetListener {
@BindView(R.id.daily_reminder_switch)
protected SwitchCompat dailyReminderSwitch;
@BindView(R.id.daily_reminder_config_container)
protected ViewGroup vgDailyReminderConfig;
@BindView(R.id.daily_reminder_time)
protected Button tvTime;
@BindView(R.id.daily_reminder_vibrate_container)
protected ViewGroup vgVibrate;
@BindView(R.id.daily_reminder_vibrate)
protected SwitchCompat vibrateSwitch;
@BindView(R.id.daily_reminder_play_sound)
protected SwitchCompat playSoundSwitch;
private ActivityNotificationSettingsBinding binding;

protected DailyReminderAdapter reminderAdapter;

private UpdateReminderPref updateReminderPref;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_notification_settings);
ButterKnife.bind(this);
binding = ActivityNotificationSettingsBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
init();
}

@Override
protected void onResume() {
super.onResume();
Bus.register(this);
}

@Override
protected void onPause() {
super.onPause();
Bus.unregister(this);
}

private void init() {
onDailyReminderSwitchToggled();
onAddReminderClicked();

updateReminderPref = Prefs.getInstance(this).getUpdateReminderPref();

if (updateReminderPref != null) {
Expand All @@ -56,83 +60,80 @@ private void init() {
}

private void initUpdateReminderPrefConfig() {
dailyReminderSwitch.setChecked(true);
vgDailyReminderConfig.setVisibility(View.VISIBLE);
binding.dailyReminderSwitch.setChecked(true);
toggleReminderViews();

if (updateReminderPref == null) {
updateReminderPref = new UpdateReminderPref();
}

tvTime.setText(updateReminderPref.toString());

initVibratePref();

playSoundSwitch.setChecked(updateReminderPref.isPlaySound());
reminderAdapter = new DailyReminderAdapter(updateReminderPref.getReminderTimes());
binding.reminderTimesRecyclerView.setLayoutManager(new LinearLayoutManager(this));
binding.reminderTimesRecyclerView.setAdapter(reminderAdapter);

setUpdateReminder();
}

private void initVibratePref() {
vgVibrate.setVisibility(NotificationUtil.deviceHasVibrator(this) ? View.VISIBLE : View.GONE);
vibrateSwitch.setChecked(updateReminderPref.isVibrate());
}

private void setUpdateReminder() {
Prefs.getInstance(this).setUpdateReminderPref(updateReminderPref);

NotificationUtil.setAlarmForUpdateReminderNotification(this, updateReminderPref);
}

private void disableUpdateReminderPref() {
dailyReminderSwitch.setChecked(false);
vgDailyReminderConfig.setVisibility(View.GONE);
binding.dailyReminderSwitch.setChecked(false);
toggleReminderViews();

NotificationUtil.cancelAlarmForUpdateReminderNotification(this, updateReminderPref);

Prefs.getInstance(this).removeUpdateReminderPref();
}

@OnClick({R.id.daily_reminder_set_time, R.id.daily_reminder_time})
public void onUpdateReminderSetTimeClicked() {
new TimePickerDialog(
DailyReminderSettingsActivity.this,
DailyReminderSettingsActivity.this,
updateReminderPref.getHourOfDay(),
updateReminderPref.getMinute(),
false)
.show();
public void onDailyReminderSwitchToggled() {
binding.dailyReminderSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
if (isChecked) {
initUpdateReminderPrefConfig();
} else {
disableUpdateReminderPref();
}
});
}

@OnCheckedChanged(R.id.daily_reminder_switch)
public void onDailyReminderSwitchToggled(final boolean isChecked) {
vgDailyReminderConfig.setVisibility(isChecked ? View.VISIBLE : View.GONE);

if (isChecked) {
initUpdateReminderPrefConfig();
} else {
disableUpdateReminderPref();
}
private void toggleReminderViews() {
binding.reminderTimesContainer.setVisibility(binding.dailyReminderSwitch.isChecked() ? View.VISIBLE : View.GONE);
binding.addReminderButton.setVisibility(binding.dailyReminderSwitch.isChecked() ? View.VISIBLE : View.GONE);
}

@OnCheckedChanged(R.id.daily_reminder_vibrate)
public void onVibrateSwitchToggled(final boolean isChecked) {
updateReminderPref.setVibrate(isChecked);
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
updateReminderPref.setHourOfDay(hourOfDay);
updateReminderPref.setMinute(minute);

updateReminderPref.addReminderTime(getApplicationContext(), hourOfDay, minute);

initUpdateReminderPrefConfig();
}

@OnCheckedChanged(R.id.daily_reminder_play_sound)
public void onPlaySoundSwitchToggled(final boolean isChecked) {
updateReminderPref.setPlaySound(isChecked);

initUpdateReminderPrefConfig();
public void onAddReminderClicked() {
binding.addReminderButton.setOnClickListener(v -> new TimePickerDialog(
DailyReminderSettingsActivity.this,
DailyReminderSettingsActivity.this,
updateReminderPref.getHourOfDay(),
updateReminderPref.getMinute(),
DateUtil.is24HourTimeFormat(getApplicationContext()))
.show());
}

@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
updateReminderPref.setHourOfDay(hourOfDay);
updateReminderPref.setMinute(minute);
@Subscribe
public void onEvent(ReminderRemovedEvent event) {
updateReminderPref.deleteReminderTime(event.getAdapterPosition());
reminderAdapter.setReminders(updateReminderPref.getReminderTimes());

initUpdateReminderPrefConfig();
if (updateReminderPref.getReminderTimes().isEmpty()) {
// Disable the notification if the last reminder time has been removed
disableUpdateReminderPref();
} else {
setUpdateReminder();
}
}
}
Loading

0 comments on commit 123a187

Please sign in to comment.