From 5609d0fe9c42908c374781660767cae5e8edb871 Mon Sep 17 00:00:00 2001 From: Defend Date: Sat, 11 Feb 2017 02:17:02 +0300 Subject: [PATCH] REFACTORING. A lot of classes replaced o OldCabinetController. --- .../defdevteam/tstu/CabinetActivity.java | 247 +++--------------- .../ru/defend/defdevteam/tstu/GroupList.java | 13 + .../defdevteam/tstu/OldCabinetController.java | 199 ++++++++++++++ 3 files changed, 247 insertions(+), 212 deletions(-) create mode 100644 app/src/main/java/ru/defend/defdevteam/tstu/GroupList.java create mode 100644 app/src/main/java/ru/defend/defdevteam/tstu/OldCabinetController.java diff --git a/app/src/main/java/ru/defend/defdevteam/tstu/CabinetActivity.java b/app/src/main/java/ru/defend/defdevteam/tstu/CabinetActivity.java index a25a6d6..5ed6104 100644 --- a/app/src/main/java/ru/defend/defdevteam/tstu/CabinetActivity.java +++ b/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 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 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 { + public class groupAdapter extends ArrayAdapter { 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 { + public class subsAdapter extends ArrayAdapter { 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 { + public class facultyAdapter extends ArrayAdapter { 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("", - "", 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("",AdditionalHTML); - RateValueURL = "http://web-iais.admin.tstu.ru:7777/zion/" + - parser.cutLine("",AdditionalHTML); - loadSite(JournalURL); - break; - case 4: - JournalHTML = siteBuf; - loadSite(RateValueURL); - break; - case 5: - RateValueHTML = siteBuf; - String rate = parser.cutLine("","",RateValueHTML); - setStudentRate(rate); - GroupRateURL = "http://web-iais.admin.tstu.ru:7777/zion/" + parser.cutLine(">",RateValueHTML); - FacultyRateURL = "http://web-iais.admin.tstu.ru:7777/zion/" + parser.cutLine("", 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(); - String n,r; - String gr = siteBuf; - gr = parser.cutLine("

Рейтинг в группе

", "", gr); - int i = 0; - while ( !(parser.cutLine("","",gr,true) == "")){ - Integer s = Integer.valueOf(parser.cutLine("","",gr)); - if(s == (i+1)) { - n = parser.cutLine("", "", gr); - if (!(parser.cutLine("", "", n) == "")) - n = parser.cutLine("", "",n); - r = parser.cutLine("", "", gr); - r += " | Группа: " + parser.cutLine("","", gr, true); - group.add(new groupList(n,"Общий балл: " + r)); - i++; - } - gr = parser.cutLine("\\n", "", gr); - } - ArrayAdapter groupL = new groupAdapter(this); + ArrayAdapter groupL = new groupAdapter(this); ListView groupList = (ListView) findViewById(R.id.groupList); groupList.setAdapter(groupL); } - public void fillGroup(ArrayList group){ - - } - public void fillFaculty(){ - OldParser parser = new OldParser(); - faculty = new ArrayList(); - String n,r; - String fr = siteBuf; - fr = parser.cutLine("

Рейтинг в институте/факультете

", "", fr); - int i = 0; - while ( !(parser.cutLine("","",fr,true) == "")){ - Integer s = Integer.valueOf(parser.cutLine("","",fr)); - if(s == (i+1)) { - n = parser.cutLine("", "", fr); - if (!(parser.cutLine("", "", n) == "")) - n = parser.cutLine("", "",n); - r = parser.cutLine("", "", fr); - r += " | Группа: " + parser.cutLine("","", fr, true); - faculty.add(new groupList(n,"Общий балл: " + r)); - i++; - } - fr = parser.cutLine("\\n", "", fr); - } - ArrayAdapter facultyL = new facultyAdapter(this); + ArrayAdapter 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("","",GroupRateHTML); - s = parser.cutLine("",s); - while (s.equals("")) { - s2 = parser.cutLine("","",s2); - s = parser.cutLine("","",s2); - s = parser.cutLine("",s); - } - s2 = parser.cutLine("","",s2); - //***// - Log.i(getString(R.string.cabinet_group_position), s2); - //***// - setGroupPosition(s2); - s = ""; - s2 = FacultyRateHTML; - s = parser.cutLine("","",FacultyRateHTML); - s = parser.cutLine("",s); - while (s.equals("")) { - s2 = parser.cutLine("","",s2); - s = parser.cutLine("","",s2); - s = parser.cutLine("",s); - } - s2 = parser.cutLine("","",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() { @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("","",siteBuf)); - Log.i("encodeHTML",siteBuf); + cabinetController.setSiteBuffer( + OldParser.removeUTFCharacters( + cabinetController.getSiteBuffer() + ).toString() + ); + Log.d("Response html","Загружена страница "+parser.cutLine("","", 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(); diff --git a/app/src/main/java/ru/defend/defdevteam/tstu/GroupList.java b/app/src/main/java/ru/defend/defdevteam/tstu/GroupList.java new file mode 100644 index 0000000..2c1348d --- /dev/null +++ b/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; + } +} diff --git a/app/src/main/java/ru/defend/defdevteam/tstu/OldCabinetController.java b/app/src/main/java/ru/defend/defdevteam/tstu/OldCabinetController.java new file mode 100644 index 0000000..285313c --- /dev/null +++ b/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("", + "", 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("
",AdditionalHTML); + RateValueURL = "http://web-iais.admin.tstu.ru:7777/zion/" + + parser.cutLine("",AdditionalHTML); + cabinetActivity.loadSite(JournalURL); + break; + case 4: + JournalHTML = siteBuf; + cabinetActivity.loadSite(RateValueURL); + break; + case 5: + RateValueHTML = siteBuf; + String rate = parser.cutLine("","",RateValueHTML); + cabinetActivity.setStudentRate(rate); + GroupRateURL = "http://web-iais.admin.tstu.ru:7777/zion/" + parser.cutLine(">",RateValueHTML); + FacultyRateURL = "http://web-iais.admin.tstu.ru:7777/zion/" + parser.cutLine("", 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("","",GroupRateHTML); + s = parser.cutLine("",s); + while (s.equals("")) { + s2 = parser.cutLine("","",s2); + s = parser.cutLine("","",s2); + s = parser.cutLine("",s); + } + s2 = parser.cutLine("","",s2); + cabinetActivity.setGroupPosition(s2); + s = ""; + s2 = FacultyRateHTML; + s = parser.cutLine("","",FacultyRateHTML); + s = parser.cutLine("",s); + while (s.equals("")) { + s2 = parser.cutLine("","",s2); + s = parser.cutLine("","",s2); + s = parser.cutLine("",s); + } + s2 = parser.cutLine("","",s2); + cabinetActivity.setFacultyPosition(s2); + } + + public void fillGroup(){ + cabinetActivity.group = new ArrayList(); + OldParser parser = new OldParser(); + String n,r; + String gr = getSiteBuffer(); + gr = parser.cutLine("

Рейтинг в группе

", "", gr); + int i = 0; + while ( !(parser.cutLine("","",gr,true) == "")){ + Integer s = Integer.valueOf(parser.cutLine("","",gr)); + if(s == (i+1)) { + n = parser.cutLine("", "", gr); + if (!(parser.cutLine("", "", n) == "")) + n = parser.cutLine("", "",n); + r = parser.cutLine("", "", gr); + r += " | Группа: " + parser.cutLine("","", gr, true); + cabinetActivity.group.add(new GroupList(n,"Общий балл: " + r)); + i++; + } + gr = parser.cutLine("\\n", "", gr); + } + cabinetActivity.fillGroup(); + } + + public void fillFaculty(){ + OldParser parser = new OldParser(); + cabinetActivity.faculty = new ArrayList(); + String n,r; + String fr = getSiteBuffer(); + fr = parser.cutLine("

Рейтинг в институте/факультете

", "", fr); + int i = 0; + while ( !(parser.cutLine("","",fr,true) == "")){ + Integer s = Integer.valueOf(parser.cutLine("","",fr)); + if(s == (i+1)) { + n = parser.cutLine("", "", fr); + if (!(parser.cutLine("", "", n) == "")) + n = parser.cutLine("", "",n); + r = parser.cutLine("", "", fr); + r += " | Группа: " + parser.cutLine("","", fr, true); + cabinetActivity.faculty.add(new GroupList(n,"Общий балл: " + r)); + i++; + } + fr = parser.cutLine("\\n", "", fr); + } + cabinetActivity.fillFaculty(); + } +}