Skip to content

Commit

Permalink
Commit 18
Browse files Browse the repository at this point in the history
- Fixed widget bugs.
- Killed myself over Admin Suite.
- Pushing before admin suite overhaul
  • Loading branch information
DigitalJesus committed Jun 17, 2019
1 parent 52caac2 commit b2d7735
Show file tree
Hide file tree
Showing 8 changed files with 217 additions and 201 deletions.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
2 changes: 0 additions & 2 deletions app/src/main/java/com/example/assessment1/AdminEditClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ protected void onCreate(Bundle savedInstanceState) {
assert extras != null;
final int selectedStudentID = extras.getInt("studentID");

Log.d("HECK", "studentEditor: " + selectedStudentID);

final String[] classList = dbHelper.queryStringAttributeForStudent("className", selectedStudentID);

final ListView listView = (ListView)findViewById(R.id.listView_admin_class_editor);
Expand Down
176 changes: 95 additions & 81 deletions app/src/main/java/com/example/assessment1/CellEditor.java
Original file line number Diff line number Diff line change
@@ -1,95 +1,109 @@
package com.example.assessment1;

import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Editable;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
import java.util.Objects;

public class CellEditor extends AppCompatActivity {

private static final String TAG = "CELLEDITOR";
public static int studentID;
public static String className;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cell_editor);
DBHelper dbHelper = new DBHelper(this);

//Import Selections from previous classes.
Bundle extras = getIntent().getExtras();
assert extras != null;
int selectedStudentID = extras.getInt("studentID");
String selectedClass = extras.getString("className");

studentID = selectedStudentID;
className = selectedClass;

Log.d(TAG, "Set studentID: " + studentID + " and className: " + className);

//Get Data for each cell from DB
final String[] dayList = dbHelper.queryCellDetails("day", selectedStudentID, selectedClass);
final String[] timeList = dbHelper.queryCellDetails("startTime", selectedStudentID, selectedClass);
final String[] durationList = dbHelper.queryCellDetails("cellDuration", selectedStudentID, selectedClass);
final String[] roomList = dbHelper.queryCellDetails("classRoom", selectedStudentID, selectedClass);

//Init. ListView and CustomObject
ListView listView = findViewById(R.id.listView_cell_editor);
final ArrayList<CustomArrayObject> objects = new ArrayList<>();

//For each List item, add to the custom object the four data point for each cell
for (int i = 0; i < dayList.length; i++) {
CustomArrayObject item1 = new CustomArrayObject(dayList[i], timeList[i], durationList[i], roomList[i]);
objects.add(item1);
}


//Display the list using the custom adapter
CustomAdapter customAdapter = new CustomAdapter(this, objects);
listView.setAdapter(customAdapter);

//Be kind, rewind.
dbHelper.close();
}

public void modifyDayData(Context context, String updatedValue, int entryNumber){
Log.d(TAG, updatedValue + " " + entryNumber);

DBHelper dbHelper = new DBHelper(context);
Log.d(TAG, "modifyDayData: " + studentID+"::"+className+":::"+entryNumber);


dbHelper.updateRow(studentID, className, Integer.parseInt(updatedValue), null, -1, -1, entryNumber);
}

public void modifyDurationData(Context context, String updatedValue, int entryNumber){
Log.d(TAG, updatedValue + " " + entryNumber);

DBHelper dbHelper = new DBHelper(context);

dbHelper.updateRow(studentID, className, -1, null, -1, Integer.parseInt(updatedValue), entryNumber);
}

public void modifyClassRoomData(Context context, String updatedValue, int entryNumber){
Log.d(TAG, updatedValue + " " + entryNumber);

DBHelper dbHelper = new DBHelper(context);

dbHelper.updateRow(studentID, className, -1, updatedValue, -1, -1, entryNumber);
}

public void modifyStartTimeData(Context context, String updatedValue, int entryNumber){
Log.d(TAG, updatedValue + " " + entryNumber);

DBHelper dbHelper = new DBHelper(context);

dbHelper.updateRow(studentID, className, -1, null, Integer.parseInt(updatedValue), -1, entryNumber);
}
}
private static final String TAG = "CELLEDITOR";
// private Map<Integer, Map<Integer, String>> mapList;
// private Map<Integer, String> dataMap;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cell_editor);
DBHelper dbHelper = new DBHelper(this);

//Import Selections from previous classes.
Bundle extras = getIntent().getExtras();
assert extras != null;
int selectedStudentID = extras.getInt("studentID");
String selectedClass = extras.getString("className");

//Get Data for each cell from DB
final String[] idList = dbHelper.queryCellDetails("_id", selectedStudentID, selectedClass);
for (int i = 0; i < idList.length; i++) {
Log.d(TAG, idList[i]);
}
final String[] dayList = dbHelper.queryCellDetails("day", selectedStudentID, selectedClass);
final String[] timeList = dbHelper.queryCellDetails("startTime", selectedStudentID, selectedClass);
final String[] durationList = dbHelper.queryCellDetails("cellDuration", selectedStudentID, selectedClass);
final String[] roomList = dbHelper.queryCellDetails("classRoom", selectedStudentID, selectedClass);

//dataMap = new Map<Integer, String>;

//Init. ListView and CustomObject
ListView listView = findViewById(R.id.listView_cell_editor);
final ArrayList<CustomArrayObject> objects = new ArrayList<>();

//For each List item, add to the custom object the four data point for each cell
for (int i = 0; i < dayList.length; i++) {
CustomArrayObject item1 = new CustomArrayObject(Integer.parseInt(idList[i]), dayList[i], timeList[i], durationList[i], roomList[i]);
objects.add(item1);
}

//Display the list using the custom adapter
CustomAdapter customAdapter = new CustomAdapter(this, objects);
listView.setAdapter(customAdapter);


listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.d(TAG, "onItemClick: "+objects.get(position).getId_());
}
});

//Be kind, rewind.
dbHelper.close();
}

// I tried so hard.
// private void saveData() {
// DBHelper dbHelper = new DBHelper(this);
// int mapSize = Objects.requireNonNull(mapList.get(0)).size() +
// Objects.requireNonNull(mapList.get(1)).size() +
// Objects.requireNonNull(mapList.get(2)).size() +
// Objects.requireNonNull(mapList.get(3)).size();
//
// for (int i = 0; i < mapSize; i++) {
// Iterator<Map.Entry<Integer, String>> itr = mapList.get(i).entrySet().iterator();
// while (itr.hasNext()) {
// Map.Entry<Integer, String> entry = itr.next();
// switch (i) {
// case 0:
// dbHelper.updateRow(entry.getKey(), Integer.parseInt(entry.getValue()), null, -1, -1);
// break;
// case 1:
// dbHelper.updateRow(entry.getKey(), -1, null, Integer.parseInt(entry.getValue()), -1);
// break;
// case 2:
// dbHelper.updateRow(entry.getKey(), -1, null, -1, Integer.parseInt(entry.getValue()));
// break;
// case 3:
// dbHelper.updateRow(entry.getKey(), -1, entry.getValue(), -1, -1);
// break;
// }
// }
// }
// }
//
// public void tempData(int id_, Editable s, int type) {
// dataMap.put(id_, s.toString());
// mapList.put(type, dataMap);
// }
}
141 changes: 75 additions & 66 deletions app/src/main/java/com/example/assessment1/CustomAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.TextView;

import java.util.ArrayList;

Expand All @@ -17,9 +18,9 @@ public class CustomAdapter extends BaseAdapter {

private LayoutInflater inflater;
private ArrayList<CustomArrayObject> objects;
private CellEditor cellEditor = new CellEditor();

private class ViewHolder {
TextView cellId_;
EditText editTextDay;
EditText editTextTime;
EditText editTextDuration;
Expand All @@ -45,10 +46,11 @@ public long getItemId(int position) {
}

public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder;
final ViewHolder holder;
if(convertView == null) {
holder = new ViewHolder();
convertView = inflater.inflate(R.layout.class_edit_listview_item, null);
holder.cellId_ = convertView.findViewById(R.id.idViewer);
holder.editTextDay = convertView.findViewById(R.id.editText_day);
holder.editTextTime = convertView.findViewById(R.id.editText_time);
holder.editTextDuration = convertView.findViewById(R.id.editText_duration);
Expand All @@ -57,72 +59,79 @@ public View getView(final int position, View convertView, ViewGroup parent) {
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.editTextDay.setText(objects.get(position).getProp1());
holder.editTextTime.setText(objects.get(position).getProp2());
holder.editTextDuration.setText(objects.get(position).getProp3());
holder.editTextRoom.setText(objects.get(position).getProp4());
final View finalConvertView = convertView;
holder.editTextDay.addTextChangedListener(new TextWatcher(){
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {

if(!s.toString().isEmpty()){
Log.d(TAG, "onTextChanged: pos: " + position); //TODO:: POSITION IS ALWAYS 0
cellEditor.modifyDayData(finalConvertView.getContext(), s.toString(), position);
}
}

@Override
public void afterTextChanged(Editable s) {}
});

holder.editTextTime.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if(!s.toString().isEmpty()){
cellEditor.modifyStartTimeData(finalConvertView.getContext(), s.toString(), position);
}
}
holder.cellId_.setText(Integer.toString(objects.get(position).getId_()));
holder.editTextDay.setText(objects.get(position).getDay());
holder.editTextTime.setText(objects.get(position).getTime());
holder.editTextDuration.setText(objects.get(position).getDuration());
holder.editTextRoom.setText(objects.get(position).getRoom());

@Override
public void afterTextChanged(Editable s) {}
});

holder.editTextDuration.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if(!s.toString().isEmpty()){
cellEditor.modifyDurationData(finalConvertView.getContext(), s.toString(), position);
}
}

@Override
public void afterTextChanged(Editable s) {}
});

holder.editTextRoom.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if(!s.toString().isEmpty()){
cellEditor.modifyClassRoomData(finalConvertView.getContext(), s.toString(), position);
}
}
final View finalConvertView = convertView;

@Override
public void afterTextChanged(Editable s) {}
});
//TODO: FIX THIS SHIT, won't save anything to anywhere.
// Wasted 4 weeks.
// holder.editTextDay.addTextChangedListener(new TextWatcher(){
// @Override
// public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
//
// @Override
// public void onTextChanged(CharSequence s, int start, int before, int count) {}
//
// @Override
// public void afterTextChanged(Editable s) {
// CellEditor cellEditor = new CellEditor();
// if(!s.toString().isEmpty()){
// cellEditor.tempData(objects.get(position).getId_(), s ,0);
// }
// }
// });
//
// holder.editTextTime.addTextChangedListener(new TextWatcher() {
// @Override
// public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
//
// @Override
// public void onTextChanged(CharSequence s, int start, int before, int count) {}
//
// @Override
// public void afterTextChanged(Editable s) {
// CellEditor cellEditor = new CellEditor();
// if(!s.toString().isEmpty()){
// cellEditor.tempData(objects.get(position).getId_(), s ,1);
// }
// }
// });
//
// holder.editTextDuration.addTextChangedListener(new TextWatcher() {
// @Override
// public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
//
// @Override
// public void onTextChanged(CharSequence s, int start, int before, int count) {}
//
// @Override
// public void afterTextChanged(Editable s) {
// CellEditor cellEditor = new CellEditor();
// if(!s.toString().isEmpty()){
// cellEditor.tempData(objects.get(position).getId_(), s ,2);
// }
// }
// });
//
// holder.editTextRoom.addTextChangedListener(new TextWatcher() {
// @Override
// public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
//
// @Override
// public void onTextChanged(CharSequence s, int start, int before, int count) {}
//
// @Override
// public void afterTextChanged(Editable s) {
// CellEditor cellEditor = new CellEditor();
// if(!s.toString().isEmpty()){
// cellEditor.tempData(objects.get(position).getId_(), s ,3);
// }
// }
// });
return convertView;
}
}
Loading

0 comments on commit b2d7735

Please sign in to comment.