Commit 337c18f6 authored by Roger Barton's avatar Roger Barton
Browse files

Fixed page viewer bug

parent 85f7bcc9
image: registry.gitlab.com/showcheap/android-ci:react-native
variables:
GIT_SUBMODULE_STRATEGY: recursive
before_script:
- git submodule sync --recursive
- git submodule update --init --recursive
- export GRADLE_USER_HOME=`pwd`/.gradle
- chmod +x ./gradlew
- npm install
cache:
key: "$CI_COMMIT_REF_NAME"
paths:
- .gradle/
stages:
- test
- build
test:
stage: test
script:
- ./gradlew check
build:
stage: build
script:
- ./gradlew assembleRelease
artifacts:
expire_in: 1 week
paths:
- app/build/outputs/
......@@ -27,13 +27,14 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:support-v4:27.1.1'
//implementation 'com.mcxiaoke.volley:library:1.0.19'
implementation project(path: ':volley')
implementation 'com.google.zxing:core:3.2.1'
implementation 'com.journeyapps:zxing-android-embedded:3.2.0@aar'
implementation 'com.google.android.gms:play-services-vision:15.0.2'
implementation 'com.google.code.gson:gson:2.8.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
......
......@@ -17,7 +17,6 @@ import com.google.zxing.common.BitMatrix;
import com.journeyapps.barcodescanner.BarcodeEncoder;
import java.lang.reflect.Field;
import java.nio.file.attribute.UserDefinedFileAttributeView;
import ch.amiv.android_app.R;
import ch.amiv.android_app.core.UserInfo;
......
package ch.amiv.android_app.core;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.NonNull;
......@@ -38,7 +40,29 @@ public class ListFragment extends Fragment {
private Requests.OnDataReceivedCallback cancelRefreshCallback = new Requests.OnDataReceivedCallback() {
@Override
public void OnDataReceived() {
swipeRefreshLayout.setRefreshing(false);
SetRefreshUI(false);
}
};
public Requests.OnDataReceivedCallback onEventsListUpdatedCallback = new Requests.OnDataReceivedCallback() {
@Override
public void OnDataReceived() {
Requests.FetchEventSignups(recyclerView.getContext(), onSignupsUpdatedCallback, null, "");
RefreshList(true);
}
};
public Requests.OnDataReceivedCallback onJobsListUpdatedCallback = new Requests.OnDataReceivedCallback() {
@Override
public void OnDataReceived() {
RefreshList(true);
}
};
private Requests.OnDataReceivedCallback onSignupsUpdatedCallback = new Requests.OnDataReceivedCallback() {
@Override
public void OnDataReceived() {
RefreshList(false);
}
};
......@@ -66,66 +90,57 @@ public class ListFragment extends Fragment {
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
recyclerView = getView().findViewById(R.id.recyclerView);
super.onViewCreated(view, savedInstanceState);
swipeRefreshLayout = getView().findViewById(R.id.swipeRefresh);
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
if(!(getActivity() instanceof MainActivity))
if(!(recyclerView.getContext() instanceof MainActivity))
return;
if(pagePosition == PageType.EVENTS)
Requests.FetchEventList(getContext(), ((MainActivity)getActivity()).onEventsListUpdatedCallback, cancelRefreshCallback, "");
Requests.FetchEventList(recyclerView.getContext(), onEventsListUpdatedCallback, cancelRefreshCallback, "");
else if (pagePosition == PageType.JOBS)
Requests.FetchJobList(getContext(), ((MainActivity)getActivity()).onJobsListUpdatedCallback, cancelRefreshCallback, "");
Requests.FetchJobList(recyclerView.getContext(), onJobsListUpdatedCallback, cancelRefreshCallback, "");
}
});
//refresh on activity start
swipeRefreshLayout.post(new Runnable() {
@Override
public void run() {
if(!(getActivity() instanceof MainActivity))
if(!(recyclerView.getContext() instanceof MainActivity))
return;
if(pagePosition == PageType.EVENTS) {
swipeRefreshLayout.setRefreshing(true);
Requests.FetchEventList(getContext(), ((MainActivity)getActivity()).onEventsListUpdatedCallback, cancelRefreshCallback, "");
SetRefreshUI(true);
Requests.FetchEventList(recyclerView.getContext(), onEventsListUpdatedCallback, cancelRefreshCallback, "");
}
else if(pagePosition == PageType.JOBS){
swipeRefreshLayout.setRefreshing(true);
Requests.FetchJobList(getContext(), ((MainActivity)getActivity()).onJobsListUpdatedCallback, cancelRefreshCallback, "");
SetRefreshUI(true);
Requests.FetchJobList(recyclerView.getContext(), 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);
// use this setting to improve performance if you know that changes
// in content do not change the layout size of the RecyclerView
recyclerView.setHasFixedSize(true);
// use a linear layout manager
recyclerLayoutAdapter = new LinearLayoutManager(getContext());
recyclerLayoutAdapter = new LinearLayoutManager(recyclerView.getContext());
recyclerView.setLayoutManager(recyclerLayoutAdapter);
// specify an adapter (see also next example)
if(pagePosition == PageType.EVENTS)
recyclerAdapter = new EventsListAdapter(getActivity());
recyclerAdapter = new EventsListAdapter(((Activity) recyclerView.getContext()));
else if (pagePosition == PageType.JOBS)
recyclerAdapter = new JobListAdapter(getActivity());
recyclerAdapter = new JobListAdapter((Activity) recyclerView.getContext());
if(recyclerAdapter != null) {
recyclerView.setLayoutAnimation(AnimationUtils.loadLayoutAnimation(getContext(), R.anim.layout_anim_falldown));
recyclerView.setLayoutAnimation(AnimationUtils.loadLayoutAnimation(recyclerView.getContext(), R.anim.layout_anim_falldown));
recyclerView.setAdapter(recyclerAdapter);
AnimateList(null);
......@@ -150,7 +165,7 @@ public class ListFragment extends Fragment {
if(recyclerAdapter == null)
return;
swipeRefreshLayout.setRefreshing(false);
SetRefreshUI(false);
recyclerAdapter.RefreshData();
if(animate)
AnimateList(null);
......@@ -175,6 +190,22 @@ public class ListFragment extends Fragment {
recyclerAdapter.RefreshData();
}
private void SetRefreshUI(boolean isRefreshing){
//Disable the refresh animation after a timeout
swipeRefreshLayout.setRefreshing(isRefreshing);
if(!isRefreshing)
return;
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
swipeRefreshLayout.setRefreshing(false);
}
}, 1000*15);
}
/**
* Animation is stored in an xml in the res/anim folder, it is applied to the views in xml, this just triggers the anim
* @param view Used to allow UI elems to call this, pass null otherwise
......@@ -184,7 +215,7 @@ public class ListFragment extends Fragment {
if(recyclerAdapter == null)
return;
getActivity().runOnUiThread(new Runnable() {
recyclerView.post(new Runnable() {
public void run() {
recyclerView.invalidate();
recyclerView.scheduleLayoutAnimation();
......
......@@ -7,7 +7,7 @@ import android.support.design.widget.BottomNavigationView;
import android.support.design.widget.NavigationView;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.GravityCompat;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.DrawerLayout;
......@@ -21,11 +21,14 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.util.Vector;
import ch.amiv.android_app.R;
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;
import ch.amiv.android_app.util.PersistentStorage;
/**
* This is the first screen. features: drawer, pageview with bottom navigation bar and within each page a list view.
......@@ -42,28 +45,6 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
private ViewPager viewPager;
private PagerAdapter pagerAdapter;
public Requests.OnDataReceivedCallback onEventsListUpdatedCallback = new Requests.OnDataReceivedCallback() {
@Override
public void OnDataReceived() {
Requests.FetchEventSignups(getApplicationContext(), onSignupsUpdatedCallback, null, "");
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() {
@Override
public void OnDataReceived() {
pagerAdapter.RefreshPage(ListFragment.PageType.EVENTS, false);
}
};
/**
* Handle what should happen when the bottom nav buttons are pressed, will change the page of the viewpager
*/
......@@ -166,14 +147,6 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
}
//endregion
@Override
protected void onPostResume() {
super.onPostResume();
if(pagerAdapter != null)
pagerAdapter.notifyDataSetChanged();
}
//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
......@@ -364,29 +337,41 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
//region =====START OF PAGEVIEW==============
protected ListFragment[] pages = new ListFragment[ListFragment.PageType.COUNT];
protected Vector<ListFragment> pages = new Vector<>(ListFragment.PageType.COUNT);
/**
* This will handle changing between the pages
*/
public class PagerAdapter extends FragmentPagerAdapter {
public class PagerAdapter extends FragmentStatePagerAdapter {
int currentPosition;
public PagerAdapter(FragmentManager fm) {
super(fm);
for(int i = 0; i< ListFragment.PageType.COUNT; i++)
pages[i] = ListFragment.NewInstance(i);
pages.add(ListFragment.NewInstance(i));
notifyDataSetChanged();
}
@Override
public int getCount() {
return ListFragment.PageType.COUNT;
return pages.size();
}
@Override
public Fragment getItem(int position) {
if(pages[position] == null)
pages[position] = ListFragment.NewInstance(position);
return pages[position];
return pages.get(position);
}
@Override
public int getItemPosition(Object object) {
ListFragment fragment = (ListFragment) object;
int position = pages.indexOf(fragment);
if (position >= 0) {
return position;
} else {
return POSITION_NONE;
}
}
@Override
......@@ -395,10 +380,15 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
super.setPrimaryItem(container, position, object);
}
/*
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
}*/
public void RefreshPage(int position, boolean animate){
if(pages[position] != null)
pages[position].RefreshList(animate);
if(pages.get(position) != null)
pages.get(position).RefreshList(animate);
else
Log.e("pageview", "RefreshPage(), Page does not exist will not refresh: " + position);
}
......@@ -438,5 +428,4 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
}
}
//endregion =====END OF PAGEVIEW================
}
}
\ No newline at end of file
package ch.amiv.android_app.core;
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Bitmap;
import android.net.ConnectivityManager;
......@@ -93,23 +94,23 @@ public final class Requests {
final JSONObject json = new JSONObject(new String(response.data));
//Update events on main thread
if(callback != null) {
Runnable runnable = new Runnable() {
@Override
public void run() {
try {
if(eventId.isEmpty())
Events.UpdateEventInfos(json.getJSONArray("_items"));
else
Events.UpdateSingleEvent(json, eventId);
} catch (JSONException e) {
e.printStackTrace();
}
callback.OnDataReceived();
Runnable runnable = new Runnable() {
@Override
public void run() {
try {
if(eventId.isEmpty())
Events.UpdateEventInfos(json.getJSONArray("_items"));
else
Events.UpdateSingleEvent(json, eventId);
if(callback != null)
callback.OnDataReceived();
} catch (JSONException e) {
RunCallback(errorCallback);
e.printStackTrace();
}
};
callbackHandler.post(runnable);
}
}
};
callbackHandler.post(runnable);
Log.e("request", new JSONObject(new String(response.data)).toString());
} catch (JSONException e) {
......@@ -257,24 +258,24 @@ public final class Requests {
try {
final JSONObject json = new JSONObject(new String(response.data));
//Update events on main thread
if(callback != null) {
Runnable runnable = new Runnable() {
@Override
public void run() {
try {
if(jobId.isEmpty())
Jobs.UpdateJobInfos(json.getJSONArray("_items"));
else
Jobs.UpdateSingleJob(json, jobId);
} catch (JSONException e) {
e.printStackTrace();
}
callback.OnDataReceived();
//Update on main thread
Runnable runnable = new Runnable() {
@Override
public void run() {
try {
if(jobId.isEmpty())
Jobs.UpdateJobInfos(json.getJSONArray("_items"));
else
Jobs.UpdateSingleJob(json, jobId);
if(callback != null)
callback.OnDataReceived();
} catch (JSONException e) {
RunCallback(errorCallback);
e.printStackTrace();
}
};
callbackHandler.post(runnable);
}
}
};
callbackHandler.post(runnable);
Log.e("request", new JSONObject(new String(response.data)).toString());
} catch (JSONException e) {
......@@ -492,6 +493,9 @@ public final class Requests {
*/
public static boolean CheckConnection(Context context)
{
if(context == null)//If we cannot check the connection then fallback to no internet
return false;
ConnectivityManager cm = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
......
......@@ -68,7 +68,7 @@
<string name="no_internet">Kein Internet</string>
<string name="requires_internet">Benötigt Internet</string>
<string name="snack_fill_all_fields">Bitte füllen sie alle Felder ein</string>
<string name="snack_fill_fields">Bitte füllen sie Felder ein</string>
<!-- Jobs -->
<string name="no_pdf_found">Kein PDF Gefunden</string>
......
......@@ -69,7 +69,7 @@
<string name="no_internet">No Internet</string>
<string name="requires_internet">Requires Internet</string>
<string name="snack_fill_all_fields">Please fill in all fields</string>
<string name="snack_fill_fields">Please fill in fields</string>
<!-- Jobs -->
<string name="no_pdf_found">No PDF found</string>
......
......@@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.android.tools.build:gradle:3.1.3'
// NOTE: Do not place your application dependencies here; they belong
......
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