Browse Source

REFACTORING. A lot of classes replaced o OldCabinetController.

master
Defend 8 years ago
parent
commit
5609d0fe9c
  1. 247
      app/src/main/java/ru/defend/defdevteam/tstu/CabinetActivity.java
  2. 13
      app/src/main/java/ru/defend/defdevteam/tstu/GroupList.java
  3. 199
      app/src/main/java/ru/defend/defdevteam/tstu/OldCabinetController.java

247
app/src/main/java/ru/defend/defdevteam/tstu/CabinetActivity.java

@ -39,40 +39,31 @@ public class CabinetActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
static public List<GroupList> group, faculty, subs;
public WebView browser;
public WebSettings browserSet;
static public String AuthURL, MainURL, AdditionalURL ,JournalURL, RateValueURL, GroupRateURL,
FacultyRateURL, siteBuf;
static public String MainHTML, AdditionalHTML, JournalHTML, RateValueHTML, GroupRateHTML,
FacultyRateHTML;
boolean authBegin,taskFinished = false;
public String AuthURL;
public Boolean authBegin = false;
public TextView studentName, studentGroup, studentRate, positionGroup,
positionFaculty, newsTextView;
public RelativeLayout profileLayout, journalLayout, gRateLayout,
fRateLayout, aboutLayout, progressLayout, newsLayout;
public Toolbar myToolbar;
public Chronometer timer;
static public List<groupList> group, faculty, subs;
Intent MainA;
FeedController feedController;
OldCabinetController cabinetController;
public class groupList {
public String name, rate;
public groupList(String name, String rate){
this.name = name;
this.rate = rate;
}
}
public class groupAdapter extends ArrayAdapter<groupList> {
public class groupAdapter extends ArrayAdapter<GroupList> {
public groupAdapter(Context context){
super(context, android.R.layout.simple_list_item_2, group);
}
@Override
public View getView(int position, View convertView, ViewGroup parent){
groupList group = getItem(position);
GroupList group = getItem(position);
if (convertView == null){
convertView = LayoutInflater.from(getContext()).inflate(android.R.layout.simple_list_item_2, null);
@ -86,7 +77,7 @@ public class CabinetActivity extends AppCompatActivity
}
public class subsAdapter extends ArrayAdapter<groupList> {
public class subsAdapter extends ArrayAdapter<GroupList> {
public subsAdapter(Context context) {
super(context, android.R.layout.simple_selectable_list_item);
}
@ -94,7 +85,7 @@ public class CabinetActivity extends AppCompatActivity
@NonNull
@Override
public View getView(int position, View convertView, ViewGroup parent) {
groupList group = getItem(position);
GroupList group = getItem(position);
if(convertView == null){
convertView = LayoutInflater.from(getContext()).inflate(android.R.layout.simple_selectable_list_item, null);
@ -104,14 +95,14 @@ public class CabinetActivity extends AppCompatActivity
}
}
public class facultyAdapter extends ArrayAdapter<groupList> {
public class facultyAdapter extends ArrayAdapter<GroupList> {
public facultyAdapter(Context context){
super(context, android.R.layout.simple_list_item_2, faculty);
}
@Override
public View getView(int position, View convertView, ViewGroup parent){
groupList group = getItem(position);
GroupList group = getItem(position);
if (convertView == null){
convertView = LayoutInflater.from(getContext()).inflate(android.R.layout.simple_list_item_2, null);
@ -176,6 +167,7 @@ public class CabinetActivity extends AppCompatActivity
myToolbar.setTitle(R.string.title_profile);
feedController = new FeedController(this, 1);
cabinetController = new OldCabinetController(this);
AuthURL = "http://web-iais.admin.tstu.ru:7777/zion/f?p=stud_main";
loadSite(AuthURL);
@ -222,9 +214,9 @@ public class CabinetActivity extends AppCompatActivity
gRateLayout.setVisibility(View.INVISIBLE);
fRateLayout.setVisibility(View.INVISIBLE);
aboutLayout.setVisibility(View.INVISIBLE);
if(!taskFinished) {
progressLayout.setVisibility(View.VISIBLE);
}
// if(!taskFinished) {
// progressLayout.setVisibility(View.VISIBLE);
// }
switch (id) {
case R.id.nav_newsfeed:
progressLayout.setVisibility(View.INVISIBLE);
@ -261,21 +253,12 @@ public class CabinetActivity extends AppCompatActivity
return true;
}
public void loadSite (String url) {
browser.loadUrl(url);
}
// НЕИЗВЕСТНОЕ ИСКЛЮЧЕНИЕ
public void unknownState(int currentState){
Log.e("unknownState","Не удалось получить ссылки на странице студента");
Log.e("unknownState",getURL());
public void cabinetClosing(Integer code, String reason){
Log.e("cabinetClosing", reason);
Log.e("cabinetClosing|URL",getURL());
finish();
}
// АВТОРИЗАЦИЯ
public boolean Auth () {
authBegin = true;
String login = MainA.getStringExtra("login");
@ -288,57 +271,14 @@ public class CabinetActivity extends AppCompatActivity
return true;
}
public byte sessionState () {
OldParser parser = new OldParser();
if(taskFinished) return 127;
Intent intent = new Intent();
Log.i("sessionActive","Checking session");
String a = parser.cutLine("http://web-iais.admin.tstu.ru:7777/zion/f?p=503:",":",getURL());
switch (a){
case "LOGIN_DESKTOP":
Log.i("sessionActive","Окно авторизации");
//MainActivity.error.setText("Конец сессии авторизации");
finish();
return 0;
case "er":
Log.i("sessionActive","Окно авторизации");
//MainActivity.error.setText("Ошибка авторизации");
finish();
return 1;
case "1":
Log.i("sessionActive","Страница студента");
intent.putExtra("error","Вход производился успешно");
MainURL = getURL();
taskGenerator(2);
return 2;
case "40":
Log.i("sessionActive","Страница - Успеваемость");
taskGenerator(3);
return 3;
case "41":
Log.i("sessionActive","Страница - Журналы|Главная");
taskGenerator(4);
return 4;
case "43":
Log.i("sessionActive","Страница - Рейтинг|Главная");
String s = parser.cutLine("","503:",MainURL) + "503:43:" + parser.cutLine(":1:","",MainURL)+":";
if(parser.cutLine(s,":NO:", getURL()).equals("RATE_GROUP")) {
taskGenerator(6);
return 6;
}
if(parser.cutLine(s,":NO:", getURL()).equals("RATE_INST")) {
taskGenerator(7);
return 7;
}
taskGenerator(5);
return 5;
}
return 0;
public void loadSite (String url) {
browser.loadUrl(url);
}
public void setStudentName(String string){
studentGroup.setText(string);
studentName.setText(string);
}
public void setStudentGroup(String string) {
@ -365,148 +305,27 @@ public class CabinetActivity extends AppCompatActivity
positionFaculty.setText(getString(R.string.cabinet_faculty_position) + position);
}
// Контент генератор
public void taskGenerator(int state){
OldParser parser = new OldParser();
if (!isFinishing())
switch (state){
case 2:
MainHTML = siteBuf;
String studNameGroup = parser.cutLine("<span id=\\\"P1_STUD\\\" class=\\\"display_only\\\" style=\\\"font-size: 120%; font-family:Verdana, Arial, Helvetica, sans-serif; color: #0000FF; font-weight:bold\\\">",
"</span>", MainHTML);
setStudentName(parser.cutLine(""," /",studNameGroup));
setStudentGroup(parser.cutLine("/ ","",studNameGroup));
loadSite("javascript:apex.submit('T_ЗАНЯТИЯ/ОЦЕНКИ');");
break;
case 3:
AdditionalHTML = siteBuf;
JournalURL = "http://web-iais.admin.tstu.ru:7777/zion/" +
parser.cutLine("<td headers=\\\"BRS\\\"><a href=\\\"","\" title=\\\"Просмотр журналов\\\">",AdditionalHTML);
RateValueURL = "http://web-iais.admin.tstu.ru:7777/zion/" +
parser.cutLine("<td headers=\\\"RTG\\\"><a href=\\\"","\\\" title=\\\"Просмотр успеваемости\\\">",AdditionalHTML);
loadSite(JournalURL);
break;
case 4:
JournalHTML = siteBuf;
loadSite(RateValueURL);
break;
case 5:
RateValueHTML = siteBuf;
String rate = parser.cutLine("<td align=\\\"center\\\" headers=\\\"STUDRATE\\\">","</td>",RateValueHTML);
setStudentRate(rate);
GroupRateURL = "http://web-iais.admin.tstu.ru:7777/zion/" + parser.cutLine("><td headers=\\\"GROUP_NAME\\\"><a href=\\\"","\\\">",RateValueHTML);
FacultyRateURL = "http://web-iais.admin.tstu.ru:7777/zion/" + parser.cutLine("<td headers=\\\"INST\\\"><a href=\\\"","\\\">", RateValueHTML);
loadSite(GroupRateURL);
break;
case 6:
GroupRateHTML = siteBuf;
fillGroup();
loadSite(FacultyRateURL);
break;
case 7:
FacultyRateHTML = siteBuf;
fillFaculty();
fillAll();
taskFinished = true;
setProgressVisibility(false);
break;
}
}
public void fillGroup(){
OldParser parser = new OldParser();
group = new ArrayList<groupList>();
String n,r;
String gr = siteBuf;
gr = parser.cutLine("<h1>Рейтинг в группе</h1>", "", gr);
int i = 0;
while ( !(parser.cutLine("<tr><td align=\\\"center\\\" headers=\\\"ROWNUM\\\">","</tr>",gr,true) == "")){
Integer s = Integer.valueOf(parser.cutLine("<td align=\\\"center\\\" headers=\\\"ROWNUM\\\">","</td>",gr));
if(s == (i+1)) {
n = parser.cutLine("<td headers=\\\"STUDNAME\\\">", "</td>", gr);
if (!(parser.cutLine("<font color=\\\"red\\\"><b>", "</b></font>", n) == ""))
n = parser.cutLine("<font color=\\\"red\\\"><b>", "</b></font>",n);
r = parser.cutLine("<td align=\\\"center\\\" headers=\\\"STUDRATE\\\">", "</td>", gr);
r += " | Группа: " + parser.cutLine("<td headers=\\\"GROUP_NAME\\\">","</td>", gr, true);
group.add(new groupList(n,"Общий балл: " + r));
i++;
}
gr = parser.cutLine("</td></tr>\\n", "", gr);
}
ArrayAdapter<groupList> groupL = new groupAdapter(this);
ArrayAdapter<GroupList> groupL = new groupAdapter(this);
ListView groupList = (ListView) findViewById(R.id.groupList);
groupList.setAdapter(groupL);
}
public void fillGroup(ArrayList<groupList> group){
}
public void fillFaculty(){
OldParser parser = new OldParser();
faculty = new ArrayList<groupList>();
String n,r;
String fr = siteBuf;
fr = parser.cutLine("<h1>Рейтинг в институте/факультете</h1>", "", fr);
int i = 0;
while ( !(parser.cutLine("<tr><td align=\\\"center\\\" headers=\\\"ROWNUM\\\">","</tr>",fr,true) == "")){
Integer s = Integer.valueOf(parser.cutLine("<td align=\\\"center\\\" headers=\\\"ROWNUM\\\">","</td>",fr));
if(s == (i+1)) {
n = parser.cutLine("<td headers=\\\"STUDNAME\\\">", "</td>", fr);
if (!(parser.cutLine("<font color=\\\"red\\\"><b>", "</b></font>", n) == ""))
n = parser.cutLine("<font color=\\\"red\\\"><b>", "</b></font>",n);
r = parser.cutLine("<td align=\\\"center\\\" headers=\\\"STUDRATE\\\">", "</td>", fr);
r += " | Группа: " + parser.cutLine("<td headers=\\\"GROUP_NAME\\\">","</td>", fr, true);
faculty.add(new groupList(n,"Общий балл: " + r));
i++;
}
fr = parser.cutLine("</td></tr>\\n", "", fr);
}
ArrayAdapter<groupList> facultyL = new facultyAdapter(this);
ArrayAdapter<GroupList> facultyL = new facultyAdapter(this);
ListView facultyList = (ListView) findViewById(R.id.facultyList);
facultyList.setAdapter(facultyL);
}
public void fillAll(){
OldParser parser = new OldParser();
String s;
String s2 = GroupRateHTML;
s = parser.cutLine("<tr>","</tr>",GroupRateHTML);
s = parser.cutLine("<font","</font>",s);
while (s.equals("")) {
s2 = parser.cutLine("</tr>","",s2);
s = parser.cutLine("<tr>","</tr>",s2);
s = parser.cutLine("<font","</font>",s);
}
s2 = parser.cutLine("<td align=\\\"center\\\" headers=\\\"ROWNUM\\\">","</td>",s2);
//***//
Log.i(getString(R.string.cabinet_group_position), s2);
//***//
setGroupPosition(s2);
s = "";
s2 = FacultyRateHTML;
s = parser.cutLine("<tr>","</tr>",FacultyRateHTML);
s = parser.cutLine("<font","</font>",s);
while (s.equals("")) {
s2 = parser.cutLine("</tr>","",s2);
s = parser.cutLine("<tr>","</tr>",s2);
s = parser.cutLine("<font","</font>",s);
}
s2 = parser.cutLine("<td align=\\\"center\\\" headers=\\\"ROWNUM\\\">","</td>",s2);
Log.i(getString(R.string.cabinet_faculty_position),s2);
setFacultyPosition(s2);
}
@TargetApi(19)
public void getHTML(){
browser.evaluateJavascript("javascript:document.documentElement.outerHTML;", new ValueCallback<String>() {
@Override
public void onReceiveValue(String s) {
siteBuf = s;
cabinetController.siteBuf = s;
encodeHTML();
if(!authBegin) Auth();
else sessionState();
else cabinetController.sessionState();
}
});
}
@ -516,16 +335,20 @@ public class CabinetActivity extends AppCompatActivity
}
public void encodeHTML(){
if(siteBuf != null){
if(cabinetController.getSiteBuffer() != null){
OldParser parser = new OldParser();
siteBuf = OldParser.removeUTFCharacters(siteBuf).toString();
Log.d("Response html","Загружена страница "+parser.cutLine("<title>","</title>",siteBuf));
Log.i("encodeHTML",siteBuf);
cabinetController.setSiteBuffer(
OldParser.removeUTFCharacters(
cabinetController.getSiteBuffer()
).toString()
);
Log.d("Response html","Загружена страница "+parser.cutLine("<title>","</title>", cabinetController.getSiteBuffer()));
Log.i("encodeHTML",cabinetController.getSiteBuffer());
}
}
private class MyWebViewClient extends WebViewClient {
private class MyWebViewClient extends WebViewClient{
@Override
public void onPageFinished(WebView view, String url) {
getHTML();

13
app/src/main/java/ru/defend/defdevteam/tstu/GroupList.java

@ -0,0 +1,13 @@
package ru.defend.defdevteam.tstu;
/**
* Created by itsmy on 11.02.2017.
*/
public class GroupList {
public String name, rate;
public GroupList(String name, String rate){
this.name = name;
this.rate = rate;
}
}

199
app/src/main/java/ru/defend/defdevteam/tstu/OldCabinetController.java

@ -0,0 +1,199 @@
package ru.defend.defdevteam.tstu;
import android.app.Activity;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import java.util.ArrayList;
import java.util.List;
/**
* Created by itsmy on 11.02.2017.
*/
public class OldCabinetController {
boolean authBegin, taskFinished = false;
static public String AuthURL, MainURL, AdditionalURL ,JournalURL, RateValueURL, GroupRateURL,
FacultyRateURL, siteBuf;
static public String MainHTML, AdditionalHTML, JournalHTML, RateValueHTML, GroupRateHTML,
FacultyRateHTML;
public CabinetActivity cabinetActivity;
public OldCabinetController(CabinetActivity cabinet){
this.cabinetActivity = cabinet;
}
public byte sessionState () {
OldParser parser = new OldParser();
if(taskFinished) return 127;
Log.i("sessionActive","Checking session");
String a = parser.cutLine("http://web-iais.admin.tstu.ru:7777/zion/f?p=503:",":",cabinetActivity.getURL());
switch (a){
case "LOGIN_DESKTOP":
Log.i("sessionActive","Окно авторизации");
cabinetActivity.cabinetClosing(0, "Конец сессии авторизации");
return 0;
case "er":
Log.i("sessionActive","Окно авторизации");
cabinetActivity.cabinetClosing(1, "Ошибка авторизации");
return 1;
case "1":
Log.i("sessionActive","Страница студента");
MainURL = cabinetActivity.getURL();
taskGenerator(2);
return 2;
case "40":
Log.i("sessionActive","Страница - Успеваемость");
taskGenerator(3);
return 3;
case "41":
Log.i("sessionActive","Страница - Журналы|Главная");
taskGenerator(4);
return 4;
case "43":
Log.i("sessionActive","Страница - Рейтинг|Главная");
String s = parser.cutLine("","503:",MainURL) + "503:43:" + parser.cutLine(":1:","",MainURL)+":";
if(parser.cutLine(s,":NO:", cabinetActivity.getURL()).equals("RATE_GROUP")) {
taskGenerator(6);
return 6;
}
if(parser.cutLine(s,":NO:", cabinetActivity.getURL()).equals("RATE_INST")) {
taskGenerator(7);
return 7;
}
taskGenerator(5);
return 5;
}
return 0;
}
public void taskGenerator(int state){
OldParser parser = new OldParser();
if (!taskFinished)
switch (state){
case 2:
MainHTML = siteBuf;
String studNameGroup = parser.cutLine("<span id=\\\"P1_STUD\\\" class=\\\"display_only\\\" style=\\\"font-size: 120%; font-family:Verdana, Arial, Helvetica, sans-serif; color: #0000FF; font-weight:bold\\\">",
"</span>", MainHTML);
cabinetActivity.setStudentName(parser.cutLine(""," /",studNameGroup));
cabinetActivity.setStudentGroup(parser.cutLine("/ ","",studNameGroup));
cabinetActivity.loadSite("javascript:apex.submit('T_ЗАНЯТИЯ/ОЦЕНКИ');");
break;
case 3:
AdditionalHTML = siteBuf;
JournalURL = "http://web-iais.admin.tstu.ru:7777/zion/" +
parser.cutLine("<td headers=\\\"BRS\\\"><a href=\\\"","\" title=\\\"Просмотр журналов\\\">",AdditionalHTML);
RateValueURL = "http://web-iais.admin.tstu.ru:7777/zion/" +
parser.cutLine("<td headers=\\\"RTG\\\"><a href=\\\"","\\\" title=\\\"Просмотр успеваемости\\\">",AdditionalHTML);
cabinetActivity.loadSite(JournalURL);
break;
case 4:
JournalHTML = siteBuf;
cabinetActivity.loadSite(RateValueURL);
break;
case 5:
RateValueHTML = siteBuf;
String rate = parser.cutLine("<td align=\\\"center\\\" headers=\\\"STUDRATE\\\">","</td>",RateValueHTML);
cabinetActivity.setStudentRate(rate);
GroupRateURL = "http://web-iais.admin.tstu.ru:7777/zion/" + parser.cutLine("><td headers=\\\"GROUP_NAME\\\"><a href=\\\"","\\\">",RateValueHTML);
FacultyRateURL = "http://web-iais.admin.tstu.ru:7777/zion/" + parser.cutLine("<td headers=\\\"INST\\\"><a href=\\\"","\\\">", RateValueHTML);
cabinetActivity.loadSite(GroupRateURL);
break;
case 6:
GroupRateHTML = siteBuf;
fillGroup();
cabinetActivity.loadSite(FacultyRateURL);
break;
case 7:
FacultyRateHTML = siteBuf;
fillFaculty();
fillRates();
taskFinished = true;
cabinetActivity.setProgressVisibility(false);
break;
}
}
public String getSiteBuffer(){
return this.siteBuf;
}
public void setSiteBuffer(String siteBuf) {
this.siteBuf = siteBuf;
}
public void fillRates(){
OldParser parser = new OldParser();
String s;
String s2 = GroupRateHTML;
s = parser.cutLine("<tr>","</tr>",GroupRateHTML);
s = parser.cutLine("<font","</font>",s);
while (s.equals("")) {
s2 = parser.cutLine("</tr>","",s2);
s = parser.cutLine("<tr>","</tr>",s2);
s = parser.cutLine("<font","</font>",s);
}
s2 = parser.cutLine("<td align=\\\"center\\\" headers=\\\"ROWNUM\\\">","</td>",s2);
cabinetActivity.setGroupPosition(s2);
s = "";
s2 = FacultyRateHTML;
s = parser.cutLine("<tr>","</tr>",FacultyRateHTML);
s = parser.cutLine("<font","</font>",s);
while (s.equals("")) {
s2 = parser.cutLine("</tr>","",s2);
s = parser.cutLine("<tr>","</tr>",s2);
s = parser.cutLine("<font","</font>",s);
}
s2 = parser.cutLine("<td align=\\\"center\\\" headers=\\\"ROWNUM\\\">","</td>",s2);
cabinetActivity.setFacultyPosition(s2);
}
public void fillGroup(){
cabinetActivity.group = new ArrayList<GroupList>();
OldParser parser = new OldParser();
String n,r;
String gr = getSiteBuffer();
gr = parser.cutLine("<h1>Рейтинг в группе</h1>", "", gr);
int i = 0;
while ( !(parser.cutLine("<tr><td align=\\\"center\\\" headers=\\\"ROWNUM\\\">","</tr>",gr,true) == "")){
Integer s = Integer.valueOf(parser.cutLine("<td align=\\\"center\\\" headers=\\\"ROWNUM\\\">","</td>",gr));
if(s == (i+1)) {
n = parser.cutLine("<td headers=\\\"STUDNAME\\\">", "</td>", gr);
if (!(parser.cutLine("<font color=\\\"red\\\"><b>", "</b></font>", n) == ""))
n = parser.cutLine("<font color=\\\"red\\\"><b>", "</b></font>",n);
r = parser.cutLine("<td align=\\\"center\\\" headers=\\\"STUDRATE\\\">", "</td>", gr);
r += " | Группа: " + parser.cutLine("<td headers=\\\"GROUP_NAME\\\">","</td>", gr, true);
cabinetActivity.group.add(new GroupList(n,"Общий балл: " + r));
i++;
}
gr = parser.cutLine("</td></tr>\\n", "", gr);
}
cabinetActivity.fillGroup();
}
public void fillFaculty(){
OldParser parser = new OldParser();
cabinetActivity.faculty = new ArrayList<GroupList>();
String n,r;
String fr = getSiteBuffer();
fr = parser.cutLine("<h1>Рейтинг в институте/факультете</h1>", "", fr);
int i = 0;
while ( !(parser.cutLine("<tr><td align=\\\"center\\\" headers=\\\"ROWNUM\\\">","</tr>",fr,true) == "")){
Integer s = Integer.valueOf(parser.cutLine("<td align=\\\"center\\\" headers=\\\"ROWNUM\\\">","</td>",fr));
if(s == (i+1)) {
n = parser.cutLine("<td headers=\\\"STUDNAME\\\">", "</td>", fr);
if (!(parser.cutLine("<font color=\\\"red\\\"><b>", "</b></font>", n) == ""))
n = parser.cutLine("<font color=\\\"red\\\"><b>", "</b></font>",n);
r = parser.cutLine("<td align=\\\"center\\\" headers=\\\"STUDRATE\\\">", "</td>", fr);
r += " | Группа: " + parser.cutLine("<td headers=\\\"GROUP_NAME\\\">","</td>", fr, true);
cabinetActivity.faculty.add(new GroupList(n,"Общий балл: " + r));
i++;
}
fr = parser.cutLine("</td></tr>\\n", "", fr);
}
cabinetActivity.fillFaculty();
}
}
Loading…
Cancel
Save