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

Settings screen with Notifications checkbox. #279 #389

Merged
merged 1 commit into from
Sep 4, 2017
Merged
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
7 changes: 7 additions & 0 deletions .idea/dictionaries/dictionary.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions opentasks/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="org.dmfs.tasks"
xmlns:android="http://schemas.android.com/apk/res/android">
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.dmfs.tasks">

<uses-permission android:name="org.dmfs.permission.READ_TASKS"/>
<uses-permission android:name="org.dmfs.permission.WRITE_TASKS"/>
Expand Down Expand Up @@ -347,6 +347,11 @@
android:scheme="content"/>
</intent-filter>
</activity>
<!-- App Settings -->
<activity
android:name=".AppSettingsActivity"
android:theme="@style/AppTheme"
android:label="@string/title_activity_settings"/>

<!-- Notification -->
<receiver
Expand Down
70 changes: 70 additions & 0 deletions opentasks/src/main/java/org/dmfs/tasks/AppSettingsActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright 2017 dmfs GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.dmfs.tasks;

import android.annotation.TargetApi;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.view.MenuItem;

import org.dmfs.tasks.utils.AppCompatActivity;


/**
* Activity for the general app settings screen.
*
* @author Gabor Keszthelyi
*/
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
public final class AppSettingsActivity extends AppCompatActivity
{

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

getFragmentManager().beginTransaction()
.replace(android.R.id.content, new AppSettingsFragment())
.commit();

setupActionBar();
}


@Override
public boolean onOptionsItemSelected(MenuItem item)
{
if (item.getItemId() == android.R.id.home)
{
finish();
return true;
}
return super.onOptionsItemSelected(item);
}


@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void setupActionBar()
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
{
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
}
}
42 changes: 42 additions & 0 deletions opentasks/src/main/java/org/dmfs/tasks/AppSettingsFragment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2017 dmfs GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.dmfs.tasks;

import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceFragment;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;


/**
* Fragment for the general app settings.
*
* @author Gabor Keszthelyi
*/
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
public final class AppSettingsFragment extends PreferenceFragment
{

@Override
public void onCreate(@Nullable Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

addPreferencesFromResource(R.xml.app_preferences);
}
}
15 changes: 2 additions & 13 deletions opentasks/src/main/java/org/dmfs/tasks/TaskListActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
import org.dmfs.tasks.groupings.BySearch;
import org.dmfs.tasks.groupings.ByStartDate;
import org.dmfs.tasks.model.ContentSet;
import org.dmfs.tasks.notification.AlarmBroadcastReceiver;
import org.dmfs.tasks.utils.AppCompatActivity;
import org.dmfs.tasks.utils.ExpandableGroupDescriptor;
import org.dmfs.tasks.utils.SearchHistoryHelper;
Expand Down Expand Up @@ -597,13 +596,6 @@ public boolean onCreateOptionsMenu(Menu menu)
addItem.setVisible(false);
}

// restore menu state
MenuItem item = menu.findItem(R.id.menu_alarms);
if (item != null)
{
item.setChecked(AlarmBroadcastReceiver.getAlarmPreference(this));
}

// search
setupSearch(menu);

Expand All @@ -626,12 +618,9 @@ else if (item.getItemId() == R.id.menu_visible_list)
startActivity(settingsIntent);
return true;
}
else if (item.getItemId() == R.id.menu_alarms)
else if (item.getItemId() == R.id.opentasks_menu_app_settings)
{
// set and save state
boolean activatedAlarms = !item.isChecked();
item.setChecked(activatedAlarms);
AlarmBroadcastReceiver.setAlarmPreference(this, activatedAlarms);
startActivity(new Intent(this, AppSettingsActivity.class));
return true;
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.preference.PreferenceManager;

import org.dmfs.tasks.R;
import org.dmfs.tasks.contract.TaskContract;


Expand All @@ -34,10 +36,6 @@
public class AlarmBroadcastReceiver extends BroadcastReceiver
{

private static String PREFS_NAME = "alarm_preferences";
private static String PREF_ALARM_ACTIVATED = "preference_alarm_activated";


/**
* Is called on an incoming alarm broadcast. Creates a notifications for this alarm.
*/
Expand All @@ -47,7 +45,7 @@ public void onReceive(Context context, Intent intent)
// continue if alarms where enabled
if (intent.getAction().equals(TaskContract.ACTION_BROADCAST_TASK_STARTING))
{
if (getAlarmPreference(context))
if (isNotificationEnabled(context))
{
Uri taskUri = intent.getData();

Expand All @@ -72,7 +70,7 @@ public void onReceive(Context context, Intent intent)
}
else if (intent.getAction().equals(TaskContract.ACTION_BROADCAST_TASK_DUE))
{
if (getAlarmPreference(context))
if (isNotificationEnabled(context))
{
Uri taskUri = intent.getData();

Expand Down Expand Up @@ -100,20 +98,10 @@ else if (intent.getAction().equals(TaskContract.ACTION_BROADCAST_TASK_DUE))
}


public static void setAlarmPreference(Context context, boolean value)
{
SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean(PREF_ALARM_ACTIVATED, value);
editor.commit();

}


public static boolean getAlarmPreference(Context context)
public boolean isNotificationEnabled(Context context)
{
SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, 0);
return settings.getBoolean(PREF_ALARM_ACTIVATED, true);
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
return settings.getBoolean(context.getString(R.string.schedjoules_pref_notification_enabled), true);

}
}
11 changes: 6 additions & 5 deletions opentasks/src/main/res/menu/task_list_activity_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
<item
android:id="@+id/menu_visible_list"
android:title="@string/visible_task_lists"
app:showAsAction="never"></item>
app:showAsAction="never"/>

<item
android:id="@+id/menu_alarms"
android:checkable="true"
android:title="@string/enable_alarms"
app:showAsAction="never"></item>
android:id="@+id/opentasks_menu_app_settings"
android:title="@string/title_activity_settings"
android:visible="@bool/postHoneycomb"
app:showAsAction="never"/>

</menu>
7 changes: 7 additions & 0 deletions opentasks/src/main/res/values/prefs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="schedjoules_pref_notification_enabled"
translatable="false">schedjoules_pref_notification_enabled</string>

</resources>
8 changes: 8 additions & 0 deletions opentasks/src/main/res/xml/app_preferences.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">

<CheckBoxPreference
android:key="@string/schedjoules_pref_notification_enabled"
android:title="@string/enable_alarms"
android:defaultValue="true"/>
</PreferenceScreen>