正在查看: St.John's v1.0.9 应用的 DetailAttendanceActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: St.John's v1.0.9 应用的 DetailAttendanceActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.mcb.stjohnsemschool.activity;
import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.google.firebase.analytics.FirebaseAnalytics;
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 org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class DetailAttendanceActivity extends AppCompatActivity {
public String TAG = DetailAttendanceActivity.class.getName();
private ConnectivityManager conMgr;
String date;
private Typeface fontMuseo;
String mAcadamicYearId;
String mClassId;
SharedPreferences.Editor mEditor;
private TableLayout mListView;
private TransparentProgressDialog mProgressbar;
SharedPreferences mSharedPref;
String mStudentEnrollmentID;
String mUserId;
int monthId;
String monthName;
private AppCompatActivity myActivity;
TextView nodata;
int yearId;
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.activity_attendance_detail);
this.myActivity = this;
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
SharedPreferences sharedPreferences = getSharedPreferences("", 0);
this.mSharedPref = sharedPreferences;
this.mEditor = sharedPreferences.edit();
this.mUserId = this.mSharedPref.getString("UseridKey", this.mUserId);
this.mClassId = this.mSharedPref.getString("ClassidKey", this.mClassId);
this.mStudentEnrollmentID = this.mSharedPref.getString("studentEnrollmentIdKey", this.mStudentEnrollmentID);
this.mAcadamicYearId = this.mSharedPref.getString("academicyearIdKey", this.mAcadamicYearId);
this.monthName = getIntent().getExtras().getString("MonthName");
this.monthId = getIntent().getExtras().getInt("MonthID");
this.yearId = getIntent().getExtras().getInt("YearId");
getSupportActionBar().setTitle(this.monthName);
this.fontMuseo = Typeface.createFromAsset(getAssets(), "Roboto-Regular.ttf");
setUpIds();
getStudentAttendanceByMonth();
}
private void setUpIds() {
this.mProgressbar = new TransparentProgressDialog(this, R.drawable.spinner_loading_imag);
this.mListView = (TableLayout) findViewById(R.id.tl_daily_attendance);
TextView textView = (TextView) findViewById(R.id.nodata_text);
this.nodata = textView;
textView.setVisibility(8);
this.nodata.setTypeface(this.fontMuseo);
}
private void getStudentAttendanceByMonth() {
ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService("connectivity");
this.conMgr = connectivityManager;
if (connectivityManager.getActiveNetworkInfo() != null && this.conMgr.getActiveNetworkInfo().isAvailable() && this.conMgr.getActiveNetworkInfo().isConnected()) {
getAttendanceByMonth();
} else {
Toast.makeText(getApplicationContext(), "Check your Network Connection", 0).show();
}
}
private void getAttendanceByMonth() {
TransparentProgressDialog transparentProgressDialog = this.mProgressbar;
if (transparentProgressDialog != null && !transparentProgressDialog.isShowing()) {
this.mProgressbar.show();
}
((ApiInterface) ApiClient.getClient1(getApplicationContext()).create(ApiInterface.class)).GetStudentAttendanceByMonth(Integer.parseInt(this.mStudentEnrollmentID), Integer.parseInt(this.mAcadamicYearId), this.monthId, this.yearId, Utility.getSchoolApiKey(this)).enqueue(new Callback<String>() {
public void onResponse(Call<String> call, Response<String> response) {
ImageView elementImageView;
if (DetailAttendanceActivity.this.mProgressbar != null && DetailAttendanceActivity.this.mProgressbar.isShowing()) {
DetailAttendanceActivity.this.mProgressbar.dismiss();
}
if (response == null || response.body() == null) {
Utility.showAlertDialog(DetailAttendanceActivity.this.myActivity);
return;
}
try {
JSONObject jSONObject = new JSONObject((String) response.body());
JSONArray jSONArray = jSONObject.getJSONArray("Attendance");
if (jSONArray.length() > 0) {
DetailAttendanceActivity.this.nodata.setVisibility(8);
DetailAttendanceActivity.this.mListView.setVisibility(0);
DetailAttendanceActivity.this.mListView.removeAllViews();
String[] split = jSONObject.getString("Columns").split(",");
TableLayout tableLayout = new TableLayout(DetailAttendanceActivity.this);
TableRow tableRow = new TableRow(DetailAttendanceActivity.this);
for (String str : split) {
tableRow.addView(DetailAttendanceActivity.this.getHeaderElementTextView(str, 1.0f));
}
tableRow.setBackgroundColor(DetailAttendanceActivity.this.getResources().getColor(R.color.ColorPrimary));
tableLayout.addView(tableRow);
for (int i = 0; i < jSONArray.length(); i++) {
JSONObject jSONObject2 = jSONArray.getJSONObject(i);
TableRow tableRow2 = new TableRow(DetailAttendanceActivity.this);
for (int i2 = 0; i2 < split.length; i2++) {
String str2 = "";
if (i2 == 0) {
if (jSONObject2.has(split[i2])) {
str2 = jSONObject2.getString(split[i2]);
}
tableRow2.addView(DetailAttendanceActivity.this.getElementTextView(str2));
} else {
RelativeLayout elementRelativeLayout = DetailAttendanceActivity.this.getElementRelativeLayout();
if (jSONObject2.has(split[i2])) {
str2 = jSONObject2.getString(split[i2]);
}
if (str2.contains("Present")) {
elementImageView = DetailAttendanceActivity.this.getElementImageView(R.drawable.ic_action_right);
} else if (str2.contains("Absent")) {
elementImageView = DetailAttendanceActivity.this.getElementImageView(R.drawable.ic_action_wrong);
} else {
elementImageView = DetailAttendanceActivity.this.getElementImageView(R.drawable.ic_action_dash);
}
elementRelativeLayout.addView(elementImageView);
tableRow2.addView(elementRelativeLayout);
}
}
tableLayout.addView(tableRow2);
}
DetailAttendanceActivity.this.mListView.addView(tableLayout);
return;
}
DetailAttendanceActivity.this.nodata.setVisibility(0);
DetailAttendanceActivity.this.mListView.setVisibility(8);
} catch (JSONException e) {
e.printStackTrace();
Toast.makeText(DetailAttendanceActivity.this.getApplicationContext(), "Something went wrong, Try again", 0).show();
DetailAttendanceActivity.this.finish();
}
}
public void onFailure(Call<String> call, Throwable th) {
if (DetailAttendanceActivity.this.mProgressbar != null && DetailAttendanceActivity.this.mProgressbar.isShowing()) {
DetailAttendanceActivity.this.mProgressbar.dismiss();
}
Utility.showAlertDialog(DetailAttendanceActivity.this.myActivity);
}
});
}
public boolean onOptionsItemSelected(MenuItem menuItem) {
if (menuItem.getItemId() == 16908332) {
super.onBackPressed();
return true;
}
return super.onOptionsItemSelected(menuItem);
}
TextView getElementTextView(String str) {
TextView textView = new TextView(this);
textView.setLayoutParams(new TableRow.LayoutParams(0, -1, 1.0f));
textView.setText(str);
textView.setTextSize(14.0f);
textView.setTextColor(-16777216);
textView.setTypeface(this.fontMuseo);
textView.setGravity(17);
textView.setPadding(5, 10, 5, 10);
textView.setBackgroundResource(R.drawable.border);
return textView;
}
TextView getHeaderElementTextView(String str, float f) {
TextView textView = new TextView(this);
textView.setLayoutParams(new TableRow.LayoutParams(0, -1, f));
textView.setText(str);
textView.setTextSize(16.0f);
textView.setTextColor(-1);
textView.setTypeface(Typeface.SERIF);
textView.setGravity(17);
textView.setBackgroundResource(R.drawable.border);
textView.setPadding(5, 7, 5, 7);
return textView;
}
ImageView getElementImageView(int i) {
ImageView imageView = new ImageView(this);
imageView.setLayoutParams(new TableRow.LayoutParams(-2, -2));
imageView.setMaxHeight(10);
imageView.setMaxWidth(10);
imageView.setPadding(5, 7, 5, 7);
imageView.setBackgroundResource(i);
return imageView;
}
RelativeLayout getElementRelativeLayout() {
RelativeLayout relativeLayout = new RelativeLayout(this);
relativeLayout.setLayoutParams(new TableRow.LayoutParams(0, -1, 1.0f));
relativeLayout.setPadding(5, 10, 5, 10);
relativeLayout.setGravity(17);
relativeLayout.setBackgroundResource(R.drawable.border);
return relativeLayout;
}
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_DETAIL_ATTENDANCE", bundle);
}
protected void onStop() {
TransparentProgressDialog transparentProgressDialog = this.mProgressbar;
if (transparentProgressDialog != null && transparentProgressDialog.isShowing()) {
this.mProgressbar.dismiss();
}
super.onStop();
}
}