Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Beginning #13

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ protected void onCreate(Bundle savedInstanceState) {
this.name = (TextView) findViewById(R.id.editor_name);
this.list = (ListView) findViewById(R.id.editor_list);

name.setTextColor(getResources().getColor(R.color.white));


// check if contact id is valid
this.db = new Database(getContentResolver());
int contactId = getIntent().getIntExtra(CONTACT_ID, NO_CONTACT_ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
import android.Manifest;
import android.annotation.SuppressLint;
import android.app.ListActivity;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
Expand Down Expand Up @@ -43,12 +47,16 @@ public class BirthdayReminder extends ListActivity {
private static final int PERMISSIONS_REQUEST_READ_CONTACTS = 1;
private final DateFormatSymbols dateSymbols = new DateFormatSymbols();

public static final String CHANNEL_ID = BirthdayReminder.class.getName();

private Database db;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getListView().setFastScrollEnabled(true);
createNotificationChannel();



this.db = new Database(getContentResolver());

Expand All @@ -69,6 +77,24 @@ public void onCreate(Bundle savedInstanceState) {
}
}

private void createNotificationChannel() {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = getString(R.string.notificationChannelName);
String description = getString(R.string.notificationDescription);
int importance = NotificationManager.IMPORTANCE_HIGH;

NotificationChannel notificationChannel = new NotificationChannel(
CHANNEL_ID,
name,
importance);
notificationChannel.setDescription(description);

NotificationManager notificationManager = getSystemService(NotificationManager.class);
assert notificationManager != null;
notificationManager.createNotificationChannel(notificationChannel);
}
}

private boolean isContactsPermissionGranted() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
return true;
Expand All @@ -80,7 +106,6 @@ private boolean isContactsPermissionGranted() {
@Override
protected void onResume() {
super.onResume();

if (isContactsPermissionGranted()) {
updateView();
}
Expand All @@ -99,9 +124,12 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis

private void updateView() {
// create new list adapter

MultiListAdapter listAdapter = new MultiListAdapter();
List<ListAdapter> adapterList = listAdapter.getListAdapters();



// load birthday and contact information
List<Contact> contacts = this.db.getAllContacts();
List<BirthContact> birthContacts = BirthContactHelper.createBirthContactList(contacts);
Expand Down Expand Up @@ -131,22 +159,28 @@ private void updateView() {

currentBirthContactAdapter = new BirthContactAdapter(this);
adapterList.add(new CategoryAdapter(this, monthStrs[currentMonth]));


adapterList.add(currentBirthContactAdapter);
}

currentBirthContactAdapter.add(birthContact);


}

adapterList.add(new CategoryAdapter(this, getResources().getString(R.string.unknownBirthdays)));

adapterList.add(new BirthContactAdapter(this, unknownBirthdays));


setListAdapter(listAdapter);
}

@SuppressLint("ResourceAsColor")
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
BirthContact birthContact = (BirthContact) l.getAdapter().getItem(position);

Intent editorIntent = new Intent(this, BirthdayEditor.class);
editorIntent.putExtra(BirthdayEditor.CONTACT_ID, birthContact.getContact().getId());
startActivity(editorIntent);
Expand Down Expand Up @@ -176,4 +210,5 @@ public boolean onOptionsItemSelected(MenuItem item) {

return super.onOptionsItemSelected(item);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle;
import android.preference.PreferenceActivity;

import androidx.preference.Preference;

import de.ubuntix.android.birthdayreminder.database.Preferences;
import de.ubuntix.android.birthdayreminder.service.BirthdayBroadcastReceiver;

Expand All @@ -14,10 +17,12 @@ public class PreferenceWindow extends PreferenceActivity implements OnSharedPref
public static final String HIDE_NOTIFICATION = "hideNotificationAfterConfirmation";
public static final String UPDATE_TIME = "updateTime";


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.layout.preferences);
addPreferencesFromResource(R.xml.preferences);

}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package de.ubuntix.android.birthdayreminder.service;

import static de.ubuntix.android.birthdayreminder.BirthdayReminder.*;

import android.app.AlarmManager;
import android.app.Notification;
import android.app.NotificationManager;
Expand All @@ -8,6 +10,14 @@
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Icon;
import android.os.Build;
import android.widget.Toast;


import androidx.annotation.RequiresApi;
import androidx.core.content.ContextCompat;

import java.sql.Time;
import java.util.ArrayList;
Expand All @@ -16,6 +26,7 @@
import java.util.SortedMap;
import java.util.TreeMap;


import de.ubuntix.android.birthdayreminder.BirthdayReminder;
import de.ubuntix.android.birthdayreminder.R;
import de.ubuntix.android.birthdayreminder.database.Database;
Expand All @@ -30,6 +41,7 @@ public class BirthdayBroadcastReceiver extends BroadcastReceiver {

private static final String TIMED = "timed";

@RequiresApi(api = Build.VERSION_CODES.O)
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getBooleanExtra(TIMED, false)) {
Expand Down Expand Up @@ -77,13 +89,16 @@ public static void restart(Context context) {
start(context);
}

@RequiresApi(api = Build.VERSION_CODES.O)
private void notifyBirthdays(Context context) {
Calendar today = CalendarUtils.todaysCalendar();
Database db = new Database(context.getContentResolver());

Preferences prefs = Preferences.getInstance(context);

NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);

Resources res = context.getResources();

List<Contact> contacts = db.getAllContacts();
Expand Down Expand Up @@ -117,6 +132,7 @@ private void notifyBirthdays(Context context) {
int countBirthdays = 0;
for (Integer days : nextBirthdays.keySet()) {
List<String> birthdayList = nextBirthdays.get(days);
assert birthdayList != null;
String names = StringUtils.join(birthdayList, ", ").toString();
notificationTexts.add(getBirthdayText(res, days, names));
countBirthdays += birthdayList.size();
Expand All @@ -133,21 +149,35 @@ private void notifyBirthdays(Context context) {
PendingIntent pi = PendingIntent.getActivity(
context, 0, intent, PendingIntent.FLAG_IMMUTABLE);

Notification.Builder builder = new Notification.Builder(context);
Notification.Builder builder = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
builder = new Notification.Builder(context,CHANNEL_ID);
}

assert builder != null;
builder.setContentIntent(pi);
builder.setSmallIcon(R.drawable.balloons);
builder.setTicker(titleText);
builder.setContentText(StringUtils.join(notificationTexts, ", "));

builder.setShowWhen(true);
builder.setWhen(System.currentTimeMillis());
builder.setContentTitle(titleText);
builder.setColorized(true);
builder.setColor(res.getColor(R.color.blue));
builder.setCategory(Notification.CATEGORY_REMINDER);
builder.setPriority(Notification.PRIORITY_HIGH);
builder.setVisibility(Notification.VISIBILITY_PUBLIC);
builder.setStyle(new Notification.BigTextStyle().bigText(
StringUtils.join(notificationTexts,"\n")));
if (countBirthdays > 1) {
builder.setNumber(countBirthdays);
}
builder.setTicker(String.format(String.valueOf(countBirthdays)));

Notification notification = builder.getNotification();
notificationManager.notify(0, notification);
notificationManager.notify(1, notification);
}
}


private String getBirthdayText(Resources res, int days, String names) {
String text;
switch (days) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package de.ubuntix.android.birthdayreminder.view.adapter;



import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import de.ubuntix.android.birthdayreminder.R;

public class CategoryAdapter extends BaseAdapter {

private final String name;
Expand Down Expand Up @@ -36,6 +41,7 @@ public long getItemId(int position) {
return position;
}

@SuppressLint("ResourceAsColor")
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView categoryView;
Expand All @@ -44,7 +50,6 @@ public View getView(int position, View convertView, ViewGroup parent) {
} else {
categoryView = (TextView) convertView;
}

categoryView.setText(this.name);
return categoryView;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

import java.util.ArrayList;
import java.util.List;
import java.util.SortedSet;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListAdapter;

import de.ubuntix.android.birthdayreminder.view.helper.BirthContact;

public class MultiListAdapter extends BaseAdapter {

private final List<ListAdapter> listAdapters = new ArrayList<ListAdapter>();
Expand Down Expand Up @@ -47,6 +50,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
int positionOffset = 0;
for (ListAdapter listAdapter : this.listAdapters) {
if (position - positionOffset < listAdapter.getCount()) {

return listAdapter.getView(position - positionOffset, convertView, parent);
}
positionOffset += listAdapter.getCount();
Expand Down
31 changes: 16 additions & 15 deletions app/src/main/res/layout/birth_contact.xml
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000"
android:orientation="vertical"
android:padding="5dp">
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/black"
android:orientation="vertical"
android:padding="5dp">

<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/name"
android:textColor="@color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
android:id="@+id/info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#22AA22" />
<TextView
android:id="@+id/info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/lightgreen" />

</LinearLayout>
7 changes: 5 additions & 2 deletions app/src/main/res/layout/editor.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000"
android:orientation="vertical">
android:background="@color/black"
android:orientation="vertical"
android:gravity="end">

<TextView
android:id="@+id/editor_name"
Expand All @@ -15,6 +16,8 @@

<ListView
android:id="@+id/editor_list"

android:background="@color/black"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical" />
Expand Down
Loading
Loading