导航菜单

页面标题

页面副标题

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

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

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


package com.mcb.stjohnsemschool.activity;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.text.Html;
import android.util.Base64;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.google.android.exoplayer2.C;
import com.google.firebase.analytics.FirebaseAnalytics;
import com.mcb.stjohnsemschool.model.LearningAssessmentQuestionWiseResultModelClass;
import com.mcb.stjohnsemschool.services.ApiClient;
import com.mcb.stjohnsemschool.services.ApiInterface;
import com.mcb.stjohnsemschool.utils.TransparentProgressDialog;
import com.mcb.stjohnsemschool.utils.Utility;
import com.squareup.picasso.Picasso;
import java.io.UnsupportedEncodingException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Iterator;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class LearningAssessmentResultActivity extends AppCompatActivity {
    private static final String TAG = "com.mcb.stjohnsemschool.activity.LearningAssessmentResultActivity";
    private Activity activity;
    private int chapterId;
    private Context context;
    private LinearLayout mAnswersLL;
    private LinearLayout mMainLL;
    private TextView mNoData;
    private TextView mPercentage;
    private TransparentProgressDialog mProgressbar;
    private TextView mScore;
    private int topicId;
    private String studentEnrollmentId = "0";
    private String academicYearId = "0";
    private String userId = "0";
    private String organizationId = "0";
    private String classId = "0";
    private String topicName = "";
    private String subject = "";
    private String subjectGUID = "";

    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.activity_learning_assessment_result);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        this.activity = this;
        this.context = getApplicationContext();
        this.mProgressbar = new TransparentProgressDialog(this, R.drawable.spinner_loading_imag);
        SharedPreferences sharedPreferences = this.context.getSharedPreferences("", 0);
        this.studentEnrollmentId = sharedPreferences.getString("studentEnrollmentIdKey", this.studentEnrollmentId);
        this.userId = sharedPreferences.getString("UseridKey", this.userId);
        this.academicYearId = sharedPreferences.getString("academicyearIdKey", this.academicYearId);
        this.organizationId = sharedPreferences.getString("orgnizationIdKey", "0");
        this.classId = sharedPreferences.getString("ClassidKey", "0");
        Bundle extras = getIntent().getExtras();
        this.chapterId = extras.getInt("ChapterId", 0);
        this.subject = extras.getString("SubjectName", "");
        this.subjectGUID = extras.getString("SubjectGUID", "");
        this.topicId = extras.getInt("TopicId", 0);
        this.topicName = extras.getString("TopicName", "");
        getSupportActionBar().setTitle(this.topicName);
        getSupportActionBar().setSubtitle("Results");
        initializations();
    }

    private void initializations() {
        this.mMainLL = (LinearLayout) findViewById(R.id.ll_main);
        this.mNoData = (TextView) findViewById(R.id.txv_no_data);
        this.mScore = (TextView) findViewById(R.id.txv_score);
        this.mPercentage = (TextView) findViewById(R.id.txv_percentage);
        this.mAnswersLL = (LinearLayout) findViewById(R.id.ll_answers);
        this.mMainLL.setVisibility(8);
        this.mNoData.setVisibility(8);
        getStudentOnlineExaminationsAnswers();
    }

    public boolean onOptionsItemSelected(MenuItem menuItem) {
        if (menuItem.getItemId() == 16908332) {
            finish();
        }
        return super.onOptionsItemSelected(menuItem);
    }

    private void getStudentOnlineExaminationsAnswers() {
        ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService("connectivity");
        if (connectivityManager.getActiveNetworkInfo() != null && connectivityManager.getActiveNetworkInfo().isAvailable() && connectivityManager.getActiveNetworkInfo().isConnected()) {
            getTopicExerciseAnswers();
        } else {
            Toast.makeText(this.context, "Check your Network Connection", 0).show();
        }
    }

    private void getTopicExerciseAnswers() {
        TransparentProgressDialog transparentProgressDialog = this.mProgressbar;
        if (transparentProgressDialog != null && !transparentProgressDialog.isShowing()) {
            this.mProgressbar.show();
        }
        ((ApiInterface) ApiClient.getClient1(this.context).create(ApiInterface.class)).GetTopicExerciseAnswers(Integer.parseInt(this.organizationId), Integer.parseInt(this.classId), this.chapterId, this.topicId, this.subjectGUID, Integer.parseInt(this.studentEnrollmentId), Utility.getSchoolApiKey(this.context)).enqueue(new Callback<ArrayList<LearningAssessmentQuestionWiseResultModelClass>>() {
            public void onResponse(Call<ArrayList<LearningAssessmentQuestionWiseResultModelClass>> call, Response<ArrayList<LearningAssessmentQuestionWiseResultModelClass>> response) {
                if (LearningAssessmentResultActivity.this.mProgressbar != null && LearningAssessmentResultActivity.this.mProgressbar.isShowing()) {
                    LearningAssessmentResultActivity.this.mProgressbar.dismiss();
                }
                if (response == null || response.body() == null) {
                    Utility.showAlertDialog(LearningAssessmentResultActivity.this.activity);
                    return;
                }
                new ArrayList();
                ArrayList arrayList = (ArrayList) response.body();
                if (arrayList == null || arrayList.size() <= 0) {
                    LearningAssessmentResultActivity.this.mMainLL.setVisibility(8);
                    LearningAssessmentResultActivity.this.mNoData.setVisibility(0);
                    return;
                }
                int size = arrayList.size();
                Iterator it = arrayList.iterator();
                double d = 0.0d;
                while (it.hasNext()) {
                    LearningAssessmentQuestionWiseResultModelClass learningAssessmentQuestionWiseResultModelClass = (LearningAssessmentQuestionWiseResultModelClass) it.next();
                    if (learningAssessmentQuestionWiseResultModelClass.getGivenAnswer() != null && learningAssessmentQuestionWiseResultModelClass.getGivenAnswer().length() > 0 && !learningAssessmentQuestionWiseResultModelClass.getGivenAnswer().equalsIgnoreCase("null") && learningAssessmentQuestionWiseResultModelClass.getGivenAnswer().equalsIgnoreCase(learningAssessmentQuestionWiseResultModelClass.getAnswerNo())) {
                        d += learningAssessmentQuestionWiseResultModelClass.getMarks();
                        learningAssessmentQuestionWiseResultModelClass.setCorrectAnswer(true);
                    }
                }
                double d2 = (d / size) * 100.0d;
                LearningAssessmentResultActivity.this.mScore.setText("Your Score: " + new DecimalFormat("##.##").format(d) + "/" + size);
                LearningAssessmentResultActivity.this.mPercentage.setText("Percentage: " + new DecimalFormat("##.##").format(d2) + "%");
                LearningAssessmentResultActivity.this.createAnswersUI(arrayList);
                LearningAssessmentResultActivity.this.mMainLL.setVisibility(0);
                LearningAssessmentResultActivity.this.mNoData.setVisibility(8);
            }

            public void onFailure(Call<ArrayList<LearningAssessmentQuestionWiseResultModelClass>> call, Throwable th) {
                if (LearningAssessmentResultActivity.this.mProgressbar != null && LearningAssessmentResultActivity.this.mProgressbar.isShowing()) {
                    LearningAssessmentResultActivity.this.mProgressbar.dismiss();
                }
                Utility.showAlertDialog(LearningAssessmentResultActivity.this.activity);
            }
        });
    }

    public void createAnswersUI(ArrayList<LearningAssessmentQuestionWiseResultModelClass> arrayList) {
        String str;
        this.mAnswersLL.removeAllViews();
        Iterator<LearningAssessmentQuestionWiseResultModelClass> it = arrayList.iterator();
        int i = 1;
        while (it.hasNext()) {
            LearningAssessmentQuestionWiseResultModelClass next = it.next();
            LinearLayout linearLayout = (LinearLayout) LayoutInflater.from(this.context).inflate(R.layout.ll_assessment_question_with_answer, (ViewGroup) null);
            ImageView imageView = (ImageView) linearLayout.findViewById(R.id.img_question);
            TextView textView = (TextView) linearLayout.findViewById(R.id.txv_question_no);
            WebView webView = (WebView) linearLayout.findViewById(R.id.txv_question);
            TextView textView2 = (TextView) linearLayout.findViewById(R.id.txv_given_ans);
            TextView textView3 = (TextView) linearLayout.findViewById(R.id.txv_correct_ans);
            TextView textView4 = (TextView) linearLayout.findViewById(R.id.txv_explanation);
            webView.setScrollBarStyle(33554432);
            webView.setScrollbarFadingEnabled(false);
            webView.setVerticalScrollBarEnabled(true);
            webView.setHorizontalScrollBarEnabled(true);
            textView.setText(i + ".");
            if (next.getQuestionImage() != null && next.getQuestionImage().length() > 0 && !next.getQuestionImage().equalsIgnoreCase(null)) {
                imageView.setVisibility(0);
                Picasso.get().load(next.getQuestionImage()).into(imageView);
            } else {
                try {
                    webView.loadData(Base64.encodeToString(next.getQuestionText().getBytes(C.UTF8_NAME), 0), "text/html; charset=utf-8", "base64");
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
                webView.setVisibility(0);
            }
            textView2.setCompoundDrawablesWithIntrinsicBounds(next.isCorrectAnswer() ? R.drawable.ic_action_right : R.drawable.ic_action_wrong, 0, 0, 0);
            if (next.getGivenAnswer() != null && next.getGivenAnswer().length() > 0 && !next.getGivenAnswer().equalsIgnoreCase("null")) {
                str = next.getGivenAnswer();
            } else {
                str = "Not Given";
            }
            textView2.setText("Given Answer : " + str);
            textView3.setText("Correct Answer : " + next.getAnswerNo());
            if (next.getExplanation() != null && next.getExplanation().length() > 0 && !next.getExplanation().equalsIgnoreCase("null")) {
                textView4.setText("Explanation : " + ((Object) Html.fromHtml(next.getExplanation())));
                textView4.setVisibility(0);
            } else {
                textView4.setVisibility(8);
            }
            this.mAnswersLL.addView(linearLayout);
            i++;
        }
    }

    TextView getElementTextView(LearningAssessmentQuestionWiseResultModelClass learningAssessmentQuestionWiseResultModelClass, int i) {
        TextView textView = new TextView(this);
        textView.setLayoutParams(new TableRow.LayoutParams(0, -1, 1.0f));
        textView.setText("Q" + (i + 1) + ". (" + learningAssessmentQuestionWiseResultModelClass.getGivenAnswer() + "/" + learningAssessmentQuestionWiseResultModelClass.getAnswerNo() + ")");
        textView.setTextSize(20.0f);
        textView.setTextColor(-16777216);
        textView.setGravity(3);
        textView.setCompoundDrawablesWithIntrinsicBounds(learningAssessmentQuestionWiseResultModelClass.isCorrectAnswer() ? R.drawable.ic_action_right : R.drawable.ic_action_wrong, 0, 0, 0);
        return textView;
    }

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

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