Commit 0902a45c authored by Roger Barton's avatar Roger Barton
Browse files

Refactoring of job offers

Bug when resuming to main activity, pageviewer is not correctly reinitialised, so the lists dont show/fragments are lost
parent 054906cf
Pipeline #4610 failed with stages
...@@ -2,6 +2,9 @@ package ch.amiv.android_app.core; ...@@ -2,6 +2,9 @@ package ch.amiv.android_app.core;
import android.support.v7.widget.RecyclerView; 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 abstract class BaseRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
public void RefreshData(){ public void RefreshData(){
......
...@@ -19,7 +19,7 @@ import ch.amiv.android_app.events.EventsListAdapter; ...@@ -19,7 +19,7 @@ import ch.amiv.android_app.events.EventsListAdapter;
import ch.amiv.android_app.jobs.JobListAdapter; 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 {
private 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
...@@ -30,7 +30,6 @@ public class ListFragment extends Fragment { ...@@ -30,7 +30,6 @@ public class ListFragment extends Fragment {
public static final int JOBS = 2; public static final int JOBS = 2;
} }
private RecyclerView recyclerView; private RecyclerView recyclerView;
private BaseRecyclerAdapter recyclerAdapter; private BaseRecyclerAdapter recyclerAdapter;
private RecyclerView.LayoutManager recyclerLayoutAdapter; private RecyclerView.LayoutManager recyclerLayoutAdapter;
......
...@@ -166,6 +166,14 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On ...@@ -166,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
...@@ -356,12 +364,12 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On ...@@ -356,12 +364,12 @@ 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 {
int currentPosition; int currentPosition;
private ListFragment[] pages = new ListFragment[ListFragment.PageType.COUNT];
public PagerAdapter(FragmentManager fm) { public PagerAdapter(FragmentManager fm) {
super(fm); super(fm);
...@@ -394,12 +402,6 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On ...@@ -394,12 +402,6 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
else else
Log.e("pageview", "RefreshPage(), Page does not exist will not refresh: " + position); Log.e("pageview", "RefreshPage(), Page does not exist will not refresh: " + position);
} }
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
pages[position] = null;
super.destroyItem(container, position, object);
}
} }
/** /**
......
...@@ -170,7 +170,7 @@ public class EventDetailActivity extends AppCompatActivity { ...@@ -170,7 +170,7 @@ public class EventDetailActivity extends AppCompatActivity {
} }
//Link up variables with UI elements from the layout xml //Link up variables with UI elements from the layout xml
scrollView = findViewById(R.id.scrollView_event); scrollView = findViewById(R.id.scrollView);
posterProgress = findViewById(R.id.progressBar); posterProgress = findViewById(R.id.progressBar);
posterImage = findViewById(R.id.eventPoster); posterImage = findViewById(R.id.eventPoster);
posterMask = findViewById(R.id.posterMask); posterMask = findViewById(R.id.posterMask);
......
...@@ -15,7 +15,7 @@ import java.util.List; ...@@ -15,7 +15,7 @@ import java.util.List;
import ch.amiv.android_app.R; import ch.amiv.android_app.R;
import ch.amiv.android_app.core.BaseRecyclerAdapter; import ch.amiv.android_app.core.BaseRecyclerAdapter;
import ch.amiv.android_app.core.ListHelper; import ch.amiv.android_app.util.ListHelper;
import ch.amiv.android_app.core.MainActivity; import ch.amiv.android_app.core.MainActivity;
import static ch.amiv.android_app.core.Settings.showHiddenFeatures; import static ch.amiv.android_app.core.Settings.showHiddenFeatures;
......
...@@ -8,6 +8,8 @@ import android.content.pm.PackageManager; ...@@ -8,6 +8,8 @@ import android.content.pm.PackageManager;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment; import android.os.Environment;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.design.widget.Snackbar; import android.support.design.widget.Snackbar;
import android.support.v4.app.ActivityCompat; import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
...@@ -67,7 +69,7 @@ public class JobDetailActivity extends AppCompatActivity { ...@@ -67,7 +69,7 @@ public class JobDetailActivity extends AppCompatActivity {
} }
/** /**
* This will retrieve the eventIndexes to display, is only set when we originate from the MainActivity, where the int is added to the intent. * This will retrieve the jobIndexes to display, is only set when we originate from the MainActivity, where the int is added to the intent.
*/ */
private void GetIntentData (){ private void GetIntentData (){
if(jobGroup == 0 && jobIndex == 0) { if(jobGroup == 0 && jobIndex == 0) {
...@@ -96,7 +98,7 @@ public class JobDetailActivity extends AppCompatActivity { ...@@ -96,7 +98,7 @@ public class JobDetailActivity extends AppCompatActivity {
} }
//Link up variables with UI elements from the layout xml //Link up variables with UI elements from the layout xml
scrollView = findViewById(R.id.scrollView_event); scrollView = findViewById(R.id.scrollView);
logoImage = findViewById(R.id.companyLogo); logoImage = findViewById(R.id.companyLogo);
downloadPdfButton = findViewById(R.id.openPdf); downloadPdfButton = findViewById(R.id.openPdf);
...@@ -136,19 +138,36 @@ public class JobDetailActivity extends AppCompatActivity { ...@@ -136,19 +138,36 @@ public class JobDetailActivity extends AppCompatActivity {
} }
} }
/**
* Will start the pdf download as a notification to the downloads folder
* @param view
*/
public void OpenJobPdf(View view) { public void OpenJobPdf(View view) {
OpenJobPdf(true);
}
//Retry downloading when the permissions have changed, but dont ask again
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
OpenJobPdf(false);
}
public void OpenJobPdf(boolean askForPermission) {
if (job().pdf_url.isEmpty()) { if (job().pdf_url.isEmpty()) {
UpdateOpenPdfButton(); UpdateOpenPdfButton();
return; return;
} }
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { //Get permission to write to downloads //Check first if we have the permission to write a file
if (askForPermission && ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { //Get permission to write to downloads
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) { if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
//Add popup //Add popup
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0); ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0);
} }
else else
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0); ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0);
return;
} }
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED)
...@@ -157,16 +176,16 @@ public class JobDetailActivity extends AppCompatActivity { ...@@ -157,16 +176,16 @@ public class JobDetailActivity extends AppCompatActivity {
Uri uri = Uri.parse(job().GetPdfUrl()); Uri uri = Uri.parse(job().GetPdfUrl());
String savePath = job().GetTitle(getResources()); String savePath = job().GetTitle(getResources());
savePath = savePath.replace(' ', '-'); savePath = savePath.replace(' ', '-');
savePath = savePath.replaceAll("[^a-zA-Z0-9\\.\\-]", "_"); //remove illegal characters
savePath = "/amiv/" + savePath; savePath = "/amiv/" + savePath;
if(!savePath.substring(savePath.length() -4, savePath.length()).equalsIgnoreCase( ".pdf")) if(!savePath.substring(savePath.length() -4, savePath.length()).equalsIgnoreCase( ".pdf"))
savePath += ".pdf"; savePath += ".pdf";
savePath = savePath.replaceAll("[^a-zA-Z0-9\\.\\-]", "_"); //remove illegal characters
DownloadManager.Request request = new DownloadManager.Request(uri) DownloadManager.Request request = new DownloadManager.Request(uri)
.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE) .setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE)
.setAllowedOverRoaming(false) .setAllowedOverRoaming(false)
.setTitle(job().GetTitle(getResources()) + ".pdf") .setTitle(job().GetTitle(getResources()))
.setDescription(getResources().getString(R.string.job_pdf_description)) .setDescription(getResources().getString(R.string.job_pdf_description))
.setVisibleInDownloadsUi(true) .setVisibleInDownloadsUi(true)
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED) .setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
......
...@@ -22,7 +22,7 @@ public class JobInfo { ...@@ -22,7 +22,7 @@ public class JobInfo {
public String company; public String company;
private String logo_url; private String logo_url;
public String pdf_url; public String pdf_url;
public String show_website; public boolean show_website;
public Date time_end; public Date time_end;
public Date time_created; public Date time_created;
...@@ -46,7 +46,7 @@ public class JobInfo { ...@@ -46,7 +46,7 @@ public class JobInfo {
description_en = json.optString("description_en"); description_en = json.optString("description_en");
description_de = json.optString("description_de"); description_de = json.optString("description_de");
company = json.optString("company"); company = json.optString("company");
show_website = json.optString("show_website"); show_website = json.optBoolean("show_website", false);
//Add dates //Add dates
String _end= json.optString("time_end"); String _end= json.optString("time_end");
...@@ -111,7 +111,4 @@ public class JobInfo { ...@@ -111,7 +111,4 @@ public class JobInfo {
public String GetPdfUrl() { public String GetPdfUrl() {
return BuildFileUrl(pdf_url); return BuildFileUrl(pdf_url);
} }
} }
...@@ -16,7 +16,7 @@ import java.util.List; ...@@ -16,7 +16,7 @@ import java.util.List;
import ch.amiv.android_app.R; import ch.amiv.android_app.R;
import ch.amiv.android_app.core.BaseRecyclerAdapter; import ch.amiv.android_app.core.BaseRecyclerAdapter;
import ch.amiv.android_app.core.ListHelper; import ch.amiv.android_app.util.ListHelper;
import ch.amiv.android_app.core.MainActivity; import ch.amiv.android_app.core.MainActivity;
import ch.amiv.android_app.core.Requests; import ch.amiv.android_app.core.Requests;
...@@ -165,10 +165,14 @@ public class JobListAdapter extends BaseRecyclerAdapter { ...@@ -165,10 +165,14 @@ public class JobListAdapter extends BaseRecyclerAdapter {
Calendar cal = Calendar.getInstance(); Calendar cal = Calendar.getInstance();
cal.setTime(j.time_created); cal.setTime(j.time_created);
cal.add(Calendar.DAY_OF_YEAR, Jobs.DAYS_NEW_TAG_ACTIVE); cal.add(Calendar.DAY_OF_YEAR, Jobs.DAYS_NEW_TAG_ACTIVE);
if (jobGroup == Jobs.JobGroup.ALL_JOBS && cal.getTime().after(Calendar.getInstance().getTime())) if (jobGroup == Jobs.JobGroup.ALL_JOBS && cal.getTime().after(Calendar.getInstance().getTime())) {
jobInfoHolder.newTag.setVisibility(View.VISIBLE); jobInfoHolder.newTag.setVisibility(View.VISIBLE);
else jobInfoHolder.titleField.setPadding(0,0,(int)(activity.getResources().getDisplayMetrics().density * 32 + 0.5f),0);
}
else {
jobInfoHolder.newTag.setVisibility(View.GONE); jobInfoHolder.newTag.setVisibility(View.GONE);
jobInfoHolder.titleField.setPadding(0,0,0,0);
}
jobInfoHolder.itemView.setOnClickListener(new View.OnClickListener() { jobInfoHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override @Override
......
...@@ -11,12 +11,15 @@ import java.util.Comparator; ...@@ -11,12 +11,15 @@ import java.util.Comparator;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
/**
* This holds all the data about the job offers similar to the events class, for more explanations see the Events class
*/
public class Jobs { public class Jobs {
public static List<JobInfo> jobInfos = new ArrayList<JobInfo>(); //This is a list of ALL events as received from the api, we will not use this directly public static List<JobInfo> jobInfos = new ArrayList<JobInfo>();
public static List<List<JobInfo>> sortedJobs = new ArrayList<>(JobGroup.SIZE); //A list of lists which has been sorted according to the EventGroup configuration public static List<List<JobInfo>> sortedJobs = new ArrayList<>(JobGroup.SIZE);
public static boolean[] invertJobGroupSorting = new boolean[] {false, false, true}; //used to invert date sorting for the event groups public static boolean[] invertJobGroupSorting = new boolean[] {false, false, true};
//Use this class to use the correct indexes for the event group for the sortedJobs list //Use this class to use the correct indexes for the job group for the sortedJobs list
public static final class JobGroup { public static final class JobGroup {
public static final int SIZE = 3; public static final int SIZE = 3;
public static final int HIDDEN_JOBS = 0; public static final int HIDDEN_JOBS = 0;
...@@ -28,11 +31,12 @@ public class Jobs { ...@@ -28,11 +31,12 @@ public class Jobs {
public static final int DAYS_NEW_TAG_ACTIVE = 3; public static final int DAYS_NEW_TAG_ACTIVE = 3;
/** /**
* Update the event infos with the data received from the api. This is just for updating information about the event NOT the signup * Update the list of job offers with a json from the api
* @param json json array of the events. * @param json json array of the events.
*/ */
public static void UpdateJobInfos(JSONArray json) public static void UpdateJobInfos(JSONArray json)
{ {
//initialise lists first or clear them
boolean isInitialising = jobInfos.size() == 0; boolean isInitialising = jobInfos.size() == 0;
if(isInitialising){ if(isInitialising){
for (int k = 0; k < JobGroup.SIZE; k++) for (int k = 0; k < JobGroup.SIZE; k++)
...@@ -47,11 +51,11 @@ public class Jobs { ...@@ -47,11 +51,11 @@ public class Jobs {
{ {
try { try {
//if we are not initialising, search for the event id and then update it, else add a new one to the list. This ensures we do not lose the signup data //if we are not initialising, search for the event id and then update it, else add a new one to the list. This ensures we do not lose the signup data
JSONObject jsonEvent = json.getJSONObject(i); JSONObject jsonJob = json.getJSONObject(i);
JobInfo e = new JobInfo(jsonEvent); JobInfo e = new JobInfo(jsonJob);
if(e._id.isEmpty()) if(e._id.isEmpty())
continue; continue;
if(isInitialising || !UpdateSingleJob(jsonEvent, e._id)) if(isInitialising || !UpdateSingleJob(jsonJob, e._id))
jobInfos.add(e); jobInfos.add(e);
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
...@@ -73,9 +77,9 @@ public class Jobs { ...@@ -73,9 +77,9 @@ public class Jobs {
Date today = Calendar.getInstance().getTime(); Date today = Calendar.getInstance().getTime();
//fill in the sorted list according to the dates of the events //fill in the sorted list according to the dates
for (int i = 0; i < jobInfos.size(); i++){ for (int i = 0; i < jobInfos.size(); i++){
if(jobInfos.get(i).time_created.after(today)) if(!jobInfos.get(i).show_website)
sortedJobs.get(JobGroup.HIDDEN_JOBS).add(jobInfos.get(i)); sortedJobs.get(JobGroup.HIDDEN_JOBS).add(jobInfos.get(i));
else if(jobInfos.get(i).time_end.after(today)) else if(jobInfos.get(i).time_end.after(today))
sortedJobs.get(JobGroup.ALL_JOBS).add(jobInfos.get(i)); sortedJobs.get(JobGroup.ALL_JOBS).add(jobInfos.get(i));
......
...@@ -3,16 +3,21 @@ package ch.amiv.android_app.util; ...@@ -3,16 +3,21 @@ package ch.amiv.android_app.util;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.drawable.*; import android.graphics.drawable.*;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet; import android.util.AttributeSet;
import com.android.volley.toolbox.NetworkImageView; import com.android.volley.toolbox.NetworkImageView;
import ch.amiv.android_app.core.Requests; import ch.amiv.android_app.core.Requests;
/**
* This is a class to override the networkimageview which is a very easy class for a layout where volley will load the image for use automatically and cache the image etc
* We add extra fading and callback functionality
*/
public class CustomNetworkImageView extends NetworkImageView { public class CustomNetworkImageView extends NetworkImageView {
private static final int FADE_IN_TIME_MS = 200; private static final int FADE_IN_TIME_MS = 200;
public Requests.OnDataReceivedCallback onImageLoaded; public Requests.OnDataReceivedCallback onImageLoaded; //use this as a callback when the image was loaded
public CustomNetworkImageView(Context context) { public CustomNetworkImageView(Context context) {
super(context); super(context);
...@@ -32,7 +37,7 @@ public class CustomNetworkImageView extends NetworkImageView { ...@@ -32,7 +37,7 @@ public class CustomNetworkImageView extends NetworkImageView {
onImageLoaded.OnDataReceived(); onImageLoaded.OnDataReceived();
TransitionDrawable td = new TransitionDrawable(new Drawable[]{ TransitionDrawable td = new TransitionDrawable(new Drawable[]{
new ColorDrawable(getResources().getColor(android.R.color.transparent)), new ColorDrawable(ContextCompat.getColor(getContext(), android.R.color.transparent)),
new BitmapDrawable(getContext().getResources(), bm) new BitmapDrawable(getContext().getResources(), bm)
}); });
......
package ch.amiv.android_app.core; package ch.amiv.android_app.util;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.View; import android.view.View;
...@@ -6,6 +6,9 @@ import android.widget.TextView; ...@@ -6,6 +6,9 @@ import android.widget.TextView;
import ch.amiv.android_app.R; import ch.amiv.android_app.R;
/**
* Provides common classes and variables for lists
*/
public final class ListHelper { public final class ListHelper {
public static class Pair { public static class Pair {
......
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
android:layout_width="match_parent"> android:layout_width="match_parent">
<ScrollView <ScrollView
android:id="@+id/scrollView_event" android:id="@+id/scrollView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
...@@ -84,6 +84,7 @@ ...@@ -84,6 +84,7 @@
<View <View
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="1dp" android:layout_height="1dp"
android:alpha="0.25"
android:background="@color/backgroundDark" /> android:background="@color/backgroundDark" />
<TextView <TextView
...@@ -110,6 +111,7 @@ ...@@ -110,6 +111,7 @@
<View <View
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="1dp" android:layout_height="1dp"
android:alpha="0.25"
android:background="@color/backgroundDark" /> android:background="@color/backgroundDark" />
<TextView <TextView
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
app:srcCompat="@drawable/ic_amiv_logo" /> app:srcCompat="@drawable/ic_amiv_logo" />
<ScrollView <ScrollView
android:id="@+id/scrollView_event" android:id="@+id/scrollView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:scrollIndicators="right" android:scrollIndicators="right"
...@@ -62,6 +62,12 @@ ...@@ -62,6 +62,12 @@
android:background="?android:attr/colorBackground" android:background="?android:attr/colorBackground"
android:orientation="vertical"> android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:alpha="0.25"
android:background="@color/backgroundDark" />
<TextView <TextView
android:id="@+id/companyTitle" android:id="@+id/companyTitle"
android:layout_width="match_parent" android:layout_width="match_parent"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment