55import android .content .Intent ;
66import android .graphics .Color ;
77import android .graphics .Typeface ;
8+ import android .graphics .drawable .Drawable ;
89import android .os .Build ;
910import android .os .Bundle ;
1011import android .util .Log ;
1112import android .view .LayoutInflater ;
13+ import android .view .MotionEvent ;
1214import android .view .View ;
1315import android .view .ViewGroup ;
16+ import android .view .ViewParent ;
1417import android .widget .BaseExpandableListAdapter ;
18+ import android .widget .ExpandableListView ;
19+ import android .widget .ListView ;
1520import android .widget .TextView ;
1621import android .widget .Toast ;
1722
2328import com .boruminc .borumjot .Note ;
2429import com .boruminc .borumjot .Task ;
2530import com .boruminc .borumjot .android .customviews .SerializableImage ;
31+ import com .google .android .flexbox .FlexboxLayout ;
2632
2733import java .io .Serializable ;
2834import java .util .ArrayList ;
2935import java .util .HashMap ;
3036import java .util .List ;
3137import java .util .Objects ;
32- import java .util .function .Predicate ;
3338
3439@ RequiresApi (api = Build .VERSION_CODES .N )
3540public class ExpandableJottingsListAdapter extends BaseExpandableListAdapter {
@@ -71,27 +76,6 @@ void setSharedData(ArrayList<Jotting> sharedJottings) {
7176 this .allJottingsLists .replace ("shared" , sharedJottings );
7277 }
7378
74- public ExpandableJottingsListAdapter .GroupTitleViewHolder onCreateDividerViewHolder (ViewGroup parent ) {
75- // Create a new view
76- View v = LayoutInflater .from (parent .getContext ()).inflate (R .layout .list_group , parent , false );
77- return new GroupTitleViewHolder (v , context );
78- }
79-
80- public ExpandableJottingsListAdapter .ChildViewHolder onCreateChildViewHolder (ViewGroup parent ) {
81- // Create a new view
82- View v = LayoutInflater .from (parent .getContext ()).inflate (R .layout .jotting_list_item , parent , false );
83- return new ChildViewHolder (v , context );
84- }
85-
86- /*
87- * Replace the contents of a view (invoked by the layout manager)
88- * Get element from the dataset at this position
89- * Replace the contents of the view with that element
90- */
91- public void onBindViewHolder (ExpandableListViewHolder holder , String key , int position ) {
92- holder .bindView (Objects .requireNonNull (allJottingsLists .get (key )).get (position ));
93- }
94-
9579 @ Override
9680 public int getGroupCount () {
9781 return this .jottingsListTitles .size ();
@@ -200,7 +184,6 @@ void bindView(Object data) {
200184 }
201185 }
202186
203- // DONE ChildViewHolder
204187 static class ChildViewHolder extends ExpandableListViewHolder implements View .OnLongClickListener {
205188 private TextView textView ;
206189 private SerializableImage pinIcon ;
@@ -271,6 +254,8 @@ public boolean onLongClick(View v) {
271254 // Make visible and set data to jotting options toolbar
272255 temporaryAppBar .setVisibility (View .VISIBLE );
273256
257+ indicateSelection (v , currentActivity );
258+
274259 Bundle bundle = new Bundle ();
275260 bundle .putSerializable ("data" , (Serializable ) v .getTag ());
276261 bundle .putSerializable ("view" , pinIcon );
@@ -282,5 +267,30 @@ public boolean onLongClick(View v) {
282267
283268 return true ;
284269 }
270+
271+ private void indicateSelection (View v , Activity currentActivity ) {
272+ if (v instanceof FlexboxLayout ) { // The row was long clicked
273+ highlightItem ((ViewGroup ) v , currentActivity );
274+ } else if (v .getParent () instanceof FlexboxLayout ) { // One of the children was long clicked
275+ highlightItem (v .getParent (), currentActivity );
276+ }
277+ }
278+
279+ private void highlightItem (ViewParent listItemRoot , Activity currentActivity ) {
280+ int backgroundForSelectedView = currentActivity .getResources ().getColor (R .color .cherryRasboraBackgroundSurface );
281+ Drawable defaultBackground = currentActivity .getResources ().getDrawable (
282+ R .drawable .orange_border ,
283+ currentActivity .getTheme ()
284+ );
285+
286+ ViewGroup listView = (ViewGroup ) listItemRoot .getParent ();
287+
288+ for (int i = 0 ; i < listView .getChildCount (); i ++) {
289+ if (listView .getChildAt (i ) instanceof FlexboxLayout )
290+ listView .getChildAt (i ).setBackground (defaultBackground );
291+ }
292+
293+ ((View ) listItemRoot ).setBackgroundColor (backgroundForSelectedView );
294+ }
285295 }
286296}
0 commit comments