diff --git a/app/src/main/java/io/github/wulkanowy/activity/dashboard/marks/MarksFragment.java b/app/src/main/java/io/github/wulkanowy/activity/dashboard/marks/MarksFragment.java index 9953e8f02..5db406628 100644 --- a/app/src/main/java/io/github/wulkanowy/activity/dashboard/marks/MarksFragment.java +++ b/app/src/main/java/io/github/wulkanowy/activity/dashboard/marks/MarksFragment.java @@ -1,7 +1,6 @@ package io.github.wulkanowy.activity.dashboard.marks; -import android.app.Activity; import android.content.Context; import android.os.AsyncTask; import android.os.Bundle; @@ -22,26 +21,17 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.util.ArrayList; -import java.util.Arrays; +import java.util.HashSet; import java.util.Map; +import java.util.Set; import io.github.wulkanowy.R; public class MarksFragment extends Fragment { - final String lista[] = { - "Donut", - "Eclair", - "Froyo", - "Gingerbread", - "Honeycomb", - "Ice Cream Sandwich", - "Jelly Bean", - "KitKat", - "Lollipop", - "Marshmallow" - }; + ArrayList subject = new ArrayList<>(); + View view; public MarksFragment() { } @@ -51,20 +41,30 @@ public class MarksFragment extends Fragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - new MarksModel(container.getContext()).execute(); + view = inflater.inflate(R.layout.fragment_marks, container, false); + if (subject.size() == 0) { - View view = inflater.inflate(R.layout.fragment_marks, container, false); + new MarksModel(container.getContext()).execute(); + } + else if (subject.size() > 1) { + + createGrid(); + view.findViewById(R.id.loadingPanel).setVisibility(View.GONE); + } + + + return view; + } + + public void createGrid(){ RecyclerView recyclerView = (RecyclerView)view.findViewById(R.id.card_recycler_view); recyclerView.setHasFixedSize(true); RecyclerView.LayoutManager layoutManager = new GridLayoutManager(view.getContext(),2); recyclerView.setLayoutManager(layoutManager); - ArrayList array = new ArrayList<>(Arrays.asList(lista)); - ImageAdapter adapter = new ImageAdapter(view.getContext(),array); + ImageAdapter adapter = new ImageAdapter(view.getContext(),subject); recyclerView.setAdapter(adapter); - - return view; } public class MarksModel extends AsyncTask { @@ -107,6 +107,16 @@ public class MarksFragment extends Fragment { .execute(); loginCookies = res.cookies(); + //get subject name + String subjectPageurl = "https://uonetplus-opiekun.vulcan.net.pl/powiatjaroslawski/005791/Oceny/Wszystkie?details=1"; + Document subjectPage = Jsoup.connect(subjectPageurl) + .cookies(loginCookies) + .get(); + Elements subjectTile = subjectPage.select(".ocenyZwykle-table > tbody > tr"); + for (Element titlelement : subjectTile){ + subject.add(titlelement.select("td:nth-child(1)").text()); + } + // get marks view String marksPageUrl = "https://uonetplus-opiekun.vulcan.net.pl/powiatjaroslawski/005791/Oceny/Wszystkie?details=2"; Document marksPage = Jsoup.connect(marksPageUrl) @@ -115,12 +125,13 @@ public class MarksFragment extends Fragment { Elements marksRows = marksPage.select(".ocenySzczegoly-table > tbody > tr"); for (Element element : marksRows) { System.out.println("----------"); - System.out.println("Subject: " + element.select("td:nth-child(1)").text()); + System.out.println("Subject" + element.select("td:nth-child(1)").text()); System.out.println("Grade: " + element.select("td:nth-child(2)").text()); System.out.println("Description: " + element.select("td:nth-child(3)").text()); System.out.println("Weight: " + element.select("td:nth-child(4)").text()); System.out.println("Date: " + element.select("td:nth-child(5)").text()); System.out.println("Teacher: " + element.select("td:nth-child(6)").text()); + } } catch (IOException e) { e.printStackTrace(); @@ -128,6 +139,20 @@ public class MarksFragment extends Fragment { return null; } + + protected void onPostExecute(Void result) { + + Set hs = new HashSet<>(); + hs.addAll(subject); + subject.clear(); + subject.addAll(hs); + + createGrid(); + + view.findViewById(R.id.loadingPanel).setVisibility(View.GONE); + + super.onPostExecute(result); + } } diff --git a/app/src/main/res/layout/fragment_marks.xml b/app/src/main/res/layout/fragment_marks.xml index bbffc4108..ef8aa4845 100644 --- a/app/src/main/res/layout/fragment_marks.xml +++ b/app/src/main/res/layout/fragment_marks.xml @@ -10,4 +10,16 @@ android:layout_width="match_parent" android:layout_height="match_parent"/> + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/row_layout.xml b/app/src/main/res/layout/row_layout.xml index 4d65b7956..f7355a56e 100644 --- a/app/src/main/res/layout/row_layout.xml +++ b/app/src/main/res/layout/row_layout.xml @@ -20,6 +20,7 @@ android:textColor="#000000" android:background="#FFFFFF" android:textStyle="bold" + android:lines="2" android:layout_width="match_parent" android:layout_height="wrap_content" /> \ No newline at end of file diff --git a/app/src/main/res/values-w820dp/dimens.xml b/app/src/main/res/values-w820dp/dimens.xml index 63fc81644..90bf00118 100644 --- a/app/src/main/res/values-w820dp/dimens.xml +++ b/app/src/main/res/values-w820dp/dimens.xml @@ -2,5 +2,4 @@ - 64dp diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 47c822467..5c1e38460 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -1,5 +1,3 @@ - 16dp - 16dp