You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
475 lines
18 KiB
475 lines
18 KiB
package ru.defend.defdevteam.tstu;
|
|
|
|
import android.annotation.TargetApi;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.graphics.Bitmap;
|
|
import android.graphics.BitmapFactory;
|
|
import android.net.Uri;
|
|
import android.os.AsyncTask;
|
|
import android.os.Bundle;
|
|
import android.support.annotation.NonNull;
|
|
import android.support.design.widget.FloatingActionButton;
|
|
import android.support.design.widget.Snackbar;
|
|
import android.support.v4.app.FragmentManager;
|
|
import android.support.v4.app.FragmentTransaction;
|
|
import android.util.Log;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.support.design.widget.NavigationView;
|
|
import android.support.v4.view.GravityCompat;
|
|
import android.support.v4.widget.DrawerLayout;
|
|
import android.support.v7.app.ActionBarDrawerToggle;
|
|
import android.support.v7.app.AppCompatActivity;
|
|
import android.support.v7.widget.Toolbar;
|
|
import android.view.Menu;
|
|
import android.view.MenuItem;
|
|
import android.view.ViewGroup;
|
|
import android.webkit.ValueCallback;
|
|
import android.webkit.WebSettings;
|
|
import android.webkit.WebView;
|
|
import android.webkit.WebViewClient;
|
|
import android.widget.ArrayAdapter;
|
|
import android.widget.FrameLayout;
|
|
import android.widget.ImageView;
|
|
import android.widget.LinearLayout;
|
|
import android.widget.ListView;
|
|
import android.widget.RelativeLayout;
|
|
import android.widget.TextView;
|
|
|
|
|
|
import java.io.InputStream;
|
|
import java.util.List;
|
|
|
|
|
|
public class CabinetActivity extends AppCompatActivity
|
|
implements NavigationView.OnNavigationItemSelectedListener, NewsFragment.OnFragmentInteractionListener {
|
|
|
|
|
|
static public List<GroupList> group, faculty, subs;
|
|
public WebView browser;
|
|
public WebSettings browserSet;
|
|
public String AuthURL;
|
|
public Boolean authBegin = false;
|
|
public TextView studentName, studentGroup, studentRate, positionGroup,
|
|
positionFaculty;
|
|
public RelativeLayout profileLayout, journalLayout, gRateLayout,
|
|
fRateLayout, aboutLayout, progressLayout, newsLayout;
|
|
public Toolbar myToolbar;
|
|
Intent MainA;
|
|
FeedController feedController;
|
|
OldCabinetController cabinetController;
|
|
|
|
@Override
|
|
public void onFragmentInteraction(Uri uri) {
|
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
if (convertView == null){
|
|
convertView = LayoutInflater.from(getContext()).inflate(android.R.layout.simple_list_item_2, null);
|
|
}
|
|
|
|
((TextView) convertView.findViewById(android.R.id.text1)).setText(group.name);
|
|
((TextView) convertView.findViewById(android.R.id.text2)).setText(group.rate);
|
|
|
|
return convertView;
|
|
}
|
|
|
|
}
|
|
|
|
public class subsAdapter extends ArrayAdapter<GroupList> {
|
|
public subsAdapter(Context context) {
|
|
super(context, android.R.layout.simple_selectable_list_item);
|
|
}
|
|
|
|
@NonNull
|
|
@Override
|
|
public View getView(int position, View convertView, ViewGroup parent) {
|
|
GroupList group = getItem(position);
|
|
|
|
if(convertView == null){
|
|
convertView = LayoutInflater.from(getContext()).inflate(android.R.layout.simple_selectable_list_item, null);
|
|
}
|
|
((TextView) convertView.findViewById(android.R.id.text1)).setText(group.name);
|
|
return convertView;
|
|
}
|
|
}
|
|
|
|
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);
|
|
|
|
if (convertView == null){
|
|
convertView = LayoutInflater.from(getContext()).inflate(android.R.layout.simple_list_item_2, null);
|
|
}
|
|
|
|
((TextView) convertView.findViewById(android.R.id.text1)).setText(group.name);
|
|
((TextView) convertView.findViewById(android.R.id.text2)).setText(group.rate);
|
|
|
|
return convertView;
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
setContentView(R.layout.cabinet);
|
|
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
|
setSupportActionBar(toolbar);
|
|
myToolbar = (Toolbar) findViewById(R.id.toolbar);
|
|
setSupportActionBar(myToolbar);
|
|
|
|
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
|
|
fab.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View view) {
|
|
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
|
|
.setAction("Action", null).show();
|
|
}
|
|
});
|
|
|
|
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
|
|
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
|
|
this, drawer, toolbar,R.string.navigation_drawer_open, R.string.navigation_drawer_close);
|
|
toggle.syncState();
|
|
|
|
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
|
|
navigationView.setNavigationItemSelectedListener(this);
|
|
|
|
MainA = getIntent();
|
|
|
|
browser = (WebView) findViewById(R.id.webView);
|
|
browser.setWebViewClient(new MyWebViewClient());
|
|
browserSet = browser.getSettings();
|
|
browserSet.setJavaScriptEnabled(true);
|
|
studentName = (TextView) findViewById(R.id.studentName);
|
|
studentRate = (TextView) findViewById(R.id.studentRate);
|
|
studentGroup = (TextView) findViewById(R.id.studentGroup);
|
|
positionFaculty = (TextView) findViewById(R.id.positionFaculty);
|
|
positionGroup = (TextView) findViewById(R.id.positionGroup);
|
|
profileLayout = (RelativeLayout) findViewById(R.id.profileLayout);
|
|
journalLayout = (RelativeLayout) findViewById(R.id.journalList);
|
|
gRateLayout = (RelativeLayout) findViewById(R.id.gRateLayout);
|
|
fRateLayout = (RelativeLayout) findViewById(R.id.fRateLayout);
|
|
aboutLayout = (RelativeLayout) findViewById(R.id.aboutLayout);
|
|
progressLayout = (RelativeLayout) findViewById(R.id.progressLayout);
|
|
newsLayout = (RelativeLayout) findViewById(R.id.newsLayout);
|
|
progressLayout.setVisibility(View.VISIBLE);
|
|
profileLayout.setVisibility(View.VISIBLE);
|
|
navigationView.getMenu().getItem(1).setChecked(true);
|
|
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);
|
|
}
|
|
|
|
@Override
|
|
public void onBackPressed() {
|
|
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
|
|
if (drawer.isDrawerOpen(GravityCompat.START)) {
|
|
drawer.closeDrawer(GravityCompat.START);
|
|
} else {
|
|
super.onBackPressed();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
|
getMenuInflater().inflate(R.menu.cabinet, menu);
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
int id = item.getItemId();
|
|
|
|
if (id == R.id.action_settings) {
|
|
return true;
|
|
}
|
|
if (id == R.id.action_reload_newsfeed) {
|
|
//Потом уберем :D
|
|
feedController.drawNewsList(feedController.newsItemList);
|
|
}
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
}
|
|
|
|
@Override
|
|
public boolean onNavigationItemSelected(MenuItem item) {
|
|
int id = item.getItemId();
|
|
newsLayout.setVisibility(View.INVISIBLE);
|
|
profileLayout.setVisibility(View.INVISIBLE);
|
|
journalLayout.setVisibility(View.INVISIBLE);
|
|
gRateLayout.setVisibility(View.INVISIBLE);
|
|
fRateLayout.setVisibility(View.INVISIBLE);
|
|
aboutLayout.setVisibility(View.INVISIBLE);
|
|
switch (id) {
|
|
case R.id.nav_newsfeed:
|
|
newsLayout.setVisibility(View.VISIBLE);
|
|
myToolbar.setTitle(R.string.title_newsfeed);
|
|
break;
|
|
case R.id.nav_profile:
|
|
profileLayout.setVisibility(View.VISIBLE);
|
|
myToolbar.setTitle(R.string.title_profile);
|
|
break;
|
|
case R.id.nav_journal:
|
|
journalLayout.setVisibility(View.VISIBLE);
|
|
myToolbar.setTitle(R.string.title_journal);
|
|
break;
|
|
case R.id.nav_grouprate:
|
|
gRateLayout.setVisibility(View.VISIBLE);
|
|
myToolbar.setTitle(R.string.title_grouprate);
|
|
break;
|
|
case R.id.nav_facultyrate:
|
|
fRateLayout.setVisibility(View.VISIBLE);
|
|
myToolbar.setTitle(R.string.title_globalrate);
|
|
break;
|
|
case R.id.nav_aboutapp:
|
|
aboutLayout.setVisibility(View.VISIBLE);
|
|
myToolbar.setTitle(R.string.title_about_dev);
|
|
break;
|
|
case R.id.nav_changeacc:
|
|
finish();
|
|
break;
|
|
}
|
|
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
|
|
drawer.closeDrawer(GravityCompat.START);
|
|
return true;
|
|
}
|
|
|
|
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");
|
|
String password = MainA.getStringExtra("pass");
|
|
Log.i("Auth|Login", login);
|
|
Log.i("Auth|Password", password);
|
|
//console("Auth|Password",MainActivity.password.getText().toString());
|
|
//loadSite("javascript:apex.submit({request:'LOGIN',set:{'P101_USERNAME':'s75389','P101_PASSWORD':'v97KFxmP'}});");
|
|
loadSite("javascript:apex.submit({request:'LOGIN',set:{'P101_USERNAME':'"+login+"','P101_PASSWORD':'"+password+"'}});");
|
|
return true;
|
|
}
|
|
|
|
private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
|
|
ImageView bmImage;
|
|
|
|
public DownloadImageTask(ImageView bmImage) {
|
|
this.bmImage = bmImage;
|
|
}
|
|
|
|
protected Bitmap doInBackground(String... urls) {
|
|
String urldisplay = urls[0];
|
|
Log.i("DownloadImageTask", urldisplay);
|
|
Bitmap mIcon11 = null;
|
|
try {
|
|
InputStream in = new java.net.URL(urldisplay).openStream();
|
|
mIcon11 = BitmapFactory.decodeStream(in);
|
|
} catch (Exception e) {
|
|
Log.e("Error", e.getMessage());
|
|
e.printStackTrace();
|
|
}
|
|
if(mIcon11.getWidth() > 3000 || mIcon11.getHeight() > 3000) {
|
|
mIcon11 = Bitmap.createScaledBitmap(
|
|
mIcon11,
|
|
mIcon11.getWidth()/4,
|
|
mIcon11.getHeight()/4,
|
|
false
|
|
);
|
|
}
|
|
return mIcon11;
|
|
}
|
|
|
|
protected void onPostExecute(Bitmap result) {
|
|
bmImage.setImageBitmap(result);
|
|
}
|
|
}
|
|
|
|
public int addNewsItem(NewsItemGroup group, Boolean LastItem) {
|
|
String title = group.getTitle();
|
|
String text = group.getText();
|
|
String link = group.getLink();
|
|
int viewId = group.getViewID();
|
|
LayoutInflater inflater = getLayoutInflater();
|
|
LinearLayout newsFeed = (LinearLayout) findViewById(R.id.newsfeed_scroll);
|
|
View layout;
|
|
if(LastItem) {
|
|
layout = inflater.inflate(R.layout.cabinet_newsfeed_lastitem, null);
|
|
} else {
|
|
layout = inflater.inflate(R.layout.cabinet_newsfeed_item, null);
|
|
}
|
|
newsFeed.addView(layout);
|
|
layout.setId(viewId);
|
|
layout.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View v) {
|
|
OnNewsItemClick(v);
|
|
}
|
|
});
|
|
|
|
TextView titleTextView = (TextView) layout.findViewById(R.id.newsfeed_item_title);
|
|
titleTextView.setText(title);
|
|
|
|
TextView textView = (TextView) layout.findViewById(R.id.newsfeed_item_text);
|
|
textView.setText(text);
|
|
if(!link.equals("")) {
|
|
new DownloadImageTask((ImageView) layout.findViewById(R.id.newsfeed_item_image))
|
|
.execute(link);
|
|
}
|
|
return layout.getId();
|
|
}
|
|
|
|
public void OnNewsItemClick(View v) {
|
|
NewsItemList newsItemList = feedController.newsItemList;
|
|
NewsItemGroup group = newsItemList.getGroupByViewId(v.getId());
|
|
Log.i("ERROR DEBUG", "" +v.getId());
|
|
FragmentManager fragmentManager = getSupportFragmentManager();
|
|
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
|
|
NewsFragment newsFragment = new NewsFragment().newInstance(group);
|
|
fragmentTransaction.add(R.id.newsfeeder, newsFragment);
|
|
fragmentTransaction.commit();
|
|
// RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.newsfeeder);
|
|
// View layout = getLayoutInflater().inflate(R.layout.cabinet_newsfeed_floatingitem, relativeLayout, false);
|
|
// relativeLayout.addView(layout);
|
|
//
|
|
|
|
// try {
|
|
// Log.i("ERROR DEBUG", "CLICK CLACK");
|
|
// TextView textView = (TextView) layout.findViewById(R.id.floatingnews_title);
|
|
// NewsItemList newsItemList = feedController.newsItemList;
|
|
// textView.setText(newsItemList.getGroupByViewId(v.getId()).getTitle());
|
|
// TextView textView1 = (TextView) layout.findViewById(R.id.floatingnews_content);
|
|
// textView1.setText(newsItemList.getGroupByViewId(v.getId()).getText());
|
|
//
|
|
// FrameLayout frameLayout = (FrameLayout) findViewById(R.id.floatingitem_first);
|
|
// LinearLayout linearLayout = (LinearLayout) findViewById(R.id.floatingitem_second);
|
|
// View.OnClickListener regionOnClickListner = new View.OnClickListener() {
|
|
// @Override
|
|
// public void onClick(View v) {
|
|
// v.setVisibility(View.GONE);
|
|
// LinearLayout linearLayout = (LinearLayout) findViewById(R.id.floatingitem_instance);
|
|
// linearLayout.setVisibility(View.GONE);
|
|
// }
|
|
// };
|
|
// linearLayout.setOnClickListener(regionOnClickListner);
|
|
// frameLayout.setOnClickListener(regionOnClickListner);
|
|
// } catch (Exception e) {
|
|
// e.printStackTrace();
|
|
// }
|
|
}
|
|
|
|
public void clearNewsFeed() {
|
|
LinearLayout newsFeedPage = (LinearLayout) findViewById(R.id.newsfeed_scroll);
|
|
try {
|
|
newsFeedPage.removeAllViews();
|
|
} catch (Exception e) {
|
|
|
|
}
|
|
}
|
|
|
|
public void loadSite (String url) {
|
|
browser.loadUrl(url);
|
|
}
|
|
|
|
public void setStudentName(String string){
|
|
studentName.setText(string);
|
|
}
|
|
|
|
public void setStudentGroup(String string) {
|
|
studentGroup.setText(getString(R.string.cabinet_group_name) + string);
|
|
}
|
|
|
|
public void setStudentRate(String string) {
|
|
studentRate.setText(getString(R.string.cabinet_student_rate) + string);
|
|
}
|
|
|
|
public void setProgressVisibility(Boolean visible) {
|
|
if(visible){
|
|
progressLayout.setVisibility(View.VISIBLE);
|
|
} else {
|
|
progressLayout.setVisibility(View.INVISIBLE);
|
|
}
|
|
}
|
|
|
|
public void setGroupPosition(String position) {
|
|
positionGroup.setText(getString(R.string.cabinet_group_position) + position);
|
|
}
|
|
|
|
public void setFacultyPosition(String position) {
|
|
positionFaculty.setText(getString(R.string.cabinet_faculty_position) + position);
|
|
}
|
|
|
|
public void updateGroup(){
|
|
ArrayAdapter<GroupList> groupL = new groupAdapter(this);
|
|
ListView groupList = (ListView) findViewById(R.id.groupList);
|
|
groupList.setAdapter(groupL);
|
|
}
|
|
|
|
public void updateFaculty(){
|
|
ArrayAdapter<GroupList> facultyL = new facultyAdapter(this);
|
|
ListView facultyList = (ListView) findViewById(R.id.facultyList);
|
|
facultyList.setAdapter(facultyL);
|
|
}
|
|
|
|
@TargetApi(19)
|
|
public void getHTML(){
|
|
browser.evaluateJavascript("javascript:document.documentElement.outerHTML;", new ValueCallback<String>() {
|
|
@Override
|
|
public void onReceiveValue(String s) {
|
|
cabinetController.siteBuf = s;
|
|
encodeHTML();
|
|
if(!authBegin) Auth();
|
|
else cabinetController.sessionState();
|
|
}
|
|
});
|
|
}
|
|
|
|
public String getURL(){
|
|
return browser.getUrl();
|
|
}
|
|
|
|
public void encodeHTML(){
|
|
if(cabinetController.getSiteBuffer() != null){
|
|
OldParser parser = new OldParser();
|
|
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{
|
|
@Override
|
|
public void onPageFinished(WebView view, String url) {
|
|
getHTML();
|
|
Log.i("onPageFinished", getURL());
|
|
}
|
|
}
|
|
}
|
|
|