From 666971bfcc3eb5c10f399b0dbc18ec44a804ab4c Mon Sep 17 00:00:00 2001 From: yxb <15805828761@163.com> Date: Sat, 12 May 2018 15:28:45 +0800 Subject: [PATCH] no message --- .idea/inspectionProfiles/profiles_settings.xml | 6 ------ .idea/misc.xml | 9 +++++---- .idea/modules.xml | 2 -- .idea/vcs.xml | 2 +- app/libs/processor.jar | Bin 5681 -> 0 bytes app/src/main/java/com/shunzhi/parent/AppConfig.java | 2 ++ app/src/main/java/com/shunzhi/parent/AppContext.java | 26 +++++++++++++++++++++++++- app/src/main/java/com/shunzhi/parent/adapter/MyArrayAdapter.java | 431 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ app/src/main/java/com/shunzhi/parent/adapter/MyThemedSpinnerAdapter.java | 15 +++++++++++++++ app/src/main/java/com/shunzhi/parent/presenter/loginandregister/LoginAndRegisterPresenter.java | 5 ++++- app/src/main/java/com/shunzhi/parent/ui/fragment/loginandregistfragment/LoginAndRegistFragment.java | 56 ++++++++++++++++++++++++++++++++++++++++++++------------ app/src/main/res/layout/fragment_login_and_regist.xml | 57 ++++++++++++++++++++++++++++++++++++++++----------------- app/src/main/res/layout/simple_dropdown_item_1line.xml | 27 +++++++++++++++++++++++++++ 13 files changed, 594 insertions(+), 44 deletions(-) delete mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 app/src/main/java/com/shunzhi/parent/adapter/MyArrayAdapter.java create mode 100644 app/src/main/java/com/shunzhi/parent/adapter/MyThemedSpinnerAdapter.java create mode 100644 app/src/main/res/layout/simple_dropdown_item_1line.xml diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml deleted file mode 100644 index cb2fdb3..0000000 --- a/.idea/inspectionProfiles/profiles_settings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 3963879..dc34569 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -5,11 +5,12 @@ @@ -24,7 +25,7 @@ - + diff --git a/.idea/modules.xml b/.idea/modules.xml index 1c542c8..df67e8a 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -4,9 +4,7 @@ - - diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 35eb1dd..94a25f7 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/app/libs/processor.jar b/app/libs/processor.jar index 952eada..7f3ef0c 100644 Binary files a/app/libs/processor.jar and b/app/libs/processor.jar differ diff --git a/app/src/main/java/com/shunzhi/parent/AppConfig.java b/app/src/main/java/com/shunzhi/parent/AppConfig.java index bd67d09..c1bf11d 100644 --- a/app/src/main/java/com/shunzhi/parent/AppConfig.java +++ b/app/src/main/java/com/shunzhi/parent/AppConfig.java @@ -13,6 +13,7 @@ import java.io.File; */ public class AppConfig { + public static final String SYSTEM_INIT_FILE_NAME = "shunzhi_sysini"; //保存键值对 public static String SCHOOL_ID = "school_id"; public static String LOGIN_NAME = "login_name"; @@ -27,6 +28,7 @@ public class AppConfig { public static String ISBINDING = "isbinding"; public static String CURRCHILDJSONSTR = ""; public static String DISTRICT="district"; + public static String LOGINHISTORY = "login_history"; public static boolean ISLOGIN = false; diff --git a/app/src/main/java/com/shunzhi/parent/AppContext.java b/app/src/main/java/com/shunzhi/parent/AppContext.java index 4f0c9f1..9ca20b5 100644 --- a/app/src/main/java/com/shunzhi/parent/AppContext.java +++ b/app/src/main/java/com/shunzhi/parent/AppContext.java @@ -26,6 +26,8 @@ import com.shunzhi.parent.ui.MainActivity; import org.greenrobot.greendao.database.Database; import org.greenrobot.greendao.database.DatabaseOpenHelper; +import org.json.JSONArray; +import org.json.JSONException; import timber.log.Timber; @@ -36,6 +38,8 @@ import timber.log.Timber; public class AppContext extends GlobalApplication { private static AppContext appContext; + private SharedPreferences sysInitSharedPreferences; + public final static int LOCATION_CITYNAME = 0x00; public String cityName = "", district = ""; @@ -62,7 +66,7 @@ public class AppContext extends GlobalApplication { public void onCreate() { appContext = this; super.onCreate(); - + sysInitSharedPreferences = getSharedPreferences(AppConfig.SYSTEM_INIT_FILE_NAME, MODE_PRIVATE); NIMClient.init(this, loginInfo(), options()); if (null==AppConfig.getAppConfig(getContext()).get(AppConfig.DISTRICT)) AppConfig.getAppConfig(getContext()).set(AppConfig.DISTRICT,"越城区"); @@ -246,4 +250,24 @@ public class AppContext extends GlobalApplication { } + public String getHistroyUser() { + return sysInitSharedPreferences.getString("histroyUser", "[]"); + } + + public void setHistroyUser(String histroyUser) { + String histroy = getHistroyUser(); + if (histroy.contains(histroyUser)) return; + JSONArray ja = null; + try { + ja = new JSONArray(histroy); + ja.put(histroyUser); + } catch (JSONException e) { + e.printStackTrace(); + } + if (ja == null) ja = new JSONArray(); + sysInitSharedPreferences.edit().putString("histroyUser", ja.toString()).apply(); + } + + + } diff --git a/app/src/main/java/com/shunzhi/parent/adapter/MyArrayAdapter.java b/app/src/main/java/com/shunzhi/parent/adapter/MyArrayAdapter.java new file mode 100644 index 0000000..a3b735b --- /dev/null +++ b/app/src/main/java/com/shunzhi/parent/adapter/MyArrayAdapter.java @@ -0,0 +1,431 @@ +package com.shunzhi.parent.adapter; + + +import android.content.Context; +import android.content.res.Resources; +import android.support.annotation.IdRes; +import android.support.annotation.LayoutRes; +import android.support.annotation.NonNull; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.Filter; +import android.widget.Filterable; +import android.widget.TextView; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +/** + * Created by Administrator on 2016/7/4. + */ +public class MyArrayAdapter extends BaseAdapter implements Filterable, MyThemedSpinnerAdapter { + private final Object mLock = new Object(); + + private final LayoutInflater mInflater; + private List mObjects; + private int mResource; + + private int mDropDownResource; + + private int mFieldId = 0; + + private boolean mNotifyOnChange = true; + + private Context mContext; + + private ArrayList mOriginalValues; + private ArrayFilter mFilter; + private LayoutInflater mDropDownInflater; + + public MyArrayAdapter(Context context, @LayoutRes int resource) { + this(context, resource, 0, new ArrayList()); + } + + public MyArrayAdapter(Context context, @LayoutRes int resource, @IdRes int textViewResourceId) { + this(context, resource, textViewResourceId, new ArrayList()); + } + + public MyArrayAdapter(Context context, @LayoutRes int resource, @NonNull List objects) { + this(context, resource, 0, objects); + } + + + /** + * Constructor + * + * @param context The current context. + * @param resource The resource ID for a layout file containing a TextView to use when + * instantiating views. + * @param objects The objects to represent in the ListView. + */ + public MyArrayAdapter(Context context, @LayoutRes int resource, @NonNull T[] objects) { + this(context, resource, 0, Arrays.asList(objects)); + } + + /** + * Constructor + * + * @param context The current context. + * @param resource The resource ID for a layout file containing a layout to use when + * instantiating views. + * @param textViewResourceId The id of the TextView within the layout resource to be populated + * @param objects The objects to represent in the ListView. + */ + public MyArrayAdapter(Context context, @LayoutRes int resource, @IdRes int textViewResourceId, + @NonNull T[] objects) { + this(context, resource, textViewResourceId, Arrays.asList(objects)); + } + + public MyArrayAdapter(Context context, @LayoutRes int resource, @IdRes int textViewResourceId, + @NonNull List objects) { + mContext = context; + mInflater = LayoutInflater.from(context); + mResource = mDropDownResource = resource; + mObjects = objects; + mFieldId = textViewResourceId; + } + + public void add(T object) { + synchronized (mLock) { + if (mOriginalValues != null) { + mOriginalValues.add(object); + } else { + mObjects.add(object); + } + } + if (mNotifyOnChange) notifyDataSetChanged(); + } + + /** + * Adds the specified Collection at the end of the array. + * + * @param collection The Collection to add at the end of the array. + */ + public void addAll(Collection collection) { + synchronized (mLock) { + if (mOriginalValues != null) { + mOriginalValues.addAll(collection); + } else { + mObjects.addAll(collection); + } + } + if (mNotifyOnChange) notifyDataSetChanged(); + } + + /** + * Adds the specified items at the end of the array. + * + * @param items The items to add at the end of the array. + */ + public void addAll(T... items) { + synchronized (mLock) { + if (mOriginalValues != null) { + Collections.addAll(mOriginalValues, items); + } else { + Collections.addAll(mObjects, items); + } + } + if (mNotifyOnChange) notifyDataSetChanged(); + } + + /** + * Inserts the specified object at the specified index in the array. + * + * @param object The object to insert into the array. + * @param index The index at which the object must be inserted. + */ + public void insert(T object, int index) { + synchronized (mLock) { + if (mOriginalValues != null) { + mOriginalValues.add(index, object); + } else { + mObjects.add(index, object); + } + } + if (mNotifyOnChange) notifyDataSetChanged(); + } + + /** + * Removes the specified object from the array. + * + * @param object The object to remove. + */ + public void remove(T object) { + synchronized (mLock) { + if (mOriginalValues != null) { + mOriginalValues.remove(object); + } else { + mObjects.remove(object); + } + } + if (mNotifyOnChange) notifyDataSetChanged(); + } + + /** + * Remove all elements from the list. + */ + public void clear() { + synchronized (mLock) { + if (mOriginalValues != null) { + mOriginalValues.clear(); + } else { + mObjects.clear(); + } + } + if (mNotifyOnChange) notifyDataSetChanged(); + } + + /** + * Sorts the content of this adapter using the specified comparator. + * + * @param comparator The comparator used to sort the objects contained + * in this adapter. + */ + public void sort(Comparator comparator) { + synchronized (mLock) { + if (mOriginalValues != null) { + Collections.sort(mOriginalValues, comparator); + } else { + Collections.sort(mObjects, comparator); + } + } + if (mNotifyOnChange) notifyDataSetChanged(); + } + + /** + * {@inheritDoc} + */ + @Override + public void notifyDataSetChanged() { + super.notifyDataSetChanged(); + mNotifyOnChange = true; + } + + /** + * Control whether methods that change the list ({@link #add}, + * {@link #insert}, {@link #remove}, {@link #clear}) automatically call + * {@link #notifyDataSetChanged}. If set to false, caller must + * manually call notifyDataSetChanged() to have the changes + * reflected in the attached view. + *

+ * The default is true, and calling notifyDataSetChanged() + * resets the flag to true. + * + * @param notifyOnChange if true, modifications to the list will + * automatically call {@link + * #notifyDataSetChanged} + */ + public void setNotifyOnChange(boolean notifyOnChange) { + mNotifyOnChange = notifyOnChange; + } + + /** + * Returns the context associated with this array adapter. The context is used + * to create views from the resource passed to the constructor. + * + * @return The Context associated with this adapter. + */ + public Context getContext() { + return mContext; + } + + /** + * {@inheritDoc} + */ + public int getCount() { + return mObjects.size(); + } + + /** + * {@inheritDoc} + */ + public T getItem(int position) { + return mObjects.get(position); + } + + /** + * Returns the position of the specified item in the array. + * + * @param item The item to retrieve the position of. + * @return The position of the specified item. + */ + public int getPosition(T item) { + return mObjects.indexOf(item); + } + + /** + * {@inheritDoc} + */ + public long getItemId(int position) { + return position; + } + + /** + * {@inheritDoc} + */ + public View getView(int position, View convertView, ViewGroup parent) { + return createViewFromResource(mInflater, position, convertView, parent, mResource); + } + + private View createViewFromResource(LayoutInflater inflater, int position, View convertView, + ViewGroup parent, int resource) { + View view; + TextView text; + + if (convertView == null) { + view = inflater.inflate(resource, parent, false); + } else { + view = convertView; + } + + try { + if (mFieldId == 0) { + // If no custom field is assigned, assume the whole resource is a TextView + text = (TextView) view; + } else { + // Otherwise, find the TextView field within the layout + text = (TextView) view.findViewById(mFieldId); + } + } catch (ClassCastException e) { + throw new IllegalStateException( + "ArrayAdapter requires the resource ID to be a TextView", e); + } + + T item = getItem(position); + if (item instanceof CharSequence) { + text.setText((CharSequence) item); + } else { + text.setText(item.toString()); + } + + return view; + } + + /** + *

Sets the layout resource to create the drop down views.

+ * + * @param resource the layout resource defining the drop down views + * @see #getDropDownView(int, View, ViewGroup) + */ + public void setDropDownViewResource(@LayoutRes int resource) { + this.mDropDownResource = resource; + } + + /** + * Sets the {@link Resources.Theme} against which drop-down views are + * inflated. + *

+ * By default, drop-down views are inflated against the theme of the + * {@link Context} passed to the adapter's constructor. + * + * @param theme the theme against which to inflate drop-down views or + * {@code null} to use the theme from the adapter's context + * @see #getDropDownView(int, View, ViewGroup) + */ + @Override + public void setDropDownViewTheme(Resources.Theme theme) { + if (theme == null) { + mDropDownInflater = null; + } else if (theme == mInflater.getContext().getTheme()) { + mDropDownInflater = mInflater; + } +// else { +// final Context context = new ContextThemeWrapper(mContext, theme); +// mDropDownInflater = LayoutInflater.from(context); +// } + } + + @Override + public Resources.Theme getDropDownViewTheme() { + return mDropDownInflater == null ? null : mDropDownInflater.getContext().getTheme(); + } + + @Override + public View getDropDownView(int position, View convertView, ViewGroup parent) { + final LayoutInflater inflater = mDropDownInflater == null ? mInflater : mDropDownInflater; + return createViewFromResource(inflater, position, convertView, parent, mDropDownResource); + } + + + public Filter getFilter() { + if (mFilter == null) { + mFilter = new ArrayFilter(); + } + return mFilter; + } + + private class ArrayFilter extends Filter { + @Override + protected FilterResults performFiltering(CharSequence prefix) { + FilterResults results = new FilterResults(); + + if (mOriginalValues == null) { + synchronized (mLock) { + mOriginalValues = new ArrayList(mObjects); + } + } + + if (prefix == null || prefix.length() == 0) { + ArrayList list; + synchronized (mLock) { + list = new ArrayList(mOriginalValues); + } + results.values = list; + results.count = list.size(); + } else { + String prefixString = prefix.toString().toLowerCase(); + + ArrayList values; + synchronized (mLock) { + values = new ArrayList(mOriginalValues); + } + + final int count = values.size(); + final ArrayList newValues = new ArrayList(); + + for (int i = 0; i < count; i++) { + final T value = values.get(i); + final String valueText = value.toString().toLowerCase(); + + // First match against the whole, non-splitted value + if (valueText.startsWith(prefixString)) { + newValues.add(value); + } else { + final String[] words = valueText.split(" "); + final int wordCount = words.length; + + // Start at index 0, in case valueText starts with space(s) + for (int k = 0; k < wordCount; k++) { + if (words[k].contains(prefixString)) { + newValues.add(value); + break; + } + } + } + } + + results.values = newValues; + results.count = newValues.size(); + } + + return results; + } + + @Override + protected void publishResults(CharSequence constraint, FilterResults results) { + //noinspection unchecked + mObjects = (List) results.values; + if (results.count > 0) { + notifyDataSetChanged(); + } else { + notifyDataSetInvalidated(); + } + } + } +} diff --git a/app/src/main/java/com/shunzhi/parent/adapter/MyThemedSpinnerAdapter.java b/app/src/main/java/com/shunzhi/parent/adapter/MyThemedSpinnerAdapter.java new file mode 100644 index 0000000..4e5de5f --- /dev/null +++ b/app/src/main/java/com/shunzhi/parent/adapter/MyThemedSpinnerAdapter.java @@ -0,0 +1,15 @@ +package com.shunzhi.parent.adapter; + +import android.content.res.Resources; +import android.support.annotation.Nullable; +import android.widget.SpinnerAdapter; + +/** + * Created by Administrator on 2016/7/5. + */ +public interface MyThemedSpinnerAdapter extends SpinnerAdapter { + @Nullable + Resources.Theme getDropDownViewTheme(); + void setDropDownViewTheme(@Nullable Resources.Theme theme); +} + diff --git a/app/src/main/java/com/shunzhi/parent/presenter/loginandregister/LoginAndRegisterPresenter.java b/app/src/main/java/com/shunzhi/parent/presenter/loginandregister/LoginAndRegisterPresenter.java index 08d4e29..aa53369 100644 --- a/app/src/main/java/com/shunzhi/parent/presenter/loginandregister/LoginAndRegisterPresenter.java +++ b/app/src/main/java/com/shunzhi/parent/presenter/loginandregister/LoginAndRegisterPresenter.java @@ -60,6 +60,9 @@ public class LoginAndRegisterPresenter extends LoginAndRegisterContract.LoginPre AppConfig.getAppConfig(AppContext.getInstance()).set(AppConfig.LOGIN_PWD, loginPwd); RetrofitCreateHelper.getInstance().setAuthorization(jsonObject.get("access_token").getAsString()); getUserInfo(loginName, 0, ""); + //fixme 新增历史登录账号 + AppContext.getInstance().setHistroyUser(loginName); + } else { ToastUtils.showToast(jsonObject.get("error").getAsString()); } @@ -173,7 +176,7 @@ public class LoginAndRegisterPresenter extends LoginAndRegisterContract.LoginPre if (currentBean.getStudentClass() != null && currentBean.getStudentClass().size() > 0) { AppConfig.getAppConfig(mIView.getBindActivity()).set(AppConfig.ISBINDING, "1"); - }else{ + } else { AppConfig.getAppConfig(mIView.getBindActivity()).set(AppConfig.ISBINDING, "0"); } diff --git a/app/src/main/java/com/shunzhi/parent/ui/fragment/loginandregistfragment/LoginAndRegistFragment.java b/app/src/main/java/com/shunzhi/parent/ui/fragment/loginandregistfragment/LoginAndRegistFragment.java index 914cf9f..7507d1f 100644 --- a/app/src/main/java/com/shunzhi/parent/ui/fragment/loginandregistfragment/LoginAndRegistFragment.java +++ b/app/src/main/java/com/shunzhi/parent/ui/fragment/loginandregistfragment/LoginAndRegistFragment.java @@ -12,6 +12,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.WindowManager; +import android.widget.AutoCompleteTextView; import android.widget.EditText; import android.widget.ImageView; import android.widget.LinearLayout; @@ -25,19 +26,27 @@ import com.share.mvpsdk.utils.ToastUtils; import com.shunzhi.parent.AppConfig; import com.shunzhi.parent.AppContext; import com.shunzhi.parent.R; +import com.shunzhi.parent.adapter.MyArrayAdapter; import com.shunzhi.parent.contract.loginandregister.LoginAndRegisterContract; import com.shunzhi.parent.presenter.loginandregister.LoginAndRegisterPresenter; import com.shunzhi.parent.ui.MainActivity; import com.shunzhi.parent.ui.activity.LoginAndRegistActivity; import com.shunzhi.parent.views.MyProcessDialog; +import org.json.JSONArray; +import org.json.JSONException; + +import java.util.ArrayList; +import java.util.List; + public class LoginAndRegistFragment extends BaseMVPCompatFragment implements LoginAndRegisterContract.ILoginView, View.OnClickListener { public RoundedImageView roundedImageView; - public EditText phoneNumber, idCode, password, et_password_new; - public TextView get_idCode, loginAndRegister, tv_info, tv_goto, tv_goto_zhuce, tv_goto_mima,center_title; + public EditText idCode, password, et_password_new; + AutoCompleteTextView phoneNumber; + public TextView get_idCode, loginAndRegister, tv_info, tv_goto, tv_goto_zhuce, tv_goto_mima, center_title; public LinearLayout phoneLayout, idCodeLayout, passwordLayout, main_login, passwordLayout_new; public ImageView img_eye, img_eye_new, back_top; public static String typepage; @@ -100,7 +109,6 @@ public class LoginAndRegistFragment extends BaseMVPCompatFragment list = new ArrayList<>(); + for (int i = 0; i < ja.length(); i++) { + list.add(ja.optString(i)); + } + MyArrayAdapter adapter = new MyArrayAdapter(getActivity(), R.layout.simple_dropdown_item_1line, list); + phoneNumber.setAdapter(adapter); + phoneNumber.setThreshold(1); + phoneNumber.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + phoneNumber.showDropDown(); + } + }); + } catch (JSONException e) { + e.printStackTrace(); + } + } + + @Override - public void getUserInfo(int type,String message) { + public void getUserInfo(int type, String message) { progressDialog.dismiss(); if (type == 0) { startActivity(new Intent().setClass(getActivity(), MainActivity.class)); @@ -173,11 +205,11 @@ public class LoginAndRegistFragment extends BaseMVPCompatFragment - + + - + + + + + + + + + + + @@ -142,12 +162,13 @@ android:background="@color/bottomline" /> + + android:orientation="vertical" + android:visibility="gone"> @@ -222,13 +243,14 @@ android:textSize="@dimen/sp_16" /> + + android:orientation="horizontal" + android:visibility="gone"> + + android:layout_weight="1" /> + + + -- libgit2 0.21.0