|
|
@@ -3,22 +3,27 @@ package com.usai.commoneditorlib;
|
|
|
import android.app.ProgressDialog;
|
|
|
import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
+import android.graphics.Color;
|
|
|
import android.os.Bundle;
|
|
|
import android.text.Editable;
|
|
|
import android.text.TextUtils;
|
|
|
import android.text.TextWatcher;
|
|
|
+import android.view.Gravity;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
|
+import android.widget.AbsListView;
|
|
|
import android.widget.AdapterView;
|
|
|
import android.widget.BaseAdapter;
|
|
|
import android.widget.EditText;
|
|
|
import android.widget.ImageView;
|
|
|
import android.widget.ListView;
|
|
|
+import android.widget.ProgressBar;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
import androidx.appcompat.app.AlertDialog;
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
+import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
|
|
|
|
|
import com.usai.redant.rautils.application.RedantApplication;
|
|
|
import com.usai.redant.rautils.utils.Network;
|
|
|
@@ -26,6 +31,8 @@ import com.usai.redant.rautils.utils.RAUtil;
|
|
|
|
|
|
import org.json.JSONException;
|
|
|
import org.json.JSONObject;
|
|
|
+
|
|
|
+
|
|
|
import org.w3c.dom.Text;
|
|
|
|
|
|
import java.io.Serializable;
|
|
|
@@ -52,11 +59,71 @@ public class EnumSlectOnlineActivity extends AppCompatActivity {
|
|
|
// Bundle params;
|
|
|
// String url;
|
|
|
int offset=0;
|
|
|
- int limit=0;
|
|
|
+ int limit=2;
|
|
|
+
|
|
|
+ private ScrollListener mScrollListener;
|
|
|
+ boolean isLoading=false;
|
|
|
+ boolean hasmore=false;
|
|
|
+ private SwipeRefreshLayout mRefreshLayout;
|
|
|
+ private ProgressBar mProgressBar;
|
|
|
+ private TextView mListFooterView;
|
|
|
+
|
|
|
+ private void setupListFooterView() {
|
|
|
+ mListFooterView = new TextView(mCtx);
|
|
|
+ mListFooterView.setBackgroundColor(Color.WHITE);
|
|
|
+ mListFooterView.setGravity(Gravity.CENTER);
|
|
|
+ mListFooterView.setText("loading more...");
|
|
|
+ mListFooterView.setTextSize(RAUtil.sp2px(mCtx,8));
|
|
|
+ mListFooterView.setVisibility(View.INVISIBLE);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setupRefreshLayout() {
|
|
|
+
|
|
|
+ mRefreshLayout = findViewById(R.id.enum_refresh_layout);
|
|
|
+ mRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
|
|
+ @Override
|
|
|
+ public void onRefresh() {
|
|
|
+ hasmore=false;
|
|
|
+ offset=0;
|
|
|
+ LoadData(LoadDataOptionReload);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private class ScrollListener implements AbsListView.OnScrollListener {
|
|
|
+
|
|
|
+ private int last_index, total_index;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onScrollStateChanged(AbsListView view, int scrollState) {
|
|
|
+// if(isNoMore&& (scrollState == SCROLL_STATE_IDLE))
|
|
|
+// {
|
|
|
+// showMessage("No more data.");
|
|
|
+// // no more 只提示一次
|
|
|
+//// isNoMore = false;
|
|
|
+//// return;
|
|
|
+// }
|
|
|
|
|
|
+ if (last_index == total_index && (scrollState == SCROLL_STATE_IDLE)) {
|
|
|
+ if (!isLoading) {
|
|
|
+
|
|
|
+ mListFooterView.setVisibility(View.VISIBLE);
|
|
|
+ EnumSlectOnlineActivity.this.LoadData(LoadDataOptionLoadMore);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
|
|
|
+ last_index = firstVisibleItem + visibleItemCount;
|
|
|
+ total_index = totalItemCount;
|
|
|
+ }
|
|
|
+ }
|
|
|
void LoadData(int option)
|
|
|
{
|
|
|
|
|
|
+
|
|
|
RedantApplication application= (RedantApplication) getApplication();
|
|
|
|
|
|
boolean fakedata = application.useFakeData();
|
|
|
@@ -68,7 +135,7 @@ public class EnumSlectOnlineActivity extends AppCompatActivity {
|
|
|
if(option == LoadDataOptionReload)
|
|
|
{
|
|
|
offset=0;
|
|
|
- limit = 0;
|
|
|
+// limit = 0;
|
|
|
}
|
|
|
|
|
|
if(params ==null)
|
|
|
@@ -81,7 +148,9 @@ public class EnumSlectOnlineActivity extends AppCompatActivity {
|
|
|
|
|
|
}
|
|
|
|
|
|
- final ProgressDialog pd = RAUtil.waiting_alert(mCtx,"loading","please wait");
|
|
|
+// final ProgressDialog pd = RAUtil.waiting_alert(mCtx,"loading","please wait");
|
|
|
+
|
|
|
+ showProgressBar();
|
|
|
Bundle finalParams = params;
|
|
|
new Thread(new Runnable() {
|
|
|
@Override
|
|
|
@@ -106,9 +175,20 @@ public class EnumSlectOnlineActivity extends AppCompatActivity {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
|
|
|
+ dismissProgressBar();
|
|
|
|
|
|
+ if(option == LoadDataOptionReload)
|
|
|
+ {
|
|
|
+
|
|
|
+ if (mRefreshLayout.isRefreshing()) {
|
|
|
+ mRefreshLayout.setRefreshing(false);
|
|
|
+ }
|
|
|
+ mListFooterView.setVisibility(View.INVISIBLE);
|
|
|
|
|
|
- pd.dismiss();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+// pd.dismiss();
|
|
|
try
|
|
|
{
|
|
|
|
|
|
@@ -120,6 +200,16 @@ public class EnumSlectOnlineActivity extends AppCompatActivity {
|
|
|
}
|
|
|
|
|
|
int count = finalResult_json.optInt("count");
|
|
|
+ if(count>=limit)
|
|
|
+ hasmore=true;
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ mListFooterView.setText("No more data");
|
|
|
+ mListFooterView.setVisibility(View.VISIBLE);
|
|
|
+ hasmore = false;
|
|
|
+
|
|
|
+ }
|
|
|
int ccount = mCadedate.optInt("count");
|
|
|
for (int ipr = 0; ipr < count; ipr++) {
|
|
|
|
|
|
@@ -252,7 +342,8 @@ public class EnumSlectOnlineActivity extends AppCompatActivity {
|
|
|
}
|
|
|
|
|
|
mKeywords = s.toString();
|
|
|
- adapter.notifyDataSetChanged();
|
|
|
+ LoadData(LoadDataOptionInitial);
|
|
|
+ //adapter.notifyDataSetChanged();
|
|
|
|
|
|
}
|
|
|
}
|
|
|
@@ -268,7 +359,7 @@ public class EnumSlectOnlineActivity extends AppCompatActivity {
|
|
|
private boolean mDirty;
|
|
|
|
|
|
private String mKeywords;
|
|
|
- private int filter_count;
|
|
|
+// private int filter_count;
|
|
|
|
|
|
private ListView enum_list_view;
|
|
|
private EnumAdapter adapter;
|
|
|
@@ -276,12 +367,24 @@ public class EnumSlectOnlineActivity extends AppCompatActivity {
|
|
|
|
|
|
private EditText searchBar;
|
|
|
|
|
|
+ // region ProgressBar
|
|
|
|
|
|
+ public void showProgressBar() {
|
|
|
+ mProgressBar.setVisibility(View.VISIBLE);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void dismissProgressBar() {
|
|
|
+ mProgressBar.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+
|
|
|
+ // endregion
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
|
- setContentView(R.layout.activity_enum_slect);
|
|
|
+ setContentView(R.layout.activity_enum_online_slect);
|
|
|
+ setupRefreshLayout();
|
|
|
|
|
|
+ mProgressBar = findViewById(R.id.enum_progress_bar);
|
|
|
init();
|
|
|
|
|
|
setTitle(mTitle);
|
|
|
@@ -291,12 +394,24 @@ public class EnumSlectOnlineActivity extends AppCompatActivity {
|
|
|
|
|
|
enum_list_view = (ListView)findViewById(R.id.enum_list_view);
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
adapter = new EnumAdapter(mCtx);
|
|
|
enum_list_view.setAdapter(adapter);
|
|
|
|
|
|
enum_list_view.setOnItemClickListener(new CellClickListener(mCtx));
|
|
|
|
|
|
|
|
|
+ mScrollListener = new ScrollListener();
|
|
|
+ enum_list_view.setOnScrollListener(mScrollListener);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ setupListFooterView();
|
|
|
+ AbsListView.LayoutParams footerLayoutParams = new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT);
|
|
|
+ mListFooterView.setLayoutParams(footerLayoutParams);
|
|
|
+ enum_list_view.addFooterView(mListFooterView);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -353,7 +468,7 @@ public class EnumSlectOnlineActivity extends AppCompatActivity {
|
|
|
|
|
|
boolean is_worked = false;
|
|
|
|
|
|
- if (mKeywords == null || mKeywords.isEmpty()) {
|
|
|
+// if (mKeywords == null || mKeywords.isEmpty()) {
|
|
|
|
|
|
for (int i = 0; i < mCadedate.optInt("count"); i++) {
|
|
|
JSONObject val_json = mCadedate.optJSONObject("val_" + i);
|
|
|
@@ -375,58 +490,58 @@ public class EnumSlectOnlineActivity extends AppCompatActivity {
|
|
|
|
|
|
} // for
|
|
|
|
|
|
- } // keywords null
|
|
|
- else {
|
|
|
-
|
|
|
-
|
|
|
- JSONObject val_json = null;
|
|
|
- int count = 0;
|
|
|
- boolean getIt = false;
|
|
|
- for (int cc = 0; cc < mCadedate.optInt("count"); cc++) {
|
|
|
-
|
|
|
- JSONObject search_json = mCadedate.optJSONObject("val_" + cc);
|
|
|
- String value = search_json.optString("value");
|
|
|
- boolean contain = value.toUpperCase().contains(mKeywords.toUpperCase());
|
|
|
- if (contain && count < filter_count) {
|
|
|
- count++;
|
|
|
- }
|
|
|
-
|
|
|
- val_json = search_json;
|
|
|
- if (!getIt && count - 1 == position) {
|
|
|
- getIt = true;
|
|
|
- //==========
|
|
|
- int select = val_json.optInt("check");
|
|
|
- if (select != 0) {
|
|
|
- val_json.put("check","0");
|
|
|
- } else {
|
|
|
- val_json.put("check","1");
|
|
|
- }
|
|
|
- is_worked = select == 0;
|
|
|
-
|
|
|
- } else {
|
|
|
- val_json.put("check","0");
|
|
|
- }
|
|
|
-
|
|
|
- mCadedate.put("val_" + cc,val_json);
|
|
|
-
|
|
|
-
|
|
|
- } // for cc
|
|
|
-
|
|
|
-// for (int sc = 0; sc < mCadedate.optInt("count"); sc++) {
|
|
|
+// } // keywords null
|
|
|
+// else {
|
|
|
+//
|
|
|
//
|
|
|
-// JSONObject sc_json = mCadedate.optJSONObject("val_" + sc);
|
|
|
+// JSONObject val_json = null;
|
|
|
+// int count = 0;
|
|
|
+// boolean getIt = false;
|
|
|
+// for (int cc = 0; cc < mCadedate.optInt("count"); cc++) {
|
|
|
//
|
|
|
-// if (sc_json.optString("value").equals(val_json.optString("value"))) {
|
|
|
-// sc_json.put("check","1");
|
|
|
-// } else {
|
|
|
-// sc_json.put("check","0");
|
|
|
+// JSONObject search_json = mCadedate.optJSONObject("val_" + cc);
|
|
|
+// String value = search_json.optString("value");
|
|
|
+// boolean contain = value.toUpperCase().contains(mKeywords.toUpperCase());
|
|
|
+// if (contain && count < filter_count) {
|
|
|
+// count++;
|
|
|
// }
|
|
|
-// mCadedate.put("val_" + sc,sc_json);
|
|
|
//
|
|
|
-// } // for sc
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
+// val_json = search_json;
|
|
|
+// if (!getIt && count - 1 == position) {
|
|
|
+// getIt = true;
|
|
|
+// //==========
|
|
|
+// int select = val_json.optInt("check");
|
|
|
+// if (select != 0) {
|
|
|
+// val_json.put("check","0");
|
|
|
+// } else {
|
|
|
+// val_json.put("check","1");
|
|
|
+// }
|
|
|
+// is_worked = select == 0;
|
|
|
+//
|
|
|
+// } else {
|
|
|
+// val_json.put("check","0");
|
|
|
+// }
|
|
|
+//
|
|
|
+// mCadedate.put("val_" + cc,val_json);
|
|
|
+//
|
|
|
+//
|
|
|
+// } // for cc
|
|
|
+//
|
|
|
+//// for (int sc = 0; sc < mCadedate.optInt("count"); sc++) {
|
|
|
+////
|
|
|
+//// JSONObject sc_json = mCadedate.optJSONObject("val_" + sc);
|
|
|
+////
|
|
|
+//// if (sc_json.optString("value").equals(val_json.optString("value"))) {
|
|
|
+//// sc_json.put("check","1");
|
|
|
+//// } else {
|
|
|
+//// sc_json.put("check","0");
|
|
|
+//// }
|
|
|
+//// mCadedate.put("val_" + sc,sc_json);
|
|
|
+////
|
|
|
+//// } // for sc
|
|
|
+//
|
|
|
+//
|
|
|
+// }
|
|
|
|
|
|
if (is_worked) {
|
|
|
if (mAuto_close) {
|
|
|
@@ -444,28 +559,29 @@ public class EnumSlectOnlineActivity extends AppCompatActivity {
|
|
|
|
|
|
int index = position;
|
|
|
JSONObject val_json = null;
|
|
|
- if (mKeywords == null || mKeywords.isEmpty()) {
|
|
|
+// if (mKeywords == null || mKeywords.isEmpty()) {
|
|
|
val_json = mCadedate.optJSONObject("val_" + position);
|
|
|
- } else {
|
|
|
- int count = 0;
|
|
|
- for (int i = 0; i < mCadedate.optInt("count"); i++) {
|
|
|
- if (count >= filter_count) {
|
|
|
- break;
|
|
|
- }
|
|
|
- JSONObject search_json = mCadedate.optJSONObject("val_" + i);
|
|
|
- String value = search_json.optString("value");
|
|
|
- boolean contain = value.toUpperCase().contains(mKeywords.toUpperCase());
|
|
|
- if (contain) {
|
|
|
- count++;
|
|
|
- }
|
|
|
-
|
|
|
- if (count - 1 == position) {
|
|
|
- val_json = search_json;
|
|
|
- index = i;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+// }
|
|
|
+// else {
|
|
|
+// int count = 0;
|
|
|
+// for (int i = 0; i < mCadedate.optInt("count"); i++) {
|
|
|
+// if (count >= filter_count) {
|
|
|
+// break;
|
|
|
+// }
|
|
|
+// JSONObject search_json = mCadedate.optJSONObject("val_" + i);
|
|
|
+// String value = search_json.optString("value");
|
|
|
+// boolean contain = value.toUpperCase().contains(mKeywords.toUpperCase());
|
|
|
+// if (contain) {
|
|
|
+// count++;
|
|
|
+// }
|
|
|
+//
|
|
|
+// if (count - 1 == position) {
|
|
|
+// val_json = search_json;
|
|
|
+// index = i;
|
|
|
+// break;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
|
|
|
int check = val_json.optInt("check");
|
|
|
if (check == 1) {
|
|
|
@@ -540,51 +656,52 @@ public class EnumSlectOnlineActivity extends AppCompatActivity {
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
- if (mKeywords == null || mKeywords.isEmpty()) {
|
|
|
- filter_count = 0;
|
|
|
+// if (mKeywords == null || mKeywords.isEmpty()) {
|
|
|
+// filter_count = 0;
|
|
|
return mCadedate.optInt("count");
|
|
|
- }
|
|
|
+// }
|
|
|
|
|
|
- int count = 0;
|
|
|
- for (int i = 0; i < mCadedate.optInt("count"); i++) {
|
|
|
- JSONObject val_json = mCadedate.optJSONObject("val_" + i);
|
|
|
- String value = val_json.optString("value");
|
|
|
- boolean contain = value.toUpperCase().contains(mKeywords.toUpperCase());
|
|
|
- if (contain) {
|
|
|
- count++;
|
|
|
- }
|
|
|
- }
|
|
|
- filter_count = count;
|
|
|
- return count;
|
|
|
+// int count = 0;
|
|
|
+// for (int i = 0; i < mCadedate.optInt("count"); i++) {
|
|
|
+// JSONObject val_json = mCadedate.optJSONObject("val_" + i);
|
|
|
+// String value = val_json.optString("value");
|
|
|
+// boolean contain = value.toUpperCase().contains(mKeywords.toUpperCase());
|
|
|
+// if (contain) {
|
|
|
+// count++;
|
|
|
+// }
|
|
|
+// }
|
|
|
+//// filter_count = count;
|
|
|
+// return count;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Object getItem(int position) {
|
|
|
JSONObject val_json = null;
|
|
|
- if (mKeywords == null || mKeywords.isEmpty()) {
|
|
|
+// if (mKeywords == null || mKeywords.isEmpty()) {
|
|
|
val_json = mCadedate.optJSONObject("val_" + position);
|
|
|
- } else {
|
|
|
- int count = 0;
|
|
|
- for (int i = 0; i < mCadedate.optInt("count"); i++) {
|
|
|
- if (count >= filter_count) {
|
|
|
- break;
|
|
|
- }
|
|
|
- JSONObject search_json = mCadedate.optJSONObject("val_" + i);
|
|
|
- String value = search_json.optString("value");
|
|
|
- boolean contain = value.toUpperCase().contains(mKeywords.toUpperCase());
|
|
|
- if (contain) {
|
|
|
- count++;
|
|
|
- } else {
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- if (count - 1 == position) {
|
|
|
- val_json = search_json;
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
+// }
|
|
|
+// else {
|
|
|
+// int count = 0;
|
|
|
+// for (int i = 0; i < mCadedate.optInt("count"); i++) {
|
|
|
+// if (count >= filter_count) {
|
|
|
+// break;
|
|
|
+// }
|
|
|
+// JSONObject search_json = mCadedate.optJSONObject("val_" + i);
|
|
|
+// String value = search_json.optString("value");
|
|
|
+// boolean contain = value.toUpperCase().contains(mKeywords.toUpperCase());
|
|
|
+// if (contain) {
|
|
|
+// count++;
|
|
|
+// } else {
|
|
|
+// continue;
|
|
|
+// }
|
|
|
+//
|
|
|
+// if (count - 1 == position) {
|
|
|
+// val_json = search_json;
|
|
|
+// break;
|
|
|
+// }
|
|
|
+//
|
|
|
+// }
|
|
|
+// }
|
|
|
return val_json;
|
|
|
}
|
|
|
|