Skip to content

Commit

Permalink
Custom prefixes for apps (abhijitvalluri#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
selius committed Feb 26, 2020
1 parent 79082aa commit 6d5a9eb
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public class AppSettingsActivity extends AppCompatActivity implements TimePicker

private AppSelection mAppSelection;
private EditText mFilterText;
private EditText mCustomPrefix;
private TextView mNextDay;
private Button mStartTimeButton;
private Button mStopTimeButton;
Expand Down Expand Up @@ -99,6 +100,7 @@ public void onCreate(Bundle savedInstanceState) {
TextView filterTextDescription;

mFilterText = (EditText) findViewById(R.id.filter_text);
mCustomPrefix = (EditText) findViewById(R.id.custom_prefix);
mStartTimeButton = (Button) findViewById(R.id.start_time);
mStopTimeButton = (Button) findViewById(R.id.stop_time);
mNextDay = (TextView) findViewById(R.id.next_day);
Expand Down Expand Up @@ -159,6 +161,7 @@ public void onClick(View v) {
discardOngoingSwitch.setChecked(mDiscardOngoingNotifications);
setTitle(mAppSelection.getAppName());
mFilterText.setText(mAppSelection.getFilterText());
mCustomPrefix.setText(mAppSelection.getCustomPrefix());

allDaySwitch.setChecked(mAllDaySchedule);
setupScheduleSettings();
Expand Down Expand Up @@ -426,6 +429,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
@Override
public void onBackPressed() {
mAppSelection.setFilterText(mFilterText.getText().toString());
mAppSelection.setCustomPrefix(mCustomPrefix.getText().toString());
mAppSelection.setStartTimeHour(mStartTimeHour);
mAppSelection.setStartTimeMinute(mStartTimeMinute);
mAppSelection.setStopTimeHour(mStopTimeHour);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public AppSelection getAppSelection() {
} else {
daysOfWeek = getInt(getColumnIndex(AppChoiceTable.Cols.DAYS_OF_WEEK));
}
String customPrefix = getString(getColumnIndex(AppChoiceTable.Cols.CUSTOM_PREFIX));

return new AppSelection(appPackageName,
appName,
Expand All @@ -63,6 +64,7 @@ public AppSelection getAppSelection() {
discardEmptyNotif != 0,
discardOngoingNotif != 0,
allDaySchedule != 0,
daysOfWeek);
daysOfWeek,
customPrefix);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* Helper class for the Database
*/
public class AppSelectionDbHelper extends SQLiteOpenHelper {
private static final int VERSION = 7;
private static final int VERSION = 8;
private static final String DATABASE_NAME = "fitNotificationAppSelection.db";
private HashMap<String, String> mDbAlterCommands;
private Context mContext;
Expand Down Expand Up @@ -91,6 +91,10 @@ public AppSelectionDbHelper(Context context) {
AppChoiceTable.Cols.DAYS_OF_WEEK,
"alter table " + AppChoiceTable.NAME + " add column " +
AppChoiceTable.Cols.DAYS_OF_WEEK + " INTEGER NOT NULL DEFAULT 127;");
mDbAlterCommands.put(
AppChoiceTable.Cols.CUSTOM_PREFIX,
"alter table " + AppChoiceTable.NAME + " add column " +
AppChoiceTable.Cols.CUSTOM_PREFIX + " TEXT DEFAULT '';");
}

@Override
Expand All @@ -109,7 +113,8 @@ public void onCreate(SQLiteDatabase db) {
AppChoiceTable.Cols.DISCARD_EMPTY_NOTIFICATIONS + ", " +
AppChoiceTable.Cols.DISCARD_ONGOING_NOTIFICATIONS + ", " +
AppChoiceTable.Cols.ALL_DAY_SCHEDULE + ", " +
AppChoiceTable.Cols.DAYS_OF_WEEK +
AppChoiceTable.Cols.DAYS_OF_WEEK + ", " +
AppChoiceTable.Cols.CUSTOM_PREFIX +
")"
// ALERT!!! Make sure you have a comma to separate all names! Had a bug because I forgot it of ALL_DAY_SCHEDULE
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
* Database Schema to store the Fit Notification app's app selection choices.
Expand All @@ -40,6 +39,7 @@ public static final class Cols {
public static final String DISCARD_ONGOING_NOTIFICATIONS = "discardOngoingNotifications";
public static final String ALL_DAY_SCHEDULE = "allDaySchedule";
public static final String DAYS_OF_WEEK = "daysOfWeek";
public static final String CUSTOM_PREFIX = "customPrefix";

static final ArrayList<String> NAME_LIST = new ArrayList<>(Arrays.asList(
"_id",
Expand All @@ -54,7 +54,8 @@ public static final class Cols {
DISCARD_EMPTY_NOTIFICATIONS,
DISCARD_ONGOING_NOTIFICATIONS,
ALL_DAY_SCHEDULE,
DAYS_OF_WEEK
DAYS_OF_WEEK,
CUSTOM_PREFIX
));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class AppSelection implements Parcelable {
private boolean mDiscardOngoingNotifications;
private boolean mAllDaySchedule;
private int mDaysOfWeek;
private String mCustomPrefix;

public AppSelection(String appPackageName, String appName) {
mAppPackageName = appPackageName;
Expand All @@ -48,6 +49,7 @@ public AppSelection(String appPackageName, String appName) {
mAllDaySchedule = true;
mDiscardOngoingNotifications = true;
mDaysOfWeek = 127;
mCustomPrefix = "";
}

public AppSelection(String appPackageName,
Expand All @@ -61,7 +63,8 @@ public AppSelection(String appPackageName,
boolean discardEmptyNotifications,
boolean discardOngoingNotifications,
boolean allDaySchedule,
int daysOfWeek) {
int daysOfWeek,
String customPrefix) {
mAppPackageName = appPackageName;
mAppName = appName;
mIsSelected = isSelected;
Expand All @@ -74,6 +77,7 @@ public AppSelection(String appPackageName,
mDiscardOngoingNotifications = discardOngoingNotifications;
mAllDaySchedule = allDaySchedule;
mDaysOfWeek = daysOfWeek;
mCustomPrefix = customPrefix;
}

public boolean isSelected() {
Expand Down Expand Up @@ -174,6 +178,14 @@ public void setDaysOfWeek(int daysOfWeek) {
mDaysOfWeek = daysOfWeek;
}

public String getCustomPrefix() {
return mCustomPrefix;
}

public void setCustomPrefix(String customPrefix) {
mCustomPrefix = customPrefix;
}

private AppSelection(Parcel in) {
mAppPackageName = in.readString();
mAppName = in.readString();
Expand All @@ -187,6 +199,7 @@ private AppSelection(Parcel in) {
mAllDaySchedule = in.readByte() != 0x00;
mDiscardOngoingNotifications = in.readByte() != 0x00;
mDaysOfWeek = in.readInt();
mCustomPrefix = in.readString();
}

@Override
Expand All @@ -208,6 +221,7 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeByte((byte) (mAllDaySchedule ? 0x01 : 0x00));
dest.writeByte((byte) (mDiscardOngoingNotifications ? 0x01 : 0x00));
dest.writeInt(mDaysOfWeek);
dest.writeString(mCustomPrefix);
}

@SuppressWarnings("unused")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import android.service.notification.StatusBarNotification;
import android.support.annotation.NonNull;
import android.support.v4.app.NotificationCompat;
import android.text.TextUtils;
import android.widget.RemoteViews;

import com.abhijitvalluri.android.fitnotifications.R;
Expand Down Expand Up @@ -237,13 +238,15 @@ public void onNotificationPosted(final StatusBarNotification sbn) {
String filterText = null;
boolean discardEmptyNotifications = false;
boolean discardOngoingNotifications = true;
String customPrefix = null;

{
AppSelection appSelection = AppSelectionsStore.get(this).getAppSelection(appPackageName);
if (appSelection != null) {
filterText = appSelection.getFilterText().trim();
discardEmptyNotifications = appSelection.isDiscardEmptyNotifications();
discardOngoingNotifications = appSelection.isDiscardOngoingNotifications();
customPrefix = appSelection.getCustomPrefix().trim();
}
}

Expand Down Expand Up @@ -309,7 +312,11 @@ public void onNotificationPosted(final StatusBarNotification sbn) {
String notificationText = titleAndText[1].toString();

if (mDisplayAppName) {
notificationText = "[" + mAppSelectionsStore.getAppName(appPackageName) + "] " + notificationText;
String appPrefix = customPrefix;
if (TextUtils.isEmpty(appPrefix)) {
appPrefix = mAppSelectionsStore.getAppName(appPackageName);
}
notificationText = "[" + appPrefix + "] " + notificationText;
}

if (mTransliterateNotif) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ private static ContentValues getContentValues(AppSelection appSelection) {
values.put(AppChoiceTable.Cols.DISCARD_ONGOING_NOTIFICATIONS, appSelection.isDiscardOngoingNotifications() ? 1 : 0);
values.put(AppChoiceTable.Cols.ALL_DAY_SCHEDULE, appSelection.isAllDaySchedule() ? 1 : 0);
values.put(AppChoiceTable.Cols.DAYS_OF_WEEK, appSelection.getDaysOfWeek());
values.put(AppChoiceTable.Cols.CUSTOM_PREFIX, appSelection.getCustomPrefix());

return values;
}
Expand Down
27 changes: 27 additions & 0 deletions app/src/main/res/layout-mdpi/activity_app_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,33 @@
android:textSize="16sp"/>

</LinearLayout>

<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:background="@color/lightGrey_translucent" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:labelFor="@+id/custom_prefix"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="19sp"
android:text="@string/custom_prefix"
android:paddingTop="16dp"/>

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:inputType="text"
android:id="@+id/custom_prefix"/>

</LinearLayout>
</ScrollView>

27 changes: 27 additions & 0 deletions app/src/main/res/layout/activity_app_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,33 @@
android:textSize="16sp"/>

</LinearLayout>

<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:background="@color/lightGrey_translucent" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:labelFor="@+id/custom_prefix"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="19sp"
android:text="@string/custom_prefix"
android:paddingTop="16dp"/>

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:inputType="text"
android:id="@+id/custom_prefix"/>

</LinearLayout>
</ScrollView>

1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@
<string name="schedule_thursday">T</string>
<string name="schedule_friday">F</string>
<string name="schedule_saturday">S</string>
<string name="custom_prefix">Custom prefix</string>

<!-- Notification summary patterns - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<string name="new_messages_summary_pattern">\\d+ new messages</string>
Expand Down

0 comments on commit 6d5a9eb

Please sign in to comment.