forked from github/wulkanowy-mirror
Add loading circle and download subject name
This commit is contained in:
parent
7d00f92b83
commit
1e3bca9559
@ -1,7 +1,6 @@
|
|||||||
package io.github.wulkanowy.activity.dashboard.marks;
|
package io.github.wulkanowy.activity.dashboard.marks;
|
||||||
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@ -22,26 +21,17 @@ import java.io.FileInputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.ObjectInputStream;
|
import java.io.ObjectInputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import io.github.wulkanowy.R;
|
import io.github.wulkanowy.R;
|
||||||
|
|
||||||
public class MarksFragment extends Fragment {
|
public class MarksFragment extends Fragment {
|
||||||
|
|
||||||
|
|
||||||
final String lista[] = {
|
ArrayList<String> subject = new ArrayList<>();
|
||||||
"Donut",
|
View view;
|
||||||
"Eclair",
|
|
||||||
"Froyo",
|
|
||||||
"Gingerbread",
|
|
||||||
"Honeycomb",
|
|
||||||
"Ice Cream Sandwich",
|
|
||||||
"Jelly Bean",
|
|
||||||
"KitKat",
|
|
||||||
"Lollipop",
|
|
||||||
"Marshmallow"
|
|
||||||
};
|
|
||||||
|
|
||||||
public MarksFragment() {
|
public MarksFragment() {
|
||||||
}
|
}
|
||||||
@ -51,20 +41,30 @@ public class MarksFragment extends Fragment {
|
|||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
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 recyclerView = (RecyclerView)view.findViewById(R.id.card_recycler_view);
|
||||||
recyclerView.setHasFixedSize(true);
|
recyclerView.setHasFixedSize(true);
|
||||||
RecyclerView.LayoutManager layoutManager = new GridLayoutManager(view.getContext(),2);
|
RecyclerView.LayoutManager layoutManager = new GridLayoutManager(view.getContext(),2);
|
||||||
recyclerView.setLayoutManager(layoutManager);
|
recyclerView.setLayoutManager(layoutManager);
|
||||||
|
|
||||||
ArrayList<String> array = new ArrayList<>(Arrays.asList(lista));
|
ImageAdapter adapter = new ImageAdapter(view.getContext(),subject);
|
||||||
ImageAdapter adapter = new ImageAdapter(view.getContext(),array);
|
|
||||||
recyclerView.setAdapter(adapter);
|
recyclerView.setAdapter(adapter);
|
||||||
|
|
||||||
return view;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class MarksModel extends AsyncTask<Void, Void, Void> {
|
public class MarksModel extends AsyncTask<Void, Void, Void> {
|
||||||
@ -107,6 +107,16 @@ public class MarksFragment extends Fragment {
|
|||||||
.execute();
|
.execute();
|
||||||
loginCookies = res.cookies();
|
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
|
// get marks view
|
||||||
String marksPageUrl = "https://uonetplus-opiekun.vulcan.net.pl/powiatjaroslawski/005791/Oceny/Wszystkie?details=2";
|
String marksPageUrl = "https://uonetplus-opiekun.vulcan.net.pl/powiatjaroslawski/005791/Oceny/Wszystkie?details=2";
|
||||||
Document marksPage = Jsoup.connect(marksPageUrl)
|
Document marksPage = Jsoup.connect(marksPageUrl)
|
||||||
@ -115,12 +125,13 @@ public class MarksFragment extends Fragment {
|
|||||||
Elements marksRows = marksPage.select(".ocenySzczegoly-table > tbody > tr");
|
Elements marksRows = marksPage.select(".ocenySzczegoly-table > tbody > tr");
|
||||||
for (Element element : marksRows) {
|
for (Element element : marksRows) {
|
||||||
System.out.println("----------");
|
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("Grade: " + element.select("td:nth-child(2)").text());
|
||||||
System.out.println("Description: " + element.select("td:nth-child(3)").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("Weight: " + element.select("td:nth-child(4)").text());
|
||||||
System.out.println("Date: " + element.select("td:nth-child(5)").text());
|
System.out.println("Date: " + element.select("td:nth-child(5)").text());
|
||||||
System.out.println("Teacher: " + element.select("td:nth-child(6)").text());
|
System.out.println("Teacher: " + element.select("td:nth-child(6)").text());
|
||||||
|
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -128,6 +139,20 @@ public class MarksFragment extends Fragment {
|
|||||||
|
|
||||||
return null;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,4 +10,16 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="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>
|
</android.support.design.widget.CoordinatorLayout>
|
@ -20,6 +20,7 @@
|
|||||||
android:textColor="#000000"
|
android:textColor="#000000"
|
||||||
android:background="#FFFFFF"
|
android:background="#FFFFFF"
|
||||||
android:textStyle="bold"
|
android:textStyle="bold"
|
||||||
|
android:lines="2"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
@ -2,5 +2,4 @@
|
|||||||
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
|
<!-- 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
|
(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). -->
|
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
|
||||||
<dimen name="activity_horizontal_margin">64dp</dimen>
|
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<!-- Default screen margins, per the Android Design guidelines. -->
|
<!-- Default screen margins, per the Android Design guidelines. -->
|
||||||
<dimen name="activity_horizontal_margin">16dp</dimen>
|
|
||||||
<dimen name="activity_vertical_margin">16dp</dimen>
|
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user