-
Notifications
You must be signed in to change notification settings - Fork 604
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
search functionality added in individual collection sheet
- Loading branch information
1 parent
310c2f2
commit d17aedf
Showing
7 changed files
with
284 additions
and
5 deletions.
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
...ndroid/src/main/java/com/mifos/mifosxdroid/dialogfragments/searchdialog/SearchDialog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package com.mifos.mifosxdroid.dialogfragments.searchdialog; | ||
|
||
import android.app.Dialog; | ||
import android.content.Context; | ||
import android.text.Editable; | ||
import android.text.TextWatcher; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.AdapterView; | ||
import android.widget.ArrayAdapter; | ||
import android.widget.EditText; | ||
import android.widget.ListView; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
import com.mifos.mifosxdroid.R; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class SearchDialog extends Dialog { | ||
|
||
private List<String> mainList; | ||
private List<String> filterList; | ||
private AdapterView.OnItemClickListener clickListener; | ||
|
||
private EditText editText; | ||
private ListView listView; | ||
private ArrayAdapter<String> adapter; | ||
|
||
public SearchDialog(@NonNull Context context, List<String> items, | ||
AdapterView.OnItemClickListener clickListener) { | ||
super(context); | ||
this.clickListener = clickListener; | ||
this.mainList = items; | ||
setUp(); | ||
} | ||
|
||
private void setUp() { | ||
filterList = new ArrayList<>(); | ||
filterList.addAll(mainList); | ||
setContentView(0); | ||
|
||
adapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_list_item_1, | ||
android.R.id.text1, filterList); | ||
listView = this.findViewById(R.id.lv_items); | ||
editText = this.findViewById(R.id.et_drop_down_search); | ||
editText.addTextChangedListener(new TextWatcher() { | ||
@Override | ||
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { } | ||
@Override | ||
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { } | ||
@Override | ||
public void afterTextChanged(Editable editable) { | ||
filterList.clear(); | ||
String text = editable.toString().toLowerCase(); | ||
for (String s: mainList) { | ||
if (s.toLowerCase().contains(text)) { | ||
filterList.add(s); | ||
} | ||
} | ||
adapter.notifyDataSetChanged(); | ||
} | ||
}); | ||
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { | ||
@Override | ||
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { | ||
for (int pos = 0; pos < mainList.size(); pos++) { | ||
if (mainList.get(pos).equals(filterList.get(i))) { | ||
clickListener.onItemClick(adapterView, view, pos, l); | ||
} | ||
} | ||
dismiss(); | ||
} | ||
}); | ||
listView.setAdapter(adapter); | ||
} | ||
|
||
@Override | ||
public void setContentView(int layoutResID) { | ||
layoutResID = R.layout.search_list_dialog_layout; | ||
super.setContentView(layoutResID); | ||
} | ||
|
||
@Override | ||
@Deprecated | ||
public void setContentView(@NonNull View view) { | ||
super.setContentView(view); | ||
} | ||
|
||
@Override | ||
@Deprecated | ||
public void addContentView(@NonNull View view, @Nullable ViewGroup.LayoutParams params) { | ||
super.addContentView(view, params); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
mifosng-android/src/main/java/com/mifos/mifosxdroid/views/CustomSpinner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package com.mifos.mifosxdroid.views; | ||
|
||
import android.content.Context; | ||
import android.content.res.Resources; | ||
import android.util.AttributeSet; | ||
import android.widget.Spinner; | ||
|
||
public class CustomSpinner extends androidx.appcompat.widget.AppCompatSpinner { | ||
|
||
public interface OnSpinnerEventsListener { | ||
|
||
/** | ||
* Callback triggered when the spinner was opened. | ||
*/ | ||
void onSpinnerOpened(Spinner spinner, boolean isItemListLarge); | ||
|
||
/** | ||
* Callback triggered when the spinner was closed. | ||
*/ | ||
void onSpinnerClosed(Spinner spinner); | ||
|
||
} | ||
|
||
private OnSpinnerEventsListener mListener; | ||
private boolean mOpenInitiated = false; | ||
|
||
@Override | ||
public boolean performClick() { | ||
// register that the Spinner was opened so we have a status | ||
// indicator for when the container holding this Spinner may lose focus | ||
mOpenInitiated = true; | ||
if (mListener != null) { | ||
if (super.getAdapter().getCount() >= 10) { | ||
mListener.onSpinnerOpened(this, true); | ||
return true; | ||
} else { | ||
mListener.onSpinnerOpened(this, false); | ||
} | ||
} | ||
return super.performClick(); | ||
} | ||
|
||
@Override | ||
public void onWindowFocusChanged (boolean hasFocus) { | ||
if (hasBeenOpened() && hasFocus) { | ||
performClosedEvent(); | ||
} | ||
} | ||
|
||
/** | ||
* Register the listener which will listen for events. | ||
*/ | ||
public void setSpinnerEventsListener( | ||
OnSpinnerEventsListener onSpinnerEventsListener) { | ||
mListener = onSpinnerEventsListener; | ||
} | ||
|
||
/** | ||
* Propagate the closed Spinner event to the listener from outside if needed. | ||
*/ | ||
public void performClosedEvent() { | ||
mOpenInitiated = false; | ||
if (mListener != null) { | ||
mListener.onSpinnerClosed(this); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* A boolean flag indicating that the Spinner triggered an open event. | ||
* | ||
* @return true for opened Spinner | ||
*/ | ||
public boolean hasBeenOpened() { | ||
return mOpenInitiated; | ||
} | ||
|
||
public CustomSpinner(Context context) { | ||
super(context); | ||
} | ||
|
||
public CustomSpinner(Context context, int mode) { | ||
super(context, mode); | ||
} | ||
|
||
public CustomSpinner(Context context, AttributeSet attrs) { | ||
super(context, attrs); | ||
} | ||
|
||
public CustomSpinner(Context context, AttributeSet attrs, int defStyleAttr) { | ||
super(context, attrs, defStyleAttr); | ||
} | ||
|
||
public CustomSpinner(Context context, AttributeSet attrs, int defStyleAttr, int mode) { | ||
super(context, attrs, defStyleAttr, mode); | ||
} | ||
|
||
public CustomSpinner(Context context, AttributeSet attrs, | ||
int defStyleAttr, int mode, Resources.Theme popupTheme) { | ||
super(context, attrs, defStyleAttr, mode, popupTheme); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:shape="rectangle"> | ||
|
||
<stroke android:color="@color/primary" android:width="2dp"/> | ||
<corners android:radius="2dp"/> | ||
|
||
</shape> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
mifosng-android/src/main/res/layout/search_list_dialog_layout.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RelativeLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content"> | ||
|
||
<EditText | ||
android:id="@+id/et_drop_down_search" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:hint="Search" | ||
android:padding="8dp" | ||
android:background="@drawable/round_outline_bg" | ||
android:visibility="visible" | ||
android:layout_margin="12dp"/> | ||
|
||
<ListView | ||
android:id="@+id/lv_items" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_below="@id/et_drop_down_search" | ||
android:layout_marginStart="12dp" | ||
android:layout_marginLeft="12dp" | ||
android:layout_marginRight="12dp" | ||
android:layout_marginEnd="12dp"/> | ||
|
||
|
||
</RelativeLayout> |