Permalink
Browse files

Fixed bugs with feed view

  • Loading branch information...
1 parent 2a1115d commit 5fff2b8c643ca003dedd0a5c08b2f075d22da982 @murgo murgo committed May 5, 2012
View
4 Android/IrssiNotifier/res/menu/mainmenu.xml
@@ -6,31 +6,27 @@
android:icon="@drawable/irssi_connectbot"
android:showAsAction="ifRoom|withText"
android:title="Launch Irssi ConnectBot"
- android:actionProviderClass="fi.iki.murgo.irssinotifier.IrssiConnectbotActionProvider"
/>
<item
android:id="@+id/menu_settings"
android:icon="@drawable/ic_menu_preferences"
android:showAsAction="ifRoom|withText"
android:title="Settings"
- android:actionProviderClass="fi.iki.murgo.irssinotifier.SettingsActionProvider"
/>
<item
android:id="@+id/menu_clear_channel"
android:icon="@drawable/ic_menu_close_clear_cancel"
android:showAsAction="never|withText"
android:title="Clear channel messages"
- android:actionProviderClass="fi.iki.murgo.irssinotifier.ClearChannelActionProvider"
/>
<item
android:id="@+id/menu_remove_all_channels"
android:icon="@drawable/ic_menu_close_clear_cancel"
android:showAsAction="never|withText"
android:title="Remove all channels"
- android:actionProviderClass="fi.iki.murgo.irssinotifier.RemoveAllChannelsActionProvider"
/>
</menu>
View
33 Android/IrssiNotifier/res/xml/preference_screen.xml
@@ -1,21 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
- <PreferenceCategory android:title="Encryption settings">
- <EditTextPreference android:title="Encryption password" android:summary="This must be the same as the one in the Irssi script" android:defaultValue="password" android:key="EncryptionPassword" />
- </PreferenceCategory>
+ <PreferenceCategory android:title="Encryption settings">
+ <EditTextPreference android:title="Encryption password" android:summary="This must be the same as the one in the Irssi script" android:defaultValue="password" android:key="EncryptionPassword" />
+ </PreferenceCategory>
<PreferenceCategory android:title="Notification settings">
- <CheckBoxPreference android:title="Enable notifications" android:key="NotificationsEnabled" android:defaultValue="true" />
- <ListPreference android:title="Notification mode" android:summary="How many notifications you want" android:key="notificationModeString" android:defaultValue="Single" android:entryValues="@array/notification_modes" android:entries="@array/notification_modes" />
- <CheckBoxPreference android:title="Enable sound" android:key="SoundEnabled" android:defaultValue="true" />
- <RingtonePreference android:title="Select notification sound" android:summary="Select the sound to play when notifying" android:ringtoneType="notification" android:key="NotificationSound" android:showDefault="true" android:showSilent="false" android:defaultValue="content://settings/system/notification_sound" />
- <CheckBoxPreference android:title="Enable vibration" android:key="VibrationEnabled" android:defaultValue="true" />
- <CheckBoxPreference android:title="Enable flashing lights" android:summary="Flashes LEDs when notifying (where applicable)" android:key="LightsEnabled" android:defaultValue="true" />
- <CheckBoxPreference android:title="Enable spam filtering" android:summary="Only plays one notification sound per minute" android:key="SpamFilterEnabled" android:defaultValue="true" />
- </PreferenceCategory>
-
- <PreferenceCategory android:title="Misc">
- <Preference android:title="Channel settings" android:summary="Reorder and remove channels" android:key="channels" />
- <Preference android:title="About IrssiNotifier" android:key="about" />
- </PreferenceCategory>
+ <CheckBoxPreference android:title="Enable notifications" android:key="NotificationsEnabled" android:defaultValue="true" />
+ <ListPreference android:title="Notification mode" android:summary="How many notifications you want" android:key="notificationModeString" android:defaultValue="Single" android:entryValues="@array/notification_modes" android:entries="@array/notification_modes" />
+ <CheckBoxPreference android:title="Enable sound" android:key="SoundEnabled" android:defaultValue="true" />
+ <RingtonePreference android:title="Select notification sound" android:summary="Select the sound to play when notifying" android:ringtoneType="notification" android:key="NotificationSound" android:showDefault="true" android:showSilent="false" android:defaultValue="content://settings/system/notification_sound" />
+ <CheckBoxPreference android:title="Enable vibration" android:key="VibrationEnabled" android:defaultValue="true" />
+ <CheckBoxPreference android:title="Enable flashing lights" android:summary="Flashes LEDs when notifying (where applicable)" android:key="LightsEnabled" android:defaultValue="true" />
+ <CheckBoxPreference android:title="Enable spam filtering" android:summary="Only plays one notification sound per minute" android:key="SpamFilterEnabled" android:defaultValue="true" />
+ <CheckBoxPreference android:title="Feed view as default tab" android:summary="If turned off, channel with activity will be the tab to open" android:key="FeedViewDefault" android:defaultValue="true" />
+ </PreferenceCategory>
+
+ <PreferenceCategory android:title="Misc">
+ <Preference android:title="Channel settings" android:summary="Reorder and remove channels" android:key="channels" />
+ <Preference android:title="About IrssiNotifier" android:key="about" />
+ </PreferenceCategory>
</PreferenceScreen>
View
33 Android/IrssiNotifier/src/fi/iki/murgo/irssinotifier/DataAccess.java
@@ -13,7 +13,7 @@
public class DataAccess extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "IrssiNotifier";
- private static final int DATABASE_VERSION = 3;
+ private static final int DATABASE_VERSION = 4;
public DataAccess(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
@@ -23,18 +23,20 @@ public DataAccess(Context context) {
public void onCreate(SQLiteDatabase db) {
try {
db.execSQL("CREATE TABLE Channel (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, orderIndex INTEGER)");
- db.execSQL("CREATE TABLE IrcMessage (id INTEGER PRIMARY KEY AUTOINCREMENT, channelId INTEGER, message TEXT, nick TEXT, serverTimestamp INTEGER, externalId TEXT, shown INTEGER, FOREIGN KEY(channelId) REFERENCES Channel(Id))");
+ db.execSQL("CREATE TABLE IrcMessage (id INTEGER PRIMARY KEY AUTOINCREMENT, channelId INTEGER, message TEXT, nick TEXT, serverTimestamp INTEGER, externalId TEXT, shown INTEGER, FOREIGN KEY(channelId) REFERENCES Channel(Id), clearedFromFeed INTEGER)");
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
- if (oldVersion < 666) {
+ if (oldVersion < 2) {
db.execSQL("DROP TABLE IF EXISTS Channel");
db.execSQL("DROP TABLE IF EXISTS IrcMessage");
onCreate(db);
+ } else if (oldVersion < 4) {
+ db.execSQL("ALTER TABLE IrcMessage ADD COLUMN clearedFromFeed INTEGER");
}
}
@@ -141,7 +143,7 @@ public void setAllMessagesAsShown() {
}
private List<IrcMessage> getMessagesForChannel(SQLiteDatabase database, Channel channel) {
- Cursor cursor = database.query("IrcMessage", new String[] {"message", "nick", "serverTimestamp", "shown", "externalId" }, "channelId = ?", new String[] { Long.toString(channel.getId()) }, null, null, "serverTimestamp DESC", "100");
+ Cursor cursor = database.query("IrcMessage", new String[] {"message", "nick", "serverTimestamp", "shown", "externalId", "clearedFromFeed", "id"}, "channelId = ?", new String[] { Long.toString(channel.getId()) }, null, null, "serverTimestamp DESC", "100");
cursor.moveToFirst();
List<IrcMessage> list = new ArrayList<IrcMessage>();
@@ -150,7 +152,9 @@ public void setAllMessagesAsShown() {
int colServerTimestamp = cursor.getColumnIndex("serverTimestamp");
int colExternalId = cursor.getColumnIndex("externalId");
int colShown = cursor.getColumnIndex("shown");
-
+ int colClearedFromFeed = cursor.getColumnIndex("clearedFromFeed");
+ int colId = cursor.getColumnIndex("id");
+
while (!cursor.isAfterLast()) {
IrcMessage message = new IrcMessage();
message.setMessage(cursor.getString(colMessage));
@@ -159,6 +163,8 @@ public void setAllMessagesAsShown() {
message.setExternalId(cursor.getString(colExternalId));
message.setChannel(channel.getName());
message.setShown(cursor.getInt(colShown) == 0 ? false : true);
+ message.setClearedFromFeed(cursor.getInt(colClearedFromFeed) == 0 ? false : true);
+ message.setId(cursor.getLong(colId));
list.add(message);
cursor.moveToNext();
@@ -177,7 +183,14 @@ public void setChannelAsShown(Channel channel) {
database.close();
}
- public void handleChannelSettings(List<String> names) {
+ public void clearMessagesFromFeed(List<Long> messageIds) {
+ SQLiteDatabase database = getWritableDatabase();
+ ContentValues values = new ContentValues();
+ values.put("clearedFromFeed", true);
+ for (Long id : messageIds) {
+ database.update("IrcMessage", values, "id = ?", new String[] { id.toString() });
+ }
+ database.close();
}
public void removeChannel(Channel channel) {
@@ -199,4 +212,12 @@ public void updateChannel(Channel channel) {
database.update("Channel", values, "id = ?", new String[] { Long.toString(channel.getId()) });
database.close();
}
+
+ public void clearAllMessagesFromFeed() {
+ SQLiteDatabase database = getWritableDatabase();
+ ContentValues values = new ContentValues();
+ values.put("clearedFromFeed", true);
+ database.update("IrcMessage", values, null, null);
+ database.close();
+ }
}
View
32 Android/IrssiNotifier/src/fi/iki/murgo/irssinotifier/DataAccessTask.java
@@ -1,5 +1,8 @@
package fi.iki.murgo.irssinotifier;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
import java.util.List;
import android.content.Context;
import android.os.AsyncTask;
@@ -24,6 +27,35 @@ public DataAccessTask(Context context, Callback<List<Channel>> callback) {
}
List<Channel> channels = da.getChannels();
+
+ // clear old messages from feed
+ List<IrcMessage> messages = new ArrayList<IrcMessage>();
+ for (Channel ch : channels) {
+ for (IrcMessage message : ch.getMessages()) {
+ if (!message.getClearedFromFeed()) {
+ messages.add(message);
+ }
+ }
+ }
+
+ final int maximumMessagesInFeed = 50;
+
+ if (messages.size() > maximumMessagesInFeed) {
+ Collections.sort(messages, new Comparator<IrcMessage>(){
+ public int compare(IrcMessage lhs, IrcMessage rhs) {
+ return lhs.getServerTimestamp().compareTo(rhs.getServerTimestamp());
+ }});
+
+ List<Long> toClearIds = new ArrayList<Long>();
+
+ for (int i = 0; i < messages.size() - maximumMessagesInFeed; i++) {
+ toClearIds.add(messages.get(i).getId());
+ messages.get(i).setClearedFromFeed(true);
+ }
+
+ da.clearMessagesFromFeed(toClearIds);
+ }
+
return channels;
}
View
18 Android/IrssiNotifier/src/fi/iki/murgo/irssinotifier/IrcMessage.java
@@ -16,6 +16,8 @@
private Date serverTimestamp;
private String externalId;
private boolean shown;
+ private boolean clearedFromFeed;
+ private long id;
public void Deserialize(String payload) throws JSONException {
Deserialize(new JSONObject(payload));
@@ -108,4 +110,20 @@ public boolean isShown() {
return shown;
}
+ public void setClearedFromFeed(boolean b) {
+ this.clearedFromFeed = b;
+ }
+
+ public boolean getClearedFromFeed() {
+ return clearedFromFeed;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public long getId() {
+ return id;
+ }
+
}
View
93 Android/IrssiNotifier/src/fi/iki/murgo/irssinotifier/IrssiNotifierActivity.java
@@ -33,6 +33,7 @@
private String channelToView;
private List<Channel> channels;
private Object channelsLock = new Object();
+ private static final String FEED = "------------------------FEED";
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -62,7 +63,7 @@ public void onCreate(Bundle savedInstanceState) {
Intent i = getIntent();
if (i != null) {
String intentChannelToView = i.getStringExtra("Channel");
- if (intentChannelToView != null)
+ if (intentChannelToView != null && !preferences.isFeedViewDefault())
channelToView = intentChannelToView;
}
@@ -79,7 +80,7 @@ public void onCreate(Bundle savedInstanceState) {
@Override
protected void onNewIntent(Intent intent) {
String intentChannelToView = intent.getStringExtra("Channel");
- if (intentChannelToView != null)
+ if (intentChannelToView != null && !preferences.isFeedViewDefault())
channelToView = intentChannelToView;
IrcNotificationManager.getInstance().mainActivityOpened(this);
@@ -137,9 +138,8 @@ public static IrssiNotifierActivity getForegroundInstance() {
return instance;
}
- private void startMainApp(boolean uptodate) {
+ private void startMainApp(final boolean uptodate) {
Log.d(TAG, "Main startup");
- refreshUi();
if (preferences.settingsNeedSending()) {
Log.d(TAG, "Settings are not saved, odd");
@@ -148,17 +148,8 @@ private void startMainApp(boolean uptodate) {
final Activity ctx = this;
- final Callback<List<Channel>> dataAccessCallback = new Callback<List<Channel>>() {
- public void doStuff(List<Channel> param) {
- synchronized (channelsLock) {
- channels = param;
- }
- refreshUi();
- }
- };
-
final long now = new Date().getTime();
- DataFetcherTask task = new DataFetcherTask(preferences.getAuthToken(), preferences.getEncryptionPassword(), preferences.getLastFetchTime(), new Callback<DataFetchResult>() {
+ final DataFetcherTask dataFetcherTask = new DataFetcherTask(preferences.getAuthToken(), preferences.getEncryptionPassword(), preferences.getLastFetchTime(), new Callback<DataFetchResult>() {
// TODO: Move this into its own activity, so orientation changes work correctly
public void doStuff(DataFetchResult param) {
setIndeterminateProgressBarVisibility(false);
@@ -191,17 +182,33 @@ public void doStuff(DataFetchResult param) {
return;
}
- DataAccessTask task = new DataAccessTask(ctx, dataAccessCallback);
+ DataAccessTask task = new DataAccessTask(ctx, new Callback<List<Channel>>() {
+ public void doStuff(List<Channel> param) {
+ synchronized (channelsLock) {
+ channels = param;
+ refreshUi();
+ }
+ }
+ });
task.execute(param.getMessages().toArray(new IrcMessage[0]));
}
});
- if (!uptodate) {
- setIndeterminateProgressBarVisibility(true);
-
- task.execute();
- }
-
+ final Callback<List<Channel>> dataAccessCallback = new Callback<List<Channel>>() {
+ public void doStuff(List<Channel> param) {
+ synchronized (channelsLock) {
+ channels = param;
+ refreshUi();
+ }
+
+ if (!uptodate) {
+ setIndeterminateProgressBarVisibility(true);
+
+ dataFetcherTask.execute();
+ }
+ }
+ };
+
DataAccessTask datask = new DataAccessTask(ctx, dataAccessCallback);
datask.execute();
}
@@ -210,7 +217,7 @@ private void refreshUi() {
synchronized (channelsLock) {
setContentView(R.layout.main);
- setIndeterminateProgressBarVisibility(!progressBarVisibility); // häx häx
+ setIndeterminateProgressBarVisibility(!progressBarVisibility); // hack
setIndeterminateProgressBarVisibility(!progressBarVisibility);
pager = (ViewPager) findViewById(R.id.pager);
@@ -228,10 +235,14 @@ private void refreshUi() {
titleIndicator.setOnPageChangeListener(new OnPageChangeListener() {
public void onPageSelected(int arg0) {
if (channels != null) {
- if (arg0 == 0) arg0 = 1; // TODO megahack
- Channel ch = channels.get(arg0 - 1); // TODO hack
- if (ch != null) {
- channelToView = ch.getName();
+ if (arg0 == 0) {
+ // feed
+ channelToView = FEED;
+ } else {
+ Channel ch = channels.get(arg0 - 1);
+ if (ch != null) {
+ channelToView = ch.getName();
+ }
}
}
}
@@ -240,14 +251,22 @@ public void onPageScrolled(int arg0, float arg1, int arg2) { }
public void onPageScrollStateChanged(int arg0) { }
});
- if (channelToView != null && channels != null && channels.size() > 1) {
- for (int i = 0; i < channels.size(); i++) {
- if (channels.get(i).getName().equals(channelToView)) {
- pager.setCurrentItem(i);
- break;
- }
+ if (channelToView != null && channels != null) {
+ if (channelToView.equals(FEED)) {
+ pager.setCurrentItem(0);
+ } else {
+ for (int i = 0; i < channels.size(); i++) {
+ if (channels.get(i).getName().equals(channelToView)) {
+ pager.setCurrentItem(i + 1);
+ break;
+ }
+ }
}
}
+
+ if (channelToView == null) {
+ channelToView = FEED;
+ }
}
}
@@ -279,6 +298,7 @@ public void doStuff(Void param) {
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getSupportMenuInflater().inflate(R.menu.mainmenu, menu);
+
if (!IntentSniffer.isIntentAvailable(this, IrssiConnectbotLauncher.INTENT_IRSSICONNECTBOT)) {
menu.findItem(R.id.menu_irssi_connectbot).setVisible(false);
menu.findItem(R.id.menu_irssi_connectbot).setEnabled(false);
@@ -298,6 +318,15 @@ public boolean onOptionsItemSelected(MenuItem item) {
DataAccess da = new DataAccess(this);
List<Channel> channels = da.getChannels();
Channel channelToClear = null;
+
+ if (channelToView == null) return true;
+
+ if (channelToView.equals(FEED)) {
+ da.clearAllMessagesFromFeed();
+ startMainApp(true);
+ return true;
+ }
+
for (Channel ch : channels) {
if (ch.getName().equals(channelToView)) {
channelToClear = ch;
View
4 Android/IrssiNotifier/src/fi/iki/murgo/irssinotifier/IrssiNotifierApplication.java
@@ -5,11 +5,11 @@
import android.app.Application;
-@ReportsCrashes(formKey = "dHgyVnlwanVub3J5NnZaYnFheWVKUHc6MQ")
+//@ReportsCrashes(formKey = "dHgyVnlwanVub3J5NnZaYnFheWVKUHc6MQ")
public class IrssiNotifierApplication extends Application {
@Override
public void onCreate() {
- ACRA.init(this);
+ //ACRA.init(this); // TODO
super.onCreate();
}
View
8 Android/IrssiNotifier/src/fi/iki/murgo/irssinotifier/MessagePagerAdapter.java
@@ -92,14 +92,18 @@ private View createEmptyChannel() {
private View createFeed() {
List<IrcMessage> messages = new ArrayList<IrcMessage>();
for (Channel ch : channels) {
- messages.addAll(ch.getMessages());
+ for (IrcMessage message : ch.getMessages()) {
+ if (!message.getClearedFromFeed()) {
+ messages.add(message);
+ }
+ }
}
Collections.sort(messages, new Comparator<IrcMessage>(){
public int compare(IrcMessage lhs, IrcMessage rhs) {
return lhs.getServerTimestamp().compareTo(rhs.getServerTimestamp());
}});
-
+
View channelView = layoutInflater.inflate(R.layout.channel, null);
TextView name = (TextView) channelView.findViewById(R.id.channel_name);
name.setText("Feed");
View
11 Android/IrssiNotifier/src/fi/iki/murgo/irssinotifier/Preferences.java
@@ -36,6 +36,7 @@
private static final String NOTIFICATION_SOUND = "NotificationSound";
private static final String LIGHTS_ENABLED = "LightsEnabled";
private static final String VIBRATION_ENABLED = "VibrationEnabled";
+ private static final String FEED_VIEW_DEFAULT = "FeedViewDefault";
private SharedPreferences sharedPreferences;
@@ -146,4 +147,14 @@ public boolean isVibrationEnabled() {
public boolean isLightsEnabled() {
return sharedPreferences.getBoolean(LIGHTS_ENABLED, true);
}
+
+ public boolean isFeedViewDefault() {
+ return sharedPreferences.getBoolean(FEED_VIEW_DEFAULT, true);
+ }
+
+ public boolean setFeedViewDefault(boolean b) {
+ SharedPreferences.Editor editor = sharedPreferences.edit();
+ editor.putBoolean(FEED_VIEW_DEFAULT, b);
+ return editor.commit();
+ }
}

0 comments on commit 5fff2b8

Please sign in to comment.