4242import android .view .LayoutInflater ;
4343import android .view .View ;
4444import android .view .ViewGroup ;
45+ import android .view .WindowManager ;
4546import android .widget .EditText ;
4647import android .widget .ImageView ;
4748import android .widget .TextView ;
4849import androidx .annotation .NonNull ;
4950import androidx .annotation .Nullable ;
5051import androidx .appcompat .app .AlertDialog ;
52+ import androidx .core .view .ViewCompat ;
53+ import androidx .core .view .WindowInsetsCompat ;
5154import androidx .recyclerview .widget .DefaultItemAnimator ;
5255import androidx .recyclerview .widget .LinearLayoutManager ;
5356import androidx .recyclerview .widget .RecyclerView ;
@@ -140,6 +143,8 @@ public final class GalleryCommentsScene extends ToolbarScene
140143 private boolean mShowAllComments = false ;
141144 private boolean mRefreshingComments = false ;
142145
146+ private int mOriginalSoftInputMode ;
147+
143148 @ Override
144149 public void onCreate (@ Nullable Bundle savedInstanceState ) {
145150 super .onCreate (savedInstanceState );
@@ -193,9 +198,9 @@ public void onSaveInstanceState(@NonNull Bundle outState) {
193198 * @param inflater
194199 * @param container
195200 * @param savedInstanceState
196- * @return
201+ * @return View
197202 */
198- @ Nullable
203+ @ NonNull
199204 @ Override
200205 public View onCreateView3 (LayoutInflater inflater ,
201206 @ Nullable ViewGroup container , @ Nullable Bundle savedInstanceState ) {
@@ -214,6 +219,7 @@ public View onCreateView3(LayoutInflater inflater,
214219 int paddingBottomFab = resources .getDimensionPixelOffset (R .dimen .gallery_padding_bottom_fab );
215220
216221 Drawable drawable = DrawableManager .getVectorDrawable (context , R .drawable .big_sad_pandroid );
222+ assert drawable != null ;
217223 drawable .setBounds (0 , 0 , drawable .getIntrinsicWidth (), drawable .getIntrinsicHeight ());
218224 tip .setCompoundDrawables (null , drawable , null , null );
219225
@@ -246,6 +252,8 @@ public View onCreateView3(LayoutInflater inflater,
246252 addAboveSnackView (mEditPanel );
247253 addAboveSnackView (mFabLayout );
248254
255+ setupEditPanelImeInsets ();
256+
249257 mViewTransition = new ViewTransition (mRecyclerView , tip );
250258
251259 updateView (false );
@@ -262,6 +270,7 @@ public void onDestroyView() {
262270 mRecyclerView = null ;
263271 }
264272 if (null != mEditPanel ) {
273+ ViewCompat .setOnApplyWindowInsetsListener (mEditPanel , null );
265274 removeAboveSnackView (mEditPanel );
266275 mEditPanel = null ;
267276 }
@@ -284,6 +293,43 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
284293 setNavigationIcon (R .drawable .v_arrow_left_dark_x24 );
285294 }
286295
296+ private void setupEditPanelImeInsets () {
297+ if (mEditPanel == null ) {
298+ return ;
299+ }
300+ ViewCompat .setOnApplyWindowInsetsListener (mEditPanel , (v , insets ) -> {
301+ int imeBottom = insets .getInsets (WindowInsetsCompat .Type .ime ()).bottom ;
302+ ViewGroup .MarginLayoutParams lp = (ViewGroup .MarginLayoutParams ) v .getLayoutParams ();
303+ if (lp .bottomMargin != imeBottom ) {
304+ lp .bottomMargin = imeBottom ;
305+ v .setLayoutParams (lp );
306+ }
307+ return insets ;
308+ });
309+ ViewCompat .requestApplyInsets (mEditPanel );
310+ }
311+
312+ @ Override
313+ public void onResume () {
314+ super .onResume ();
315+ MainActivity activity = getActivity2 ();
316+ if (activity != null ) {
317+ mOriginalSoftInputMode = activity .getWindow ().getAttributes ().softInputMode ;
318+ activity .getWindow ().setSoftInputMode (
319+ WindowManager .LayoutParams .SOFT_INPUT_STATE_HIDDEN
320+ | WindowManager .LayoutParams .SOFT_INPUT_ADJUST_RESIZE );
321+ }
322+ }
323+
324+ @ Override
325+ public void onPause () {
326+ MainActivity activity = getActivity2 ();
327+ if (activity != null ) {
328+ activity .getWindow ().setSoftInputMode (mOriginalSoftInputMode );
329+ }
330+ super .onPause ();
331+ }
332+
287333 @ Override
288334 public void onNavigationClick (View view ) {
289335 onBackPressed ();
@@ -307,7 +353,7 @@ private void voteComment(long id, int vote) {
307353
308354
309355
310- private class InfoHolder extends RecyclerView .ViewHolder {
356+ private static class InfoHolder extends RecyclerView .ViewHolder {
311357
312358 private final TextView key ;
313359 private final TextView value ;
@@ -343,13 +389,14 @@ public void showVoteStatusDialog(Context context, String voteStatus) {
343389 final LayoutInflater inflater = LayoutInflater .from (context );
344390 EasyRecyclerView rv = (EasyRecyclerView ) inflater .inflate (R .layout .dialog_recycler_view , null );
345391 rv .setAdapter (new RecyclerView .Adapter <InfoHolder >() {
392+ @ NonNull
346393 @ Override
347- public InfoHolder onCreateViewHolder (ViewGroup parent , int viewType ) {
394+ public InfoHolder onCreateViewHolder (@ NonNull ViewGroup parent , int viewType ) {
348395 return new InfoHolder (inflater .inflate (R .layout .item_drawer_favorites , parent , false ));
349396 }
350397
351398 @ Override
352- public void onBindViewHolder (InfoHolder holder , int position ) {
399+ public void onBindViewHolder (@ NonNull InfoHolder holder , int position ) {
353400 holder .key .setText (userArray [position ]);
354401 holder .value .setText (voteArray [position ]);
355402 }
@@ -403,7 +450,8 @@ private void showCommentDialog(int position) {
403450 }
404451
405452 new AlertDialog .Builder (context )
406- .setItems (menu .toArray (new String [menu .size ()]), new DialogInterface .OnClickListener () {
453+ .setItems (menu .toArray (new String [0 ]), new DialogInterface .OnClickListener () {
454+ @ SuppressLint ({"NonConstantResourceId" , "NotifyDataSetChanged" })
407455 @ Override
408456 public void onClick (DialogInterface dialog , int which ) {
409457 if (which < 0 || which >= menuId .size ()) {
@@ -434,6 +482,7 @@ public void onClick(DialogInterface dialog, int which) {
434482 case R .id .join_blacklist :
435483 EhDB .insertBlackList (BlackListUtils .parseBlacklist (comment ));
436484 mCommentList .DeleteComment (position );
485+ assert mAdapter != null ;
437486 mAdapter .notifyDataSetChanged ();
438487 updateView (true );
439488 break ;
@@ -450,8 +499,7 @@ public boolean onItemClick(EasyRecyclerView parent, View view, int position, lon
450499 }
451500
452501 RecyclerView .ViewHolder holder = parent .getChildViewHolder (view );
453- if (holder instanceof ActualCommentHolder ) {
454- ActualCommentHolder commentHolder = (ActualCommentHolder ) holder ;
502+ if (holder instanceof ActualCommentHolder commentHolder ) {
455503 ClickableSpan span = commentHolder .comment .getCurrentSpan ();
456504 commentHolder .comment .clearCurrentSpan ();
457505
0 commit comments