Skip to content

Commit

Permalink
Merge pull request #109 from ZeusWPI/preferences
Browse files Browse the repository at this point in the history
Improvements & fixes for associations
  • Loading branch information
niknetniko authored Oct 4, 2016
2 parents d5d16fa + ae21fa5 commit 85d5618
Show file tree
Hide file tree
Showing 13 changed files with 187 additions and 150 deletions.
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ dependencies {
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.timehop.stickyheadersrecyclerview:library:0.4.3@aar'
compile 'com.jakewharton.threetenabp:threetenabp:1.0.4'
compile 'com.google.android.gms:play-services-analytics:9.4.0'
compile 'com.google.android.gms:play-services-analytics:9.6.1'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.github.KyoSherlock:expandablelayout:master-SNAPSHOT'
compile 'com.github.pluscubed:recycler-fast-scroll:0.3.1@aar'
Expand All @@ -81,9 +81,9 @@ dependencies {
}

//compile 'com.google.firebase:firebase-core:9.4.0'
//compile 'com.google.firebase:firebase-crash:9.4.0'
compile 'com.google.firebase:firebase-messaging:9.4.0'
compile 'com.google.firebase:firebase-config:9.4.0'
releaseCompile 'com.google.firebase:firebase-crash:9.6.1'
compile 'com.google.firebase:firebase-messaging:9.6.1'
compile 'com.google.firebase:firebase-config:9.6.1'

compile 'su.j2e:rv-joiner:1.0.9'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import android.os.Parcelable;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v4.text.util.LinkifyCompat;
import android.text.util.Linkify;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
Expand Down Expand Up @@ -67,6 +69,7 @@ protected void onCreate(Bundle savedInstanceState) {

if(event.getDescription() != null && !event.getDescription().trim().isEmpty()) {
description.setText(event.getDescription());
LinkifyCompat.addLinks(description, Linkify.ALL);
}

if(event.hasLocation()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ protected void onPause() {

//Save the values.
Set<String> disabled = new HashSet<>();
for (Pair<Association, Boolean> pair: adapter.getItems()) {
if(!pair.second) {
disabled.add(pair.first.getInternalName());
for (Map.Entry<Association, Boolean> pair: adapter.allData.entrySet()) {
if(!pair.getValue()) {
disabled.add(pair.getKey().getInternalName());
}
}

Expand All @@ -122,12 +122,29 @@ protected void onPause() {

private static class SearchableAdapter extends MultiSelectListAdapter<Association> implements SearchView.OnQueryTextListener, SectionTitleProvider {

private List<Pair<Association, Boolean>> allData;
private Map<Association, Boolean> allData = new HashMap<>();

@Override
public void setItems(List<Pair<Association, Boolean>> list) {
super.setItems(list);
allData = list;
for(Pair<Association, Boolean> pair: list) {
allData.put(pair.first, pair.second);
}
}

@Override
public void setChecked(int position) {
super.setChecked(position);
Pair<Association, Boolean> newData = items.get(position);
allData.put(newData.first, newData.second);
}

@Override
public void setAllChecked(boolean checked) {
super.setAllChecked(checked);
for(Association key: allData.keySet()) {
allData.put(key, checked);
}
}

@Override
Expand All @@ -143,17 +160,23 @@ public boolean onQueryTextChange(String newText) {
}

if(newText.isEmpty()) {
this.items = allData;
List<Pair<Association, Boolean>> newList = new ArrayList<>();
for(Map.Entry<Association, Boolean> pair: allData.entrySet()) {
newList.add(new Pair<>(pair.getKey(), pair.getValue()));
}
this.items = newList;
notifyDataSetChanged();
}

List<Pair<Association, Boolean>> newList = new ArrayList<>();

for(Pair<Association, Boolean> pair: allData) {
Association a = pair.first;
for(Map.Entry<Association, Boolean> pair: allData.entrySet()) {
String text = newText.toLowerCase();
if(a.getDisplayName().toLowerCase().contains(text) || (a.getFullName() != null && a.getFullName().toLowerCase().contains(text))) {
newList.add(pair);
Association a = pair.getKey();
if(a.getDisplayName().toLowerCase().contains(text) ||
(a.getFullName() != null && a.getFullName().toLowerCase().contains(text)) ||
a.getInternalName().toLowerCase().contains(text)) {
newList.add(new Pair<>(a, pair.getValue()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.Loader;
import android.support.v7.preference.PreferenceManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
Expand All @@ -15,12 +16,15 @@
import android.widget.LinearLayout;

import be.ugent.zeus.hydra.R;
import be.ugent.zeus.hydra.activities.preferences.AssociationSelectPrefActivity;
import be.ugent.zeus.hydra.activities.preferences.SettingsActivity;
import be.ugent.zeus.hydra.fragments.common.CachedLoaderFragment;
import be.ugent.zeus.hydra.fragments.common.LoaderFragment;
import be.ugent.zeus.hydra.loaders.RequestAsyncTaskLoader;
import be.ugent.zeus.hydra.loaders.ThrowableEither;
import be.ugent.zeus.hydra.models.association.Activities;
import be.ugent.zeus.hydra.models.association.Activity;
import be.ugent.zeus.hydra.recyclerview.adapters.ActivityListAdapter;
import be.ugent.zeus.hydra.requests.ActivitiesRequest;
import be.ugent.zeus.hydra.requests.events.FilteredEventRequest;
import be.ugent.zeus.hydra.utils.recycler.DividerItemDecoration;
import com.timehop.stickyheadersrecyclerview.StickyRecyclerHeadersDecoration;

Expand All @@ -34,7 +38,7 @@
* @author ellen
* @author Niko Strijbol
*/
public class ActivitiesFragment extends CachedLoaderFragment<Activities> implements SharedPreferences.OnSharedPreferenceChangeListener {
public class ActivitiesFragment extends LoaderFragment<Activities> implements SharedPreferences.OnSharedPreferenceChangeListener {

private ActivityListAdapter adapter;
private LinearLayout noData;
Expand Down Expand Up @@ -92,8 +96,7 @@ private void setData(@NonNull List<Activity> data) {

Activities.filterActivities(data, getContext());

adapter.setData(data);
adapter.notifyDataSetChanged();
adapter.setItems(data);

//If empty, show it.
if(data.isEmpty()) {
Expand All @@ -109,8 +112,7 @@ public void onResume() {

//Refresh the data.
if(invalid) {
//No need for a new thread, since this is pretty fast.
setData(adapter.getOriginal());
loaderHandler.restartLoader();
invalid = false;
}
}
Expand All @@ -126,7 +128,7 @@ public void onResume() {
*/
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if(key.equals("pref_association_checkbox") || key.equals("associationPrefListScreen")) {
if(AssociationSelectPrefActivity.PREF_ASSOCIATIONS_SHOWING.equals(key)) {
invalid = true;
}
}
Expand All @@ -138,15 +140,11 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
*/
@Override
public void receiveData(@NonNull Activities data) {
adapter.setOriginal(data);
setData(data);
}

/**
* @return The request that will be executed.
*/
@Override
protected ActivitiesRequest getRequest() {
return new ActivitiesRequest();
public Loader<ThrowableEither<Activities>> getLoader() {
return new RequestAsyncTaskLoader<>(new FilteredEventRequest(getContext(), shouldRenew), getContext());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import be.ugent.zeus.hydra.models.cards.AssociationActivityCard;
import be.ugent.zeus.hydra.models.cards.HomeCard;
import be.ugent.zeus.hydra.recyclerview.adapters.HomeCardAdapter;
import be.ugent.zeus.hydra.requests.ActivitiesRequest;
import be.ugent.zeus.hydra.requests.events.ActivitiesRequest;
import org.threeten.bp.ZonedDateTime;

import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class Activities extends ArrayList<Activity> {
* class. While not optimal, this is a consequence of the type erasure of Java. This should be solved in Java 9, so
* we'll probably see it in Android in 2050 or so.
*
* @param data The data to filter. This list is not touched.
* @param data The data to filter.
* @param context The context.
*/
public static List<Activity> filterActivities(List<Activity> data, Context context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@

import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.NonNull;

import java.io.Serializable;
import com.google.gson.annotations.SerializedName;

import java.io.Serializable;

/**
* Created by feliciaan on 04/02/16.
* Represents an association registered with the DSA.
*
* An association is identified by it's internal name. If the internal name is the same, the association is the same.
* Both the hash and equals method are implemented for this class.
*
* @author feliciaan
* @author Niko Strijbol
*/

public class Association implements Parcelable, Serializable {

@SerializedName("internal_name")
Expand All @@ -21,50 +28,56 @@ public class Association implements Parcelable, Serializable {
@SerializedName("parent_association")
private String parentAssociation;

protected Association(Parcel in) {
internalName = in.readString();
fullName = in.readString();
displayName = in.readString();
parentAssociation = in.readString();
@SuppressWarnings("unused")
private Association() {
//GSON no args constructor
}

/**
* @return A name for this association. If a full name is available, that is returned. If not, the display name is.
*/
public String getName() {
if (fullName != null) {
return fullName;
}
return displayName;
}

@NonNull
public String getInternalName() {
return internalName;
}

public void setInternalName(String internalName) {
this.internalName = internalName;
}

public String getFullName() {
return fullName;
}

public void setFullName(String fullName) {
this.fullName = fullName;
}

public String getDisplayName() {
return displayName;
}

public void setDisplayName(String displayName) {
this.displayName = displayName;
}

public String getParentAssociation() {
return parentAssociation;
}

public void setParentAssociation(String parentAssociation) {
this.parentAssociation = parentAssociation;
public String getImageLink() {
return "https://zeus.ugent.be/hydra/api/2.0/association/logo/" + internalName.toLowerCase() + ".png";
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

Association that = (Association) o;

return internalName.equals(that.internalName);

}

@Override
public int hashCode() {
return internalName.hashCode();
}

public static final Creator<Association> CREATOR = new Creator<Association>() {
Expand Down Expand Up @@ -92,11 +105,10 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeString(parentAssociation);
}

public String getImageLink() {
if(internalName == null) {
return null;
}

return "https://zeus.ugent.be/hydra/api/2.0/association/logo/" + internalName.toLowerCase() + ".png";
protected Association(Parcel in) {
internalName = in.readString();
fullName = in.readString();
displayName = in.readString();
parentAssociation = in.readString();
}
}
Loading

0 comments on commit 85d5618

Please sign in to comment.