导航菜单

页面标题

页面副标题

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

正在查看: St.John's v1.0.9 应用的 LearningTopicNoteActivity.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.os.Bundle;
import android.view.ContextThemeWrapper;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import com.google.firebase.analytics.FirebaseAnalytics;
import com.mcb.stjohnsemschool.adapter.LearningNotesAdapter;
import com.mcb.stjohnsemschool.interfaces.EditDeleteNote;
import com.mcb.stjohnsemschool.model.LearningNoteModel;
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 java.util.ArrayList;
import java.util.HashMap;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class LearningTopicNoteActivity extends AppCompatActivity implements EditDeleteNote {
    private Activity activity;
    private int chapterId;
    private Context context;
    private EditDeleteNote editDeleteNote;
    private TextView mNoDataFoundTv;
    private ListView mNotes;
    private TransparentProgressDialog mProgressbar;
    private SharedPreferences mSharedPref;
    private int topicId;
    private String topicName = "";
    private String studentEnrollmentId = "0";
    private String subjectGUID = "";

    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.activity_learning_topic_note);
        this.activity = this;
        this.context = getApplicationContext();
        this.editDeleteNote = this;
        this.mProgressbar = new TransparentProgressDialog(this.activity, R.drawable.spinner_loading_imag);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setDisplayShowTitleEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);
        setUpIds();
    }

    private void setUpIds() {
        SharedPreferences sharedPreferences = this.context.getSharedPreferences("", 0);
        this.mSharedPref = sharedPreferences;
        this.studentEnrollmentId = sharedPreferences.getString("studentEnrollmentIdKey", this.studentEnrollmentId);
        Bundle extras = getIntent().getExtras();
        this.topicId = extras.getInt("TopicId", 0);
        this.topicName = extras.getString("TopicName", getResources().getString(2131886124));
        this.subjectGUID = extras.getString("SubjectGUID", "");
        this.chapterId = extras.getInt("ChapterId", 0);
        getSupportActionBar().setTitle("Notes");
        getSupportActionBar().setSubtitle(this.topicName);
        this.mNotes = (ListView) findViewById(R.id.lst_notes);
        this.mNoDataFoundTv = (TextView) findViewById(R.id.noDataTv);
        this.mNotes.setDividerHeight(0);
        this.mNotes.setVisibility(8);
        this.mNoDataFoundTv.setVisibility(8);
    }

    public void editDeleteNote(int i, String str) {
        if (str == null || str.isEmpty()) {
            if (!Utility.hasNetworkConnection(this.context)) {
                Toast.makeText(this.context, "Check your Network Connection", 0).show();
                return;
            } else {
                deleteLearningNotes(i);
                return;
            }
        }
        if (!Utility.hasNetworkConnection(this.context)) {
            Toast.makeText(this.context, "Check your Network Connection", 0).show();
        } else {
            saveLearningNotes(i, str);
        }
    }

    public void getLearningNotes() {
        TransparentProgressDialog transparentProgressDialog = this.mProgressbar;
        if (transparentProgressDialog != null && !transparentProgressDialog.isShowing()) {
            this.mProgressbar.show();
        }
        ((ApiInterface) ApiClient.getClient1(this.context).create(ApiInterface.class)).GetLearningNotes(Integer.parseInt(this.studentEnrollmentId), this.topicId, Utility.getSchoolApiKey(this.context)).enqueue(new Callback<ArrayList<LearningNoteModel>>() {
            public void onResponse(Call<ArrayList<LearningNoteModel>> call, Response<ArrayList<LearningNoteModel>> response) {
                if (response == null || response.body() == null) {
                    if (LearningTopicNoteActivity.this.mProgressbar != null && LearningTopicNoteActivity.this.mProgressbar.isShowing()) {
                        LearningTopicNoteActivity.this.mProgressbar.dismiss();
                    }
                    Utility.showAlertDialog(LearningTopicNoteActivity.this.activity);
                    return;
                }
                ArrayList arrayList = (ArrayList) response.body();
                if (arrayList.size() <= 0) {
                    LearningTopicNoteActivity.this.mNotes.setVisibility(8);
                    LearningTopicNoteActivity.this.mNoDataFoundTv.setVisibility(0);
                } else {
                    LearningTopicNoteActivity.this.mNotes.setAdapter(new LearningNotesAdapter(LearningTopicNoteActivity.this.context, LearningTopicNoteActivity.this.activity, arrayList, LearningTopicNoteActivity.this.editDeleteNote, LearningTopicNoteActivity.this.subjectGUID, LearningTopicNoteActivity.this.chapterId, LearningTopicNoteActivity.this.topicId));
                    LearningTopicNoteActivity.this.mNotes.setVisibility(0);
                    LearningTopicNoteActivity.this.mNoDataFoundTv.setVisibility(8);
                }
                if (LearningTopicNoteActivity.this.mProgressbar == null || !LearningTopicNoteActivity.this.mProgressbar.isShowing()) {
                    return;
                }
                LearningTopicNoteActivity.this.mProgressbar.dismiss();
            }

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

    private void saveLearningNotes(int i, String str) {
        TransparentProgressDialog transparentProgressDialog = this.mProgressbar;
        if (transparentProgressDialog != null && !transparentProgressDialog.isShowing()) {
            this.mProgressbar.show();
        }
        HashMap hashMap = new HashMap();
        hashMap.put("StudentEnrollmentID", this.studentEnrollmentId);
        hashMap.put("SubjectGUID", this.subjectGUID);
        hashMap.put("SubjectSyllabusID", String.valueOf(this.chapterId));
        hashMap.put("TopicID", String.valueOf(this.topicId));
        hashMap.put("Note", str);
        hashMap.put("noteID", String.valueOf(i));
        hashMap.put("apikey", Utility.getSchoolApiKey(this.context));
        ((ApiInterface) ApiClient.getClient1(getApplicationContext()).create(ApiInterface.class)).SaveLearningNotes(hashMap).enqueue(new Callback<String>() {
            public void onResponse(Call<String> call, Response<String> response) {
                if (LearningTopicNoteActivity.this.mProgressbar != null && LearningTopicNoteActivity.this.mProgressbar.isShowing()) {
                    LearningTopicNoteActivity.this.mProgressbar.dismiss();
                }
                if (response == null || response.body() == null) {
                    Utility.showAlertDialog(LearningTopicNoteActivity.this.activity);
                    return;
                }
                String str2 = (String) response.body();
                AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper((Context) LearningTopicNoteActivity.this, R.style.MyDialogTheme));
                builder.setMessage(str2);
                builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i2) {
                        dialogInterface.dismiss();
                        if (Utility.hasNetworkConnection(LearningTopicNoteActivity.this.context)) {
                            LearningTopicNoteActivity.this.getLearningNotes();
                        } else {
                            Toast.makeText(LearningTopicNoteActivity.this.context, "Check your Network Connection", 0).show();
                        }
                    }
                });
                builder.show();
            }

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

    private void deleteLearningNotes(int i) {
        TransparentProgressDialog transparentProgressDialog = this.mProgressbar;
        if (transparentProgressDialog != null && !transparentProgressDialog.isShowing()) {
            this.mProgressbar.show();
        }
        HashMap hashMap = new HashMap();
        hashMap.put("NoteID", String.valueOf(i));
        hashMap.put("apikey", Utility.getSchoolApiKey(this.context));
        ((ApiInterface) ApiClient.getClient1(getApplicationContext()).create(ApiInterface.class)).DeleteLearningNotes(hashMap).enqueue(new Callback<String>() {
            public void onResponse(Call<String> call, Response<String> response) {
                if (LearningTopicNoteActivity.this.mProgressbar != null && LearningTopicNoteActivity.this.mProgressbar.isShowing()) {
                    LearningTopicNoteActivity.this.mProgressbar.dismiss();
                }
                if (response == null || response.body() == null) {
                    Utility.showAlertDialog(LearningTopicNoteActivity.this.activity);
                    return;
                }
                String str = (String) response.body();
                AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper((Context) LearningTopicNoteActivity.this, R.style.MyDialogTheme));
                builder.setMessage(str);
                builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i2) {
                        dialogInterface.dismiss();
                        if (Utility.hasNetworkConnection(LearningTopicNoteActivity.this.context)) {
                            LearningTopicNoteActivity.this.getLearningNotes();
                        } else {
                            Toast.makeText(LearningTopicNoteActivity.this.context, "Check your Network Connection", 0).show();
                        }
                    }
                });
                builder.show();
            }

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

    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_create, menu);
        return super.onCreateOptionsMenu(menu);
    }

    public boolean onOptionsItemSelected(MenuItem menuItem) {
        int itemId = menuItem.getItemId();
        if (itemId == 16908332) {
            finish();
            return true;
        }
        if (itemId == 2131362208) {
            Intent intent = new Intent(getApplicationContext(), (Class<?>) EditLearningNoteActivity.class);
            intent.addFlags(268435456);
            intent.putExtra("noteId", 0);
            intent.putExtra("note", "");
            intent.putExtra("subjectGUID", this.subjectGUID);
            intent.putExtra("chapterId", this.chapterId);
            intent.putExtra("topicId", this.topicId);
            intent.putExtra("title", "Create Note");
            startActivity(intent);
            return true;
        }
        return super.onOptionsItemSelected(menuItem);
    }

    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_NOTES", bundle);
        if (Utility.hasNetworkConnection(this.context)) {
            getLearningNotes();
        } else {
            Toast.makeText(this.context, "Check your Network Connection", 0).show();
        }
    }
}