diff --git a/app/src/main/java/com/github/dfa/diaspora_android/activity/MainActivity.java b/app/src/main/java/com/github/dfa/diaspora_android/activity/MainActivity.java index 586d786d..42b0d98d 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/activity/MainActivity.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/activity/MainActivity.java @@ -48,6 +48,7 @@ import android.support.v4.widget.DrawerLayout; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.app.AppCompatActivity; +import android.support.v7.app.NotificationCompat; import android.support.v7.widget.ActionMenuView; import android.support.v7.widget.Toolbar; import android.text.Html; @@ -120,7 +121,6 @@ public class MainActivity extends AppCompatActivity private App app; private String podDomain; - private Menu menu; private ValueCallback mFilePathCallback; private String mCameraPhotoPath; private WebSettings webSettings; @@ -314,19 +314,15 @@ public class MainActivity extends AppCompatActivity progressBar.setProgress(progress); if (progress > 0 && progress <= 60) { - Helpers.getNotificationCount(wv); Helpers.getUserProfile(wv); + Helpers.optimizeMobileSiteLayout(wv); } if (progress > 60) { - Helpers.applyDiasporaMobileSiteChanges(wv); + Helpers.optimizeMobileSiteLayout(wv); } - if (progress == 100) { - progressBar.setVisibility(View.GONE); - } else { - progressBar.setVisibility(View.VISIBLE); - } + progressBar.setVisibility(progress == 100 ? View.GONE : View.VISIBLE); } @Override @@ -535,9 +531,11 @@ public class MainActivity extends AppCompatActivity if (webView.canGoBack()) { webView.goBack(); - } else { - if (!snackbarExitApp.isShown()) - snackbarExitApp.show(); + return; + } + + if (!snackbarExitApp.isShown()) { + snackbarExitApp.show(); } } @@ -598,7 +596,6 @@ public class MainActivity extends AppCompatActivity @Override public boolean onPrepareOptionsMenu(Menu menu) { - this.menu = menu; MenuItem itemNotification = menu.findItem(R.id.action_notifications); if (itemNotification != null) { if (podUserProfile.getNotificationCount() > 0) { @@ -756,6 +753,7 @@ public class MainActivity extends AppCompatActivity return super.onOptionsItemSelected(item); } + @SuppressWarnings("ResultOfMethodCallIgnored") private boolean makeScreenshotOfWebView(boolean hasToShareScreenshot) { if (android.os.Build.VERSION.SDK_INT >= 23) { int hasWRITE_EXTERNAL_STORAGE = checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE); @@ -811,7 +809,7 @@ public class MainActivity extends AppCompatActivity if (bitmapWriter != null) { try { bitmapWriter.close(); - } catch (IOException _ignored) {/* Nothing */} + } catch (IOException _ignSaveored) {/* Nothing */} } } @@ -918,32 +916,24 @@ public class MainActivity extends AppCompatActivity // TODO: Move from Javascript interface @Override public void onNotificationCountChanged(int notificationCount) { - MenuItem item = menu.findItem(R.id.action_notifications); + // Count saved in PodUserProfile + invalidateOptionsMenu(); - if (item != null) { - if (notificationCount > 0) { - item.setIcon(R.drawable.ic_notifications_colored_48px); - if (!snackbarNewNotification.isShown() && !webView.getUrl().equals("https://" + podDomain + "/notifications")) - snackbarNewNotification.show(); - } else { - item.setIcon(R.drawable.ic_notifications_white_48px); - } + if (notificationCount > 0 && !snackbarNewNotification.isShown() + && !webView.getUrl().equals("https://" + podDomain + "/notifications")) { + snackbarNewNotification.show(); } } // TODO: Move from Javascript interface @Override public void onUnreadMessageCountChanged(int unreadMessageCount) { - MenuItem item = menu.findItem(R.id.action_conversations); + // Count saved in PodUserProfile + invalidateOptionsMenu(); - if (item != null) { - if (unreadMessageCount > 0) { - item.setIcon(R.drawable.ic_email_colored_48px); - if (!snackbarNewNotification.isShown() && !webView.getUrl().equals("https://" + podDomain + "/conversations")) - snackbarNewNotification.show(); - } else { - item.setIcon(R.drawable.ic_mail_white_48px); - } + if (unreadMessageCount > 0 && !snackbarNewNotification.isShown() + && !webView.getUrl().equals("https://" + podDomain + "/notifications")) { + snackbarNewNotification.show(); } } diff --git a/app/src/main/java/com/github/dfa/diaspora_android/data/AppSettings.java b/app/src/main/java/com/github/dfa/diaspora_android/data/AppSettings.java index 82daf248..e15f35e2 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/data/AppSettings.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/data/AppSettings.java @@ -87,6 +87,10 @@ public class AppSettings { return pref.getBoolean(context.getString(ressourceId), defaultValue); } + private int getInt(SharedPreferences pref, int ressourceId, int defaultValue) { + return pref.getInt(context.getString(ressourceId), defaultValue); + } + /* // Setters & Getters @@ -174,6 +178,22 @@ public class AppSettings { setStringArray(prefPod, R.string.pref_key__podprofile_followed_tags, tags); } + public int getUnreadMessageCount(){ + return getInt(prefPod, R.string.pref_key__podprofile_unread_message_count, 0); + } + + public void setUnreadMessageCount(int unreadMessageCount) { + setInt(prefPod, R.string.pref_key__podprofile_unread_message_count, unreadMessageCount); + } + + public int getNotificationCount(){ + return getInt(prefPod, R.string.pref_key__podprofile_notification_count, 0); + } + + public void setNotificationCount(int notificationCount) { + setInt(prefPod, R.string.pref_key__podprofile_notification_count, notificationCount); + } + public boolean isAppendSharedViaApp() { return getBoolean(prefApp, R.string.pref_key__append_shared_via_app, true); } diff --git a/app/src/main/java/com/github/dfa/diaspora_android/data/PodUserProfile.java b/app/src/main/java/com/github/dfa/diaspora_android/data/PodUserProfile.java index 898ca0a1..420d984b 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/data/PodUserProfile.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/data/PodUserProfile.java @@ -60,6 +60,8 @@ public class PodUserProfile { name = appSettings.getName(); podAspects = appSettings.getPodAspects(); followedTags = appSettings.getFollowedTags(); + notificationCount = appSettings.getNotificationCount(); + unreadMessagesCount = appSettings.getUnreadMessageCount(); } public PodUserProfile(App app, Handler callbackHandler, WebUserProfileChangedListener listener) { @@ -102,11 +104,12 @@ public class PodUserProfile { // Unread message count if (json.has("notifications_count") && loadNotificationCount(json.getInt("notifications_count"))) { + appSettings.setNotificationCount(notificationCount); } // Unread message count if (json.has("unread_messages_count") && loadUnreadMessagesCount(json.getInt("unread_messages_count"))) { - appSettings.setPodAspects(podAspects); + appSettings.setUnreadMessageCount(unreadMessagesCount); } // Aspect diff --git a/app/src/main/java/com/github/dfa/diaspora_android/util/Helpers.java b/app/src/main/java/com/github/dfa/diaspora_android/util/Helpers.java index 2a77e77e..ecb584fc 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/util/Helpers.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/util/Helpers.java @@ -53,8 +53,9 @@ public class Helpers { } } - public static void applyDiasporaMobileSiteChanges(final WebView wv) { + public static void optimizeMobileSiteLayout(final WebView wv) { wv.loadUrl("javascript: ( function() {" + + " if (document.documentElement == null || document.documentElement.style == null) { return; }" + " document.documentElement.style.paddingBottom = '260px';" + " document.getElementById('main').style.paddingTop = '5px';" + " if(document.getElementById('main_nav')) {" + diff --git a/app/src/main/res/values/strings-preferences.xml b/app/src/main/res/values/strings-preferences.xml index 864b90bd..77b45318 100644 --- a/app/src/main/res/values/strings-preferences.xml +++ b/app/src/main/res/values/strings-preferences.xml @@ -30,6 +30,8 @@ podUserProfile_guid podUserProfile_aspects podUserProfile_followedTags + podUserProfile_unreadMessageCount + podUserProfile_NotificationCount