From fe89751e71854f9a9b87e3a4d2ac9f3f43ac1283 Mon Sep 17 00:00:00 2001 From: David Development Date: Thu, 14 Jan 2016 16:51:56 +0100 Subject: [PATCH] Fix #374 --- .../PodcastFragmentActivity.java | 3 ++ .../helper/TeslaUnreadManager.java | 39 +++++++++++++++++++ .../services/OwnCloudSyncService.java | 5 ++- 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/TeslaUnreadManager.java diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/PodcastFragmentActivity.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/PodcastFragmentActivity.java index efa04ff5..406388c5 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/PodcastFragmentActivity.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/PodcastFragmentActivity.java @@ -38,6 +38,7 @@ import de.luhmer.owncloudnewsreader.events.podcast.PodcastCompletedEvent; import de.luhmer.owncloudnewsreader.events.podcast.RegisterVideoOutput; import de.luhmer.owncloudnewsreader.events.podcast.UpdatePodcastStatusEvent; import de.luhmer.owncloudnewsreader.helper.SizeAnimator; +import de.luhmer.owncloudnewsreader.helper.TeslaUnreadManager; import de.luhmer.owncloudnewsreader.interfaces.IPlayPausePodcastClicked; import de.luhmer.owncloudnewsreader.model.MediaItem; import de.luhmer.owncloudnewsreader.model.PodcastItem; @@ -147,6 +148,8 @@ public class PodcastFragmentActivity extends AppCompatActivity implements IPlayP eventBus.unregister(this); eventBus.post(new RegisterVideoOutput(null, null)); + TeslaUnreadManager.PublishUnreadCount(this); + super.onPause(); } diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/TeslaUnreadManager.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/TeslaUnreadManager.java new file mode 100644 index 00000000..1980ef63 --- /dev/null +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/TeslaUnreadManager.java @@ -0,0 +1,39 @@ +package de.luhmer.owncloudnewsreader.helper; + +import android.content.ContentValues; +import android.content.Context; +import android.net.Uri; + +import de.luhmer.owncloudnewsreader.ListView.SubscriptionExpandableListAdapter; +import de.luhmer.owncloudnewsreader.database.DatabaseConnectionOrm; + +/** + * Created by David on 14.01.2016. + */ +public class TeslaUnreadManager { + public static void PublishUnreadCount(Context context) { + try { + //Check if TeslaUnread is installed before doing some expensive database query + ContentValues cv = new ContentValues(); + cv.put("tag", "de.luhmer.owncloudnewsreader/de.luhmer.owncloudnewsreader"); + cv.put("count", 0); + context.getContentResolver().insert(Uri.parse("content://com.teslacoilsw.notifier/unread_count"), cv); + + //If we get here.. TeslaUnread is installed + DatabaseConnectionOrm dbConn = new DatabaseConnectionOrm(context); + int count = Integer.parseInt(dbConn.getUnreadItemsCountForSpecificFolder(SubscriptionExpandableListAdapter.SPECIAL_FOLDERS.ALL_UNREAD_ITEMS)); + + cv.put("count", count); + context.getContentResolver().insert(Uri.parse("content://com.teslacoilsw.notifier/unread_count"), cv); + } catch (IllegalArgumentException ex) { + /* Fine, TeslaUnread is not installed. */ + } catch (Exception ex) { + /* Some other error, possibly because the format of the ContentValues are incorrect. + Log but do not crash over this. */ + + ex.printStackTrace(); + + } + + } +} diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/services/OwnCloudSyncService.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/services/OwnCloudSyncService.java index d64beead..b09977d8 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/services/OwnCloudSyncService.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/services/OwnCloudSyncService.java @@ -48,6 +48,7 @@ import de.luhmer.owncloudnewsreader.R; import de.luhmer.owncloudnewsreader.SettingsActivity; import de.luhmer.owncloudnewsreader.helper.AidlException; import de.luhmer.owncloudnewsreader.helper.NotificationManagerNewsReader; +import de.luhmer.owncloudnewsreader.helper.TeslaUnreadManager; import de.luhmer.owncloudnewsreader.reader.FeedItemTags; import de.luhmer.owncloudnewsreader.reader.OnAsyncTaskCompletedListener; import de.luhmer.owncloudnewsreader.reader.owncloud.OwnCloud_Reader; @@ -189,6 +190,8 @@ public class OwnCloudSyncService extends Service { } private void finishedSync() { + TeslaUnreadManager.PublishUnreadCount(this); + syncRunning = false; syncStopWatch.stop(); Log.v(TAG, "Time needed (synchronization): " + syncStopWatch.toString()); @@ -217,7 +220,7 @@ public class OwnCloudSyncService extends Service { try { icb.finishedSync(); //icb.finishedSyncOfItems(); - } catch (RemoteException e) { + } catch (RemoteException e) { e.printStackTrace(); } }