diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index f28155de..7de530cf 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -36,6 +36,7 @@
+
{
protected Boolean doInBackground(Bitmap... bitmaps) {
final int count = bitmaps.length;
resultList = new ArrayList<>(count);
- for (int i = 0; i < count; i++) {
+ for (Bitmap bitmap : bitmaps) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
/* Unfortunately, there isn't a determined worst case compression ratio for image
* formats. So, the only way to tell if they're too big is to compress them and
@@ -54,16 +54,16 @@ public class DownsizeImageTask extends AsyncTask {
int scaledImageSize = 4096;
do {
stream.reset();
- Bitmap bitmap = scaleDown(bitmaps[i], scaledImageSize, true);
+ Bitmap scaledBitmap = scaleDown(bitmap, scaledImageSize, true);
Bitmap.CompressFormat format;
/* It's not likely the user will give transparent images over the upload limit, but
* if they do, make sure the transparency is retained. */
- if (!bitmap.hasAlpha()) {
+ if (!scaledBitmap.hasAlpha()) {
format = Bitmap.CompressFormat.JPEG;
} else {
format = Bitmap.CompressFormat.PNG;
}
- bitmap.compress(format, 75, stream);
+ scaledBitmap.compress(format, 75, stream);
scaledImageSize /= 2;
iterations++;
} while (stream.size() > sizeLimit);
diff --git a/app/src/main/java/com/keylesspalace/tusky/FlowLayout.java b/app/src/main/java/com/keylesspalace/tusky/FlowLayout.java
index 08ceb2fb..58759233 100644
--- a/app/src/main/java/com/keylesspalace/tusky/FlowLayout.java
+++ b/app/src/main/java/com/keylesspalace/tusky/FlowLayout.java
@@ -1,3 +1,18 @@
+/* Copyright 2017 Andrew Dawson
+ *
+ * This file is part of Tusky.
+ *
+ * Tusky is free software: you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License as published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
+ * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+ * Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with Tusky. If not, see
+ * . */
+
package com.keylesspalace.tusky;
import android.content.Context;
diff --git a/app/src/main/java/com/keylesspalace/tusky/MainActivity.java b/app/src/main/java/com/keylesspalace/tusky/MainActivity.java
index eaf9b366..ab02c97b 100644
--- a/app/src/main/java/com/keylesspalace/tusky/MainActivity.java
+++ b/app/src/main/java/com/keylesspalace/tusky/MainActivity.java
@@ -21,6 +21,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.SystemClock;
+import android.preference.PreferenceManager;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
@@ -81,11 +82,12 @@ public class MainActivity extends AppCompatActivity {
tabLayout.setupWithViewPager(viewPager);
// Retrieve notification update preference.
- SharedPreferences preferences = getSharedPreferences(
- getString(R.string.preferences_file_key), Context.MODE_PRIVATE);
- notificationServiceEnabled = preferences.getBoolean("notificationService", false);
- long notificationCheckInterval =
- preferences.getLong("notificationCheckInterval", 5 * 60 * 1000);
+ SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
+ notificationServiceEnabled = preferences.getBoolean("pullNotifications", true);
+ String minutesString = preferences.getString("pullNotificationCheckInterval", "15");
+ long notificationCheckInterval = 60 * 1000 * Integer.valueOf(minutesString);
+ Log.d(TAG, String.format("pull notifications: %b %dm", notificationServiceEnabled,
+ Integer.valueOf(minutesString)));
// Start up the PullNotificationsService.
alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(this, PullNotificationService.class);
@@ -252,6 +254,11 @@ public class MainActivity extends AppCompatActivity {
startActivity(intent);
}
+ private void viewPreferences() {
+ Intent intent = new Intent(this, PreferencesActivity.class);
+ startActivity(intent);
+ }
+
private void logOut() {
if (notificationServiceEnabled) {
alarmManager.cancel(serviceAlarmIntent);
@@ -284,6 +291,10 @@ public class MainActivity extends AppCompatActivity {
viewProfile();
return true;
}
+ case R.id.action_preferences: {
+ viewPreferences();
+ return true;
+ }
case R.id.action_logout: {
logOut();
return true;
diff --git a/app/src/main/java/com/keylesspalace/tusky/NotificationsAdapter.java b/app/src/main/java/com/keylesspalace/tusky/NotificationsAdapter.java
index 871cde80..13b3bd42 100644
--- a/app/src/main/java/com/keylesspalace/tusky/NotificationsAdapter.java
+++ b/app/src/main/java/com/keylesspalace/tusky/NotificationsAdapter.java
@@ -18,7 +18,6 @@ package com.keylesspalace.tusky;
import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
-import android.text.Spanned;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -83,7 +82,6 @@ public class NotificationsAdapter extends RecyclerView.Adapter implements Adapte
case MENTION: {
StatusViewHolder holder = (StatusViewHolder) viewHolder;
Status status = notification.getStatus();
- assert(status != null);
holder.setupWithStatus(status, statusListener, position);
break;
}
diff --git a/app/src/main/java/com/keylesspalace/tusky/NotificationsFragment.java b/app/src/main/java/com/keylesspalace/tusky/NotificationsFragment.java
index e1c59b2a..7cf6b25b 100644
--- a/app/src/main/java/com/keylesspalace/tusky/NotificationsFragment.java
+++ b/app/src/main/java/com/keylesspalace/tusky/NotificationsFragment.java
@@ -35,9 +35,7 @@ import com.android.volley.toolbox.JsonArrayRequest;
import org.json.JSONArray;
import org.json.JSONException;
-import org.json.JSONObject;
-import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
diff --git a/app/src/main/java/com/keylesspalace/tusky/PreferencesActivity.java b/app/src/main/java/com/keylesspalace/tusky/PreferencesActivity.java
new file mode 100644
index 00000000..f09c6d23
--- /dev/null
+++ b/app/src/main/java/com/keylesspalace/tusky/PreferencesActivity.java
@@ -0,0 +1,30 @@
+/* Copyright 2017 Andrew Dawson
+ *
+ * This file is part of Tusky.
+ *
+ * Tusky is free software: you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License as published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
+ * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+ * Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with Tusky. If not, see
+ * . */
+
+package com.keylesspalace.tusky;
+
+import android.os.Bundle;
+import android.support.annotation.Nullable;
+import android.support.v7.app.AppCompatActivity;
+
+public class PreferencesActivity extends AppCompatActivity {
+ @Override
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ getFragmentManager().beginTransaction()
+ .replace(android.R.id.content, new PreferencesFragment())
+ .commit();
+ }
+}
diff --git a/app/src/main/java/com/keylesspalace/tusky/PreferencesFragment.java b/app/src/main/java/com/keylesspalace/tusky/PreferencesFragment.java
new file mode 100644
index 00000000..1d405a19
--- /dev/null
+++ b/app/src/main/java/com/keylesspalace/tusky/PreferencesFragment.java
@@ -0,0 +1,27 @@
+/* Copyright 2017 Andrew Dawson
+ *
+ * This file is part of Tusky.
+ *
+ * Tusky is free software: you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License as published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
+ * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+ * Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with Tusky. If not, see
+ * . */
+
+package com.keylesspalace.tusky;
+
+import android.os.Bundle;
+import android.preference.PreferenceFragment;
+
+public class PreferencesFragment extends PreferenceFragment {
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ addPreferencesFromResource(R.xml.preferences);
+ }
+}
diff --git a/app/src/main/java/com/keylesspalace/tusky/PullNotificationService.java b/app/src/main/java/com/keylesspalace/tusky/PullNotificationService.java
index 51f08e74..a32bc993 100644
--- a/app/src/main/java/com/keylesspalace/tusky/PullNotificationService.java
+++ b/app/src/main/java/com/keylesspalace/tusky/PullNotificationService.java
@@ -21,6 +21,7 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.os.Build;
+import android.preference.PreferenceManager;
import android.provider.Settings;
import android.support.annotation.Nullable;
import android.support.v4.app.NotificationCompat;
@@ -46,7 +47,7 @@ public class PullNotificationService extends IntentService {
private final int NOTIFY_ID = 6; // This is an arbitrary number.
public PullNotificationService() {
- super("Tusky Notification Service");
+ super("Tusky Pull Notification Service");
}
@Override
@@ -60,8 +61,6 @@ public class PullNotificationService extends IntentService {
if (date != 0) {
lastUpdate = new Date(date);
}
- assert(domain != null);
- assert(accessToken != null);
checkNotifications(domain, accessToken, lastUpdate);
}
@@ -171,8 +170,7 @@ public class PullNotificationService extends IntentService {
private void updateNotification(List mentions, @Nullable Bitmap icon) {
final int NOTIFICATION_CONTENT_LIMIT = 40;
- SharedPreferences preferences = getSharedPreferences(
- getString(R.string.preferences_file_key), Context.MODE_PRIVATE);
+ SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
String title;
if (mentions.size() > 1) {
title = String.format(
@@ -189,13 +187,13 @@ public class PullNotificationService extends IntentService {
if (icon != null) {
builder.setLargeIcon(icon);
}
- if (preferences.getBoolean("notificationAlertSound", false)) {
+ if (preferences.getBoolean("notificationAlertSound", true)) {
builder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI);
}
if (preferences.getBoolean("notificationStyleVibrate", false)) {
builder.setVibrate(new long[] { 500, 500 });
}
- if (preferences.getBoolean("notificationStyleLight", false)) {
+ if (preferences.getBoolean("notificationStyleLight", true)) {
builder.setLights(0xFF00FF8F, 300, 1000);
}
for (int i = 0; i < mentions.size(); i++) {
diff --git a/app/src/main/java/com/keylesspalace/tusky/SFragment.java b/app/src/main/java/com/keylesspalace/tusky/SFragment.java
index aea5b552..515b838c 100644
--- a/app/src/main/java/com/keylesspalace/tusky/SFragment.java
+++ b/app/src/main/java/com/keylesspalace/tusky/SFragment.java
@@ -18,7 +18,6 @@ package com.keylesspalace.tusky;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
-import android.media.ImageReader;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
@@ -37,7 +36,6 @@ import com.android.volley.toolbox.JsonObjectRequest;
import org.json.JSONObject;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
diff --git a/app/src/main/res/menu/main_toolbar.xml b/app/src/main/res/menu/main_toolbar.xml
index c5021b36..6da838bb 100644
--- a/app/src/main/res/menu/main_toolbar.xml
+++ b/app/src/main/res/menu/main_toolbar.xml
@@ -14,6 +14,11 @@
android:title="@string/action_profile"
app:showAsAction="never" />
+
+
-
+
+
+
+
- 5 minutes
+ - 10 minutes
+ - 15 minutes
+ - 20 minutes
+ - 25 minutes
+ - 30 minutes
+ - 45 minutes
+ - 1 hour
+ - 2 hours
+
+
+
+ - 5
+ - 10
+ - 15
+ - 20
+ - 25
+ - 30
+ - 45
+ - 60
+ - 120
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 121daab0..cf188b6b 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -96,6 +96,8 @@
Back
Profile
Open In Web
+ Preferences
+ Set
Toot!
@@ -119,4 +121,13 @@
%d new mentions
Mention from %s
+ Notifications
+ Enable Pull Notifcations
+ check for notifications periodically
+ Check Interval
+ how often to pull
+ Notify with a sound
+ Notify with vibration
+ Notify with light
+
diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml
new file mode 100644
index 00000000..e2b7f417
--- /dev/null
+++ b/app/src/main/res/xml/preferences.xml
@@ -0,0 +1,43 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+