Commit 85f7bcc9 authored by Roger Barton's avatar Roger Barton
Browse files

Merge branch 'Joboffers'

parents 1780c988 0902a45c
Pipeline #4611 failed with stages
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
<uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" /> <uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" /> <uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application <application
android:name=".core.MyApplication" android:name=".core.MyApplication"
...@@ -50,7 +51,15 @@ ...@@ -50,7 +51,15 @@
android:value="ch.amiv.android_app.core.MainActivity" /> android:value="ch.amiv.android_app.core.MainActivity" />
</activity> </activity>
<activity <activity
android:name=".core.EventDetailActivity" android:name=".events.EventDetailActivity"
android:configChanges="orientation|layoutDirection|locale"
android:theme="@style/AppThemeLight">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="ch.amiv.android_app.core.MainActivity" />
</activity>
<activity
android:name=".jobs.JobDetailActivity"
android:configChanges="orientation|layoutDirection|locale" android:configChanges="orientation|layoutDirection|locale"
android:theme="@style/AppThemeLight"> android:theme="@style/AppThemeLight">
<meta-data <meta-data
......
...@@ -65,7 +65,7 @@ public class MainActivity extends AppCompatActivity { ...@@ -65,7 +65,7 @@ public class MainActivity extends AppCompatActivity {
} }
}); });
View logo = findViewById(R.id.LogoImage); View logo = findViewById(R.id.logoImage);
if(logo != null) { if(logo != null) {
Animation animation = AnimationUtils.loadAnimation(this, R.anim.item_anim_pop); Animation animation = AnimationUtils.loadAnimation(this, R.anim.item_anim_pop);
animation.setDuration(150); animation.setDuration(150);
......
package ch.amiv.android_app.core;
import android.support.v7.widget.RecyclerView;
/**
* A class to simplify refreshsing a recyclerview, used in events and jobs list for example
*/
public abstract class BaseRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
public void RefreshData(){
BuildDataset();
notifyDataSetChanged();
}
public void BuildDataset(){}
}
package ch.amiv.android_app.core; package ch.amiv.android_app.core;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout; import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
...@@ -15,18 +15,27 @@ import android.view.ViewGroup; ...@@ -15,18 +15,27 @@ import android.view.ViewGroup;
import android.view.animation.AnimationUtils; import android.view.animation.AnimationUtils;
import ch.amiv.android_app.R; import ch.amiv.android_app.R;
import ch.amiv.android_app.events.EventsListAdapter;
import ch.amiv.android_app.jobs.JobListAdapter;
/** /**
* An example fragment, the central view in MainActivity, for showing a list, should be replaced by a standard fragment with a custom recyclerView, create one different class for different views * This class is a fragment for a list screen used in the main activity by the page viewer for events, jobs, it will use the given page position to tell which one it is
*/ */
public class ListFragment extends Fragment { public class ListFragment extends Fragment {
int pagePosition; //the fragments page in the pageview of the main activity private int pagePosition; //the fragments page in the pageview of the main activity
RecyclerView recyclerView; public static final class PageType {
EventsListAdapter recylcerAdaper; public static final int COUNT = 3;
RecyclerView.LayoutManager recyclerLayoutAdapter; public static final int EVENTS = 0;
public static final int NOTIFICATIONS = 1;
public static final int JOBS = 2;
}
private RecyclerView recyclerView;
private BaseRecyclerAdapter recyclerAdapter;
private RecyclerView.LayoutManager recyclerLayoutAdapter;
SwipeRefreshLayout swipeRefreshLayout; private SwipeRefreshLayout swipeRefreshLayout;
Requests.OnDataReceivedCallback cancelRefreshCallback = new Requests.OnDataReceivedCallback() { private Requests.OnDataReceivedCallback cancelRefreshCallback = new Requests.OnDataReceivedCallback() {
@Override @Override
public void OnDataReceived() { public void OnDataReceived() {
swipeRefreshLayout.setRefreshing(false); swipeRefreshLayout.setRefreshing(false);
...@@ -52,31 +61,53 @@ public class ListFragment extends Fragment { ...@@ -52,31 +61,53 @@ public class ListFragment extends Fragment {
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
pagePosition = getArguments() != null ? getArguments().getInt("pagePosition") : 1; pagePosition = getArguments() != null ? getArguments().getInt("pagePosition") : 0;
} }
@Override @Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
swipeRefreshLayout = getView().findViewById(R.id.swipeRefresh); swipeRefreshLayout = getView().findViewById(R.id.swipeRefresh);
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override @Override
public void onRefresh() { public void onRefresh() {
if(pagePosition == 0 && getActivity() instanceof MainActivity) if(!(getActivity() instanceof MainActivity))
return;
if(pagePosition == PageType.EVENTS)
Requests.FetchEventList(getContext(), ((MainActivity)getActivity()).onEventsListUpdatedCallback, cancelRefreshCallback, ""); Requests.FetchEventList(getContext(), ((MainActivity)getActivity()).onEventsListUpdatedCallback, cancelRefreshCallback, "");
else if (pagePosition == PageType.JOBS)
Requests.FetchJobList(getContext(), ((MainActivity)getActivity()).onJobsListUpdatedCallback, cancelRefreshCallback, "");
} }
}); });
//refresh on activity start //refresh on activity start
swipeRefreshLayout.post(new Runnable() { swipeRefreshLayout.post(new Runnable() {
@Override @Override
public void run() { public void run() {
if(pagePosition == 0 && getActivity() instanceof MainActivity) { if(!(getActivity() instanceof MainActivity))
return;
if(pagePosition == PageType.EVENTS) {
swipeRefreshLayout.setRefreshing(true); swipeRefreshLayout.setRefreshing(true);
Requests.FetchEventList(getContext(), ((MainActivity)getActivity()).onEventsListUpdatedCallback, cancelRefreshCallback, ""); Requests.FetchEventList(getContext(), ((MainActivity)getActivity()).onEventsListUpdatedCallback, cancelRefreshCallback, "");
} }
else if(pagePosition == PageType.JOBS){
swipeRefreshLayout.setRefreshing(true);
Requests.FetchJobList(getContext(), ((MainActivity)getActivity()).onJobsListUpdatedCallback, cancelRefreshCallback, "");
}
} }
}); });
//Disable the refresh animation after a timeout
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
swipeRefreshLayout.setRefreshing(false);
}
}, 1000*15);
recyclerView = getView().findViewById(R.id.recyclerView); recyclerView = getView().findViewById(R.id.recyclerView);
// use this setting to improve performance if you know that changes // use this setting to improve performance if you know that changes
...@@ -88,12 +119,17 @@ public class ListFragment extends Fragment { ...@@ -88,12 +119,17 @@ public class ListFragment extends Fragment {
recyclerView.setLayoutManager(recyclerLayoutAdapter); recyclerView.setLayoutManager(recyclerLayoutAdapter);
// specify an adapter (see also next example) // specify an adapter (see also next example)
if(pagePosition == 0) { if(pagePosition == PageType.EVENTS)
recylcerAdaper = new EventsListAdapter(getActivity()); recyclerAdapter = new EventsListAdapter(getActivity());
else if (pagePosition == PageType.JOBS)
recyclerAdapter = new JobListAdapter(getActivity());
if(recyclerAdapter != null) {
recyclerView.setLayoutAnimation(AnimationUtils.loadLayoutAnimation(getContext(), R.anim.layout_anim_falldown)); recyclerView.setLayoutAnimation(AnimationUtils.loadLayoutAnimation(getContext(), R.anim.layout_anim_falldown));
recyclerView.setAdapter(recylcerAdaper); recyclerView.setAdapter(recyclerAdapter);
} AnimateList(null);
//Used to show feedback when touching item
recyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() { recyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
@Override @Override
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) { public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
...@@ -101,23 +137,21 @@ public class ListFragment extends Fragment { ...@@ -101,23 +137,21 @@ public class ListFragment extends Fragment {
} }
@Override @Override
public void onTouchEvent(RecyclerView rv, MotionEvent e) { public void onTouchEvent(RecyclerView rv, MotionEvent e) { }
}
@Override @Override
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) { public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) { }
}
}); });
AnimateList(null); }
} }
public void RefreshList(boolean animate) public void RefreshList(boolean animate)
{ {
recylcerAdaper.RefreshData(); if(recyclerAdapter == null)
return;
swipeRefreshLayout.setRefreshing(false); swipeRefreshLayout.setRefreshing(false);
recyclerAdapter.RefreshData();
if(animate) if(animate)
AnimateList(null); AnimateList(null);
} }
...@@ -137,8 +171,8 @@ public class ListFragment extends Fragment { ...@@ -137,8 +171,8 @@ public class ListFragment extends Fragment {
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
if(recylcerAdaper != null) if(recyclerAdapter != null)
recylcerAdaper.RefreshData(); recyclerAdapter.RefreshData();
} }
/** /**
...@@ -147,6 +181,9 @@ public class ListFragment extends Fragment { ...@@ -147,6 +181,9 @@ public class ListFragment extends Fragment {
*/ */
public void AnimateList(View view) public void AnimateList(View view)
{ {
if(recyclerAdapter == null)
return;
getActivity().runOnUiThread(new Runnable() { getActivity().runOnUiThread(new Runnable() {
public void run() { public void run() {
recyclerView.invalidate(); recyclerView.invalidate();
......
...@@ -14,6 +14,7 @@ import android.support.v4.widget.DrawerLayout; ...@@ -14,6 +14,7 @@ import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
...@@ -22,6 +23,9 @@ import android.widget.TextView; ...@@ -22,6 +23,9 @@ import android.widget.TextView;
import ch.amiv.android_app.R; import ch.amiv.android_app.R;
import ch.amiv.android_app.checkin.BarcodeIdActivity; import ch.amiv.android_app.checkin.BarcodeIdActivity;
import ch.amiv.android_app.events.EventDetailActivity;
import ch.amiv.android_app.events.Events;
import ch.amiv.android_app.jobs.JobDetailActivity;
/** /**
* This is the first screen. features: drawer, pageview with bottom navigation bar and within each page a list view. * This is the first screen. features: drawer, pageview with bottom navigation bar and within each page a list view.
...@@ -42,14 +46,21 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On ...@@ -42,14 +46,21 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
@Override @Override
public void OnDataReceived() { public void OnDataReceived() {
Requests.FetchEventSignups(getApplicationContext(), onSignupsUpdatedCallback, null, ""); Requests.FetchEventSignups(getApplicationContext(), onSignupsUpdatedCallback, null, "");
pagerAdapter.RefreshCurrentList(true); pagerAdapter.RefreshPage(ListFragment.PageType.EVENTS, true);
}
};
public Requests.OnDataReceivedCallback onJobsListUpdatedCallback = new Requests.OnDataReceivedCallback() {
@Override
public void OnDataReceived() {
pagerAdapter.RefreshPage(ListFragment.PageType.JOBS, true);
} }
}; };
private Requests.OnDataReceivedCallback onSignupsUpdatedCallback = new Requests.OnDataReceivedCallback() { private Requests.OnDataReceivedCallback onSignupsUpdatedCallback = new Requests.OnDataReceivedCallback() {
@Override @Override
public void OnDataReceived() { public void OnDataReceived() {
pagerAdapter.RefreshCurrentList(false); pagerAdapter.RefreshPage(ListFragment.PageType.EVENTS, false);
} }
}; };
...@@ -62,15 +73,18 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On ...@@ -62,15 +73,18 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
@Override @Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) { public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.bottom_nav_home: case R.id.bottom_nav_events:
viewPager.setCurrentItem(0); viewPager.setCurrentItem(ListFragment.PageType.EVENTS);
return true;
case R.id.bottom_nav_notifications:
viewPager.setCurrentItem(ListFragment.PageType.NOTIFICATIONS);
return true;
case R.id.bottom_nav_jobs:
viewPager.setCurrentItem(ListFragment.PageType.JOBS);
return true; return true;
/*case R.id.bottom_nav_blitz: /*case R.id.bottom_nav_blitz:
viewPager.setCurrentItem(1); viewPager.setCurrentItem(3);
return true;*/ return true;*/
case R.id.bottom_nav_events:
viewPager.setCurrentItem(1);
return true;
} }
return false; return false;
} }
...@@ -124,6 +138,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On ...@@ -124,6 +138,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
viewPager = findViewById(R.id.viewPager); viewPager = findViewById(R.id.viewPager);
viewPager.setAdapter(pagerAdapter); viewPager.setAdapter(pagerAdapter);
viewPager.setPageTransformer(true, new DepthPageTransformer()); //used for animating viewPager.setPageTransformer(true, new DepthPageTransformer()); //used for animating
viewPager.setOffscreenPageLimit(ListFragment.PageType.COUNT);//prevent pages being deleted when we swipe to far
//set for the bottom nav to be updated when we swipe to change the page //set for the bottom nav to be updated when we swipe to change the page
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
...@@ -133,12 +148,14 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On ...@@ -133,12 +148,14 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
@Override @Override
public void onPageSelected(int position) { public void onPageSelected(int position) {
//need to convert index to resource id //need to convert index to resource id
if(position == 0) if(position == ListFragment.PageType.EVENTS)
position = R.id.bottom_nav_home; position = R.id.bottom_nav_events;
/*else if (position == 1) /*else if (position == 1)
position = R.id.bottom_nav_blitz;*/ position = R.id.bottom_nav_blitz;*/
else if (position == 1) else if (position == ListFragment.PageType.NOTIFICATIONS)
position = R.id.bottom_nav_events; position = R.id.bottom_nav_notifications;
else if (position == ListFragment.PageType.JOBS)
position = R.id.bottom_nav_jobs;
bottomNavigation.setSelectedItemId(position); bottomNavigation.setSelectedItemId(position);
} }
...@@ -149,6 +166,14 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On ...@@ -149,6 +166,14 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
} }
//endregion //endregion
@Override
protected void onPostResume() {
super.onPostResume();
if(pagerAdapter != null)
pagerAdapter.notifyDataSetChanged();
}
//region - ====Login==== //region - ====Login====
/** /**
* Log the user out, delete token. Will not log the user out of the device with the API as this is used with other amiv services as well * Log the user out, delete token. Will not log the user out of the device with the API as this is used with other amiv services as well
...@@ -160,7 +185,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On ...@@ -160,7 +185,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
UserInfo.current = null; UserInfo.current = null;
Events.ClearSignups(); Events.ClearSignups();
pagerAdapter.RefreshCurrentList(true); pagerAdapter.RefreshPage(ListFragment.PageType.EVENTS, true);
SetLoginUIDirty(); SetLoginUIDirty();
System.gc();//run garbage collector explicitly to clean up user data System.gc();//run garbage collector explicitly to clean up user data
...@@ -216,6 +241,14 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On ...@@ -216,6 +241,14 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
startActivityForResult(intent, 0); startActivityForResult(intent, 0);
} }
public void StartJobDetailActivity(int jobGroup, int jobIndex)
{
Intent intent = new Intent(this, JobDetailActivity.class);
intent.putExtra("jobGroup", jobGroup);
intent.putExtra("jobIndex", jobIndex);
startActivityForResult(intent, 0);
}
private void StartCheckinActivity() { private void StartCheckinActivity() {
Intent intent = new Intent(this, ch.amiv.android_app.checkin.MainActivity.class); Intent intent = new Intent(this, ch.amiv.android_app.checkin.MainActivity.class);
startActivity(intent); startActivity(intent);
...@@ -331,39 +364,43 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On ...@@ -331,39 +364,43 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
//region =====START OF PAGEVIEW============== //region =====START OF PAGEVIEW==============
protected ListFragment[] pages = new ListFragment[ListFragment.PageType.COUNT];
/** /**
* This will handle changing between the pages * This will handle changing between the pages
*/ */
public class PagerAdapter extends FragmentPagerAdapter { public class PagerAdapter extends FragmentPagerAdapter {
ListFragment currentFragment; int currentPosition;
public PagerAdapter(FragmentManager fm) { public PagerAdapter(FragmentManager fm) {
super(fm); super(fm);
for(int i = 0; i< ListFragment.PageType.COUNT; i++)
pages[i] = ListFragment.NewInstance(i);
} }
@Override @Override
public int getCount() { public int getCount() {
return 2; return ListFragment.PageType.COUNT;
} }
@Override @Override
public Fragment getItem(int position) { public Fragment getItem(int position) {
return ListFragment.NewInstance(position); if(pages[position] == null)
pages[position] = ListFragment.NewInstance(position);
return pages[position];
} }
@Override @Override
public void setPrimaryItem(ViewGroup container, int position, Object object) { public void setPrimaryItem(ViewGroup container, int position, Object object) {
if (currentFragment != object) { currentPosition = position;
currentFragment = ((ListFragment) object);
}
super.setPrimaryItem(container, position, object); super.setPrimaryItem(container, position, object);
} }
public void RefreshCurrentList(boolean animate) public void RefreshPage(int position, boolean animate){
{ if(pages[position] != null)
if(currentFragment != null) pages[position].RefreshList(animate);
currentFragment.RefreshList(animate); else
Log.e("pageview", "RefreshPage(), Page does not exist will not refresh: " + position);
} }
} }
......
<
...@@ -29,9 +29,13 @@ import java.text.SimpleDateFormat; ...@@ -29,9 +29,13 @@ import java.text.SimpleDateFormat;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import ch.amiv.android_app.events.Events;
import ch.amiv.android_app.jobs.Jobs;
public final class Requests { public final class Requests {
private static RequestQueue requestQueue; private static RequestQueue requestQueue;
private static ImageLoader imageLoader; private static ImageLoader imageLoader;
private static final int MAX_CACHED_IMAGES = 50;
public static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); public static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
...@@ -73,7 +77,9 @@ public final class Requests { ...@@ -73,7 +77,9 @@ public final class Requests {
return; return;
} }