导航菜单

页面标题

页面副标题

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

正在查看: St.John's v1.0.9 应用的 EditLearningNoteActivity.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.view.View;
import android.view.ViewTreeObserver;
import android.widget.ImageView;
import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import com.chinalwb.are.AREditText;
import com.chinalwb.are.spans.AreImageSpan;
import com.chinalwb.are.strategies.ImageStrategy;
import com.chinalwb.are.styles.toolbar.ARE_ToolbarDefault;
import com.chinalwb.are.styles.toolbar.IARE_Toolbar;
import com.chinalwb.are.styles.toolitems.ARE_ToolItem_Image;
import com.chinalwb.are.styles.toolitems.styles.ARE_Style_Image;
import com.google.android.exoplayer2.C;
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.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class EditLearningNoteActivity extends AppCompatActivity {
    private Activity activity;
    private int chapterId;
    private String editNoteStr;
    private ARE_ToolItem_Image insertImageView;
    private AREditText mDescription;
    private TransparentProgressDialog mProgressbar;
    private SharedPreferences mSharedPref;
    private IARE_Toolbar mToolbar;
    private int noteId;
    private boolean scrollerAtEnd;
    private String studentEnrollmentId = "0";
    private String subjectGUID = "";
    private int topicId;

    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.activity_edit_learning_note);
        getWindow().addFlags(128);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setDisplayShowTitleEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);
        this.activity = this;
        setupIds();
    }

    private void setupIds() {
        Intent intent = getIntent();
        this.subjectGUID = intent.getStringExtra("subjectGUID");
        this.chapterId = intent.getIntExtra("chapterId", 0);
        this.topicId = intent.getIntExtra("topicId", 0);
        this.noteId = intent.getIntExtra("noteId", 0);
        this.editNoteStr = intent.getStringExtra("note");
        getSupportActionBar().setTitle(intent.getStringExtra("title"));
        this.mProgressbar = new TransparentProgressDialog(this, R.drawable.spinner_loading_imag);
        SharedPreferences sharedPreferences = getSharedPreferences("", 0);
        this.mSharedPref = sharedPreferences;
        this.studentEnrollmentId = sharedPreferences.getString("studentEnrollmentIdKey", this.studentEnrollmentId);
        this.mDescription = findViewById(R.id.edt_description);
        IARE_Toolbar findViewById = findViewById(R.id.areToolbar);
        this.mToolbar = findViewById;
        this.insertImageView = Utility.initToolbar(findViewById, this.mDescription, false);
        initToolbarArrow();
        this.mDescription.fromHtml(this.editNoteStr);
    }

    private void initToolbarArrow() {
        final ImageView imageView = (ImageView) findViewById(R.id.arrow);
        ARE_ToolbarDefault aRE_ToolbarDefault = this.mToolbar;
        if (aRE_ToolbarDefault instanceof ARE_ToolbarDefault) {
            aRE_ToolbarDefault.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
                @Override
                public void onScrollChanged() {
                    if (EditLearningNoteActivity.this.mToolbar.getScrollX() + EditLearningNoteActivity.this.mToolbar.getWidth() < EditLearningNoteActivity.this.mToolbar.getChildAt(0).getWidth()) {
                        imageView.setImageResource(R.drawable.arrow_right);
                        EditLearningNoteActivity.this.scrollerAtEnd = false;
                    } else {
                        imageView.setImageResource(R.drawable.arrow_left);
                        EditLearningNoteActivity.this.scrollerAtEnd = true;
                    }
                }
            });
        }
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (EditLearningNoteActivity.this.scrollerAtEnd) {
                    EditLearningNoteActivity.this.mToolbar.smoothScrollBy(-2147483647, 0);
                    EditLearningNoteActivity.this.scrollerAtEnd = false;
                } else {
                    EditLearningNoteActivity.this.mToolbar.smoothScrollBy(EditLearningNoteActivity.this.mToolbar.getChildAt(0).getWidth(), 0);
                    EditLearningNoteActivity.this.scrollerAtEnd = true;
                }
            }
        });
    }

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

    public boolean onOptionsItemSelected(MenuItem menuItem) {
        int itemId = menuItem.getItemId();
        if (itemId == 16908332) {
            finish();
            return true;
        }
        if (itemId == 2131361885) {
            String html = this.mDescription.getHtml();
            if (html == null || html.isEmpty()) {
                if (!Utility.hasNetworkConnection(getApplicationContext())) {
                    Toast.makeText(getApplicationContext(), "Check your Network Connection", 0).show();
                } else {
                    deleteLearningNotes(this.noteId);
                }
            } else if (!Utility.hasNetworkConnection(getApplicationContext())) {
                Toast.makeText(getApplicationContext(), "Check your Network Connection", 0).show();
            } else {
                saveLearningNotes(this.noteId, html);
            }
            return true;
        }
        return super.onOptionsItemSelected(menuItem);
    }

    private void saveLearningNotes(int i, String str) {
        TransparentProgressDialog transparentProgressDialog = this.mProgressbar;
        if (transparentProgressDialog != null && !transparentProgressDialog.isShowing()) {
            this.mProgressbar.show();
        }
        try {
            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", URLEncoder.encode(str, C.UTF8_NAME));
            hashMap.put("noteID", String.valueOf(i));
            hashMap.put("apikey", Utility.getSchoolApiKey(this));
            ((ApiInterface) ApiClient.getClient1(getApplicationContext()).create(ApiInterface.class)).SaveLearningNotes(hashMap).enqueue(new Callback<String>() {
                public void onResponse(Call<String> call, Response<String> response) {
                    if (EditLearningNoteActivity.this.mProgressbar != null && EditLearningNoteActivity.this.mProgressbar.isShowing()) {
                        EditLearningNoteActivity.this.mProgressbar.dismiss();
                    }
                    if (response == null || response.body() == null) {
                        Utility.showAlertDialog(EditLearningNoteActivity.this.activity);
                        return;
                    }
                    String str2 = (String) response.body();
                    AlertDialog.Builder builder = new AlertDialog.Builder(EditLearningNoteActivity.this.activity);
                    builder.setMessage(str2);
                    builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i2) {
                            dialogInterface.dismiss();
                            EditLearningNoteActivity.this.finish();
                        }
                    });
                    builder.show();
                }

                public void onFailure(Call<String> call, Throwable th) {
                    if (EditLearningNoteActivity.this.mProgressbar != null && EditLearningNoteActivity.this.mProgressbar.isShowing()) {
                        EditLearningNoteActivity.this.mProgressbar.dismiss();
                    }
                    Utility.showAlertDialog(EditLearningNoteActivity.this.activity);
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
            Toast.makeText(getApplicationContext(), "Unable to get Server Response", 0).show();
            TransparentProgressDialog transparentProgressDialog2 = this.mProgressbar;
            if (transparentProgressDialog2 == null || !transparentProgressDialog2.isShowing()) {
                return;
            }
            this.mProgressbar.dismiss();
        }
    }

    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));
        ((ApiInterface) ApiClient.getClient1(getApplicationContext()).create(ApiInterface.class)).DeleteLearningNotes(hashMap).enqueue(new Callback<String>() {
            public void onResponse(Call<String> call, Response<String> response) {
                if (EditLearningNoteActivity.this.mProgressbar != null && EditLearningNoteActivity.this.mProgressbar.isShowing()) {
                    EditLearningNoteActivity.this.mProgressbar.dismiss();
                }
                if (response == null || response.body() == null) {
                    Utility.showAlertDialog(EditLearningNoteActivity.this.activity);
                    return;
                }
                String str = (String) response.body();
                AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper((Context) EditLearningNoteActivity.this, R.style.MyDialogTheme));
                builder.setMessage(str);
                builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i2) {
                        dialogInterface.dismiss();
                        EditLearningNoteActivity.this.finish();
                    }
                });
                builder.show();
            }

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

    public void onActivityResult(int i, int i2, Intent intent) {
        super.onActivityResult(i, i2, intent);
        if (i2 == 100 && ARE_Style_Image.REQUEST_CODE == i) {
            ARE_Style_Image style = this.insertImageView.getStyle();
            if (intent != null) {
                ArrayList<String> stringArrayListExtra = intent.getStringArrayListExtra("FilePaths");
                if (stringArrayListExtra.size() > 0) {
                    ImageStrategy imageStrategy = this.mDescription.getImageStrategy();
                    if (imageStrategy != null) {
                        imageStrategy.uploadAndInsertImage(stringArrayListExtra.get(0), style);
                    } else {
                        style.insertImage(stringArrayListExtra.get(0), AreImageSpan.ImageType.URI);
                    }
                }
            }
        }
    }
}