|
|
@@ -38,13 +38,15 @@ import org.w3c.dom.Text;
|
|
|
import java.io.Serializable;
|
|
|
|
|
|
import static com.usai.redant.rautils.utils.RAUtil.getJsonFromAsset;
|
|
|
+import static java.lang.Thread.sleep;
|
|
|
|
|
|
-public class EnumSlectOnlineActivity extends AppCompatActivity {
|
|
|
+public class EnumSlectOnlineActivity extends AppCompatActivity
|
|
|
+{
|
|
|
|
|
|
static String MAX_SELECT = "max_select";
|
|
|
static String GROUP_POSITION = "group";
|
|
|
static String CHILD_POSITION = "child";
|
|
|
-// static String CADEDATE = "cadedate";
|
|
|
+ // static String CADEDATE = "cadedate";
|
|
|
static String SINGLE_SELECT = "single_select";
|
|
|
static String TITLE = "title";
|
|
|
static String AUTO_CLOSE = "auto_close";
|
|
|
@@ -56,47 +58,53 @@ public class EnumSlectOnlineActivity extends AppCompatActivity {
|
|
|
private final int LoadDataOptionLoadMore = 2;
|
|
|
|
|
|
|
|
|
-// Bundle params;
|
|
|
+ // Bundle params;
|
|
|
// String url;
|
|
|
- int offset=0;
|
|
|
- int limit=2;
|
|
|
+ int offset = 0;
|
|
|
+ int limit = 20;
|
|
|
|
|
|
private ScrollListener mScrollListener;
|
|
|
- boolean isLoading=false;
|
|
|
- boolean hasmore=false;
|
|
|
+ boolean isLoading = false;
|
|
|
+ boolean hasmore = false;
|
|
|
private SwipeRefreshLayout mRefreshLayout;
|
|
|
private ProgressBar mProgressBar;
|
|
|
private TextView mListFooterView;
|
|
|
|
|
|
- private void setupListFooterView() {
|
|
|
+ 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.setTextSize(RAUtil.sp2px(mCtx, 8));
|
|
|
mListFooterView.setVisibility(View.INVISIBLE);
|
|
|
}
|
|
|
|
|
|
- private void setupRefreshLayout() {
|
|
|
+ private void setupRefreshLayout()
|
|
|
+ {
|
|
|
|
|
|
mRefreshLayout = findViewById(R.id.enum_refresh_layout);
|
|
|
- mRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
|
|
+ mRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener()
|
|
|
+ {
|
|
|
@Override
|
|
|
- public void onRefresh() {
|
|
|
- hasmore=false;
|
|
|
- offset=0;
|
|
|
+ public void onRefresh()
|
|
|
+ {
|
|
|
+ hasmore = false;
|
|
|
+ offset = 0;
|
|
|
LoadData(LoadDataOptionReload);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
|
|
|
- private class ScrollListener implements AbsListView.OnScrollListener {
|
|
|
+ private class ScrollListener implements AbsListView.OnScrollListener
|
|
|
+ {
|
|
|
|
|
|
private int last_index, total_index;
|
|
|
|
|
|
@Override
|
|
|
- public void onScrollStateChanged(AbsListView view, int scrollState) {
|
|
|
+ public void onScrollStateChanged(AbsListView view, int scrollState)
|
|
|
+ {
|
|
|
// if(isNoMore&& (scrollState == SCROLL_STATE_IDLE))
|
|
|
// {
|
|
|
// showMessage("No more data.");
|
|
|
@@ -105,8 +113,10 @@ public class EnumSlectOnlineActivity extends AppCompatActivity {
|
|
|
//// return;
|
|
|
// }
|
|
|
|
|
|
- if (last_index == total_index && (scrollState == SCROLL_STATE_IDLE)) {
|
|
|
- if (!isLoading) {
|
|
|
+ if (last_index == total_index && (scrollState == SCROLL_STATE_IDLE))
|
|
|
+ {
|
|
|
+ if (!isLoading)
|
|
|
+ {
|
|
|
|
|
|
mListFooterView.setVisibility(View.VISIBLE);
|
|
|
EnumSlectOnlineActivity.this.LoadData(LoadDataOptionLoadMore);
|
|
|
@@ -115,16 +125,18 @@ public class EnumSlectOnlineActivity extends AppCompatActivity {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
|
|
|
+ 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();
|
|
|
+ RedantApplication application = (RedantApplication) getApplication();
|
|
|
|
|
|
boolean fakedata = application.useFakeData();
|
|
|
|
|
|
@@ -132,19 +144,21 @@ public class EnumSlectOnlineActivity extends AppCompatActivity {
|
|
|
Bundle params = intent.getBundleExtra(PARAMETERS);
|
|
|
|
|
|
String url = intent.getStringExtra(URL);
|
|
|
- if(option == LoadDataOptionReload)
|
|
|
+ if (option == LoadDataOptionReload)
|
|
|
{
|
|
|
- offset=0;
|
|
|
+ offset = 0;
|
|
|
// limit = 0;
|
|
|
}
|
|
|
|
|
|
- if(params ==null)
|
|
|
+ if (params == null)
|
|
|
+ {
|
|
|
params = new Bundle();
|
|
|
- params.putInt("offset",offset);
|
|
|
- params.putInt("limit",limit);
|
|
|
- if(!TextUtils.isEmpty(mKeywords))
|
|
|
+ }
|
|
|
+ params.putInt("offset", offset);
|
|
|
+ params.putInt("limit", limit);
|
|
|
+ if (!TextUtils.isEmpty(mKeywords))
|
|
|
{
|
|
|
- params.putString("keywords",mKeywords);
|
|
|
+ params.putString("keywords", mKeywords);
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -152,35 +166,47 @@ public class EnumSlectOnlineActivity extends AppCompatActivity {
|
|
|
|
|
|
showProgressBar();
|
|
|
Bundle finalParams = params;
|
|
|
- new Thread(new Runnable() {
|
|
|
+ new Thread(new Runnable()
|
|
|
+ {
|
|
|
@Override
|
|
|
- public void run() {
|
|
|
-
|
|
|
+ public void run()
|
|
|
+ {
|
|
|
|
|
|
|
|
|
JSONObject result_json = null;
|
|
|
|
|
|
- if(fakedata)
|
|
|
+ if (fakedata)
|
|
|
{
|
|
|
-
|
|
|
- result_json = getJsonFromAsset(getApplicationContext(),"enum_cadedate.json");
|
|
|
+// try
|
|
|
+// {
|
|
|
+// sleep(2000);
|
|
|
+// } catch (InterruptedException e)
|
|
|
+// {
|
|
|
+// e.printStackTrace();
|
|
|
+// }
|
|
|
+ result_json = getJsonFromAsset(getApplicationContext(), "enum_cadedate.json");
|
|
|
|
|
|
|
|
|
}
|
|
|
else
|
|
|
- result_json=Network.GetCadedate(url, finalParams);
|
|
|
+ {
|
|
|
+ result_json = Network.GetCadedate(url, finalParams);
|
|
|
+ }
|
|
|
|
|
|
JSONObject finalResult_json = result_json;
|
|
|
- runOnUiThread(new Runnable() {
|
|
|
+ runOnUiThread(new Runnable()
|
|
|
+ {
|
|
|
@Override
|
|
|
- public void run() {
|
|
|
+ public void run()
|
|
|
+ {
|
|
|
|
|
|
dismissProgressBar();
|
|
|
-
|
|
|
- if(option == LoadDataOptionReload)
|
|
|
+ mListFooterView.setVisibility(View.INVISIBLE);
|
|
|
+ if (option == LoadDataOptionReload)
|
|
|
{
|
|
|
|
|
|
- if (mRefreshLayout.isRefreshing()) {
|
|
|
+ if (mRefreshLayout.isRefreshing())
|
|
|
+ {
|
|
|
mRefreshLayout.setRefreshing(false);
|
|
|
}
|
|
|
mListFooterView.setVisibility(View.INVISIBLE);
|
|
|
@@ -192,43 +218,49 @@ public class EnumSlectOnlineActivity extends AppCompatActivity {
|
|
|
try
|
|
|
{
|
|
|
|
|
|
- int result = finalResult_json.optInt("result");
|
|
|
- if (result == 2) {
|
|
|
-
|
|
|
- if (option != LoadDataOptionLoadMore) {
|
|
|
- mCadedate = new JSONObject();
|
|
|
- }
|
|
|
-
|
|
|
- int count = finalResult_json.optInt("count");
|
|
|
- if(count>=limit)
|
|
|
- hasmore=true;
|
|
|
- else
|
|
|
+ int result = finalResult_json.optInt("result");
|
|
|
+ if (result == 2)
|
|
|
{
|
|
|
|
|
|
- mListFooterView.setText("No more data");
|
|
|
- mListFooterView.setVisibility(View.VISIBLE);
|
|
|
- hasmore = false;
|
|
|
+ if (option != LoadDataOptionLoadMore)
|
|
|
+ {
|
|
|
+ mCadedate = new JSONObject();
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
- int ccount = mCadedate.optInt("count");
|
|
|
- for (int ipr = 0; ipr < count; ipr++) {
|
|
|
+ int count = finalResult_json.optInt("count");
|
|
|
+ if (count >= limit)
|
|
|
+ {
|
|
|
+ hasmore = true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
|
|
|
- JSONObject item = finalResult_json.optJSONObject("val_" + ipr);
|
|
|
+ mListFooterView.setText("No more data");
|
|
|
+ mListFooterView.setVisibility(View.VISIBLE);
|
|
|
+ hasmore = false;
|
|
|
|
|
|
+ }
|
|
|
+ int ccount = mCadedate.optInt("count");
|
|
|
+ for (int ipr = 0; ipr < count; ipr++)
|
|
|
+ {
|
|
|
|
|
|
- mCadedate.put("val_"+(ccount+ipr),item);
|
|
|
+ JSONObject item = finalResult_json.optJSONObject("val_" + ipr);
|
|
|
|
|
|
|
|
|
+ mCadedate.put("val_" + (ccount + ipr), item);
|
|
|
|
|
|
- }
|
|
|
- mCadedate.put("count",ccount+count);
|
|
|
- offset = ccount+count;
|
|
|
|
|
|
- adapter.notifyDataSetChanged();
|
|
|
+ }
|
|
|
+ mCadedate.put("count", ccount + count);
|
|
|
+ offset = ccount + count;
|
|
|
|
|
|
- } else {
|
|
|
- RAUtil.alertMessage(mCtx,"", finalResult_json.optString("err_msg"));
|
|
|
- }
|
|
|
+ adapter.notifyDataSetChanged();
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ RAUtil.alertMessage(mCtx, "", finalResult_json.optString("err_msg"));
|
|
|
+ }
|
|
|
} catch (JSONException e)
|
|
|
{
|
|
|
e.printStackTrace();
|
|
|
@@ -241,39 +273,45 @@ public class EnumSlectOnlineActivity extends AppCompatActivity {
|
|
|
|
|
|
}
|
|
|
|
|
|
- public static class Builder {
|
|
|
- public Intent build(Context context,String title, int max_select, int group, int child, boolean single_select,boolean auto_close,String url, Bundle params) {
|
|
|
- if (context == null) {
|
|
|
+ public static class Builder
|
|
|
+ {
|
|
|
+ public Intent build(Context context, String title, int max_select, int group, int child, boolean single_select, boolean auto_close, String url, Bundle params)
|
|
|
+ {
|
|
|
+ if (context == null)
|
|
|
+ {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
Intent intent = new Intent(context, EnumSlectOnlineActivity.class);
|
|
|
|
|
|
- intent.putExtra(MAX_SELECT,max_select);
|
|
|
- intent.putExtra(GROUP_POSITION,group);
|
|
|
- intent.putExtra(CHILD_POSITION,child);
|
|
|
- intent.putExtra(PARAMETERS,params);
|
|
|
- intent.putExtra(URL,url);
|
|
|
+ intent.putExtra(MAX_SELECT, max_select);
|
|
|
+ intent.putExtra(GROUP_POSITION, group);
|
|
|
+ intent.putExtra(CHILD_POSITION, child);
|
|
|
+ intent.putExtra(PARAMETERS, params);
|
|
|
+ intent.putExtra(URL, url);
|
|
|
|
|
|
// if (cadedate != null) {
|
|
|
// intent.putExtra(CADEDATE,(Serializable) cadedate);
|
|
|
// }
|
|
|
- intent.putExtra(SINGLE_SELECT,single_select);
|
|
|
- if (title != null) {
|
|
|
- intent.putExtra(TITLE,title);
|
|
|
+ intent.putExtra(SINGLE_SELECT, single_select);
|
|
|
+ if (title != null)
|
|
|
+ {
|
|
|
+ intent.putExtra(TITLE, title);
|
|
|
}
|
|
|
- intent.putExtra(AUTO_CLOSE,auto_close);
|
|
|
+ intent.putExtra(AUTO_CLOSE, auto_close);
|
|
|
|
|
|
return intent;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public class SearchBarWatcher implements TextWatcher {
|
|
|
+ public class SearchBarWatcher implements TextWatcher
|
|
|
+ {
|
|
|
|
|
|
Context mCtx;
|
|
|
EditText textView;
|
|
|
|
|
|
- public SearchBarWatcher(Context ctx,EditText textView) {
|
|
|
+ public SearchBarWatcher(Context ctx, EditText textView)
|
|
|
+ {
|
|
|
this.mCtx = ctx;
|
|
|
this.textView = textView;
|
|
|
|
|
|
@@ -292,9 +330,10 @@ public class EnumSlectOnlineActivity extends AppCompatActivity {
|
|
|
* start 增加内容前光标位置,删除内容后光标位置 (起始位置)
|
|
|
* count 选中s中的内容长度(发生改变的原内容长度),未选中为0
|
|
|
* after 新添加的内容长度,删除为0
|
|
|
- * */
|
|
|
+ */
|
|
|
@Override
|
|
|
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
|
+ public void beforeTextChanged(CharSequence s, int start, int count, int after)
|
|
|
+ {
|
|
|
// Log.d("TextChange", "before Text Changed: " + s + " Start: " + start + " Count: " + count + " After: " + after);
|
|
|
|
|
|
origin_text = s.toString();
|
|
|
@@ -308,27 +347,35 @@ public class EnumSlectOnlineActivity extends AppCompatActivity {
|
|
|
* start 增加内容前光标位置,删除内容后光标位置 (起始位置)
|
|
|
* before 选中s中的内容长度(发生改变的原内容长度),未选中为0
|
|
|
* count 增加内容长度,删除内容为0
|
|
|
- * */
|
|
|
+ */
|
|
|
@Override
|
|
|
- public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
|
+ public void onTextChanged(CharSequence s, int start, int before, int count)
|
|
|
+ {
|
|
|
// Log.d("TextChange", "on Text Changed: " + s + " Start: " + start + " Before: " + before + " Count: " + count);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void afterTextChanged(Editable s) {
|
|
|
+ public void afterTextChanged(Editable s)
|
|
|
+ {
|
|
|
|
|
|
/**
|
|
|
* 文本处理
|
|
|
* */
|
|
|
- if (new_string_length == 0) {
|
|
|
+ if (new_string_length == 0)
|
|
|
+ {
|
|
|
string = "";
|
|
|
- } else {
|
|
|
- string = s.toString().substring(start_position,start_position + new_string_length);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ string = s.toString().substring(start_position, start_position + new_string_length);
|
|
|
}
|
|
|
|
|
|
- if (change_length == 0) { // 新加内容
|
|
|
+ if (change_length == 0)
|
|
|
+ { // 新加内容
|
|
|
|
|
|
- } else { // 替换原文或删除原文
|
|
|
+ }
|
|
|
+ else
|
|
|
+ { // 替换原文或删除原文
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -336,7 +383,8 @@ public class EnumSlectOnlineActivity extends AppCompatActivity {
|
|
|
* 业务逻辑
|
|
|
* */
|
|
|
|
|
|
- if (string.equals("\n") || string.equals("\r") || string.equals("\r\n")) {
|
|
|
+ if (string.equals("\n") || string.equals("\r") || string.equals("\r\n"))
|
|
|
+ {
|
|
|
textView.setText(origin_text);
|
|
|
return;
|
|
|
}
|
|
|
@@ -369,17 +417,20 @@ public class EnumSlectOnlineActivity extends AppCompatActivity {
|
|
|
|
|
|
// region ProgressBar
|
|
|
|
|
|
- public void showProgressBar() {
|
|
|
+ public void showProgressBar()
|
|
|
+ {
|
|
|
mProgressBar.setVisibility(View.VISIBLE);
|
|
|
}
|
|
|
|
|
|
- public void dismissProgressBar() {
|
|
|
+ public void dismissProgressBar()
|
|
|
+ {
|
|
|
mProgressBar.setVisibility(View.GONE);
|
|
|
}
|
|
|
|
|
|
// endregion
|
|
|
@Override
|
|
|
- protected void onCreate(Bundle savedInstanceState) {
|
|
|
+ protected void onCreate(Bundle savedInstanceState)
|
|
|
+ {
|
|
|
super.onCreate(savedInstanceState);
|
|
|
setContentView(R.layout.activity_enum_online_slect);
|
|
|
setupRefreshLayout();
|
|
|
@@ -389,12 +440,10 @@ public class EnumSlectOnlineActivity extends AppCompatActivity {
|
|
|
|
|
|
setTitle(mTitle);
|
|
|
|
|
|
- searchBar = (EditText)findViewById(R.id.common_editor_enum_search_bar);
|
|
|
- searchBar.addTextChangedListener(new SearchBarWatcher(mCtx,searchBar));
|
|
|
-
|
|
|
- enum_list_view = (ListView)findViewById(R.id.enum_list_view);
|
|
|
-
|
|
|
+ searchBar = (EditText) findViewById(R.id.common_editor_enum_search_bar);
|
|
|
+ searchBar.addTextChangedListener(new SearchBarWatcher(mCtx, searchBar));
|
|
|
|
|
|
+ enum_list_view = (ListView) findViewById(R.id.enum_list_view);
|
|
|
|
|
|
|
|
|
adapter = new EnumAdapter(mCtx);
|
|
|
@@ -407,30 +456,32 @@ public class EnumSlectOnlineActivity extends AppCompatActivity {
|
|
|
enum_list_view.setOnScrollListener(mScrollListener);
|
|
|
|
|
|
|
|
|
-
|
|
|
setupListFooterView();
|
|
|
- AbsListView.LayoutParams footerLayoutParams = new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT);
|
|
|
+ AbsListView.LayoutParams footerLayoutParams = new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
|
|
mListFooterView.setLayoutParams(footerLayoutParams);
|
|
|
enum_list_view.addFooterView(mListFooterView);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void finish() {
|
|
|
+ public void finish()
|
|
|
+ {
|
|
|
|
|
|
- if (mDirty != false) {
|
|
|
+ if (mDirty != false)
|
|
|
+ {
|
|
|
Intent intent = new Intent();
|
|
|
// intent.putExtra(CADEDATE,mCadedate.toString());
|
|
|
- intent.putExtra(GROUP_POSITION,mGroup);
|
|
|
- intent.putExtra(CHILD_POSITION,mChild);
|
|
|
+ intent.putExtra(GROUP_POSITION, mGroup);
|
|
|
+ intent.putExtra(CHILD_POSITION, mChild);
|
|
|
|
|
|
- setResult(RESULT_OK,intent);
|
|
|
+ setResult(RESULT_OK, intent);
|
|
|
}
|
|
|
|
|
|
|
|
|
super.finish();
|
|
|
}
|
|
|
|
|
|
- private void init() {
|
|
|
+ private void init()
|
|
|
+ {
|
|
|
mCtx = this;
|
|
|
Intent intent = getIntent();
|
|
|
|
|
|
@@ -441,54 +492,66 @@ public class EnumSlectOnlineActivity extends AppCompatActivity {
|
|
|
// } catch (Exception e) {
|
|
|
// e.printStackTrace();
|
|
|
// }
|
|
|
- mSingleSelect = intent.getBooleanExtra(SINGLE_SELECT,true);
|
|
|
- mGroup = intent.getIntExtra(GROUP_POSITION,0);
|
|
|
- mChild = intent.getIntExtra(CHILD_POSITION,0);
|
|
|
+ mSingleSelect = intent.getBooleanExtra(SINGLE_SELECT, true);
|
|
|
+ mGroup = intent.getIntExtra(GROUP_POSITION, 0);
|
|
|
+ mChild = intent.getIntExtra(CHILD_POSITION, 0);
|
|
|
mTitle = intent.getStringExtra(TITLE);
|
|
|
- maxSelect = intent.getIntExtra(MAX_SELECT,0);
|
|
|
- mAuto_close = intent.getBooleanExtra(AUTO_CLOSE,true);
|
|
|
+ maxSelect = intent.getIntExtra(MAX_SELECT, 0);
|
|
|
+ mAuto_close = intent.getBooleanExtra(AUTO_CLOSE, true);
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
- private class CellClickListener implements AdapterView.OnItemClickListener {
|
|
|
+ private class CellClickListener implements AdapterView.OnItemClickListener
|
|
|
+ {
|
|
|
|
|
|
private Context ctx;
|
|
|
- public CellClickListener(Context ctx) {
|
|
|
+
|
|
|
+ public CellClickListener(Context ctx)
|
|
|
+ {
|
|
|
this.ctx = ctx;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
|
|
+ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
|
|
|
+ {
|
|
|
|
|
|
mDirty = true;
|
|
|
|
|
|
- try {
|
|
|
- if (mSingleSelect) {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (mSingleSelect)
|
|
|
+ {
|
|
|
|
|
|
- boolean is_worked = false;
|
|
|
+ boolean is_worked = true;
|
|
|
|
|
|
// if (mKeywords == null || mKeywords.isEmpty()) {
|
|
|
|
|
|
- for (int i = 0; i < mCadedate.optInt("count"); i++) {
|
|
|
- JSONObject val_json = mCadedate.optJSONObject("val_" + i);
|
|
|
+ for (int i = 0; i < mCadedate.optInt("count"); i++)
|
|
|
+ {
|
|
|
+ JSONObject val_json = mCadedate.optJSONObject("val_" + i);
|
|
|
|
|
|
- if (i == position) {
|
|
|
- int select = val_json.optInt("check");
|
|
|
- if (select == 0) {
|
|
|
- val_json.put("check","1");
|
|
|
- } else {
|
|
|
- val_json.put("check","0");
|
|
|
- }
|
|
|
- is_worked = select == 0;
|
|
|
- } else {
|
|
|
- val_json.put("check","0");
|
|
|
+ if (i == position)
|
|
|
+ {
|
|
|
+ int select = val_json.optInt("check");
|
|
|
+ if (select == 0)
|
|
|
+ {
|
|
|
+ val_json.put("check", "1");
|
|
|
}
|
|
|
- mCadedate.put("val_" + i,val_json);
|
|
|
-
|
|
|
+// else
|
|
|
+// {
|
|
|
+// val_json.put("check", "0");
|
|
|
+// }
|
|
|
+// is_worked =true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ val_json.put("check", "0");
|
|
|
+ }
|
|
|
+ mCadedate.put("val_" + i, val_json);
|
|
|
|
|
|
|
|
|
- } // for
|
|
|
+ } // for
|
|
|
|
|
|
// } // keywords null
|
|
|
// else {
|
|
|
@@ -543,24 +606,31 @@ public class EnumSlectOnlineActivity extends AppCompatActivity {
|
|
|
//
|
|
|
// }
|
|
|
|
|
|
- if (is_worked) {
|
|
|
- if (mAuto_close) {
|
|
|
+ if (is_worked)
|
|
|
+ {
|
|
|
+ if (mAuto_close)
|
|
|
+ {
|
|
|
finish();
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
adapter.notifyDataSetChanged();
|
|
|
}
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
adapter.notifyDataSetChanged();
|
|
|
}
|
|
|
|
|
|
|
|
|
} // single select
|
|
|
- else {
|
|
|
+ else
|
|
|
+ {
|
|
|
|
|
|
int index = position;
|
|
|
JSONObject val_json = null;
|
|
|
// if (mKeywords == null || mKeywords.isEmpty()) {
|
|
|
- val_json = mCadedate.optJSONObject("val_" + position);
|
|
|
+ val_json = mCadedate.optJSONObject("val_" + position);
|
|
|
// }
|
|
|
// else {
|
|
|
// int count = 0;
|
|
|
@@ -584,39 +654,47 @@ public class EnumSlectOnlineActivity extends AppCompatActivity {
|
|
|
// }
|
|
|
|
|
|
int check = val_json.optInt("check");
|
|
|
- if (check == 1) {
|
|
|
- val_json.put("check","0");
|
|
|
- } else {
|
|
|
- if (check_count() >= maxSelect && maxSelect > 0) {
|
|
|
+ if (check == 1)
|
|
|
+ {
|
|
|
+ val_json.put("check", "0");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (check_count() >= maxSelect && maxSelect > 0)
|
|
|
+ {
|
|
|
new AlertDialog.Builder(this.ctx)
|
|
|
.setTitle("Max count reached")
|
|
|
.setMessage(maxSelect + " items at most for this field.")
|
|
|
- .setPositiveButton("OK",null)
|
|
|
+ .setPositiveButton("OK", null)
|
|
|
.show();
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
- val_json.put("check","1");
|
|
|
+ val_json.put("check", "1");
|
|
|
}
|
|
|
- mCadedate.put("val_" + index,val_json);
|
|
|
+ mCadedate.put("val_" + index, val_json);
|
|
|
|
|
|
}
|
|
|
adapter.notifyDataSetChanged();
|
|
|
|
|
|
- } catch (Exception e) {
|
|
|
+ } catch (Exception e)
|
|
|
+ {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public int check_count() {
|
|
|
+ public int check_count()
|
|
|
+ {
|
|
|
|
|
|
int check_count = 0;
|
|
|
- for (int i = 0; i < mCadedate.optInt("count"); i++) {
|
|
|
+ for (int i = 0; i < mCadedate.optInt("count"); i++)
|
|
|
+ {
|
|
|
JSONObject val_json = mCadedate.optJSONObject("val_" + i);
|
|
|
int check = val_json.optInt("check");
|
|
|
- if (check == 1) {
|
|
|
+ if (check == 1)
|
|
|
+ {
|
|
|
check_count++;
|
|
|
}
|
|
|
}
|
|
|
@@ -624,18 +702,22 @@ public class EnumSlectOnlineActivity extends AppCompatActivity {
|
|
|
}
|
|
|
|
|
|
|
|
|
- private class EnumAdapter extends BaseAdapter {
|
|
|
+ private class EnumAdapter extends BaseAdapter
|
|
|
+ {
|
|
|
|
|
|
- public class Holder {
|
|
|
+ public class Holder
|
|
|
+ {
|
|
|
public TextView value_tv;
|
|
|
public ImageView check_iv;
|
|
|
|
|
|
- public Holder(View cell) {
|
|
|
- if (cell == null) {
|
|
|
+ public Holder(View cell)
|
|
|
+ {
|
|
|
+ if (cell == null)
|
|
|
+ {
|
|
|
return;
|
|
|
}
|
|
|
- value_tv = (TextView)cell.findViewById(R.id.enum_value_tv);
|
|
|
- check_iv = (ImageView)cell.findViewById(R.id.enum_check_iv);
|
|
|
+ value_tv = (TextView) cell.findViewById(R.id.enum_value_tv);
|
|
|
+ check_iv = (ImageView) cell.findViewById(R.id.enum_check_iv);
|
|
|
check_iv.setClickable(false);
|
|
|
check_iv.setFocusable(false);
|
|
|
cell.setTag(this);
|
|
|
@@ -645,20 +727,24 @@ public class EnumSlectOnlineActivity extends AppCompatActivity {
|
|
|
|
|
|
|
|
|
private Context ctx;
|
|
|
- public EnumAdapter(Context context) {
|
|
|
+
|
|
|
+ public EnumAdapter(Context context)
|
|
|
+ {
|
|
|
this.ctx = context;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public int getCount() {
|
|
|
+ public int getCount()
|
|
|
+ {
|
|
|
|
|
|
- if (mCadedate == null) {
|
|
|
+ if (mCadedate == null)
|
|
|
+ {
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
// if (mKeywords == null || mKeywords.isEmpty()) {
|
|
|
// filter_count = 0;
|
|
|
- return mCadedate.optInt("count");
|
|
|
+ return mCadedate.optInt("count");
|
|
|
// }
|
|
|
|
|
|
// int count = 0;
|
|
|
@@ -675,10 +761,11 @@ public class EnumSlectOnlineActivity extends AppCompatActivity {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Object getItem(int position) {
|
|
|
+ public Object getItem(int position)
|
|
|
+ {
|
|
|
JSONObject val_json = null;
|
|
|
// if (mKeywords == null || mKeywords.isEmpty()) {
|
|
|
- val_json = mCadedate.optJSONObject("val_" + position);
|
|
|
+ val_json = mCadedate.optJSONObject("val_" + position);
|
|
|
// }
|
|
|
// else {
|
|
|
// int count = 0;
|
|
|
@@ -706,12 +793,14 @@ public class EnumSlectOnlineActivity extends AppCompatActivity {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public long getItemId(int position) {
|
|
|
+ public long getItemId(int position)
|
|
|
+ {
|
|
|
return position;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public View getView(int position, View convertView, ViewGroup parent) {
|
|
|
+ public View getView(int position, View convertView, ViewGroup parent)
|
|
|
+ {
|
|
|
JSONObject val_json = (JSONObject) getItem(position);
|
|
|
// if (mKeywords == null || mKeywords.isEmpty()) {
|
|
|
// val_json = mCadedate.optJSONObject("val_" + position);
|
|
|
@@ -720,12 +809,15 @@ public class EnumSlectOnlineActivity extends AppCompatActivity {
|
|
|
// }
|
|
|
|
|
|
Holder holder;
|
|
|
- if (convertView == null) {
|
|
|
+ if (convertView == null)
|
|
|
+ {
|
|
|
|
|
|
- convertView = LayoutInflater.from(this.ctx).inflate(R.layout.enum_select_cell,null);
|
|
|
+ convertView = LayoutInflater.from(this.ctx).inflate(R.layout.enum_select_cell, null);
|
|
|
holder = new Holder(convertView);
|
|
|
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
holder = (Holder) convertView.getTag();
|
|
|
}
|
|
|
|
|
|
@@ -733,9 +825,12 @@ public class EnumSlectOnlineActivity extends AppCompatActivity {
|
|
|
holder.value_tv.setText(value);
|
|
|
|
|
|
int check = val_json.optInt("check");
|
|
|
- if (check == 1) {
|
|
|
+ if (check == 1)
|
|
|
+ {
|
|
|
holder.check_iv.setVisibility(View.VISIBLE);
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
holder.check_iv.setVisibility(View.INVISIBLE);
|
|
|
}
|
|
|
|