Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
import android.widget.AdapterView;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CheckedTextView;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;

Expand Down Expand Up @@ -95,6 +98,8 @@ public class ProjectXMapFragment extends Fragment implements OnMapReadyCallback,
private Integer[] filter_chosen = new Integer[]{0, 1, 2, 3, 4};
private PendingIntent mGeofencePendingIntent = null;
private HashMap<String, Boolean> identity;
private Button lastMonthFilter,lastWeekFilter,showAllFilter,lastYearFilter;
private List<Shame> active_list = new ArrayList<>();

@Nullable
@Override
Expand All @@ -103,10 +108,57 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
initializeViews();
setCustomFont();

showAllFilter.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
map.clear();
active_list.clear();
for (Shame shame : loadFromLastYearSQLite()) {
active_list.add(shame);
}
loadData(active_list);
}
});

lastYearFilter.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
map.clear();
active_list.clear();
for (Shame shame : loadFromLastYearSQLite()) {
active_list.add(shame);
}
loadData(active_list);
}
});

lastMonthFilter.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
map.clear();
active_list.clear();
for (Shame shame : loadFromLastMonthSQLite()) {
active_list.add(shame);
}
loadData(active_list);
}
});
lastWeekFilter.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
map.clear();
active_list.clear();
for (Shame shame : loadFromLastWeekSQLite()) {
active_list.add(shame);
}
loadData(active_list);
}
});

preferences = getActivity().getSharedPreferences(Constants.SHARED_PREFERENCE, Context.MODE_PRIVATE);
geofenceEnabled = preferences.getBoolean(Constants.ALLOW_GEOFENCE, false);
if (!preferences.getBoolean(Constants.IS_CONNECTED, false))
loadData();
loadData(active_list);

identity = new HashMap<>();
identity.put(Constants.MAN, preferences.getBoolean(Constants.MAN, false));
Expand Down Expand Up @@ -199,22 +251,22 @@ public void done(final List<Shame> results, ParseException e) {
preferences.edit().putString(Constants.LAST_UPDATE, new SimpleDateFormat("yyyyMMdd_HHmmss").format(cal.getTime())).apply();
}

loadData();
Log.d("List of Shames", "Inserted " + results.size() + " Shames");
} else {
Log.d("List of Shames", "Error: " + e.getMessage());
}
}
});
}

public void loadData() {
//TODO FILTERS
public void loadData(final List<Shame> shames) {
new AsyncTask<Void, Void, String>() {
@Override
protected String doInBackground(Void[] params) {
List<Shame> active_list = loadFromSQLite();
Log.i("SQLite Shames loaded", String.valueOf(active_list.size()));
for (Shame incident : active_list) {
// active_list = loadFromLastWeekSQLite();

Log.i("SQLite Shames loaded", String.valueOf(shames.size()));
for (Shame incident : shames) {
double latitude = incident.getLatitude();
double longitude = incident.getLongitude();
LatLng location = new LatLng(latitude, longitude);
Expand Down Expand Up @@ -250,14 +302,35 @@ protected void onPostExecute(String all) {
}.execute();
}

// load incidents from past 2 months
public List<Shame> loadFromSQLite() {
public List<Shame> loadAllFromSQLite() {
ShameSQLiteHelper helper = ShameSQLiteHelper.getInstance(view.getContext());
Calendar cal = Calendar.getInstance();
cal.set(Calendar.MONTH, cal.get(Calendar.MONTH) - 2);
return helper.loadData(new String[]{new SimpleDateFormat("yyyyMMdd").format(cal.getTime())});
}

public List<Shame> loadFromLastWeekSQLite() {
ShameSQLiteHelper helper = ShameSQLiteHelper.getInstance(view.getContext());
Calendar cal = Calendar.getInstance();
cal.set(Calendar.WEEK_OF_YEAR, cal.get(Calendar.WEEK_OF_YEAR) - 1);
return helper.loadData(new String[]{new SimpleDateFormat("yyyyMMdd").format(cal.getTime())});
}

public List<Shame> loadFromLastMonthSQLite() {
ShameSQLiteHelper helper = ShameSQLiteHelper.getInstance(view.getContext());
Calendar cal = Calendar.getInstance();
cal.set(Calendar.MONTH, cal.get(Calendar.MONTH) - 1);
return helper.loadData(new String[]{new SimpleDateFormat("yyyyMMdd").format(cal.getTime())});
}

public List<Shame> loadFromLastYearSQLite() {
ShameSQLiteHelper helper = ShameSQLiteHelper.getInstance(view.getContext());
Calendar cal = Calendar.getInstance();
cal.set(Calendar.MONTH, cal.get(Calendar.MONTH) - 12);
return helper.loadData(new String[]{new SimpleDateFormat("yyyyMMdd").format(cal.getTime())});
}


public void insertDatatoSQLite(List<Shame> results) {
ShameSQLiteHelper helper = ShameSQLiteHelper.getInstance(view.getContext());
helper.insertData(results);
Expand Down Expand Up @@ -292,6 +365,7 @@ public void onMapClick(LatLng point) {
new_marker.remove();
new_marker = map.addMarker(new MarkerOptions()
.position(point).icon(BitmapDescriptorFactory.fromResource(R.drawable.smallredlogo)).draggable(true));

addShame.setVisibility(View.VISIBLE);
}

Expand All @@ -302,6 +376,7 @@ public void onMapClick(LatLng point) {
preferences.edit().putBoolean(Constants.IS_DROPPED, true).apply();
preferences.edit().putLong(Constants.LATITUDE_PREFERENCE, lat).apply();
preferences.edit().putLong(Constants.LONGITUDE_PREFERENCE, longit).apply();

}
};

Expand Down Expand Up @@ -695,6 +770,10 @@ public void initializeViews() {
addShame = (FloatingActionButton) view.findViewById(R.id.add_shame);
search = (AutoCompleteTextView) view.findViewById(R.id.search);
filter = (Button) view.findViewById(R.id.filter);
showAllFilter = (Button) view.findViewById(R.id.show_all_box);
lastWeekFilter = (Button) view.findViewById(R.id.show_week_box);
lastMonthFilter = (Button) view.findViewById(R.id.show_month_box);
lastYearFilter = (Button) view.findViewById(R.id.show_year_box);
}

public void setCustomFont() {
Expand Down Expand Up @@ -748,4 +827,5 @@ public void addSubmittedMarker() {
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.parse.ParseClassName;
import com.parse.ParseObject;

import java.util.Date;

import charlyn23.c4q.nyc.projectx.Constants;

@ParseClassName(Constants.SHAME)
Expand Down
32 changes: 30 additions & 2 deletions app/src/main/res/layout/map_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:hint="Search by location "
android:hint="Search by location "
android:imeOptions="actionGo"
android:textSize="18dp" />

Expand All @@ -64,7 +64,8 @@
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="400dp" />


<android.support.design.widget.FloatingActionButton
android:id="@+id/add_shame"
Expand All @@ -77,5 +78,32 @@
app:pressedTranslationZ="6dp"
app:rippleColor="@color/primary_dark" />

<Button
android:id="@+id/show_all_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/map"
android:text="All"/>
<Button
android:id="@+id/show_week_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/map"
android:layout_toRightOf="@id/show_all_box"
android:text="Week"/>
<Button
android:id="@+id/show_month_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/map"
android:layout_toRightOf="@id/show_week_box"
android:text="Month"/>
<Button
android:id="@+id/show_year_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/map"
android:layout_toRightOf="@id/show_month_box"
android:text="Year"/>
</RelativeLayout>
</LinearLayout>