mirror of
https://github.com/wulkanowy/wulkanowy.git
synced 2025-01-31 13:28:21 +01:00
Code style fixes
This commit is contained in:
parent
e845fc1f15
commit
a7cd6e7983
228
.idea/codeStyleSettings.xml
generated
Normal file
228
.idea/codeStyleSettings.xml
generated
Normal file
@ -0,0 +1,228 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectCodeStyleSettingsManager">
|
||||
<option name="PER_PROJECT_SETTINGS">
|
||||
<value>
|
||||
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="99" />
|
||||
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="99" />
|
||||
<option name="PACKAGES_TO_USE_IMPORT_ON_DEMAND">
|
||||
<value />
|
||||
</option>
|
||||
<option name="IMPORT_LAYOUT_TABLE">
|
||||
<value>
|
||||
<package name="android" withSubpackages="true" static="false" />
|
||||
<emptyLine />
|
||||
<package name="com" withSubpackages="true" static="false" />
|
||||
<emptyLine />
|
||||
<package name="junit" withSubpackages="true" static="false" />
|
||||
<emptyLine />
|
||||
<package name="net" withSubpackages="true" static="false" />
|
||||
<emptyLine />
|
||||
<package name="org" withSubpackages="true" static="false" />
|
||||
<emptyLine />
|
||||
<package name="java" withSubpackages="true" static="false" />
|
||||
<emptyLine />
|
||||
<package name="javax" withSubpackages="true" static="false" />
|
||||
<emptyLine />
|
||||
<package name="" withSubpackages="true" static="false" />
|
||||
<emptyLine />
|
||||
<package name="" withSubpackages="true" static="true" />
|
||||
<emptyLine />
|
||||
</value>
|
||||
</option>
|
||||
<option name="RIGHT_MARGIN" value="100" />
|
||||
<AndroidXmlCodeStyleSettings>
|
||||
<option name="USE_CUSTOM_SETTINGS" value="true" />
|
||||
</AndroidXmlCodeStyleSettings>
|
||||
<Objective-C-extensions>
|
||||
<file>
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Import" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Macro" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Typedef" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Enum" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Constant" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Global" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Struct" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="FunctionPredecl" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Function" />
|
||||
</file>
|
||||
<class>
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Property" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Synthesize" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InitMethod" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="StaticMethod" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InstanceMethod" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="DeallocMethod" />
|
||||
</class>
|
||||
<extensions>
|
||||
<pair source="cpp" header="h" />
|
||||
<pair source="c" header="h" />
|
||||
</extensions>
|
||||
</Objective-C-extensions>
|
||||
<XML>
|
||||
<option name="XML_KEEP_LINE_BREAKS" value="false" />
|
||||
<option name="XML_ALIGN_ATTRIBUTES" value="false" />
|
||||
<option name="XML_SPACE_INSIDE_EMPTY_TAG" value="true" />
|
||||
</XML>
|
||||
<codeStyleSettings language="XML">
|
||||
<option name="FORCE_REARRANGE_MODE" value="1" />
|
||||
<indentOptions>
|
||||
<option name="CONTINUATION_INDENT_SIZE" value="4" />
|
||||
</indentOptions>
|
||||
<arrangement>
|
||||
<rules>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>xmlns:android</NAME>
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>xmlns:.*</NAME>
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:id</NAME>
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:name</NAME>
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>name</NAME>
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>style</NAME>
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:layout_width</NAME>
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:layout_height</NAME>
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:layout_.*</NAME>
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:width</NAME>
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:height</NAME>
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_NAMESPACE>.*</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
</rules>
|
||||
</arrangement>
|
||||
</codeStyleSettings>
|
||||
</value>
|
||||
</option>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="AndroidStyle" />
|
||||
</component>
|
||||
</project>
|
@ -1,5 +1,7 @@
|
||||
package io.github.wulkanowy;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.test.InstrumentationRegistry;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
@ -7,8 +9,6 @@ import android.support.test.runner.AndroidJUnit4;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Instrumentation test, which will execute on an Android device.
|
||||
*
|
||||
|
@ -1,6 +1,5 @@
|
||||
package io.github.wulkanowy.activity.dashboard;
|
||||
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.BottomNavigationView;
|
||||
@ -11,18 +10,15 @@ import android.view.MenuItem;
|
||||
import io.github.wulkanowy.R;
|
||||
import io.github.wulkanowy.activity.dashboard.attendance.AttendanceFragment;
|
||||
import io.github.wulkanowy.activity.dashboard.board.BoardFragment;
|
||||
import io.github.wulkanowy.activity.dashboard.lessonplan.LessonplanFragment;
|
||||
import io.github.wulkanowy.activity.dashboard.lessonplan.LessonPlanFragment;
|
||||
import io.github.wulkanowy.activity.dashboard.marks.MarksFragment;
|
||||
|
||||
|
||||
public class DashboardActivity extends AppCompatActivity {
|
||||
|
||||
|
||||
private MarksFragment marksFragment = new MarksFragment();
|
||||
private AttendanceFragment attendanceFragment = new AttendanceFragment();
|
||||
private BoardFragment boardFragment = new BoardFragment();
|
||||
private LessonplanFragment lessonplanFragment = new LessonplanFragment();
|
||||
|
||||
private LessonPlanFragment lessonPlanFragment = new LessonPlanFragment();
|
||||
|
||||
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
|
||||
= new BottomNavigationView.OnNavigationItemSelectedListener() {
|
||||
@ -38,28 +34,26 @@ public class DashboardActivity extends AppCompatActivity {
|
||||
transaction.replace(R.id.fragment_container, marksFragment);
|
||||
transaction.commit();
|
||||
return true;
|
||||
|
||||
case R.id.navigation_attendance:
|
||||
setTitle(R.string.title_attendance);
|
||||
transaction.replace(R.id.fragment_container, attendanceFragment);
|
||||
transaction.commit();
|
||||
return true;
|
||||
|
||||
case R.id.navigation_lessonplan:
|
||||
setTitle(R.string.title_lessonplan);
|
||||
transaction.replace(R.id.fragment_container, lessonPlanFragment);
|
||||
transaction.commit();
|
||||
return true;
|
||||
|
||||
case R.id.navigation_dashboard:
|
||||
default:
|
||||
setTitle(R.string.title_dashboard);
|
||||
transaction.replace(R.id.fragment_container, boardFragment);
|
||||
transaction.commit();
|
||||
return true;
|
||||
case R.id.navigation_lessonplan:
|
||||
setTitle(R.string.title_lessonplan);
|
||||
transaction.replace(R.id.fragment_container, lessonplanFragment);
|
||||
transaction.commit();
|
||||
return true;
|
||||
/*
|
||||
case R.id.navigation_settings:
|
||||
|
||||
return true;
|
||||
*/
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
@ -83,15 +77,9 @@ public class DashboardActivity extends AppCompatActivity {
|
||||
BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
|
||||
|
||||
if (navigation.getSelectedItemId() != R.id.navigation_dashboard) {
|
||||
|
||||
navigation.setSelectedItemId(R.id.navigation_dashboard);
|
||||
|
||||
}
|
||||
|
||||
else if (navigation.getSelectedItemId() == R.id.navigation_dashboard){
|
||||
|
||||
} else if (navigation.getSelectedItemId() == R.id.navigation_dashboard) {
|
||||
moveTaskToBack(true);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package io.github.wulkanowy.activity.dashboard.attendance;
|
||||
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
@ -11,15 +10,12 @@ import io.github.wulkanowy.R;
|
||||
|
||||
public class AttendanceFragment extends Fragment {
|
||||
|
||||
|
||||
public AttendanceFragment() {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.fragment_attendance, container, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package io.github.wulkanowy.activity.dashboard.board;
|
||||
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
@ -11,15 +10,12 @@ import io.github.wulkanowy.R;
|
||||
|
||||
public class BoardFragment extends Fragment {
|
||||
|
||||
|
||||
public BoardFragment() {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.fragment_board, container, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package io.github.wulkanowy.activity.dashboard.lessonplan;
|
||||
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
@ -9,17 +8,14 @@ import android.view.ViewGroup;
|
||||
|
||||
import io.github.wulkanowy.R;
|
||||
|
||||
public class LessonplanFragment extends Fragment {
|
||||
public class LessonPlanFragment extends Fragment {
|
||||
|
||||
|
||||
public LessonplanFragment() {
|
||||
public LessonPlanFragment() {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.fragment_lessonplan, container, false);
|
||||
}
|
||||
|
||||
}
|
@ -17,26 +17,27 @@ import io.github.wulkanowy.R;
|
||||
public class ImageAdapter extends RecyclerView.Adapter<ImageAdapter.ViewHolder> {
|
||||
|
||||
private Context context;
|
||||
private ArrayList<String> lista;
|
||||
private ArrayList<String> list;
|
||||
|
||||
public ImageAdapter(Context context, ArrayList<String> lista) {
|
||||
this.lista = lista;
|
||||
public ImageAdapter(Context context, ArrayList<String> list) {
|
||||
this.list = list;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImageAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
|
||||
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.row_layout, viewGroup, false);
|
||||
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.row_layout,
|
||||
viewGroup, false);
|
||||
return new ViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(ImageAdapter.ViewHolder viewHolder, int i) {
|
||||
|
||||
viewHolder.tv_android.setText(lista.get(i));
|
||||
viewHolder.tv_android.setText(list.get(i));
|
||||
Picasso.with(context)
|
||||
.load(R.drawable.sample_0)
|
||||
.resize(240,120)
|
||||
.resize(240, 120)
|
||||
.noFade()
|
||||
.into(viewHolder.img_android);
|
||||
|
||||
@ -44,18 +45,19 @@ public class ImageAdapter extends RecyclerView.Adapter<ImageAdapter.ViewHolder>
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return lista.size();
|
||||
return list.size();
|
||||
}
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder{
|
||||
public class ViewHolder extends RecyclerView.ViewHolder {
|
||||
private TextView tv_android;
|
||||
private ImageView img_android;
|
||||
|
||||
public ViewHolder(View view) {
|
||||
super(view);
|
||||
|
||||
tv_android = (TextView)view.findViewById(R.id.tv_android);
|
||||
tv_android = (TextView) view.findViewById(R.id.tv_android);
|
||||
img_android = (ImageView) view.findViewById(R.id.img_android);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,10 @@ import java.util.Map;
|
||||
|
||||
import io.github.wulkanowy.R;
|
||||
import io.github.wulkanowy.api.Cookies;
|
||||
import io.github.wulkanowy.api.grades.*;
|
||||
import io.github.wulkanowy.api.grades.Grade;
|
||||
import io.github.wulkanowy.api.grades.GradesList;
|
||||
import io.github.wulkanowy.api.grades.Subject;
|
||||
import io.github.wulkanowy.api.grades.SubjectsList;
|
||||
|
||||
public class MarksFragment extends Fragment {
|
||||
|
||||
@ -31,9 +34,10 @@ public class MarksFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
Bundle savedInstanceState) {
|
||||
|
||||
view = inflater.inflate(R.layout.fragment_marks, container, false);
|
||||
|
||||
if (subject.size() == 0) {
|
||||
new MarksTask(container.getContext()).execute();
|
||||
} else if (subject.size() > 1) {
|
||||
@ -44,14 +48,14 @@ public class MarksFragment extends Fragment {
|
||||
return view;
|
||||
}
|
||||
|
||||
public void createGrid(){
|
||||
public void createGrid() {
|
||||
|
||||
RecyclerView recyclerView = (RecyclerView)view.findViewById(R.id.card_recycler_view);
|
||||
RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.card_recycler_view);
|
||||
recyclerView.setHasFixedSize(true);
|
||||
RecyclerView.LayoutManager layoutManager = new GridLayoutManager(view.getContext(),2);
|
||||
RecyclerView.LayoutManager layoutManager = new GridLayoutManager(view.getContext(), 2);
|
||||
recyclerView.setLayoutManager(layoutManager);
|
||||
|
||||
ImageAdapter adapter = new ImageAdapter(view.getContext(),subject);
|
||||
ImageAdapter adapter = new ImageAdapter(view.getContext(), subject);
|
||||
recyclerView.setAdapter(adapter);
|
||||
}
|
||||
|
||||
@ -80,13 +84,13 @@ public class MarksFragment extends Fragment {
|
||||
cookies.setItems(loginCookies);
|
||||
SubjectsList subjectsList = new SubjectsList(cookies, "powiatjaroslawski");
|
||||
List<Subject> subjects = subjectsList.getAll();
|
||||
for (Subject item : subjects){
|
||||
for (Subject item : subjects) {
|
||||
subject.add(item.getName());
|
||||
}
|
||||
|
||||
GradesList gradesList = new GradesList(cookies, "powiatjaroslawski");
|
||||
List<Grade> grades = gradesList.getAll();
|
||||
for (Grade item : grades){
|
||||
for (Grade item : grades) {
|
||||
System.out.println(item.getSubject() + ": " + item.getValue());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
@ -27,14 +27,15 @@ public class LoginTask extends AsyncTask<String, Integer, Integer> {
|
||||
|
||||
private Activity activity;
|
||||
|
||||
private ProgressDialog progress;
|
||||
|
||||
private boolean save;
|
||||
|
||||
public LoginTask(Activity context, boolean save) {
|
||||
activity = context;
|
||||
progress = new ProgressDialog(activity);
|
||||
private ProgressDialog progress;
|
||||
|
||||
public LoginTask(Activity activity, boolean save) {
|
||||
this.activity = activity;
|
||||
this.save = save;
|
||||
|
||||
this.progress = new ProgressDialog(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -74,7 +75,8 @@ public class LoginTask extends AsyncTask<String, Integer, Integer> {
|
||||
|
||||
if (save) {
|
||||
try {
|
||||
BasicInformation userInfo = new BasicInformation(login.getCookies(), credentials[2]);
|
||||
BasicInformation userInfo = new BasicInformation(login.getCookies(),
|
||||
credentials[2]);
|
||||
PersonalData personalData = userInfo.getPersonalData();
|
||||
String firstAndLastName = personalData.getFirstAndLastName();
|
||||
|
||||
@ -107,7 +109,7 @@ public class LoginTask extends AsyncTask<String, Integer, Integer> {
|
||||
|
||||
Toast.makeText(activity, activity.getString(messageID), Toast.LENGTH_LONG).show();
|
||||
|
||||
if (messageID == R.string.login_accepted){
|
||||
if (messageID == R.string.login_accepted) {
|
||||
Intent intent = new Intent(activity, DashboardActivity.class);
|
||||
activity.startActivity(intent);
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
.setMessage(R.string.warning_text)
|
||||
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
})
|
||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||
@ -47,22 +48,22 @@ public class MainActivity extends AppCompatActivity {
|
||||
// Get the string array
|
||||
String[] countries = getResources().getStringArray(R.array.counties);
|
||||
// Create the adapter and set it to the AutoCompleteTextView
|
||||
ArrayAdapter<String> adapter =
|
||||
new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, countries);
|
||||
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1,
|
||||
countries);
|
||||
textView.setAdapter(adapter);
|
||||
}
|
||||
|
||||
public void login(View a) {
|
||||
EditText adressEmail = (EditText) findViewById(R.id.emailText);
|
||||
EditText emailText = (EditText) findViewById(R.id.emailText);
|
||||
EditText passwordText = (EditText) findViewById(R.id.passwordText);
|
||||
EditText countyText = (EditText) findViewById(R.id.countyText);
|
||||
String password = passwordText.getText().toString();
|
||||
String email = adressEmail.getText().toString();
|
||||
String email = emailText.getText().toString();
|
||||
String county = countyText.getText().toString();
|
||||
|
||||
String[] keys = this.getResources().getStringArray(R.array.counties);
|
||||
String[] values = this.getResources().getStringArray(R.array.counties_values);
|
||||
LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
|
||||
LinkedHashMap<String, String> map = new LinkedHashMap<>();
|
||||
|
||||
for (int i = 0; i < Math.min(keys.length, values.length); ++i) {
|
||||
map.put(keys[i], values[i]);
|
||||
@ -73,7 +74,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
if (!email.isEmpty() && !password.isEmpty() && !county.isEmpty()) {
|
||||
new LoginTask(this,true).execute(email, password, county);
|
||||
new LoginTask(this, true).execute(email, password, county);
|
||||
} else {
|
||||
Toast.makeText(this, R.string.data_text, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
@ -88,20 +89,25 @@ public class MainActivity extends AppCompatActivity {
|
||||
if (ev.getAction() == MotionEvent.ACTION_UP) {
|
||||
mReleasePosition = ev.getY();
|
||||
|
||||
if (mTouchPosition - mReleasePosition == 0 ) {
|
||||
if (mTouchPosition - mReleasePosition == 0) {
|
||||
View view = getCurrentFocus();
|
||||
if (view != null && (ev.getAction() == MotionEvent.ACTION_UP || ev.getAction() == MotionEvent.ACTION_MOVE) && view instanceof EditText && !view.getClass().getName().startsWith("android.webkit.")) {
|
||||
if (view != null && (ev.getAction() == MotionEvent.ACTION_UP
|
||||
|| ev.getAction() == MotionEvent.ACTION_MOVE) && view instanceof EditText
|
||||
&& !view.getClass().getName().startsWith("android.webkit.")) {
|
||||
|
||||
int scrcoords[] = new int[2];
|
||||
view.getLocationOnScreen(scrcoords);
|
||||
float x = ev.getRawX() + view.getLeft() - scrcoords[0];
|
||||
float y = ev.getRawY() + view.getTop() - scrcoords[1];
|
||||
if (x < view.getLeft() || x > view.getRight() || y < view.getTop() || y > view.getBottom()) {
|
||||
((InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow((this.getWindow().getDecorView().getApplicationWindowToken()), 0);
|
||||
if (x < view.getLeft() || x > view.getRight() || y < view.getTop()
|
||||
|| y > view.getBottom()) {
|
||||
((InputMethodManager) this.getSystemService(
|
||||
Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(
|
||||
(this.getWindow().getDecorView().getApplicationWindowToken()), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.dispatchTouchEvent(ev);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package io.github.wulkanowy.activity.started;
|
||||
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.database.SQLException;
|
||||
@ -20,11 +19,10 @@ import io.github.wulkanowy.database.accounts.DatabaseAccount;
|
||||
|
||||
public class LoadingTask extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
private final boolean SAVE_DATA = true;
|
||||
private Activity activity;
|
||||
private boolean isOnline;
|
||||
|
||||
private final boolean SAVE_DATA = true;
|
||||
|
||||
LoadingTask(Activity main) {
|
||||
activity = main;
|
||||
}
|
||||
@ -47,23 +45,23 @@ public class LoadingTask extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
protected void onPostExecute(Void result) {
|
||||
|
||||
if (isOnline) {
|
||||
signIn();
|
||||
} else{
|
||||
Intent intent = new Intent(activity, MainActivity.class);
|
||||
activity.startActivity(intent);
|
||||
if (isOnline) {
|
||||
signIn();
|
||||
} else {
|
||||
Intent intent = new Intent(activity, MainActivity.class);
|
||||
activity.startActivity(intent);
|
||||
|
||||
Toast.makeText(activity,R.string.noInternet_text,Toast.LENGTH_SHORT ).show();
|
||||
}
|
||||
Toast.makeText(activity, R.string.noInternet_text, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isOnline() {
|
||||
try {
|
||||
int timeoutMs = 1500;
|
||||
Socket sock = new Socket();
|
||||
SocketAddress sockaddr = new InetSocketAddress("8.8.8.8", 53);
|
||||
SocketAddress address = new InetSocketAddress("8.8.8.8", 53);
|
||||
|
||||
sock.connect(sockaddr, timeoutMs);
|
||||
sock.connect(address, timeoutMs);
|
||||
sock.close();
|
||||
|
||||
return true;
|
||||
@ -72,22 +70,28 @@ public class LoadingTask extends AsyncTask<Void, Void, Void> {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean signIn(){
|
||||
private boolean signIn() {
|
||||
|
||||
if (SAVE_DATA) {
|
||||
|
||||
DatabaseAccount databaseAccount = new DatabaseAccount(activity);
|
||||
|
||||
if (databaseAccount.checkExist()) {
|
||||
try {
|
||||
AccountData accountData = databaseAccount.getAccount(1);
|
||||
databaseAccount.close();
|
||||
|
||||
if (accountData != null) {
|
||||
new LoginTask(activity, false).execute(accountData.getEmail(), accountData.getPassword(), accountData.getCounty());
|
||||
new LoginTask(activity, false).execute(
|
||||
accountData.getEmail(),
|
||||
accountData.getPassword(),
|
||||
accountData.getCounty()
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
} catch (SQLException e){
|
||||
Toast.makeText(activity,R.string.SQLite_ioError_text,Toast.LENGTH_LONG ).show();
|
||||
} catch (SQLException e) {
|
||||
Toast.makeText(activity, R.string.SQLite_ioError_text,
|
||||
Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,10 +11,6 @@ public class StartedActivity extends AppCompatActivity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_started);
|
||||
Task();
|
||||
}
|
||||
|
||||
public void Task(){
|
||||
|
||||
new LoadingTask(this).execute();
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ public class StudentAndParent extends Vulcan {
|
||||
public StudentAndParent(Cookies cookies, String locID) throws IOException {
|
||||
super(cookies);
|
||||
|
||||
locationID = locID;
|
||||
this.locationID = locID;
|
||||
|
||||
setUp();
|
||||
}
|
||||
|
@ -16,73 +16,73 @@ public class Grade {
|
||||
|
||||
private String teacher;
|
||||
|
||||
public String getSubject() {
|
||||
return subject;
|
||||
}
|
||||
|
||||
public Grade setSubject(String subject) {
|
||||
this.subject = subject;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public Grade setValue(String value) {
|
||||
this.value = value;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public Grade setColor(String color) {
|
||||
this.color = color;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public Grade setDescription(String description) {
|
||||
this.description = description;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getWeight() {
|
||||
return weight;
|
||||
}
|
||||
|
||||
public Grade setWeight(String weight) {
|
||||
this.weight = weight;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public Grade setDate(String date) {
|
||||
this.date = date;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getTeacher() {
|
||||
return teacher;
|
||||
}
|
||||
|
||||
public Grade setTeacher(String teacher) {
|
||||
this.teacher = teacher;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getSubject() {
|
||||
return subject;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public String getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public String getWeight() {
|
||||
return weight;
|
||||
}
|
||||
|
||||
public String getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public String getTeacher() {
|
||||
return teacher;
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,8 @@ import io.github.wulkanowy.api.login.LoginErrorException;
|
||||
|
||||
public class GradesList extends StudentAndParent {
|
||||
|
||||
private String gradesPageUrl = "https://uonetplus-opiekun.vulcan.net.pl/{locationID}/{ID}/Oceny/Wszystkie?details=2";
|
||||
private String gradesPageUrl =
|
||||
"https://uonetplus-opiekun.vulcan.net.pl/{locationID}/{ID}/Oceny/Wszystkie?details=2";
|
||||
|
||||
private List<Grade> grades = new ArrayList<>();
|
||||
|
||||
@ -37,7 +38,8 @@ public class GradesList extends StudentAndParent {
|
||||
|
||||
for (Element row : marksRows) {
|
||||
Pattern pattern = Pattern.compile("#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})");
|
||||
Matcher matcher = pattern.matcher(row.select("td:nth-child(2) span.ocenaCzastkowa").attr("style"));
|
||||
Matcher matcher = pattern.matcher(
|
||||
row.select("td:nth-child(2) span.ocenaCzastkowa").attr("style"));
|
||||
String color;
|
||||
if (!matcher.find()) {
|
||||
color = "000000";
|
||||
|
@ -6,33 +6,33 @@ public class Subject {
|
||||
private String predictedRating;
|
||||
private String finalRating;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Subject setName(String name) {
|
||||
this.name = name;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getPredictedRating() {
|
||||
return predictedRating;
|
||||
}
|
||||
|
||||
public Subject setPredictedRating(String predictedRating) {
|
||||
this.predictedRating = predictedRating;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getFinalRating() {
|
||||
return finalRating;
|
||||
}
|
||||
|
||||
public Subject setFinalRating(String finalRating) {
|
||||
this.finalRating = finalRating;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getPredictedRating() {
|
||||
return predictedRating;
|
||||
}
|
||||
|
||||
public String getFinalRating() {
|
||||
return finalRating;
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,8 @@ import io.github.wulkanowy.api.login.LoginErrorException;
|
||||
|
||||
public class SubjectsList extends StudentAndParent {
|
||||
|
||||
private String subjectsPageUrl = "https://uonetplus-opiekun.vulcan.net.pl/{locationID}/{ID}/Oceny/Wszystkie?details=1";
|
||||
private String subjectsPageUrl =
|
||||
"https://uonetplus-opiekun.vulcan.net.pl/{locationID}/{ID}/Oceny/Wszystkie?details=1";
|
||||
|
||||
private List<Subject> subjects = new ArrayList<>();
|
||||
|
||||
@ -33,7 +34,7 @@ public class SubjectsList extends StudentAndParent {
|
||||
|
||||
Elements rows = subjectPage.select(".ocenyZwykle-table > tbody > tr");
|
||||
|
||||
for (Element subjectRow : rows){
|
||||
for (Element subjectRow : rows) {
|
||||
subjects.add(new Subject()
|
||||
.setName(subjectRow.select("td:nth-child(1)").text())
|
||||
.setPredictedRating(subjectRow.select("td:nth-child(3)").text())
|
||||
|
@ -13,15 +13,21 @@ public class Login extends Vulcan {
|
||||
|
||||
private String loginPageUrl = "https://cufs.vulcan.net.pl/{locationID}/Account/LogOn";
|
||||
|
||||
private String certificatePageUrl = "https://cufs.vulcan.net.pl/{locationID}/FS/LS?wa=wsignin1.0&wtrealm=https://uonetplus.vulcan.net.pl/{locationID}/LoginEndpoint.aspx&wctx=https://uonetplus.vulcan.net.pl/{locationID}/LoginEndpoint.aspx";
|
||||
private String certificatePageUrl =
|
||||
"https://cufs.vulcan.net.pl/"
|
||||
+ "{locationID}/FS/LS?wa=wsignin1.0&wtrealm=https://uonetplus.vulcan.net.pl/"
|
||||
+ "{locationID}/LoginEndpoint.aspx&wctx=https://uonetplus.vulcan.net.pl/"
|
||||
+ "{locationID}/LoginEndpoint.aspx";
|
||||
|
||||
private String loginEndpointPageUrl = "https://uonetplus.vulcan.net.pl/{locationID}/LoginEndpoint.aspx";
|
||||
private String loginEndpointPageUrl =
|
||||
"https://uonetplus.vulcan.net.pl/{locationID}/LoginEndpoint.aspx";
|
||||
|
||||
public Login(Cookies cookies) {
|
||||
super(cookies);
|
||||
}
|
||||
|
||||
public boolean login(String email, String password, String county) throws BadCredentialsException, LoginErrorException, AccountPermissionException {
|
||||
public boolean login(String email, String password, String county)
|
||||
throws BadCredentialsException, LoginErrorException, AccountPermissionException {
|
||||
try {
|
||||
sendCredentials(email, password, county);
|
||||
String[] certificate = getCertificateData(county);
|
||||
@ -33,7 +39,8 @@ public class Login extends Vulcan {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void sendCredentials(String email, String password, String county) throws IOException, BadCredentialsException {
|
||||
private void sendCredentials(String email, String password, String county)
|
||||
throws IOException, BadCredentialsException {
|
||||
loginPageUrl = loginPageUrl.replace("{locationID}", county);
|
||||
|
||||
Connection.Response response = Jsoup.connect(loginPageUrl)
|
||||
@ -57,13 +64,14 @@ public class Login extends Vulcan {
|
||||
.cookies(getJar())
|
||||
.get();
|
||||
|
||||
return new String[] {
|
||||
return new String[]{
|
||||
certificatePage.select("input[name=wa]").attr("value"),
|
||||
certificatePage.select("input[name=wresult]").attr("value")
|
||||
};
|
||||
}
|
||||
|
||||
private void sendCertificate(String protocolVersion, String certificate, String county) throws IOException, LoginErrorException, AccountPermissionException {
|
||||
private void sendCertificate(String protocolVersion, String certificate, String county)
|
||||
throws IOException, LoginErrorException, AccountPermissionException {
|
||||
loginEndpointPageUrl = loginEndpointPageUrl.replace("{locationID}", county);
|
||||
|
||||
Connection.Response response = Jsoup.connect(loginEndpointPageUrl)
|
||||
@ -77,7 +85,7 @@ public class Login extends Vulcan {
|
||||
setCookies(response.cookies());
|
||||
Document html = response.parse();
|
||||
|
||||
if(html.getElementsByTag("title").text().equals("Logowanie")) {
|
||||
if (html.getElementsByTag("title").text().equals("Logowanie")) {
|
||||
throw new AccountPermissionException();
|
||||
}
|
||||
|
||||
|
@ -8,33 +8,33 @@ public class AddressData {
|
||||
|
||||
private String correspondenceAddress;
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public AddressData setAddress(String address) {
|
||||
this.address = address;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getRegisteredAddress() {
|
||||
return registeredAddress;
|
||||
}
|
||||
|
||||
public AddressData setRegisteredAddress(String registeredAddress) {
|
||||
this.registeredAddress = registeredAddress;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getCorrespondenceAddress() {
|
||||
return correspondenceAddress;
|
||||
}
|
||||
|
||||
public AddressData setCorrespondenceAddress(String correspondenceAddress) {
|
||||
this.correspondenceAddress = correspondenceAddress;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public String getRegisteredAddress() {
|
||||
return registeredAddress;
|
||||
}
|
||||
|
||||
public String getCorrespondenceAddress() {
|
||||
return correspondenceAddress;
|
||||
}
|
||||
}
|
||||
|
@ -12,11 +12,13 @@ import io.github.wulkanowy.api.login.LoginErrorException;
|
||||
|
||||
public class BasicInformation extends StudentAndParent {
|
||||
|
||||
private String studentDataPageUrl = "https://uonetplus-opiekun.vulcan.net.pl/{locationID}/{ID}/Uczen.mvc/DanePodstawowe";
|
||||
private String studentDataPageUrl =
|
||||
"https://uonetplus-opiekun.vulcan.net.pl/{locationID}/{ID}/Uczen.mvc/DanePodstawowe";
|
||||
|
||||
private Document studentDataPageDocument;
|
||||
|
||||
public BasicInformation(Cookies cookies, String locationID) throws IOException, LoginErrorException {
|
||||
public BasicInformation(Cookies cookies, String locationID)
|
||||
throws IOException, LoginErrorException {
|
||||
super(cookies, locationID);
|
||||
|
||||
studentDataPageDocument = getPage();
|
||||
|
@ -8,30 +8,30 @@ public class ContactDetails {
|
||||
|
||||
private String email;
|
||||
|
||||
public String getPhoneNumber() {
|
||||
return phoneNumber;
|
||||
}
|
||||
|
||||
public ContactDetails setPhoneNumber(String phoneNumber) {
|
||||
this.phoneNumber = phoneNumber;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getCellPhoneNumber() {
|
||||
return cellPhoneNumber;
|
||||
}
|
||||
|
||||
public ContactDetails setCellPhoneNumber(String cellPhoneNumber) {
|
||||
this.cellPhoneNumber = cellPhoneNumber;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public ContactDetails setEmail(String email) {
|
||||
this.email = email;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getPhoneNumber() {
|
||||
return phoneNumber;
|
||||
}
|
||||
|
||||
public String getCellPhoneNumber() {
|
||||
return cellPhoneNumber;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
}
|
||||
|
@ -16,52 +16,16 @@ public class PersonalData {
|
||||
|
||||
private String parentsNames;
|
||||
|
||||
public String getNames() {
|
||||
return names;
|
||||
}
|
||||
|
||||
public PersonalData setNames(String names) {
|
||||
this.names = names;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public PersonalData setDateAndBirthPlace(String dateAndBirthPlace) {
|
||||
this.dateAndBirthPlace = dateAndBirthPlace;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public PersonalData setPesel(String pesel) {
|
||||
this.pesel = pesel;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public PersonalData setGender(String gender) {
|
||||
this.gender = gender;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public PersonalData setPolishCitizenship(String polishCitizenship) {
|
||||
isPolishCitizenship = polishCitizenship;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public PersonalData setFamilyName(String familyName) {
|
||||
this.familyName = familyName;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public PersonalData setParentsNames(String parentsNames) {
|
||||
this.parentsNames = parentsNames;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getNames() {
|
||||
return names;
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
String[] name = names.split(" ");
|
||||
|
||||
@ -82,23 +46,59 @@ public class PersonalData {
|
||||
return dateAndBirthPlace;
|
||||
}
|
||||
|
||||
public PersonalData setDateAndBirthPlace(String dateAndBirthPlace) {
|
||||
this.dateAndBirthPlace = dateAndBirthPlace;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getPesel() {
|
||||
return pesel;
|
||||
}
|
||||
|
||||
public PersonalData setPesel(String pesel) {
|
||||
this.pesel = pesel;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getGender() {
|
||||
return gender;
|
||||
}
|
||||
|
||||
public PersonalData setGender(String gender) {
|
||||
this.gender = gender;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isPolishCitizenship() {
|
||||
return isPolishCitizenship.equals("Tak");
|
||||
return "Tak".equals(isPolishCitizenship);
|
||||
}
|
||||
|
||||
public PersonalData setPolishCitizenship(String polishCitizenship) {
|
||||
isPolishCitizenship = polishCitizenship;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getFamilyName() {
|
||||
return familyName;
|
||||
}
|
||||
|
||||
public PersonalData setFamilyName(String familyName) {
|
||||
this.familyName = familyName;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getParentsNames() {
|
||||
return parentsNames;
|
||||
}
|
||||
|
||||
public PersonalData setParentsNames(String parentsNames) {
|
||||
this.parentsNames = parentsNames;
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package io.github.wulkanowy.database.accounts;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.SQLException;
|
||||
@ -9,53 +8,52 @@ import android.util.Log;
|
||||
|
||||
public class AccountAdapter {
|
||||
|
||||
private DatabaseHelper databaseHelper;
|
||||
private Context context;
|
||||
public SQLiteDatabase database;
|
||||
|
||||
private final String DATABASE_NAME = "accountdatabase.db";
|
||||
private final int DATABASE_VERSION = 1;
|
||||
public SQLiteDatabase database;
|
||||
private DatabaseHelper databaseHelper;
|
||||
private Context context;
|
||||
|
||||
AccountAdapter(Context context){
|
||||
this.context = context;
|
||||
AccountAdapter(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public AccountAdapter open(){
|
||||
public AccountAdapter open() {
|
||||
|
||||
databaseHelper = new DatabaseHelper(context, DATABASE_NAME, null, DATABASE_VERSION);
|
||||
|
||||
try{
|
||||
try {
|
||||
database = databaseHelper.getWritableDatabase();
|
||||
} catch (SQLException e){
|
||||
} catch (SQLException e) {
|
||||
database = databaseHelper.getReadableDatabase();
|
||||
Log.w(DatabaseHelper.DEBUG_TAG,"Database in read-only");
|
||||
Log.w(DatabaseHelper.DEBUG_TAG, "Database in read-only");
|
||||
}
|
||||
|
||||
Log.d(DatabaseHelper.DEBUG_TAG,"Open database");
|
||||
Log.d(DatabaseHelper.DEBUG_TAG, "Open database");
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public void close(){
|
||||
public void close() {
|
||||
databaseHelper.close();
|
||||
|
||||
Log.d(DatabaseHelper.DEBUG_TAG,"Close database");
|
||||
Log.d(DatabaseHelper.DEBUG_TAG, "Close database");
|
||||
}
|
||||
|
||||
public boolean checkExist(){
|
||||
public boolean checkExist() {
|
||||
|
||||
open();
|
||||
|
||||
Log.d(DatabaseHelper.DEBUG_TAG,"Check exist table");
|
||||
Log.d(DatabaseHelper.DEBUG_TAG, "Check exist table");
|
||||
|
||||
Cursor cursor = database.rawQuery("SELECT COUNT(*) FROM accounts", null);
|
||||
if(cursor != null){
|
||||
|
||||
if (cursor != null) {
|
||||
cursor.moveToFirst();
|
||||
|
||||
int count = cursor.getInt(0);
|
||||
|
||||
if(count > 0){
|
||||
if (count > 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -13,48 +13,48 @@ public class AccountData {
|
||||
|
||||
private String county;
|
||||
|
||||
public AccountData setId(int id){
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public AccountData setId(int id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AccountData setName(String name){
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public AccountData setName(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AccountData setEmail(String email){
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public AccountData setEmail(String email) {
|
||||
this.email = email;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AccountData setPassword(String password){
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public AccountData setPassword(String password) {
|
||||
this.password = password;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AccountData setCounty(String county){
|
||||
public String getCounty() {
|
||||
return county;
|
||||
}
|
||||
|
||||
public AccountData setCounty(String county) {
|
||||
this.county = county;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getId(){
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName(){
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getEmail(){
|
||||
return email;
|
||||
}
|
||||
|
||||
public String getPassword(){
|
||||
return password;
|
||||
}
|
||||
|
||||
public String getCounty(){
|
||||
return county;
|
||||
}
|
||||
}
|
||||
|
@ -15,42 +15,41 @@ public class DatabaseAccount extends AccountAdapter {
|
||||
private String idText = "id";
|
||||
private String accounts = "accounts";
|
||||
|
||||
public DatabaseAccount(Context context){
|
||||
public DatabaseAccount(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public void put(AccountData accountData) throws SQLException{
|
||||
public void put(AccountData accountData) throws SQLException {
|
||||
|
||||
ContentValues newAccount = new ContentValues();
|
||||
newAccount.put(name,accountData.getName());
|
||||
newAccount.put(email,accountData.getEmail());
|
||||
newAccount.put(password,accountData.getPassword());
|
||||
newAccount.put(county,accountData.getCounty());
|
||||
newAccount.put(name, accountData.getName());
|
||||
newAccount.put(email, accountData.getEmail());
|
||||
newAccount.put(password, accountData.getPassword());
|
||||
newAccount.put(county, accountData.getCounty());
|
||||
|
||||
Log.d(DatabaseHelper.DEBUG_TAG,"Put account into database");
|
||||
Log.d(DatabaseHelper.DEBUG_TAG, "Put account into database");
|
||||
|
||||
if(!database.isReadOnly()) {
|
||||
if (!database.isReadOnly()) {
|
||||
database.insertOrThrow(accounts, null, newAccount);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public long update(AccountData accountData){
|
||||
public long update(AccountData accountData) {
|
||||
|
||||
ContentValues updateAccount = new ContentValues();
|
||||
|
||||
updateAccount.put(name,accountData.getName());
|
||||
updateAccount.put(email,accountData.getEmail());
|
||||
updateAccount.put(password,accountData.getPassword());
|
||||
updateAccount.put(county,accountData.getCounty());
|
||||
updateAccount.put(name, accountData.getName());
|
||||
updateAccount.put(email, accountData.getEmail());
|
||||
updateAccount.put(password, accountData.getPassword());
|
||||
updateAccount.put(county, accountData.getCounty());
|
||||
String args[] = {accountData.getId() + ""};
|
||||
|
||||
Log.d(DatabaseHelper.DEBUG_TAG,"Update account into database");
|
||||
Log.d(DatabaseHelper.DEBUG_TAG, "Update account into database");
|
||||
|
||||
return database.update(accounts, updateAccount, "id=?", args);
|
||||
}
|
||||
|
||||
public AccountData getAccount(int id) throws SQLException{
|
||||
public AccountData getAccount(int id) throws SQLException {
|
||||
|
||||
AccountData accountData = new AccountData();
|
||||
|
||||
@ -59,7 +58,7 @@ public class DatabaseAccount extends AccountAdapter {
|
||||
|
||||
try {
|
||||
Cursor cursor = database.query(accounts, columns, "id=?", args, null, null, null, null);
|
||||
if(cursor != null) {
|
||||
if (cursor != null) {
|
||||
cursor.moveToFirst();
|
||||
accountData.setId(cursor.getInt(0));
|
||||
accountData.setName(cursor.getString(1));
|
||||
@ -68,15 +67,14 @@ public class DatabaseAccount extends AccountAdapter {
|
||||
accountData.setCounty(cursor.getString(4));
|
||||
cursor.close();
|
||||
}
|
||||
}catch (SQLException e){
|
||||
} catch (SQLException e) {
|
||||
|
||||
Log.e(DatabaseHelper.DEBUG_TAG,e.getMessage());
|
||||
Log.e(DatabaseHelper.DEBUG_TAG, e.getMessage());
|
||||
throw e;
|
||||
}
|
||||
|
||||
Log.d(DatabaseHelper.DEBUG_TAG,"Extract account from base");
|
||||
Log.d(DatabaseHelper.DEBUG_TAG, "Extract account from base");
|
||||
|
||||
return accountData;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,39 +1,36 @@
|
||||
package io.github.wulkanowy.database.accounts;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteDatabase.*;
|
||||
import android.database.sqlite.SQLiteDatabase.CursorFactory;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.util.Log;
|
||||
|
||||
public class DatabaseHelper extends SQLiteOpenHelper {
|
||||
|
||||
private final String ACCOUN_TABLE = "CREATE TABLE accounts( " +
|
||||
public final static String DEBUG_TAG = "SQLiteAccountsDatabase";
|
||||
private final String ACCOUNT_TABLE = "CREATE TABLE accounts( " +
|
||||
"id INTEGER PRIMARY KEY AUTOINCREMENT, " +
|
||||
"name TEXT, " +
|
||||
"email TEXT," +
|
||||
"password TEXT, " +
|
||||
"county TEXT );";
|
||||
|
||||
private final String DROP_ACCOUNT_TABLE = "DROP TABLE IF EXISTS accounts";
|
||||
public final static String DEBUG_TAG = "SQLiteAccountsDatabse";
|
||||
|
||||
public DatabaseHelper(Context context, String name, CursorFactory factory, int version){
|
||||
public DatabaseHelper(Context context, String name, CursorFactory factory, int version) {
|
||||
super(context, name, factory, version);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(SQLiteDatabase db){
|
||||
db.execSQL(ACCOUN_TABLE);
|
||||
|
||||
Log.d(DEBUG_TAG,"Create database");
|
||||
public void onCreate(SQLiteDatabase db) {
|
||||
db.execSQL(ACCOUNT_TABLE);
|
||||
Log.d(DEBUG_TAG, "Create database");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
db.execSQL(DROP_ACCOUNT_TABLE);
|
||||
onCreate(db);
|
||||
Log.d(DEBUG_TAG,"Upgrade database");
|
||||
Log.d(DEBUG_TAG, "Upgrade database");
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="io.github.wulkanowy.activity.dashboard.lessonplan.LessonplanFragment">
|
||||
tools:context="io.github.wulkanowy.activity.dashboard.lessonplan.LessonPlanFragment">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
|
Loading…
x
Reference in New Issue
Block a user