mirror of
https://github.com/gsantner/dandelion
synced 2024-11-22 04:12:08 +01:00
Update notification&message icon to visualize current state
This commit is contained in:
parent
4b9bbdb5d7
commit
a5d9f05700
2 changed files with 22 additions and 75 deletions
|
@ -121,8 +121,6 @@ public class MainActivity extends AppCompatActivity
|
|||
private App app;
|
||||
private String podDomain;
|
||||
private Menu menu;
|
||||
private int notificationCount = 0;
|
||||
private int conversationCount = 0;
|
||||
private ValueCallback<Uri[]> mFilePathCallback;
|
||||
private String mCameraPhotoPath;
|
||||
private WebSettings webSettings;
|
||||
|
@ -603,14 +601,14 @@ public class MainActivity extends AppCompatActivity
|
|||
this.menu = menu;
|
||||
MenuItem itemNotification = menu.findItem(R.id.action_notifications);
|
||||
if (itemNotification != null) {
|
||||
if (notificationCount > 0) {
|
||||
if (podUserProfile.getNotificationCount() > 0) {
|
||||
itemNotification.setIcon(R.drawable.ic_notifications_colored_48px);
|
||||
} else {
|
||||
itemNotification.setIcon(R.drawable.ic_notifications_white_48px);
|
||||
}
|
||||
|
||||
MenuItem itemConversation = menu.findItem(R.id.action_conversations);
|
||||
if (conversationCount > 0) {
|
||||
if (podUserProfile.getUnreadMessagesCount() > 0) {
|
||||
itemConversation.setIcon(R.drawable.ic_email_colored_48px);
|
||||
} else {
|
||||
itemConversation.setIcon(R.drawable.ic_mail_white_48px);
|
||||
|
@ -920,26 +918,6 @@ public class MainActivity extends AppCompatActivity
|
|||
// TODO: Move from Javascript interface
|
||||
@Override
|
||||
public void onNotificationCountChanged(int notificationCount) {
|
||||
|
||||
}
|
||||
|
||||
// TODO: Move from Javascript interface
|
||||
@Override
|
||||
public void onUnreadMessageCountChanged(int unreadMessageCount) {
|
||||
|
||||
}
|
||||
|
||||
private class JavaScriptInterface {
|
||||
@JavascriptInterface
|
||||
public void setNotificationCount(final String webMessage) {
|
||||
uiHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (menu == null) {
|
||||
return;
|
||||
}
|
||||
notificationCount = Integer.valueOf(webMessage);
|
||||
|
||||
MenuItem item = menu.findItem(R.id.action_notifications);
|
||||
|
||||
if (item != null) {
|
||||
|
@ -951,45 +929,31 @@ public class MainActivity extends AppCompatActivity
|
|||
item.setIcon(R.drawable.ic_notifications_white_48px);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// TODO: Move from Javascript interface
|
||||
@Override
|
||||
public void onUnreadMessageCountChanged(int unreadMessageCount) {
|
||||
MenuItem item = menu.findItem(R.id.action_conversations);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class JavaScriptInterface {
|
||||
@JavascriptInterface
|
||||
public void setUserProfile(final String webMessage) throws JSONException {
|
||||
if (podUserProfile.isRefreshNeeded()) {
|
||||
podUserProfile.parseJson(webMessage);
|
||||
}
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void setConversationCount(final String webMessage) {
|
||||
uiHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (menu == null) {
|
||||
return;
|
||||
}
|
||||
conversationCount = Integer.valueOf(webMessage);
|
||||
|
||||
MenuItem item = menu.findItem(R.id.action_conversations);
|
||||
|
||||
if (item != null) {
|
||||
if (conversationCount > 0) {
|
||||
item.setIcon(R.drawable.ic_email_colored_48px);
|
||||
if (!snackbarNewNotification.isShown() && !webView.getUrl().equals("https://" + podDomain + "/notifications"))
|
||||
snackbarNewNotification.show();
|
||||
} else {
|
||||
item.setIcon(R.drawable.ic_mail_white_48px);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("StatementWithEmptyBody")
|
||||
|
|
|
@ -67,23 +67,6 @@ public class Helpers {
|
|||
"})();");
|
||||
}
|
||||
|
||||
public static void getNotificationCount(final WebView wv) {
|
||||
wv.loadUrl("javascript: ( function() {" +
|
||||
"if (document.getElementById('notification')) {" +
|
||||
" var count = document.getElementById('notification').innerHTML;" +
|
||||
" AndroidBridge.setNotificationCount(count.replace(/(\\r\\n|\\n|\\r)/gm, \"\"));" +
|
||||
" } else {" +
|
||||
" AndroidBridge.setNotificationCount('0');" +
|
||||
" }" +
|
||||
" if (document.getElementById('conversation')) {" +
|
||||
" var count = document.getElementById('conversation').innerHTML;" +
|
||||
" AndroidBridge.setConversationCount(count.replace(/(\\r\\n|\\n|\\r)/gm, \"\"));" +
|
||||
" } else {" +
|
||||
" AndroidBridge.setConversationCount('0');" +
|
||||
" }" +
|
||||
"})();");
|
||||
}
|
||||
|
||||
public static void getUserProfile(final WebView wv) {
|
||||
// aspects":[{"id":124934,"name":"Friends","selected":true},{"id":124937,"name":"Liked me","selected":false},{"id":124938,"name":"Follow","selected":false},{"id":128327,"name":"Nur ich","selected":false}]
|
||||
wv.loadUrl("javascript: ( function() {" +
|
||||
|
|
Loading…
Reference in a new issue