1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-11-25 22:02:08 +01:00

Load from/save counts from prefs

This commit is contained in:
Gregor Santner 2016-08-07 11:39:20 +02:00
parent a5d9f05700
commit 8f2a01ca73
5 changed files with 49 additions and 33 deletions

View file

@ -48,6 +48,7 @@ import android.support.v4.widget.DrawerLayout;
import android.support.v4.widget.SwipeRefreshLayout; import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.support.v7.app.NotificationCompat;
import android.support.v7.widget.ActionMenuView; import android.support.v7.widget.ActionMenuView;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.text.Html; import android.text.Html;
@ -120,7 +121,6 @@ public class MainActivity extends AppCompatActivity
private App app; private App app;
private String podDomain; private String podDomain;
private Menu menu;
private ValueCallback<Uri[]> mFilePathCallback; private ValueCallback<Uri[]> mFilePathCallback;
private String mCameraPhotoPath; private String mCameraPhotoPath;
private WebSettings webSettings; private WebSettings webSettings;
@ -314,19 +314,15 @@ public class MainActivity extends AppCompatActivity
progressBar.setProgress(progress); progressBar.setProgress(progress);
if (progress > 0 && progress <= 60) { if (progress > 0 && progress <= 60) {
Helpers.getNotificationCount(wv);
Helpers.getUserProfile(wv); Helpers.getUserProfile(wv);
Helpers.optimizeMobileSiteLayout(wv);
} }
if (progress > 60) { if (progress > 60) {
Helpers.applyDiasporaMobileSiteChanges(wv); Helpers.optimizeMobileSiteLayout(wv);
} }
if (progress == 100) { progressBar.setVisibility(progress == 100 ? View.GONE : View.VISIBLE);
progressBar.setVisibility(View.GONE);
} else {
progressBar.setVisibility(View.VISIBLE);
}
} }
@Override @Override
@ -535,8 +531,10 @@ public class MainActivity extends AppCompatActivity
if (webView.canGoBack()) { if (webView.canGoBack()) {
webView.goBack(); webView.goBack();
} else { return;
if (!snackbarExitApp.isShown()) }
if (!snackbarExitApp.isShown()) {
snackbarExitApp.show(); snackbarExitApp.show();
} }
} }
@ -598,7 +596,6 @@ public class MainActivity extends AppCompatActivity
@Override @Override
public boolean onPrepareOptionsMenu(Menu menu) { public boolean onPrepareOptionsMenu(Menu menu) {
this.menu = menu;
MenuItem itemNotification = menu.findItem(R.id.action_notifications); MenuItem itemNotification = menu.findItem(R.id.action_notifications);
if (itemNotification != null) { if (itemNotification != null) {
if (podUserProfile.getNotificationCount() > 0) { if (podUserProfile.getNotificationCount() > 0) {
@ -756,6 +753,7 @@ public class MainActivity extends AppCompatActivity
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
@SuppressWarnings("ResultOfMethodCallIgnored")
private boolean makeScreenshotOfWebView(boolean hasToShareScreenshot) { private boolean makeScreenshotOfWebView(boolean hasToShareScreenshot) {
if (android.os.Build.VERSION.SDK_INT >= 23) { if (android.os.Build.VERSION.SDK_INT >= 23) {
int hasWRITE_EXTERNAL_STORAGE = checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE); int hasWRITE_EXTERNAL_STORAGE = checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
@ -811,7 +809,7 @@ public class MainActivity extends AppCompatActivity
if (bitmapWriter != null) { if (bitmapWriter != null) {
try { try {
bitmapWriter.close(); bitmapWriter.close();
} catch (IOException _ignored) {/* Nothing */} } catch (IOException _ignSaveored) {/* Nothing */}
} }
} }
@ -918,32 +916,24 @@ public class MainActivity extends AppCompatActivity
// TODO: Move from Javascript interface // TODO: Move from Javascript interface
@Override @Override
public void onNotificationCountChanged(int notificationCount) { public void onNotificationCountChanged(int notificationCount) {
MenuItem item = menu.findItem(R.id.action_notifications); // Count saved in PodUserProfile
invalidateOptionsMenu();
if (item != null) { if (notificationCount > 0 && !snackbarNewNotification.isShown()
if (notificationCount > 0) { && !webView.getUrl().equals("https://" + podDomain + "/notifications")) {
item.setIcon(R.drawable.ic_notifications_colored_48px);
if (!snackbarNewNotification.isShown() && !webView.getUrl().equals("https://" + podDomain + "/notifications"))
snackbarNewNotification.show(); snackbarNewNotification.show();
} else {
item.setIcon(R.drawable.ic_notifications_white_48px);
}
} }
} }
// TODO: Move from Javascript interface // TODO: Move from Javascript interface
@Override @Override
public void onUnreadMessageCountChanged(int unreadMessageCount) { public void onUnreadMessageCountChanged(int unreadMessageCount) {
MenuItem item = menu.findItem(R.id.action_conversations); // Count saved in PodUserProfile
invalidateOptionsMenu();
if (item != null) { if (unreadMessageCount > 0 && !snackbarNewNotification.isShown()
if (unreadMessageCount > 0) { && !webView.getUrl().equals("https://" + podDomain + "/notifications")) {
item.setIcon(R.drawable.ic_email_colored_48px);
if (!snackbarNewNotification.isShown() && !webView.getUrl().equals("https://" + podDomain + "/conversations"))
snackbarNewNotification.show(); snackbarNewNotification.show();
} else {
item.setIcon(R.drawable.ic_mail_white_48px);
}
} }
} }

View file

@ -87,6 +87,10 @@ public class AppSettings {
return pref.getBoolean(context.getString(ressourceId), defaultValue); 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 // Setters & Getters
@ -174,6 +178,22 @@ public class AppSettings {
setStringArray(prefPod, R.string.pref_key__podprofile_followed_tags, tags); 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() { public boolean isAppendSharedViaApp() {
return getBoolean(prefApp, R.string.pref_key__append_shared_via_app, true); return getBoolean(prefApp, R.string.pref_key__append_shared_via_app, true);
} }

View file

@ -60,6 +60,8 @@ public class PodUserProfile {
name = appSettings.getName(); name = appSettings.getName();
podAspects = appSettings.getPodAspects(); podAspects = appSettings.getPodAspects();
followedTags = appSettings.getFollowedTags(); followedTags = appSettings.getFollowedTags();
notificationCount = appSettings.getNotificationCount();
unreadMessagesCount = appSettings.getUnreadMessageCount();
} }
public PodUserProfile(App app, Handler callbackHandler, WebUserProfileChangedListener listener) { public PodUserProfile(App app, Handler callbackHandler, WebUserProfileChangedListener listener) {
@ -102,11 +104,12 @@ public class PodUserProfile {
// Unread message count // Unread message count
if (json.has("notifications_count") && loadNotificationCount(json.getInt("notifications_count"))) { if (json.has("notifications_count") && loadNotificationCount(json.getInt("notifications_count"))) {
appSettings.setNotificationCount(notificationCount);
} }
// Unread message count // Unread message count
if (json.has("unread_messages_count") && loadUnreadMessagesCount(json.getInt("unread_messages_count"))) { if (json.has("unread_messages_count") && loadUnreadMessagesCount(json.getInt("unread_messages_count"))) {
appSettings.setPodAspects(podAspects); appSettings.setUnreadMessageCount(unreadMessagesCount);
} }
// Aspect // Aspect

View file

@ -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() {" + wv.loadUrl("javascript: ( function() {" +
" if (document.documentElement == null || document.documentElement.style == null) { return; }" +
" document.documentElement.style.paddingBottom = '260px';" + " document.documentElement.style.paddingBottom = '260px';" +
" document.getElementById('main').style.paddingTop = '5px';" + " document.getElementById('main').style.paddingTop = '5px';" +
" if(document.getElementById('main_nav')) {" + " if(document.getElementById('main_nav')) {" +

View file

@ -30,6 +30,8 @@
<string name="pref_key__podprofile_id" translatable="false">podUserProfile_guid</string> <string name="pref_key__podprofile_id" translatable="false">podUserProfile_guid</string>
<string name="pref_key__podprofile_aspects" translatable="false">podUserProfile_aspects</string> <string name="pref_key__podprofile_aspects" translatable="false">podUserProfile_aspects</string>
<string name="pref_key__podprofile_followed_tags" translatable="false">podUserProfile_followedTags</string> <string name="pref_key__podprofile_followed_tags" translatable="false">podUserProfile_followedTags</string>
<string name="pref_key__podprofile_unread_message_count" translatable="false">podUserProfile_unreadMessageCount</string>
<string name="pref_key__podprofile_notification_count" translatable="false">podUserProfile_NotificationCount</string>
<!-- Category Titles --> <!-- Category Titles -->