1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-11-22 04:12: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.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<Uri[]> 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,8 +531,10 @@ public class MainActivity extends AppCompatActivity
if (webView.canGoBack()) {
webView.goBack();
} else {
if (!snackbarExitApp.isShown())
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"))
if (notificationCount > 0 && !snackbarNewNotification.isShown()
&& !webView.getUrl().equals("https://" + podDomain + "/notifications")) {
snackbarNewNotification.show();
} else {
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);
// 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"))
if (unreadMessageCount > 0 && !snackbarNewNotification.isShown()
&& !webView.getUrl().equals("https://" + podDomain + "/notifications")) {
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);
}
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);
}

View file

@ -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

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() {" +
" 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')) {" +

View file

@ -30,6 +30,8 @@
<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_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 -->