21
21
import android .database .MergeCursor ;
22
22
import android .graphics .Bitmap ;
23
23
import android .graphics .PorterDuff ;
24
+ import android .graphics .Rect ;
24
25
import android .graphics .drawable .Drawable ;
25
26
import android .net .Uri ;
26
27
import android .os .Build ;
32
33
import android .support .design .widget .AppBarLayout ;
33
34
import android .support .design .widget .CoordinatorLayout ;
34
35
import android .support .design .widget .FloatingActionButton ;
35
- import android .support .design .widget .Snackbar ;
36
36
import android .support .v4 .app .ActionBarDrawerToggle ;
37
37
import android .support .v4 .app .ActivityCompat ;
38
38
import android .support .v4 .app .FragmentManager ;
58
58
import android .view .View ;
59
59
import android .view .ViewPropertyAnimator ;
60
60
import android .view .WindowManager ;
61
+ import android .view .Window ;
61
62
import android .view .animation .Interpolator ;
62
63
import android .view .inputmethod .InputMethodManager ;
63
64
import android .widget .AdapterView ;
107
108
import com .zulip .android .util .SwipeRemoveLinearLayout ;
108
109
import com .zulip .android .util .UrlHelper ;
109
110
import com .zulip .android .util .ZLog ;
111
+ import com .zulip .android .viewholders .TopSnackBar ;
110
112
111
113
import org .json .JSONObject ;
112
114
@@ -167,6 +169,7 @@ public class ZulipActivity extends BaseActivity implements
167
169
private Runnable statusUpdateRunnable ;
168
170
169
171
private int mToolbarHeightInPx ;
172
+ private int statusBarHeight = 0 ;
170
173
private MessageListFragment narrowedList ;
171
174
private MessageListFragment homeList ;
172
175
private AutoCompleteTextView streamActv ;
@@ -249,6 +252,7 @@ public boolean setViewValue(View view, Cursor cursor, int i) {
249
252
private RefreshableCursorAdapter peopleAdapter ;
250
253
private LinearLayout composeStatus ;
251
254
private String tempStreamSave = null ;
255
+ private TopSnackBar topSnackBar ;
252
256
253
257
@ Override
254
258
public void removeChatBox (boolean animToRight ) {
@@ -1663,6 +1667,9 @@ public void setLayoutBehaviour(LinearLayoutManager linearLayoutManager, Recycler
1663
1667
layoutParams = (CoordinatorLayout .LayoutParams ) fab .getLayoutParams ();
1664
1668
layoutParams .setBehavior (new RemoveViewsOnScroll (linearLayoutManager , adapter ));
1665
1669
fab .setLayoutParams (layoutParams );
1670
+
1671
+ topSnackBar .setMessagesLayoutManager (linearLayoutManager );
1672
+ topSnackBar .setMessagesAdapter (adapter );
1666
1673
}
1667
1674
1668
1675
@ Override
@@ -2218,32 +2225,27 @@ public void onNewMessages(Message[] messages) {
2218
2225
showSnackbarNotification (messages ); //Show notification
2219
2226
}
2220
2227
2221
- Snackbar snackbar ;
2222
- CoordinatorLayout .LayoutParams snackBarParams ;
2223
2228
private void setupSnackBar () {
2224
2229
final CoordinatorLayout coordinatorLayout = (CoordinatorLayout ) findViewById (R .id .coordinatorLayout );
2225
- snackbar = Snackbar .make (coordinatorLayout , "" , Snackbar .LENGTH_LONG );
2226
- View v = snackbar .getView ();
2227
- snackBarParams = (CoordinatorLayout .LayoutParams ) v .getLayoutParams ();
2228
- snackBarParams .gravity = Gravity .TOP ;
2229
- v .setLayoutParams (snackBarParams );
2230
2230
TypedValue tv = new TypedValue ();
2231
2231
if (getTheme ().resolveAttribute (android .R .attr .actionBarSize , tv , true ))
2232
2232
mToolbarHeightInPx = TypedValue .complexToDimensionPixelSize (tv .data , getResources ().getDisplayMetrics ());
2233
- snackbar .setCallback (new Snackbar .Callback () {
2234
- @ Override
2235
- public void onDismissed (Snackbar snackbar , int event ) {
2236
- super .onDismissed (snackbar , event );
2237
- if (event == Snackbar .Callback .DISMISS_EVENT_TIMEOUT ) prevMessageSameCount = -1 ;
2238
- }
2239
- });
2233
+
2234
+ int resourceId = getResources ().getIdentifier ("status_bar_height" , "dimen" , "android" );
2235
+ if (resourceId > 0 ) {
2236
+ statusBarHeight = getResources ().getDimensionPixelSize (resourceId );
2237
+ }
2238
+
2239
+ topSnackBar = new TopSnackBar (this );
2240
+ coordinatorLayout .addView (topSnackBar .getLinearLayout ());
2240
2241
}
2241
2242
2242
2243
NarrowFilter narrowFilter ;
2243
2244
String prevId = null ;
2244
2245
int prevMessageSameCount = -1 ;
2245
2246
private void showSnackbarNotification (Message [] messages ) {
2246
2247
MutedTopics mutedTopics = MutedTopics .get ();
2248
+ String notificationMessage ;
2247
2249
int nonMutedMessagesCount = 0 ;
2248
2250
Message tempMessage = null ; //Stores a temporary message which is non-muted, later used for retrieving Stream/Topic
2249
2251
for (Message message : messages ) {
@@ -2266,38 +2268,35 @@ private void showSnackbarNotification(Message[] messages) {
2266
2268
}
2267
2269
if (nonMutedMessagesCount == 0 ) return ;
2268
2270
if (prevId == null && messages .length > 1 ) {
2269
- snackbar . setText ( getResources ().getQuantityString (R .plurals .new_message_mul_sender , nonMutedMessagesCount , nonMutedMessagesCount ) );
2271
+ notificationMessage = getResources ().getQuantityString (R .plurals .new_message_mul_sender , nonMutedMessagesCount , nonMutedMessagesCount );
2270
2272
narrowFilter = null ;
2271
2273
if (narrowedList != null ) {
2272
2274
narrowedList = null ;
2273
2275
getSupportFragmentManager ().popBackStack (NARROW ,
2274
2276
FragmentManager .POP_BACK_STACK_INCLUSIVE );
2275
2277
}
2276
- snackbar .setAction (R .string .SHOW , new View .OnClickListener () {
2278
+ topSnackBar .setAction (R .string .SHOW , new View .OnClickListener () {
2277
2279
@ Override
2278
2280
public void onClick (View view ) {
2281
+ topSnackBar .dismiss ();
2279
2282
homeList .showLatestMessages ();
2280
2283
}
2281
2284
});
2282
2285
} else {
2283
2286
if (messages .length == 1 ) tempMessage = messages [0 ];
2284
2287
String name = (tempMessage .getType () == MessageType .PRIVATE_MESSAGE ) ? getString (R .string .notify_private , tempMessage .getSenderFullName ()) : getString (R .string .notify_stream , tempMessage .getStream ().getName () , tempMessage .getSubject ());
2285
2288
if (prevMessageSameCount > 0 ) name += " (" + prevMessageSameCount + ")" ;
2286
- snackbar . setText ( getResources ().getQuantityString (R .plurals .new_message , nonMutedMessagesCount , nonMutedMessagesCount , name ) );
2289
+ notificationMessage = getResources ().getQuantityString (R .plurals .new_message , nonMutedMessagesCount , nonMutedMessagesCount , name );
2287
2290
narrowFilter = (tempMessage .getType () == MessageType .PRIVATE_MESSAGE ) ? new NarrowFilterPM (Arrays .asList (tempMessage .getRecipients (app ))) : new NarrowFilterStream (tempMessage .getStream (), tempMessage .getSubject ());
2288
- snackbar .setAction (R .string .SHOW , new View .OnClickListener () {
2291
+ topSnackBar .setAction (R .string .SHOW , new View .OnClickListener () {
2289
2292
@ Override
2290
2293
public void onClick (View view ) {
2294
+ topSnackBar .dismiss ();
2291
2295
doNarrow (narrowFilter );
2292
2296
}
2293
2297
});
2294
2298
}
2295
- if (appBarLayout .getVisibility () == View .GONE ) {
2296
- snackBarParams .setMargins (0 , 0 , 0 , 0 );
2297
- } else {
2298
- snackBarParams .setMargins (0 , mToolbarHeightInPx , 0 , 0 );
2299
- }
2300
- snackbar .show ();
2299
+ topSnackBar .show ((appBarLayout .getVisibility () == View .GONE ) ? statusBarHeight : statusBarHeight + mToolbarHeightInPx , notificationMessage , TopSnackBar .LENGTH_LONG );
2301
2300
}
2302
2301
2303
2302
// Intent Extra constants
0 commit comments