Added refesh to module overview

This commit is contained in:
Caesar2011
2018-07-03 14:29:03 +02:00
parent 2b34167724
commit 11c3f9157b
6 changed files with 64 additions and 45 deletions

View File

@@ -72,7 +72,6 @@ public class MainActivity extends AppCompatActivity
this.getGoogleAuth().connect(() -> {
// getGoogleAuth().setLoginState("seedorf96", "m&gcwBaT@");
getGoogleAuth().getLoginState(credentials -> {
if (credentials == null || credentials.getUsername() == null || credentials.getPassword() == null) {
MainActivity.this.getKVV().endUpdate();
@@ -257,9 +256,7 @@ public class MainActivity extends AppCompatActivity
@Override
public void onModulesFragmentInteraction(final int itemPosition) {
log.d("Item clicked", itemPosition);
getKVV().getModuleList(success -> log.d(success.get(itemPosition).title), error -> {
// TODO
});
getKVV().getModuleList(success -> log.d(success.get(itemPosition).title), error -> log.e(error));
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.fragcontainer, ModDetailFragment.newInstance(itemPosition));

View File

@@ -5,6 +5,7 @@ import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
@@ -31,6 +32,8 @@ public class ModDetailOverviewFragment extends Fragment {
// TODO: Rename and change types of parameters
private int mItemPos;
private Logger log = new Logger(this);
private ModDetailOverviewAdapter adapter;
private SwipeRefreshLayout swipeLayout;
public ModDetailOverviewFragment() {
@@ -70,40 +73,48 @@ public class ModDetailOverviewFragment extends Fragment {
log.d("on create");
View view = inflater.inflate(R.layout.fragment_mod_detail_overview, container, false);
// Set the adapter
if (view instanceof RecyclerView) {
Context context = view.getContext();
RecyclerView recyclerView = (RecyclerView) view;
recyclerView.setLayoutManager(new LinearLayoutManager(context));
final ModDetailOverviewAdapter adapter = new ModDetailOverviewAdapter();
recyclerView.setAdapter(adapter);
if (getActivity() != null) {
KVV kvv = ((MainActivity) getActivity()).getKVV();
kvv.getModuleList((Modules success) -> {
log.d(success);
Modules.Module module = success.get(mItemPos);
adapter.setModule(module);
kvv.getModuleAnnouncements(module, module1 -> {
log.d("announcements", module.announcements);
adapter.setModule();
}, error -> log.e(error));
kvv.getModuleAssignments(module, module1 -> {
log.d("assignments", module.assignments);
adapter.setModule();
}, error -> log.e(error));
kvv.getModuleEvents(module, module1 -> {
log.d("events", module.events);
adapter.setModule();
}, error -> log.e(error));
}, error -> log.e(error));
}
}
Context context = view.getContext();
RecyclerView recyclerView = view.findViewById(R.id.list);
recyclerView.setLayoutManager(new LinearLayoutManager(context));
adapter = new ModDetailOverviewAdapter();
recyclerView.setAdapter(adapter);
// Getting SwipeContainerLayout
swipeLayout = view.findViewById(R.id.swipe_container);
// Adding Listener
swipeLayout.setOnRefreshListener(this::refresh);
refresh();
return view;
}
private void refresh() {
if (getActivity() != null) {
KVV kvv = ((MainActivity) getActivity()).getKVV();
kvv.getModuleList((Modules success) -> {
log.d(success);
Modules.Module module = success.get(mItemPos);
log.d("Print c");
adapter.setModule(module);
kvv.getModuleAnnouncements(module, module1 -> {
//log.d("announcements", module.announcements);
adapter.setModule();
}, error -> log.e(error));
kvv.getModuleAssignments(module, module1 -> {
//log.d("assignments", module.assignments);
adapter.setModule();
}, error -> log.e(error));
kvv.getModuleEvents(module, module1 -> {
//log.d("events", module.events);
adapter.setModule();
}, error -> log.e(error));
kvv.getModuleGradebook(module, module1 -> {
log.d("gradebook", module.gradebook);
adapter.setModule();
}, error -> log.e(error));
}, error -> log.e(error));
}
swipeLayout.setRefreshing(false);
}
}

View File

@@ -22,4 +22,10 @@ public class Gradebook {
public String getItemName() {
return itemName;
}
@Override
public String toString() {
// TODO
return super.toString();
}
}

View File

@@ -1,13 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/list"
android:name=".fragments.moddetails.ModDetailOverviewFragment"
android:id="@+id/swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"
tools:context=".fragments.moddetails.ModDetailOverviewFragment"
tools:listitem="@layout/list_all_caption" />
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/list"
android:name=".fragments.moddetails.ModDetailOverviewFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"
tools:context=".fragments.moddetails.ModDetailOverviewFragment"
tools:listitem="@layout/list_all_caption" />
</android.support.v4.widget.SwipeRefreshLayout>