导航菜单

页面标题

页面副标题

St.John's v1.0.9 - SchoolSelectionActivity.java 源代码

正在查看: St.John's v1.0.9 应用的 SchoolSelectionActivity.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.mcb.stjohnsemschool.activity;

import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.net.ConnectivityManager;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Html;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.SearchView;
import androidx.appcompat.widget.Toolbar;
import com.google.firebase.analytics.FirebaseAnalytics;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.mcb.stjohnsemschool.model.Result;
import com.mcb.stjohnsemschool.model.SchoolListModel;
import com.mcb.stjohnsemschool.utils.TransparentProgressDialog;
import com.mcb.stjohnsemschool.utils.async_task_thread_pool.AsyncTaskEx;
import com.mcb.stjohnsemschool.utils.async_task_thread_pool.AsyncTaskThreadPool;
import com.squareup.picasso.Picasso;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import lb.library.PinnedHeaderListView;
import lb.library.SearchablePinnedHeaderListViewAdapter;
import lb.library.StringArrayAlphabetIndexer;

public class SchoolSelectionActivity extends AppCompatActivity implements AdapterView.OnItemClickListener, SearchView.OnQueryTextListener {
    public static final String TAG = "com.mcb.stjohnsemschool.activity.SchoolSelectionActivity";
    public static AppCompatActivity myActivity;
    private ConnectivityManager conMgr;
    private ContactsAdapter mAdapter;
    private SharedPreferences.Editor mEditor;
    private LayoutInflater mInflater;
    private PinnedHeaderListView mListView;
    private TextView mNoData;
    private TransparentProgressDialog mProgressbar;
    private SharedPreferences mSharedPref;
    private SearchView searchView;
    private Toolbar toolbar;
    private String SERVICE_URL = "https://mcbapi.myclassboard.com/School/get_allschools";
    private ArrayList<Result> mSchoolsList = new ArrayList<>();
    private ArrayList<Result> mSchoolsListDup = new ArrayList<>();

    public boolean onQueryTextSubmit(String str) {
        return false;
    }

    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        this.mInflater = LayoutInflater.from(this);
        setContentView(R.layout.activity_schoolselection);
        Toolbar findViewById = findViewById(R.id.tool_bar);
        this.toolbar = findViewById;
        myActivity = this;
        setSupportActionBar(findViewById);
        getSupportActionBar().setTitle("");
        getSupportActionBar().setDisplayHomeAsUpEnabled(false);
        getSupportActionBar().setDisplayShowTitleEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(false);
        ((TextView) this.toolbar.findViewById(R.id.actionBarText)).setText("");
        SharedPreferences sharedPreferences = getSharedPreferences("", 0);
        this.mSharedPref = sharedPreferences;
        this.mEditor = sharedPreferences.edit();
        PinnedHeaderListView findViewById2 = findViewById(android.R.id.list);
        this.mListView = findViewById2;
        findViewById2.setOnItemClickListener(this);
        this.mProgressbar = new TransparentProgressDialog(this, R.drawable.spinner_loading_imag);
        findViewById(R.id.card_search);
        SearchView findViewById3 = findViewById(R.id.edit_text_search);
        this.searchView = findViewById3;
        ((EditText) findViewById3.findViewById(2131363577)).setTextColor(getResources().getColor(R.color.ColorPrimary));
        this.searchView.setOnQueryTextListener(this);
        this.searchView.setIconified(false);
        this.mNoData = (TextView) findViewById(R.id.txv_no_data);
        this.mListView.setVisibility(8);
        this.mNoData.setVisibility(0);
        this.mNoData.setText("Please enter your ward's school name in the search box above.");
        loadSchoolsData();
    }

    public static int getResIdFromAttribute(Activity activity, int i) {
        if (i == 0) {
            return 0;
        }
        TypedValue typedValue = new TypedValue();
        activity.getTheme().resolveAttribute(i, typedValue, true);
        return typedValue.resourceId;
    }

    protected void onDestroy() {
        ContactsAdapter contactsAdapter;
        super.onDestroy();
        if (this.mListView == null || (contactsAdapter = this.mAdapter) == null || contactsAdapter.mAsyncTaskThreadPool == null) {
            return;
        }
        this.mAdapter.mAsyncTaskThreadPool.cancelAllTasks(true);
    }

    public void displaySchoolsList() {
        this.mSchoolsListDup.clear();
        this.mSchoolsListDup.addAll(this.mSchoolsList);
        Collections.sort(this.mSchoolsList, new Comparator<Result>() {
            @Override
            public int compare(Result result, Result result2) {
                int upperCase = Character.toUpperCase(TextUtils.isEmpty(result.getSchoolName()) ? ' ' : result.getSchoolName().charAt(0)) - Character.toUpperCase(TextUtils.isEmpty(result2.getSchoolName()) ? ' ' : result2.getSchoolName().charAt(0));
                return upperCase == 0 ? result.getSchoolName().compareTo(result2.getSchoolName()) : upperCase;
            }
        });
        this.mAdapter = new ContactsAdapter(this, this.mSchoolsList);
        this.mAdapter.setPinnedHeaderBackgroundColor(getResources().getColor(getResIdFromAttribute(this, android.R.attr.colorBackground)));
        this.mAdapter.setPinnedHeaderTextColor(getResources().getColor(R.color.pinned_header_text));
        ViewGroup viewGroup = this.mListView;
        viewGroup.setPinnedHeaderView(this.mInflater.inflate(R.layout.pinned_header_listview_side_header, viewGroup, false));
        this.mListView.setAdapter(this.mAdapter);
        this.mListView.setOnScrollListener(this.mAdapter);
        this.mListView.setEnableHeaderTransparencyChanges(false);
    }

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long j) {
        Result result = this.mSchoolsList.get(i);
        String schoolName = result.getSchoolName();
        result.getAppName();
        result.getAppLogoUrl();
        String valueOf = String.valueOf("" + result.getOrganisationID());
        final String appPlayStoreUrl = result.getAppPlayStoreUrl();
        String webServiceUrl = result.getWebServiceUrl();
        String apiUrl = result.getApiUrl();
        if (appPlayStoreUrl != null && appPlayStoreUrl.length() > 0 && !appPlayStoreUrl.equalsIgnoreCase("null")) {
            AlertDialog.Builder positiveButton = new AlertDialog.Builder(this).setMessage(Html.fromHtml("Already <font color='#009688'><b>" + schoolName + "</b></font> has Android App. Do you want download from play store?")).setCancelable(false).setPositiveButton("YES", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i2) {
                    SchoolSelectionActivity.this.startActivity(new Intent("android.intent.action.VIEW", Uri.parse(appPlayStoreUrl)));
                    SchoolSelectionActivity.this.finish();
                    dialogInterface.cancel();
                }
            });
            positiveButton.setNegativeButton("NO", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i2) {
                    dialogInterface.cancel();
                }
            });
            positiveButton.show();
            return;
        }
        if (webServiceUrl == null || webServiceUrl.length() <= 0 || webServiceUrl.equalsIgnoreCase("null") || !webServiceUrl.contains("//") || !webServiceUrl.contains(".")) {
            return;
        }
        String substring = webServiceUrl.substring(webServiceUrl.indexOf("//") + 2, webServiceUrl.indexOf("."));
        if (apiUrl != null && apiUrl.length() > 0 && !apiUrl.equalsIgnoreCase("null") && apiUrl.contains("//") && apiUrl.contains(".")) {
            this.mEditor.putString("schoolApiUrlKey", apiUrl.substring(apiUrl.indexOf("//") + 2, apiUrl.indexOf(".")));
        }
        this.mEditor.putString("schoolNameURLkey", substring);
        this.mEditor.putString("schoolNameKey", schoolName);
        this.mEditor.putString("schoolServiceURLKey", webServiceUrl);
        this.mEditor.putString("OrganisationId", valueOf);
        this.mEditor.commit();
        startActivity(new Intent(getApplicationContext(), (Class<?>) LoginActivity.class));
        finish();
    }

    public boolean onQueryTextChange(String str) {
        if (str.length() > 2) {
            ArrayList arrayList = new ArrayList();
            for (int i = 0; i < this.mSchoolsListDup.size(); i++) {
                Result result = this.mSchoolsListDup.get(i);
                if (result.getSchoolName().toLowerCase().contains(str.toLowerCase())) {
                    arrayList.add(result);
                }
            }
            this.mSchoolsList.clear();
            this.mSchoolsList.addAll(arrayList);
            addDataToView();
        } else {
            this.mSchoolsList.clear();
            this.mSchoolsList.addAll(this.mSchoolsListDup);
            this.mListView.setVisibility(8);
            this.mNoData.setVisibility(0);
            this.mNoData.setText("Please enter your ward's school name in the search box above.");
        }
        return false;
    }

    private void addDataToView() {
        if (this.mSchoolsList.size() > 0) {
            this.mListView.setVisibility(0);
            this.mNoData.setVisibility(8);
            Collections.sort(this.mSchoolsList, new Comparator<Result>() {
                @Override
                public int compare(Result result, Result result2) {
                    int upperCase = Character.toUpperCase(TextUtils.isEmpty(result.getSchoolName()) ? ' ' : result.getSchoolName().charAt(0)) - Character.toUpperCase(TextUtils.isEmpty(result2.getSchoolName()) ? ' ' : result2.getSchoolName().charAt(0));
                    return upperCase == 0 ? result.getSchoolName().compareTo(result2.getSchoolName()) : upperCase;
                }
            });
            this.mAdapter = new ContactsAdapter(this, this.mSchoolsList);
            this.mAdapter.setPinnedHeaderBackgroundColor(getResources().getColor(getResIdFromAttribute(this, android.R.attr.colorBackground)));
            this.mAdapter.setPinnedHeaderTextColor(getResources().getColor(R.color.pinned_header_text));
            ViewGroup viewGroup = this.mListView;
            viewGroup.setPinnedHeaderView(this.mInflater.inflate(R.layout.pinned_header_listview_side_header, viewGroup, false));
            this.mListView.setAdapter(this.mAdapter);
            this.mListView.setOnScrollListener(this.mAdapter);
            this.mListView.setEnableHeaderTransparencyChanges(false);
            return;
        }
        this.mListView.setVisibility(8);
        this.mNoData.setVisibility(0);
        this.mNoData.setText("School not found");
    }

    private class ContactsAdapter extends SearchablePinnedHeaderListViewAdapter<Result> {
        private final AsyncTaskThreadPool mAsyncTaskThreadPool = new AsyncTaskThreadPool(1, 2, 10);
        Context mContext;
        private ArrayList<Result> mSchools;

        public CharSequence getSectionTitle(int i) {
            return ((StringArrayAlphabetIndexer.AlphaBetSection) getSections()[i]).getName();
        }

        public ContactsAdapter(Context context, ArrayList<Result> arrayList) {
            this.mContext = context;
            setData(arrayList);
        }

        public void setData(ArrayList<Result> arrayList) {
            this.mSchools = arrayList;
            setSectionIndexer(new StringArrayAlphabetIndexer(generateContactNames(arrayList), true));
        }

        private String[] generateContactNames(List<Result> list) {
            ArrayList arrayList = new ArrayList();
            if (list != null) {
                Iterator<Result> it = list.iterator();
                while (it.hasNext()) {
                    arrayList.add(it.next().getSchoolName());
                }
            }
            return (String[]) arrayList.toArray(new String[arrayList.size()]);
        }

        public View getView(int i, View view, ViewGroup viewGroup) {
            View view2;
            ViewHolder viewHolder;
            if (view == null) {
                viewHolder = new ViewHolder();
                view2 = SchoolSelectionActivity.this.mInflater.inflate(R.layout.listview_item, viewGroup, false);
                viewHolder.friendProfileCircularContactView = (ImageView) view2.findViewById(R.id.school_imageview_listitem);
                viewHolder.friendName = (TextView) view2.findViewById(R.id.school_name);
                viewHolder.headerView = (TextView) view2.findViewById(R.id.header_text);
                viewHolder.mStarImg = (ImageView) view2.findViewById(R.id.star_imageview_listitem);
                view2.setTag(viewHolder);
            } else {
                view2 = view;
                viewHolder = (ViewHolder) view.getTag();
            }
            Result result = (Result) getItem(i);
            viewHolder.friendName.setText(result.getSchoolName());
            String appLogoUrl = result.getAppLogoUrl();
            if (appLogoUrl != null) {
                try {
                    if (appLogoUrl.length() > 0 && !appLogoUrl.equalsIgnoreCase("null")) {
                        Picasso.get().load(appLogoUrl).into(viewHolder.friendProfileCircularContactView);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            String appPlayStoreUrl = result.getAppPlayStoreUrl();
            if (appPlayStoreUrl != null && appPlayStoreUrl.length() > 0 && !appPlayStoreUrl.equalsIgnoreCase("null")) {
                viewHolder.mStarImg.setVisibility(0);
            } else {
                viewHolder.mStarImg.setVisibility(8);
            }
            bindSectionHeader(viewHolder.headerView, null, i);
            return view2;
        }

        public boolean doFilter(Result result, CharSequence charSequence) {
            if (TextUtils.isEmpty(charSequence)) {
                return true;
            }
            String schoolName = result.getSchoolName();
            return !TextUtils.isEmpty(schoolName) && schoolName.toLowerCase(Locale.getDefault()).contains(charSequence.toString().toLowerCase(Locale.getDefault()));
        }

        public ArrayList<Result> getOriginalList() {
            return this.mSchools;
        }
    }

    private static class ViewHolder {
        TextView friendName;
        public ImageView friendProfileCircularContactView;
        TextView headerView;
        public ImageView mStarImg;
        public AsyncTaskEx<Void, Void, Bitmap> updateTask;

        private ViewHolder() {
        }
    }

    private void loadSchoolsData() {
        ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService("connectivity");
        this.conMgr = connectivityManager;
        if (connectivityManager.getActiveNetworkInfo() != null && this.conMgr.getActiveNetworkInfo().isAvailable() && this.conMgr.getActiveNetworkInfo().isConnected()) {
            new SchoolListHttpGetRequest().execute(this.SERVICE_URL);
        } else {
            Toast.makeText(getApplicationContext(), "Check your Network Connection", 0).show();
        }
    }

    public class SchoolListHttpGetRequest extends AsyncTask<String, Void, String> {
        public static final int CONNECTION_TIMEOUT = 15000;
        public static final int READ_TIMEOUT = 15000;
        public static final String REQUEST_METHOD = "GET";

        public SchoolListHttpGetRequest() {
        }

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            SchoolSelectionActivity.this.mProgressbar.show();
        }

        @Override
        public String doInBackground(String... strArr) {
            try {
                HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(strArr[0]).openConnection();
                httpURLConnection.setRequestMethod(REQUEST_METHOD);
                httpURLConnection.setReadTimeout(15000);
                httpURLConnection.setConnectTimeout(15000);
                httpURLConnection.setRequestProperty("apikey", "cec596b4528b5016ee9b46a678a68e28");
                httpURLConnection.connect();
                InputStreamReader inputStreamReader = new InputStreamReader(httpURLConnection.getInputStream());
                BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
                StringBuilder sb = new StringBuilder();
                while (true) {
                    String readLine = bufferedReader.readLine();
                    if (readLine != null) {
                        sb.append(readLine);
                    } else {
                        bufferedReader.close();
                        inputStreamReader.close();
                        return sb.toString();
                    }
                }
            } catch (IOException e) {
                e.printStackTrace();
                return null;
            }
        }

        @Override
        public void onPostExecute(String str) {
            if (SchoolSelectionActivity.this.mProgressbar != null && SchoolSelectionActivity.this.mProgressbar.isShowing()) {
                SchoolSelectionActivity.this.mProgressbar.dismiss();
            }
            try {
                SchoolListModel schoolListModel = (SchoolListModel) new Gson().fromJson(str, new TypeToken<SchoolListModel>() {
                }.getType());
                SchoolSelectionActivity.this.mSchoolsList = schoolListModel.getResults();
                SchoolSelectionActivity.this.displaySchoolsList();
            } catch (Exception e) {
                e.printStackTrace();
            }
            super.onPostExecute((SchoolListHttpGetRequest) str);
        }
    }

    protected void onResume() {
        super.onResume();
        String string = this.mSharedPref.getString("usernamekey", "");
        Bundle bundle = new Bundle();
        bundle.putString("user_name", string);
        FirebaseAnalytics.getInstance(this).logEvent("PAGE_SCHOOL_SELECTION", bundle);
    }

    protected void onStop() {
        TransparentProgressDialog transparentProgressDialog = this.mProgressbar;
        if (transparentProgressDialog != null && transparentProgressDialog.isShowing()) {
            this.mProgressbar.dismiss();
        }
        super.onStop();
    }
}