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

Capsuled all reused snackbars

This commit is contained in:
vanitasvitae 2016-06-24 13:31:01 +02:00
parent d2cf0d8a4c
commit ab4ffebb49

View file

@ -125,6 +125,8 @@ public class MainActivity extends AppCompatActivity
private final Handler uiHandler = new Handler(); private final Handler uiHandler = new Handler();
private CustomWebViewClient webViewClient; private CustomWebViewClient webViewClient;
private Snackbar snackbarExitApp; private Snackbar snackbarExitApp;
private Snackbar snackbarNewNotification;
private Snackbar snackbarNoInternet;
/** /**
* UI Bindings * UI Bindings
@ -209,6 +211,20 @@ public class MainActivity extends AppCompatActivity
moveTaskToBack(true); moveTaskToBack(true);
} }
}); });
snackbarNewNotification = Snackbar
.make(swipeRefreshLayout, R.string.new_notifications, Snackbar.LENGTH_LONG)
.setAction(android.R.string.yes, new View.OnClickListener() {
@Override
public void onClick(View view) {
if (Helpers.isOnline(MainActivity.this)) {
webView.loadUrl("https://" + podDomain + "/notifications");
setTitle(R.string.title_notifications);
} else {
Snackbar.make(swipeRefreshLayout, R.string.no_internet, Snackbar.LENGTH_LONG).show();
}
}
});
snackbarNoInternet = Snackbar.make(swipeRefreshLayout, R.string.no_internet, Snackbar.LENGTH_LONG);
// Load app settings // Load app settings
setupNavigationSlider(); setupNavigationSlider();
@ -225,7 +241,7 @@ public class MainActivity extends AppCompatActivity
webView.loadData("", "text/html", null); webView.loadData("", "text/html", null);
webView.loadUrl(url); webView.loadUrl(url);
} else { } else {
Snackbar.make(swipeRefreshLayout, R.string.no_internet, Snackbar.LENGTH_LONG).show(); snackbarNoInternet.show();
} }
} }
} }
@ -276,7 +292,7 @@ public class MainActivity extends AppCompatActivity
if (Helpers.isOnline(MainActivity.this)) { if (Helpers.isOnline(MainActivity.this)) {
webView.reload(); webView.reload();
} else { } else {
Snackbar.make(swipeRefreshLayout, R.string.no_internet, Snackbar.LENGTH_LONG).show(); snackbarNoInternet.show();
swipeRefreshLayout.setRefreshing(false); swipeRefreshLayout.setRefreshing(false);
} }
} }
@ -523,7 +539,7 @@ public class MainActivity extends AppCompatActivity
setTitle(R.string.title_notifications); setTitle(R.string.title_notifications);
return true; return true;
} else { } else {
Snackbar.make(swipeRefreshLayout, R.string.no_internet, Snackbar.LENGTH_LONG).show(); snackbarNoInternet.show();
return false; return false;
} }
} }
@ -534,7 +550,7 @@ public class MainActivity extends AppCompatActivity
setTitle(R.string.title_conversations); setTitle(R.string.title_conversations);
return true; return true;
} else { } else {
Snackbar.make(swipeRefreshLayout, R.string.no_internet, Snackbar.LENGTH_LONG).show(); snackbarNoInternet.show();
return false; return false;
} }
} }
@ -554,7 +570,7 @@ public class MainActivity extends AppCompatActivity
webView.loadUrl("https://" + podDomain + "/status_messages/new"); webView.loadUrl("https://" + podDomain + "/status_messages/new");
setTitle(R.string.new_post); setTitle(R.string.new_post);
} else { } else {
Snackbar.make(swipeRefreshLayout, R.string.no_internet, Snackbar.LENGTH_LONG).show(); snackbarNoInternet.show();
} }
return true; return true;
} }
@ -646,7 +662,7 @@ public class MainActivity extends AppCompatActivity
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
} else { } else {
Snackbar.make(swipeRefreshLayout, R.string.no_internet, Snackbar.LENGTH_LONG).show(); snackbarNoInternet.show();
} }
return true; return true;
} }
@ -774,20 +790,8 @@ public class MainActivity extends AppCompatActivity
if (item != null) { if (item != null) {
if (notificationCount > 0) { if (notificationCount > 0) {
item.setIcon(R.drawable.ic_bell_ring_white_24dp); item.setIcon(R.drawable.ic_bell_ring_white_24dp);
Snackbar snackbar = Snackbar if(!snackbarNewNotification.isShown())
.make(swipeRefreshLayout, R.string.new_notifications, Snackbar.LENGTH_LONG) snackbarNewNotification.show();
.setAction(android.R.string.yes, new View.OnClickListener() {
@Override
public void onClick(View view) {
if (Helpers.isOnline(MainActivity.this)) {
webView.loadUrl("https://" + podDomain + "/notifications");
setTitle(R.string.title_notifications);
} else {
Snackbar.make(swipeRefreshLayout, R.string.no_internet, Snackbar.LENGTH_LONG).show();
}
}
});
snackbar.show();
} else { } else {
item.setIcon(R.drawable.ic_bell_outline_white_24dp); item.setIcon(R.drawable.ic_bell_outline_white_24dp);
} }
@ -820,20 +824,8 @@ public class MainActivity extends AppCompatActivity
if (item != null) { if (item != null) {
if (conversationCount > 0) { if (conversationCount > 0) {
item.setIcon(R.drawable.ic_message_text_white_24dp); item.setIcon(R.drawable.ic_message_text_white_24dp);
Snackbar snackbar = Snackbar if(!snackbarNewNotification.isShown())
.make(swipeRefreshLayout, R.string.new_conversations, Snackbar.LENGTH_LONG) snackbarNewNotification.show();
.setAction(android.R.string.yes, new View.OnClickListener() {
@Override
public void onClick(View view) {
if (Helpers.isOnline(MainActivity.this)) {
webView.loadUrl("https://" + podDomain + "/conversations");
setTitle(R.string.title_conversations);
} else {
Snackbar.make(swipeRefreshLayout, R.string.no_internet, Snackbar.LENGTH_LONG).show();
}
}
});
snackbar.show();
} else { } else {
item.setIcon(R.drawable.ic_message_text_outline_white_24dp); item.setIcon(R.drawable.ic_message_text_outline_white_24dp);
} }
@ -855,7 +847,7 @@ public class MainActivity extends AppCompatActivity
webView.loadUrl("https://" + podDomain + "/stream"); webView.loadUrl("https://" + podDomain + "/stream");
setTitle(R.string.title_stream); setTitle(R.string.title_stream);
} else { } else {
Snackbar.make(swipeRefreshLayout, R.string.no_internet, Snackbar.LENGTH_LONG).show(); snackbarNoInternet.show();
} }
} }
break; break;
@ -865,7 +857,7 @@ public class MainActivity extends AppCompatActivity
webView.loadUrl("https://" + podDomain + "/people/" + appSettings.getProfileId()); webView.loadUrl("https://" + podDomain + "/people/" + appSettings.getProfileId());
setTitle(R.string.title_profil); setTitle(R.string.title_profil);
} else { } else {
Snackbar.make(swipeRefreshLayout, R.string.no_internet, Snackbar.LENGTH_LONG).show(); snackbarNoInternet.show();
} }
} }
break; break;
@ -876,7 +868,7 @@ public class MainActivity extends AppCompatActivity
webView.loadUrl("https://" + podDomain + "/followed_tags"); webView.loadUrl("https://" + podDomain + "/followed_tags");
setTitle(R.string.jb_followed_tags); setTitle(R.string.jb_followed_tags);
} else { } else {
Snackbar.make(swipeRefreshLayout, R.string.no_internet, Snackbar.LENGTH_LONG).show(); snackbarNoInternet.show();
} }
} }
break; break;
@ -887,7 +879,7 @@ public class MainActivity extends AppCompatActivity
Helpers.showAspectList(webView, app); Helpers.showAspectList(webView, app);
setTitle(R.string.title_aspects); setTitle(R.string.title_aspects);
} else { } else {
Snackbar.make(swipeRefreshLayout, R.string.no_internet, Snackbar.LENGTH_LONG).show(); snackbarNoInternet.show();
} }
} }
break; break;
@ -897,7 +889,7 @@ public class MainActivity extends AppCompatActivity
webView.loadUrl("https://" + podDomain + "/activity"); webView.loadUrl("https://" + podDomain + "/activity");
setTitle(R.string.title_activities); setTitle(R.string.title_activities);
} else { } else {
Snackbar.make(swipeRefreshLayout, R.string.no_internet, Snackbar.LENGTH_LONG).show(); snackbarNoInternet.show();
} }
} }
break; break;
@ -907,7 +899,7 @@ public class MainActivity extends AppCompatActivity
webView.loadUrl("https://" + podDomain + "/liked"); webView.loadUrl("https://" + podDomain + "/liked");
setTitle(R.string.title_liked); setTitle(R.string.title_liked);
} else { } else {
Snackbar.make(swipeRefreshLayout, R.string.no_internet, Snackbar.LENGTH_LONG).show(); snackbarNoInternet.show();
} }
} }
break; break;
@ -917,7 +909,7 @@ public class MainActivity extends AppCompatActivity
webView.loadUrl("https://" + podDomain + "/commented"); webView.loadUrl("https://" + podDomain + "/commented");
setTitle(R.string.title_commented); setTitle(R.string.title_commented);
} else { } else {
Snackbar.make(swipeRefreshLayout, R.string.no_internet, Snackbar.LENGTH_LONG).show(); snackbarNoInternet.show();
} }
} }
break; break;
@ -927,7 +919,7 @@ public class MainActivity extends AppCompatActivity
webView.loadUrl("https://" + podDomain + "/mentions"); webView.loadUrl("https://" + podDomain + "/mentions");
setTitle(R.string.title_mentions); setTitle(R.string.title_mentions);
} else { } else {
Snackbar.make(swipeRefreshLayout, R.string.no_internet, Snackbar.LENGTH_LONG).show(); snackbarNoInternet.show();
} }
} }
break; break;
@ -937,7 +929,7 @@ public class MainActivity extends AppCompatActivity
webView.loadUrl("https://" + podDomain + "/public"); webView.loadUrl("https://" + podDomain + "/public");
setTitle(R.string.title_public); setTitle(R.string.title_public);
} else { } else {
Snackbar.make(swipeRefreshLayout, R.string.no_internet, Snackbar.LENGTH_LONG).show(); snackbarNoInternet.show();
} }
} }
break; break;