1
0
mirror of https://github.com/wulkanowy/wulkanowy.git synced 2024-09-20 01:59:10 -05:00

Add loading circle and download subject name

This commit is contained in:
RicomenPL 2017-07-20 13:59:00 +02:00
parent 7d00f92b83
commit 1e3bca9559
5 changed files with 59 additions and 24 deletions

View File

@ -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<String> 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<String> 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<Void, Void, Void> {
@ -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<String> hs = new HashSet<>();
hs.addAll(subject);
subject.clear();
subject.addAll(hs);
createGrid();
view.findViewById(R.id.loadingPanel).setVisibility(View.GONE);
super.onPostExecute(result);
}
}

View File

@ -10,4 +10,16 @@
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<RelativeLayout
android:id="@+id/loadingPanel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" >
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true" />
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>

View File

@ -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" />
</LinearLayout>

View File

@ -2,5 +2,4 @@
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
(such as screen margins) for screens with more than 820dp of available width. This
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
<dimen name="activity_horizontal_margin">64dp</dimen>
</resources>

View File

@ -1,5 +1,3 @@
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
</resources>