No more hardcoded strings
Save and load packageName as lowercase String Do not save empty strings as Notification Filter Entry
This commit is contained in:
parent
c5358bcbdf
commit
f90ba76fc0
|
@ -3,6 +3,7 @@ package nodomain.freeyourgadget.gadgetbridge.activities;
|
|||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.*;
|
||||
|
||||
import de.greenrobot.dao.query.Query;
|
||||
import nodomain.freeyourgadget.gadgetbridge.BuildConfig;
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
|
@ -14,6 +15,7 @@ import nodomain.freeyourgadget.gadgetbridge.entities.NotificationFilter;
|
|||
import nodomain.freeyourgadget.gadgetbridge.entities.NotificationFilterDao;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.NotificationFilterEntry;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.NotificationFilterEntryDao;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -54,6 +56,8 @@ public class NotificationFilterActivity extends AbstractGBActivity {
|
|||
this.finish();
|
||||
}
|
||||
|
||||
packageName = packageName.toLowerCase();
|
||||
|
||||
try {
|
||||
db = GBApplication.acquireDB();
|
||||
} catch (GBException e) {
|
||||
|
@ -146,7 +150,6 @@ public class NotificationFilterActivity extends AbstractGBActivity {
|
|||
public void onClick(View view) {
|
||||
|
||||
// TODO: check for modifications, only save if something changed
|
||||
|
||||
String words = mEditTextWords.getText().toString();
|
||||
|
||||
if (StringUtils.isBlank(words) && mSpinnerFilterMode.getSelectedItemPosition() != NOTIFICATION_FILTER_MODE_NONE) {
|
||||
|
@ -172,6 +175,11 @@ public class NotificationFilterActivity extends AbstractGBActivity {
|
|||
if (mNotificationFilter.getNotificationFilterMode() != NOTIFICATION_FILTER_MODE_NONE) {
|
||||
String[] wordsSplitted = words.split("\n");
|
||||
for (String temp : wordsSplitted) {
|
||||
|
||||
if (StringUtils.isBlank(temp)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
temp = temp.trim();
|
||||
NotificationFilterEntry notificationFilterEntry = new NotificationFilterEntry();
|
||||
notificationFilterEntry.setNotificationFilterContent(temp);
|
||||
|
|
|
@ -378,7 +378,7 @@ public class NotificationListener extends NotificationListenerService {
|
|||
NotificationFilterDao notificationFilterDao = db.getDaoSession().getNotificationFilterDao();
|
||||
NotificationFilterEntryDao notificationFilterEntryDao = db.getDaoSession().getNotificationFilterEntryDao();
|
||||
|
||||
Query<NotificationFilter> query = notificationFilterDao.queryBuilder().where(NotificationFilterDao.Properties.AppIdentifier.eq(packageName)).build();
|
||||
Query<NotificationFilter> query = notificationFilterDao.queryBuilder().where(NotificationFilterDao.Properties.AppIdentifier.eq(packageName.toLowerCase())).build();
|
||||
NotificationFilter notificationFilter = query.unique();
|
||||
|
||||
if (notificationFilter == null) {
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:text="Filter Mode"
|
||||
android:text="@string/filter_mode"
|
||||
app:layout_constraintEnd_toStartOf="@+id/guideline"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
@ -38,7 +38,7 @@
|
|||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:text="Mode Configuration"
|
||||
android:text="@string/mode_configuration"
|
||||
app:layout_constraintEnd_toStartOf="@+id/guideline"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/spinnerFilterMode" />
|
||||
|
@ -82,7 +82,7 @@
|
|||
android:layout_marginBottom="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:text="Save Configuration"
|
||||
android:text="@string/save_configuration"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
|
|
@ -1,65 +1,86 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".activities.NotificationFilterActivity"
|
||||
tools:layout_editor_absoluteY="81dp">
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".activities.NotificationFilterActivity"
|
||||
tools:layout_editor_absoluteY="81dp">
|
||||
|
||||
<TextView
|
||||
android:text="Filter Mode"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/textView2"
|
||||
android:layout_marginTop="16dp"
|
||||
app:layout_constraintTop_toTopOf="parent" app:layout_constraintStart_toStartOf="parent"
|
||||
android:layout_marginStart="16dp"/>
|
||||
android:id="@+id/textView2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:text="@string/filter_mode"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<Spinner
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/spinnerFilterMode" android:layout_marginTop="16dp"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textView2" app:layout_constraintStart_toStartOf="parent"
|
||||
android:layout_marginStart="16dp" app:layout_constraintEnd_toEndOf="parent"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:entries="@array/notification_filter_modes_entries"/>
|
||||
android:id="@+id/spinnerFilterMode"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:entries="@array/notification_filter_modes_entries"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textView2" />
|
||||
|
||||
<TextView
|
||||
android:text="Mode Configuration"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/textView3" android:layout_marginTop="16dp"
|
||||
app:layout_constraintTop_toBottomOf="@+id/spinnerFilterMode" app:layout_constraintStart_toStartOf="parent"
|
||||
android:layout_marginStart="16dp"/>
|
||||
android:id="@+id/textView3"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:text="@string/mode_configuration"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/spinnerFilterMode" />
|
||||
|
||||
<Spinner
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/spinnerSubMode" android:layout_marginTop="16dp"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textView3" app:layout_constraintStart_toStartOf="parent"
|
||||
android:layout_marginStart="16dp" app:layout_constraintEnd_toEndOf="parent"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:entries="@array/notification_filter_submodes_entries"/>
|
||||
android:id="@+id/spinnerSubMode"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:entries="@array/notification_filter_submodes_entries"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textView3" />
|
||||
|
||||
<EditText
|
||||
android:gravity="start"
|
||||
style="@style/Widget.AppCompat.EditText"
|
||||
android:scrollbars="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:inputType="textMultiLine"
|
||||
android:hint="@string/edittext_notification_filter_words_hint"
|
||||
android:ems="10"
|
||||
android:minLines="10"
|
||||
android:maxLines="25"
|
||||
android:id="@+id/editTextWords" android:layout_marginTop="16dp"
|
||||
app:layout_constraintTop_toBottomOf="@+id/spinnerSubMode" android:layout_marginStart="16dp"
|
||||
app:layout_constraintStart_toStartOf="parent" android:layout_marginEnd="16dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
android:layout_marginBottom="16dp" app:layout_constraintBottom_toTopOf="@+id/buttonSaveFilter"/>
|
||||
android:id="@+id/editTextWords"
|
||||
style="@style/Widget.AppCompat.EditText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:ems="10"
|
||||
android:gravity="start"
|
||||
android:hint="@string/edittext_notification_filter_words_hint"
|
||||
android:inputType="textMultiLine"
|
||||
android:maxLines="25"
|
||||
android:minLines="10"
|
||||
android:scrollbars="vertical"
|
||||
app:layout_constraintBottom_toTopOf="@+id/buttonSaveFilter"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/spinnerSubMode" />
|
||||
|
||||
<Button
|
||||
android:text="Save Configuration"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/buttonSaveFilter" android:layout_marginBottom="16dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent"
|
||||
android:layout_marginEnd="16dp" app:layout_constraintStart_toStartOf="parent"
|
||||
android:layout_marginStart="16dp"/>
|
||||
android:id="@+id/buttonSaveFilter"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:text="@string/save_configuration"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
</android.support.constraint.ConstraintLayout>
|
|
@ -680,4 +680,7 @@
|
|||
<string name="filter_submode_at_least_one">At least one of the words</string>
|
||||
<string name="filter_submode_all">All of the words</string>
|
||||
<string name="toast_notification_filter_words_empty_hint">Please enter at least one word</string>
|
||||
<string name="filter_mode">Filter Mode</string>
|
||||
<string name="mode_configuration">Mode Configuration</string>
|
||||
<string name="save_configuration">Save Configuration</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue