Commit 70ae3039 authored by Thiago Mendes's avatar Thiago Mendes

Merge branch 'fix-layout' into 'master'

Fix layout

See merge request !37
parents ae3569ed be11039b
Pipeline #128366773 passed with stage
in 23 seconds
*.iml
.gradle
app/release
/local.properties
/.idea/caches
/.idea/codeStyles
......
......@@ -2,7 +2,7 @@
<project version="4">
<component name="NullableNotNullManager">
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
<option name="myDefaultNotNull" value="androidx.annotation.NonNull" />
<option name="myNullables">
<value>
<list size="12">
......
......@@ -7,8 +7,8 @@ android {
applicationId "com.tmendes.birthdaydroid"
minSdkVersion 23
targetSdkVersion 29
versionCode 43
versionName '20200307_V43'
versionCode 45
versionName '20200321_V45'
}
buildTypes {
release {
......@@ -80,7 +80,6 @@ allprojects {
dependencies {
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
implementation fileTree(include: ['*.jar'], dir: 'libs')
api 'androidx.appcompat:appcompat:1.1.0'
api 'androidx.legacy:legacy-support-v4:1.0.0'
api 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
......
* V45
- Layout changes
- Do not show badge when contact has no year defined
- Shows current age on birthday
- Fix an issue with some contacts that were missing
* V43
- Fix Birthday List Order and Notification Messages
- Fix Notification in Advance
......
......@@ -22,6 +22,7 @@ import java.text.DateFormatSymbols;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.concurrent.TimeUnit;
......@@ -54,6 +55,7 @@ public class Contact {
private boolean ignore;
private boolean bornInFuture;
private boolean missingYearInfo;
public Contact(String key, String name, String photoURI,
String eventTypeLabel) {
......@@ -62,6 +64,7 @@ public class Contact {
this.photoURI = photoURI;
this.eventTypeLabel = eventTypeLabel;
this.dbID = -1;
this.missingYearInfo = false;
}
public String getZodiac() {
......@@ -92,10 +95,6 @@ public class Contact {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int getDaysOld() {
return daysOld;
}
......@@ -106,8 +105,6 @@ public class Contact {
public void setBornOn(Calendar bornOn) {
if (bornOn != null) {
boolean lateBDD = false;
this.bornOn = bornOn;
this.bornOn.set(Calendar.HOUR_OF_DAY, 0);
this.bornOn.set(Calendar.MINUTE, 0);
......@@ -139,7 +136,7 @@ public class Contact {
this.nextBirthday.set(Calendar.YEAR, now.get(Calendar.YEAR) + 1);
}
this.bornInFuture = this.bornOn.compareTo(now) >= 1;
this.bornInFuture = this.bornOn.compareTo(now) >= 1 && !this.missingYearInfo;
diffInMillies = bornOn.getTimeInMillis() - now.getTimeInMillis();
this.daysOld = Math.abs((int) TimeUnit.DAYS.convert(diffInMillies,
......@@ -153,10 +150,6 @@ public class Contact {
}
}
public boolean isBornInFuture() {
return bornInFuture;
}
public int getBornOnDay() {
return bornOnDay;
}
......@@ -166,7 +159,7 @@ public class Contact {
}
public String getNextBirthDayInfo() {
DateFormat dateFormat = new SimpleDateFormat("MMM/dd - E");
DateFormat dateFormat = new SimpleDateFormat("MMM/dd - E", Locale.getDefault());
Date date = this.nextBirthday.getTime();
return dateFormat.format(date);
}
......@@ -251,4 +244,12 @@ public class Contact {
public String getZodiacElementSymbol() {
return this.zodiacElementSymbol;
}
public void setMissinYearInfo() {
this.missingYearInfo = true;
}
public boolean isMissingYearInfo() {
return this.missingYearInfo;
}
}
\ No newline at end of file
......@@ -37,21 +37,23 @@ import java.util.List;
public class ContactsDataAdapter extends RecyclerView.Adapter<ContactsDataAdapter.ContactViewHolder>
implements Filterable {
private List<Contact> contacts;
private final List<Contact> contactsOrignal;
private final List<Contact> readyOnlyOriginalContacts;
private final Context ctx;
private final SharedPreferences prefs;
private final int MAX_DAYS_AGO = -7;
private int sortOrder;
private int sortType;
private final boolean hideZoadiac;
private final boolean showCurrentAge;
public ContactsDataAdapter(Context ctx, List<Contact> contacts) {
this.contacts = contacts;
this.contactsOrignal = contacts;
this.readyOnlyOriginalContacts = contacts;
this.ctx = ctx;
this.prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
this.hideZoadiac = prefs.getBoolean("hide_zodiac", false);
this.showCurrentAge = prefs.getBoolean("show_current_age", false);
}
@Override
......@@ -60,9 +62,6 @@ public class ContactsDataAdapter extends RecyclerView.Adapter<ContactsDataAdapte
RoundedBitmapDrawable picture = null;
boolean hideZoadiac = prefs.getBoolean("hide_zodiac", false);
boolean showCurrentAge = prefs.getBoolean("show_current_age", false);
int age = contact.getAge();
int daysOld = contact.getDaysOld();
......@@ -70,7 +69,7 @@ public class ContactsDataAdapter extends RecyclerView.Adapter<ContactsDataAdapte
String status = "";
String ageText;
String partyMsg = "";
String partyMsg;
String birthdayMsg;
String photoUri = contact.getPhotoURI();
......@@ -107,19 +106,20 @@ public class ContactsDataAdapter extends RecyclerView.Adapter<ContactsDataAdapte
}
/* Age badge */
if (showCurrentAge) {
if (!contact.shallWePartyToday()) {
--age;
}
ageText = String.valueOf(age);
} else {
if (showCurrentAge && !contact.shallWePartyToday()) {
--age;
}
if (!showCurrentAge && !contact.shallWePartyToday()) {
ageText = "↑" + age;
} else {
ageText = String.valueOf(age);
}
birthdayMsg = contact.getNextBirthDayInfo();
/* Party */
if (daysUntilNextBirthday == 0 && contact.shallWePartyToday()) {
int MAX_DAYS_AGO = -7;
if (contact.shallWePartyToday()) {
partyMsg = ctx.getResources().getString(R.string.party_message);
status = status + " " + ctx.getResources()
.getString(R.string.emoji_today_party);
......@@ -144,7 +144,6 @@ public class ContactsDataAdapter extends RecyclerView.Adapter<ContactsDataAdapte
eventTypeLabel = Character.toString(eventTypeLabel.charAt(0)).toUpperCase()
+ eventTypeLabel.substring(1);
if (picture == null) {
holder.picture.setImageDrawable(
ContextCompat.getDrawable(
......@@ -161,7 +160,7 @@ public class ContactsDataAdapter extends RecyclerView.Adapter<ContactsDataAdapte
holder.lineTwo.setText(eventTypeLabel);
holder.lineThree.setText(partyMsg);
if (contact.getAge() == 0 && !contact.shallWePartyToday()) {
if (age == 0 && !contact.shallWePartyToday()) {
holder.lineFour.setText(ctx.getResources().getQuantityString(
R.plurals.days_old, daysOld, daysOld));
}
......@@ -180,45 +179,43 @@ public class ContactsDataAdapter extends RecyclerView.Adapter<ContactsDataAdapte
}
holder.contactStatus.setText(status);
if (contact.isMissingYearInfo()) {
holder.ageBadge.setVisibility(View.INVISIBLE);
holder.lineFour.setVisibility(View.INVISIBLE);
}
}
@Override
public Filter getFilter() {
return new Filter() {
@Override
protected void publishResults(CharSequence constraint, Filter.FilterResults results) {
if (constraint.length() == 0) {
contacts = contactsOrignal;
} else {
contacts = (ArrayList<Contact>) results.values;
}
contacts = readyOnlyOriginalContacts;
} else contacts = (ArrayList<Contact>) results.values;
notifyDataSetChanged();
}
@Override
protected FilterResults performFiltering(CharSequence charSequence) {
FilterResults results = new FilterResults();
if (charSequence == null || charSequence.length() == 0) {
results.count = contactsOrignal.size();
results.values = contactsOrignal;
protected FilterResults performFiltering(CharSequence query) {
FilterResults filterResults = new FilterResults();
if (query == null || query.length() == 0) {
filterResults.count = contacts.size();
filterResults.values = contacts;
} else {
String filterString = charSequence.toString().toLowerCase();
ArrayList<Contact> nlist = new ArrayList<>();
String filterString = query.toString().toLowerCase();
ArrayList<Contact> filteredContacts = new ArrayList<>();
for (int idx = 0; idx < contactsOrignal.size(); ++idx) {
Contact contact = contactsOrignal.get(idx);
for (Contact contact : readyOnlyOriginalContacts) {
if (applyFilter(contact, filterString)) {
nlist.add(contact);
filteredContacts.add(contact);
}
}
results.count = nlist.size();
results.values = nlist;
filterResults.count = filteredContacts.size();
filterResults.values = filteredContacts;
}
return results;
return filterResults;
}
boolean applyFilter(Contact contact, String filter) {
......
......@@ -43,13 +43,13 @@ public class AboutUsFragment extends Fragment implements View.OnClickListener {
View v = inflater.inflate(R.layout.fragment_about_us,
container, false);
setHasOptionsMenu(true);
TextView appVersion = v.findViewById(R.id.tvVersion);
Button btChangelog = v.findViewById(R.id.about_us_bt_changelog);
btChangelog.setOnClickListener(this);
appVersion.setText(container.getContext().getResources()
.getString(R.string.build, BuildConfig.VERSION_CODE));
......
......@@ -36,6 +36,7 @@ public class BarChartAgeFragment extends Fragment implements OnChartValueSelecte
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_barchart, container, false);
setHasOptionsMenu(true);
float max_age = 0;
float min_age = Integer.MAX_VALUE;
......@@ -56,7 +57,8 @@ public class BarChartAgeFragment extends Fragment implements OnChartValueSelecte
chart.setDrawBarShadow(false);
chart.setDrawValueAboveBar(false);
chart.setPinchZoom(false);
chart.setDrawGridBackground(true);
chart.setDrawGridBackground(false);
chart.setBackgroundColor(Color.TRANSPARENT);
chart.getLegend().setEnabled(false);
chart.getDescription().setText(getResources().getString(R.string.menu_statistics_age));
chart.setDrawBorders(false);
......@@ -73,8 +75,6 @@ public class BarChartAgeFragment extends Fragment implements OnChartValueSelecte
leftAxis.setAxisMinimum(0f);
if (useDarkTheme) {
chart.setBackgroundColor(Color.BLACK);
chart.setDrawGridBackground(false);
leftAxis.setTextColor(Color.WHITE);
rightAxis.setTextColor(Color.WHITE);
xAxis.setTextColor(Color.WHITE);
......
......@@ -17,6 +17,7 @@
package com.tmendes.birthdaydroid.fragments;
import android.app.SearchManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
......@@ -25,16 +26,17 @@ import android.graphics.Color;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.provider.ContactsContract;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.SearchView;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.ItemTouchHelper;
......@@ -57,8 +59,9 @@ import static androidx.recyclerview.widget.ItemTouchHelper.Callback.getDefaultUI
public class ContactListFragment extends Fragment implements RecyclerItemTouchHelper.RecyclerItemTouchHelperListener {
private SearchView searchView;
private SearchView.OnQueryTextListener queryTextListener;
private BirthdayDataProvider bddDataProviver;
private EditText inputSearch;
private ContactsDataAdapter contactsDataAdapter;
private boolean hideIgnoredContacts;
private DBHelper dbHelper;
......@@ -73,6 +76,8 @@ public class ContactListFragment extends Fragment implements RecyclerItemTouchHe
View v = inflater.inflate(R.layout.fragment_contact_list,
container, false);
setHasOptionsMenu(true);
PreferenceManager.setDefaultValues(getContext(), R.xml.preferences, false);
prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
hideIgnoredContacts = prefs.getBoolean("hide_ignored_contacts", false);
......@@ -85,18 +90,16 @@ public class ContactListFragment extends Fragment implements RecyclerItemTouchHe
RecyclerView recyclerView = v.findViewById(R.id.recyclerView);
recyclerView.setHasFixedSize(true);
recyclerView.setAdapter(contactsDataAdapter);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext(),
LinearLayoutManager.VERTICAL, false));
recyclerView.setAdapter(contactsDataAdapter);
ItemTouchHelper.SimpleCallback itemTouchHelperCallback = new RecyclerItemTouchHelper(
0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT, this);
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(itemTouchHelperCallback);
itemTouchHelper.attachToRecyclerView(recyclerView);
inputSearch = v.findViewById(R.id.inputSearch);
coordinatorLayout = v.findViewById(R.id.coordinator_layout);
Objects.requireNonNull(getActivity()).getWindow()
......@@ -115,39 +118,6 @@ public class ContactListFragment extends Fragment implements RecyclerItemTouchHe
showHideAddNewBirthday();
inputSearch.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
// When user changed the Text
contactsDataAdapter.getFilter().filter(cs.toString());
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
}
@Override
public void afterTextChanged(Editable arg0) {
String text = inputSearch.getText().toString();
contactsDataAdapter.getFilter().filter(text);
}
});
inputSearch.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
InputMethodManager inputManager = (InputMethodManager) Objects
.requireNonNull(getContext()).
getSystemService(Context.INPUT_METHOD_SERVICE);
Objects.requireNonNull(inputManager).hideSoftInputFromWindow(
Objects.requireNonNull(getView()).getWindowToken(), 0);
}
}
});
return v;
}
......@@ -160,12 +130,51 @@ public class ContactListFragment extends Fragment implements RecyclerItemTouchHe
}
}
public void onCreateOptionsMenu(@NonNull Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.menu_toolbar, menu);
SearchManager searchManager = (SearchManager) Objects.requireNonNull(getContext())
.getSystemService(getContext().SEARCH_SERVICE);
searchView = (SearchView) menu.findItem(R.id.app_bar_search).getActionView();
searchView.setSearchableInfo(Objects.requireNonNull(searchManager)
.getSearchableInfo(Objects.requireNonNull(getActivity()).getComponentName()));
searchView.setMaxWidth(Integer.MAX_VALUE);
if (searchView != null) {
searchView.setSearchableInfo(searchManager
.getSearchableInfo(getActivity().getComponentName()));
queryTextListener = new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextChange(String query) {
contactsDataAdapter.getFilter().filter(query);
return true;
}
@Override
public boolean onQueryTextSubmit(String query) {
contactsDataAdapter.getFilter().filter(query);
return true;
}
};
searchView.setOnQueryTextListener(queryTextListener);
}
super.onCreateOptionsMenu(menu, inflater);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.app_bar_search) {
return false;
}
searchView.setOnQueryTextListener(queryTextListener);
return super.onOptionsItemSelected(item);
}
@Override
public void onResume() {
super.onResume();
int sortInput = Integer.valueOf(prefs.getString("sort_input", "0"));
int sortMethod = Integer.valueOf(prefs.getString("sort_method", "0"));
int sortInput = Integer.parseInt(prefs.getString("sort_input", "0"));
int sortMethod = Integer.parseInt(prefs.getString("sort_method", "0"));
showHideAddNewBirthday();
......
......@@ -39,6 +39,7 @@ public class PieChartMonthFragment extends Fragment implements OnChartValueSelec
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_piechart, container, false);
setHasOptionsMenu(true);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean useDarkTheme = prefs.getBoolean("dark_theme", false);
......@@ -56,6 +57,7 @@ public class PieChartMonthFragment extends Fragment implements OnChartValueSelec
this.chart.setHighlightPerTapEnabled(true);
chart.setBackgroundColor(Color.TRANSPARENT);
this.chart.setUsePercentValues(true);
this.chart.getDescription().setEnabled(false);
this.chart.setExtraOffsets(5, 10, 5, 5);
......@@ -69,7 +71,6 @@ public class PieChartMonthFragment extends Fragment implements OnChartValueSelec
this.chart.setDrawCenterText(true);
if (useDarkTheme) {
this.chart.setBackgroundColor(Color.BLACK);
this.chart.setHoleColor(Color.BLACK);
}
......
......@@ -39,6 +39,7 @@ public class PieChartWeekFragment extends Fragment implements OnChartValueSelect
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_piechart, container, false);
setHasOptionsMenu(true);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean useDarkTheme = prefs.getBoolean("dark_theme", false);
......@@ -56,6 +57,7 @@ public class PieChartWeekFragment extends Fragment implements OnChartValueSelect
this.chart.setHighlightPerTapEnabled(true);
chart.setBackgroundColor(Color.TRANSPARENT);
this.chart.setUsePercentValues(true);
this.chart.getDescription().setEnabled(false);
this.chart.setExtraOffsets(5, 10, 5, 5);
......@@ -69,7 +71,6 @@ public class PieChartWeekFragment extends Fragment implements OnChartValueSelect
this.chart.setDrawCenterText(true);
if (useDarkTheme) {
this.chart.setBackgroundColor(Color.BLACK);
this.chart.setHoleColor(Color.BLACK);
}
......
......@@ -37,6 +37,7 @@ public class PieChartZodiacFragment extends Fragment implements OnChartValueSele
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_piechart, container, false);
setHasOptionsMenu(true);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean useDarkTheme = prefs.getBoolean("dark_theme", false);
......@@ -54,6 +55,7 @@ public class PieChartZodiacFragment extends Fragment implements OnChartValueSele
this.chart.setHighlightPerTapEnabled(true);
chart.setBackgroundColor(Color.TRANSPARENT);
this.chart.setUsePercentValues(true);
this.chart.getDescription().setEnabled(false);
this.chart.setExtraOffsets(5, 10, 5, 5);
......@@ -67,7 +69,6 @@ public class PieChartZodiacFragment extends Fragment implements OnChartValueSele
this.chart.setDrawCenterText(true);
if (useDarkTheme) {
this.chart.setBackgroundColor(Color.BLACK);
this.chart.setHoleColor(Color.BLACK);
}
......
......@@ -28,6 +28,8 @@ import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.provider.Settings;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
......@@ -63,6 +65,13 @@ public class SettingsFragment extends Fragment {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
setPowerServiceStatus();
setHasOptionsMenu(false);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
menu.clear();
}
@Override
......
......@@ -22,6 +22,8 @@ public class TextAgeFragment extends Fragment {
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_text_statistics, container, false);
setHasOptionsMenu(true);
TableLayout tableLayout = v.findViewById(R.id.tableLayout);
BirthdayDataProvider bddDataProviver = BirthdayDataProvider.getInstance();
......
......@@ -23,6 +23,8 @@ public class TextMonthFragment extends Fragment {
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_text_statistics, container, false);
setHasOptionsMenu(true);
TableLayout tableLayout = v.findViewById(R.id.tableLayout);
BirthdayDataProvider bddDataProviver = BirthdayDataProvider.getInstance();
......
......@@ -23,6 +23,8 @@ public class TextWeekFragment extends Fragment {
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_text_statistics, container, false);
setHasOptionsMenu(true);
TableLayout tableLayout = v.findViewById(R.id.tableLayout);
BirthdayDataProvider bddDataProviver = BirthdayDataProvider.getInstance();
......
......@@ -22,6 +22,8 @@ public class TextZodiacFragment extends Fragment {
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_text_statistics, container, false);
setHasOptionsMenu(true);